Skip to content

Commit 6dddfa8

Browse files
authored
feat: migrate to ESLint v9 with flat config (#4508)
1 parent e0992fd commit 6dddfa8

File tree

9 files changed

+173
-107
lines changed

9 files changed

+173
-107
lines changed

.eslintignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

.eslintrc.js

Lines changed: 0 additions & 66 deletions
This file was deleted.

eslint.config.mjs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
import { defineConfig } from 'eslint/config';
4+
import js from '@eslint/js';
5+
import tsPlugin from '@typescript-eslint/eslint-plugin';
6+
import tsParser from '@typescript-eslint/parser';
7+
import prettierConfig from 'eslint-config-prettier';
8+
import simpleImportSort from 'eslint-plugin-simple-import-sort';
9+
import globals from 'globals';
10+
11+
// Custom inline plugin for header checking
12+
const headerRule = {
13+
create(context) {
14+
return {
15+
Program(node) {
16+
const comments = context.sourceCode.getAllComments();
17+
const hasHeader = comments[0]?.value.trim() === 'SPDX-License-Identifier: Apache-2.0';
18+
19+
if (!hasHeader) {
20+
context.report({ node, message: 'Missing SPDX license header' });
21+
}
22+
},
23+
};
24+
},
25+
};
26+
27+
export default defineConfig([
28+
// Global ignores
29+
{
30+
ignores: ['**/node_modules/**', '**/dist/**'],
31+
},
32+
33+
// Base recommended configs
34+
js.configs.recommended,
35+
36+
// Main configuration for all JS/TS files
37+
{
38+
files: ['**/*.js', '**/*.mjs', '**/*.cjs', '**/*.ts'],
39+
plugins: {
40+
'@typescript-eslint': tsPlugin,
41+
'simple-import-sort': simpleImportSort,
42+
local: {
43+
rules: {
44+
header: headerRule,
45+
},
46+
},
47+
},
48+
languageOptions: {
49+
ecmaVersion: 'latest',
50+
sourceType: 'module',
51+
parser: tsParser,
52+
globals: {
53+
...globals.node,
54+
...globals.es2021,
55+
__ENV: 'readonly',
56+
NodeJS: 'readonly',
57+
},
58+
},
59+
rules: {
60+
// Merge recommended TypeScript rules
61+
...tsPlugin.configs.recommended.rules,
62+
// Merge prettier config rules (disables conflicting rules)
63+
...prettierConfig.rules,
64+
// Custom rules
65+
'@typescript-eslint/ban-ts-comment': 'off',
66+
'@typescript-eslint/no-explicit-any': 'off',
67+
'@typescript-eslint/no-var-requires': 'warn',
68+
'@typescript-eslint/no-unused-vars': 'warn',
69+
'no-trailing-spaces': 'error',
70+
'no-useless-escape': 'warn',
71+
'prefer-const': 'error',
72+
'comma-dangle': [
73+
'error',
74+
{
75+
arrays: 'always-multiline',
76+
objects: 'always-multiline',
77+
imports: 'always-multiline',
78+
exports: 'always-multiline',
79+
functions: 'always-multiline',
80+
},
81+
],
82+
'simple-import-sort/imports': 'error',
83+
'simple-import-sort/exports': 'off',
84+
'local/header': 'error',
85+
},
86+
},
87+
88+
// Config for eslint config files themselves
89+
{
90+
files: ['eslint.config.js', '.eslintrc.{js,cjs}'],
91+
languageOptions: {
92+
sourceType: 'script',
93+
globals: {
94+
...globals.node,
95+
},
96+
},
97+
},
98+
99+
// Test files - relaxed rules
100+
{
101+
files: ['**/*.spec.ts', '**/*.test.ts', '**/tests/**/*.ts'],
102+
languageOptions: {
103+
globals: {
104+
...globals.mocha,
105+
},
106+
},
107+
rules: {
108+
'@typescript-eslint/no-unused-expressions': 'off',
109+
},
110+
},
111+
]);

package-lock.json

Lines changed: 56 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "root",
33
"version": "0.73.0-SNAPSHOT",
44
"devDependencies": {
5+
"@eslint/js": "^9.38.0",
56
"@hashgraph/hedera-local": "^2.39.0",
67
"@open-rpc/schema-utils-js": "^2.1.2",
78
"@types/chai-as-promised": "^8.0.2",
@@ -20,9 +21,9 @@
2021
"chai-exclude": "^2.1.1",
2122
"eslint": "^9.34.0",
2223
"eslint-config-prettier": "^10.1.8",
23-
"eslint-plugin-header": "^3.1.1",
2424
"eslint-plugin-n": "^17.21.3",
2525
"eslint-plugin-simple-import-sort": "^12.1.1",
26+
"globals": "^16.4.0",
2627
"husky": "^9.1.7",
2728
"lint-staged": "^16.1.6",
2829
"mocha": "^11.7.1",

0 commit comments

Comments
 (0)