@plugjs/eslint-plugin 0.2.2 → 0.2.3

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.
@@ -180,7 +180,7 @@ var require_package = __commonJS({
180
180
  "node_modules/eslint-plugin-import-x/package.json"(exports2, module2) {
181
181
  module2.exports = {
182
182
  name: "eslint-plugin-import-x",
183
- version: "0.5.3",
183
+ version: "3.0.0",
184
184
  description: "Import with sanity.",
185
185
  repository: "git+https://github.com/un-ts/eslint-plugin-import-x",
186
186
  author: "JounQin <admin@1stg.me> (https://www.1stG.me)",
@@ -4444,6 +4444,27 @@ var require_no_deprecated = __commonJS({
4444
4444
  }
4445
4445
  });
4446
4446
 
4447
+ // node_modules/eslint-plugin-import-x/lib/utils/lazy-value.js
4448
+ var require_lazy_value = __commonJS({
4449
+ "node_modules/eslint-plugin-import-x/lib/utils/lazy-value.js"(exports2) {
4450
+ "use strict";
4451
+ Object.defineProperty(exports2, "__esModule", { value: true });
4452
+ exports2.lazy = void 0;
4453
+ var lazy = (cb) => {
4454
+ let isCalled = false;
4455
+ let result;
4456
+ return () => {
4457
+ if (!isCalled) {
4458
+ isCalled = true;
4459
+ result = cb();
4460
+ }
4461
+ return result;
4462
+ };
4463
+ };
4464
+ exports2.lazy = lazy;
4465
+ }
4466
+ });
4467
+
4447
4468
  // node_modules/eslint-plugin-import-x/lib/rules/no-duplicates.js
4448
4469
  var require_no_duplicates = __commonJS({
4449
4470
  "node_modules/eslint-plugin-import-x/lib/rules/no-duplicates.js"(exports2, module2) {
@@ -4451,69 +4472,67 @@ var require_no_duplicates = __commonJS({
4451
4472
  var tslib_12 = require("tslib");
4452
4473
  var semver_1 = tslib_12.__importDefault(require("semver"));
4453
4474
  var utils_1 = require_utils();
4454
- var typescriptPkg;
4455
- try {
4456
- typescriptPkg = require("typescript/package.json");
4457
- } catch (_a) {
4458
- }
4475
+ var lazy_value_1 = require_lazy_value();
4476
+ var isTypeScriptVersionSupportPreferInline = (0, lazy_value_1.lazy)(() => {
4477
+ let typescriptPkg;
4478
+ try {
4479
+ typescriptPkg = require("typescript/package.json");
4480
+ } catch (_a) {
4481
+ }
4482
+ return !typescriptPkg || !semver_1.default.satisfies(typescriptPkg.version, ">= 4.5");
4483
+ });
4459
4484
  function checkImports(imported, context) {
4460
- for (const [module3, nodes] of imported.entries()) {
4461
- if (nodes.length > 1) {
4462
- const [first, ...rest] = nodes;
4463
- const { sourceCode } = context;
4464
- const fix = getFix(first, rest, sourceCode, context);
4485
+ imported.forEach((nodes, module3) => {
4486
+ if (nodes.length <= 1) {
4487
+ return;
4488
+ }
4489
+ for (let i = 0, len = nodes.length; i < len; i++) {
4490
+ const node = nodes[i];
4465
4491
  context.report({
4466
- node: first.source,
4492
+ node: node.source,
4467
4493
  messageId: "duplicate",
4468
4494
  data: {
4469
4495
  module: module3
4470
4496
  },
4471
- fix
4497
+ fix: i === 0 ? getFix(nodes, context.sourceCode, context) : null
4472
4498
  });
4473
- for (const node of rest) {
4474
- context.report({
4475
- node: node.source,
4476
- messageId: "duplicate",
4477
- data: {
4478
- module: module3
4479
- }
4480
- });
4481
- }
4482
4499
  }
4483
- }
4500
+ });
4484
4501
  }
4485
- function getFix(first, rest, sourceCode, context) {
4486
- if (typeof sourceCode.getCommentsBefore !== "function") {
4487
- return;
4488
- }
4502
+ function getFix(nodes, sourceCode, context) {
4503
+ const first = nodes[0];
4489
4504
  if (hasProblematicComments(first, sourceCode) || hasNamespace(first)) {
4490
- return;
4505
+ return null;
4491
4506
  }
4492
- const defaultImportNames = new Set([first, ...rest].flatMap((x) => getDefaultImportName(x) || []));
4507
+ const defaultImportNames = new Set(nodes.flatMap((x) => getDefaultImportName(x) || []));
4493
4508
  if (defaultImportNames.size > 1) {
4494
- return;
4509
+ return null;
4495
4510
  }
4496
- const restWithoutComments = rest.filter((node) => !hasProblematicComments(node, sourceCode) && !hasNamespace(node));
4497
- const specifiers = restWithoutComments.map((node) => {
4511
+ const rest = nodes.slice(1);
4512
+ const restWithoutCommentsAndNamespaces = rest.filter((node) => !hasProblematicComments(node, sourceCode) && !hasNamespace(node));
4513
+ const restWithoutCommentsAndNamespacesHasSpecifiers = restWithoutCommentsAndNamespaces.map(hasSpecifiers);
4514
+ const specifiers = restWithoutCommentsAndNamespaces.reduce((acc, node, nodeIndex) => {
4498
4515
  const tokens = sourceCode.getTokens(node);
4499
4516
  const openBrace = tokens.find((token) => isPunctuator(token, "{"));
4500
4517
  const closeBrace = tokens.find((token) => isPunctuator(token, "}"));
4501
4518
  if (openBrace == null || closeBrace == null) {
4502
- return;
4519
+ return acc;
4503
4520
  }
4504
- return {
4521
+ acc.push({
4505
4522
  importNode: node,
4506
4523
  identifiers: sourceCode.text.slice(openBrace.range[1], closeBrace.range[0]).split(","),
4507
- isEmpty: !hasSpecifiers(node)
4508
- };
4509
- }).filter(Boolean);
4510
- const unnecessaryImports = restWithoutComments.filter((node) => !hasSpecifiers(node) && !hasNamespace(node) && !specifiers.some((specifier) => "importNode" in specifier && specifier.importNode === node));
4511
- const shouldAddDefault = getDefaultImportName(first) == null && defaultImportNames.size === 1;
4524
+ isEmpty: !restWithoutCommentsAndNamespacesHasSpecifiers[nodeIndex]
4525
+ });
4526
+ return acc;
4527
+ }, []);
4528
+ const unnecessaryImports = restWithoutCommentsAndNamespaces.filter((node, nodeIndex) => !restWithoutCommentsAndNamespacesHasSpecifiers[nodeIndex] && !specifiers.some((specifier) => specifier.importNode === node));
4512
4529
  const shouldAddSpecifiers = specifiers.length > 0;
4513
4530
  const shouldRemoveUnnecessary = unnecessaryImports.length > 0;
4514
- if (!(shouldAddDefault || shouldAddSpecifiers || shouldRemoveUnnecessary)) {
4515
- return;
4531
+ const shouldAddDefault = (0, lazy_value_1.lazy)(() => getDefaultImportName(first) == null && defaultImportNames.size === 1);
4532
+ if (!shouldAddSpecifiers && !shouldRemoveUnnecessary && !shouldAddDefault()) {
4533
+ return null;
4516
4534
  }
4535
+ const preferInline = context.options[0] && context.options[0]["prefer-inline"];
4517
4536
  return (fixer) => {
4518
4537
  const tokens = sourceCode.getTokens(first);
4519
4538
  const openBrace = tokens.find((token) => isPunctuator(token, "{"));
@@ -4525,8 +4544,7 @@ var require_no_duplicates = __commonJS({
4525
4544
  const firstExistingIdentifiers = firstIsEmpty ? /* @__PURE__ */ new Set() : new Set(sourceCode.text.slice(openBrace.range[1], closeBrace.range[0]).split(",").map((x) => x.trim()));
4526
4545
  const [specifiersText] = specifiers.reduce(([result, needsComma, existingIdentifiers], specifier) => {
4527
4546
  const isTypeSpecifier = "importNode" in specifier && specifier.importNode.importKind === "type";
4528
- const preferInline = context.options[0] && context.options[0]["prefer-inline"];
4529
- if (preferInline && (!typescriptPkg || !semver_1.default.satisfies(typescriptPkg.version, ">= 4.5"))) {
4547
+ if (preferInline && isTypeScriptVersionSupportPreferInline()) {
4530
4548
  throw new Error("Your version of TypeScript does not support inline type imports.");
4531
4549
  }
4532
4550
  const [specifierText, updatedExistingIdentifiers] = specifier.identifiers.reduce(([text, set], cur) => {
@@ -4547,22 +4565,22 @@ var require_no_duplicates = __commonJS({
4547
4565
  ];
4548
4566
  }, ["", !firstHasTrailingComma && !firstIsEmpty, firstExistingIdentifiers]);
4549
4567
  const fixes = [];
4550
- if (shouldAddDefault && openBrace == null && shouldAddSpecifiers) {
4568
+ if (openBrace == null && shouldAddSpecifiers && shouldAddDefault()) {
4551
4569
  fixes.push(fixer.insertTextAfter(firstToken, ` ${defaultImportName}, {${specifiersText}} from`));
4552
- } else if (shouldAddDefault && openBrace == null && !shouldAddSpecifiers) {
4570
+ } else if (openBrace == null && !shouldAddSpecifiers && shouldAddDefault()) {
4553
4571
  fixes.push(fixer.insertTextAfter(firstToken, ` ${defaultImportName} from`));
4554
- } else if (shouldAddDefault && openBrace != null && closeBrace != null) {
4572
+ } else if (openBrace != null && closeBrace != null && shouldAddDefault()) {
4555
4573
  fixes.push(fixer.insertTextAfter(firstToken, ` ${defaultImportName},`));
4556
4574
  if (shouldAddSpecifiers) {
4557
4575
  fixes.push(fixer.insertTextBefore(closeBrace, specifiersText));
4558
4576
  }
4559
- } else if (!shouldAddDefault && openBrace == null && shouldAddSpecifiers) {
4577
+ } else if (openBrace == null && shouldAddSpecifiers && !shouldAddDefault()) {
4560
4578
  if (first.specifiers.length === 0) {
4561
4579
  fixes.push(fixer.insertTextAfter(firstToken, ` {${specifiersText}} from`));
4562
4580
  } else {
4563
4581
  fixes.push(fixer.insertTextAfter(first.specifiers[0], `, {${specifiersText}}`));
4564
4582
  }
4565
- } else if (!shouldAddDefault && openBrace != null && closeBrace != null) {
4583
+ } else if (openBrace != null && closeBrace != null && !shouldAddDefault()) {
4566
4584
  fixes.push(fixer.insertTextBefore(closeBrace, specifiersText));
4567
4585
  }
4568
4586
  for (const specifier of specifiers) {
@@ -4593,15 +4611,13 @@ var require_no_duplicates = __commonJS({
4593
4611
  }
4594
4612
  function getDefaultImportName(node) {
4595
4613
  const defaultSpecifier = node.specifiers.find((specifier) => specifier.type === "ImportDefaultSpecifier");
4596
- return defaultSpecifier == null ? void 0 : defaultSpecifier.local.name;
4614
+ return defaultSpecifier === null || defaultSpecifier === void 0 ? void 0 : defaultSpecifier.local.name;
4597
4615
  }
4598
4616
  function hasNamespace(node) {
4599
- const specifiers = node.specifiers.filter((specifier) => specifier.type === "ImportNamespaceSpecifier");
4600
- return specifiers.length > 0;
4617
+ return node.specifiers.some((specifier) => specifier.type === "ImportNamespaceSpecifier");
4601
4618
  }
4602
4619
  function hasSpecifiers(node) {
4603
- const specifiers = node.specifiers.filter((specifier) => specifier.type === "ImportSpecifier");
4604
- return specifiers.length > 0;
4620
+ return node.specifiers.some((specifier) => specifier.type === "ImportSpecifier");
4605
4621
  }
4606
4622
  function hasProblematicComments(node, sourceCode) {
4607
4623
  return hasCommentBefore(node, sourceCode) || hasCommentAfter(node, sourceCode) || hasCommentInsideNonSpecifiers(node, sourceCode);
@@ -4651,8 +4667,9 @@ var require_no_duplicates = __commonJS({
4651
4667
  },
4652
4668
  defaultOptions: [],
4653
4669
  create(context) {
4654
- var _a;
4655
- const considerQueryStringOption = (_a = context.options[0]) === null || _a === void 0 ? void 0 : _a.considerQueryString;
4670
+ var _a, _b;
4671
+ const preferInline = (_a = context.options[0]) === null || _a === void 0 ? void 0 : _a["prefer-inline"];
4672
+ const considerQueryStringOption = (_b = context.options[0]) === null || _b === void 0 ? void 0 : _b.considerQueryString;
4656
4673
  const defaultResolver = (sourcePath) => (0, utils_1.resolve)(sourcePath, context) || sourcePath;
4657
4674
  const resolver = considerQueryStringOption ? (sourcePath) => {
4658
4675
  const parts = sourcePath.match(/^([^?]*)\?(.*)$/);
@@ -4663,18 +4680,19 @@ var require_no_duplicates = __commonJS({
4663
4680
  } : defaultResolver;
4664
4681
  const moduleMaps = /* @__PURE__ */ new Map();
4665
4682
  function getImportMap(n) {
4666
- var _a2;
4667
4683
  const parent = n.parent;
4668
- if (!moduleMaps.has(parent)) {
4669
- moduleMaps.set(parent, {
4684
+ let map;
4685
+ if (moduleMaps.has(parent)) {
4686
+ map = moduleMaps.get(parent);
4687
+ } else {
4688
+ map = {
4670
4689
  imported: /* @__PURE__ */ new Map(),
4671
4690
  nsImported: /* @__PURE__ */ new Map(),
4672
4691
  defaultTypesImported: /* @__PURE__ */ new Map(),
4673
4692
  namedTypesImported: /* @__PURE__ */ new Map()
4674
- });
4693
+ };
4694
+ moduleMaps.set(parent, map);
4675
4695
  }
4676
- const map = moduleMaps.get(parent);
4677
- const preferInline = (_a2 = context.options[0]) === null || _a2 === void 0 ? void 0 : _a2["prefer-inline"];
4678
4696
  if (!preferInline && n.importKind === "type") {
4679
4697
  return n.specifiers.length > 0 && n.specifiers[0].type === "ImportDefaultSpecifier" ? map.defaultTypesImported : map.namedTypesImported;
4680
4698
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plugjs/eslint-plugin",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Shared ESLint configurations and extras",
5
5
  "main": "./eslint.config.mjs",
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "@eslint/js": "9.6.0",
23
- "@typescript-eslint/utils": "8.0.0-alpha.40",
23
+ "@typescript-eslint/utils": "8.0.0-alpha.41",
24
24
  "debug": "4.3.5",
25
25
  "doctrine": "2.1.0",
26
26
  "enhanced-resolve": "5.17.0",
@@ -42,6 +42,6 @@
42
42
  "stable-hash": "0.0.4",
43
43
  "tslib": "2.6.3",
44
44
  "typescript": "5.5.3",
45
- "typescript-eslint": "8.0.0-alpha.39"
45
+ "typescript-eslint": "8.0.0-alpha.41"
46
46
  }
47
47
  }