Skip to content

Commit a393bd8

Browse files
author
Hecht,Matthias (IT EDP) BIG-DE-B
committed
refactor(lint): eat our own dogfood ;)
1 parent 7daccf3 commit a393bd8

8 files changed

Lines changed: 35 additions & 17 deletions

File tree

eslint.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import eslint from '@eslint/js';
2-
import perfectionist from 'eslint-plugin-perfectionist';
31
import { defineConfig } from 'eslint/config';
42
import globals from 'globals';
3+
import strict from './src/configs/strict.js';
54

6-
export default defineConfig(eslint.configs.recommended, perfectionist.configs['recommended-natural'], {
5+
export default defineConfig(strict, {
76
languageOptions: {
87
globals: {
98
...globals.node,
109
},
1110
parserOptions: {
1211
projectService: {
13-
allowDefaultProject: ['*.js', '*.ts'],
12+
allowDefaultProject: ['*.*js', '*.*ts'],
1413
},
1514
},
1615
},
@@ -21,6 +20,7 @@ export default defineConfig(eslint.configs.recommended, perfectionist.configs['r
2120
partitionByComment: true,
2221
},
2322
],
23+
'sonarjs/todo-tag': 'warn',
2424
'sort-keys': 'off', // disabled due to conflict with eslint-plugin-perfectionist
2525
},
2626
});

src/configs/base.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as eslint from '@eslint/js';
2-
import { defineConfig } from 'eslint/config';
32
import * as importPlugin from 'eslint-plugin-import';
43
import * as perfectionist from 'eslint-plugin-perfectionist';
54
import * as sonarjs from 'eslint-plugin-sonarjs';
5+
import { defineConfig } from 'eslint/config';
66
import * as tseslint from 'typescript-eslint';
7-
87
import {
98
PERFECTIONIST_SETTINGS,
109
SORT_CLASSES_GROUPS,

src/configs/nextjs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as nextPlugin from '@next/eslint-plugin-next';
22
import { defineConfig } from 'eslint/config';
3-
43
import { NEXTJS_ROUTING_FILES } from '../lib/nextjs.utils.js';
54
import react from './react.js';
65

src/configs/playwright.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { defineConfig } from 'eslint/config';
21
import * as playwright from 'eslint-plugin-playwright';
2+
import { defineConfig } from 'eslint/config';
33

44
const playwrightPlugin = playwright as typeof playwright & {
55
configs: {

src/configs/prettier-disable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { defineConfig } from 'eslint/config';
21
import * as prettier from 'eslint-config-prettier';
2+
import { defineConfig } from 'eslint/config';
33

44
export default defineConfig({
55
...prettier,

src/configs/react.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1-
import { defineConfig } from 'eslint/config';
21
import jsxA11y from 'eslint-plugin-jsx-a11y';
32
import react from 'eslint-plugin-react';
43
import reactHooks from 'eslint-plugin-react-hooks';
54
import reactRefresh from 'eslint-plugin-react-refresh';
5+
import { defineConfig } from 'eslint/config';
66
import globals from 'globals';
7-
87
import { PERFECTIONIST_SETTINGS, SORT_IMPORTS_GROUPS } from '../lib/eslint-plugin-perfectionist.js';
98
import base from './base.js';
109

10+
const reactRecommendedConfig = react.configs.flat.recommended;
11+
12+
if (!reactRecommendedConfig) {
13+
throw new Error(
14+
'Expected to find the "flat/recommended" configuration in the eslint-plugin-react plugin, but it was not found.',
15+
);
16+
}
17+
18+
const reactJsxRuntimeConfig = react.configs.flat['jsx-runtime'];
19+
20+
if (!reactJsxRuntimeConfig) {
21+
throw new Error(
22+
'Expected to find the "flat/jsx-runtime" configuration in the eslint-plugin-react plugin, but it was not found.',
23+
);
24+
}
25+
1126
export default defineConfig(
1227
...base,
1328
jsxA11y.flatConfigs.recommended,
14-
react.configs.flat.recommended!,
15-
react.configs.flat['jsx-runtime']!,
29+
reactRecommendedConfig,
30+
reactJsxRuntimeConfig,
1631
reactRefresh.configs.recommended,
1732
{
1833
languageOptions: {

src/configs/strict.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { defineConfig } from 'eslint/config';
22
import * as tseslint from 'typescript-eslint';
3-
43
import base from './base.js';
54

65
const strictTemplateExpressionsRule = (
76
tseslint.plugin as typeof tseslint.plugin & {
87
rules: Record<string, { meta: { docs: { recommended: { strict: [Record<string, unknown>] } } } }>;
98
}
10-
).rules['restrict-template-expressions']!;
9+
).rules['restrict-template-expressions'];
10+
11+
if (!strictTemplateExpressionsRule) {
12+
throw new Error(
13+
'Expected to find the "restrict-template-expressions" rule in the typescript-eslint plugin, but it was not found.',
14+
);
15+
}
1116

1217
export default defineConfig(...base, tseslint.configs.strictTypeChecked, {
1318
rules: {

src/lib/include-ignore-file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { includeIgnoreFile as includeIgnoreFileAbsolute } from '@eslint/compat';
21
import * as path from 'node:path';
32
import { cwd } from 'node:process';
3+
import { includeIgnoreFile as includeIgnoreFileAbsolute } from '@eslint/compat';
44

55
/**
66
* Reads an ignore file (e.g. `.gitignore`) and returns an object with the ignore patterns.
@@ -10,7 +10,7 @@ import { cwd } from 'node:process';
1010
* @throws {Error} If the provided path is an empty string.
1111
* @returns {import('@eslint/compat').FlatConfig} The result of including the ignore file at the resolved absolute path.
1212
*/
13-
export const includeIgnoreFile = (ignoreFilePath: string = '.gitignore') => {
13+
export const includeIgnoreFile = (ignoreFilePath = '.gitignore') => {
1414
if (typeof ignoreFilePath !== 'string') {
1515
throw new TypeError('Expected a string');
1616
}

0 commit comments

Comments
 (0)