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

Question: Considering .eslintignore #584

Closed
hepiyellow opened this issue Feb 25, 2019 · 15 comments
Closed

Question: Considering .eslintignore #584

hepiyellow opened this issue Feb 25, 2019 · 15 comments

Comments

@hepiyellow
Copy link

Description

It sems that with this configuration:

"lint-staged": {
   "*.js": ["eslint --fix", "git add"]
}

eslint does NOT consider any .eslintignore, thus I get errors for files which are in folders that have an .eslintignore.

I have corrected this by doing this:

"lint-staged": {
   "*.js,.eslintignore": ["eslint --fix", "git add"]
}

Is this the correct way to configure this?
Should this be a default behaviour?
Maybe worth adding this to the example configs?

Thanks.

Steps to reproduce

Debug Logs

Environment

@hepiyellow hepiyellow changed the title Questions: Considering .eslintignore Question: Considering .eslintignore Feb 25, 2019
@okonet
Copy link
Collaborator

okonet commented Feb 25, 2019

No, it should not affect how eslint works. 🚫💩 Lint-staged only calls eslint with arguments that are staged files so I don’t think this is a valid solution. Are you sure it’s not considering it? If so that must be some isssue with eslint since I’ve been using eslint with ignores like this before.

@okonet okonet closed this as completed May 30, 2019
@okonet
Copy link
Collaborator

okonet commented May 30, 2019

Closing of inactivity

@zoharsanchez
Copy link

zoharsanchez commented Jun 13, 2019

@okonet So strange, I'm also having the same error as @hepiyellow. I run eslint --fix with lint-staged but it completely ignores my .eslintignore. I also tried to the ignore option by passing in the same files/folders from .eslintignore, but that didn't work.

Is there a way to pass the .eslintignore file? Thanks!

@okonet
Copy link
Collaborator

okonet commented Jun 13, 2019

That's weird indeed. I never had such issues with it before. If that's an issue with lint-staged, when we'd need a reproducible case.

@zoharsanchez
Copy link

@okonet Of course! Hopefully it's just something in my configuration.

Let me give some background:

Description

When running husky with lint-staged, my .eslintignore file is omitted. The files and folders to be ignored instead show up.
I've temporarily removed lint-staged to keep on coding. :)

Steps to reproduce

This is my configuration:

"lint-staged": {
		"linters": {
			"*.js": [
				"eslint --fix", // Also tried npm run lint:fix
				"prettier --write",
				"git add"
			]
		}
	}

I tried this as well:

"lint-staged": {
		"linters": {
			"src/**/*.js": [
				"eslint --fix",
				"prettier --write",
				"git add"
			],
			"ignore": ["**/src/config/*", "**/src/crons/*", "**/src/db-postgres/**/*.js", "**/src/db-postgres/**/*.js", "**/src/middleware/*", "**/src/public/*", "**/src/routes/*", "**/src/services/*", "**/src/tests/**/*.js", "**/src/index.js"]
		}
	}

Folder structure

root
|-- src
|-- package.json
|-- .eslintignore

Debug Logs

Environment

Node v10.13.0
NPM v6.9.0

Thanks for your help! 😄

@okonet
Copy link
Collaborator

okonet commented Jul 1, 2019

Please investigate the root cause of this and submit a fix.

@iamchathu
Copy link

I also have this is issue. I have added *d.ts files to ignore and it works well with my eslint but fails with lint-staged

@iiroj
Copy link
Member

iiroj commented Feb 5, 2020

Please post debug logs, otherwise there is nothing we can do to debug this issue.

@roelkok
Copy link

roelkok commented Feb 11, 2020

I have the same problem. Even if I explictly pass --ignore-path it won't work. When running eslint with execa it can't see the .eslintignore file. It seems to have to do with that my project path contains a space. But didn't have the time to verify that.

I defined the ignore patterns in package.json instead.

"eslintIgnore": [
  "path1",
  "path2"
]

@kunalnagar
Copy link

kunalnagar commented Dec 10, 2020

