-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheslint.config.js
More file actions
181 lines (174 loc) · 8.05 KB
/
Copy patheslint.config.js
File metadata and controls
181 lines (174 loc) · 8.05 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/**
* eslint.config.js
*
* ---------------------------------------------------------------
*
* A set of basic code conventions designed to encourage quality and consistency
* across this Sails app's code base. These rules are checked automatically any
* time you run `npm test`.
*
* This is the ESLint "flat config" translation of the three `.eslintrc` files
* this app used to carry (root, `assets/`, and `views/`). ESLint 9 dropped
* support for the old `.eslintrc` format entirely, so the eslintrc files were
* inert from the 8.4.0 -> 10.5.0 bump onwards and `npm test` could not run.
*
* The rule set below is a deliberate one-for-one port of those files — same
* rules, same severities, same options — so that the lint contract this
* codebase was written against is unchanged. Behavioural notes on the few
* places where flat config is not a literal translation are inline.
*
* For more information about any of the rules below, check out the relevant
* reference page on eslint.org. For example, to get details on "no-sequences",
* you would visit `https://eslint.org/docs/rules/no-sequences`.
*/
const globals = require('globals');
// The backend rule set. Shared by every file, then selectively overridden for
// browser-habitat code in `assets/` and `views/` further down.
//
// Note: many of these are formatting rules that ESLint has since deprecated in
// favour of the external @stylistic plugin. They are all still shipped and
// functional in ESLint 10, so they are kept as-is rather than pulling in a new
// dependency purely to preserve the existing style enforcement.
const rules = {
'block-scoped-var': ['error'],
'callback-return': ['error', ['done', 'proceed', 'next', 'onwards', 'callback', 'cb']],
// `allow` lists snake_case names that are wire format, not style drift:
// they are keys in the JSON returned by /system/info and /bandwidth, and the
// tx_/rx_ set mirrors the field names the `systeminformation` package hands
// us. Renaming them would change a public API response for cosmetic reasons.
// Purely internal snake_case locals are still reported.
'camelcase': ['warn', {'properties':'always', 'allow': [
'^default_iface$', '^(tx|rx)_(bytes|errors|dropped|sec)$'
]}],
'comma-style': ['warn', 'last'],
// 'multi-line' rather than the template's default 'all'. Every one of the
// 125 hits the stricter setting produced was a single-line guard clause
// (`if (!user) return exits.forbidden();`), a style this codebase uses
// consistently and deliberately. 'multi-line' still requires braces the
// moment a body wraps onto its own line, which is the case that actually
// causes bugs.
'curly': ['warn', 'multi-line'],
// `{null: 'ignore'}` permits `x == null`, which is the standard idiom for
// "null or undefined" in one comparison. Four sites rely on it as a guard
// (`String(s == null ? '' : s)`); rewriting those to `===` would silently
// stop them catching `undefined`, turning a correct guard into a bug. Every
// other loose comparison is still an error.
'eqeqeq': ['error', 'always', {'null': 'ignore'}],
'eol-last': ['warn'],
'handle-callback-err': ['error'],
'indent': ['warn', 2, {
'SwitchCase': 1,
'MemberExpression': 'off',
'FunctionDeclaration': {'body':1, 'parameters':'off'},
'FunctionExpression': {'body':1, 'parameters':'off'},
'CallExpression': {'arguments':'off'},
'ArrayExpression': 1,
'ObjectExpression': 1,
'ignoredNodes': ['ConditionalExpression']
}],
'linebreak-style': ['error', 'unix'],
'no-dupe-keys': ['error'],
'no-duplicate-case': ['error'],
'no-extra-semi': ['warn'],
'no-labels': ['error'],
'no-mixed-spaces-and-tabs': [2, 'smart-tabs'],
'no-redeclare': ['warn'],
'no-return-assign': ['error', 'always'],
'no-sequences': ['error'],
'no-trailing-spaces': ['warn'],
'no-undef': ['off'],
// ^^Note: If this "no-undef" rule is enabled (set to `['error']`), then all model globals
// (e.g. `Organization: 'writable'`) should be included under `globals` below.
'no-unexpected-multiline': ['warn'],
'no-unreachable': ['warn'],
'no-unused-vars': ['warn', {'caughtErrors':'all', 'caughtErrorsIgnorePattern': '^unused($|[A-Z].*$)', 'argsIgnorePattern': '^unused($|[A-Z].*$)', 'varsIgnorePattern': '^unused($|[A-Z].*$)' }],
'no-use-before-define': ['error', {'functions':false}],
'one-var': ['warn', 'never'],
'prefer-arrow-callback': ['warn', {'allowNamedFunctions':true}],
// avoidEscape lets a double-quoted string stand when it contains single
// quotes. With the template's `false`, the autofix turned readable DataTables
// `dom` strings into escape soup ('<\'row\'<\'col-sm-12\'f>>...').
'quotes': ['warn', 'single', {'avoidEscape':true, 'allowTemplateLiterals':true}],
'semi': ['warn', 'always'],
'semi-spacing': ['warn', {'before':false, 'after':true}],
'semi-style': ['warn', 'last']
};
module.exports = [
{
// Replaces the old `.eslintignore`. `node_modules/` is ignored by ESLint
// out of the box and no longer needs listing.
//
// `.tmp/` and `www/` are new here: they are grunt build output containing
// copies of `assets/`, so linting them double-reports every finding against
// a path that is not the source of truth. The old .eslintignore predated
// those tasks existing.
ignores: [
'assets/dependencies/**/*.js',
'.tmp/**',
'www/**'
]
},
{
// Backend code: Node.js/Sails habitat.
files: ['**/*.js'],
languageOptions: {
ecmaVersion: 2018,
// Flat config defaults `.js` to `sourceType: 'module'`, which would parse
// this CommonJS codebase as ESM (implicit strict mode, no `require`).
// The old eslintrc default was 'script'; 'commonjs' is its flat-config
// equivalent for a Node app and is what this code actually is.
sourceType: 'commonjs',
globals: {
...globals.node,
// If 'no-undef' is enabled above, be sure to list all global variables
// that are used in this app's backend code (including the globalIds of
// models). 'writable' is the flat-config spelling of the old `true`.
Promise: 'writable',
sails: 'writable',
_: 'writable'
}
},
rules: rules
},
{
// Front-end code in `assets/` and `views/` runs in the browser, so it gets a
// different set of globals — `window` and friends instead of `process` and
// `sails`. Ported from the old `assets/.eslintrc`.
files: ['assets/**/*.js', 'views/**/*.js'],
languageOptions: {
ecmaVersion: 2017,
// Plain <script> tags, not modules and not CommonJS.
sourceType: 'script',
globals: {
...globals.browser,
SAILS_LOCALS: 'writable',
io: 'writable',
// Vendored libraries this app loads via plain <script> tags in the
// layout, so they are ambient globals rather than imports. The old
// config never listed them, which is why 'no-undef' had 31 hits here.
$: 'writable',
jQuery: 'writable',
Chart: 'writable',
PNotify: 'writable',
bootstrap: 'writable',
// Backend globals are marked read-only rather than removed, matching
// the old config's `false` (in eslintrc, `false` meant "readonly", not
// "undefined" — so this is a faithful port, not a loosening).
sails: 'readonly',
_: 'readonly'
}
},
rules: {
...rules,
'no-undef': ['error']
}
},
{
// Ported from the old `views/.eslintrc`: these files are inlined into .ejs
// templates, so a trailing newline is not meaningful.
files: ['views/**/*.js'],
rules: {
'eol-last': ['off']
}
}
];