I'm using ESLint with typescript and wrote the eslint.config.mjs as below.
import importPlugin from "eslint-plugin-import";
import js from "@eslint/js";
import ts from 'typescript-eslint';
export default ts.config({
files: ["src/**/*.ts"],
extends: [
js.configs.recommended,
...ts.configs.recommended,
importPlugin.flatConfigs.recommended,
importPlugin.flatConfigs.typescript,
],
languageOptions: {
ecmaVersion: 5,
sourceType: "script",
parserOptions: {
tsconfigRootDir: ".",
project: ["./tsconfig.json"],
},
},
rules: {/* omitted here because it's so long */}
});
Running eslint . with this configuration results in the following error:
<PROJECT-ROOT>/built/index.js
<row>:<col> error Definition for rule '@typescript-eslint/no-unnecessary-condition' was not found @typescript-eslint/no-unnecessary-condition
<row>:<col> warning Unused eslint-disable directive (no problems were reported from 'no-constant-condition')
(and non-problematic warnings for src/**/*.ts)
The problem is it's linting ./built/index.js that's not included in files field in the configuration.
It's value is ["src/**/*.ts"] and should be meaning ESLint should scan only .ts files in src folder.
Error message itself is quite understandable because ESLint is scanning .js file and @typescript-eslint/no-unnecessary-condition is not for this.
Additional info: this project has some .js or .mjs files outside ./src or ./built, and they do not seem to be scanned.
Additional info 2: adding ignores: ["built/"] did not work. "built/*", "built/**/*", "built/index.js" resulted in the same.
From https://eslint.org/docs/latest/use/configure/configuration-files#specifying-files-and-ignores:
You can use a combination of
filesandignoresto determine which files the configuration object should apply to and which not. By default, ESLint lints files that match the patterns**/*.js,**/*.cjs, and**/*.mjs. Those files are always matched unless you explicitly exclude them using global ignores.
export default ts.config(
{
ignores: ["**/*.js"]
}
{
files: ["src/**/*.ts"],
// ...
}
);