eslint
Created: 2018-02-23 10:57:34 -0800 Modified: 2018-02-23 11:03:10 -0800
Disabling for lines (reference)
Section titled Disabling for lines (reference)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
Troubleshooting
Section titled Troubleshootinglint-staged
is using the wrong config in a monorepo
Section titled lint-staged is using the wrong config in a monorepolint-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:
Ignoring warnings on ignored files
Section titled Ignoring warnings on ignored filesScenario: 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:
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. 🙃
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
:
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.