Skip to content

Commit 13e4aa4

Browse files
committed
Translate eslint config for CDS extractor
Translates the eslint config for the CDS extractor to match the requirements of the latest eslint dependency. Migrates to a "flat" config file (aka `eslint.config.mjs`). Updates other sub-project configs to support the modified/translated eslint config for the CDS extractor.
1 parent 4f81d44 commit 13e4aa4

File tree

4 files changed

+200
-118
lines changed

4 files changed

+200
-118
lines changed

extractors/cds/tools/.eslintrc.js

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

extractors/cds/tools/.prettierrc.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ module.exports = {
55
printWidth: 100,
66
tabWidth: 2,
77
endOfLine: 'auto',
8-
arrowParens: 'avoid',
9-
// Explicitly handle trailing whitespace
10-
trailingSpaces: false,
8+
arrowParens: 'avoid'
119
};
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
import { defineConfig, globalIgnores } from "eslint/config";
2+
import { fixupConfigRules, fixupPluginRules } from "@eslint/compat";
3+
import typescriptEslint from "@typescript-eslint/eslint-plugin";
4+
import _import from "eslint-plugin-import";
5+
import prettier from "eslint-plugin-prettier";
6+
import globals from "globals";
7+
import tsParser from "@typescript-eslint/parser";
8+
import path from "node:path";
9+
import { fileURLToPath } from "node:url";
10+
import js from "@eslint/js";
11+
import { FlatCompat } from "@eslint/eslintrc";
12+
import jestPlugin from "eslint-plugin-jest";
13+
14+
const __filename = fileURLToPath(import.meta.url);
15+
const __dirname = path.dirname(__filename);
16+
const compat = new FlatCompat({
17+
baseDirectory: __dirname,
18+
recommendedConfig: js.configs.recommended,
19+
allConfig: js.configs.all
20+
});
21+
22+
export default defineConfig([
23+
globalIgnores(["out/**/*", "**/node_modules", "**/coverage", "**/*.d.ts"]),
24+
{
25+
extends: fixupConfigRules(compat.extends(
26+
"eslint:recommended",
27+
"plugin:@typescript-eslint/recommended",
28+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
29+
"plugin:import/errors",
30+
"plugin:import/warnings",
31+
"plugin:import/typescript",
32+
"plugin:prettier/recommended",
33+
)),
34+
35+
plugins: {
36+
"@typescript-eslint": fixupPluginRules(typescriptEslint),
37+
import: fixupPluginRules(_import),
38+
prettier: fixupPluginRules(prettier),
39+
},
40+
41+
languageOptions: {
42+
globals: {
43+
...globals.node,
44+
},
45+
46+
parser: tsParser,
47+
ecmaVersion: 2018,
48+
sourceType: "module",
49+
50+
parserOptions: {
51+
project: "./tsconfig.json",
52+
tsconfigRootDir: "/Users/data-douser/Git/data-douser/codeql-sap-js/extractors/cds/tools",
53+
createDefaultProgram: true,
54+
},
55+
},
56+
57+
settings: {
58+
"import/resolver": {
59+
typescript: {
60+
alwaysTryTypes: true,
61+
project: "./tsconfig.json",
62+
},
63+
64+
node: {
65+
extensions: [".js", ".jsx", ".ts", ".tsx"],
66+
},
67+
},
68+
},
69+
70+
rules: {
71+
"no-console": "off",
72+
"no-duplicate-imports": "error",
73+
"no-unused-vars": "off",
74+
"no-use-before-define": "off",
75+
"no-trailing-spaces": "error",
76+
"@typescript-eslint/explicit-module-boundary-types": "off",
77+
78+
"@typescript-eslint/no-unused-vars": ["warn", {
79+
argsIgnorePattern: "^_",
80+
varsIgnorePattern: "^_",
81+
}],
82+
83+
"@typescript-eslint/no-use-before-define": ["error", {
84+
functions: false,
85+
classes: true,
86+
}],
87+
88+
"@typescript-eslint/explicit-function-return-type": ["warn", {
89+
allowExpressions: true,
90+
allowTypedFunctionExpressions: true,
91+
}],
92+
93+
"@typescript-eslint/no-explicit-any": "warn",
94+
"@typescript-eslint/ban-ts-comment": "warn",
95+
"@typescript-eslint/prefer-nullish-coalescing": "warn",
96+
"@typescript-eslint/prefer-optional-chain": "warn",
97+
98+
"import/order": ["error", {
99+
groups: ["builtin", "external", "internal", ["parent", "sibling"], "index"],
100+
"newlines-between": "always",
101+
102+
alphabetize: {
103+
order: "asc",
104+
caseInsensitive: true,
105+
},
106+
}],
107+
108+
"import/no-duplicates": "error",
109+
110+
"prettier/prettier": ["error", {
111+
singleQuote: true,
112+
trailingComma: "all",
113+
printWidth: 100,
114+
tabWidth: 2,
115+
}],
116+
},
117+
},
118+
{
119+
files: ["**/*.ts"],
120+
121+
languageOptions: {
122+
ecmaVersion: 5,
123+
sourceType: "script",
124+
125+
parserOptions: {
126+
project: "./tsconfig.json",
127+
tsconfigRootDir: "/Users/data-douser/Git/data-douser/codeql-sap-js/extractors/cds/tools",
128+
},
129+
},
130+
},
131+
{
132+
files: ["**/*.test.ts", "test/**/*.ts", "**/index-files.ts"],
133+
extends: fixupConfigRules(compat.extends("plugin:jest/recommended")),
134+
plugins: {
135+
jest: fixupPluginRules(jestPlugin),
136+
},
137+
languageOptions: {
138+
ecmaVersion: 2018,
139+
sourceType: "module",
140+
141+
parserOptions: {
142+
project: "./tsconfig.json",
143+
tsconfigRootDir: "/Users/data-douser/Git/data-douser/codeql-sap-js/extractors/cds/tools",
144+
},
145+
},
146+
147+
rules: {
148+
"@typescript-eslint/explicit-function-return-type": "off",
149+
"@typescript-eslint/no-unsafe-assignment": "off",
150+
"@typescript-eslint/no-unsafe-call": "off",
151+
"@typescript-eslint/no-unsafe-member-access": "off",
152+
"@typescript-eslint/no-unsafe-return": "off",
153+
"@typescript-eslint/restrict-template-expressions": "off",
154+
"@typescript-eslint/no-unsafe-argument": "off",
155+
"@typescript-eslint/unbound-method": "off"
156+
},
157+
},
158+
// Add JavaScript-specific configuration that doesn't use TypeScript parser
159+
{
160+
files: ["**/*.js", "**/.prettierrc.js", "**/jest.config.js"],
161+
languageOptions: {
162+
// Use default parser for JS files (removes TS parser requirement)
163+
parser: undefined,
164+
ecmaVersion: 2018,
165+
sourceType: "module"
166+
},
167+
rules: {
168+
// Disable TypeScript-specific rules for JS files
169+
"@typescript-eslint/explicit-function-return-type": "off",
170+
"@typescript-eslint/no-unsafe-assignment": "off",
171+
"@typescript-eslint/no-unsafe-call": "off",
172+
"@typescript-eslint/no-unsafe-member-access": "off",
173+
"@typescript-eslint/no-unsafe-return": "off",
174+
"@typescript-eslint/restrict-template-expressions": "off",
175+
"@typescript-eslint/no-unsafe-argument": "off",
176+
"@typescript-eslint/unbound-method": "off"
177+
}
178+
},
179+
{
180+
files: ["test/src/**/*.js"],
181+
extends: fixupConfigRules(compat.extends("plugin:jest/recommended")),
182+
plugins: {
183+
jest: fixupPluginRules(jestPlugin),
184+
},
185+
languageOptions: {
186+
// Use default parser for JS files (removes TS parser requirement)
187+
parser: undefined,
188+
ecmaVersion: 2018,
189+
sourceType: "module"
190+
},
191+
},
192+
]);

