Skip to content

Commit 117c066

Browse files
Merge pull request #179 from MaddyGuthridge/maddy-eslint-improvements
Massively improve ESLint config
2 parents 2314c3b + 6ad2e19 commit 117c066

File tree

136 files changed

+714
-519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+714
-519
lines changed

eslint.config.mjs

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ import js from '@eslint/js';
33
import ts from 'typescript-eslint';
44
import svelte from 'eslint-plugin-svelte';
55
import svelteParser from 'svelte-eslint-parser';
6+
import stylistic from '@stylistic/eslint-plugin';
7+
import esNode from 'eslint-plugin-n';
68
import globals from 'globals';
79

810
export default ts.config(
911
js.configs.recommended,
1012
...ts.configs.recommendedTypeChecked,
1113
...ts.configs.stylisticTypeChecked,
1214
...svelte.configs['flat/recommended'],
15+
stylistic.configs.recommended,
16+
{
17+
plugins: {
18+
n: esNode,
19+
},
20+
},
1321
{
1422
languageOptions: {
1523
globals: {
@@ -42,6 +50,33 @@ export default ts.config(
4250
},
4351
{
4452
rules: {
53+
// Default ESLint rules
54+
// ====================
55+
56+
// Use `Promise.all` instead of `await` in a for loop for better async performance
57+
'no-await-in-loop': 'error',
58+
// Don't allow duplicate imports, because they are yucky
59+
'no-duplicate-imports': 'error',
60+
// Common mistake with `new Promise`
61+
'no-promise-executor-return': ['error', { allowVoid: true }],
62+
// Accidentally forgetting to use `back-ticks` for template literals
63+
'no-template-curly-in-string': 'error',
64+
// Use === instead of ==
65+
'eqeqeq': 'error',
66+
// Use dot notation for object property access
67+
'dot-notation': 'error',
68+
// Don't use `alert` and similar functions
69+
'no-alert': 'error',
70+
// Use camelCase for naming
71+
'camelcase': 'error',
72+
// Use `const` over `let` where reasonable
73+
// Not required for destructuring, since that just makes things painful for Svelte props where
74+
// some props are bindable
75+
'prefer-const': ['error', { destructuring: 'all' }],
76+
77+
// @typescript-eslint rules
78+
// ========================
79+
4580
// Allow explicit any, to avoid type gymnastics
4681
'@typescript-eslint/no-explicit-any': 'off',
4782
'@typescript-eslint/no-unused-vars': ['error', {
@@ -50,8 +85,6 @@ export default ts.config(
5085
}],
5186
// Disallow floating promises to avoid random crashes
5287
'@typescript-eslint/no-floating-promises': 'error',
53-
// Single quotes where possible
54-
quotes: ['error', 'single', { 'avoidEscape': true, 'allowTemplateLiterals': false }],
5588
// Allow some `any` expressions since otherwise they seriously mess with tests, or enforce
5689
// strictness in areas where it really doesn't matter (eg error handling)
5790
'@typescript-eslint/no-unsafe-assignment': 'off',
@@ -66,40 +99,49 @@ export default ts.config(
6699
// Allow empty functions, as they are useful to silence promise errors
67100
'@typescript-eslint/no-empty-function': 'off',
68101
// Use `type` instead of `interface`
69-
"@typescript-eslint/consistent-type-definitions": ["error", 'type'],
102+
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
70103
// This error is already picked up by TypeScript, and it's annoying to need to silence it
71104
// twice when it is incorrect
72-
"@typescript-eslint/no-unsafe-call": "off",
73-
// Prevent node standard library imports without `node:` prefix
74-
"no-restricted-imports": ["error", {
105+
'@typescript-eslint/no-unsafe-call': 'off',
106+
'no-restricted-imports': ['error', {
75107
paths: [
76-
{ name: "os", message: "Import from `node:os`" },
77-
{ name: "path", message: "Import from `node:path`" },
78-
{ name: "fs", message: "Import from `node:fs`" },
79-
{ name: "fs/promises", message: "Import from `node:fs/promises`" },
80-
{ name: "svelte/legacy", message: "Avoid legacy Svelte features" },
108+
{ name: 'svelte/legacy', message: 'Avoid legacy Svelte features' },
81109
]
82110
}],
83-
// Use `Promise.all` instead of `await` in a for loop for better async performance
84-
"no-await-in-loop": "error",
85-
// Don't allow duplicate imports, because they are yucky
86-
"no-duplicate-imports": "error",
87-
// Common mistake with `new Promise`
88-
"no-promise-executor-return": ["error", { allowVoid: true }],
89-
// Accidentally forgetting to use `back-ticks` for template literals
90-
"no-template-curly-in-string": "error",
91-
// Use === instead of ==
92-
"eqeqeq": "error",
93-
// Use dot notation for object property access
94-
"dot-notation": "error",
95-
// Don't use `alert` and similar functions
96-
"no-alert": "error",
97-
// Use camelCase for naming
98-
"camelcase": "error",
99-
// Use `const` over `let` where reasonable
100-
// Not required for destructuring, since that just makes things painful for Svelte props where
101-
// some props are bindable
102-
"prefer-const": ["error", { destructuring: "all" }],
111+
112+
// Stylistic ESLint rules
113+
// ======================
114+
115+
// Use semicolons to help prevent weird and wonderful JS quirks
116+
"@stylistic/semi": ["error", "always", { omitLastInOneLineBlock: true }],
117+
// Single quotes where possible
118+
"@stylistic/quotes": ["error", "single", { avoidEscape: true, allowTemplateLiterals: false }],
119+
// Only quote object properties if it'd be a syntax error otherwise
120+
"@stylistic/quote-props": ["error", "as-needed"],
121+
// Use one true brace style
122+
"@stylistic/brace-style": ["error", "1tbs", { "allowSingleLine": true }],
123+
// Always use comma for delimiting type definitions, since it matches object notation
124+
"@stylistic/member-delimiter-style": ["error", {
125+
multiline: {
126+
delimiter: "comma",
127+
requireLast: true,
128+
},
129+
singleline: {
130+
delimiter: "comma",
131+
requireLast: false,
132+
}
133+
}],
134+
135+
// Node (eslint-plugin-n) rules
136+
// ============================
137+
138+
// For bin scripts listed in package.json, require a correct shebang
139+
'n/hashbang': 'error',
140+
// Don't concat to __file and __dirname (this is unsafe, use `path.join` instead)
141+
'n/no-path-concat': 'error',
142+
// Use `node:` prefix when importing from node standard library modules (they don't exist in
143+
// some other runtimes)
144+
'n/prefer-node-protocol': 'error',
103145
},
104146
},
105147
{

package-lock.json

Lines changed: 175 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)