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
Tsconfig includes not recognized (typescript-eslint@2.0.0) #853
Comments
I don't think this is Vue specific. I'm experiencing the same problem with my Next.js project. I would suggest to take Vue out of the title. |
Yeh, i
I got equal issue with jest mockup and snapshot files |
Can confirm, this issue occurs in my Bot Framework project as well. Edit: It went away when I changed an unrelated option in my ESLint config. |
@0x80, @gho1b, @mrestorff and anyone else who chooses to comment here. Please provide details about your setups to help us investigate any problems, as 1 line comments don't really tell us anything about the problem. We don't want to have to go and google everything about your specific use case, as that's not scalable or maintainable for us, as we are volunteers. Help us to help you. Post your eslint config, your tsconfig, code samples, links to repos, etc. Anything and everything that you think might help. @gho1b - jest snapshot files are not something we parse. So I need more information about what your setup looks like. @sem4phor we have an integration test setup for |
@bradzacher Sorry for assuming the problem was somehow obvious. In my case the problem occurs as part of a Next.js project. I have the following config:
{
"compilerOptions": {
"esModuleInterop": true,
"jsx": "preserve",
"lib": ["dom", "esnext"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveConstEnums": true,
"removeComments": false,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "esnext",
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "**/*.js", "**/*.ts", "**/*.tsx"]
}
module.exports = {
parser: "@typescript-eslint/parser",
parserOptions: {
project: "./tsconfig.json", // required for rules that need type information
ecmaVersion: 2018,
sourceType: "module",
ecmaFeatures: {
jsx: true
}
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"prettier/@typescript-eslint"
],
rules: {
"no-console": ["error", { allow: ["error", "log"] }],
"no-empty": "off",
"react/prop-types": "off", // seems to clash
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-use-before-define": "off",
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/explicit-function-return-type": "off"
},
settings: {
react: {
version: "detect" // Tells eslint-plugin-react to automatically detect the version of React to use
}
}
}; ESlint starts giving me the error (as described by @sem4phor) but only on Javascript files that I have mixed with my Typescript ones. It does not complain about the Typescript files. |
Having same issue with regards to the new parser having a fit on any .js files on a personal project (haven't uploaded to github yet). Seeing no issues with .ts files, but .js files are having the same error as described here. The only thing that changed was upgrading to v2.0.0 from v1.13.0. The project is pretty much pure typescript, no frameworks being used so it is definitely an issue with the parser.
{
"compilerOptions": {
"baseUrl": "./src",
"incremental": true,
"tsBuildInfoFile": "./.cache/tsBuildInfo",
"sourceMap": true,
"strict": true,
"noUnusedLocals": true,
"esModuleInterop": true,
"module":"esnext",
"moduleResolution": "node",
"rootDir": "./src"
},
"include": [
"./src/**/*"
]
}
import typescript from "rollup-plugin-typescript2";
import { terser } from "rollup-plugin-terser";
export default {
input: ["./src/index.ts"],
plugins: [
typescript({
tsconfig: "./tsconfig.json"
}),
terser({
output: {
ecma: 5
},
mangle: {
properties: {
regex: /^(_|\$\$)/
}
}
})
],
output: {
file: "./dist/umd/lib.min.js",
format: "umd",
name: "MyLib",
sourcemap: true
}
};
{
"root": true,
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier/@typescript-eslint"
],
"env": {
"browser": true,
"es6": true
},
"plugins": ["@typescript-eslint", "prettier"],
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-this-alias": "off"
}
} Versions:
|
Please try adding cc @uniqueiniquity / @JamesHenry. |
It is also described on the @typescript-eslint/eslint-plugin page but you could also make a tconfug.eslint.json, target than in eslintrc and have it extend your base tsconfig. That way you can allowJS and include non-source files (I.e. tests) while not dirtying your build. |
@bradzacher i has done to solve the snap files after exclude generated files from eslint. But the issue still happen for config files (*.config.js, *.mockup.js, etc). This is my tsconfig and eslintrc
|
@gho1b, you need to include the {
"extends": "./tsconfig.json",
"includes": [
"src",
"**/*.tsx",
"**/*.ts",
"**/*.js",
"next-env.d.ts"
],
"excludes": [
"node_modules",
"dist",
".next",
"out"
]
} Alternatively you can also tell typescript-eslint parser to create a default program to regain pe-v2.x behaviour, see configuration in the readme: |
@bradzacher Adding What actually fixed this for me is creating a separate tsconfig.json for eslint, which has to include the files I want to lint, both the JS and TS files, including configuration files. I'm not sure I particularly like this solution as it seems more work just to set up a working configuration. I'll probably have to do the same with my other projects as well to do this upgrade, but the separate tsconfig approach works for me. |
@Bluefinger what I told @gho1b also applies to you. You should read the README of the parser package. You can optionally pass the |
@favna Please keep in mind that the configuration I posted worked pre-v2 (and I read the README previously to get that working originally). I didn't expect the very configuration behaviour to change in a breaking way with the upgrade, considering simply setting an Now I understand what is going on, so thanks for the help. |
@bradzacher I checked the sfc-integration test and the relevant difference is that there is no .js file in the test folder. In my repository these files are causing the issues. |
TL;DR summary: Either: update your base tsconfig to include all files you want to lint, OR create a new {
// extend your base config so you don't have to redefine your compilerOptions
"extends": "./tsconfig.json",
"include": [
"src/**/*.ts",
"test/**/*.ts",
"typings/**/*.ts"
// etc
],
// IF (and only if) you have a mixed JS/TS codebase - you should also turn on JS support
"compilerOptions": {
"allowJs": true,
"checkJs": true
}
} If you are using non standard file extensions (i.e. .vue files), you should add the following config to your .eslintrc file: {
"parserOptions": {
"extraFileExtensions": [".vue"]
}
} For those saying "it worked in 1.x, but it's broken in 2.x". We know. We purposely introduced a breaking change in 2.0.0. It's documented clearly in the 2.0.0 release notes. This change wasn't done lightly, nor was it done for no reason. In v1.x, when you performed a lint, essentially this happened (note this only applies when passing in
As you can probably guess, that last point absolutely destroyed performance if you provided a "bad" tsconfig file. The typescript compiler does not share any information between each program, meaning there was likely going to be a heck of a lot of duplicated work. The breaking change we made was simple. Instead of silently (and slowly) handling "unexpected" files, we now throw an error. This alerts you, the user, that you've given us a "bad" config, and gives you the opportunity to review and correct your config so that we can parse everything up-front, and do everything in a very fast manner. The simplest, and most correct solution is as mentioned in the docs, and by @favna:
We understand that this is an extra config file, and a bit of extra work on your end, but this is the price to pay for performance. As @favna points out, we still have the old code paths - it's just been hidden behind a flag. We left this in for one simple reason: in case there was a use case that we missed / cannot support properly. We obviously didn't want to completely break the experience for users whose use case we hadn't thought of. If you really, really, really want to use this flag, it's likely going to be very, very, very slow. USING THIS FLAG IS NOT RECOMMENDED. AT ALL. NOT ONE BIT. FOR OBVIOUS REASONS. |
@favna Wogh, thank you. Your solutions solve my issue, then i just exclude |
@bradzacher AFAICT I already had the right configuration, including all files and having allowJs enabled. So I'm using the flag as a workaround for now. |
Breaking changes in Electron and here: https://github.com/typescript-eslint/typescript-eslint/releases/tag/v2.0.0 as noted here: typescript-eslint/typescript-eslint#853 (comment)
I'm using a Typescript/Next.js project. I already have all of the files that I want to be linted in my {
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": false,
"skipLibCheck": false,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"typeRoots": ["node_modules/@types"]
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
} With this configuration, I get the error described. Setting Here's my eslint config: "eslintConfig": {
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"tsconfigRootDir": "."
},
"plugins": [
"@typescript-eslint"
],
"extends": [
"plugin:react/recommended",
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier",
"prettier/@typescript-eslint"
],
"settings": {
"react": {
"version": "detect"
}
}
} |
We've just merged a change into master which should make this a bit easier and clearer for you all:
Please give it a try on the |
Greetings @bradzacher and thank you for your active support. I tried the canary (2.0.1-alpha.14) and I noticed that by having "*.js" in the tsconfig.json include all JS files (even in subfolders) get matched instead of only those in the same folder as tsconfig.json. I was expecting to get error message on JS files in the sub folders. But may be I am wrong? |
I also just noticed that while using IntelliJ, I created a new JS file but was not matched, although I have glob-like patterns in my tsconfig.json that should get it matched. |
That's actually the cause of my issue too in vscode. If I create a new file, I get this error. If I stop eslint and run it again, it works as expected. It doesn't seem to automatically lint the new file even though it's part of the glob. |
What code were you trying to parse?
Vue files (see https://github.com/sem4phor/vue-typescript-eslint-bug)
What did you expect to happen?
Parser lints files specified in tsconfig->include
What actually happened?
I have to add
extraFileExtensions: [".vue"]
in.eslintrc.js
to lint vue files even its declared ininclude
option intsconfig.json
And for all .js files the Parser says:
Reproduction:
git clone git@github.com:sem4phor/vue-typescript-eslint-bug.git
npm run lint
Moreover eslint is not able to parse vue template section of single file components since upgrade of typescript eslint. But i guess thats more a problem of
eslint-plugin-vue
.Versions
@typescript-eslint/parser
2.0.0
TypeScript
3.4.3
ESLint
5.16.0
node
11.6.0
npm
6.10.2
The text was updated successfully, but these errors were encountered: