-
Notifications
You must be signed in to change notification settings - Fork 170
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
Don't lint generated code #165
Comments
Is there a way for the linter to know that these are generated files? It seems like it would be best if we didn't do any unnecessary analysis of generated files (including generating errors and warnings). |
Probably not in this case, as it long predates source_gen and such. Is there a way I could tell the linter they're generated. There is a big "DO NOT EDIT. This is generated", etc. at the top. I'd be happy to add something more machine-intelligible. |
No idea of the for of the patter is correct. |
The .analysis_options file is probably the best way. I'd like to avoid having to open and read files in order to determine whether we need to analyze them. Does the analysis options file solve the problem? |
The issue with the .analysis_options is that each user has to do it. As the author of a library that generates code I can't do anything except put it in a README that no one reads. |
Yep. But the problem with using something embedded in the file is that it hurt the analyzer's performance. I don't know that there's a good solution. At least if you could generate all of these files into the same directory that every other generator uses then users would only have to add one "exclude" entry (or we could make it part of the package structure convention). |
I wouldn't mind configuring that in |
Presumably opening a file and then knowing that you can ignore the rest of its contents is actually a performance improvement over reading and analyzing the whole file. |
But not over not reading the file. |
But imposing the burden on the user of maintaining a bunch of entries there. Does analysis options include excluding files for some purposes but not others? In this case users probably don't want to be told about style issues in code they don't control. But they also don't want calls into the generated code to be shown as errors, which I presume is what would happen if the analyzer just ignored those files completely. |
Having done codegen I personally think the library should generate code that passes everything but the flutter rules. Those are just a bit too extreme for my liking. That being said I would be okay if there was a file naming convention for generated files that implied they were generated like |
I also don't know what effect excluding in |
I would also be fine with a file naming convention.
It effectively says "treat this file as if it were not in this directory at all", which means that it will only be analyzed if it is referenced by some other file that is being analyzed, and only to the extent that is necessary to fully analyze the files that are not excluded. It won't generate error or warnings, and it might not do other pieces of analysis that are not required (such as evaluating constant expressions). |
sgtm |
@kevmoo source_gen uses a .g.dart right? |
@donny-dont Yes, but it's not an approved convention. I'd rather we standardize on a code comment at the top of a file to flag this |
Code comment would also be okay with me. Thanks @kevmoo I figured you should probably be around for this conversation. |
Why? It's much faster to look at the name of the file than it is to read the content of the file. |
I also think a file name conversation would be better. It works with all tools not only with the analyzer. |
Did anything happen after this point? |
The build package added support for adding headers to generated code |
That sounds great, do you have any pointers on how to add that? |
Information about that seems sparse |
Exclude doesn't work for me |
Can we get a solution for this, please? It's been 4 and a half years (!). The "exclude" option still doesn't work. My linter settings are pretty strict. I'm getting errors (not even warnings) because of someone else's code generator problems and I can't ignore them. This is very frustrating. Getting this to work would be nice: exclude:
- "**/*.g.dart" |
Try "dart analyze" instead of "dartanalyzer". Worked for me for the same issue (in beta channel, not sure this is available in stable already) |
This worked for me in
full analysis options looks like this: (btw dont judge me for how i placed all the rules)
|
The authors of code generators can now suppress all lint in a generated file with |
I'll go ahead and close this issue with that solution. |
lovely |
I see too many issues with the linter complaining about Intl generated code. The people seeing the problems can't really do anything about it, and in some cases it's a lot of work just to satisfy the linter. For example, it complains about the library names in generated message files, which it wants to follow a convention including their whole directory structure. Since the generator doesn't even know the directory structure this is painful. Fortunately I think I can just remove it entirely, but in general I'd rather these files could be skipped.
The text was updated successfully, but these errors were encountered: