eslint-plugin-import-lite 0.5.0 → 0.5.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.
@@ -1,14 +1,27 @@
1
- import type { ESLint } from 'eslint'
2
- import type { Configs } from './configs'
3
- import type { Rules } from './rules'
4
-
5
- export type { Configs } from './configs'
6
- export type { RuleOptions } from './rule-options'
7
- export type { Rules } from './rules'
1
+ import { RuleOptions } from "./rule-options.js";
2
+ import { ESLint, Linter, Rule } from "eslint";
8
3
 
4
+ //#region src/dts/configs.d.ts
5
+ declare const configs: {
6
+ /**
7
+ * The default recommended config in Flat Config Format
8
+ */
9
+ recommended: Linter.Config;
10
+ /**
11
+ * Enable all rules, in Flat Config Format
12
+ */
13
+ all: Linter.Config;
14
+ };
15
+ type Configs = typeof configs;
16
+ //#endregion
17
+ //#region src/dts/rules.d.ts
18
+ type RuleName<K extends string> = K extends `${string}/${infer Name}` ? RuleName<Name> : K;
19
+ type Rules = Required<{ [K in keyof RuleOptions as RuleName<K>]: Rule.RuleModule }>;
20
+ //#endregion
21
+ //#region src/dts/index.d.ts
9
22
  declare const plugin: {
10
- rules: Rules
11
- configs: ESLint.Plugin['configs'] & Configs
12
- }
13
-
14
- export default plugin
23
+ rules: Rules;
24
+ configs: ESLint.Plugin['configs'] & Configs;
25
+ };
26
+ //#endregion
27
+ export { type Configs, type RuleOptions, type Rules, plugin as default };
@@ -1,71 +1,67 @@
1
- /* eslint-disable */
2
- /* prettier-ignore */
3
- import type { Linter } from 'eslint'
1
+ import { Linter } from "eslint";
4
2
 
