@longzai-intelligence-oxlint/perfectionist-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 +17 -0
- package/dist/configs/recommended.d.ts +10 -0
- package/dist/configs/recommended.js +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @longzai-intelligence-oxlint/perfectionist-plugin
|
|
2
|
+
|
|
3
|
+
## 意图
|
|
4
|
+
|
|
5
|
+
在静态检查阶段统一导入排序风格,提升代码可读性与 diff 稳定性。
|
|
6
|
+
|
|
7
|
+
## 定位
|
|
8
|
+
|
|
9
|
+
Oxlint 生态的 perfectionist 规则实现插件,对标 ESLint 生态 perfectionist 插件,通过 `eslintCompatPlugin` 包装以同时兼容 Oxlint 与 ESLint 运行时。
|
|
10
|
+
|
|
11
|
+
## 职能
|
|
12
|
+
|
|
13
|
+
提供 `sort-imports` 与 `sort-named-imports` 两条规则,分别约束导入语句顺序与命名导入内部顺序;使用 `defineRule` + `createOnce` 实现以获得最佳性能。
|
|
14
|
+
|
|
15
|
+
## 实现情况
|
|
16
|
+
|
|
17
|
+
两条规则均已实现并按规则文件组织,规则集合与插件对象一并导出;当前规则集合聚焦导入排序维度,处于稳定可用形态。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={"@longzai-intelligence-oxlint/perfectionist-plugin/sort-imports":`error`,"@longzai-intelligence-oxlint/perfectionist-plugin/sort-named-imports":`error`};export{e as recommended};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Rule } from "@oxlint/plugins";
|
|
2
|
+
//#region src/index.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* perfectionist 规则集合
|
|
5
|
+
*/
|
|
6
|
+
declare const perfectionistRules: Record<string, Rule>;
|
|
7
|
+
/**
|
|
8
|
+
* perfectionist 插件
|
|
9
|
+
*/
|
|
10
|
+
declare const perfectionistPlugin: import("@oxlint/plugins").Plugin;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { perfectionistPlugin as default, perfectionistPlugin, perfectionistRules };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{defineRule as e,eslintCompatPlugin as t}from"@oxlint/plugins";const n=[/^@\//,/^@main\//,/^@renderer\//,/^@preload\//,/^@shared\//],r=/^@longzai-intelligence\//;function i(e){return e.type===`Program`}function a(e){return e.type===`ImportDeclaration`}function o(e,t){return t?`type`:n.some(t=>t.test(e))?`internal`:r.test(e)?`external`:e.startsWith(`.`)?e===`.`||e===`./`?`index`:e.startsWith(`../`)?`parent`:`sibling`:`external`}const s={type:0,"side-effect":1,external:2,internal:3,parent:4,sibling:5,index:6,unknown:7},c=e({meta:{type:`layout`,docs:{description:`对 import 语句进行排序`}},createOnce(e){return{Program(t){if(!i(t))return;let n=t.body,r=[];for(let e of n)if(a(e)){let t=e.source.value,n=e.importKind===`type`;r.push({node:e,source:t,group:o(t,n),isType:n})}else e.type===`ExpressionStatement`&&e.expression.type===`CallExpression`&&e.expression.callee.type===`Identifier`&&e.expression.callee.name===`import`&&r.push({node:e,source:``,group:`side-effect`,isType:!1});for(let t=1;t<r.length;t++){let n=r[t-1],i=r[t];!n||!i||s[n.group]>s[i.group]&&e.report({node:i.node,message:`导入顺序错误:'${i.source}' 应在 '${n.source}' 之前`})}}}}});function l(e){return e.type===`ImportDeclaration`}function u(e){return e.type===`ImportSpecifier`}const d={"sort-imports":c,"sort-named-imports":e({meta:{type:`layout`,docs:{description:`对具名导入进行排序`}},createOnce(e){return{ImportDeclaration(t){if(!l(t))return;let n=t.specifiers.filter(u);if(n.length<=1)return;let r=n.map(e=>e.imported.type===`Identifier`?e.imported.name:String(e.imported.value)),i=[...r].sort((e,t)=>e.localeCompare(t,void 0,{numeric:!0}));for(let n=0;n<r.length;n++)if(r[n]!==i[n]){e.report({node:t,message:`具名导入未按字母顺序排列:'${r[n]}' 应为 '${i[n]}'`});break}}}}})},f=t({meta:{name:`@longzai-intelligence-oxlint/perfectionist-plugin`},rules:d});export{f as default,f as perfectionistPlugin,d as perfectionistRules};
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-oxlint/perfectionist-plugin",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Oxlint perfectionist 兼容插件,提供排序规则的 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
|
+
"acorn": "^8.17.0",
|
|
45
|
+
"acorn-loose": "^8.5.2",
|
|
46
|
+
"typescript": "^6.0.3"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"oxlint": ">=1.0.0"
|
|
50
|
+
}
|
|
51
|
+
}
|