typescript-eslint: `parseForESLint` from parser `@typescript-eslint/parser` is invalid and will just be ignored

What code were you trying to parse?

I am trying to work with this setup: https://github.com/wemake-services/wemake-vue-template/blob/master/template/.eslintrc.js

Here’s how other eslint reusable packages from there are defined:

The problem might be in the amount of packages there.

What did you expect to happen?

It should work correctly.

What actually happened?

» npm run lint:js

> name@0.0.0 lint:js /Users/sobolev/Documents/github/wemake-vue-template/template
> eslint --cache --ext .js,.ts,.vue,.json --ignore-path .gitignore .

`parseForESLint` from parser `@typescript-eslint/parser` is invalid and will just be ignored
`parseForESLint` from parser `@typescript-eslint/parser` is invalid and will just be ignored
`parseForESLint` from parser `@typescript-eslint/parser` is invalid and will just be ignored
`parseForESLint` from parser `@typescript-eslint/parser` is invalid and will just be ignored

Versions

package version
@typescript-eslint/parser 2.11.0
TypeScript 3.7.3
ESLint 6.7.2
node 10.16
npm 6.11

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (8 by maintainers)

Most upvoted comments

@bradzacher it would be easier with https://github.com/wemake-services/wemake-frontend-styleguide

Steps:

  1. Clone the repo and run yarn install
  2. Uncomment this line: https://github.com/wemake-services/wemake-frontend-styleguide/blob/master/packages/eslint-config-typescript/base.js#L71
  3. Run yarn lint:ts

It will show the warning. Thanks for your help!

If there was a parser error when invoked by eslint-plugin-import, then it would show up as part of the normal lint run; eslint-plugin-import doesn’t to anything special with its parse.

The fact that there is no parsing error reported by the user in the normal lint run suggests that there is a different issue, one likely with their config.

I guess there is a slim chance that eslint-plugin-import is parsing an npm dependency, which is throwing (which wouldn’t happen as part of a normal lint run), but that’s seems unlikely?

It’s hard to tell because the plugin swallows the error, if there was one.

Didn’t seen like it was worth the time to investigate further at the time; as it was the first and only report of this, and we recommend not using those rules anyways.

If more people are running into it, we can look at reopening and investigating further.

eslint-plugin-import parses the files touched by all import/require statements. That includes files in node_modules. This parsing is separate to the standard eslint parsing cycle.

This is done so that it can collect information about the exports of the file, so that it can report if you’re importing names/default correctly, etc.

This is the reason I suggest TS users don’t use the rules which require a parser - because TS itself does this validation as part of the standard typecheck, so it’s double handling.

https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/FAQ.md#eslint-plugin-import

I did the same as @bradzacher and for me, the files are as follows:

./node_modules/@react-native-community/async-storage/jest/async-storage-mock.js

./node_modules/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js

./node_modules/@react-native-community/async-storage/lib/AsyncStorage.js

./node_modules/@storybook/addons/src/index.js

Why is my node_modules folder even being parsed, shouldn’t it be disabled by default?

In this case, nah it’s not that - the .vue files are written in vue, which our parser doesn’t support. The problem is having separate lint commands which don’t properly include/exclude the files that they support.

Your typescript lint command shouldn’t attempt to lint .vue files, because that won’t work.

Solutions are either:

  • Add the vue eslint parser to your typescript config so it can handle .vue files
  • Explicitly exclude .vue files from your typescript lint command.

@sobolevn could you list the exact repro steps for your repo?

Is it just clone the repo linked in the post (https://github.com/wemake-services/wemake-vue-template/), npm install, npm run lint:js?

I’m not sure how this isn’t a bug in the parser - if parseForEslint doesn’t return a valid ast then it seems like the parser is broken.

Disabling rules as a perf recommendation doesn’t change that the rules should still work when enabled.