Skip to content

Commit 594caf2

Browse files
committed
BSA-270: add linters
1 parent 1e2efd5 commit 594caf2

25 files changed

+5999
-698
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
charset = utf-8
10+
11+
[*.md]
12+
indent_size = unset

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
node_modules
22
build
3-
.vscode
3+
.vscode

.ls-lint.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ls:
2+
.dir: regex:([.a-z0-9]*)([-.][a-z0-9]+)*
3+
.css: regex:([.a-z0-9]*)([-.][a-z0-9]+)*
4+
.ts: regex:([.a-z0-9]*)([-.][a-z0-9]+)*
5+
.js: regex:([.a-z0-9]*)([-.][a-z0-9]+)*
6+
.mjs: regex:([.a-z0-9]*)([-.][a-z0-9]+)*
7+
8+
ignore:
9+
- .git
10+
- .github
11+
- .idea/**
12+
- node_modules
13+
- build

.prettierrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
"tabWidth": 4,
33
"useTabs": false,
44
"semi": true,
5-
"singleQuote": true,
5+
"singleQuote": false,
66
"trailingComma": "none",
77
"bracketSpacing": true,
8-
"arrowParens": "avoid",
8+
"arrowParens": "always",
99
"quoteProps": "preserve",
1010
"printWidth": 120
1111
}

eslint.config.js

Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
1+
import js from "@eslint/js";
2+
import stylistic from "@stylistic/eslint-plugin";
3+
import ts from "@typescript-eslint/eslint-plugin";
4+
import tsParser from "@typescript-eslint/parser";
5+
import { resolve as tsResolver } from "eslint-import-resolver-typescript";
6+
import importPlugin from "eslint-plugin-import";
7+
import jsdoc from "eslint-plugin-jsdoc";
8+
import perfectionist from "eslint-plugin-perfectionist";
9+
import explicitGenerics from "eslint-plugin-require-explicit-generics";
10+
import sonarjs from "eslint-plugin-sonarjs";
11+
import unicorn from "eslint-plugin-unicorn";
12+
import globals from "globals";
13+
14+
const JS_MAX_PARAMS_ALLOWED = 3;
15+
16+
/** @typedef {import("eslint").Linter.Config} */
17+
let Config;
18+
/** @typedef {import("eslint").Linter.ParserModule} */
19+
let ParserModule;
20+
21+
/** @type {Config} */
22+
const filesConfig = {
23+
files: ["./src/**/*.{js,ts,mjs}"]
24+
};
25+
26+
/** @type {Config} */
27+
const ignoresConfig = {
28+
ignores: ["public", "build"]
29+
};
30+
31+
/** @type {Config} */
32+
const jsConfig = {
33+
languageOptions: {
34+
globals: globals.node,
35+
parserOptions: {
36+
ecmaVersion: 14,
37+
sourceType: "module"
38+
}
39+
},
40+
rules: {
41+
...js.configs.recommended.rules,
42+
"arrow-parens": ["error", "always"],
43+
curly: ["error", "all"],
44+
"max-params": ["error", JS_MAX_PARAMS_ALLOWED],
45+
"no-console": ["error"],
46+
"no-multiple-empty-lines": [
47+
"error",
48+
{
49+
max: 1
50+
}
51+
],
52+
"no-restricted-syntax": [
53+
"error",
54+
{
55+
message: "Export/Import all (*) is forbidden.",
56+
selector: "ExportAllDeclaration,ImportAllDeclaration"
57+
},
58+
{
59+
message: "Exports should be at the end of the file.",
60+
selector: "ExportNamedDeclaration[declaration!=null]"
61+
},
62+
{
63+
message: "TS features are forbidden.",
64+
selector: "TSEnumDeclaration,ClassDeclaration[abstract=true]"
65+
},
66+
{
67+
message:
68+
"Avoid import/export type { Type } from './module'. Prefer import/export { type Type } from './module'.",
69+
selector: "ImportDeclaration[importKind=type],ExportNamedDeclaration[exportKind=type]"
70+
}
71+
],
72+
"no-unused-vars": [
73+
"error",
74+
{
75+
"argsIgnorePattern": "^_",
76+
"caughtErrorsIgnorePattern": "^_",
77+
"varsIgnorePattern": "^_"
78+
}
79+
],
80+
"object-shorthand": ["error"],
81+
"prefer-destructuring": ["error"],
82+
quotes: ["error", "double"]
83+
}
84+
};
85+
86+
/** @type {Config} */
87+
const importConfig = {
88+
plugins: {
89+
import: importPlugin
90+
},
91+
rules: {
92+
...importPlugin.configs.recommended.rules,
93+
"import/exports-last": ["error"],
94+
"import/extensions": [
95+
"error",
96+
{
97+
js: "always"
98+
}
99+
],
100+
"import/newline-after-import": ["error"],
101+
"import/no-default-export": ["error"],
102+
"import/no-duplicates": ["error"]
103+
},
104+
settings: {
105+
"import/parsers": {
106+
espree: [".js", ".cjs"]
107+
},
108+
"import/resolver": {
109+
typescript: tsResolver
110+
}
111+
}
112+
};
113+
114+
/** @type {Config} */
115+
const sonarConfig = {
116+
plugins: {
117+
sonarjs
118+
},
119+
rules: {
120+
...sonarjs.configs.recommended.rules,
121+
"sonarjs/no-duplicate-string": ["off"],
122+
"sonarjs/no-unused-vars": ["off"]
123+
}
124+
};
125+
126+
/** @type {Config} */
127+
const unicornConfig = {
128+
plugins: {
129+
unicorn
130+
},
131+
rules: {
132+
...unicorn.configs.recommended.rules,
133+
"unicorn/no-null": ["off"]
134+
}
135+
};
136+
137+
/** @type {Config} */
138+
const perfectionistConfig = {
139+
plugins: {
140+
perfectionist
141+
},
142+
rules: perfectionist.configs["recommended-natural"].rules
143+
};
144+
145+
/** @type {Config} */
146+
const typescriptConfig = {
147+
ignores: ["eslint.config.js", "lint-staged.config.js", "stylelint.config.js"],
148+
languageOptions: {
149+
parser: /** @type {ParserModule} */ (tsParser),
150+
parserOptions: {
151+
project: "./tsconfig.json"
152+
}
153+
},
154+
plugins: {
155+
"@typescript-eslint": ts
156+
},
157+
rules: {
158+
...ts.configs["strict-type-checked"].rules,
159+
"@typescript-eslint/consistent-type-exports": ["error"],
160+
"@typescript-eslint/consistent-type-imports": [
161+
"error",
162+
{
163+
fixStyle: "inline-type-imports"
164+
}
165+
],
166+
"@typescript-eslint/explicit-function-return-type": [
167+
"error",
168+
{
169+
allowTypedFunctionExpressions: true
170+
}
171+
],
172+
"@typescript-eslint/no-magic-numbers": [
173+
"error",
174+
{
175+
ignoreEnums: true,
176+
ignoreReadonlyClassProperties: true
177+
}
178+
],
179+
"@typescript-eslint/no-misused-promises": [
180+
"error",
181+
{
182+
"checksVoidReturn": false
183+
}
184+
],
185+
"@typescript-eslint/no-unused-vars": ["off"],
186+
"@typescript-eslint/return-await": ["error", "always"]
187+
}
188+
};
189+
190+
/** @type {Config} */
191+
const jsdocConfig = {
192+
files: ["eslint.config.js", "lint-staged.config.js"],
193+
plugins: {
194+
jsdoc
195+
},
196+
rules: {
197+
...jsdoc.configs["recommended-typescript-flavor-error"].rules,
198+
"jsdoc/no-undefined-types": ["error"]
199+
}
200+
};
201+
202+
/** @type {Config} */
203+
const stylisticConfig = {
204+
plugins: {
205+
"@stylistic": stylistic
206+
},
207+
rules: {
208+
"@stylistic/padding-line-between-statements": [
209+
"error",
210+
{
211+
blankLine: "never",
212+
next: "export",
213+
prev: "export"
214+
},
215+
{
216+
blankLine: "always",
217+
next: "*",
218+
prev: ["block-like", "throw"]
219+
},
220+
{
221+
blankLine: "always",
222+
next: ["return", "block-like", "throw"],
223+
prev: "*"
224+
}
225+
]
226+
}
227+
};
228+
229+
/** @type {Config} */
230+
const explicitGenericsConfig = {
231+
plugins: {
232+
"require-explicit-generics": explicitGenerics
233+
}
234+
};
235+
236+
/** @type {Config[]} */
237+
const overridesConfigs = [
238+
{
239+
files: ["packages.d.ts", "lint-staged.config.js", "eslint.config.js"],
240+
rules: {
241+
"import/no-default-export": ["off"]
242+
}
243+
},
244+
{
245+
files: ["*.js"],
246+
rules: {
247+
"@typescript-eslint/explicit-function-return-type": ["off"]
248+
}
249+
},
250+
{
251+
files: ["./src/server.ts"],
252+
rules: {
253+
"import/no-default-export": ["off"],
254+
"no-console": ["off"]
255+
}
256+
}
257+
];
258+
259+
/** @type {Config[]} */
260+
const config = [
261+
filesConfig,
262+
ignoresConfig,
263+
jsConfig,
264+
importConfig,
265+
sonarConfig,
266+
unicornConfig,
267+
perfectionistConfig,
268+
typescriptConfig,
269+
jsdocConfig,
270+
stylisticConfig,
271+
explicitGenericsConfig,
272+
...overridesConfigs
273+
];
274+
275+
export default config;

lint-staged.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('lint-staged').Config} */
2+
const config = {
3+
"*": [() => "npm run lint:editor", () => "npm run lint:fs", () => "npm run lint:js", () => "npm run lint:format"]
4+
};
5+
6+
export default config;

0 commit comments

Comments
 (0)