5
- export interface RuleOptions {
3
+ //#region src/dts/rule-options.d.ts
4
+ interface RuleOptions {
6
5
  /**
7
6
  * Enforce or ban the use of inline type-only markers for named imports.
8
7
  * @see https://github.com/9romise/eslint-plugin-import-lite/blob/main/src/rules/consistent-type-specifier-style/README.md
9
8
  */
10
- 'import-lite/consistent-type-specifier-style'?: Linter.RuleEntry<ImportLiteConsistentTypeSpecifierStyle>
9
+ 'import-lite/consistent-type-specifier-style'?: Linter.RuleEntry<ImportLiteConsistentTypeSpecifierStyle>;
11
10
  /**
12
11
  * Ensure all exports appear after other statements.
13
12
  * @see https://github.com/9romise/eslint-plugin-import-lite/blob/main/src/rules/exports-last/README.md
14
13
  */
15
- 'import-lite/exports-last'?: Linter.RuleEntry<[]>
14
+ 'import-lite/exports-last'?: Linter.RuleEntry<[]>;
16
15
  /**
17
16
  * Ensure all imports appear before other statements.
18
17
  * @see https://github.com/9romise/eslint-plugin-import-lite/blob/main/src/rules/first/README.md
19
18
  */
20
- 'import-lite/first'?: Linter.RuleEntry<ImportLiteFirst>
19
+ 'import-lite/first'?: Linter.RuleEntry<ImportLiteFirst>;
21
20
  /**
22
21
  * Enforce a newline after import statements.
23
22
  * @see https://github.com/9romise/eslint-plugin-import-lite/blob/main/src/rules/newline-after-import/README.md
24
23
  */
25
- 'import-lite/newline-after-import'?: Linter.RuleEntry<ImportLiteNewlineAfterImport>
24
+ 'import-lite/newline-after-import'?: Linter.RuleEntry<ImportLiteNewlineAfterImport>;
26
25
  /**
27
26
  * Forbid default exports.
28
27
  * @see https://github.com/9romise/eslint-plugin-import-lite/blob/main/src/rules/no-default-export/README.md
29
28
  */
30
- 'import-lite/no-default-export'?: Linter.RuleEntry<[]>
29
+ 'import-lite/no-default-export'?: Linter.RuleEntry<[]>;
31
30
  /**
32
31
  * Forbid repeated import of the same module in multiple places.
33
32
  * @see https://github.com/9romise/eslint-plugin-import-lite/blob/main/src/rules/no-duplicates/README.md
34
33
  */
35
- 'import-lite/no-duplicates'?: Linter.RuleEntry<ImportLiteNoDuplicates>
34
+ 'import-lite/no-duplicates'?: Linter.RuleEntry<ImportLiteNoDuplicates>;
36
35
  /**
37
36
  * Forbid the use of mutable exports with `var` or `let`.
38
37
  * @see https://github.com/9romise/eslint-plugin-import-lite/blob/main/src/rules/no-mutable-exports/README.md
39
38
  */
40
- 'import-lite/no-mutable-exports'?: Linter.RuleEntry<[]>
39
+ 'import-lite/no-mutable-exports'?: Linter.RuleEntry<[]>;
41
40
  /**
42
41
  * Forbid named default exports.
43
42
  * @see https://github.com/9romise/eslint-plugin-import-lite/blob/main/src/rules/no-named-default/README.md
44
43
  */
45
- 'import-lite/no-named-default'?: Linter.RuleEntry<[]>
44
+ 'import-lite/no-named-default'?: Linter.RuleEntry<[]>;
46
45
  /**
47
46
  * Prefer a default export if module exports a single name or multiple names.
48
47
  * @see https://github.com/9romise/eslint-plugin-import-lite/blob/main/src/rules/prefer-default-export/README.md
49
48
  */
50
- 'import-lite/prefer-default-export'?: Linter.RuleEntry<ImportLitePreferDefaultExport>
49
+ 'import-lite/prefer-default-export'?: Linter.RuleEntry<ImportLitePreferDefaultExport>;
51
50
  }
52
-
53
51
  /* ======= Declarations ======= */
54
52
  // ----- import-lite/consistent-type-specifier-style -----
55
- type ImportLiteConsistentTypeSpecifierStyle = []|[("top-level" | "inline" | "prefer-top-level")]
56
- // ----- import-lite/first -----
57
- type ImportLiteFirst = []|[("absolute-first" | "disable-absolute-first")]
58
- // ----- import-lite/newline-after-import -----
59
- type ImportLiteNewlineAfterImport = []|[{
60
- count?: number
61
- exactCount?: boolean
62
- considerComments?: boolean
63
- }]
64
- // ----- import-lite/no-duplicates -----
65
- type ImportLiteNoDuplicates = []|[{
66
- "prefer-inline"?: boolean
67
- }]
68
- // ----- import-lite/prefer-default-export -----
69
- type ImportLitePreferDefaultExport = []|[{
70
- target?: ("single" | "any")
71
- }]
53
+ type ImportLiteConsistentTypeSpecifierStyle = [] | [("top-level" | "inline" | "prefer-top-level")]; // ----- import-lite/first -----
54
+ type ImportLiteFirst = [] | [("absolute-first" | "disable-absolute-first")]; // ----- import-lite/newline-after-import -----
55
+ type ImportLiteNewlineAfterImport = [] | [{
56
+ count?: number;
57
+ exactCount?: boolean;
58
+ considerComments?: boolean;
59
+ }]; // ----- import-lite/no-duplicates -----
60
+ type ImportLiteNoDuplicates = [] | [{
61
+ "prefer-inline"?: boolean;
62
+ }]; // ----- import-lite/prefer-default-export -----
63
+ type ImportLitePreferDefaultExport = [] | [{
64
+ target?: ("single" | "any");
65
+ }];
66
+ //#endregion
67
+ export { RuleOptions };
@@ -76,16 +76,16 @@ var consistent_type_specifier_style_default = createRule({
76
76
  fix(fixer) {
77
77
  const fixes = [];
78
78
  if (valueSpecifiers.length > 0) {
79
- for (const specifier$1 of typeSpecifiers) {
80
- const token = sourceCode.getTokenAfter(specifier$1);
79
+ for (const specifier of typeSpecifiers) {
80
+ const token = sourceCode.getTokenAfter(specifier);
81
81
  if (token && isCommaToken(token)) fixes.push(fixer.remove(token));
82
- fixes.push(fixer.remove(specifier$1));
82
+ fixes.push(fixer.remove(specifier));
83
83
  }
84
- const maybeComma = sourceCode.getTokenAfter(valueSpecifiers[valueSpecifiers.length - 1]);
84
+ const maybeComma = sourceCode.getTokenAfter(valueSpecifiers.at(-1));
85
85
  if (isCommaToken(maybeComma)) fixes.push(fixer.remove(maybeComma));
86
86
  } else if (defaultSpecifier) {
87
87
  const comma = sourceCode.getTokenAfter(defaultSpecifier, isCommaToken);
88
- const closingBrace = sourceCode.getTokenAfter(node.specifiers[node.specifiers.length - 1], (token) => token.type === "Punctuator" && token.value === "}");
88
+ const closingBrace = sourceCode.getTokenAfter(node.specifiers.at(-1), (token) => token.type === "Punctuator" && token.value === "}");
89
89
  fixes.push(fixer.removeRange([comma.range[0], closingBrace.range[1]]));
90
90
  }
91
91
  return [...fixes, fixer.insertTextAfter(node, `\n${typeImport}`)];
@@ -73,10 +73,10 @@ var first_default = createRule({
73
73
  else if (index === lastSortNodesIndex) {
74
74
  const sortNodes = errorInfos.slice(0, lastSortNodesIndex + 1);
75
75
  fix = (fixer) => {
76
- const removeFixers = sortNodes.map(({ range: range$1 }) => fixer.removeRange(range$1));
77
- const range = [0, removeFixers[removeFixers.length - 1].range[1]];
78
- let insertSourceCode = sortNodes.map(({ range: range$1 }) => {
79
- const nodeSourceCode = originSourceCode.slice(...range$1);
76
+ const removeFixers = sortNodes.map(({ range }) => fixer.removeRange(range));
77
+ const range = [0, removeFixers.at(-1).range[1]];
78
+ let insertSourceCode = sortNodes.map(({ range }) => {
79
+ const nodeSourceCode = originSourceCode.slice(...range);
80
80
  if (/\S/.test(nodeSourceCode[0])) return `\n${nodeSourceCode}`;
81
81
  return nodeSourceCode;
82
82
  }).join("");
@@ -133,8 +133,8 @@ var newline_after_import_default = createRule({
133
133
  },
134
134
  "Program:exit": function(node) {
135
135
  const scopeBody = getScopeBody(context.sourceCode.getScope(node));
136
- for (const [index, node$1] of requireCalls.entries()) {
137
- const nodePosition = findNodeIndexInScopeBody(scopeBody, node$1);
136
+ for (const [index, node] of requireCalls.entries()) {
137
+ const nodePosition = findNodeIndexInScopeBody(scopeBody, node);
138
138
  const statementWithRequireCall = scopeBody[nodePosition];
139
139
  const nextStatement = scopeBody[nodePosition + 1];
140
140
  const nextRequireCall = requireCalls[index + 1];
@@ -142,7 +142,7 @@ var newline_after_import_default = createRule({
142
142
  if (nextStatement && (!nextRequireCall || !containsNodeOrEqual(nextStatement, nextRequireCall))) {
143
143
  let nextComment;
144
144
  if ("comments" in statementWithRequireCall.parent && statementWithRequireCall.parent.comments !== void 0 && considerComments) {
145
- const endLine = node$1.loc.end.line;
145
+ const endLine = node.loc.end.line;
146
146
  nextComment = statementWithRequireCall.parent.comments.find((o) => o.loc.start.line >= endLine && o.loc.start.line <= endLine + count + 1);
147
147
  }
148
148
  if (nextComment && nextComment !== void 0) commentAfterImport(statementWithRequireCall, nextComment, "require");
@@ -26,7 +26,7 @@ var no_default_export_default = createRule({
26
26
  });
27
27
  },
28
28
  ExportNamedDeclaration(node) {
29
- for (const specifier of node.specifiers.filter((specifier$1) => getValue(specifier$1.exported) === "default")) {
29
+ for (const specifier of node.specifiers.filter((specifier) => getValue(specifier.exported) === "default")) {
30
30
  const { loc } = sourceCode.getFirstTokens(node)[1] || {};
31
31
  if (specifier.type === "ExportDefaultSpecifier") context.report({
32
32
  node,
package/dist/vender.mjs CHANGED
@@ -1,20 +1,21 @@
1
- //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
1
+ //#region node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
2
2
  function isPrimitive(value) {
3
3
  return value == null || typeof value !== "object" && typeof value !== "function";
4
4
  }
5
5
 
6
6
  //#endregion
7
- //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/predicate/isTypedArray.mjs
7
+ //#region node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/predicate/isTypedArray.mjs
8
8
  function isTypedArray(x) {
9
9
  return ArrayBuffer.isView(x) && !(x instanceof DataView);
10
10
  }
11
11
 
12
12
  //#endregion
13
- //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/object/clone.mjs
13
+ //#region node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/object/clone.mjs
14
14
  function clone(obj) {
15
15
  if (isPrimitive(obj)) return obj;
16
16
  if (Array.isArray(obj) || isTypedArray(obj) || obj instanceof ArrayBuffer || typeof SharedArrayBuffer !== "undefined" && obj instanceof SharedArrayBuffer) return obj.slice(0);
17
17
  const prototype = Object.getPrototypeOf(obj);
18
+ if (prototype == null) return Object.assign(Object.create(prototype), obj);
18
19
  const Constructor = prototype.constructor;
19
20
  if (obj instanceof Date || obj instanceof Map || obj instanceof Set) return new Constructor(obj);
20
21
  if (obj instanceof RegExp) {
@@ -24,10 +25,11 @@ function clone(obj) {
24
25
  }
25
26
  if (obj instanceof DataView) return new Constructor(obj.buffer.slice(0));
26
27
  if (obj instanceof Error) {
27
- const newError = new Constructor(obj.message);
28
+ let newError;
29
+ if (obj instanceof AggregateError) newError = new Constructor(obj.errors, obj.message, { cause: obj.cause });
30
+ else newError = new Constructor(obj.message, { cause: obj.cause });
28
31
  newError.stack = obj.stack;
29
- newError.name = obj.name;
30
- newError.cause = obj.cause;
32
+ Object.assign(newError, obj);
31
33
  return newError;
32
34
  }
33
35
  if (typeof File !== "undefined" && obj instanceof File) return new Constructor([obj], obj.name, {
@@ -42,7 +44,7 @@ function clone(obj) {
42
44
  }
43
45
 
44
46
  //#endregion
45
- //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
47
+ //#region node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
46
48
  function isPlainObject(value) {
47
49
  if (!value || typeof value !== "object") return false;
48
50
  const proto = Object.getPrototypeOf(value);
@@ -51,13 +53,13 @@ function isPlainObject(value) {
51
53
  }
52
54
 
53
55
  //#endregion
54
- //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs
56
+ //#region node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/_internal/isUnsafeProperty.mjs
55
57
  function isUnsafeProperty(key) {
56
58
  return key === "__proto__";
57
59
  }
58
60
 
59
61
  //#endregion
60
- //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/object/mergeWith.mjs
62
+ //#region node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/object/mergeWith.mjs
61
63
  function mergeWith(target, source, merge) {
62
64
  const sourceKeys = Object.keys(source);
63
65
  for (let i = 0; i < sourceKeys.length; i++) {
@@ -77,7 +79,7 @@ function mergeWith(target, source, merge) {
77
79
  }
78
80
 
79
81
  //#endregion
80
- //#region node_modules/.pnpm/es-toolkit@1.43.0/node_modules/es-toolkit/dist/object/toMerged.mjs
82
+ //#region node_modules/.pnpm/es-toolkit@1.44.0/node_modules/es-toolkit/dist/object/toMerged.mjs
81
83
  function toMerged(target, source) {
82
84
  return mergeWith(clone(target), source, function mergeRecursively(targetValue, sourceValue) {
83
85
  if (Array.isArray(sourceValue)) if (Array.isArray(targetValue)) return mergeWith(clone(targetValue), sourceValue, mergeRecursively);
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-import-lite",
3
3
  "type": "module",
4
- "version": "0.5.0",
5
- "packageManager": "pnpm@10.27.0",
4
+ "version": "0.5.2",
6
5
  "author": "Vida Xie<https://github.com/9romise>",
7
6
  "license": "MIT",
8
7
  "homepage": "https://github.com/9romise/eslint-plugin-import-lite#readme",
@@ -18,15 +17,11 @@
18
17
  "exports": {
19
18
  ".": {
20
19
  "types": "./dist/dts/index.d.ts",
21
- "import": "./dist/index.mjs",
22
- "require": "./dist/index.mjs"
20
+ "default": "./dist/index.mjs"
23
21
  },
24
- "./rule-options": {
25
- "types": "./dist/dts/rule-options.d.ts"
26
- }
22
+ "./package.json": "./package.json",
23
+ "./rule-options": "./dist/dts/rule-options.d.ts"
27
24
  },
28
- "main": "./dist/index.mjs",
29
- "module": "./dist/index.mjs",
30
25
  "types": "./dist/dts/index.d.ts",
31
26
  "files": [
32
27
  "dist"
@@ -34,44 +29,45 @@
34
29
  "engines": {
35
30
  "node": "^18.18.0 || ^20.9.0 || >=21.1.0"
36
31
  },
37
- "scripts": {
38
- "dev": "tsdown --watch",
39
- "build": "tsdown",
40
- "test": "vitest",
41
- "lint": "eslint .",
42
- "update": "tsx scripts/update && eslint . --fix",
43
- "typecheck": "tsc --noEmit",
44
- "check": "npm run lint && npm run typecheck",
45
- "prepare": "npm run build"
46
- },
47
32
  "peerDependencies": {
48
33
  "eslint": ">=9.0.0"
49
34
  },
50
35
  "devDependencies": {
51
- "@types/node": "catalog:dev",
52
- "@typescript-eslint/parser": "catalog:test",
53
- "@typescript-eslint/utils": "catalog:dev",
54
- "@vida0905/eslint-config": "catalog:dev",
55
- "@vitest/coverage-v8": "catalog:test",
56
- "change-case": "catalog:dev",
57
- "es-toolkit": "catalog:inline",
58
- "eslint": "catalog:dev",
59
- "eslint-plugin-import-lite": "workspace:*",
60
- "eslint-typegen": "catalog:dev",
61
- "eslint-vitest-rule-tester": "catalog:test",
62
- "json-schema-to-typescript-lite": "catalog:dev",
63
- "nano-staged": "catalog:dev",
64
- "simple-git-hooks": "catalog:dev",
65
- "tinyglobby": "catalog:dev",
66
- "tsdown": "catalog:dev",
67
- "tsx": "catalog:dev",
68
- "typescript": "catalog:dev",
69
- "vitest": "catalog:test"
36
+ "@arethetypeswrong/core": "^0.18.2",
37
+ "@types/node": "^25.3.0",
38
+ "@typescript-eslint/parser": "^8.56.0",
39
+ "@typescript-eslint/utils": "^8.56.0",
40
+ "@vida0905/eslint-config": "^2.10.0",
41
+ "@vitest/coverage-v8": "^4.0.18",
42
+ "change-case": "^5.4.4",
43
+ "es-toolkit": "^1.44.0",
44
+ "eslint": "^9.39.3",
45
+ "eslint-typegen": "^2.3.1",
46
+ "eslint-vitest-rule-tester": "^3.1.0",
47
+ "json-schema-to-typescript-lite": "^15.0.0",
48
+ "nano-staged": "^0.9.0",
49
+ "simple-git-hooks": "^2.13.1",
50
+ "tinyglobby": "^0.2.15",
51
+ "tsdown": "^0.20.3",
52
+ "tsx": "^4.21.0",
53
+ "typescript": "^5.9.3",
54
+ "vitest": "^4.0.18",
55
+ "eslint-plugin-import-lite": "0.5.2"
70
56
  },
71
57
  "simple-git-hooks": {
72
58
  "pre-commit": "npx nano-staged"
73
59
  },
74
60
  "nano-staged": {
75
61
  "*": "eslint --fix"
62
+ },
63
+ "scripts": {
64
+ "dev": "tsdown --watch",
65
+ "build": "tsdown",
66
+ "test": "vitest",
67
+ "lint": "eslint .",
68
+ "update": "tsx scripts/update && eslint . --fix",
69
+ "typecheck": "tsc --noEmit",
70
+ "check": "npm run lint && npm run typecheck",
71
+ "release": "npx bumpp"
76
72
  }
77
- }
73
+ }
@@ -1,14 +0,0 @@
1
- import type { Linter } from 'eslint'
2
-
3
- export declare const configs: {
4
- /**
5
- * The default recommended config in Flat Config Format
6
- */
7
- recommended: Linter.Config
8
- /**
9
- * Enable all rules, in Flat Config Format
10
- */
11
- all: Linter.Config
12
- }
13
-
14
- export type Configs = typeof configs
@@ -1,11 +0,0 @@
1
- import type { Rule } from 'eslint'
2
- import type { RuleOptions } from './rule-options'
3
-
4
- type RuleName<K extends string>
5
- = K extends `${string}/${infer Name}`
6
- ? RuleName<Name>
7
- : K
8
-
9
- export type Rules = Required<{
10
- [K in keyof RuleOptions as RuleName<K>]: Rule.RuleModule
11
- }>