Adding this plugin to existing eslint config as a new configuration object seems to disable other rules #38
Replies: 5 comments 7 replies
-
Other rules should be extended for specific file extension types, as shown here: |
Beta Was this translation helpful? Give feedback.
-
As a temporary workaround, if you don't need folder-structure rules for file extensions not supported by the default parser, such as .json, .svg, etc., you can avoid using the projectStructurePlugin. |
Beta Was this translation helpful? Give feedback.
-
the |
Beta Was this translation helpful? Give feedback.
-
const commonLanguageOptions = {
globals: {
...globals.builtin,
...globals.commonjs,
...globals.node,
...globals.jest,
},
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
allowImportExportEverywhere: true
},
};
const tsLanguageOptions = {
...commonLanguageOptions,
parser: tsParser,
parserOptions: {
...commonLanguageOptions.parserOptions,
tsconfigRootDir: process.cwd(),
project: ['tsconfig.json', 'tsconfig.test.json'],
},
};
...
return [
{
settings: {
jest: {
version: 'latest'
},
'import/resolver': ({
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts', '.d.cts'],
},
typescript: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts', '.d.cts'],
alwaysTryTypes: true,
project: tsLanguageOptions.parserOptions.project,
}
})
}
},
{
files: ['{app,test,src}/**/*.{j,t}s','app.js', 'server.js'],
plugins: {
'@stylistic': stylistic,
import: eslintImportPlugin,
},
languageOptions: tsLanguageOptions,
rules: {
...js.configs.recommended.rules,
...stylistic.configs['disable-legacy'].rules,
...stylistic.configs['recommended-flat'].rules,
...eslintImportPlugin.flatConfigs.recommended.rules,
//overrides
},
ignores: [
'sequelize.config.js',
'{jest,database,config,downloads}/**/*.ts',
]
},
{
files: ['**/*.{js,cjs}', '*.{js,cjs}', 'app.js'],
plugins: {
'@stylistic': stylistic,
import: eslintImportPlugin,
},
languageOptions: {
...commonLanguageOptions,
},
rules: {
...stylistic.configs['disable-legacy'].rules,
...js.configs.recommended.rules,
...eslintImportPlugin.flatConfigs.recommended.rules,
//overrides
}
},
{
files: ['{app,test,src}/**/*.ts'],
ignores: ['eslint.config.{j,t}s'],
plugins: { '@typescript-eslint': ts, '@stylistic': stylistic },
languageOptions: tsLanguageOptions,
rules: {
...ts.configs.recommended.rules,
//overrides
},
},
{
files: ['test/**/*.{js,ts}', '**/*.{test,spec}.{js,ts}'],
plugins: {
'@stylistic': stylistic,
jest,
},
languageOptions: tsLanguageOptions,
rules: {
...jest.configs.recommended.rules,
//overrides
},
},
{
ignores: [
'app/models/index.ts',
'**/*.d.ts',
'node_modules/*',
'dist/*',
'.idea/*',
'.husky/*',
'.prettierrc.js',
]
}
] And config above is spread-joined with the following: {
files: ['**'],
ignores: ['projectStructure.cache.json'],
languageOptions: { parser: projectStructureParser },
plugins: {
'project-structure': projectStructurePlugin,
},
rules: {
'project-structure/folder-structure': [
severity,
structureRules,
],
},
} Still trying to get the |
Beta Was this translation helpful? Give feedback.
-
Hey I put together the repro repo but I couldn't reproduce the issue. So I read more and more files and found that the issue was that the file I was creating intentionally as a check was just not included in tsconfig. This caused the parser related error. So if anyone stumbles about this the solution is to make sure:
Thank you so much for offering your help! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have weird situation and not yet sure why it happens.
My eslint.config.cjs:
The
configure
function returns an array of configurationObjects. some of them target*.js
files and some*.ts
files, and some both. Each config there has its ownlanguageOptions
with own parser. TS files get@typescript-eslint/parser
and other files getThe
create
function returns a single object as below:The result is like eslint only uses this last config to lint the project and ignores the other configs.
If I swap the order in the
eslint.config.cjs
:My other configs are picked up but the structure plugin fails. For test I changed the name of file in controllers directory and I got
Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser.
The file is in TS but so are other files in the same directory.I also tried to create another config, without this plugin but targeting all files with
['**']
and as soon as I add the parser property it starts breaking.I suspect that https://eslint.org/docs/latest/use/configure/configuration-files#cascading-configuration-objects mergers are the cause. But how to resolve this issue?
The eslint --inspect-config shows that the rules that match the bad file both have different parsers, correct ones. Yet it still fails. So I am not sure if I should trust the inspector.
Beta Was this translation helpful? Give feedback.
All reactions