@so1ve/eslint-plugin 1.4.0 → 1.5.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.
package/dist/index.cjs CHANGED
@@ -39,7 +39,7 @@ const functionStyle = createEslintRule({
39
39
  },
40
40
  defaultOptions: [],
41
41
  create: (context) => {
42
- const sourceCode = context.getSourceCode();
42
+ const sourceCode = context.sourceCode;
43
43
  function getLoneReturnStatement(node) {
44
44
  const { body } = node;
45
45
  if (body.type !== types.AST_NODE_TYPES.BlockStatement) {
@@ -70,8 +70,8 @@ const functionStyle = createEslintRule({
70
70
  }
71
71
  const scopeStack = [];
72
72
  let haveThisAccess = false;
73
- function setupScope() {
74
- scopeStack.push(context.getScope());
73
+ function setupScope(node) {
74
+ scopeStack.push(sourceCode.getScope(node));
75
75
  }
76
76
  function clearThisAccess() {
77
77
  scopeStack.pop();
@@ -161,8 +161,8 @@ const functionStyle = createEslintRule({
161
161
  }
162
162
  clearThisAccess();
163
163
  },
164
- ThisExpression() {
165
- haveThisAccess = scopeStack.includes(context.getScope());
164
+ ThisExpression(node) {
165
+ haveThisAccess = scopeStack.includes(sourceCode.getScope(node));
166
166
  }
167
167
  };
168
168
  }
@@ -203,7 +203,7 @@ const importDedupe = createEslintRule({
203
203
  fix(fixer) {
204
204
  const start = n.range[0];
205
205
  let end = n.range[1];
206
- const nextToken = context.getSourceCode().getTokenAfter(n);
206
+ const nextToken = context.sourceCode.getTokenAfter(n);
207
207
  if (nextToken && nextToken.value === ",") {
208
208
  end = nextToken.range[1];
209
209
  }
@@ -239,7 +239,7 @@ const noImportPromisesAs = createEslintRule({
239
239
  },
240
240
  defaultOptions: [],
241
241
  create: (context) => {
242
- const sourceCode = context.getSourceCode();
242
+ const sourceCode = context.sourceCode;
243
243
  const { text } = sourceCode;
244
244
  return {
245
245
  ImportDeclaration(node) {
@@ -292,7 +292,7 @@ const noInlineTypeImport = createEslintRule({
292
292
  },
293
293
  defaultOptions: [],
294
294
  create: (context) => {
295
- const sourceCode = context.getSourceCode();
295
+ const sourceCode = context.sourceCode;
296
296
  return {
297
297
  ImportDeclaration: (node) => {
298
298
  const { specifiers } = node;
@@ -446,7 +446,7 @@ const padAfterLastImport = createEslintRule({
446
446
  },
447
447
  defaultOptions: [],
448
448
  create: (context) => {
449
- const sourceCode = context.getSourceCode();
449
+ const sourceCode = context.sourceCode;
450
450
  let lastImportNode = null;
451
451
  return {
452
452
  ImportDeclaration(node) {
@@ -472,19 +472,19 @@ const padAfterLastImport = createEslintRule({
472
472
  }
473
473
  });
474
474
 
475
- const RULE_NAME = "use-async-with-await";
476
- const useAsyncWithAwait = createEslintRule({
475
+ const RULE_NAME = "require-async-with-await";
476
+ const requireAsyncWithAwait = createEslintRule({
477
477
  name: RULE_NAME,
478
478
  meta: {
479
479
  type: "problem",
480
480
  docs: {
481
- description: "Enforce using async keyword with await.",
481
+ description: "Require using async keyword with await.",
482
482
  recommended: "recommended"
483
483
  },
484
484
  fixable: "code",
485
485
  schema: [],
486
486
  messages: {
487
- useAsyncWithAwait: "Expect using async keyword with await."
487
+ requireAsyncWithAwait: "Expect using async keyword with await."
488
488
  }
489
489
  },
490
490
  defaultOptions: [],
@@ -504,17 +504,30 @@ const useAsyncWithAwait = createEslintRule({
504
504
  "ArrowFunctionExpression": setupNode,
505
505
  "ArrowFunctionExpression:exit": clearNode,
506
506
  AwaitExpression() {
507
- const closestFunctionNode = functionNodeStack[functionNodeStack.length - 1];
508
- if (!closestFunctionNode || closestFunctionNode.async) {
507
+ const node = functionNodeStack[functionNodeStack.length - 1];
508
+ if (!node || node.async) {
509
509
  return;
510
510
  }
511
- const node = closestFunctionNode.type === types.TSESTree.AST_NODE_TYPES.FunctionExpression && closestFunctionNode.parent?.type === types.TSESTree.AST_NODE_TYPES.MethodDefinition ? closestFunctionNode.parent : closestFunctionNode;
512
- const fixRange = node.type === types.TSESTree.AST_NODE_TYPES.MethodDefinition ? node.key.range : node.range;
513
- context.report({
514
- node,
515
- messageId: "useAsyncWithAwait",
516
- fix: (fixer) => fixer.insertTextBeforeRange(fixRange, "async ")
517
- });
511
+ let fixRange;
512
+ if (node.type === types.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression) {
513
+ fixRange = node.range;
514
+ }
515
+ if (node.type === types.TSESTree.AST_NODE_TYPES.FunctionDeclaration || node.type === types.TSESTree.AST_NODE_TYPES.FunctionExpression) {
516
+ if (node.parent.type === types.TSESTree.AST_NODE_TYPES.Property || node.parent.type === types.TSESTree.AST_NODE_TYPES.MethodDefinition) {
517
+ if (node.parent.kind === "method" || node.parent.kind === "init") {
518
+ fixRange = node.parent.key.range;
519
+ }
520
+ } else {
521
+ fixRange = node.range;
522
+ }
523
+ }
524
+ if (fixRange) {
525
+ context.report({
526
+ node,
527
+ messageId: "requireAsyncWithAwait",
528
+ fix: (fixer) => fixer.insertTextBeforeRange(fixRange, "async ")
529
+ });
530
+ }
518
531
  }
519
532
  };
520
533
  }
@@ -529,7 +542,7 @@ const index = {
529
542
  "no-useless-template-string": noUselessTemplateString,
530
543
  "no-import-promises-as": noImportPromisesAs,
531
544
  "pad-after-last-import": padAfterLastImport,
532
- "use-async-with-await": useAsyncWithAwait
545
+ "require-async-with-await": requireAsyncWithAwait
533
546
  }
534
547
  };
535
548
 
package/dist/index.d.cts CHANGED
@@ -1,13 +1,17 @@
1
+ import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
+
3
+ type MessageIds = "arrow" | "declaration";
4
+
1
5
  declare const _default: {
2
6
  rules: {
3
- "function-style": any;
4
- "import-dedupe": any;
5
- "no-inline-type-import": any;
6
- "no-negated-comparison": any;
7
- "no-useless-template-string": any;
8
- "no-import-promises-as": any;
9
- "pad-after-last-import": any;
10
- "use-async-with-await": any;
7
+ "function-style": _typescript_eslint_utils_ts_eslint.RuleModule<MessageIds, [], _typescript_eslint_utils_ts_eslint.RuleListener>;
8
+ "import-dedupe": _typescript_eslint_utils_ts_eslint.RuleModule<"importDedupe", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
9
+ "no-inline-type-import": _typescript_eslint_utils_ts_eslint.RuleModule<"noInlineTypeImport", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
10
+ "no-negated-comparison": _typescript_eslint_utils_ts_eslint.RuleModule<"noNegatedComparison", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
11
+ "no-useless-template-string": _typescript_eslint_utils_ts_eslint.RuleModule<"noUselessTemplateString", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
12
+ "no-import-promises-as": _typescript_eslint_utils_ts_eslint.RuleModule<"noImportPromisesAs", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
13
+ "pad-after-last-import": _typescript_eslint_utils_ts_eslint.RuleModule<"padAfterLastImport", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
14
+ "require-async-with-await": _typescript_eslint_utils_ts_eslint.RuleModule<"requireAsyncWithAwait", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
11
15
  };
12
16
  };
13
17
 
package/dist/index.d.mts CHANGED
@@ -1,13 +1,17 @@
1
+ import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
+
3
+ type MessageIds = "arrow" | "declaration";
4
+
1
5
  declare const _default: {
2
6
  rules: {
3
- "function-style": any;
4
- "import-dedupe": any;
5
- "no-inline-type-import": any;
6
- "no-negated-comparison": any;
7
- "no-useless-template-string": any;
8
- "no-import-promises-as": any;
9
- "pad-after-last-import": any;
10
- "use-async-with-await": any;
7
+ "function-style": _typescript_eslint_utils_ts_eslint.RuleModule<MessageIds, [], _typescript_eslint_utils_ts_eslint.RuleListener>;
8
+ "import-dedupe": _typescript_eslint_utils_ts_eslint.RuleModule<"importDedupe", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
9
+ "no-inline-type-import": _typescript_eslint_utils_ts_eslint.RuleModule<"noInlineTypeImport", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
10
+ "no-negated-comparison": _typescript_eslint_utils_ts_eslint.RuleModule<"noNegatedComparison", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
11
+ "no-useless-template-string": _typescript_eslint_utils_ts_eslint.RuleModule<"noUselessTemplateString", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
12
+ "no-import-promises-as": _typescript_eslint_utils_ts_eslint.RuleModule<"noImportPromisesAs", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
13
+ "pad-after-last-import": _typescript_eslint_utils_ts_eslint.RuleModule<"padAfterLastImport", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
14
+ "require-async-with-await": _typescript_eslint_utils_ts_eslint.RuleModule<"requireAsyncWithAwait", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
11
15
  };
12
16
  };
13
17
 
package/dist/index.d.ts CHANGED
@@ -1,13 +1,17 @@
1
+ import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
2
+
3
+ type MessageIds = "arrow" | "declaration";
4
+
1
5
  declare const _default: {
2
6
  rules: {
3
- "function-style": any;
4
- "import-dedupe": any;
5
- "no-inline-type-import": any;
6
- "no-negated-comparison": any;
7
- "no-useless-template-string": any;
8
- "no-import-promises-as": any;
9
- "pad-after-last-import": any;
10
- "use-async-with-await": any;
7
+ "function-style": _typescript_eslint_utils_ts_eslint.RuleModule<MessageIds, [], _typescript_eslint_utils_ts_eslint.RuleListener>;
8
+ "import-dedupe": _typescript_eslint_utils_ts_eslint.RuleModule<"importDedupe", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
9
+ "no-inline-type-import": _typescript_eslint_utils_ts_eslint.RuleModule<"noInlineTypeImport", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
10
+ "no-negated-comparison": _typescript_eslint_utils_ts_eslint.RuleModule<"noNegatedComparison", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
11
+ "no-useless-template-string": _typescript_eslint_utils_ts_eslint.RuleModule<"noUselessTemplateString", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
12
+ "no-import-promises-as": _typescript_eslint_utils_ts_eslint.RuleModule<"noImportPromisesAs", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
13
+ "pad-after-last-import": _typescript_eslint_utils_ts_eslint.RuleModule<"padAfterLastImport", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
14
+ "require-async-with-await": _typescript_eslint_utils_ts_eslint.RuleModule<"requireAsyncWithAwait", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
11
15
  };
12
16
  };
13
17
 
package/dist/index.mjs CHANGED
@@ -37,7 +37,7 @@ const functionStyle = createEslintRule({
37
37
  },
38
38
  defaultOptions: [],
39
39
  create: (context) => {
40
- const sourceCode = context.getSourceCode();
40
+ const sourceCode = context.sourceCode;
41
41
  function getLoneReturnStatement(node) {
42
42
  const { body } = node;
43
43
  if (body.type !== AST_NODE_TYPES.BlockStatement) {
@@ -68,8 +68,8 @@ const functionStyle = createEslintRule({
68
68
  }
69
69
  const scopeStack = [];
70
70
  let haveThisAccess = false;
71
- function setupScope() {
72
- scopeStack.push(context.getScope());
71
+ function setupScope(node) {
72
+ scopeStack.push(sourceCode.getScope(node));
73
73
  }
74
74
  function clearThisAccess() {
75
75
  scopeStack.pop();
@@ -159,8 +159,8 @@ const functionStyle = createEslintRule({
159
159
  }
160
160
  clearThisAccess();
161
161
  },
162
- ThisExpression() {
163
- haveThisAccess = scopeStack.includes(context.getScope());
162
+ ThisExpression(node) {
163
+ haveThisAccess = scopeStack.includes(sourceCode.getScope(node));
164
164
  }
165
165
  };
166
166
  }
@@ -201,7 +201,7 @@ const importDedupe = createEslintRule({
201
201
  fix(fixer) {
202
202
  const start = n.range[0];
203
203
  let end = n.range[1];
204
- const nextToken = context.getSourceCode().getTokenAfter(n);
204
+ const nextToken = context.sourceCode.getTokenAfter(n);
205
205
  if (nextToken && nextToken.value === ",") {
206
206
  end = nextToken.range[1];
207
207
  }
@@ -237,7 +237,7 @@ const noImportPromisesAs = createEslintRule({
237
237
  },
238
238
  defaultOptions: [],
239
239
  create: (context) => {
240
- const sourceCode = context.getSourceCode();
240
+ const sourceCode = context.sourceCode;
241
241
  const { text } = sourceCode;
242
242
  return {
243
243
  ImportDeclaration(node) {
@@ -290,7 +290,7 @@ const noInlineTypeImport = createEslintRule({
290
290
  },
291
291
  defaultOptions: [],
292
292
  create: (context) => {
293
- const sourceCode = context.getSourceCode();
293
+ const sourceCode = context.sourceCode;
294
294
  return {
295
295
  ImportDeclaration: (node) => {
296
296
  const { specifiers } = node;
@@ -444,7 +444,7 @@ const padAfterLastImport = createEslintRule({
444
444
  },
445
445
  defaultOptions: [],
446
446
  create: (context) => {
447
- const sourceCode = context.getSourceCode();
447
+ const sourceCode = context.sourceCode;
448
448
  let lastImportNode = null;
449
449
  return {
450
450
  ImportDeclaration(node) {
@@ -470,19 +470,19 @@ const padAfterLastImport = createEslintRule({
470
470
  }
471
471
  });
472
472
 
473
- const RULE_NAME = "use-async-with-await";
474
- const useAsyncWithAwait = createEslintRule({
473
+ const RULE_NAME = "require-async-with-await";
474
+ const requireAsyncWithAwait = createEslintRule({
475
475
  name: RULE_NAME,
476
476
  meta: {
477
477
  type: "problem",
478
478
  docs: {
479
- description: "Enforce using async keyword with await.",
479
+ description: "Require using async keyword with await.",
480
480
  recommended: "recommended"
481
481
  },
482
482
  fixable: "code",
483
483
  schema: [],
484
484
  messages: {
485
- useAsyncWithAwait: "Expect using async keyword with await."
485
+ requireAsyncWithAwait: "Expect using async keyword with await."
486
486
  }
487
487
  },
488
488
  defaultOptions: [],
@@ -502,17 +502,30 @@ const useAsyncWithAwait = createEslintRule({
502
502
  "ArrowFunctionExpression": setupNode,
503
503
  "ArrowFunctionExpression:exit": clearNode,
504
504
  AwaitExpression() {
505
- const closestFunctionNode = functionNodeStack[functionNodeStack.length - 1];
506
- if (!closestFunctionNode || closestFunctionNode.async) {
505
+ const node = functionNodeStack[functionNodeStack.length - 1];
506
+ if (!node || node.async) {
507
507
  return;
508
508
  }
509
- const node = closestFunctionNode.type === TSESTree.AST_NODE_TYPES.FunctionExpression && closestFunctionNode.parent?.type === TSESTree.AST_NODE_TYPES.MethodDefinition ? closestFunctionNode.parent : closestFunctionNode;
510
- const fixRange = node.type === TSESTree.AST_NODE_TYPES.MethodDefinition ? node.key.range : node.range;
511
- context.report({
512
- node,
513
- messageId: "useAsyncWithAwait",
514
- fix: (fixer) => fixer.insertTextBeforeRange(fixRange, "async ")
515
- });
509
+ let fixRange;
510
+ if (node.type === TSESTree.AST_NODE_TYPES.ArrowFunctionExpression) {
511
+ fixRange = node.range;
512
+ }
513
+ if (node.type === TSESTree.AST_NODE_TYPES.FunctionDeclaration || node.type === TSESTree.AST_NODE_TYPES.FunctionExpression) {
514
+ if (node.parent.type === TSESTree.AST_NODE_TYPES.Property || node.parent.type === TSESTree.AST_NODE_TYPES.MethodDefinition) {
515
+ if (node.parent.kind === "method" || node.parent.kind === "init") {
516
+ fixRange = node.parent.key.range;
517
+ }
518
+ } else {
519
+ fixRange = node.range;
520
+ }
521
+ }
522
+ if (fixRange) {
523
+ context.report({
524
+ node,
525
+ messageId: "requireAsyncWithAwait",
526
+ fix: (fixer) => fixer.insertTextBeforeRange(fixRange, "async ")
527
+ });
528
+ }
516
529
  }
517
530
  };
518
531
  }
@@ -527,7 +540,7 @@ const index = {
527
540
  "no-useless-template-string": noUselessTemplateString,
528
541
  "no-import-promises-as": noImportPromisesAs,
529
542
  "pad-after-last-import": padAfterLastImport,
530
- "use-async-with-await": useAsyncWithAwait
543
+ "require-async-with-await": requireAsyncWithAwait
531
544
  }
532
545
  };
533
546
 
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@so1ve/eslint-plugin",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve/)",
5
5
  "keywords": [
6
6
  "eslint",
7
7
  "eslint-config",
8
8
  "eslint-plugin"
9
9
  ],
10
- "homepage": "https://github.com/so1ve/eslint-config#readme",
10
+ "homepage": "https://github.com/so1ve/codestyle-config#readme",
11
11
  "repository": {
12
12
  "type": "git",
13
- "url": "git+https://github.com/so1ve/eslint-config.git"
13
+ "url": "git+https://github.com/so1ve/codestyle-config.git"
14
14
  },
15
15
  "bugs": {
16
- "url": "https://github.com/so1ve/eslint-config/issues"
16
+ "url": "https://github.com/so1ve/codestyle-config/issues"
17
17
  },
18
18
  "license": "MIT",
19
19
  "main": "./dist/index.cjs",
@@ -26,12 +26,11 @@
26
26
  "access": "public"
27
27
  },
28
28
  "dependencies": {
29
- "@typescript-eslint/types": "^6.2.0",
30
- "@typescript-eslint/utils": "^6.2.0"
29
+ "@typescript-eslint/types": "^7.1.0",
30
+ "@typescript-eslint/utils": "^7.1.0"
31
31
  },
32
32
  "scripts": {
33
- "build": "tsx scripts/build.ts",
34
- "build:real": "unbuild",
33
+ "build": "unbuild",
35
34
  "stub": "unbuild --stub",
36
35
  "test": "vitest"
37
36
  }