extractors/cds/tools/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"build:all": "npm run lint:fix && npm run test:coverage && npm run build",
99
"clean": "rm -rf out coverage",
1010
"prebuild": "npm run clean",
11-
"lint": "eslint --ext .ts .",
12-
"lint:fix": "eslint --ext .ts --fix .",
11+
"lint": "eslint --ext .ts src/",
12+
"lint:fix": "eslint --ext .ts --fix src/",
1313
"format": "prettier --write 'src/**/*.ts'",
1414
"test": "jest",
1515
"test:watch": "jest --watch",
@@ -24,6 +24,9 @@
2424
"shell-quote": "^1.8.2"
2525
},
2626
"devDependencies": {
27+
"@eslint/compat": "^1.2.8",
28+
"@eslint/eslintrc": "^3.3.1",
29+
"@eslint/js": "^9.25.1",
2730
"@types/jest": "^29.5.14",
2831
"@types/node": "^22.15.3",
2932
"@types/shell-quote": "^1.7.5",
@@ -33,7 +36,9 @@
3336
"eslint-config-prettier": "^10.1.2",
3437
"eslint-import-resolver-typescript": "^4.3.4",
3538
"eslint-plugin-import": "^2.31.0",
39+
"eslint-plugin-jest": "^28.11.0",
3640
"eslint-plugin-prettier": "^5.2.6",
41+
"globals": "^16.0.0",
3742
"jest": "^29.7.0",
3843
"prettier": "^3.5.3",
3944
"ts-jest": "^29.3.2",

0 commit comments

Comments
 (0)