@so1ve/eslint-plugin 0.107.2 → 0.108.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/dist/index.cjs CHANGED
@@ -21,12 +21,12 @@ function getPreviousNode(node) {
21
21
  }
22
22
  }
23
23
 
24
- const RULE_NAME$6 = "function-style";
24
+ const RULE_NAME$7 = "function-style";
25
25
  const START_RETURN = /^return /;
26
26
  const RETURN_ONLY = /^return\s*(?:;\s*)?$/;
27
27
  const END_SEMICOLON = /;$/;
28
28
  const functionStyle = createEslintRule({
29
- name: RULE_NAME$6,
29
+ name: RULE_NAME$7,
30
30
  meta: {
31
31
  type: "problem",
32
32
  docs: {
@@ -76,9 +76,7 @@ const functionStyle = createEslintRule({
76
76
  haveThisAccess = false;
77
77
  }
78
78
  return {
79
- FunctionExpression() {
80
- setupScope();
81
- },
79
+ "FunctionExpression": setupScope,
82
80
  "FunctionExpression:exit"(node) {
83
81
  if (node.parent?.id?.typeAnnotation || node.parent?.type !== types.AST_NODE_TYPES.VariableDeclarator || haveThisAccess) {
84
82
  clearThisAccess();
@@ -95,9 +93,7 @@ const functionStyle = createEslintRule({
95
93
  });
96
94
  clearThisAccess();
97
95
  },
98
- "FunctionDeclaration:not(TSDeclareFunction + FunctionDeclaration)"() {
99
- setupScope();
100
- },
96
+ "FunctionDeclaration:not(TSDeclareFunction + FunctionDeclaration)": setupScope,
101
97
  "FunctionDeclaration:not(TSDeclareFunction + FunctionDeclaration):exit"(node) {
102
98
  if (haveThisAccess) {
103
99
  return;
@@ -134,9 +130,7 @@ const functionStyle = createEslintRule({
134
130
  });
135
131
  clearThisAccess();
136
132
  },
137
- ArrowFunctionExpression() {
138
- setupScope();
139
- },
133
+ "ArrowFunctionExpression": setupScope,
140
134
  "ArrowFunctionExpression:exit"(node) {
141
135
  if (haveThisAccess) {
142
136
  return;
@@ -189,9 +183,9 @@ const functionStyle = createEslintRule({
189
183
  }
190
184
  });
191
185
 
192
- const RULE_NAME$5 = "import-dedupe";
186
+ const RULE_NAME$6 = "import-dedupe";
193
187
  const importDedupe = createEslintRule({
194
- name: RULE_NAME$5,
188
+ name: RULE_NAME$6,
195
189
  meta: {
196
190
  type: "problem",
197
191
  docs: {
@@ -237,14 +231,14 @@ const importDedupe = createEslintRule({
237
231
  })
238
232
  });
239
233
 
240
- const RULE_NAME$4 = "no-import-promises-as";
234
+ const RULE_NAME$5 = "no-import-promises-as";
241
235
  const _POSSIBLE_IMPORT_SOURCES = ["dns", "fs", "readline", "stream"];
242
236
  const POSSIBLE_IMPORT_SOURCES = [
243
237
  ..._POSSIBLE_IMPORT_SOURCES,
244
238
  ..._POSSIBLE_IMPORT_SOURCES.map((s) => `node:${s}`)
245
239
  ];
246
240
  const noImportPromisesAs = createEslintRule({
247
- name: RULE_NAME$4,
241
+ name: RULE_NAME$5,
248
242
  meta: {
249
243
  type: "problem",
250
244
  docs: {
@@ -295,9 +289,9 @@ import ${as} from "${node.source.value}/promises";`
295
289
  }
296
290
  });
297
291
 
298
- const RULE_NAME$3 = "no-inline-type-import";
292
+ const RULE_NAME$4 = "no-inline-type-import";
299
293
  const noInlineTypeImport = createEslintRule({
300
- name: RULE_NAME$3,
294
+ name: RULE_NAME$4,
301
295
  meta: {
302
296
  type: "layout",
303
297
  docs: {
@@ -361,7 +355,7 @@ const noInlineTypeImport = createEslintRule({
361
355
  }
362
356
  });
363
357
 
364
- const RULE_NAME$2 = "no-negated-comparison";
358
+ const RULE_NAME$3 = "no-negated-comparison";
365
359
  const negatedToPositive = {
366
360
  "==": "!=",
367
361
  "===": "!==",
@@ -374,7 +368,7 @@ const negatedToPositive = {
374
368
  };
375
369
  const negatives = Object.keys(negatedToPositive);
376
370
  const noNegatedComparison = createEslintRule({
377
- name: RULE_NAME$2,
371
+ name: RULE_NAME$3,
378
372
  meta: {
379
373
  type: "problem",
380
374
  docs: {
@@ -411,9 +405,9 @@ const noNegatedComparison = createEslintRule({
411
405
  })
412
406
  });
413
407
 
414
- const RULE_NAME$1 = "no-useless-template-string";
408
+ const RULE_NAME$2 = "no-useless-template-string";
415
409
  const noUselessTemplateString = createEslintRule({
416
- name: RULE_NAME$1,
410
+ name: RULE_NAME$2,
417
411
  meta: {
418
412
  type: "problem",
419
413
  docs: {
@@ -449,9 +443,9 @@ const noUselessTemplateString = createEslintRule({
449
443
  })
450
444
  });
451
445
 
452
- const RULE_NAME = "pad-after-last-import";
446
+ const RULE_NAME$1 = "pad-after-last-import";
453
447
  const padAfterLastImport = createEslintRule({
454
- name: RULE_NAME,
448
+ name: RULE_NAME$1,
455
449
  meta: {
456
450
  type: "problem",
457
451
  docs: {
@@ -492,6 +486,76 @@ const padAfterLastImport = createEslintRule({
492
486
  }
493
487
  });
494
488
 
489
+ const RULE_NAME = "use-async-with-await";
490
+ const useAsyncWithAwait = createEslintRule({
491
+ name: RULE_NAME,
492
+ meta: {
493
+ type: "problem",
494
+ docs: {
495
+ description: "Enforce using async keyword with await.",
496
+ recommended: "error"
497
+ },
498
+ fixable: "code",
499
+ schema: [],
500
+ messages: {
501
+ useAsyncWithAwait: "Expect using async keyword with await."
502
+ }
503
+ },
504
+ defaultOptions: [],
505
+ create: (context) => {
506
+ const scopeStack = [];
507
+ let haveAwaitExpression = false;
508
+ function setupScope() {
509
+ scopeStack.push(context.getScope());
510
+ }
511
+ function clearAwaitExpression() {
512
+ scopeStack.pop();
513
+ haveAwaitExpression = false;
514
+ }
515
+ return {
516
+ "FunctionExpression[async=false]": setupScope,
517
+ "FunctionExpression[async=false]:exit"(node) {
518
+ if (!haveAwaitExpression) {
519
+ return;
520
+ }
521
+ context.report({
522
+ node,
523
+ messageId: "useAsyncWithAwait",
524
+ fix: (fixer) => fixer.insertTextBefore(node, "async ")
525
+ });
526
+ clearAwaitExpression();
527
+ },
528
+ "FunctionDeclaration[async=false]": setupScope,
529
+ "FunctionDeclaration[async=false]:exit"(node) {
530
+ if (!haveAwaitExpression) {
531
+ return;
532
+ }
533
+ context.report({
534
+ node,
535
+ messageId: "useAsyncWithAwait",
536
+ fix: (fixer) => fixer.insertTextBefore(node, "async ")
537
+ });
538
+ clearAwaitExpression();
539
+ },
540
+ "ArrowFunctionExpression[async=false]": setupScope,
541
+ "ArrowFunctionExpression[async=false]:exit"(node) {
542
+ if (!haveAwaitExpression) {
543
+ return;
544
+ }
545
+ context.report({
546
+ node,
547
+ messageId: "useAsyncWithAwait",
548
+ fix: (fixer) => fixer.insertTextBefore(node, "async ")
549
+ });
550
+ clearAwaitExpression();
551
+ },
552
+ AwaitExpression() {
553
+ haveAwaitExpression = scopeStack.includes(context.getScope());
554
+ }
555
+ };
556
+ }
557
+ });
558
+
495
559
  const index = {
496
560
  rules: {
497
561
  "function-style": functionStyle,
@@ -500,7 +564,8 @@ const index = {
500
564
  "no-negated-comparison": noNegatedComparison,
501
565
  "no-useless-template-string": noUselessTemplateString,
502
566
  "no-import-promises-as": noImportPromisesAs,
503
- "pad-after-last-import": padAfterLastImport
567
+ "pad-after-last-import": padAfterLastImport,
568
+ "use-async-with-await": useAsyncWithAwait
504
569
  }
505
570
  };
506
571
 
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ declare const _default: {
11
11
  "no-useless-template-string": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noUselessTemplateString", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
12
12
  "no-import-promises-as": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noImportPromisesAs", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
13
13
  "pad-after-last-import": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"padAfterLastImport", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
14
+ "use-async-with-await": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"useAsyncWithAwait", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
14
15
  };
15
16
  };
16
17
 
package/dist/index.mjs CHANGED
@@ -19,12 +19,12 @@ function getPreviousNode(node) {
19
19
  }
20
20
  }
21
21
 
22
- const RULE_NAME$6 = "function-style";
22
+ const RULE_NAME$7 = "function-style";
23
23
  const START_RETURN = /^return /;
24
24
  const RETURN_ONLY = /^return\s*(?:;\s*)?$/;
25
25
  const END_SEMICOLON = /;$/;
26
26
  const functionStyle = createEslintRule({
27
- name: RULE_NAME$6,
27
+ name: RULE_NAME$7,
28
28
  meta: {
29
29
  type: "problem",
30
30
  docs: {
@@ -74,9 +74,7 @@ const functionStyle = createEslintRule({
74
74
  haveThisAccess = false;
75
75
  }
76
76
  return {
77
- FunctionExpression() {
78
- setupScope();
79
- },
77
+ "FunctionExpression": setupScope,
80
78
  "FunctionExpression:exit"(node) {
81
79
  if (node.parent?.id?.typeAnnotation || node.parent?.type !== AST_NODE_TYPES.VariableDeclarator || haveThisAccess) {
82
80
  clearThisAccess();
@@ -93,9 +91,7 @@ const functionStyle = createEslintRule({
93
91
  });
94
92
  clearThisAccess();
95
93
  },
96
- "FunctionDeclaration:not(TSDeclareFunction + FunctionDeclaration)"() {
97
- setupScope();
98
- },
94
+ "FunctionDeclaration:not(TSDeclareFunction + FunctionDeclaration)": setupScope,
99
95
  "FunctionDeclaration:not(TSDeclareFunction + FunctionDeclaration):exit"(node) {
100
96
  if (haveThisAccess) {
101
97
  return;
@@ -132,9 +128,7 @@ const functionStyle = createEslintRule({
132
128
  });
133
129
  clearThisAccess();
134
130
  },
135
- ArrowFunctionExpression() {
136
- setupScope();
137
- },
131
+ "ArrowFunctionExpression": setupScope,
138
132
  "ArrowFunctionExpression:exit"(node) {
139
133
  if (haveThisAccess) {
140
134
  return;
@@ -187,9 +181,9 @@ const functionStyle = createEslintRule({
187
181
  }
188
182
  });
189
183
 
190
- const RULE_NAME$5 = "import-dedupe";
184
+ const RULE_NAME$6 = "import-dedupe";
191
185
  const importDedupe = createEslintRule({
192
- name: RULE_NAME$5,
186
+ name: RULE_NAME$6,
193
187
  meta: {
194
188
  type: "problem",
195
189
  docs: {
@@ -235,14 +229,14 @@ const importDedupe = createEslintRule({
235
229
  })
236
230
  });
237
231
 
238
- const RULE_NAME$4 = "no-import-promises-as";
232
+ const RULE_NAME$5 = "no-import-promises-as";
239
233
  const _POSSIBLE_IMPORT_SOURCES = ["dns", "fs", "readline", "stream"];
240
234
  const POSSIBLE_IMPORT_SOURCES = [
241
235
  ..._POSSIBLE_IMPORT_SOURCES,
242
236
  ..._POSSIBLE_IMPORT_SOURCES.map((s) => `node:${s}`)
243
237
  ];
244
238
  const noImportPromisesAs = createEslintRule({
245
- name: RULE_NAME$4,
239
+ name: RULE_NAME$5,
246
240
  meta: {
247
241
  type: "problem",
248
242
  docs: {
@@ -293,9 +287,9 @@ import ${as} from "${node.source.value}/promises";`
293
287
  }
294
288
  });
295
289
 
296
- const RULE_NAME$3 = "no-inline-type-import";
290
+ const RULE_NAME$4 = "no-inline-type-import";
297
291
  const noInlineTypeImport = createEslintRule({
298
- name: RULE_NAME$3,
292
+ name: RULE_NAME$4,
299
293
  meta: {
300
294
  type: "layout",
301
295
  docs: {
@@ -359,7 +353,7 @@ const noInlineTypeImport = createEslintRule({
359
353
  }
360
354
  });
361
355
 
362
- const RULE_NAME$2 = "no-negated-comparison";
356
+ const RULE_NAME$3 = "no-negated-comparison";
363
357
  const negatedToPositive = {
364
358
  "==": "!=",
365
359
  "===": "!==",
@@ -372,7 +366,7 @@ const negatedToPositive = {
372
366
  };
373
367
  const negatives = Object.keys(negatedToPositive);
374
368
  const noNegatedComparison = createEslintRule({
375
- name: RULE_NAME$2,
369
+ name: RULE_NAME$3,
376
370
  meta: {
377
371
  type: "problem",
378
372
  docs: {
@@ -409,9 +403,9 @@ const noNegatedComparison = createEslintRule({
409
403
  })
410
404
  });
411
405
 
412
- const RULE_NAME$1 = "no-useless-template-string";
406
+ const RULE_NAME$2 = "no-useless-template-string";
413
407
  const noUselessTemplateString = createEslintRule({
414
- name: RULE_NAME$1,
408
+ name: RULE_NAME$2,
415
409
  meta: {
416
410
  type: "problem",
417
411
  docs: {
@@ -447,9 +441,9 @@ const noUselessTemplateString = createEslintRule({
447
441
  })
448
442
  });
449
443
 
450
- const RULE_NAME = "pad-after-last-import";
444
+ const RULE_NAME$1 = "pad-after-last-import";
451
445
  const padAfterLastImport = createEslintRule({
452
- name: RULE_NAME,
446
+ name: RULE_NAME$1,
453
447
  meta: {
454
448
  type: "problem",
455
449
  docs: {
@@ -490,6 +484,76 @@ const padAfterLastImport = createEslintRule({
490
484
  }
491
485
  });
492
486
 
487
+ const RULE_NAME = "use-async-with-await";
488
+ const useAsyncWithAwait = createEslintRule({
489
+ name: RULE_NAME,
490
+ meta: {
491
+ type: "problem",
492
+ docs: {
493
+ description: "Enforce using async keyword with await.",
494
+ recommended: "error"
495
+ },
496
+ fixable: "code",
497
+ schema: [],
498
+ messages: {
499
+ useAsyncWithAwait: "Expect using async keyword with await."
500
+ }
501
+ },
502
+ defaultOptions: [],
503
+ create: (context) => {
504
+ const scopeStack = [];
505
+ let haveAwaitExpression = false;
506
+ function setupScope() {
507
+ scopeStack.push(context.getScope());
508
+ }
509
+ function clearAwaitExpression() {
510
+ scopeStack.pop();
511
+ haveAwaitExpression = false;
512
+ }
513
+ return {
514
+ "FunctionExpression[async=false]": setupScope,
515
+ "FunctionExpression[async=false]:exit"(node) {
516
+ if (!haveAwaitExpression) {
517
+ return;
518
+ }
519
+ context.report({
520
+ node,
521
+ messageId: "useAsyncWithAwait",
522
+ fix: (fixer) => fixer.insertTextBefore(node, "async ")
523
+ });
524
+ clearAwaitExpression();
525
+ },
526
+ "FunctionDeclaration[async=false]": setupScope,
527
+ "FunctionDeclaration[async=false]:exit"(node) {
528
+ if (!haveAwaitExpression) {
529
+ return;
530
+ }
531
+ context.report({
532
+ node,
533
+ messageId: "useAsyncWithAwait",
534
+ fix: (fixer) => fixer.insertTextBefore(node, "async ")
535
+ });
536
+ clearAwaitExpression();
537
+ },
538
+ "ArrowFunctionExpression[async=false]": setupScope,
539
+ "ArrowFunctionExpression[async=false]:exit"(node) {
540
+ if (!haveAwaitExpression) {
541
+ return;
542
+ }
543
+ context.report({
544
+ node,
545
+ messageId: "useAsyncWithAwait",
546
+ fix: (fixer) => fixer.insertTextBefore(node, "async ")
547
+ });
548
+ clearAwaitExpression();
549
+ },
550
+ AwaitExpression() {
551
+ haveAwaitExpression = scopeStack.includes(context.getScope());
552
+ }
553
+ };
554
+ }
555
+ });
556
+
493
557
  const index = {
494
558
  rules: {
495
559
  "function-style": functionStyle,
@@ -498,7 +562,8 @@ const index = {
498
562
  "no-negated-comparison": noNegatedComparison,
499
563
  "no-useless-template-string": noUselessTemplateString,
500
564
  "no-import-promises-as": noImportPromisesAs,
501
- "pad-after-last-import": padAfterLastImport
565
+ "pad-after-last-import": padAfterLastImport,
566
+ "use-async-with-await": useAsyncWithAwait
502
567
  }
503
568
  };
504
569
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@so1ve/eslint-plugin",
3
- "version": "0.107.2",
3
+ "version": "0.108.0",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve/)",
5
5
  "keywords": [
6
6
  "eslint",