question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Respect .gitignore files by default?

See original GitHub issue

Current situation

ESLint has several features around ignoring things, e.g.:

  • .eslintignore
  • some built-in rules like ignoring node_modules automatically (this changes over time, see e.g. 7.0.0 release notes)
  • ignorePatterns in config files
  • --ignore-path

Still, it’s currently quite hard to configure ignore rules correctly in a larger repo, without the setup being sort of duplicate/fragile. For example, in our monorepo, we have several subfolders, each with its own .gitignore file, and to replicate the correct ignoring behavior means duplicating ignore paths in the root .eslintignore file.

Previous discussions about .gitignore support

There have been issues around .gitignore support in the past, e.g.:

  • Use .gitignore by default if no .eslintignore is found #5848
  • Fallback to using .gitignore when .eslintignore doesn’t exist #12199

Some arguments against it were that ESLint should have its own mechanism independent on other systems, that it would add magic behavior, that it’s a breaking change or that you can usually find some workaround like building config.ignorePatterns in code.

I sort of agree with all of that, or at least see the point, but as a regular user of ripgrep or fd I have to say that I see no practical downside of respecting .gitignore by default – in fact, it’s a beautiful usability feature.

Worth an RFC?

I realize these things should go through the RFC process and I’m willing to do it but first I wanted to discuss this in an issue (that is not locked; otherwise, this is quite relevant: #12199).

What do you think about this? Am I missing some major downsides?

The biggest counter-argument, IMO, is that some files that were linted before would not be linted after this. To that, I’d say:

  1. I’m not sure how common is linting e.g. dist/**.js files. My guess would be that it’s very rare but I acknowledge that it can happen.
  2. These kinds of breaking changes are already happening, for example, with v6, someone could be linting subdir/node_modules which stopped working in v7.

It’s also possible to add this to ESLint in a non-breaking way, behind some new flag like --ignore-strategy=gitignore (this is different from --ignore-path, even if it supported multiple paths – #9794).

I generally think that the new behavior would be useful for most projects using ESLint (like the vast majority; “99%”) without many downsides. What do you think?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
mysticateacommented, Jun 11, 2020

For a workaround for right now, I have released eslint-gitignore package as we can convert .gitignore files to our ignorePatterns option.

For example:

// .eslintrc.js
const { readGitignoreFiles } = require("eslint-gitignore")

module.exports = {
  // Your config.

  ignorePatterns: readGitignoreFiles({ cwd: __dirname })
};

My thoughts:

  • It’s worth that we consider this feature because we have heard this request frequently.
  • We can implement it by a utility package like eslint-gitignore in userland, but if ESLint reads it while traversing directories, it will improve performance. Because .gitignore files can be in subdirectories.
  • Fallback to .gitignore is nice, but:
    • we should be able to override it by our config files (.eslintignore / .eslintrc.* / eslint.config.js). For example, I have often /test.* in .gitignore to play something, but I want to lint it.
    • we should support .eslintignore in subdirectories to be consistent. So both .gitignore and .eslintignore should behave samely.
    • Should we support other patterns of .gitignore? For example, $GIT_DIR/info/exclude, core.excludesFile setting of git, and ~/.gitignore? It will bring complex…
  • I’m not a fan of new options for this because we have a lot of options.
1reaction
borekbcommented, Jun 10, 2020

already doable using a CLI flag

I don’t know how (--ignore-path cannot replicate the proposed behavior).

it’s a breaking change

I think it would be worth it but you’re right. Do you think it would be better to propose the behavior behind a new CLI flag to make it backwards compatible?

Read more comments on GitHub >

github_iconTop Results From Across the Web

gitignore is ignored by Git
My .gitignore file seems to be being ignored by Git - could the .gitignore file be corrupt? Which file format, locale or culture...
Read more >
gitignore file - ignoring files in Git
Git ignore patterns are used to exclude certain files in your working directory from your Git history. They can be local, global, or...
Read more >
How can I ignore a file that has already been committed to ...
Make sure your .gitignore file is up-to-date and contains all the correct patterns you want to ignore. Commit or stash any outstanding local...
Read more >
Files added to .gitignore are still shown in commit changes
So I created a .gitignore file in the project root directory to ignore some files when I'm committing changes. But the problem is...
Read more >
My .gitignore file is ignored by git and it does not work
Some times, even if you haven't added some files to the repository, git seems to monitor them even after you add them to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found