Skip to content

eslint

Created: 2018-02-23 10:57:34 -0800 Modified: 2018-02-23 11:03:10 -0800

You can disable on the current line with // eslint-disable-line no-use-before-define, but sometimes it’s better to disable it on the next line with // eslint-disable-next-line no-unused-vars, that way you can add in more comments beforehand.

To disable for multiple lines, you can do this

/* eslint-disable quotes */
// "bad" code
/* eslint-enable quotes */

lint-staged is using the wrong config in a monorepo

Section titled lint-staged is using the wrong config in a monorepo

lint-staged usually runs a command like this: eslint --cache --max-warnings=0 /path/to/code/foo.ts

The problem is that it runs that command from the root, so you’ll use the root’s eslintrc.cjs, not the package-specific one. To fix this, follow these instructions. E.g. I just had these files:

// Root-level .lintstagedrc.js
export default {
"**/src/*.{js,ts}": [
"eslint --cache --max-warnings=0",
"prettier --cache --write",
],
}
// Package-specific .lintstagedrc.js
import baseConfig from "../../.lintstagedrc.js"
export default {
...baseConfig,
}

Ignoring warnings on ignored files

Section titled Ignoring warnings on ignored files

Scenario: I had a vitest.config.ts that was producing lint warnings, so I wanted to ignore the file entirely. I tried to add ignorePatterns: ["vitest.config.ts"], to my eslintrc, but then pnpx lint-staged would fail with the following:

/Volumes/inland/code/Abbott/packages/bots/vitest.config.ts
0:0 warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override

The solution I went with was to disable eslint on the offending file. That in itself wouldn’t work without another ignore directive because you’re not supposed to disable eslint for an entire file. 🙃

/* eslint-disable unicorn/no-abusive-eslint-disable */
/* eslint-disable */

Note that you may still get issues when running lint-staged. The best way to fix those is to change the glob that lint-staged uses to only include files in src, e.g. having this in .lintstagedrc.json:

{
"**/src/*.{js,ts}": [
"eslint --cache --max-warnings=0",
"prettier --cache --write"
]
}

There is a --no-warn-ignored option, but it’s only usable with flat config files (reference), and those apparently aren’t ready yet as of Mon 01/29/2024.