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

IDE Parsing error when using overlapping globs #1394

Closed
kalbert312 opened this issue Dec 31, 2019 · 10 comments · Fixed by #1412
Closed

IDE Parsing error when using overlapping globs #1394

kalbert312 opened this issue Dec 31, 2019 · 10 comments · Fixed by #1412
Assignees
Labels
bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree

Comments

@kalbert312
Copy link

kalbert312 commented Dec 31, 2019

What code were you trying to parse?
New files added to the project

What did you expect to happen?
ESLint works

What actually happened?

Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: src/ui/components/core/DragHandle/DragHandle.tsx.
The file must be included in at least one of the projects provided.

Versions

package version
@typescript-eslint/parser 2.10.0
TypeScript 3.7.4
ESLint 6.7.2
node 12.8.0
npm 6.13.4

.eslintrc.js

module.exports = {
	plugins: ["import"],
	extends: ["react-app", "plugin:import/errors", "plugin:import/warnings", "plugin:import/typescript", "prettier"],
	parserOptions: {
		project: "./tsconfig.eslint.json",
	},
	rules: {
		"import/default": "off", // not working with TS right now for export = (https://github.com/benmosher/eslint-plugin-import/issues/1527)
		"import/named": "off", // not needed with TS.
		"import/namespace": "off", // not needed with TS.
		"import/no-cycle": "off", // takes long, using madge for this
		"import/no-internal-modules": "off",
		"import/order": [
			"error",
			{
				"newlines-between": "always",
			},
		],
		"no-shadow": ["error"],
		"prefer-const": [
			"warn",
			{
				destructuring: "all",
			},
		],
		"require-await": "off",
	},
	overrides: [
		{
			files: ["**/*.ts?(x)"],
			rules: {
				"@typescript-eslint/ban-ts-ignore": "warn",
				"@typescript-eslint/explicit-function-return-type": "off",
				"@typescript-eslint/interface-name-prefix": [
					"warn",
					{
						prefixWithI: "always",
						allowUnderscorePrefix: false,
					},
				],
				"@typescript-eslint/no-inferrable-types": "off",
				"@typescript-eslint/require-await": "warn",
			},
		},
	],
	settings: {
		"import/extesions": [".js", ".ts", ".tsx"],
		"import/parsers": {
			"@typescript-eslint/parser": [".ts", ".tsx"],
		},
	},

tsconfig.eslint.json

{
	"extends": "./tsconfig",
	"include": ["./**/*", "./.storybook/**/*"],
	"exclude": ["assets", "build", "build-resources", "node_modules", "tmp"]
}

tsconfig.json

{
	"compilerOptions": {
		"target": "es6",
		"lib": ["dom", "dom.iterable", "esnext"],
		"allowJs": false,
		"skipLibCheck": true,
		"esModuleInterop": true,
		"allowSyntheticDefaultImports": true,
		"strict": true,
		"forceConsistentCasingInFileNames": true,
		"module": "esnext",
		"moduleResolution": "node",
		"resolveJsonModule": true,
		"isolatedModules": true,
		"noEmit": true,
		"jsx": "preserve",
		"downlevelIteration": true,
		"sourceMap": true
	},
	"include": ["src"],
	"exclude": ["src/electron"]
}

.env (for create-react-app)

EXTEND_ESLINT=true

The only fix this to restart the ESLint process in IntelliJ. Once it's restarted, eslint works just fine on all files in src no matter how deeply nested. As soon as I create a new file it comes back.
Looks related to #1303 (comment)

@kalbert312 kalbert312 added package: parser Issues related to @typescript-eslint/parser triage Waiting for maintainers to take a look labels Dec 31, 2019
@kalbert312 kalbert312 changed the title Parsing error: "parserOptions.project" has ben set for @typescript/eslint-parser Parsing error: "parserOptions.project" has been set for @typescript/eslint-parser Dec 31, 2019
@armano2
Copy link
Member

armano2 commented Dec 31, 2019

can you tell me what version of IntelliJ you using?

this seems similar to https://youtrack.jetbrains.com/issue/WEB-41250 but i don't see any active tickets on their side for this: https://youtrack.jetbrains.com/issues?q=parserOptions.project%20@typescript-eslint%2Fparser

i'm using similar setup in both webstorm and intelij and i don't have this issue (its possible that there was fix for that in newer version of plugin)

image

@kalbert312
Copy link
Author

IntelliJ IDEA 2019.3.1 (Ultimate Edition)
Build #IU-193.5662.53, built on December 18, 2019
Runtime version: 11.0.5+10-b520.17 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.2
GC: ParNew, ConcurrentMarkSweep
Memory: 4012M
Cores: 12
Registry: suppress.focus.stealing.active.window.checks=true, suppress.focus.stealing.disable.auto.request.focus=true, ide.mac.file.chooser.native=false, ide.balloon.shadow.size=0
Non-Bundled Plugins: com.intellij.plugins.watcher, Karma, Lombook Plugin, PlantUML integration, Pythonid, com.almightyalpaca.intellij.plugins.discord, com.deadlock.scsyntax, com.dmarcotte.handlebars, com.github.shiraji.emoji, com.intellij.kubernetes, com.intellij.lang.jsgraphql, com.intellij.plugin.applescript, com.jetbrains.FocusTuner, com.jetbrains.plugins.ini4idea, com.paperetto.dash, com.vecheslav.darculaDarkerTheme, intellij.prettierJS, io.plugin.tsnode, org.intellij.plugins.postcss, org.jetbrains.kotlin, org.jetbrains.plugins.ruby, ru.adelf.idea.dotenv, training

@armano2 armano2 added awaiting response Issues waiting for a reply from the OP or another party and removed triage Waiting for maintainers to take a look package: parser Issues related to @typescript-eslint/parser labels Dec 31, 2019
@armano2 armano2 self-assigned this Dec 31, 2019
@armano2
Copy link
Member

armano2 commented Dec 31, 2019

@kalbert312 to fix this issue you have to fix your tsconfig,

include is a glob path not directory

tsconfig.json

-   "include": ["src"],
+   "include": ["./src/*"],

@kalbert312
Copy link
Author

That seems to have worked. Thanks.

@armano2 armano2 closed this as completed Dec 31, 2019
@bradzacher
Copy link
Member

this should work in both cases - typescript determines the passed path is a directory, and treats it the same as src/**/*

If this is not working correctly, then it's probably a bug in our invalidation logic.

I've got microsoft/TypeScript#35676 open to work with the MSFT team on a better way of doing the parsing logic

@armano2
Copy link
Member

armano2 commented Dec 31, 2019

issue seems to be present only if extends is present and when its trying to merge glob patterns and non glob one

"include": ["src"], + "include": ["./**/*", "./.storybook/**/*"],

This seems to not work well in IntelliJ, but it works when running from console.

@bradzacher
Copy link
Member

It'll always work from the console. This error will only be triggered from the IDE because the IDE is persistent, so it uses the program invalidation logic. There's the function maybeInvalidateProgram which handles that logic.

When a new file is created, it doesn't exist in the program, so we have to detect this case and trigger typescript to recreate the program (same as when a file is deleted or moved/renamed).

This was introduced in 2.0, because 2.0 had a breaking change in which we started throwing errors instead of creating a "catch-all" program when we encountered a file that wasn't within the tsconfigs given to us. We did this because this "catch-all" program path was slow (because it has to reparse a file's entire dependency tree), and there was no warnings when it was used; so it caused perf issues for many users.

