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.

Question: Considering `.eslintignore`

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:11
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

10reactions
kunalnagarcommented, 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
6reactions
jrozbickicommented, Jul 6, 2021

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}`]
  },
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Turning off eslint rule for a specific file - Stack Overflow
1) Disabling "All rules" · You can go with 1.2 and add /* eslint-disable */ on top of the files, one by one....
Read more >
Webstorm doesn't apply ESLint – IDEs Support (IntelliJ Platform)
First of all I've been assuming it would be a problem with ESLint's ... Please look for .eslintignore in your /Users/Mesut/workspace folder.
Read more >
lint-staged - npm
This config will execute your-cmd with the list of currently staged files passed as arguments. So, considering you did git add file1.ext file2....
Read more >
student-question - npm Package Health Analysis - Snyk
Learn more about student-question: package health score, ... project maintenance signal to consider for student-question is that it hasn't ...
Read more >
ESLint - Quasar Framework
.eslintrc.js – ESLint configuration, including rules .eslintignore – what ESLint should ... consider switching to `plugin:vue/strongly-recommended` or ...
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