Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@typescript-eslint/parser doesn't ignore files, which is excluded by/in tsconfig.json #905

Closed
dimabory opened this issue Aug 26, 2019 · 11 comments
Labels
package: parser Issues related to @typescript-eslint/parser working as intended Issues that are closed as they are working as intended

Comments

@dimabory
Copy link
Contributor

The sample project is available here https://github.com/dimabory/ts-eslint-project.

In case of project is specified within parserOptions, @typescript-eslint/parser doesn't ignore files, which is excluded by/in tsconfig.json.

// tsconfig
{
  "compilerOptions": {
    "outDir": "./build/",
    "target": "es5",
    "module": "commonjs",
    "esModuleInterop": true
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "src/**/*.test.ts"
  ]
}
// .eslintrc.js
module.exports = {
  'env':           {
    'node': true,
    'es6':  true
  },
  'parser':        '@typescript-eslint/parser',
  'extends':       [
    'eslint:recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
  ],
  'parserOptions': {
    'ecmaVersion': 2015,
    'sourceType':  'module',
    'project':     './tsconfig.json'
  },
  'rules':         {}
}

What did you expect to happen?

Excluded files should be ignored by eslint.

What actually happened?

0:0 error Parsing error: If "parserOptions.project" has been set for @typescript-eslint/parser, .../src/index.test.ts must be included in at least one of the projects provided

Versions

package version
@typescript-eslint/parser 2.0.0
TypeScript 3.5.3
ESLint 6.2.2
node 10.16.3
npm 6.9.0
@dimabory dimabory added package: parser Issues related to @typescript-eslint/parser triage Waiting for maintainers to take a look labels Aug 26, 2019
@dimabory dimabory changed the title @typescript-eslint/parser' doesn't ignore files, which is **excluded** by/in tsconfig.json '@typescript-eslint/parser' doesn't ignore files, which is excluded by/in tsconfig.json Aug 26, 2019
@dimabory dimabory changed the title '@typescript-eslint/parser' doesn't ignore files, which is excluded by/in tsconfig.json @typescript-eslint/parser doesn't ignore files, which is excluded by/in tsconfig.json Aug 26, 2019
@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for maintainers to take a look labels Aug 26, 2019
@bradzacher
Copy link
Member

What command are you running to do your linting?
Note that includes/excludes from your tsconfig does not dictate what files we report lint errors for - just what files we can parse.

If you want to exclude files, either use a .eslintignore file, or make sure the globs you pass to the cli is the same as the tsconfig.

@dimabory
Copy link
Contributor Author

dimabory commented Aug 26, 2019

What command are you running to do your linting?
Note that includes/excludes from your tsconfig does not dictate what files we report lint errors for - just what files we can parse.

I'm running eslint src/**/*.ts.
I assumed that excluded files in tsconfig considered as ignored by the parser as well.

If you want to exclude files, either use a .eslintignore file, or make sure the globs you pass to the cli is the same as the tsconfig.

The glob is actually the same therefore I have to provide an additional option in cli to ignore some files eslint src/**/*.ts --ignore-pattern "*.test.*". It can be really annoying in case of the long list of excluded files.

@bradzacher bradzacher added working as intended Issues that are closed as they are working as intended and removed awaiting response Issues waiting for a reply from the OP or another party labels Aug 26, 2019
@bradzacher
Copy link
Member

bradzacher commented Aug 26, 2019

It's not a good idea to do zero linting on test files.
Test files are code all the same, so they should be linted to ensure standards are met, though they can be subject to a laxer set of standards.


That aside, ESLint passes us the list of files, which it takes from the CLI. We cannot control this list, we can only act based upon this list.

The action we take is to inform you (via an error) that you've asked eslint to lint a file that you've excluded. This is done on purpose because we can't tell the difference between an explicitly excluded file (i.e. one that was added to exclude), and an implicitly excluded one (i.e. one that was forgotten to be added to the include). In the latter (much more common case), we want to tell you that your config is wrong, so that you can correct it.

If you have a complex set of excludes in your tsconfig, you should use a .eslintignore file instead of the CLI flag.

Or you should consider providing a more inclusive tsconfig via creating a new tsconfig.eslint.json, as documented in our readmes.

@dimabory
Copy link
Contributor Author

Gotcha!
Thank you @bradzacher for the clarity and quick response. 👍

@TokugawaTakeshi
Copy link

TokugawaTakeshi commented Sep 6, 2019

@bradzacher ,
I am sorry, but there is noone full match for tsconfig.eslint.json in Google search request results for September 2019. Could you please to provide the link to your readme which mentions the tsconfig.eslint.json?

i.e. one that was forgotten to be added to the include

It looks like include option is incompatible with comilerOptions.paths and comilerOptions.paths. So, it to use include, we lost the path aliases usage.

{
  "compilerOptions": {

    // will be ignored because of `include`:
    "baseUrl": "./",
    "paths": {

      "@SourceFiles:Root/*": ["./Source/*"],
      "@ProjectBuilder:Root/*": ["./Source/ProjectBuilder/*"],
      // ...
  },
  "include": [
    "Source/**/*.(ts|vue)"
  ]
}

image

@bradzacher
Copy link
Member

Could you please to provide the link to your readme which mentions the tsconfig.eslint.json?

Google doesn't always index github readmes fully. You should consider using the github search feature instead.

It's listed in the parser readme:
https://github.com/typescript-eslint/typescript-eslint/blob/4a29098/packages/parser/README.md#L71

As well as the 2.0.0 release notes:
https://github.com/typescript-eslint/typescript-eslint/releases/tag/v2.0.0

There are currently some problems with parsing vue files, because vue is a weird, very custom, use case that is unsupported by typescript. See #883

@lvl99
Copy link

lvl99 commented Sep 24, 2019

Or you should consider providing a more inclusive tsconfig via creating a new tsconfig.eslint.json, as documented in our readmes.

Thanks @bradzacher , I duplicated my tsconfig.json and removed the "excludes": ["**/*.test.ts"] and that seemed to solve it well for me.

@TokugawaTakeshi
Copy link

TokugawaTakeshi commented Sep 25, 2019

@lvl99 , duplicated tsconfig.json?! Is it normal practice or just a hack?

@lvl99
Copy link

lvl99 commented Sep 25, 2019

@tokugawatakesi it was a quick hack to get working, then I remembered the extends option and simplified the file even more. My tsconfig.eslint.json now contains minimum 3 options:

{
  “extends”: “./tsconfig”,
  “include”: [“src”],
  “exclude”: []
}

This lets me target all files in src (I have all my tests within src too) and exclude none for purposes of compiling TS for eslint.

@TokugawaTakeshi
Copy link

@lvl99, I see, thank you for sharing of your solution!

@dcDalin
Copy link

dcDalin commented Dec 18, 2019

What command are you running to do your linting?
Note that includes/excludes from your tsconfig does not dictate what files we report lint errors for - just what files we can parse.

If you want to exclude files, either use a .eslintignore file, or make sure the globs you pass to the cli is the same as the tsconfig.

It should be as simple as creating an .eslintignore file containing folders you want to ignore; Like so

node_modules/
public/
bin/
build/

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: parser Issues related to @typescript-eslint/parser working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

5 participants