@so1ve/eslint-plugin 0.108.0 → 0.108.2

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
@@ -503,54 +503,30 @@ const useAsyncWithAwait = createEslintRule({
503
503
  },
504
504
  defaultOptions: [],
505
505
  create: (context) => {
506
- const scopeStack = [];
507
- let haveAwaitExpression = false;
508
- function setupScope() {
509
- scopeStack.push(context.getScope());
506
+ const functionNodeScopeStack = [];
507
+ function setupNode(node) {
508
+ functionNodeScopeStack.push(node);
510
509
  }
511
- function clearAwaitExpression() {
512
- scopeStack.pop();
513
- haveAwaitExpression = false;
510
+ function clearNode() {
511
+ functionNodeScopeStack.pop();
514
512
  }
515
513
  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) {
514
+ "FunctionExpression": setupNode,
515
+ "FunctionExpression:exit": clearNode,
516
+ "FunctionDeclaration": setupNode,
517
+ "FunctionDeclaration:exit": clearNode,
518
+ "ArrowFunctionExpression": setupNode,
519
+ "ArrowFunctionExpression:exit": clearNode,
520
+ AwaitExpression() {
521
+ const closestFunctionNode = functionNodeScopeStack[functionNodeScopeStack.length - 1];
522
+ if (!closestFunctionNode || closestFunctionNode.async) {
543
523
  return;
544
524
  }
545
525
  context.report({
546
- node,
526
+ node: closestFunctionNode,
547
527
  messageId: "useAsyncWithAwait",
548
- fix: (fixer) => fixer.insertTextBefore(node, "async ")
528
+ fix: (fixer) => fixer.insertTextBefore(closestFunctionNode, "async ")
549
529
  });
550
- clearAwaitExpression();
551
- },
552
- AwaitExpression() {
553
- haveAwaitExpression = scopeStack.includes(context.getScope());
554
530
  }
555
531
  };
556
532
  }
package/dist/index.mjs CHANGED
@@ -501,54 +501,30 @@ const useAsyncWithAwait = createEslintRule({
501
501
  },
502
502
  defaultOptions: [],
503
503
  create: (context) => {
504
- const scopeStack = [];
505
- let haveAwaitExpression = false;
506
- function setupScope() {
507
- scopeStack.push(context.getScope());
504
+ const functionNodeScopeStack = [];
505
+ function setupNode(node) {
506
+ functionNodeScopeStack.push(node);
508
507
  }
509
- function clearAwaitExpression() {
510
- scopeStack.pop();
511
- haveAwaitExpression = false;
508
+ function clearNode() {
509
+ functionNodeScopeStack.pop();
512
510
  }
513
511
  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) {
512
+ "FunctionExpression": setupNode,
513
+ "FunctionExpression:exit": clearNode,
514
+ "FunctionDeclaration": setupNode,
515
+ "FunctionDeclaration:exit": clearNode,
516
+ "ArrowFunctionExpression": setupNode,
517
+ "ArrowFunctionExpression:exit": clearNode,
518
+ AwaitExpression() {
519
+ const closestFunctionNode = functionNodeScopeStack[functionNodeScopeStack.length - 1];
520
+ if (!closestFunctionNode || closestFunctionNode.async) {
541
521
  return;
542
522
  }
543
523
  context.report({
544
- node,
524
+ node: closestFunctionNode,
545
525
  messageId: "useAsyncWithAwait",
546
- fix: (fixer) => fixer.insertTextBefore(node, "async ")
526
+ fix: (fixer) => fixer.insertTextBefore(closestFunctionNode, "async ")
547
527
  });
548
- clearAwaitExpression();
549
- },
550
- AwaitExpression() {
551
- haveAwaitExpression = scopeStack.includes(context.getScope());
552
528
  }
553
529
  };
554
530
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@so1ve/eslint-plugin",
3
- "version": "0.108.0",
3
+ "version": "0.108.2",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve/)",
5
5
  "keywords": [
6
6
  "eslint",