Search code examples
javascripttypescripteslint

ESLint Stylistic is ignoring ts files


I'm using the new ESLint flat style with @stylistic/eslint-plugin but it fails to detect ts files and when I try to run it directly against a ts file it gives me the error:

warning  File ignored because no matching configuration was supplied

Here are my files:

eslint.config.mjs

import stylistic from "@stylistic/eslint-plugin";

export default [
    {
        plugins : {
            "@stylistic" : stylistic,
        },
        rules : {
            "@stylistic/comma-dangle" : ["error", "always-multiline"],
            "@stylistic/eol-last" : ["error", "always"],
            "@stylistic/indent" : [
                "error",
                "tab",
                {
                    "SwitchCase" : 1,
                },
            ],
            "@stylistic/key-spacing" : ["error", { "beforeColon" : true }],
            "@stylistic/linebreak-style" : [
                "error",
                "unix",
            ],
            "@stylistic/quotes" : [
                "error",
                "double",
                {
                    "allowTemplateLiterals" : true,
                    "avoidEscape" : true,
                },
            ],
            "@stylistic/semi" : [
                "error",
                "always",
            ],
            "@stylistic/type-annotation-spacing" : [
                "error",
                {
                    "before" : true,
                },
            ],
        },
    },
];

tsconfig.json

{
    "compilerOptions": {
      "target": "es2016",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
      "module": "commonjs",                                /* Specify what module code is generated. */
      "noEmit": true,                                   /* Disable emitting files from a compilation. */
      "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
      "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */
      "strict": true,                                      /* Enable all strict type-checking options. */
      "skipLibCheck": true                                 /* Skip type checking all .d.ts files. */
    },
    "exclude": [
      "node_modules"
    ]
  }

dependencies

  "devDependencies": {
    "@eslint/js": "^9.8.0",
    "@stylistic/eslint-plugin": "^2.6.0",
    "appium": "^2.11.2",
    "eslint": "^9.8.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.5.4",
    "typescript-eslint": "^8.0.0",
    "webdriverio": "^8.39.1"
  }

Solution

  • By default, ESLint includes all files with the extensions .js, .cjs and .mjs. If you want to lint files with other extensions, such as .ts, you need to specify them via files. Source: ESLint config docs. Updated config:

    import stylistic from "@stylistic/eslint-plugin";
    
    export default [
        {
            plugins: {
                "@stylistic" : stylistic,
            },
            files: ["**/*.ts"],
            rules: {
                // your rules
            },
        },
    ]