@byscripts/eslint-plugin 0.4.0 → 0.6.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 +10 -5
- package/dist/vue-block-attribute-order.d.mts +18 -0
- package/dist/vue-block-attribute-order.d.mts.map +1 -0
- package/dist/{index.mjs → vue-block-attribute-order.mjs} +7 -8
- package/dist/vue-block-attribute-order.mjs.map +1 -0
- package/package.json +7 -7
- package/dist/index.d.mts +0 -8
package/README.md
CHANGED
|
@@ -24,15 +24,20 @@ Custom order via rule options:
|
|
|
24
24
|
}]
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
##
|
|
27
|
+
## Install
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
|
-
pnpm
|
|
31
|
-
|
|
30
|
+
pnpm add -D @byscripts/eslint-plugin eslint
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
// eslint.config.js
|
|
35
|
+
import vueBlockAttributeOrder from "@byscripts/eslint-plugin/vue-block-attribute-order";
|
|
36
|
+
|
|
37
|
+
export default [...yourOtherRules, vueBlockAttributeOrder];
|
|
32
38
|
```
|
|
33
39
|
|
|
34
40
|
## Notes
|
|
35
41
|
|
|
36
|
-
-
|
|
37
|
-
- Peer dependency: `eslint ^9.22.0`
|
|
42
|
+
- Peer dependency: `eslint ^9.22.0 || ^10.0.0`
|
|
38
43
|
- Requires `vue-eslint-parser` in the consumer project (for `parserServices.getDocumentFragment()`)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Rule } from "eslint";
|
|
2
|
+
|
|
3
|
+
//#region src/vue-block-attribute-order.d.ts
|
|
4
|
+
declare const _default: {
|
|
5
|
+
plugins: {
|
|
6
|
+
byscripts: {
|
|
7
|
+
rules: {
|
|
8
|
+
"vue-block-attribute-order": Rule.RuleModule;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
rules: {
|
|
13
|
+
"byscripts/vue-block-attribute-order": "error";
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
export { _default as default };
|
|
18
|
+
//# sourceMappingURL=vue-block-attribute-order.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue-block-attribute-order.d.mts","names":[],"sources":["../src/vue-block-attribute-order.ts"],"mappings":";;;cAA2C,QAAA"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
//#region src/block-attribute-order.ts
|
|
2
1
|
const DEFAULT_ORDER = {
|
|
3
2
|
script: ["lang", "setup"],
|
|
4
3
|
style: ["lang", "scoped"]
|
|
5
4
|
};
|
|
6
|
-
const
|
|
5
|
+
const rule = {
|
|
7
6
|
meta: {
|
|
8
7
|
type: "layout",
|
|
9
8
|
fixable: "code",
|
|
@@ -57,10 +56,10 @@ const blockAttributeOrder = {
|
|
|
57
56
|
} };
|
|
58
57
|
}
|
|
59
58
|
};
|
|
59
|
+
var vue_block_attribute_order_default = {
|
|
60
|
+
plugins: { byscripts: { rules: { "vue-block-attribute-order": rule } } },
|
|
61
|
+
rules: { "byscripts/vue-block-attribute-order": "error" }
|
|
62
|
+
};
|
|
63
|
+
export { vue_block_attribute_order_default as default };
|
|
60
64
|
|
|
61
|
-
//#
|
|
62
|
-
//#region src/index.ts
|
|
63
|
-
var src_default = { blockAttributeOrder };
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
|
-
export { src_default as default };
|
|
65
|
+
//# sourceMappingURL=vue-block-attribute-order.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue-block-attribute-order.mjs","names":[],"sources":["../src/vue-block-attribute-order.ts"],"sourcesContent":["import type { Linter, Rule } from \"eslint\";\n\ntype AttributeOrder = Record<string, string[]>;\n\nconst DEFAULT_ORDER: AttributeOrder = {\n script: [\"lang\", \"setup\"],\n style: [\"lang\", \"scoped\"],\n};\n\nconst rule: Rule.RuleModule = {\n meta: {\n type: \"layout\",\n fixable: \"code\",\n schema: [\n {\n type: \"object\",\n additionalProperties: {\n type: \"array\",\n items: { type: \"string\" },\n },\n },\n ],\n messages: {\n wrongOrder: \"Attributes on <{{tag}}> should follow order: {{expected}}.\",\n },\n },\n create(context) {\n if (!context.filename.endsWith(\".vue\")) {\n return {};\n }\n\n const attributeOrder: AttributeOrder = {\n ...DEFAULT_ORDER,\n ...(context.options[0] as AttributeOrder),\n };\n\n const { parserServices } = context.sourceCode;\n\n const documentFragment = parserServices.getDocumentFragment?.();\n\n if (!documentFragment) {\n return {};\n }\n\n return {\n Program() {\n for (const child of documentFragment.children) {\n if (child.type !== \"VElement\") {\n continue;\n }\n\n const expectedOrder = attributeOrder[child.name];\n\n if (!expectedOrder) {\n continue;\n }\n\n const attributes = child.startTag.attributes.filter(\n (a: Record<string, unknown>) =>\n a.type === \"VAttribute\" && !a.directive,\n );\n\n const attributeNames: string[] = attributes.map(\n (a: Record<string, Record<string, unknown>>) => a.key.name,\n );\n\n const relevantNames = attributeNames.filter((n) =>\n expectedOrder.includes(n),\n );\n\n const expectedNames = expectedOrder.filter((n) =>\n relevantNames.includes(n),\n );\n\n if (relevantNames.every((name, i) => name === expectedNames[i])) {\n continue;\n }\n\n const sourceCode = context.sourceCode;\n\n context.report({\n loc: child.startTag.loc,\n messageId: \"wrongOrder\",\n data: { tag: child.name, expected: expectedNames.join(\", \") },\n fix(fixer) {\n const sorted = [...attributes].sort((attributeA, attributeB) => {\n const attributeAIndex = expectedOrder.indexOf(\n attributeA.key.name,\n );\n\n const attributeBIndex = expectedOrder.indexOf(\n attributeB.key.name,\n );\n\n return (\n (attributeAIndex === -1 ? 999 : attributeAIndex) -\n (attributeBIndex === -1 ? 999 : attributeBIndex)\n );\n });\n\n const newText = sorted\n .map((a) => sourceCode.getText(a))\n .join(\" \");\n\n const firstAttribute = attributes[0];\n\n const lastAttribute = attributes[attributes.length - 1];\n\n return fixer.replaceTextRange(\n [firstAttribute.range[0], lastAttribute.range[1]],\n newText,\n );\n },\n });\n }\n },\n };\n },\n};\n\nexport default {\n plugins: {\n byscripts: {\n rules: {\n \"vue-block-attribute-order\": rule,\n },\n },\n },\n rules: {\n \"byscripts/vue-block-attribute-order\": \"error\",\n },\n} satisfies Linter.Config;\n"],"mappings":"AAIA,MAAM,gBAAgC;CACpC,QAAQ,CAAC,QAAQ,QAAQ;CACzB,OAAO,CAAC,QAAQ,SAAA;CACjB;AAED,MAAM,OAAwB;CAC5B,MAAM;EACJ,MAAM;EACN,SAAS;EACT,QAAQ,CACN;GACE,MAAM;GACN,sBAAsB;IACpB,MAAM;IACN,OAAO,EAAE,MAAM,UAAA;;GAElB,CACF;EACD,UAAU,EACR,YAAY,8DAAA;EAEf;CACD,OAAO,SAAS;AACd,MAAI,CAAC,QAAQ,SAAS,SAAS,OAAO,CACpC,QAAO,EAAE;EAGX,MAAM,iBAAiC;GACrC,GAAG;GACH,GAAI,QAAQ,QAAQ;GACrB;EAED,MAAM,EAAE,mBAAmB,QAAQ;EAEnC,MAAM,mBAAmB,eAAe,uBAAuB;AAE/D,MAAI,CAAC,iBACH,QAAO,EAAE;AAGX,SAAO,EACL,UAAU;AACR,QAAK,MAAM,SAAS,iBAAiB,UAAU;AAC7C,QAAI,MAAM,SAAS,WACjB;IAGF,MAAM,gBAAgB,eAAe,MAAM;AAE3C,QAAI,CAAC,cACH;IAGF,MAAM,aAAa,MAAM,SAAS,WAAW,QAC1C,MACC,EAAE,SAAS,gBAAgB,CAAC,EAAE,UACjC;IAMD,MAAM,gBAJ2B,WAAW,KACzC,MAA+C,EAAE,IAAI,KACvD,CAEoC,QAAQ,MAC3C,cAAc,SAAS,EAAE,CAC1B;IAED,MAAM,gBAAgB,cAAc,QAAQ,MAC1C,cAAc,SAAS,EAAE,CAC1B;AAED,QAAI,cAAc,OAAO,MAAM,MAAM,SAAS,cAAc,GAAG,CAC7D;IAGF,MAAM,aAAa,QAAQ;AAE3B,YAAQ,OAAO;KACb,KAAK,MAAM,SAAS;KACpB,WAAW;KACX,MAAM;MAAE,KAAK,MAAM;MAAM,UAAU,cAAc,KAAK,KAAA;MAAO;KAC7D,IAAI,OAAO;MAgBT,MAAM,UAfS,CAAC,GAAG,WAAW,CAAC,MAAM,YAAY,eAAe;OAC9D,MAAM,kBAAkB,cAAc,QACpC,WAAW,IAAI,KAChB;OAED,MAAM,kBAAkB,cAAc,QACpC,WAAW,IAAI,KAChB;AAED,eACG,oBAAoB,KAAK,MAAM,oBAC/B,oBAAoB,KAAK,MAAM;QAElC,CAGC,KAAK,MAAM,WAAW,QAAQ,EAAE,CAAC,CACjC,KAAK,IAAI;MAEZ,MAAM,iBAAiB,WAAW;MAElC,MAAM,gBAAgB,WAAW,WAAW,SAAS;AAErD,aAAO,MAAM,iBACX,CAAC,eAAe,MAAM,IAAI,cAAc,MAAM,GAAG,EACjD,QACD;;KAEJ,CAAC;;KAGP;;CAEJ;AAED,IAAA,oCAAe;CACb,SAAS,EACP,WAAW,EACT,OAAO,EACL,6BAA6B,MAC9B,EACF,EACF;CACD,OAAO,EACL,uCAAuC,SAAA;CAE1C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@byscripts/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"url": "https://github.com/ByScripts/toolbox"
|
|
6
6
|
},
|
|
@@ -9,20 +9,20 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"exports": {
|
|
12
|
-
"
|
|
13
|
-
"types": "./dist/
|
|
14
|
-
"default": "./dist/
|
|
12
|
+
"./vue-block-attribute-order": {
|
|
13
|
+
"types": "./dist/vue-block-attribute-order.d.mts",
|
|
14
|
+
"default": "./dist/vue-block-attribute-order.mjs"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@tsconfig/node22": "^22.0.5",
|
|
19
|
-
"
|
|
19
|
+
"obuild": "^0.4.31"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"eslint": "^9.22.0"
|
|
22
|
+
"eslint": "^9.22.0 || ^10.0.0"
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"scripts": {
|
|
26
|
-
"build": "
|
|
26
|
+
"build": "obuild"
|
|
27
27
|
}
|
|
28
28
|
}
|