@byscripts/eslint-plugin 0.5.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 CHANGED
@@ -24,15 +24,20 @@ Custom order via rule options:
24
24
  }]
25
25
  ```
26
26
 
27
- ## Dev
27
+ ## Install
28
28
 
29
29
  ```bash
30
- pnpm build # compile src/ -> dist/index.mjs + dist/index.d.mts
31
- pnpm publish --access public # publish to npm
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
- - Built with `tsdown --dts`
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()`)
@@ -2,27 +2,17 @@ import { Rule } from "eslint";
2
2
 
3
3
  //#region src/vue-block-attribute-order.d.ts
4
4
  declare const _default: {
5
- meta: {
6
- type: "layout";
7
- fixable: "code";
8
- schema: {
9
- type: "object";
10
- additionalProperties: {
11
- type: "array";
12
- items: {
13
- type: "string";
14
- };
5
+ plugins: {
6
+ byscripts: {
7
+ rules: {
8
+ "vue-block-attribute-order": Rule.RuleModule;
15
9
  };
16
- }[];
17
- messages: {
18
- wrongOrder: string;
19
10
  };
20
11
  };
21
- create(context: Rule.RuleContext): {
22
- Program?: undefined;
23
- } | {
24
- Program(): void;
12
+ rules: {
13
+ "byscripts/vue-block-attribute-order": "error";
25
14
  };
26
15
  };
27
16
  //#endregion
28
- export { _default as default };
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"}
@@ -2,7 +2,7 @@ const DEFAULT_ORDER = {
2
2
  script: ["lang", "setup"],
3
3
  style: ["lang", "scoped"]
4
4
  };
5
- var vue_block_attribute_order_default = {
5
+ const rule = {
6
6
  meta: {
7
7
  type: "layout",
8
8
  fixable: "code",
@@ -56,4 +56,10 @@ var vue_block_attribute_order_default = {
56
56
  } };
57
57
  }
58
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
+ };
59
63
  export { vue_block_attribute_order_default as default };
64
+
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,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,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.5.0",
3
+ "version": "0.6.0",
4
4
  "repository": {
5
5
  "url": "https://github.com/ByScripts/toolbox"
6
6
  },