@okonet I'm having a similar issue: I have an .eslintignore file.

  1. If I run eslint on it's own with --max-warnings 0, it respects the .eslintignore and I get no warnings

  2. However, if I run the same command in lint-staged, it does not take into account the .eslintignore and throws the warnings

Here's the command I'm running:

eslint --fix src/ --ext .ts --max-warnings 0

Here it is in lint-staged:

"lint-staged": {
    "*.md": [
      "prettier --parser markdown --write"
    ],
    "package.json": [
      "sort-package-json"
    ],
    "src/**/*.ts": [
      "prettier --write src/**/*.ts",
      "eslint --fix src/ --ext .ts --max-warnings 0"
    ]
  },

Here is the warning log when run from lint-staged:

/Users/kunalnagar/code/src/DefaultModel.ts
  0:0  warning  File ignored because of a matching ignore pattern. Use "--no-ignore" to override

/Users/kunalnagar/code/src/index.ts
  0:0  warning  File ignored because of a matching ignore pattern. Use "--no-ignore" to override

@1o1w1
Copy link

1o1w1 commented Jan 12, 2021

same error +1

@kunalnagar
Copy link

@1o1w1 - I solved it by adding a .lintstagedrc.js file: https://github.com/okonet/lint-staged#eslint--7

@jrozbicki
Copy link

For those traveling through the issues in future (like me for last couple hours):

@kunalnagar answer above was very helpful, but I had to adjust it to consider 2 .eslintrc configs I had (root and for cypress):

const { ESLint } = require('eslint')
const filterAsync = require('node-filter-async').default

// All of this below is caused by eslint dropping warnings (File ignored because of a matching ignore pattern.) on ignored files
// solution taken from: https://github.com/okonet/lint-staged#eslint--7

// two eslint initializations because we have two .eslintrc, one in root, another one in cypress/.eslintrc
const rootEslintCli = new ESLint()
const cypressEslintCli = new ESLint({ overrideConfigFile: './cypress/.eslintrc'})

const removeIgnoredFiles = async (files, eslintCli) => {
  const filteredFiles = await filterAsync(files, async (file) => {
    const isIgnored = await eslintCli.isPathIgnored(file)
    return !isIgnored
  })
  return filteredFiles.join(' ')
}

module.exports = {
  'src/**/*.{ts,tsx,js,jsx}': async (files) => {
    const filesToLint = await removeIgnoredFiles(files, rootEslintCli)
    return ['tsc', `eslint --fix --max-warnings=0 ${filesToLint}`]
  },
  'cypress/**/*.{ts,tsx,js,jsx}': async (files) => {
    const filesToLint = await removeIgnoredFiles(files, cypressEslintCli)
    return ['tsc --project cypress', `eslint --config cypress/.eslintrc --fix --max-warnings=0 ${filesToLint}`]
  },
}

@skarab42
Copy link

skarab42 commented Jan 9, 2024

Hi everyone,

To address this, I've published a tool called @skarab/eslint-staged.

This CLI tool enhances lint-staged by ensuring it respects the ignored files, avoiding the common issue where ignored files still get processed.

It's straightforward to use, first install:

pnpm add @skarab/eslint-staged --save-dev

And add the following to your lint-staged config:

{
  "*": [
    "pnpm eslint-staged --fix --max-warnings=0",
    "pnpm prettier --write --ignore-unknown"
  ]
}

I believe this could be a helpful solution for those experiencing similar issues. The package is open for contributions, and I'd love to hear your feedback!

You can find it here: https://github.com/skarab42/eslint-staged

Happy coding!

@iiroj
Copy link
Member

iiroj commented Jan 9, 2024

ESLint now has a command line flag --no-warn-ignored that makes it not care about ignored files:

Suppress warnings when the file list includes ignored files. Flat Config Mode Only

https://eslint.org/docs/latest/use/command-line-interface

This also documented in our readme: https://github.com/lint-staged/lint-staged#how-can-i-ignore-files-from-eslintignore

@lint-staged lint-staged locked as resolved and limited conversation to collaborators Jan 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

10 participants