-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Why is having a tsconfig
file required?
#689
Comments
what command do you run when you run Do you literally just run The reason we require a If you're using a rule that requires type information, typescript has to parse and typecheck every dependency of that file, so it can provide complete types. We can only do a greedy parse if we know what files are in your project. How can we do that? |
I just keep my TypeScript TypeScript and setup my I guess what I'm saying is: I used to be able to lint TypeScript files -- whether they built correctly or not, using
Update: No, I was definitely dealing with rules like promise-function-async and no-floating-promises. |
tsc
works without a tsconfig
file, why is having a tsconfig
file required? Could it be optional with sensible defaults instead?tsc
works without a tsconfig
file, why is having a tsconfig
file required?
When using tslint works in the same way; i.e. when you use The difference between us and tslint, is that tslint controls their entire stack - from cli to parser to rules. We, on the other hand, don't control the eslint stack - just the parser and the rules. Because we don't control the CLI, we can't make the same optimisation that tslint can. ESLint tells us one file at a time which files are going to be linted, but the typescript compiler API requires you to tell it what files to parse up front. You can achieve the same result with this minimal {
"files": [
"<entrypoint>.ts"
]
} |
Hmm, okay, I've confirmed that that works. But doesn't that mean I can't use my It just feels like having the |
if you have a project with only javascript files, and you want to use a rule which requires type information - the process is the same. Though I think you might be able to use a |
Huh, didn't know that was a thing. But furthering my why-is-this-necessary point, I just set my
And now I can open both JavaScript and TypeScript files and the I have achieved my desired functionality by having a Update: Even better, I made my |
tsc
works without a tsconfig
file, why is having a tsconfig
file required?tsconfig
file required?
Why did this get closed? I shouldn't have to set Something about this code is wrong:
|
If the above comments above aren't enough of a reason to explain why.. The typescript compiler api requires us to provide a config file. It takes in a path to a config file, not a config file object, but a path. We can parse without a config, but typescript will parse in isolated modules mode, meaning you don't get much (if any) type information. We also use the project to turn on/off a type check parse. The full project parse can take a lot longer, so some users don't want to use it. The typescript compiler is pretty smart however, it can react to new files. Which is why it will allow files not defined within the config file to be parsed. |
Are those "new" files parsed in isolated modules mode? |
Sorry, I was on mobile before so I missed this bit. This is where you need to be careful with how the project is setup and how eslint works.
ESLint passes a filename to ESLint passes these parser services to the rules in The code for coordinating the typescript compiler API is located here, in
I'll be honest with you, we're at the limit of my knowledge of how I think it might parse the "unknown" files as if they were a new program - which I believe means it invalidates any caching that's been done, meaning it will duplicate work (the side effect of this is that if the dependency graph is big, it will be very, very slow because it duplicates work). If you've got a small project, doing this is fine - there's not enough files for the parse + typecheck to take too long. {
"include": [
"src/**/*"
]
} More info: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html |
I'm okay with specifying
Looks like a feature request for |
This use case is supported - just don't provide a However in isolated modules mode, you cannot use any rules that require type information, because it straight up isn't generated by the typescript API. |
But if I do specify a This is what I want. I just don't want to have to pass in a path to a file that contains an empty object. Something like Basically like what's being suggested here: #101 (comment) but with a default of empty object. |
Well I dug real deep into the source code and then realized what you were pointing at when you linked typescript-eslint/packages/typescript-estree/src/tsconfig-parser.ts Lines 100 to 101 in e0aeb18
So this isn't possible, as is strictly determined by parsing the config file. |
Repro
Any code will do.
Expected Result
Successful linting.
Actual Result
Because I'm not specifying
parserOptions.project
.Additional Info
tsc
falls back on sensible defaults, shouldn't@typescript-eslint/eslint-plugin
do the same?I'd rather not specify a
tsconfig.json
file if I don't have to. It's just another configuration file to keep track of and I've made it this far without needing it.Versions
@typescript-eslint/eslint-plugin
1.11.0
@typescript-eslint/parser
1.11.0
TypeScript
3.5.3
ESLint
6.0.1
node
11.14.0
npm
6.9.0
The text was updated successfully, but these errors were encountered: