How does one go about configuring ESLint using the new Flat-Config system (aka eslint.config.js file) such that it works with the @TypeScript-ESLint/ESLint-plugin & TypeScript parser?
—
ESLint's new configuration system, "Flat Config" allows for multiple rule-sets in a single configuration file. This makes overriding rules much easier than using the cascading file-system concept that ESLint implements in its original configuration system. Because I have to add support for both ESM & CJS when I publish a package to NPM, the Flat-config is like a dream come true, as it will allow me to use ESLint in a far more simple manner.
The only problem is I cannot get ESLint's new configuration system to work with any plug-ins, and on the opposite side of the coin, I cannot get plugins to work with flat-config.
When Linting TypeScript using ESLint, its pretty important to equip the 2 plug-ins I listed below. Those two plug-ins implement rules that allows typescript to be able to lint TypeScript code bases correctly. Its imperative that I have them.
- ...the TypeScript-ESLint Parser @typescript-eslint/parser
- & the TypeScript-ESLint Plugin @typescript-eslint/eslint-plugin
2BH I am all over the place with my configuration file, currently it looks like the example bellow, but the example just shows my latest desperate attempt, I have tried all sorts of things.
import eslintPlugin from '@typescript-eslint/eslint-plugin'
export default [
{
files: ["src/**/*.ts", "src/main.cts", "src/main.mts"],
ignores: ["**/*.d.*", "**/*.map.*", "**/*.js", "**/*.mjs", "**/*.cjs"],
plugins: { eslintPlugin },
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
parser: "eslintPlugin/parser",
},
rules: {
semi: "error",
quotes: ["error", "single"],
indent: [
"error",
2,
{
SwitchCase: 1,
VariableDeclarator: "first",
ImportDeclaration: "first",
ArrayExpression: "first",
ObjectExpression: "first",
CallExpression: { arguments: "first" },
FunctionDeclaration: { body: 1, parameters: 4 },
FunctionExpression: { body: 1, parameters: 4 },
},
],
},
},
];
I also use the TypeScript plugin TypeScript ESLint Language Service plug-in. I don't like when TypeScript & ESLint report the same errors, so I don't use any extension for ESLint, but I do integrate a build system that lints my project as work on, and the errors found by ESLint are reported through the TSC compiler.
The problem is the same though, I cannot get the "TypeScript/ESLint language service" plug-in to work with the new ESLint Configuration System (aka flat-config).
If anyone knows how to configure eslint using the eslint.config.js flat config file so that it works with the typescript/eslint plug-ins (plug-ins for eslint) &/or the "TS Language Service" plugin (plugin for typescript) I would like if you could show me what that configuration looks like.
Im using flat config with typescript. Heres what I think are the important parts of the config:
Take note that the ts plugin is there twice. The shared configs use the longer namespace than what I wanted to use.