-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy patheslint.config.mjs
More file actions
160 lines (142 loc) · 5.95 KB
/
eslint.config.mjs
File metadata and controls
160 lines (142 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import path from "path";
import { fileURLToPath } from "url";
import { defineConfig, globalIgnores } from "eslint/config";
import tsParser from "@typescript-eslint/parser";
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import unusedImports from "eslint-plugin-unused-imports";
import workspaces from "eslint-plugin-workspaces";
import notice from "eslint-plugin-notice";
import globals from "globals";
import js from "@eslint/js";
import checkFile from "eslint-plugin-check-file";
import extraneousDependencies from "eslint-plugin-import";
import { FlatCompat } from "@eslint/eslintrc";
import nodePlugin from "eslint-plugin-n";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
export default defineConfig([
...compat.extends(
"eslint:recommended",
"prettier",
"plugin:@typescript-eslint/recommended",
"plugin:workspaces/recommended",
"plugin:n/recommended"
),
//
nodePlugin.configs["flat/recommended-script"],
{
languageOptions: {
parser: tsParser,
parserOptions: {
tsconfigRootDir: __dirname,
project: ["./tsconfig.eslint.json"],
},
globals: {
...globals.node,
},
},
plugins: {
"@typescript-eslint": typescriptEslint,
"unused-imports": unusedImports,
workspaces,
notice,
"extraneous-dependencies": extraneousDependencies,
n: nodePlugin,
"check-file": checkFile,
},
rules: {
// *************** Ensure that copyright notice is present ***************
"notice/notice": [
"error",
{
mustMatch: "Copyright \\(c\\) [0-9]{0,4} Contributors to the Eclipse Foundation",
templateFile: __dirname + "/license.template.txt",
onNonMatchingHeader: "replace",
},
],
// *************** NodeJS specific rules - relaxing default setting of n ***************
"n/no-path-concat": "error",
"n/no-unsupported-features/es-syntax": [
"error",
{
ignores: ["modules"],
},
],
// relax missing import rule to warning, as we sometimes have optional dependencies
// import "../foo" will braise a warning ,
// import "../foo.js" is the correct way to import a file that may not exist
"n/no-missing-import": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1428
"n/no-unsupported-features/node-builtins": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
"n/no-extraneous-import": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
"n/no-deprecated-api": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
"n/no-unpublished-import": "error",
"n/no-process-exit": "error",
"n/hashbang": "warn",
// *************** Ensure that only used dependencies are imported ***************
"extraneous-dependencies/no-extraneous-dependencies": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
// *************** Code style and best practices ***************
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"error",
{
args: "none",
varsIgnorePattern: "Test",
},
],
// **************** enforece kebab-case for filenames ****************
"check-file/filename-naming-convention": [
"error",
{
"**/*.{js,ts}": "KEBAB_CASE",
},
{
ignoreMiddleExtensions: true,
},
],
"check-file/folder-naming-convention": [
"error",
{
"**/*": "KEBAB_CASE",
},
],
// *************** Customization of other typescript rules ***************
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/no-empty-object-type": "error",
"@typescript-eslint/no-floating-promises": "off", // https://github.com/eclipse-thingweb/node-wot/issues/1430
// **************** Enforce usage of `const` over `let` wherever possible, to prevent accidental reassignments
"prefer-const": "error",
// *************** Other rules ***************
"no-restricted-globals": "error",
"no-restricted-properties": "error",
"no-use-before-define": "error",
"no-unused-private-class-members": "error",
"no-prototype-builtins": "off",
"no-case-declarations": "off",
"no-console": "error",
// ***************** Enforce that for-in loops include an if statement to filter properties from the prototype chain
"guard-for-in": "error",
},
},
globalIgnores([
"utils/*",
"packages/browser-bundle/types/index.d.ts",
"packages/*/eslint.config.mjs",
"eslint.config.mjs",
"packages/browser-bundle/web-test-runner.config.mjs",
"**/.eslintrc.js",
"**/dist",
"**/node_modules",
"examples",
"**/bin",
"**/*.js",
]),
]);