@so1ve/eslint-plugin 0.88.0 → 0.89.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
@@ -5,11 +5,11 @@ const utils = require('@typescript-eslint/utils');
5
5
 
6
6
  const createEslintRule = utils.ESLintUtils.RuleCreator((ruleName) => ruleName);
7
7
 
8
- const RULE_NAME$5 = "function-style";
8
+ const RULE_NAME$6 = "function-style";
9
9
  const START_RETURN = /^return /;
10
10
  const END_SEMICOLON = /;$/;
11
11
  const functionStyle = createEslintRule({
12
- name: RULE_NAME$5,
12
+ name: RULE_NAME$6,
13
13
  meta: {
14
14
  type: "problem",
15
15
  docs: {
@@ -162,9 +162,9 @@ const functionStyle = createEslintRule({
162
162
  }
163
163
  });
164
164
 
165
- const RULE_NAME$4 = "import-dedupe";
165
+ const RULE_NAME$5 = "import-dedupe";
166
166
  const importDedupe = createEslintRule({
167
- name: RULE_NAME$4,
167
+ name: RULE_NAME$5,
168
168
  meta: {
169
169
  type: "problem",
170
170
  docs: {
@@ -210,9 +210,9 @@ const importDedupe = createEslintRule({
210
210
  })
211
211
  });
212
212
 
213
- const RULE_NAME$3 = "no-inline-type-import";
213
+ const RULE_NAME$4 = "no-inline-type-import";
214
214
  const noInlineTypeImport = createEslintRule({
215
- name: RULE_NAME$3,
215
+ name: RULE_NAME$4,
216
216
  meta: {
217
217
  type: "layout",
218
218
  docs: {
@@ -276,7 +276,7 @@ const noInlineTypeImport = createEslintRule({
276
276
  }
277
277
  });
278
278
 
279
- const RULE_NAME$2 = "no-negated-comparison";
279
+ const RULE_NAME$3 = "no-negated-comparison";
280
280
  const negatedToPositive = {
281
281
  "==": "!=",
282
282
  "===": "!==",
@@ -289,7 +289,7 @@ const negatedToPositive = {
289
289
  };
290
290
  const negatives = Object.keys(negatedToPositive);
291
291
  const noNegatedComparison = createEslintRule({
292
- name: RULE_NAME$2,
292
+ name: RULE_NAME$3,
293
293
  meta: {
294
294
  type: "problem",
295
295
  docs: {
@@ -326,9 +326,9 @@ const noNegatedComparison = createEslintRule({
326
326
  })
327
327
  });
328
328
 
329
- const RULE_NAME$1 = "no-useless-template-string";
329
+ const RULE_NAME$2 = "no-useless-template-string";
330
330
  const noUselessTemplateString = createEslintRule({
331
- name: RULE_NAME$1,
331
+ name: RULE_NAME$2,
332
332
  meta: {
333
333
  type: "problem",
334
334
  docs: {
@@ -361,6 +361,64 @@ const noUselessTemplateString = createEslintRule({
361
361
  })
362
362
  });
363
363
 
364
+ const RULE_NAME$1 = "no-import-promises-as";
365
+ const _POSSIBLE_IMPORT_SOURCES = ["dns", "fs", "readline", "stream"];
366
+ const POSSIBLE_IMPORT_SOURCES = [
367
+ ..._POSSIBLE_IMPORT_SOURCES,
368
+ ..._POSSIBLE_IMPORT_SOURCES.map((s) => `node:${s}`)
369
+ ];
370
+ const noImportPromisesAs = createEslintRule({
371
+ name: RULE_NAME$1,
372
+ meta: {
373
+ type: "problem",
374
+ docs: {
375
+ description: "Disallow import promises as.",
376
+ recommended: "error"
377
+ },
378
+ fixable: "code",
379
+ schema: [],
380
+ messages: {
381
+ noImportPromisesAs: "Expect no import promises as."
382
+ }
383
+ },
384
+ defaultOptions: [],
385
+ create: (context) => {
386
+ const sourceCode = context.getSourceCode();
387
+ const { text } = sourceCode;
388
+ return {
389
+ ImportDeclaration(node) {
390
+ if (!POSSIBLE_IMPORT_SOURCES.includes(node.source.value)) {
391
+ return;
392
+ }
393
+ const promisesSpecifier = node.specifiers.find(
394
+ (s) => s.type === "ImportSpecifier" && s.imported.name === "promises" && s.local.name !== "promises"
395
+ );
396
+ const as = promisesSpecifier?.local.name;
397
+ if (!promisesSpecifier || !as) {
398
+ return;
399
+ }
400
+ context.report({
401
+ node,
402
+ messageId: "noImportPromisesAs",
403
+ *fix(fixer) {
404
+ const s = promisesSpecifier.range[0];
405
+ let e = promisesSpecifier.range[1];
406
+ if (text[e] === ",") {
407
+ e += 1;
408
+ }
409
+ yield fixer.removeRange([s, e]);
410
+ yield fixer.insertTextAfter(
411
+ node,
412
+ `
413
+ import ${as} from "${node.source.value}/promises";`
414
+ );
415
+ }
416
+ });
417
+ }
418
+ };
419
+ }
420
+ });
421
+
364
422
  const RULE_NAME = "pad-after-last-import";
365
423
  const padAfterLastImport = createEslintRule({
366
424
  name: RULE_NAME,
@@ -409,8 +467,9 @@ const index = {
409
467
  "function-style": functionStyle,
410
468
  "import-dedupe": importDedupe,
411
469
  "no-inline-type-import": noInlineTypeImport,
412
- "no-useless-template-string": noUselessTemplateString,
413
470
  "no-negated-comparison": noNegatedComparison,
471
+ "no-useless-template-string": noUselessTemplateString,
472
+ "no-import-promises-as": noImportPromisesAs,
414
473
  "pad-after-last-import": padAfterLastImport
415
474
  }
416
475
  };
package/dist/index.d.ts CHANGED
@@ -7,8 +7,9 @@ declare const _default: {
7
7
  "function-style": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<MessageIds, [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
8
8
  "import-dedupe": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"importDedupe", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
9
9
  "no-inline-type-import": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noInlineTypeImport", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
10
- "no-useless-template-string": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noUselessTemplateString", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
11
10
  "no-negated-comparison": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noNegatedComparison", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
11
+ "no-useless-template-string": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noUselessTemplateString", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
12
+ "no-import-promises-as": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"noImportPromisesAs", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
12
13
  "pad-after-last-import": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"padAfterLastImport", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
13
14
  };
14
15
  };
package/dist/index.mjs CHANGED
@@ -3,11 +3,11 @@ import { ESLintUtils } from '@typescript-eslint/utils';
3
3
 
4
4
  const createEslintRule = ESLintUtils.RuleCreator((ruleName) => ruleName);
5
5
 
6
- const RULE_NAME$5 = "function-style";
6
+ const RULE_NAME$6 = "function-style";
7
7
  const START_RETURN = /^return /;
8
8
  const END_SEMICOLON = /;$/;
9
9
  const functionStyle = createEslintRule({
10
- name: RULE_NAME$5,
10
+ name: RULE_NAME$6,
11
11
  meta: {
12
12
  type: "problem",
13
13
  docs: {
@@ -160,9 +160,9 @@ const functionStyle = createEslintRule({
160
160
  }
161
161
  });
162
162
 
163
- const RULE_NAME$4 = "import-dedupe";
163
+ const RULE_NAME$5 = "import-dedupe";
164
164
  const importDedupe = createEslintRule({
165
- name: RULE_NAME$4,
165
+ name: RULE_NAME$5,
166
166
  meta: {
167
167
  type: "problem",
168
168
  docs: {
@@ -208,9 +208,9 @@ const importDedupe = createEslintRule({
208
208
  })
209
209
  });
210
210
 
211
- const RULE_NAME$3 = "no-inline-type-import";
211
+ const RULE_NAME$4 = "no-inline-type-import";
212
212
  const noInlineTypeImport = createEslintRule({
213
- name: RULE_NAME$3,
213
+ name: RULE_NAME$4,
214
214
  meta: {
215
215
  type: "layout",
216
216
  docs: {
@@ -274,7 +274,7 @@ const noInlineTypeImport = createEslintRule({
274
274
  }
275
275
  });
276
276
 
277
- const RULE_NAME$2 = "no-negated-comparison";
277
+ const RULE_NAME$3 = "no-negated-comparison";
278
278
  const negatedToPositive = {
279
279
  "==": "!=",
280
280
  "===": "!==",
@@ -287,7 +287,7 @@ const negatedToPositive = {
287
287
  };
288
288
  const negatives = Object.keys(negatedToPositive);
289
289
  const noNegatedComparison = createEslintRule({
290
- name: RULE_NAME$2,
290
+ name: RULE_NAME$3,
291
291
  meta: {
292
292
  type: "problem",
293
293
  docs: {
@@ -324,9 +324,9 @@ const noNegatedComparison = createEslintRule({
324
324
  })
325
325
  });
326
326
 
327
- const RULE_NAME$1 = "no-useless-template-string";
327
+ const RULE_NAME$2 = "no-useless-template-string";
328
328
  const noUselessTemplateString = createEslintRule({
329
- name: RULE_NAME$1,
329
+ name: RULE_NAME$2,
330
330
  meta: {
331
331
  type: "problem",
332
332
  docs: {
@@ -359,6 +359,64 @@ const noUselessTemplateString = createEslintRule({
359
359
  })
360
360
  });
361
361
 
362
+ const RULE_NAME$1 = "no-import-promises-as";
363
+ const _POSSIBLE_IMPORT_SOURCES = ["dns", "fs", "readline", "stream"];
364
+ const POSSIBLE_IMPORT_SOURCES = [
365
+ ..._POSSIBLE_IMPORT_SOURCES,
366
+ ..._POSSIBLE_IMPORT_SOURCES.map((s) => `node:${s}`)
367
+ ];
368
+ const noImportPromisesAs = createEslintRule({
369
+ name: RULE_NAME$1,
370
+ meta: {
371
+ type: "problem",
372
+ docs: {
373
+ description: "Disallow import promises as.",
374
+ recommended: "error"
375
+ },
376
+ fixable: "code",
377
+ schema: [],
378
+ messages: {
379
+ noImportPromisesAs: "Expect no import promises as."
380
+ }
381
+ },
382
+ defaultOptions: [],
383
+ create: (context) => {
384
+ const sourceCode = context.getSourceCode();
385
+ const { text } = sourceCode;
386
+ return {
387
+ ImportDeclaration(node) {
388
+ if (!POSSIBLE_IMPORT_SOURCES.includes(node.source.value)) {
389
+ return;
390
+ }
391
+ const promisesSpecifier = node.specifiers.find(
392
+ (s) => s.type === "ImportSpecifier" && s.imported.name === "promises" && s.local.name !== "promises"
393
+ );
394
+ const as = promisesSpecifier?.local.name;
395
+ if (!promisesSpecifier || !as) {
396
+ return;
397
+ }
398
+ context.report({
399
+ node,
400
+ messageId: "noImportPromisesAs",
401
+ *fix(fixer) {
402
+ const s = promisesSpecifier.range[0];
403
+ let e = promisesSpecifier.range[1];
404
+ if (text[e] === ",") {
405
+ e += 1;
406
+ }
407
+ yield fixer.removeRange([s, e]);
408
+ yield fixer.insertTextAfter(
409
+ node,
410
+ `
411
+ import ${as} from "${node.source.value}/promises";`
412
+ );
413
+ }
414
+ });
415
+ }
416
+ };
417
+ }
418
+ });
419
+
362
420
  const RULE_NAME = "pad-after-last-import";
363
421
  const padAfterLastImport = createEslintRule({
364
422
  name: RULE_NAME,
@@ -407,8 +465,9 @@ const index = {
407
465
  "function-style": functionStyle,
408
466
  "import-dedupe": importDedupe,
409
467
  "no-inline-type-import": noInlineTypeImport,
410
- "no-useless-template-string": noUselessTemplateString,
411
468
  "no-negated-comparison": noNegatedComparison,
469
+ "no-useless-template-string": noUselessTemplateString,
470
+ "no-import-promises-as": noImportPromisesAs,
412
471
  "pad-after-last-import": padAfterLastImport
413
472
  }
414
473
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@so1ve/eslint-plugin",
3
- "version": "0.88.0",
3
+ "version": "0.89.0",
4
4
  "author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
5
5
  "contributors": [
6
6
  {