question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ESLint should adhere to ignore rules that wrap import() and import.meta

See original GitHub issue

The version of ESLint you are using.

Latest (5.x.x at time of writing)

The problem you want to solve.

// eslint-disable-next-line
const module = import('./foo.js');

This line should be skipped rather than blow up with a parsing error.

Your take on the correct solution to problem.

ESLint could instead analyze my code for exclusion rules and then parse what remains. This would be the expected ignore behavior IMO, and not require a policy debate.

It seems totally reasonable to adopt only Stage 4 features, but on balance it seems completely unreasonable to not actually ignore this line. ESLint should consider a less pure solution that strikes a balance here. Folding in a transpile step via babel-eslint to make sure this ignore happens is not a good option. Ultimately I don’t care if this line is skipped, but to have all the proximal code become collateral damage is a bummer.

Thanks in advance for considering!

Related:

Are you willing to submit a pull request to implement this change?

I’m not currently informed enough to know the level of effort here, so I can’t commit to making the change yet.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, Mar 16, 2019

Requiring both /* eslint-disable */ and /* eslint-disable */ would help with the second issue from https://github.com/eslint/eslint/issues/11514#issuecomment-473415680 in some cases, but would not address the first issue.

Currently, /* eslint-disable */ means “ESLint should suppress any errors reported for this section of the code”, not “ESLint should pretend this section of the code doesn’t exist at all”. (To illustrate the difference: If ESLint entirely ignored the line containing import in your example, then it would also start reporting errors about the variable module not being defined if the variable was used later.) So while I sympathize with the inconvenience of having ESLint fail on parsing errors, I’m not convinced that being able to use // eslint-disable to suppress parsing errors is a desirable goal in the first place. Unlike many other linters, ESLint does separate passes for parsing and linting (this makes it possible to support arbitrary custom parsers and rules), and so there is naturally a fundamental difference between parsing errors and other types of linting errors. I’m not sure having eslint-disable comments conflate the two is a good idea.

One could imagine having a separate type of directive that does what you’re asking (i.e. it strips out sections of code before the code gets parsed). But it seems to me that it would almost always be better to use a different parser that handles the case you want, rather than adding directives to slice that case out of the code before linting.

0reactions
platinumazurecommented, May 6, 2019

@johanneswilm As has been noted multiple times in this issue, you can use the babel-eslint parser to have ESLint work with that syntax.

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-restricted-imports - ESLint - Pluggable JavaScript Linter
This rule allows you to specify imports that you don't want to use in your application. It applies to static imports only, not...
Read more >
What if ESLint's configuration worked like elm-review?
I was curious to see how the configuration for ESLint would look like if it used ... import * as core from "eslint";...
Read more >
Linter rules - Dart
Avoid relative imports for files in lib/ . This rule is available as of Dart 2.0.0. Rule sets: core, recommended, flutter. This rule...
Read more >
ESlint - import.meta causes Fatal Parsing Error - Stack Overflow
Using the Atom editor, with the linter-eslint package installed, I have a node. mjs script that uses ES6 module's import statement to import...
Read more >
JSHint Options Reference
If you would like to enforce rules relating to code style, check out the JSCS ... Notable additions: "export * as ns from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found