@electrum-cash/eslint-config 1.1.0-development

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 General Protocols Pte Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @electrum-cash/eslint-config
2
+
3
+ This repository contains an ESLint configuration for TypeScript projects in the `@electrum-cash/*` NPM package namespace. It is based on and extends the official Airbnb ESLint configuration and its TypeScript equivalent.
4
+
5
+ ## Dependencies
6
+
7
+ Before you can use this you need to install the peer depenencies required by the configuration setup.
8
+
9
+ ```bash
10
+ npm install --save-dev \
11
+ eslint \
12
+ typescript-eslint \
13
+ @typescript-eslint/parser \
14
+ @typescript-eslint/eslint-plugin \
15
+ @stylistic/eslint-plugin \
16
+ @chalp/eslint-airbnb
17
+ ```
18
+
19
+ After installing the dependencies, you can install the module containing the configuration:
20
+
21
+ ```bash
22
+ npm install --save-dev https://gitlab.com/electrum-cash/eslint-config
23
+ ```
24
+
25
+ and put the following `eslint.config.mjs` in your project root directory:
26
+
27
+ ```ts
28
+ export { default } from '@electrum-cash/eslint-config';
29
+ ```
@@ -0,0 +1,333 @@
1
+ // Import globally available component required in different contexts (like window, document, Promise etc)
2
+ import globals from 'globals';
3
+
4
+ // Import support for typescript.
5
+ import { parser } from 'typescript-eslint';
6
+ import typescriptEslint from '@typescript-eslint/eslint-plugin';
7
+
8
+ // Import formatting relates extensions to eslint.
9
+ import stylistic from '@stylistic/eslint-plugin';
10
+
11
+ // Import community maintained fork of the airbnb rules.
12
+ import airbnbTypescript from '@chalp/eslint-airbnb/typescript';
13
+
14
+ //
15
+ export default
16
+ [
17
+ {
18
+ // Ignore common build artifacts and dependency files.
19
+ // NOTE: This needs to be the first object in the array, or eslint may fail due to trying to parse these files.
20
+ ignores:
21
+ [
22
+ 'dist/**',
23
+ 'public/**',
24
+ 'node_modules/**',
25
+ '**/*.d.{ts,mts}'
26
+ ],
27
+ },
28
+ {
29
+ // Configure which files to lint.
30
+ files:
31
+ [
32
+ '**/*.{ts,mts}',
33
+ ],
34
+
35
+ languageOptions:
36
+ {
37
+ // Always enable full type-aware linting
38
+ parser: parser,
39
+ parserOptions: {
40
+ projectService: true,
41
+ tsconfigRootDir: import.meta.dirname,
42
+ },
43
+ },
44
+ },
45
+
46
+ // Enable the stylistic plugin.
47
+ {
48
+ plugins:
49
+ {
50
+ '@stylistic': stylistic,
51
+ '@typescript-eslint': typescriptEslint,
52
+ },
53
+ },
54
+
55
+ // Configure which globals are required in the various environments.
56
+ {
57
+ languageOptions:
58
+ {
59
+ globals:
60
+ {
61
+ ...globals.browser,
62
+ ...globals.es2021,
63
+ },
64
+ },
65
+ },
66
+
67
+ // Configure eslint-plugin-import to support typescript path aliases from tsconfig.json, with a default fallback if needed.
68
+ {
69
+ settings:
70
+ {
71
+ 'import/resolver':
72
+ {
73
+ typescript: {},
74
+ node: {},
75
+ },
76
+ },
77
+ },
78
+
79
+ // Start with the airbnb ruleset.
80
+ ...airbnbTypescript,
81
+
82
+ // Custom linting rules.
83
+ {
84
+ rules:
85
+ {
86
+ // require function expressions to have a name when it can't be inferred
87
+ // https://eslint.org/docs/rules/func-names
88
+ 'func-names': [ 'error', 'as-needed' ],
89
+
90
+ // enforce intentional scoping for function declarations
91
+ // https://eslint.org/docs/rules/func-style
92
+ 'func-style': [ 'error', 'expression' ],
93
+
94
+ // enforce position of line comments above the statement
95
+ // https://eslint.org/docs/rules/line-comment-position
96
+ 'line-comment-position': [ 'error', {
97
+ position: 'above',
98
+ ignorePattern: '',
99
+ }],
100
+
101
+ // warn at very high nesting levels
102
+ // https://eslint.org/docs/rules/max-depth
103
+ 'max-depth': [ 'warn', 5 ],
104
+
105
+ // warn if max number of lines exceeds 250 (consistent with GitLab code quality reports)
106
+ // turned off because of editor highlighting
107
+ // https://eslint.org/docs/rules/max-lines
108
+ 'max-lines': [ 'off', {
109
+ max: 250,
110
+ skipBlankLines: true,
111
+ skipComments: true,
112
+ }],
113
+
114
+ // warn if max function length exceeds 25 (consistent with GitLab code quality reports)
115
+ // turned off because of editor highlighting
116
+ // https://eslint.org/docs/rules/max-lines-per-function
117
+ 'max-lines-per-function': [ 'off', {
118
+ max: 25,
119
+ skipBlankLines: true,
120
+ skipComments: true,
121
+ IIFEs: true,
122
+ }],
123
+
124
+ // warn when the number of function parameters gets too large
125
+ // https://eslint.org/docs/rules/max-params
126
+ 'max-params': [ 'warn', 5 ],
127
+
128
+ // disallow multiple statements per line for readability
129
+ // https://eslint.org/docs/rules/max-statements-per-line
130
+ 'max-statements-per-line': [ 'error', { max: 1 }],
131
+
132
+ // disallow multiline ternaries for readability
133
+ // https://eslint.org/docs/rules/multiline-ternary
134
+ 'multiline-ternary': [ 'warn', 'never' ],
135
+
136
+ // we prefer the readability of separated return statements
137
+ // can be ignored if done intentionally
138
+ // https://eslint.org/docs/rules/newline-before-return
139
+ 'newline-before-return': [ 'warn' ],
140
+
141
+ // allow bitwise operators (e.g. for AnyHedge simulation)
142
+ // https://eslint.org/docs/rules/no-bitwise
143
+ 'no-bitwise': [ 'off' ],
144
+
145
+ // allow the use of the continue statement because there is no clear
146
+ // argument against them
147
+ // https://eslint.org/docs/rules/no-continue
148
+ 'no-continue': [ 'off' ],
149
+
150
+ // discourage use of line comments on the same line as code
151
+ // https://eslint.org/docs/rules/no-inline-comments
152
+ 'no-inline-comments': [ 'warn' ],
153
+
154
+ // disabllow single-line blocks
155
+ // https://eslint.org/docs/rules/no-unexpected-multiline
156
+ 'no-unexpected-multiline': [ 'off' ],
157
+
158
+ // we want to allow the use of for..in and for..of statements
159
+ // https://eslint.org/docs/rules/no-restricted-syntax
160
+ // https://eslint.org/docs/rules/guard-for-in
161
+ 'no-restricted-syntax': [ 'off' ],
162
+ 'guard-for-in': [ 'off' ],
163
+
164
+ // Disallow the use of Math.pow in favor of the ** operator for consistency
165
+ // with other arithmetic operators
166
+ // https://eslint.org/docs/rules/prefer-exponentiation-operator
167
+ 'prefer-exponentiation-operator': [ 'error' ],
168
+
169
+ // warn about unused variables if not starting with underscore, in order to not break the pre-commit hooks
170
+ // https://eslint.org/docs/rules/no-unused-vars
171
+ 'no-unused-vars': [ 'warn', { varsIgnorePattern: '^_', argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_' }],
172
+ '@typescript-eslint/no-unused-vars': [ 'warn', { varsIgnorePattern: '^_', argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_', destructuredArrayIgnorePattern: '^_' }],
173
+
174
+ // do not allow re-declaring names in nested namespaces.
175
+ 'no-shadow': [ 'error' ],
176
+
177
+ // for singleton classes it makes sense not to enforce this rule
178
+ // https://eslint.org/docs/rules/class-methods-use-this
179
+ 'class-methods-use-this': [ 'off' ],
180
+
181
+ // encourages use of dot notation whenever possible
182
+ // https://eslint.org/docs/rules/dot-notation
183
+ 'dot-notation': [ 'warn', { allowKeywords: true }],
184
+
185
+ // warn about a maximum number of classes per file
186
+ // https://eslint.org/docs/rules/max-classes-per-file
187
+ 'max-classes-per-file': [ 'warn', 1 ],
188
+
189
+ // discourage unnecessary nested blocks
190
+ // https://eslint.org/docs/rules/no-lone-blocks
191
+ 'no-lone-blocks': [ 'warn' ],
192
+
193
+ // Sometimes you want to execute async calls in loops sequentially
194
+ // https://eslint.org/docs/rules/no-await-in-loop
195
+ 'no-await-in-loop': [ 'off' ],
196
+
197
+ // disallow use of constant expressions in conditions
198
+ // https://eslint.org/docs/rules/no-constant-condition
199
+ 'no-constant-condition': [ 'error' ],
200
+
201
+ // require explicit file extension when importing from files.
202
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
203
+ 'import/extensions': [ 'error', 'ignorePackages', { 'js': 'always', 'ts': 'always' }],
204
+
205
+ // do not enforce any import ordering
206
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
207
+ 'import/order': [ 'off' ],
208
+
209
+ // do not require default export
210
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/prefer-default-export.md
211
+ 'import/prefer-default-export': [ 'off' ],
212
+
213
+ // allows shorthands on a case-by-case basis in order to maintain
214
+ // consistency across sections of code with multiple statements.
215
+ // https://eslint.org/docs/rules/object-shorthand
216
+ 'object-shorthand': [ 'off' ],
217
+
218
+ // callbacks can either be named functions or arrow functions
219
+ 'prefer-arrow-callback': [ 'error', {
220
+ allowNamedFunctions: true,
221
+ }],
222
+ },
223
+ },
224
+
225
+ // Custom formatting rules.
226
+ {
227
+ rules:
228
+ {
229
+ // enforce consistent line breaks after opening and before closing array brackets
230
+ // https://eslint.style/rules/array-bracket-newline
231
+ '@stylistic/array-bracket-newline': [ 'error', 'consistent' ],
232
+
233
+ // warn about consistent line breaks between array elements
234
+ // warn instead of error to allow intentional deviations
235
+ // https://eslint.style/rules/array-element-newline
236
+ '@stylistic/array-element-newline': [ 'warn', 'consistent' ],
237
+
238
+ // enforce spacing inside array brackets to be consistent with object brackets
239
+ // https://eslint.style/rules/array-bracket-spacing
240
+ '@stylistic/array-bracket-spacing': [ 'error', 'always', { objectsInArrays: false, arraysInArrays: false }],
241
+
242
+ // enforce allman brace style, disallow single line blocks
243
+ // https://eslint.style/rules/brace-style
244
+ // https://eslint.style/rules/operator-linebreak
245
+ '@stylistic/brace-style': [ 'error', 'allman', { allowSingleLine: true }],
246
+ '@stylistic/operator-linebreak': [ 'error', 'before', { overrides: { '=': 'ignore' } }],
247
+
248
+ // enforce consistent line breaks in function calls
249
+ // https://eslint.style/rules/function-call-argument-newline
250
+ '@stylistic/function-call-argument-newline': [ 'off', 'consistent' ],
251
+
252
+ // use tabs for indentation and use indentation in switch-cases for readability
253
+ // https://eslint.style/rules/indent
254
+ // https://eslint.style/rules/no-tabs
255
+ // NOTE: This is set to warn due to incompatibility with typescript in some cases
256
+ // https://github.com/typescript-eslint/typescript-eslint/issues/1824
257
+ '@stylistic/no-tabs': [ 'off' ],
258
+ '@stylistic/indent':
259
+ [
260
+ 'warn',
261
+ "tab",
262
+ {
263
+ SwitchCase: 1,
264
+ MemberExpression: 1,
265
+ FunctionDeclaration: { parameters: 1, body: 1 },
266
+ FunctionExpression: { parameters: 1, body: 1 },
267
+ CallExpression: { arguments: 1 }
268
+ }
269
+ ],
270
+
271
+ // Selectively disable to allow extra indent for object literals in class properties.
272
+ '@stylistic/indent':
273
+ [
274
+ 'off',
275
+ {
276
+ selector: [ 'ClassProperty > ObjectExpression' ]
277
+ }
278
+ ],
279
+
280
+
281
+ // allow multiple spaces for alignment
282
+ // https://eslint.style/rules/key-spacing
283
+ '@stylistic/key-spacing': [ 'error', { mode: 'minimum' }],
284
+ '@stylistic/no-multi-spaces': [ 'off' ],
285
+
286
+ // no spaces after if/for/while/catch/switch
287
+ // https://eslint.style/rules/keyword-spacing
288
+ '@stylistic/keyword-spacing': [ 'error', { overrides: {
289
+ if: { after: false },
290
+ for: { after: false },
291
+ while: { after: false },
292
+ throw: { after: false },
293
+ catch: { after: false },
294
+ switch: { after: false },
295
+ }}],
296
+
297
+ // specify the maximum length of a line in your program
298
+ // https://eslint.style/rules/max-len
299
+ '@stylistic/max-len': [ 'off', 200, 4, {
300
+ ignoreUrls: true,
301
+ ignoreComments: false,
302
+ ignoreRegExpLiterals: true,
303
+ ignoreStrings: true,
304
+ ignoreTemplateLiterals: true,
305
+ }],
306
+
307
+ // enforces new line after each method call in the chain to make it
308
+ // more readable and easy to maintain
309
+ // https://eslint.style/rules/newline-per-chained-call
310
+ '@stylistic/newline-per-chained-call': [ 'error', { ignoreChainWithDepth: 2 }],
311
+
312
+ // enforce that an object is either on one line, or every property is on a new line
313
+ // https://eslint.style/rules/object-curly-newline
314
+ '@stylistic/object-curly-newline': [ 'error', { consistent: true }],
315
+
316
+ // enforce consistency between anonymous and named functions
317
+ // https://eslint.style/rules/space-before-function-paren
318
+ '@stylistic/space-before-function-paren': [ 'error', {
319
+ anonymous: 'never',
320
+ named: 'ignore',
321
+ asyncArrow: 'always'
322
+ }],
323
+
324
+ // enforce each parameter on a separate line for functions that are not declared in a single line.
325
+ // https://eslint.style/rules/function-paren-newline
326
+ '@stylistic/function-paren-newline': [ 'error', 'multiline' ],
327
+
328
+ // allow grouping of class properties in TypeScript
329
+ // https://eslint.org/docs/rules/lines-between-class-members
330
+ '@stylistic/lines-between-class-members': [ 'error', 'always', { exceptAfterSingleLine: true }],
331
+ },
332
+ },
333
+ ];
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@electrum-cash/eslint-config",
3
+ "version": "1.1.0-development",
4
+ "description": "ESLint configuration for Electrum Cash projects",
5
+ "type": "module",
6
+ "main": "eslint.config.mjs",
7
+ "exports": {
8
+ ".": "./eslint.config.mjs"
9
+ },
10
+ "files": [
11
+ "eslint.config.mjs"
12
+ ],
13
+ "scripts": {
14
+ "syntax": "eslint eslint.config.mjs"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+ssh://git@gitlab.com/electrum-cash/eslint-config.git"
19
+ },
20
+ "author": "Jonathan Silverblood",
21
+ "license": "MIT",
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "bugs": {
26
+ "url": "https://gitlab.com/electrum-cash/eslint-config/issues"
27
+ },
28
+ "homepage": "https://gitlab.com/electrum-cash/eslint-config#readme",
29
+ "devDependencies": {
30
+ "@chalp/eslint-airbnb": "^1.3.0",
31
+ "@stylistic/eslint-plugin": "^4.4.1",
32
+ "@typescript-eslint/eslint-plugin": "^8.53.0",
33
+ "@typescript-eslint/parser": "^8.53.0",
34
+ "eslint": "^9.39.2",
35
+ "eslint-import-resolver-typescript": "^3.10.1",
36
+ "eslint-plugin-import": "^2.32.0",
37
+ "globals": "^17.0.0",
38
+ "typescript": "^5.9.3",
39
+ "typescript-eslint": "^8.53.0"
40
+ },
41
+ "peerDependencies": {
42
+ "eslint": "^9.0.0",
43
+ "typescript-eslint": "^8.0.0",
44
+ "@stylistic/eslint-plugin": "^5.0.0",
45
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
46
+ "@typescript-eslint/parser": "^8.0.0",
47
+ "@chalp/eslint-airbnb": "^1.3.0"
48
+ }
49
+ }