@elgato/eslint-config 0.1.0
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 +21 -0
- package/README.md +123 -0
- package/package.json +50 -0
- package/src/index.js +8 -0
- package/src/recommended.js +166 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Corsair Memory Inc.
|
|
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,123 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @elgato/eslint-config
|
|
4
|
+
|
|
5
|
+
[ESLint](https://https://eslint.org/.io/) configuration used by Elgato projects.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@elgato/eslint-config)
|
|
8
|
+
[](https://discord.gg/GehBUcu627)
|
|
9
|
+
[](https://elgato.com)
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
npm install @elgato/eslint-config --save-dev
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Create an `eslint.config.js` file at the root of your project.
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
// eslint.config.js
|
|
25
|
+
import { config } from "@elgato/eslint-config";
|
|
26
|
+
|
|
27
|
+
export default config.recommended;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Then add a linting script to your `package.json` file.
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"scripts": {
|
|
35
|
+
"lint": "eslint --max-warnings 0"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Finally, to test everything is working run `npm run lint`.
|
|
41
|
+
|
|
42
|
+
## Configuration
|
|
43
|
+
|
|
44
|
+
The `recommended` configuration is catered for TypeScript, and enforces stricter types through explicit return types and no `any`, amongst other rules. Additionally, the configuration emphasizes the importance of well-documented code ([jsdocs](https://jsdoc.app/)) and encourages structured code in the form of member ordering.
|
|
45
|
+
|
|
46
|
+
### Extends
|
|
47
|
+
|
|
48
|
+
- JSDoc recommended
|
|
49
|
+
- ESLint recommended
|
|
50
|
+
- TypeScript ESLint recommended
|
|
51
|
+
|
|
52
|
+
### Rules
|
|
53
|
+
|
|
54
|
+
| Rule | Severity | Notes |
|
|
55
|
+
| ------------------------------------------ | -------- | ------------------------------------------------------------- |
|
|
56
|
+
| Indent: Tabs | ⚠️ Warn | |
|
|
57
|
+
| JSDoc: Check tag names | ⚠️ Warn | |
|
|
58
|
+
| JSDoc: No undefined types | ⚠️ Warn | |
|
|
59
|
+
| JSDoc: Require JSDoc | ⚠️ Warn | |
|
|
60
|
+
| TypeScript: Explicit function return types | ⚠️ Warn | Disabled for JavaScript, tests, and mock files. |
|
|
61
|
+
| TypeScript: Explicit member accessibility | ⚠️ Warn | No `public` required `constructor`. |
|
|
62
|
+
| TypeScript: Member ordering | ⚠️ Warn | Grouped by type and then access, and ordered alphabetically . |
|
|
63
|
+
| TypeScript: Sort type contituents | ⚠️ Warn | |
|
|
64
|
+
|
|
65
|
+
Additionally, the following rules are disabled for test and mock files:
|
|
66
|
+
|
|
67
|
+
- TypeScript: No explicit `any`
|
|
68
|
+
- TypeScript: No `require` imports
|
|
69
|
+
|
|
70
|
+
### Variants
|
|
71
|
+
|
|
72
|
+
- Mocks and tests
|
|
73
|
+
|
|
74
|
+
- Allow `any` and `require`.
|
|
75
|
+
- Do not require explicit return types.
|
|
76
|
+
|
|
77
|
+
### Ignored
|
|
78
|
+
|
|
79
|
+
- `.github/`
|
|
80
|
+
- `bin/`
|
|
81
|
+
- `dist/`
|
|
82
|
+
- `node_modules/`
|
|
83
|
+
|
|
84
|
+
## Member Ordering
|
|
85
|
+
|
|
86
|
+
Members of a class should be grouped by type and then by access, and ordered alphabetically. The ordersing is as follows:
|
|
87
|
+
|
|
88
|
+
**Type Order**
|
|
89
|
+
|
|
90
|
+
- Fields
|
|
91
|
+
- Constructors
|
|
92
|
+
- Signatures / call signatures
|
|
93
|
+
- Properties (get / set)
|
|
94
|
+
- Methods
|
|
95
|
+
|
|
96
|
+
**Access Order**
|
|
97
|
+
|
|
98
|
+
- Public (static / abstract / regular)
|
|
99
|
+
- Protected (static / abstract / regular)
|
|
100
|
+
- Private (static / abstract / regular)
|
|
101
|
+
|
|
102
|
+
## Overrides
|
|
103
|
+
|
|
104
|
+
Configuration settings can be overriden using the `defineConfig` helper function from ESLint, extending `@elgato/eslint-config`, and then defining your preferred settings.
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
// eslint.config.js
|
|
108
|
+
import { defineConfig } from "eslint/config";
|
|
109
|
+
import { config } from "@elgato/eslint-config";
|
|
110
|
+
|
|
111
|
+
export default defineConfig([
|
|
112
|
+
{
|
|
113
|
+
extends: [export default config.recommended],
|
|
114
|
+
|
|
115
|
+
// Anything from here will override @elgato/eslint-config
|
|
116
|
+
rules: {
|
|
117
|
+
"no-unused-vars": "warn",
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
]);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
[Learn more](https://eslint.org/docs/latest/extend/shareable-configs#overriding-settings-from-shareable-configs) about overriding settings.
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elgato/eslint-config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ESLint configuration used by Elgato projects.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"src/"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"lint": "eslint --max-warnings 0",
|
|
12
|
+
"lint:fix": "prettier \"./src/**/*.js\" --write",
|
|
13
|
+
"preversion": "npm run lint && npm test",
|
|
14
|
+
"test": "vitest run",
|
|
15
|
+
"test:watch": "vitest"
|
|
16
|
+
},
|
|
17
|
+
"prettier": "@elgato/prettier-config",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/elgatosf/eslint-config.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"elgato",
|
|
24
|
+
"eslint",
|
|
25
|
+
"linting"
|
|
26
|
+
],
|
|
27
|
+
"author": {
|
|
28
|
+
"name": "Elgato",
|
|
29
|
+
"url": "https://www.elgato.com"
|
|
30
|
+
},
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/elgatosf/eslint-config/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/elgatosf/eslint-config#readme",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@elgato/prettier-config": "^0.2.6",
|
|
38
|
+
"@tsconfig/node20": "^20.1.5",
|
|
39
|
+
"@types/node": "^22.15.17",
|
|
40
|
+
"typescript": "^5.8.3",
|
|
41
|
+
"vitest": "^3.1.3"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@eslint/js": "^9.26.0",
|
|
45
|
+
"eslint": "^9.26.0",
|
|
46
|
+
"eslint-plugin-jsdoc": "^50.6.14",
|
|
47
|
+
"typescript": "^5.8.3",
|
|
48
|
+
"typescript-eslint": "^8.32.0"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import eslint from "@eslint/js";
|
|
2
|
+
import jsdoc from "eslint-plugin-jsdoc";
|
|
3
|
+
import { defineConfig } from "eslint/config";
|
|
4
|
+
import globals from "globals";
|
|
5
|
+
import tsEslint from "typescript-eslint";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Recommended ESLint configuration.
|
|
9
|
+
*/
|
|
10
|
+
export default defineConfig([
|
|
11
|
+
/**
|
|
12
|
+
* Default ignores.
|
|
13
|
+
*/
|
|
14
|
+
{
|
|
15
|
+
ignores: [
|
|
16
|
+
".github/",
|
|
17
|
+
"bin/",
|
|
18
|
+
"dist/",
|
|
19
|
+
"node_modules/",
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* External library configurations.
|
|
25
|
+
*/
|
|
26
|
+
{
|
|
27
|
+
extends: [
|
|
28
|
+
jsdoc.configs["flat/recommended-typescript"],
|
|
29
|
+
eslint.configs.recommended,
|
|
30
|
+
tsEslint.configs.recommended,
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Main rules.
|
|
36
|
+
*/
|
|
37
|
+
{
|
|
38
|
+
plugins: {
|
|
39
|
+
jsdoc,
|
|
40
|
+
},
|
|
41
|
+
languageOptions: {
|
|
42
|
+
globals: {
|
|
43
|
+
...globals.node,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
rules: {
|
|
47
|
+
indent: [
|
|
48
|
+
"warn",
|
|
49
|
+
"tab",
|
|
50
|
+
{
|
|
51
|
+
ignoredNodes: ["TemplateLiteral *"],
|
|
52
|
+
SwitchCase: 1,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
"jsdoc/check-tag-names": [
|
|
56
|
+
"warn",
|
|
57
|
+
{
|
|
58
|
+
definedTags: ["jest-environment"],
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
"jsdoc/no-undefined-types": "warn",
|
|
62
|
+
"jsdoc/require-jsdoc": [
|
|
63
|
+
"warn",
|
|
64
|
+
{
|
|
65
|
+
contexts: [
|
|
66
|
+
"ClassDeclaration",
|
|
67
|
+
"PropertyDefinition",
|
|
68
|
+
"MethodDefinition",
|
|
69
|
+
"TSEnumDeclaration",
|
|
70
|
+
"TSEnumMember",
|
|
71
|
+
"TSPropertySignature",
|
|
72
|
+
"TSTypeAliasDeclaration",
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
"@typescript-eslint/explicit-function-return-type": "warn",
|
|
77
|
+
"@typescript-eslint/explicit-member-accessibility": [
|
|
78
|
+
"warn",
|
|
79
|
+
{
|
|
80
|
+
accessibility: "explicit",
|
|
81
|
+
overrides: {
|
|
82
|
+
constructors: "no-public",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
"@typescript-eslint/member-ordering": [
|
|
87
|
+
"warn",
|
|
88
|
+
{
|
|
89
|
+
default: {
|
|
90
|
+
memberTypes: [
|
|
91
|
+
"public-static-field",
|
|
92
|
+
"public-abstract-field",
|
|
93
|
+
"public-field",
|
|
94
|
+
"protected-static-field",
|
|
95
|
+
"protected-abstract-field",
|
|
96
|
+
"protected-field",
|
|
97
|
+
"private-static-field",
|
|
98
|
+
"private-field",
|
|
99
|
+
"public-constructor",
|
|
100
|
+
"protected-constructor",
|
|
101
|
+
"private-constructor",
|
|
102
|
+
"signature",
|
|
103
|
+
"call-signature",
|
|
104
|
+
"public-static-get",
|
|
105
|
+
"public-static-set",
|
|
106
|
+
"public-abstract-get",
|
|
107
|
+
"public-abstract-set",
|
|
108
|
+
"public-get",
|
|
109
|
+
"public-set",
|
|
110
|
+
"protected-static-get",
|
|
111
|
+
"protected-static-set",
|
|
112
|
+
"protected-abstract-get",
|
|
113
|
+
"protected-abstract-set",
|
|
114
|
+
"protected-get",
|
|
115
|
+
"protected-set",
|
|
116
|
+
"private-static-get",
|
|
117
|
+
"private-static-set",
|
|
118
|
+
"private-get",
|
|
119
|
+
"private-set",
|
|
120
|
+
"public-static-method",
|
|
121
|
+
"public-abstract-method",
|
|
122
|
+
"public-method",
|
|
123
|
+
"protected-static-method",
|
|
124
|
+
"protected-abstract-method",
|
|
125
|
+
"protected-method",
|
|
126
|
+
"private-static-method",
|
|
127
|
+
"private-method",
|
|
128
|
+
],
|
|
129
|
+
|
|
130
|
+
order: "alphabetically",
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
"@typescript-eslint/sort-type-constituents": "warn",
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* JavaScript-only rules.
|
|
140
|
+
*/
|
|
141
|
+
{
|
|
142
|
+
files: ["**/*.{js,cjs,mjs}"],
|
|
143
|
+
rules: {
|
|
144
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
145
|
+
"jsdoc/no-types": "off",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Test and mock rules.
|
|
151
|
+
*/
|
|
152
|
+
{
|
|
153
|
+
files: ["{src,tests}/**/__mocks__/*.ts", "{src,tests}/**/__tests__/*test.ts"],
|
|
154
|
+
rules: {
|
|
155
|
+
"jsdoc/require-jsdoc": [
|
|
156
|
+
"warn",
|
|
157
|
+
{
|
|
158
|
+
contexts: ["MethodDefinition"],
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
"@typescript-eslint/explicit-function-return-type": "off",
|
|
162
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
163
|
+
"@typescript-eslint/no-require-imports": "off",
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
]);
|