Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 66 additions & 44 deletions src/content/9/en/part9b.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```
Expand Down Expand Up @@ -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"
}
}
```
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down