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
Change Request: Add an /* eslint-ignore-file */
directive
#18028
Comments
A problem with this is how to find the comment if the file is not parsed.
How would we define the top of a file? For example, can some other comments appear before |
Just sharing crude ideas: In order to skip parsing entirely, it'd need to work with plaintext, perhaps a good solution would be something like:
I'm not exactly sure of how it works with TypeScript ESLint, but I assume that TSC is going to parse the file anyway, but we can skip ESLint's AST at least. :) It can't require it to be the first like as there are |
Could you explain the motivation for this request? Is it to save the time spent by the parser, or to avoid errors with files that cannot be parsed? What is the issue with ignoring those files per |
The immediate motivation for this issue is this bug in a rule that crashes ESLint when the file is processed. A speed boost is a tiny benefit on the side. Functionally, there is no difference to using an Practically, this is already done. Most generated source files start with a /* eslint-ignore */
/* tslint-ignore */
/* istanbul ignore file */ prelude that tries to achieve this. |
It's not unusual for third-party plugins to crash ESLint. If this only happens for a particular file, it's okay to ignore that file until the bug is fixed, for example in
That's a reasonable point, but I see two problems in the suggested solution:
|
I would say it's reasonable to require this comment to appear at the top of the file (see a naive implementation in the above comment). If such a comment appears without any preceding source code, I can't come up with any scenario in which this would result in a false positive. Or perhaps I'm misunderstanding what you mean, are you thinking about embedded JS in a markdown file that would falsely ignore the whole file? I would consider that a rare edge-case that can be handled separately.
I'm not sure what you mean with this comment. On one hand, the performance wouldn't get worse: currently, every file is read+parsed, with such a comment, there's at least the possibility for files to be skipped. If the issue is about reading the file from disk twice (once to scan for the comment, twice to parse the code), I would defer that as an implementation detail that can be considered once a general decision about the feature has been made. 🙂 |
I think your pseudocode would match that commant in any line, not just in the first one? Many formats don't even allow JavaScript style block comments at the top (think of HTML). Nor does JavaScript if there is a hashbang.
Yes, eslint-plugin-markdown for example lets you lint JavaScript code in markdown files.
Files are only read once as long as they are not cached or ignored. In flat config, you can add a global ignore pattern to your config and all files matching that pattern would be skipped - not read. This is much more performant than accessing the contents of every file because you're not sure if it should be ignored or not. There is no mechanism to mark a file or folder as ignored outside the config. We could add one if we really need it, but I think the indication to ignore a file should not be included in the contents of the file itself. |
That might be on me for making that unclear - the
I'm not sure how that plugin handles JS code mixed with markdown (maybe virtual files per JS block, dunno?). The way I imagine how This is just me guessing, but if each JS snippet in a markdown file is treated as a virtual file with its own AST, then the comment would still make sense even in the context of embedded JS in Markdown.
I am again not exactly sure how ESLint implements traverse, read, parse, but an option would be to adjust the parse method from (dummy code:) export declare function parseFile(filePath: string): AST; to something like export function parseFile(filePath: string): AST | null {
const fileContent = readFileContent(filePath);
if (shouldIgnore(fileContent)) return null;
return parseFileImpl(fileContent);
}
declare function parseFileImpl(fileContent: string): AST; In this scenario, the file would be read and a |
That plugin uses a processor to extract blocks of JavaScript code from the markdown files. Each block is linted as a separate source. In order to run the processor, the file must have been read, the config for the file must have been resolved, and the plugin that provides the processor must have been loaded (ESLint does come with any built-in processors).
I imagine you mean traversing the directory structure, as opposed to traversing the AST. This function is where all the files are looked up before the contents are read here. And this function is what triggers the parsing, which is done in a separate package, depending on the parser. If it interests you, you can dig into that code to see how it's implemented. |
Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update. |
ping @eslint/eslint-team |
I think this is an interesting idea that's worth pursuing, but as this conversation shows, there is a fair amount of detail work needed to figure out if this would work for us. So, I think the most logical next step is to ask someone to write up an RFC to explore the details and concerns with this approach. |
Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update. |
@jeengbe are you interested in putting together an RFC for this proposal? |
I will look into it and hand over the task once my limited understanding of ESLint's internals is exhausted 👍🏻 |
Per the discussion on eslint/rfcs#118, we are choosing not to pursue this any further. |
ESLint version
n/a
What problem do you want to solve?
Many libraries that generate code (such as
tsoa
,typescript-swagger-api
,graphql-codegen
, the grpc library, etc.) generate leading/* eslint-disable */
directives at the top of generated files. However, the files are still parsed and validated (see here), which slows down the linting process needlessly because potentially large and complex files are processed.This is not an issue if the file is ignored by e.g.
.eslintignore
.What do you think is the correct solution?
Add an
/* eslint-ignore-file */
(or similar) that gives files the ability to ignore themselves. This is useful for the above mentioned automatically generated source files in whose linting errors the user very seldom has interest.The directive would error if it appeared anywhere other than the top of a file.
Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: