@longzai-intelligence-oxlint/typescript-eslint-plugin 0.1.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/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @longzai-intelligence-oxlint/typescript-eslint-plugin
2
+
3
+ ## 意图
4
+
5
+ 在 Oxlint 运行时复刻 typescript-eslint 生态的关键规则,弥补 Oxlint 原生规则覆盖不足的部分。
6
+
7
+ ## 定位
8
+
9
+ Oxlint 生态的 typescript-eslint 规则实现插件,对标 ESLint 生态 typescript-eslint 插件,通过 `eslintCompatPlugin` 包装以同时兼容 Oxlint 与 ESLint 运行时。
10
+
11
+ ## 职能
12
+
13
+ 提供 `consistent-type-assertions` 规则,约束类型断言风格的一致性;使用 `defineRule` + `createOnce` 实现以获得最佳性能;同时导出断言风格类型与选项类型供外部复用。
14
+
15
+ ## 实现情况
16
+
17
+ 当前仅落地类型断言一致性一条规则,规则、类型与插件对象均已导出;整体处于聚焦单点的成熟形态,其余 typescript-eslint 规则尚未纳入。
@@ -0,0 +1,10 @@
1
+ import { OxlintRules } from "@longzai-intelligence-oxlint/core";
2
+ //#region src/configs/recommended.config.d.ts
3
+ /**
4
+ * 推荐规则配置
5
+ *
6
+ * 包含 typescript-eslint 插件的推荐规则配置。
7
+ */
8
+ declare const recommended: OxlintRules;
9
+ //#endregion
10
+ export { recommended };
@@ -0,0 +1 @@
1
+ const e={"@longzai-intelligence-oxlint/typescript-eslint-plugin/consistent-type-assertions":`error`};export{e as recommended};
@@ -0,0 +1,46 @@
1
+ import { Rule } from "@oxlint/plugins";
2
+ //#region src/rules/consistent-type-assertions/types.d.ts
3
+ /**
4
+ * consistent-type-assertions 规则类型定义
5
+ *
6
+ * 定义规则所需的配置选项和辅助类型。
7
+ */
8
+ /**
9
+ * 断言风格选项
10
+ *
11
+ * - never: 禁止所有类型断言
12
+ * - as: 只允许 as 断言
13
+ * - angle-bracket: 只允许尖括号断言
14
+ */
15
+ type AssertionStyle = 'never' | 'as' | 'angle-bracket';
16
+ /**
17
+ * 规则配置选项
18
+ */
19
+ type ConsistentTypeAssertionsOptions = {
20
+ /**
21
+ * 允许的断言风格
22
+ */
23
+ assertionStyle: AssertionStyle;
24
+ /**
25
+ * 是否允许对象字面量类型的 as const 断言
26
+ */
27
+ objectLiteralTypeAssertions?: boolean;
28
+ };
29
+ //#endregion
30
+ //#region src/rules/consistent-type-assertions/index.d.ts
31
+ /**
32
+ * consistent-type-assertions 规则定义
33
+ */
34
+ declare const consistentTypeAssertionsRule: import("@oxlint/plugins").Rule;
35
+ //#endregion
36
+ //#region src/index.d.ts
37
+ /**
38
+ * typescript-eslint 规则集合
39
+ */
40
+ declare const typescriptEslintRules: Record<string, Rule>;
41
+ /**
42
+ * typescript-eslint 插件
43
+ */
44
+ declare const typescriptEslintPlugin: import("@oxlint/plugins").Plugin;
45
+ //#endregion
46
+ export { type AssertionStyle, type ConsistentTypeAssertionsOptions, consistentTypeAssertionsRule, typescriptEslintPlugin as default, typescriptEslintPlugin, typescriptEslintRules };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{defineRule as e,eslintCompatPlugin as t}from"@oxlint/plugins";function n(e){return typeof e==`object`&&!!e&&`typeAnnotation`in e&&e.typeAnnotation!==null&&typeof e.typeAnnotation==`object`}function r(e){return typeof e==`object`&&!!e}function i(e){return typeof e==`object`&&!!e}function a(e){if(!r(e)||!(`type`in e)||e.type!==`TSTypeReference`||!(`typeName`in e)||e.typeName===null||typeof e.typeName!=`object`)return!1;let t=e.typeName;return i(t)?`name`in t&&t.name===`const`:!1}function o(e){return!r(e)||!(`type`in e)?!1:e.type===`TSTypeLiteral`}function s(e,t,r){if(!n(e))return;let i=e.typeAnnotation;if(r.assertionStyle===`never`){if(a(i))return;t.report({node:e,message:`禁止使用 as 类型断言,请使用类型守卫或 Zod 进行类型验证`});return}if(r.assertionStyle===`angle-bracket`){if(a(i)||r.objectLiteralTypeAssertions&&o(i))return;t.report({node:e,message:`应使用尖括号断言而非 as 断言`});return}}function c(e,t,r){if(r.assertionStyle===`never`){t.report({node:e,message:`禁止使用尖括号类型断言,请使用类型守卫或 Zod 进行类型验证`});return}if(r.assertionStyle===`as`){if(n(e)&&r.objectLiteralTypeAssertions&&o(e.typeAnnotation))return;t.report({node:e,message:`应使用 as 断言而非尖括号断言`});return}}function l(e,t,n){n.assertionStyle===`never`&&t.report({node:e,message:`禁止使用非空断言 (!),请使用类型守卫或 Zod 进行类型验证`})}function u(e){return e===`never`||e===`as`||e===`angle-bracket`}function d(e){return typeof e==`object`&&!!e}function f(e){return!d(e)||!(`assertionStyle`in e)?!1:u(e.assertionStyle)}function p(e){let t={assertionStyle:`never`,objectLiteralTypeAssertions:!1};if(!Array.isArray(e)||e.length===0)return t;let n=e[0];return f(n)?{assertionStyle:n.assertionStyle,objectLiteralTypeAssertions:n.objectLiteralTypeAssertions??!1}:t}const m=e({meta:{type:`suggestion`,docs:{description:`禁止使用类型断言,强制使用类型守卫或 Zod 进行类型验证`}},createOnce(e){let t=p(e.options);return{TSAsExpression(n){s(n,e,t)},TSTypeAssertion(n){c(n,e,t)},TSNonNullExpression(n){l(n,e,t)}}}}),h={"consistent-type-assertions":m},g=t({meta:{name:`@longzai-intelligence-oxlint/typescript-eslint-plugin`},rules:h});export{m as consistentTypeAssertionsRule,g as default,g as typescriptEslintPlugin,h as typescriptEslintRules};
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@longzai-intelligence-oxlint/typescript-eslint-plugin",
3
+ "version": "0.1.0",
4
+ "description": "Oxlint TypeScript ESLint 兼容插件,提供 typescript-eslint 规则的 Oxlint 实现",
5
+ "license": "UNLICENSED",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "type": "module",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ },
17
+ "./configs/recommended": {
18
+ "types": "./dist/configs/recommended.d.ts",
19
+ "import": "./dist/configs/recommended.js"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "build": "lzi-builder",
24
+ "build:prod": "NODE_ENV=production lzi-builder",
25
+ "prepublishOnly": "bun run build:prod",
26
+ "dev": "lzi-builder --watch",
27
+ "clean": "rimraf dist",
28
+ "test": "vitest run",
29
+ "test:watch": "vitest",
30
+ "test:coverage": "vitest run --coverage",
31
+ "lint": "oxlint && oxfmt --check",
32
+ "lint:fix": "oxlint --fix && oxfmt",
33
+ "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
34
+ "typecheck:app": "tsgo --noEmit -p tsconfig/app.json",
35
+ "typecheck:node": "tsgo --noEmit -p tsconfig/node.json",
36
+ "typecheck:test": "tsgo --noEmit -p tsconfig/test.json"
37
+ },
38
+ "dependencies": {
39
+ "@longzai-intelligence-oxlint/core": "0.1.0",
40
+ "@oxlint/plugins": "^1.74.0"
41
+ },
42
+ "devDependencies": {
43
+ "@vitest/coverage-v8": "^4.1.10",
44
+ "typescript": "^6.0.3"
45
+ },
46
+ "peerDependencies": {
47
+ "oxlint": ">=1.0.0"
48
+ }
49
+ }