Skip to content

Commit f682aff

Browse files
authored
Add base ESLint config (#3)
1 parent 3a4fcde commit f682aff

File tree

5 files changed

+1403
-20
lines changed

5 files changed

+1403
-20
lines changed

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"scripts": {
1212
"all": "concurrently -g pnpm:check-*",
1313
"check-format": "pnpm run _prettier-base --check",
14-
"check-lint": "echo \"not implemented\"",
14+
"check-lint": "eslint \"**/*.@(js|cjs|ts)\"",
1515
"check-types": "tsc",
1616
"format": "pnpm run _prettier-base --write",
1717
"_prettier-base": "prettier \"**/*.@(js|cjs|ts|json|yaml|md)\""
@@ -23,8 +23,15 @@
2323
},
2424
"devDependencies": {
2525
"@types/node": "^18.15.11",
26+
"@typescript-eslint/eslint-plugin": "^5.57.0",
27+
"@typescript-eslint/parser": "^5.57.0",
2628
"concurrently": "^8.0.1",
2729
"eslint": "^8.37.0",
30+
"eslint-config-prettier": "^8.8.0",
31+
"eslint-import-resolver-typescript": "^3.5.4",
32+
"eslint-plugin-import": "^2.27.5",
33+
"eslint-plugin-sonarjs": "^0.19.0",
34+
"eslint-plugin-unicorn": "^46.0.0",
2835
"prettier": "^2.8.7",
2936
"typescript": "^5.0.2"
3037
}

packages/eslint-config/base.cjs

Lines changed: 184 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,186 @@
11
'use strict';
22

3-
module.exports = {};
3+
module.exports = {
4+
parser: '@typescript-eslint/parser',
5+
plugins: ['@typescript-eslint'],
6+
extends: [
7+
'eslint:recommended',
8+
'plugin:@typescript-eslint/recommended',
9+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
10+
'plugin:@typescript-eslint/strict',
11+
'plugin:unicorn/recommended',
12+
'plugin:import/recommended',
13+
'plugin:import/typescript',
14+
'plugin:sonarjs/recommended',
15+
'prettier',
16+
],
17+
parserOptions: {
18+
sourceType: 'module',
19+
ecmaVersion: 'latest',
20+
},
21+
rules: {
22+
// Extra built-in rules
23+
'accessor-pairs': ['error'],
24+
'array-callback-return': ['error', { checkForEach: true }],
25+
camelcase: ['error', { properties: 'never' }],
26+
'class-methods-use-this': ['error'],
27+
curly: ['error', 'all'],
28+
'default-case-last': ['error'],
29+
'default-param-last': ['error'],
30+
eqeqeq: ['error', 'always', { null: 'always' }],
31+
'func-names': 'error',
32+
'func-style': 'error',
33+
'grouped-accessor-pairs': 'error',
34+
'guard-for-in': 'error',
35+
'id-length': [
36+
'error',
37+
{
38+
exceptions: [
39+
'_',
40+
'x',
41+
'y',
42+
'z',
43+
'w',
44+
'r',
45+
'i',
46+
'j',
47+
'k',
48+
'l',
49+
'h',
50+
'a',
51+
'b',
52+
],
53+
},
54+
],
55+
'line-comment-position': 'error',
56+
'lines-between-class-members': 'error',
57+
'logical-assignment-operators': 'error',
58+
'max-classes-per-file': 'error',
59+
'max-depth': 'error',
60+
'max-nested-callbacks': 'error',
61+
'max-statements-per-line': 'error',
62+
'multiline-comment-style': 'error',
63+
'new-cap': 'error',
64+
'no-alert': 'error',
65+
'no-await-in-loop': 'error',
66+
'no-bitwise': 'error',
67+
'no-caller': 'error',
68+
'no-console': 'warn',
69+
'no-constant-binary-expression': 'error',
70+
'no-constructor-return': 'error',
71+
'no-debugger': 'warn',
72+
'no-div-regex': 'error',
73+
'no-duplicate-imports': 'error',
74+
'no-else-return': 'error',
75+
'no-empty-static-block': 'error',
76+
'no-eval': 'error',
77+
'no-extend-native': 'error',
78+
'no-extra-bind': 'error',
79+
'no-extra-label': 'error',
80+
'no-implicit-coercion': 'error',
81+
'no-implicit-globals': 'error',
82+
'no-invalid-this': 'error',
83+
'no-iterator': 'error',
84+
'no-label-var': 'error',
85+
'no-labels': 'error',
86+
'no-lone-blocks': 'error',
87+
'no-lonely-if': 'error',
88+
'no-loop-func': 'error',
89+
'no-multi-assign': 'error',
90+
'no-multi-str': 'error',
91+
'no-new': 'error',
92+
'no-new-func': 'error',
93+
'no-new-native-nonconstructor': 'error',
94+
'no-new-object': 'error',
95+
'no-new-wrappers': 'error',
96+
'no-octal-escape': 'error',
97+
'no-param-reassign': 'error',
98+
'no-plusplus': 'error',
99+
'no-promise-executor-return': 'error',
100+
'no-proto': 'error',
101+
'no-return-assign': 'error',
102+
'no-script-url': 'error',
103+
'no-self-compare': 'error',
104+
'no-sequences': 'error',
105+
'no-template-curly-in-string': 'error',
106+
'no-unneeded-ternary': 'error',
107+
'no-unreachable-loop': 'error',
108+
'no-undef-init': 'error',
109+
'no-underscore-dangle': 'error',
110+
'no-unmodified-loop-condition': 'error',
111+
'no-unused-expressions': 'error',
112+
'no-unused-private-class-members': 'error',
113+
'no-use-before-define': 'error',
114+
'no-useless-call': 'error',
115+
'no-useless-computed-key': 'error',
116+
'no-useless-concat': 'error',
117+
'no-useless-rename': 'error',
118+
'no-useless-return': 'error',
119+
'no-var': 'error',
120+
'no-void': 'error',
121+
'object-shorthand': ['error', 'properties'],
122+
'one-var': ['error', 'never'],
123+
'operator-assignment': 'error',
124+
'padding-line-between-statements': 'error',
125+
'prefer-arrow-callback': 'error',
126+
'prefer-const': 'error',
127+
'prefer-destructuring': [
128+
'error',
129+
{
130+
AssignmentExpression: { object: false, array: false },
131+
VariableDeclarator: { object: true, array: true },
132+
},
133+
],
134+
'prefer-exponentiation-operator': 'error',
135+
'prefer-named-capture-group': 'error',
136+
'prefer-numeric-literals': 'error',
137+
'prefer-object-has-own': 'error',
138+
'prefer-object-spread': 'error',
139+
'prefer-promise-reject-errors': 'error',
140+
'prefer-regex-literals': 'error',
141+
'prefer-rest-params': 'error',
142+
'prefer-spread': 'error',
143+
'prefer-template': 'error',
144+
radix: 'error',
145+
'require-unicode-regexp': 'error',
146+
'require-atomic-updates': 'error',
147+
'spaced-comment': ['error', 'always', { markers: ['/'] }],
148+
strict: 'error',
149+
'symbol-description': 'error',
150+
'vars-on-top': 'error',
151+
yoda: 'error',
152+
153+
// Extra TypeScript rules
154+
'@typescript-eslint/return-await': 'error',
155+
'@typescript-eslint/no-non-null-assertion': 'off',
156+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
157+
158+
// Extra import rules
159+
'import/no-absolute-path': 'error',
160+
'import/no-cycle': 'error',
161+
'import/no-self-import': 'error',
162+
'import/no-useless-path-segments': 'error',
163+
'import/order': 'error',
164+
165+
// Extra Unicorn rules
166+
'unicorn/consistent-destructuring': 'off',
167+
'unicorn/custom-error-definition': 'error',
168+
'unicorn/no-null': 'off',
169+
'unicorn/no-unused-properties': 'error',
170+
'unicorn/prefer-string-replace-all': 'error',
171+
'unicorn/prefer-top-level-await': 'off',
172+
'unicorn/prevent-abbreviations': 'off',
173+
},
174+
overrides: [
175+
// CommonJS files are scripts that are allowed to use `require`
176+
{
177+
files: ['**/*.cjs'],
178+
parserOptions: {
179+
sourceType: 'script',
180+
},
181+
rules: {
182+
'@typescript-eslint/no-var-requires': 'off',
183+
},
184+
},
185+
],
186+
};

packages/eslint-config/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
],
2020
"license": "Apache-2.0",
2121
"peerDependencies": {
22-
"eslint": ">=8 <9"
22+
"@typescript-eslint/eslint-plugin": ">=5 <6",
23+
"@typescript-eslint/parser": ">=5 <6",
24+
"eslint": ">=8 <9",
25+
"eslint-config-prettier": ">=8 <9",
26+
"eslint-import-resolver-typescript": ">=3 <4",
27+
"eslint-plugin-import": ">=2 <3",
28+
"eslint-plugin-sonarjs": ">=0.19 <0.20",
29+
"eslint-plugin-unicorn": ">=46 <47"
2330
}
2431
}

