@longzai-intelligence-oxlint/perfectionist-plugin 0.1.18 → 0.1.19

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 CHANGED
@@ -1,17 +1,13 @@
1
1
  # @longzai-intelligence-oxlint/perfectionist-plugin
2
2
 
3
- ## 意图
3
+ Longzai Intelligence Oxlint 的导入排序插件,统一导入排序风格。
4
4
 
5
- 在静态检查阶段统一导入排序风格,提升代码可读性与 diff 稳定性。
5
+ ## 简介
6
6
 
7
- ## 定位
7
+ 治理导入排序风格漂移的问题:导入语句顺序与命名导入内部顺序在静态检查阶段统一约束,防止排序风格漂移损害可读性与 diff 稳定性。
8
8
 
9
- Oxlint 生态的 perfectionist 规则实现插件,对标 ESLint 生态 perfectionist 插件,通过 `eslintCompatPlugin` 包装以同时兼容 Oxlint 与 ESLint 运行时。
9
+ ## 能力
10
10
 
11
- ## 职能
12
-
13
- 提供 `sort-imports` 与 `sort-named-imports` 两条规则,分别约束导入语句顺序与命名导入内部顺序;使用 `defineRule` + `createOnce` 实现以获得最佳性能。
14
-
15
- ## 实现情况
16
-
17
- 两条规则均已实现并按规则文件组织,规则集合与插件对象一并导出;当前规则集合聚焦导入排序维度,处于稳定可用形态。
11
+ - `sort-imports` — 导入语句顺序约束
12
+ - `sort-named-imports` — 命名导入内部顺序约束
13
+ - 同时兼容 Oxlint 与 ESLint 运行时
package/dist/index.js CHANGED
@@ -1 +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};
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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longzai-intelligence-oxlint/perfectionist-plugin",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Oxlint perfectionist 兼容插件,提供排序规则的 Oxlint 实现",
5
5
  "license": "UNLICENSED",
6
6
  "files": [
@@ -36,7 +36,7 @@
36
36
  "typecheck:test": "lzi-tsgo typecheck tsconfig/test.json"
37
37
  },
38
38
  "dependencies": {
39
- "@longzai-intelligence-oxlint/core": "0.1.18",
39
+ "@longzai-intelligence-oxlint/core": "0.1.19",
40
40
  "@oxlint/plugins": "^1.74.0"
41
41
  },
42
42
  "devDependencies": {