forked from skycoin/skycoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.base.config.js
More file actions
115 lines (110 loc) · 4.13 KB
/
Copy patheslint.base.config.js
File metadata and controls
115 lines (110 loc) · 4.13 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
// @ts-check
//
// Shared ESLint flat-config base for the Angular front-ends: /explorer,
// /src/gui/static and /src/skycoin-web.
//
// The three projects had drifted into three different rule sets, so the same
// code could be clean in one and rejected in another. This file holds the rules
// that should hold everywhere; each project's eslint.config.js passes in only
// what is genuinely local to it.
//
// It is a factory rather than a plain config object because ESLint plugins are
// installed per project. Each project requires its own copies of @eslint/js,
// typescript-eslint and angular-eslint and hands them in, which keeps this file
// dependency-free and avoids a repository-root node_modules.
//
// Usage, from a project's eslint.config.js:
//
// const eslint = require("@eslint/js");
// const tseslint = require("typescript-eslint");
// const angular = require("angular-eslint");
// const createConfig = require("<relative path>/eslint.base.config.js");
//
// module.exports = createConfig({ eslint, tseslint, angular });
/**
* @param {object} options
* @param {any} options.eslint `@eslint/js`
* @param {any} options.tseslint `typescript-eslint`
* @param {any} options.angular `angular-eslint`
* @param {string|string[]} [options.directiveSelectorPrefix]
* Attribute-selector prefix(es) accepted for directives. Defaults to "app".
* @param {Record<string, any>} [options.legacyRules]
* Per-project opt-outs. These are pre-existing debt, not policy: each entry
* marks a rule the project's code cannot satisfy yet. Deleting entries here
* (and fixing the code) is the direction of travel.
* @param {Record<string, any>} [options.templateRules]
* Per-project overrides for the HTML template block.
*/
module.exports = function createAngularEslintConfig({
eslint,
tseslint,
angular,
directiveSelectorPrefix = "app",
legacyRules = {},
templateRules = {},
}) {
return tseslint.config(
{
files: ["**/*.ts"],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
...angular.configs.tsRecommended,
],
processor: angular.processInlineTemplates,
languageOptions: {
parserOptions: {
project: ["tsconfig.json"],
},
},
rules: {
// --- Angular conventions -------------------------------------------
"@angular-eslint/component-selector": [
"error",
{
type: "element",
prefix: "app",
style: "kebab-case",
},
],
"@angular-eslint/directive-selector": [
"error",
{
type: "attribute",
prefix: directiveSelectorPrefix,
style: "camelCase",
},
],
// --- Opinionated angular-eslint rules this codebase does not follow --
// inject() vs constructor injection, and standalone components, are
// both migrations these NgModule-based apps have not made.
"@angular-eslint/prefer-inject": "off",
"@angular-eslint/prefer-standalone": "off",
// --- Style and correctness held in common ---------------------------
"max-len": ["error", { code: 200 }],
"no-underscore-dangle": "off",
"prefer-const": "error",
curly: "error",
eqeqeq: ["error", "always", { null: "ignore" }],
"valid-typeof": "error",
"@typescript-eslint/consistent-type-definitions": "error",
// --- Deliberately relaxed everywhere --------------------------------
// These fire throughout code that predates the current toolchain and
// would be noise rather than signal.
"no-constant-binary-expression": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-empty-function": "off",
// --- Per-project debt ------------------------------------------------
...legacyRules,
},
},
{
files: ["**/*.html"],
extends: [...angular.configs.templateRecommended],
rules: {
...templateRules,
},
}
);
};