packages/prettier-config/base.cjs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
'use strict';
22

33
module.exports = {
4-
printWidth: 80, // default
5-
tabWidth: 2, // default
6-
useTabs: false, // default
7-
semi: true, // default
4+
// overrides
85
singleQuote: true,
9-
quoteProps: 'as-needed', // default
106
jsxSingleQuote: true,
11-
trailingComma: 'es5', // default
12-
bracketSpacing: true, // default
13-
bracketSameLine: false, //default
14-
arrowParens: 'always', // default
15-
proseWrap: 'preserve', // default
16-
htmlWhitespaceSensitivity: 'css', // default
17-
vueIndentScriptAndStyle: false, // default
18-
endOfLine: 'lf', // default
19-
embeddedLanguageFormatting: 'auto', // default
20-
singleAttributePerLine: false, // default
7+
8+
// default values
9+
printWidth: 80,
10+
tabWidth: 2,
11+
useTabs: false,
12+
semi: true,
13+
quoteProps: 'as-needed',
14+
trailingComma: 'es5',
15+
bracketSpacing: true,
16+
bracketSameLine: false,
17+
arrowParens: 'always',
18+
proseWrap: 'preserve',
19+
htmlWhitespaceSensitivity: 'css',
20+
vueIndentScriptAndStyle: false,
21+
endOfLine: 'lf',
22+
embeddedLanguageFormatting: 'auto',
23+
singleAttributePerLine: false,
2124
};

0 commit comments

Comments
 (0)