I need to add some parserOptions to make it easier for people to debug from the IDE, as right now it relies on environment variables to turn on the debug logs (DEBUG=typescript-eslint:* yarn lint).

I'll reopen this to keep track of this bug then.

@bradzacher bradzacher reopened this Dec 31, 2019
@bradzacher bradzacher added bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree and removed awaiting response Issues waiting for a reply from the OP or another party labels Dec 31, 2019
@bradzacher bradzacher changed the title Parsing error: "parserOptions.project" has been set for @typescript/eslint-parser IDE Parsing error when using overlapping globs Dec 31, 2019
@kalbert312
Copy link
Author

kalbert312 commented Jan 1, 2020

Well it seemed to initially work but I'm still getting this same error on new files with new glob. For the record, I do have IntelliJ configured to recognize tsconfig.*.json as TSConfigs so it will respect them. By default I think it only looks for tsconfig.json (based on file types settings).
Screen Shot 2020-01-01 at 12 32 17 PM

@robbiespeed
Copy link

This also happens if "include" is left undefined, then all new files get this error until eslint is restarted

@armano2
Copy link
Member

armano2 commented Jan 7, 2020

This issue is weird:

https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/typescript-estree/src/create-program/createWatchProgram.ts#L393-L405

while (current !== next) {
    current = next;
    const folderWatchCallbacks = folderWatchCallbackTrackingMap.get(current);
    if (folderWatchCallbacks) {
      folderWatchCallbacks.forEach(cb =>
        cb(currentDir, ts.FileWatcherEventKind.Changed),
      );
      hasCallback = true;
      break;
    }

    next = canonicalDirname(current);
  }

cb is called correctly one for correct path


https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/typescript-estree/src/create-program/createWatchProgram.ts#L419-L423

  // force the immediate resync
  updatedProgram = existingWatch.getProgram().getProgram();
  sourceFile = updatedProgram.getSourceFile(filePath);
  if (sourceFile) {
    return updatedProgram;
  }

updatedProgram is present and sourceFile is falsly (it should find it)


edit:

This issue is present not only in Intellij products (can be reproduced in vscode)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: typescript-estree Issues related to @typescript-eslint/typescript-estree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants