@longzai-intelligence/oxlint-utils 0.0.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 ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:path`);c=s(c,1);function l(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`ImportDeclaration`&&`source`in e&&e.source!==null&&typeof e.source==`object`&&`value`in e.source&&typeof e.source.value==`string`&&`specifiers`in e&&Array.isArray(e.specifiers)}function u(e){return typeof e==`object`&&!!e&&`type`in e&&(e.type===`ImportSpecifier`||e.type===`ImportDefaultSpecifier`||e.type===`ImportNamespaceSpecifier`)&&`imported`in e&&e.imported!==null&&typeof e.imported==`object`&&`name`in e.imported&&typeof e.imported.name==`string`&&`local`in e&&e.local!==null&&typeof e.local==`object`&&`name`in e.local&&typeof e.local.name==`string`}function d(e){return e.type===`ImportDefaultSpecifier`}function f(e){return e.type===`ImportNamespaceSpecifier`}function p(e){return e.specifiers.filter(u).map(e=>e.imported.name)}function m(e,t){return p(e).includes(t)}function h(e){return e.endsWith(`.test.ts`)||e.endsWith(`.spec.ts`)}function g(e,t){return e.endsWith(t)}function _(e,t){return t.some(t=>e.endsWith(t))}function v(e){return c.default.basename(e)}function y(e,t){let n=e.replace(/\\/g,`/`);return t.some(e=>n.endsWith(e))}function b(e){return/^I[A-Z]/.test(e)}function x(e){return e.endsWith(`DTO`)}function S(e){return e.endsWith(`Dto`)}function C(e){return b(e)?e.substring(1):e}function w(e){return e.replace(/DTO$/,`Dto`)}function T(e){return e.replace(/Dto$/,`DTO`)}function E(e){return typeof e==`object`&&!!e&&`id`in e&&e.id!==null&&typeof e.id==`object`&&`name`in e.id&&typeof e.id.name==`string`&&`type`in e&&typeof e.type==`string`}function D(e){return E(e)&&`range`in e.id&&Array.isArray(e.id.range)&&e.id.range.length===2}function O(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`CallExpression`&&`callee`in e&&typeof e.callee==`object`&&e.callee!==null&&`name`in e.callee}function k(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`ObjectExpression`}function A(e){return typeof e==`object`&&!!e&&`meta`in e&&typeof e.meta==`object`&&e.meta!==null&&`name`in e.meta&&typeof e.meta.name==`string`}function j(e){if(!A(e))throw Error(`无效的 Oxlint 插件:插件对象必须包含 meta.name 属性`);return e.meta.name}exports.getFileName=v,exports.getImportedNames=p,exports.getPluginName=j,exports.hasAnyFileSuffix=_,exports.hasFileSuffix=g,exports.hasIPrefix=b,exports.hasIdWithName=E,exports.hasIdWithNameAndRange=D,exports.hasImportedName=m,exports.isCallExpressionNode=O,exports.isDefaultImport=d,exports.isImportDeclaration=l,exports.isImportSpecifier=u,exports.isInExcludedPath=y,exports.isNamespaceImport=f,exports.isObjectExpressionNode=k,exports.isPlugin=A,exports.isTestFile=h,exports.isValidDtoNameCamelCase=S,exports.isValidDtoNameUpperCase=x,exports.removeIPrefix=C,exports.toDtoCamelCase=w,exports.toDtoUpperCase=T;
@@ -0,0 +1,102 @@
1
+ import { Context } from "@oxlint/plugins";
2
+
3
+ //#region src/types/rule.types.d.ts
4
+ type OxlintContext = Context;
5
+ type RuleState = {
6
+ hasValidImport: boolean;
7
+ hasForbiddenImport: boolean;
8
+ hasExportDefault: boolean;
9
+ forbiddenImportNode: unknown | null;
10
+ forbiddenImportName: string;
11
+ };
12
+ //#endregion
13
+ //#region src/types/ast.types.d.ts
14
+ type NodeWithIdentifier = {
15
+ id: {
16
+ name: string;
17
+ };
18
+ type: string;
19
+ };
20
+ type NodeWithIdentifierAndRange = NodeWithIdentifier & {
21
+ id: {
22
+ name: string;
23
+ range: [number, number];
24
+ };
25
+ };
26
+ type ImportSpecifierNode = {
27
+ type: 'ImportSpecifier' | 'ImportDefaultSpecifier' | 'ImportNamespaceSpecifier';
28
+ imported: {
29
+ name: string;
30
+ };
31
+ local: {
32
+ name: string;
33
+ };
34
+ };
35
+ type ImportDeclarationNode = {
36
+ type: 'ImportDeclaration';
37
+ source: {
38
+ value: string;
39
+ };
40
+ specifiers: ImportSpecifierNode[];
41
+ };
42
+ type ExportDefaultDeclarationNode = {
43
+ type: 'ExportDefaultDeclaration';
44
+ declaration: {
45
+ type: string;
46
+ name?: string;
47
+ callee?: {
48
+ name?: string;
49
+ };
50
+ properties?: unknown[];
51
+ };
52
+ };
53
+ type CallExpressionNode = {
54
+ type: 'CallExpression';
55
+ callee: {
56
+ name?: string;
57
+ };
58
+ };
59
+ type ObjectExpressionNode = {
60
+ type: 'ObjectExpression';
61
+ };
62
+ //#endregion
63
+ //#region src/utils/import.utils.d.ts
64
+ declare function isImportDeclaration(node: unknown): node is ImportDeclarationNode;
65
+ declare function isImportSpecifier(specifier: unknown): specifier is ImportSpecifierNode;
66
+ declare function isDefaultImport(specifier: ImportSpecifierNode): boolean;
67
+ declare function isNamespaceImport(specifier: ImportSpecifierNode): boolean;
68
+ declare function getImportedNames(node: ImportDeclarationNode): string[];
69
+ declare function hasImportedName(node: ImportDeclarationNode, name: string): boolean;
70
+ //#endregion
71
+ //#region src/utils/file.utils.d.ts
72
+ declare function isTestFile(fileName: string): boolean;
73
+ declare function hasFileSuffix(fileName: string, suffix: string): boolean;
74
+ declare function hasAnyFileSuffix(fileName: string, suffixes: string[]): boolean;
75
+ declare function getFileName(filePath: string): string;
76
+ declare function isInExcludedPath(filePath: string, excludedPaths: string[]): boolean;
77
+ //#endregion
78
+ //#region src/utils/naming.utils.d.ts
79
+ declare function hasIPrefix(name: string): boolean;
80
+ declare function isValidDtoNameUpperCase(name: string): boolean;
81
+ declare function isValidDtoNameCamelCase(name: string): boolean;
82
+ declare function removeIPrefix(name: string): string;
83
+ declare function toDtoCamelCase(name: string): string;
84
+ declare function toDtoUpperCase(name: string): string;
85
+ //#endregion
86
+ //#region src/guards/ast.guards.d.ts
87
+ declare function hasIdWithName(node: unknown): node is NodeWithIdentifier;
88
+ declare function hasIdWithNameAndRange(node: unknown): node is NodeWithIdentifierAndRange;
89
+ declare function isCallExpressionNode(obj: unknown): obj is CallExpressionNode;
90
+ declare function isObjectExpressionNode(obj: unknown): obj is ObjectExpressionNode;
91
+ //#endregion
92
+ //#region src/guards/plugin.guards.d.ts
93
+ type PluginMeta = {
94
+ name: string;
95
+ };
96
+ type Plugin = {
97
+ meta: PluginMeta;
98
+ };
99
+ declare function isPlugin(obj: unknown): obj is Plugin;
100
+ declare function getPluginName(plugin: unknown): string;
101
+ //#endregion
102
+ export { CallExpressionNode, ExportDefaultDeclarationNode, ImportDeclarationNode, ImportSpecifierNode, NodeWithIdentifier, NodeWithIdentifierAndRange, ObjectExpressionNode, OxlintContext, Plugin, PluginMeta, RuleState, getFileName, getImportedNames, getPluginName, hasAnyFileSuffix, hasFileSuffix, hasIPrefix, hasIdWithName, hasIdWithNameAndRange, hasImportedName, isCallExpressionNode, isDefaultImport, isImportDeclaration, isImportSpecifier, isInExcludedPath, isNamespaceImport, isObjectExpressionNode, isPlugin, isTestFile, isValidDtoNameCamelCase, isValidDtoNameUpperCase, removeIPrefix, toDtoCamelCase, toDtoUpperCase };
@@ -0,0 +1,102 @@
1
+ import { Context } from "@oxlint/plugins";
2
+
3
+ //#region src/types/rule.types.d.ts
4
+ type OxlintContext = Context;
5
+ type RuleState = {
6
+ hasValidImport: boolean;
7
+ hasForbiddenImport: boolean;
8
+ hasExportDefault: boolean;
9
+ forbiddenImportNode: unknown | null;
10
+ forbiddenImportName: string;
11
+ };
12
+ //#endregion
13
+ //#region src/types/ast.types.d.ts
14
+ type NodeWithIdentifier = {
15
+ id: {
16
+ name: string;
17
+ };
18
+ type: string;
19
+ };
20
+ type NodeWithIdentifierAndRange = NodeWithIdentifier & {
21
+ id: {
22
+ name: string;
23
+ range: [number, number];
24
+ };
25
+ };
26
+ type ImportSpecifierNode = {
27
+ type: 'ImportSpecifier' | 'ImportDefaultSpecifier' | 'ImportNamespaceSpecifier';
28
+ imported: {
29
+ name: string;
30
+ };
31
+ local: {
32
+ name: string;
33
+ };
34
+ };
35
+ type ImportDeclarationNode = {
36
+ type: 'ImportDeclaration';
37
+ source: {
38
+ value: string;
39
+ };
40
+ specifiers: ImportSpecifierNode[];
41
+ };
42
+ type ExportDefaultDeclarationNode = {
43
+ type: 'ExportDefaultDeclaration';
44
+ declaration: {
45
+ type: string;
46
+ name?: string;
47
+ callee?: {
48
+ name?: string;
49
+ };
50
+ properties?: unknown[];
51
+ };
52
+ };
53
+ type CallExpressionNode = {
54
+ type: 'CallExpression';
55
+ callee: {
56
+ name?: string;
57
+ };
58
+ };
59
+ type ObjectExpressionNode = {
60
+ type: 'ObjectExpression';
61
+ };
62
+ //#endregion
63
+ //#region src/utils/import.utils.d.ts
64
+ declare function isImportDeclaration(node: unknown): node is ImportDeclarationNode;
65
+ declare function isImportSpecifier(specifier: unknown): specifier is ImportSpecifierNode;
66
+ declare function isDefaultImport(specifier: ImportSpecifierNode): boolean;
67
+ declare function isNamespaceImport(specifier: ImportSpecifierNode): boolean;
68
+ declare function getImportedNames(node: ImportDeclarationNode): string[];
69
+ declare function hasImportedName(node: ImportDeclarationNode, name: string): boolean;
70
+ //#endregion
71
+ //#region src/utils/file.utils.d.ts
72
+ declare function isTestFile(fileName: string): boolean;
73
+ declare function hasFileSuffix(fileName: string, suffix: string): boolean;
74
+ declare function hasAnyFileSuffix(fileName: string, suffixes: string[]): boolean;
75
+ declare function getFileName(filePath: string): string;
76
+ declare function isInExcludedPath(filePath: string, excludedPaths: string[]): boolean;
77
+ //#endregion
78
+ //#region src/utils/naming.utils.d.ts
79
+ declare function hasIPrefix(name: string): boolean;
80
+ declare function isValidDtoNameUpperCase(name: string): boolean;
81
+ declare function isValidDtoNameCamelCase(name: string): boolean;
82
+ declare function removeIPrefix(name: string): string;
83
+ declare function toDtoCamelCase(name: string): string;
84
+ declare function toDtoUpperCase(name: string): string;
85
+ //#endregion
86
+ //#region src/guards/ast.guards.d.ts
87
+ declare function hasIdWithName(node: unknown): node is NodeWithIdentifier;
88
+ declare function hasIdWithNameAndRange(node: unknown): node is NodeWithIdentifierAndRange;
89
+ declare function isCallExpressionNode(obj: unknown): obj is CallExpressionNode;
90
+ declare function isObjectExpressionNode(obj: unknown): obj is ObjectExpressionNode;
91
+ //#endregion
92
+ //#region src/guards/plugin.guards.d.ts
93
+ type PluginMeta = {
94
+ name: string;
95
+ };
96
+ type Plugin = {
97
+ meta: PluginMeta;
98
+ };
99
+ declare function isPlugin(obj: unknown): obj is Plugin;
100
+ declare function getPluginName(plugin: unknown): string;
101
+ //#endregion
102
+ export { CallExpressionNode, ExportDefaultDeclarationNode, ImportDeclarationNode, ImportSpecifierNode, NodeWithIdentifier, NodeWithIdentifierAndRange, ObjectExpressionNode, OxlintContext, Plugin, PluginMeta, RuleState, getFileName, getImportedNames, getPluginName, hasAnyFileSuffix, hasFileSuffix, hasIPrefix, hasIdWithName, hasIdWithNameAndRange, hasImportedName, isCallExpressionNode, isDefaultImport, isImportDeclaration, isImportSpecifier, isInExcludedPath, isNamespaceImport, isObjectExpressionNode, isPlugin, isTestFile, isValidDtoNameCamelCase, isValidDtoNameUpperCase, removeIPrefix, toDtoCamelCase, toDtoUpperCase };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import e from"node:path";function t(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`ImportDeclaration`&&`source`in e&&e.source!==null&&typeof e.source==`object`&&`value`in e.source&&typeof e.source.value==`string`&&`specifiers`in e&&Array.isArray(e.specifiers)}function n(e){return typeof e==`object`&&!!e&&`type`in e&&(e.type===`ImportSpecifier`||e.type===`ImportDefaultSpecifier`||e.type===`ImportNamespaceSpecifier`)&&`imported`in e&&e.imported!==null&&typeof e.imported==`object`&&`name`in e.imported&&typeof e.imported.name==`string`&&`local`in e&&e.local!==null&&typeof e.local==`object`&&`name`in e.local&&typeof e.local.name==`string`}function r(e){return e.type===`ImportDefaultSpecifier`}function i(e){return e.type===`ImportNamespaceSpecifier`}function a(e){return e.specifiers.filter(n).map(e=>e.imported.name)}function o(e,t){return a(e).includes(t)}function s(e){return e.endsWith(`.test.ts`)||e.endsWith(`.spec.ts`)}function c(e,t){return e.endsWith(t)}function l(e,t){return t.some(t=>e.endsWith(t))}function u(t){return e.basename(t)}function d(e,t){let n=e.replace(/\\/g,`/`);return t.some(e=>n.endsWith(e))}function f(e){return/^I[A-Z]/.test(e)}function p(e){return e.endsWith(`DTO`)}function m(e){return e.endsWith(`Dto`)}function h(e){return f(e)?e.substring(1):e}function g(e){return e.replace(/DTO$/,`Dto`)}function _(e){return e.replace(/Dto$/,`DTO`)}function v(e){return typeof e==`object`&&!!e&&`id`in e&&e.id!==null&&typeof e.id==`object`&&`name`in e.id&&typeof e.id.name==`string`&&`type`in e&&typeof e.type==`string`}function y(e){return v(e)&&`range`in e.id&&Array.isArray(e.id.range)&&e.id.range.length===2}function b(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`CallExpression`&&`callee`in e&&typeof e.callee==`object`&&e.callee!==null&&`name`in e.callee}function x(e){return typeof e==`object`&&!!e&&`type`in e&&e.type===`ObjectExpression`}function S(e){return typeof e==`object`&&!!e&&`meta`in e&&typeof e.meta==`object`&&e.meta!==null&&`name`in e.meta&&typeof e.meta.name==`string`}function C(e){if(!S(e))throw Error(`无效的 Oxlint 插件:插件对象必须包含 meta.name 属性`);return e.meta.name}export{u as getFileName,a as getImportedNames,C as getPluginName,l as hasAnyFileSuffix,c as hasFileSuffix,f as hasIPrefix,v as hasIdWithName,y as hasIdWithNameAndRange,o as hasImportedName,b as isCallExpressionNode,r as isDefaultImport,t as isImportDeclaration,n as isImportSpecifier,d as isInExcludedPath,i as isNamespaceImport,x as isObjectExpressionNode,S as isPlugin,s as isTestFile,m as isValidDtoNameCamelCase,p as isValidDtoNameUpperCase,h as removeIPrefix,g as toDtoCamelCase,_ as toDtoUpperCase};
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@longzai-intelligence/oxlint-utils",
3
+ "version": "0.0.1",
4
+ "license": "UNLICENSED",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "type": "module",
9
+ "main": "./dist/index.cjs",
10
+ "module": "./dist/index.mjs",
11
+ "types": "./dist/index.d.mts",
12
+ "exports": {
13
+ ".": {
14
+ "types": {
15
+ "import": "./dist/index.d.mts",
16
+ "require": "./dist/index.d.cts"
17
+ },
18
+ "import": "./dist/index.mjs",
19
+ "require": "./dist/index.cjs"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "build": "tsdown",
24
+ "build:prod": "NODE_ENV=production tsdown",
25
+ "prepublishOnly": "bun run build:prod",
26
+ "dev": "tsdown --watch",
27
+ "clean": "rimraf dist",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest",
30
+ "test:coverage": "vitest run --coverage",
31
+ "lint": "bun run lint:oxlint",
32
+ "lint:oxlint": "oxlint",
33
+ "lint:eslint": "eslint .",
34
+ "lint:fix": "bun run oxc:fix",
35
+ "lint:fix:oxlint": "oxlint --fix",
36
+ "lint:fix:eslint": "eslint . --fix",
37
+ "typecheck": "bun run typecheck:app && bun run typecheck:node",
38
+ "typecheck:app": "tsc --noEmit -p tsconfig/app.json",
39
+ "typecheck:node": "tsc --noEmit -p tsconfig/node.json",
40
+ "lint:file": "bun run lint:file:oxlint",
41
+ "lint:file:oxlint": "oxlint",
42
+ "lint:file:eslint": "eslint",
43
+ "fmt": "oxfmt",
44
+ "fmt:check": "oxfmt --check",
45
+ "oxc": "bun run lint:oxlint && bun run fmt:check",
46
+ "oxc:fix": "bun run lint:fix:oxlint && bun run fmt"
47
+ },
48
+ "dependencies": {
49
+ "@oxlint/plugins": "^1.64.0"
50
+ },
51
+ "devDependencies": {
52
+ "@longzai-intelligence/eslint-preset-library": "0.2.13",
53
+ "@longzai-intelligence/oxlint-config": "0.0.1",
54
+ "@longzai-intelligence/oxlint-plugin-architecture": "0.0.1",
55
+ "@longzai-intelligence/oxlint-plugin-code-style": "0.0.1",
56
+ "@longzai-intelligence/oxlint-plugin-package-json": "0.0.1",
57
+ "@longzai-intelligence/oxlint-plugin-perfectionist": "0.0.1",
58
+ "@longzai-intelligence/oxlint-plugin-schema-type-separation": "0.0.1",
59
+ "@longzai-intelligence/oxlint-plugin-stylistic": "0.0.1",
60
+ "@longzai-intelligence/oxlint-plugin-tsdoc": "0.0.1",
61
+ "@longzai-intelligence/oxlint-plugin-typescript-eslint": "0.0.1",
62
+ "@longzai-intelligence/oxlint-plugin-zod": "0.0.1",
63
+ "@longzai-intelligence/tsdown-config": "0.0.1",
64
+ "@longzai-intelligence/typescript-config": "0.0.3",
65
+ "@longzai-intelligence/vitest-config": "0.0.10",
66
+ "@types/node": "^25.7.0",
67
+ "oxlint": "^1.64.0",
68
+ "rimraf": "^6.1.3",
69
+ "tsdown": "^0.21.10",
70
+ "vitest": "^4.1.6"
71
+ },
72
+ "peerDependencies": {
73
+ "oxlint": ">=1.0.0"
74
+ }
75
+ }