lint-rules-alvin 2.2.0 → 2.2.1

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.
@@ -13,4 +13,4 @@
13
13
  "typescriptreact"
14
14
  ],
15
15
  "typescript.tsdk": "node_modules\\typescript\\lib"
16
- }
16
+ }
@@ -3,7 +3,7 @@
3
3
  "format_on_save": "on",
4
4
  "formatter": {
5
5
  "code_actions": {
6
- "source.fixAll.eslint": true,
7
- },
6
+ "source.fixAll.eslint": true
7
+ }
8
8
  }
9
9
  }
@@ -4,14 +4,11 @@ import { importX as eslintPluginImportX } from 'eslint-plugin-import-x';
4
4
  /**
5
5
  * The ESLint import config. Configures all rules.
6
6
  */
7
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
8
7
  export const importX: TSESLint.FlatConfig.Config = {
9
8
  name: 'eslint-plugin-import-x',
10
-
11
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
12
9
  plugins: { 'import-x': eslintPluginImportX },
13
- // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
14
10
  ...eslintPluginImportX.flatConfigs.typescript,
11
+ files: [ '**/*.{js,ts}' ],
15
12
  settings: {
16
13
  'import-x/resolver': {
17
14
  typescript: true,
@@ -5,7 +5,8 @@ export const custom: TSESLint.FlatConfig.Config;
5
5
  export const importX: TSESLint.FlatConfig.Config;
6
6
  export const json: TSESLint.FlatConfig.ConfigArray;
7
7
  export const markdown: TSESLint.FlatConfig.Config;
8
+ export const perfectionist: TSESLint.FlatConfig.Config;
8
9
  export const reactHooks: TSESLint.FlatConfig.Config;
9
10
  export const stylistic: TSESLint.FlatConfig.Config;
10
11
  export const sveltekit: TSESLint.FlatConfig.ConfigArray;
11
- export const typescript: TSESLint.FlatConfig.Config;
12
+ export const typescript: TSESLint.FlatConfig.Config;
@@ -4,6 +4,7 @@ export { custom } from './custom';
4
4
  export { importX } from './importX';
5
5
  export { json } from './json';
6
6
  export { markdown } from './markdown';
7
+ export { perfectionist } from './perfectionist';
7
8
  export { reactHooks } from './reactHooks';
8
9
  export { stylistic } from './stylistic';
9
10
  export { sveltekit } from './sveltekit';
@@ -0,0 +1,8 @@
1
+ import { TSESLint } from '@typescript-eslint/utils';
2
+ import eslintPluginPerfectionist from 'eslint-plugin-perfectionist';
3
+
4
+ export const perfectionist: TSESLint.FlatConfig.Config = {
5
+ name: 'eslint-plugin-perfectionist',
6
+ plugins: { eslintPluginPerfectionist },
7
+ ...eslintPluginPerfectionist.configs['recommended-natural']
8
+ };
@@ -179,19 +179,6 @@ export const stylistic: TSESLint.FlatConfig.Config = {
179
179
  'error',
180
180
  { component: true }
181
181
  ],
182
- '@stylistic/jsx-sort-props': [
183
- 'error',
184
- {
185
- ignoreCase: false,
186
- callbacksLast: true,
187
- shorthandFirst: true,
188
- shorthandLast: false,
189
- multiline: 'ignore',
190
- noSortAlphabetically: true,
191
- reservedFirst: true,
192
- locale: 'en'
193
- }
194
- ],
195
182
  '@stylistic/jsx-tag-spacing': [
196
183
  'error',
197
184
  {
@@ -60,9 +60,8 @@ export const jsxMultilinePropNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
60
60
 
61
61
  // Only enforce for JSX props (attributes), not for children
62
62
  /* eslint-disable-next-line
63
- @typescript-eslint/no-unnecessary-condition,
64
- @typescript-eslint/strict-boolean-expressions */
65
- if (!node?.parent || node.parent.type !== AST_NODE_TYPES.JSXAttribute)
63
+ @typescript-eslint/no-unnecessary-condition */
64
+ if (node?.parent?.type !== AST_NODE_TYPES.JSXAttribute)
66
65
  return;
67
66
 
68
67
  const expr = node.expression;
@@ -113,7 +112,7 @@ export const jsxMultilinePropNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
113
112
  context.report({
114
113
  node: openBrace,
115
114
  messageId: 'collapse',
116
- fix: (fixer) => fixer.removeRange([
115
+ fix: (fixer)=> fixer.removeRange([
117
116
  openBrace.range[1],
118
117
  firstTokenOfExpr.range[0]
119
118
  ])
@@ -133,7 +132,7 @@ export const jsxMultilinePropNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
133
132
  context.report({
134
133
  node: closeBrace,
135
134
  messageId: 'collapse',
136
- fix: (fixer) => fixer.removeRange([
135
+ fix: (fixer)=> fixer.removeRange([
137
136
  lastTokenOfExpr.range[1],
138
137
  closeBrace.range[0]
139
138
  ])
@@ -160,7 +159,7 @@ export const jsxMultilinePropNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
160
159
  context.report({
161
160
  node: openBrace,
162
161
  messageId: 'expand',
163
- fix: (fixer) => fixer.insertTextAfter(
162
+ fix: (fixer)=> fixer.insertTextAfter(
164
163
  openBrace,
165
164
  '\n'
166
165
  )
@@ -180,7 +179,7 @@ export const jsxMultilinePropNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
180
179
  context.report({
181
180
  node: closeBrace,
182
181
  messageId: 'expand',
183
- fix: (fixer) => fixer.insertTextBefore(
182
+ fix: (fixer)=> fixer.insertTextBefore(
184
183
  closeBrace,
185
184
  '\n'
186
185
  )
@@ -207,7 +206,7 @@ export const jsxMultilinePropNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
207
206
  context.report({
208
207
  node: openBrace,
209
208
  messageId: 'collapse',
210
- fix: (fixer) => fixer.removeRange([
209
+ fix: (fixer)=> fixer.removeRange([
211
210
  openBrace.range[1],
212
211
  firstTokenOfExpr.range[0]
213
212
  ])
@@ -227,7 +226,7 @@ export const jsxMultilinePropNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
227
226
  context.report({
228
227
  node: closeBrace,
229
228
  messageId: 'collapse',
230
- fix: (fixer) => fixer.removeRange([
229
+ fix: (fixer)=> fixer.removeRange([
231
230
  lastTokenOfExpr.range[1],
232
231
  closeBrace.range[0]
233
232
  ])
@@ -173,7 +173,7 @@ export const maxChainPerLineRule = ESLintUtils.RuleCreator.withoutDocs({
173
173
  // Find the dot separator for this link.
174
174
  const separatorToken = sourceCode.getTokenBefore(
175
175
  linkNode.property,
176
- { filter: (token) => token.value === '.' || token.value === '?.' }
176
+ { filter: (token)=> token.value === '.' || token.value === '?.' }
177
177
  );
178
178
 
179
179
  // If we couldn't find the separator token, bail out for safety.
@@ -199,7 +199,7 @@ export const maxChainPerLineRule = ESLintUtils.RuleCreator.withoutDocs({
199
199
  node: linkNode.property,
200
200
  loc: separatorToken.loc,
201
201
  messageId: 'expand',
202
- fix: (fixer) => fixer.insertTextBefore(
202
+ fix: (fixer)=> fixer.insertTextBefore(
203
203
  separatorToken,
204
204
  `\n${baseIndent}`
205
205
  )
@@ -218,7 +218,7 @@ export const maxChainPerLineRule = ESLintUtils.RuleCreator.withoutDocs({
218
218
  const previousNode = linkNode.object;
219
219
  const separatorToken2 = sourceCode.getTokenBefore(
220
220
  linkNode.property,
221
- { filter: (token) => token.value === '.' || token.value === '?.' }
221
+ { filter: (token)=> token.value === '.' || token.value === '?.' }
222
222
  );
223
223
  if (!separatorToken2)
224
224
  continue;
@@ -241,7 +241,7 @@ export const maxChainPerLineRule = ESLintUtils.RuleCreator.withoutDocs({
241
241
  node: linkNode.property,
242
242
  loc: separatorToken2.loc,
243
243
  messageId: 'collapse',
244
- fix: (fixer) => {
244
+ fix: (fixer)=> {
245
245
 
246
246
  const between = sourceCode.text.slice(
247
247
  from,
@@ -255,11 +255,9 @@ export const maxChainPerLineRule = ESLintUtils.RuleCreator.withoutDocs({
255
255
 
256
256
  }
257
257
 
258
- const segments = between.split(
259
- /\r\n|\r|\n/
260
- );
258
+ const segments = between.split(/\r\n|\r|\n/);
261
259
 
262
- let collapsed = '';
260
+ let collapsed;
263
261
 
264
262
  if (segments.length === 1) {
265
263
 
@@ -24,7 +24,7 @@ export const multilineArrayAccessorNewlineRule = ESLintUtils.RuleCreator.without
24
24
 
25
25
  const openBracket = sourceCode.getTokenAfter(
26
26
  node.object,
27
- { filter: (t) => t.value === '[' }
27
+ { filter: (t)=> t.value === '[' }
28
28
  );
29
29
 
30
30
  if (!openBracket) {
@@ -199,7 +199,7 @@ export const multilineArrayAccessorNewlineRule = ESLintUtils.RuleCreator.without
199
199
  context.report({
200
200
  node: openBracket,
201
201
  messageId: 'expandAfter',
202
- fix: (fixer) => fixer.insertTextAfter(
202
+ fix: (fixer)=> fixer.insertTextAfter(
203
203
  openBracket,
204
204
  '\n'
205
205
  )
@@ -221,7 +221,7 @@ export const multilineArrayAccessorNewlineRule = ESLintUtils.RuleCreator.without
221
221
  context.report({
222
222
  node: closeBracket,
223
223
  messageId: 'expandBefore',
224
- fix: (fixer) => fixer.insertTextBefore(
224
+ fix: (fixer)=> fixer.insertTextBefore(
225
225
  closeBracket,
226
226
  '\n'
227
227
  )
@@ -73,7 +73,7 @@ export const multilineParenNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
73
73
 
74
74
  const openParen = sourceCode.getTokenAfter(
75
75
  callee,
76
- { filter: (t) => t.value === '(' }
76
+ { filter: (t)=> t.value === '(' }
77
77
  );
78
78
 
79
79
  if (!openParen) { // e.g. `new Date`
@@ -229,12 +229,11 @@ export const multilineParenNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
229
229
  const contentIsSingleLine = node.arguments.length === 0
230
230
  ? true
231
231
  : Boolean(
232
- firstTokenOfFirstArg && lastTokenOfLastArg
233
- && firstTokenOfFirstArg
232
+ firstTokenOfFirstArg && firstTokenOfFirstArg
234
233
  .loc
235
234
  .start
236
235
  .line === lastTokenOfLastArg
237
- .loc
236
+ ?.loc
238
237
  .end
239
238
  .line
240
239
  );
@@ -345,11 +344,11 @@ export const multilineParenNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
345
344
  if (firstArg) {
346
345
 
347
346
  if (
348
- firstTokenOfFirstArg && openParen
347
+ openParen
349
348
  .loc
350
349
  .end
351
350
  .line === firstTokenOfFirstArg
352
- .loc
351
+ ?.loc
353
352
  .start
354
353
  .line
355
354
  ) {
@@ -357,7 +356,7 @@ export const multilineParenNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
357
356
  context.report({
358
357
  node: openParen,
359
358
  messageId: 'expandAfter',
360
- fix: (fixer) => fixer.insertTextAfter(
359
+ fix: (fixer)=> fixer.insertTextAfter(
361
360
  openParen,
362
361
  '\n'
363
362
  )
@@ -374,8 +373,8 @@ export const multilineParenNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
374
373
  if (lastArg) {
375
374
 
376
375
  if (
377
- lastTokenOfLastArg && lastTokenOfLastArg
378
- .loc
376
+ lastTokenOfLastArg
377
+ ?.loc
379
378
  .end
380
379
  .line === closeParen
381
380
  .loc
@@ -386,7 +385,7 @@ export const multilineParenNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
386
385
  context.report({
387
386
  node: closeParen,
388
387
  messageId: 'expandBefore',
389
- fix: (fixer) => fixer.insertTextBefore(
388
+ fix: (fixer)=> fixer.insertTextBefore(
390
389
  closeParen,
391
390
  '\n'
392
391
  )
@@ -477,12 +476,11 @@ export const multilineParenNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
477
476
  const lastTokenOfNode = sourceCode.getLastToken(node);
478
477
 
479
478
  const contentIsSingleLine = Boolean(
480
- firstTokenOfNode && lastTokenOfNode
481
- && firstTokenOfNode
479
+ firstTokenOfNode && firstTokenOfNode
482
480
  .loc
483
481
  .start
484
482
  .line === lastTokenOfNode
485
- .loc
483
+ ?.loc
486
484
  .end
487
485
  .line
488
486
  );
@@ -568,11 +566,11 @@ export const multilineParenNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
568
566
  }
569
567
 
570
568
  if (
571
- firstTokenOfNode && openParen
569
+ openParen
572
570
  .loc
573
571
  .end
574
572
  .line === firstTokenOfNode
575
- .loc
573
+ ?.loc
576
574
  .start
577
575
  .line
578
576
  ) {
@@ -580,7 +578,7 @@ export const multilineParenNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
580
578
  context.report({
581
579
  node: openParen,
582
580
  messageId: 'expandAfter',
583
- fix: (fixer) => fixer.insertTextAfter(
581
+ fix: (fixer)=> fixer.insertTextAfter(
584
582
  openParen,
585
583
  '\n'
586
584
  )
@@ -589,8 +587,8 @@ export const multilineParenNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
589
587
  }
590
588
 
591
589
  if (
592
- lastTokenOfNode && lastTokenOfNode
593
- .loc
590
+ lastTokenOfNode
591
+ ?.loc
594
592
  .end
595
593
  .line === closeParen
596
594
  .loc
@@ -601,7 +599,7 @@ export const multilineParenNewlineRule = ESLintUtils.RuleCreator.withoutDocs({
601
599
  context.report({
602
600
  node: closeParen,
603
601
  messageId: 'expandBefore',
604
- fix: (fixer) => fixer.insertTextBefore(
602
+ fix: (fixer)=> fixer.insertTextBefore(
605
603
  closeParen,
606
604
  '\n'
607
605
  )
@@ -32,7 +32,7 @@ export const newlineBetweenImportsRule = ESLintUtils.RuleCreator.withoutDocs({
32
32
  return {
33
33
  ImportDeclaration(node) {
34
34
 
35
- const specifiers = node.specifiers.filter((specifier) => specifier.type === AST_NODE_TYPES.ImportSpecifier);
35
+ const specifiers = node.specifiers.filter((specifier)=> specifier.type === AST_NODE_TYPES.ImportSpecifier);
36
36
 
37
37
  if (specifiers.length < minItems) {
38
38
 
@@ -20,7 +20,7 @@ export const unnamedImportsLastRule = ESLintUtils.RuleCreator.withoutDocs({
20
20
  'Program:exit'(program) {
21
21
 
22
22
  const sourceCode = context.sourceCode;
23
- const allImports = program.body.filter((node) => node.type === AST_NODE_TYPES.ImportDeclaration);
23
+ const allImports = program.body.filter((node)=> node.type === AST_NODE_TYPES.ImportDeclaration);
24
24
 
25
25
  if (allImports.length < 2) {
26
26
 
@@ -28,8 +28,8 @@ export const unnamedImportsLastRule = ESLintUtils.RuleCreator.withoutDocs({
28
28
 
29
29
  }
30
30
 
31
- const regularImports = allImports.filter((node) => node.specifiers.length > 0);
32
- const sideEffectImports = allImports.filter((node) => node.specifiers.length === 0);
31
+ const regularImports = allImports.filter((node)=> node.specifiers.length > 0);
32
+ const sideEffectImports = allImports.filter((node)=> node.specifiers.length === 0);
33
33
 
34
34
  if (regularImports.length === 0 || sideEffectImports.length === 0) {
35
35
 
@@ -39,7 +39,7 @@ export const unnamedImportsLastRule = ESLintUtils.RuleCreator.withoutDocs({
39
39
 
40
40
  const lastRegularImport = regularImports[regularImports.length - 1];
41
41
 
42
- const misplacedImports = sideEffectImports.filter((node) => node.range[0] < lastRegularImport.range[0]);
42
+ const misplacedImports = sideEffectImports.filter((node)=> node.range[0] < lastRegularImport.range[0]);
43
43
 
44
44
  if (misplacedImports.length === 0) {
45
45
 
@@ -12,6 +12,7 @@ import { typescript } from '../configs/typescript';
12
12
  import { reactHooks } from '../configs/reactHooks';
13
13
  import { stylistic } from '../configs/stylistic';
14
14
  import { importX } from '../configs/importX';
15
+ import { perfectionist } from '../configs/perfectionist';
15
16
 
16
17
  /**
17
18
  * The `ESLint` Astro/React config with typescript.
@@ -27,6 +28,7 @@ export const astroReactPreset = defineConfig(
27
28
  } as any,
28
29
  reactHooks as any,
29
30
  stylistic as any,
31
+ perfectionist as any,
30
32
  custom as any,
31
33
  {
32
34
  name: 'eslint-plugin-astro-stylistic-override',
@@ -7,6 +7,7 @@ import { base } from '../configs/base';
7
7
  import { importX } from '../configs/importX';
8
8
  import { sveltekit } from '../configs/sveltekit';
9
9
  import { stylistic } from '../configs/stylistic';
10
+ import { perfectionist } from '../configs/perfectionist';
10
11
  import { custom } from '../configs/custom';
11
12
  import { typescript } from '../configs/typescript';
12
13
 
@@ -23,6 +24,7 @@ export const sveltekitPreset = defineConfig(
23
24
 
24
25
  } as Linter.Config,
25
26
  stylistic as Linter.Config,
27
+ perfectionist as Linter.Config,
26
28
  custom as Linter.Config,
27
29
  {
28
30
  name: 'sveltekit-override',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-rules-alvin",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "My own personal linting ruleset for a bunch of different plugins. Includes a few custom rules. Used in a few of my repos.",
5
5
  "keywords": [
6
6
  "eslint"
@@ -41,14 +41,15 @@
41
41
  "eslint-plugin-astro": "^1.6.0",
42
42
  "eslint-plugin-import-x": "^4.16.2",
43
43
  "eslint-plugin-jsonc": "^3.1.2",
44
+ "eslint-plugin-perfectionist": "^5.6.0",
44
45
  "eslint-plugin-react-hooks": "^7.0.1",
45
46
  "eslint-plugin-svelte": "^3.15.2",
46
47
  "eslint-plugin-vue": "^10.8.0",
47
48
  "globals": "^17.4.0",
48
49
  "jiti": "^2.6.1",
49
50
  "mocha": "^11.7.5",
50
- "ts-node": "^10.9.2",
51
51
  "svelte": "^5.53.11",
52
+ "ts-node": "^10.9.2",
52
53
  "typescript": "^5.9.3",
53
54
  "typescript-eslint": "^8.57.0"
54
55
  },
@@ -68,6 +69,7 @@
68
69
  "eslint-plugin-astro": "^1",
69
70
  "eslint-plugin-import-x": "^4",
70
71
  "eslint-plugin-jsonc": "^3",
72
+ "eslint-plugin-perfectionist": "^5",
71
73
  "eslint-plugin-react-hooks": "^7",
72
74
  "eslint-plugin-svelte": "^3",
73
75
  "eslint-plugin-vue": "^10",
@@ -119,6 +121,9 @@
119
121
  "eslint-plugin-jsonc": {
120
122
  "optional": true
121
123
  },
124
+ "eslint-plugin-perfectionist": {
125
+ "optional": true
126
+ },
122
127
  "eslint-plugin-react-hooks": {
123
128
  "optional": true
124
129
  },
@@ -15,4 +15,4 @@
15
15
  "test/**/*.ts",
16
16
  "eslint/custom_rules/**/*.ts"
17
17
  ]
18
- }
18
+ }