#eslint: files outside the src folder

12 messages · Page 1 of 1 (latest)

eager egret
#

I would like to have eslint enforce the rules in files outside of the src folder, eslint is currently complaining about there scripts:

Parsing error: ESLint was configured to run on `<tsconfigRootDir>/scripts/development-loader.js` using `parserOptions.project`: /development/test-backend/tsconfig.json
However, that TSConfig does not include this file.

.eslintrc

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "tsconfig.json",
    "sourceType": "module"
  },
  "plugins": ["@typescript-eslint"],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/strict-type-checked",
    "plugin:@typescript-eslint/stylistic-type-checked",
    "plugin:@typescript-eslint/eslint-recommended",
    "prettier"
  ],
  "rules": {
    "no-console": "error"
  },
  "env": {
    "node": true
  }
}

tsconfig.json

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "compilerOptions": {
    "composite": false,
    "declaration": true,
    "declarationMap": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "incremental": true,
    "inlineSources": false,
    "isolatedModules": true,
    "module": "nodenext",
    "moduleResolution": "nodenext",
    "noEmitOnError": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "outDir": "./dist",
    "preserveWatchOutput": true,
    "removeComments": true,
    "skipDefaultLibCheck": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "strictNullChecks": true,
    "target": "es2022",
    "useUnknownInCatchVariables": true
  },
  "exclude": ["node_modules"],
  "include": ["src"]
}
#

Adding directories to the tsconfig.json include array will resolve that issue, however, on build those files are also compiled to the dist directory (what i don't want)

fresh obsidian
fresh obsidian
eager egret
eager egret
#
Parsing error: ESLint was configured to run on `<tsconfigRootDir>/scripts/development-database.ts` using `parserOptions.project`: /development/test-backend/tsconfig.json
However, that TSConfig does not include this file.
fresh obsidian
#

so to clarify; you have a ts project with a ts src, but with other js/ts files outside of src that aren't part of the build?

eager egret
#

That's correct, they are used for database migrations and other dev scripts

fresh obsidian
#

i think in that case, you would have 2 tsconfigs, one for the build and one for the entire project, and you can use 1 eslintrc over the entire project with the latter config
that might not work with the js files though. i guess you could fix that by providing overrides in the eslintrc

eager egret
#

overrides did the trick with an additional tsconfig file, thanks!

tsconfig.scripts.json

{
  "$schema": "https://json.schemastore.org/tsconfig",
  "extends": "tsconfig.json",
  "include": ["scritps"]
}

.eslintrc

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "tsconfig.json",
    "sourceType": "module"
  },
  "plugins": ["@typescript-eslint"],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/strict-type-checked",
    "plugin:@typescript-eslint/stylistic-type-checked",
    "prettier"
  ],
  "rules": {
    "no-console": "error"
  },
  "env": {
    "node": true
  },
  "overrides": [
    {
      "files": ["scripts/**/*.ts"],
      "parserOptions": { "project": "tsconfig.scripts.json", "sourceType": "module" }
    }
  ]
}
#

!resolved