diff --git a/src/content/9/en/part9b.md b/src/content/9/en/part9b.md index ad95b4e357c..b3f226ea941 100644 --- a/src/content/9/en/part9b.md +++ b/src/content/9/en/part9b.md @@ -622,7 +622,8 @@ Let's specify the following configuration in our *tsconfig.json* file: "noFallthroughCasesInSwitch": true, "noImplicitAny": true, // highlight-line "esModuleInterop": true, - "moduleResolution": "node" + "module": "node16", + "moduleResolution": "node16" } } ``` @@ -733,7 +734,8 @@ This is because we banned unused parameters in our *tsconfig.json*: "noFallthroughCasesInSwitch": true, "noImplicitAny": true, "esModuleInterop": true, - "moduleResolution": "node" + "module": "node16", + "moduleResolution": "node16" } } ``` @@ -907,22 +909,32 @@ We will configure ESlint to [disallow explicit any](https://github.com/typescrip import eslint from '@eslint/js'; import tseslint from 'typescript-eslint'; -export default tseslint.config({ - files: ['**/*.ts'], - extends: [ - eslint.configs.recommended, - ...tseslint.configs.recommendedTypeChecked, - ], - languageOptions: { - parserOptions: { - project: true, - tsconfigRootDir: import.meta.dirname, - }, +export default [ + { + ignores: ["dist/**", "build/**", "eslint.config.*", "**/*.js", "**/*.mjs"], }, - rules: { - '@typescript-eslint/no-explicit-any': 'error', + { + files: ["**/*.ts"], }, -}); + + // Base ESLint recommended rules + eslint.configs.recommended, + + // TypeScript ESLint rules (type-aware) + ...tseslint.configs.recommendedTypeChecked, + + { + languageOptions: { + parserOptions: { + project: true, // looks for tsconfig.json automatically + tsconfigRootDir: import.meta.dirname, + }, + }, + rules: { + "@typescript-eslint/no-explicit-any": "error", + }, + }, +]; ``` Let us also set up a *lint* npm script to inspect the files by modifying the *package.json* file: @@ -955,39 +967,49 @@ npm install --save-dev @stylistic/eslint-plugin Our final *eslint.config.mjs* looks as follows: ```js -import eslint from '@eslint/js'; -import tseslint from 'typescript-eslint'; +import eslint from "@eslint/js"; +import tseslint from "typescript-eslint"; import stylistic from "@stylistic/eslint-plugin"; -export default tseslint.config({ - files: ['**/*.ts'], - extends: [ - eslint.configs.recommended, - ...tseslint.configs.recommendedTypeChecked, - ], - languageOptions: { - parserOptions: { - project: true, - tsconfigRootDir: import.meta.dirname, - }, +export default [ + { + ignores: ["dist/**", "build/**", "eslint.config.*", "**/*.js", "**/*.mjs"], }, - plugins: { - "@stylistic": stylistic, + { + files: ["**/*.ts"], }, - rules: { - '@stylistic/semi': 'error', - '@typescript-eslint/no-unsafe-assignment': 'error', - '@typescript-eslint/no-explicit-any': 'error', - '@typescript-eslint/explicit-function-return-type': 'off', - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/restrict-template-expressions': 'off', - '@typescript-eslint/restrict-plus-operands': 'off', - '@typescript-eslint/no-unused-vars': [ - 'error', - { 'argsIgnorePattern': '^_' } - ], + + // Base ESLint recommended rules + eslint.configs.recommended, + + // TypeScript ESLint rules (type-aware) + ...tseslint.configs.recommendedTypeChecked, + + { + languageOptions: { + parserOptions: { + project: true, // looks for tsconfig.json automatically + tsconfigRootDir: import.meta.dirname, + }, + }, + plugins: { + "@stylistic": stylistic, + }, + rules: { + "@stylistic/semi": "error", + "@typescript-eslint/no-unsafe-assignment": "error", + "@typescript-eslint/no-explicit-any": "error", + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", + "@typescript-eslint/restrict-template-expressions": "off", + "@typescript-eslint/restrict-plus-operands": "off", + "@typescript-eslint/no-unused-vars": [ + "error", + { argsIgnorePattern: "^_" }, + ], + }, }, -}); +]; ``` Quite a few semicolons are missing, but those are easy to add. We also have to solve the ESlint issues concerning the *any* type: