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
Bug: when using flat config, the ignored files are still parsed #17400
Comments
Hi @Comandeer, thanks for the issue! This works as intended.
https://eslint.org/docs/latest/use/configure/configuration-files-new#specifying-files-and-ignores
If you want to ignore import js from '@eslint/js';
export default [
{
files: [
'**/*.js'
],
...js.configs.recommended
},
{
ignores: [
'ignored.js'
]
}
]; |
Hi @mdjermanovic I'm also bump into this. So Doesn't work: const jsConfig = {
files: ['**/*.{js,mjs,cjs}'],
// ignore.js is not ignored as expected
ignores: ['ignore.js']
}
export default [jsConfig] Works: const jsConfig = {
files: ['**/*.{js,mjs,cjs}']
}
export default [
jsConfig,
{
// ignore.js is ignored as expected
ignores: ['ignore.js']
}
] This is a bit confusing, so how can we use this with shared configurations without always explicitly setting Let's say we have a shared configuration with import { jsConfig } from 'npm-package'
export default [
jsConfig,
{
ignores: ['ignore.js']
}
] |
@ivodolenc
Shared configuration could export an array of configuration objects: // npm-package
export const jsConfig = [
{
files: ['**/*.{js,mjs,cjs}'],
rules: {
// ...
}
},
{
ignores: ['ignore.js']
}
]; // eslint.config.js
import { jsConfig } from 'npm-package';
export default [
...jsConfig
]; |
@mdjermanovic tnx for fast reply. Hmm strange, because I have this config: // eslint.config.js
import jsPlugin from '@eslint/js'
const ignores = ['**/examples/**/*']
const jsConfig = {
files: ['**/*.{js,mjs,cjs}'],
ignores: [...ignores, '**/*.{ts,mts,cts,tsx}'],
rules: {
...jsPlugin.configs['recommended'].rules
}
}
export default [jsConfig] According to that configuration, I expect the This config works fine: // eslint.config.js
import jsPlugin from '@eslint/js'
const ignores = ['**/examples/**/*']
const jsConfig = {
files: ['**/*.{js,mjs,cjs}'],
rules: {
...jsPlugin.configs['recommended'].rules
}
}
export default [
jsConfig,
{
ignores: [...ignores, '**/*.{ts,mts,cts,tsx}']
}
]
Yep, I figured that as soon as I posted it 😀 So configuration within shared packages should be rearranged to follow that form if we use I haven't tried it yet, but I assume that when the configuration is imported from the package, the user can always overwrite the options later? import { jsConfig } from 'npm-package'
export default [
jsConfig,
{
// this will extend ignores from config above, right?
ignores: ['!ignore.js', 'ignore-2.js', ...]
}
] |
Just feedback from a user perspective because it's confusing, maybe because this is a new configuration system we have to get used to. From the user's perspective, the My understanding to current eslint behaviour is that if the |
This is the least intuitive thing you could possibly have done. |
I also encountered this issue. I was following the readme of antfu/eslint-config. // eslint.config.js
import antfu from '@antfu/eslint-config'
export default antfu({
// Enable stylistic formatting rules
// stylistic: true,
// Or customize the stylistic rules
stylistic: {
indent: 2, // 4, or 'tab'
quotes: 'single', // or 'double'
},
// TypeScript and Vue are auto-detected, you can also explicitly enable them:
typescript: true,
vue: true,
// Disable jsonc and yaml support
jsonc: false,
yaml: false,
// `.eslintignore` is no longer supported in Flat config, use `ignores` instead
ignores: [
'./fixtures',
// ...globs
]
}) Somehow the author believed After reading this page, I finally made a workaround by moving This is the insanely intuitive! |
Environment
Node version: v20.5.0
npm version: v9.8.0
Local ESLint version: v8.45.0 (Currently used)
Global ESLint version: Not found
Operating System: darwin 22.5.0
What parser are you using?
Default (Espree)
What did you do?
Configuration
Command for linting:
eslint .
.What did you expect to happen?
As the file is listed in the
ignores
section, I would assume it is completely ignored, including parsing it.What actually happened?
The file was parsed and the error about invalid JS syntax was raised
Link to Minimal Reproducible Example
https://github.com/Comandeer/bugs-reports/tree/eslint-parsing-ignored
Participation
Additional comments
A quick debugging shows that the issue is connected with the
eslint/lib/eslint/flat-eslint.js
Lines 808 to 810 in 10e9cfa
When running the
eslint .
command, the file is matched against several configs, including default ones. They do not contain any rules but contain default settings for the parser – and due to that the condition is almost always false. The config for the ignored file contains an emptyrules
property. That doesn't cause any issues for files containing valid JS syntax (as they are parsed and checked against zero rules) but fails for files with invalid JS syntax.Probably the simplest solution would be to also check if the
config.rules
property has at least one key.The text was updated successfully, but these errors were encountered: