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

Use .gitignore as default for lint ignores #517

Closed
chrbala opened this issue Feb 26, 2020 · 4 comments
Closed

Use .gitignore as default for lint ignores #517

chrbala opened this issue Feb 26, 2020 · 4 comments
Labels
scope: upstream Issue in upstream dependency

Comments

@chrbala
Copy link

chrbala commented Feb 26, 2020

Current Behavior

Right now if .js/.ts/etc files are generated by tooling, they are included in lint config. This makes it difficult to read the files if editors are configured to show lint errors. It also will mess up the lint command, and do unnecessary work when formatting.

Desired Behavior

.gitignored files should be ignored for linting and formatting. It probably also makes sense to use user-provided files as overrides when present.

Suggested Solution

.gitignore should be used as the default for .eslintignore/.prettierignore. I see little reason to include files that won't ever be checked in.

These can be configured in the underlying tools: eslint and prettier.

People using IDEs would have to update their configuration to reflect this. For example, in VSCode, you'd want to set

{
  "prettier.ignorePath": ".gitignore",
  "eslint.lintTask.options": ". --ignore-path .gitignore"
}

Who does this impact? Who is this for?

This change is for people who generate .js/.ts/etc files with various tooling.

Describe alternatives you've considered

It's also possible to accomplish this by symlinking the .gitignore file to .eslintignore and .prettierignore, but it is not obvious that the files would update together, and overriding the behavior is unclear. I'm also not sure how that would work on Windows.

Additional context

ESLint allows multiple files supplied to the command to ignore them all. Rather than the .gitignore default/override solution I've proposed, it might be nice to have a .gitignore base/augmentation solution where the files in .gitignore are always ignored, and the user provided files add to those. This would require changing prettier and the prettier IDE integrations though, so it would require more work and package maintainer buy-in.

@agilgur5
Copy link
Collaborator

While I think this proposal makes sense for a default case, ESLint decided against making this the default case: eslint/eslint#5848.
As such, changing ESLint's underlying behavior could be quite unexpected.

ESLint allows multiple files supplied to the command to ignore them all.

Did you mean multiple --ignore-paths? I haven't tested it myself, but my interpretation of the API is that you can only pass one in, since it says it will override the default .eslintignore if you do.
If this were to be added to TSDX, it really should use both files, otherwise it'd be very unexpected for .eslintignore to not be used for some reason.

It's also possible to accomplish this by symlinking the .gitignore file to .eslintignore and .prettierignore, but it is not obvious that the files would update together, and overriding the behavior is unclear.

It's listed as a workaround in the ESLint issue. I don't see why this wouldn't work.

Some other things:

  • TSDX is meant to be 0-config (or as little as possible for basic usage), the IDE changes go against this. Would be cool if eslintrc allowed configuring this but it doesn't seem to 😕
    • I also think this would preclude any custom augmentation, due to the various downsides you mentioned. (It's possible for TSDX to make its own IDE plugins, but that typically causes more problems rather than less)
  • gitignore can be nested at any level of the file hierarchy, not just at root.

@chrbala
Copy link
Author

chrbala commented Mar 3, 2020

  1. I actually misinterpreted the ESLint API. It doesn't appear as though it allows multiple ignore files.
  2. It's probably fine to use symlinks, but I'm still not sure how they work on Windows because I don't have any Windows computers. Do you think symlinking is a good enough solution to recommend as a general solution for people who want to keep their .gitignore file in sync with the other ignore files?

@agilgur5
Copy link
Collaborator

agilgur5 commented Mar 4, 2020

but I'm still not sure how they work on Windows because I don't have any Windows computers.

I haven't used one in a while and the last time I did for development I used a VM 😅 So I can't say for sure

Do you think symlinking is a good enough solution to recommend as a general solution for people who want to keep their .gitignore file in sync with the other ignore files?

I mean, I'm not going to go out there and officially recommend it, especially as that's more an upstream issue with ESLint, which, afaik, hasn't given an official workaround.
But yea, there's no reason a symlink wouldn't keep them in sync, it's literally the same file that way.
But it'll still have the issue with nested .gitignores.

The only other option I can think of is using .eslintrc.js, parsing out .gitignore, and adding each entry to ignorePatterns. ¯\_(ツ)_/¯

@kylemh

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: upstream Issue in upstream dependency
Projects
None yet
Development

No branches or pull requests

3 participants