Skip to content

Commit 8341e8d

Browse files
committed
Add eslint plugin to lint unused translation keys
1 parent 0df55aa commit 8341e8d

File tree

8 files changed

+640
-140
lines changed

8 files changed

+640
-140
lines changed

app/eslint.config.js renamed to app/eslint.config.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
// eslint.config.js
2+
// @ts-expect-error: @eslint/eslintrc has no types
13
import { FlatCompat } from '@eslint/eslintrc';
24
import js from '@eslint/js';
35
import json from "@eslint/json";
46
import tseslint from "typescript-eslint";
57
import process from 'process';
68

9+
import i18nUsage from './scripts/eslint/i18n-usage';
10+
711
const dirname = process.cwd();
812

913
const compat = new FlatCompat({
@@ -33,7 +37,7 @@ const appConfigs = compat.config({
3337
'@typescript-eslint',
3438
'react-refresh',
3539
'simple-import-sort',
36-
'import-newlines'
40+
'import-newlines',
3741
],
3842
settings: {
3943
'import/parsers': {
@@ -101,7 +105,9 @@ const appConfigs = compat.config({
101105
'react/require-default-props': ['warn', { ignoreFunctionalComponents: true }],
102106
'simple-import-sort/imports': 'warn',
103107
'simple-import-sort/exports': 'warn',
104-
'import-newlines/enforce': ['warn', 1]
108+
'import-newlines/enforce': ['warn', 1],
109+
110+
// 'i18n-usage/ensure-i18n-keys-used': ['warn']
105111
},
106112
overrides: [
107113
{
@@ -128,7 +134,7 @@ const appConfigs = compat.config({
128134
}
129135
}
130136
]
131-
}).map((conf) => ({
137+
}).map((conf: object) => ({
132138
...conf,
133139
files: ['src/**/*.tsx', 'src/**/*.jsx', 'src/**/*.ts', 'src/**/*.js'],
134140
ignores: [
@@ -139,27 +145,43 @@ const appConfigs = compat.config({
139145
],
140146
}));
141147

148+
const tseslintRecommendedRules = tseslint.configs.recommended.map((conf) => ({
149+
...(conf.rules)
150+
}));
151+
142152
const otherConfig = {
143153
files: ['*.js', '*.ts', '*.cjs'],
144154
...js.configs.recommended,
145-
...tseslint.configs.recommended,
155+
...tseslintRecommendedRules,
146156
};
147157

148158
const jsonConfig = {
149159
files: ['**/*.json'],
150160
language: 'json/json',
151161
rules: {
152162
'json/no-duplicate-keys': 'error',
163+
'json/no-empty-keys': 'error',
164+
'i18n-usage/ensure-i18n-keys-used': 'warn',
153165
},
154166
};
155167

168+
// const i18nJsonConfig = {
169+
// files: ['**/i18n.json'],
170+
// language: 'json/json',
171+
// rules: {
172+
// 'i18n-usage/ensure-i18n-keys-used': 'warn',
173+
// },
174+
// };
175+
156176
export default [
157177
{
158178
plugins: {
159179
json,
180+
'i18n-usage': i18nUsage,
160181
},
161182
},
162183
...appConfigs,
163184
otherConfig,
164185
jsonConfig,
186+
// i18nJsonConfig,
165187
];

app/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,22 @@
5959
"sanitize-html": "^2.10.0"
6060
},
6161
"devDependencies": {
62-
"@eslint/eslintrc": "^3.1.0",
62+
"@eslint/eslintrc": "^3.2.0",
6363
"@eslint/js": "^9.20.0",
6464
"@eslint/json": "^0.5.0",
6565
"@julr/vite-plugin-validate-env": "^1.0.1",
6666
"@types/file-saver": "^2.0.5",
6767
"@types/mapbox-gl": "^1.13.0",
68-
"@types/node": "^20.11.6",
68+
"@types/node": "^20.17.19",
6969
"@types/papaparse": "^5.3.8",
7070
"@types/react": "^18.0.28",
7171
"@types/react-dom": "^18.0.11",
7272
"@types/sanitize-html": "^2.9.0",
7373
"@types/yargs": "^17.0.32",
7474
"@typescript-eslint/eslint-plugin": "^8.11.0",
7575
"@typescript-eslint/parser": "^8.11.0",
76+
"@typescript-eslint/typescript-estree": "^8.43.0",
77+
"@typescript-eslint/visitor-keys": "^8.44.0",
7678
"@vitejs/plugin-react-swc": "^3.5.0",
7779
"@vitest/coverage-v8": "^1.2.2",
7880
"autoprefixer": "^10.4.14",
@@ -91,6 +93,7 @@
9193
"eslint-plugin-simple-import-sort": "^12.1.1",
9294
"fast-glob": "^3.3.2",
9395
"happy-dom": "^9.18.3",
96+
"jiti": "^2.5.1",
9497
"openapi-typescript": "6.5.5",
9598
"postcss": "^8.5.3",
9699
"postcss-nested": "^7.0.2",

0 commit comments

Comments
 (0)