@ttskch/prettier-plugin-tailwindcss-anywhere 0.0.2 → 0.0.4

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.
@@ -4,19 +4,14 @@ export const languages = [
4
4
  {
5
5
  name: "Any HTML-like Languages",
6
6
  parsers: ["anywhere"],
7
- aceMode: "text",
8
7
  },
9
8
  ];
10
9
  export const parsers = {
11
10
  anywhere: {
12
11
  parse,
13
12
  astFormat: "anywhere",
14
- locStart(node) {
15
- return node.start;
16
- },
17
- locEnd(node) {
18
- return node.end;
19
- },
13
+ locStart: (node) => node.start,
14
+ locEnd: (node) => node.end,
20
15
  },
21
16
  };
22
17
  export const printers = {
@@ -27,7 +22,7 @@ export const printers = {
27
22
  export const options = {
28
23
  regex: {
29
24
  type: "string",
30
- category: "Anywhere",
25
+ category: "Format",
31
26
  default: 'class="([^"]*)"',
32
27
  description: "regex to match class attribute",
33
28
  },
@@ -0,0 +1,3 @@
1
+ import { type ParserOptions } from "prettier";
2
+ import type { AnywhereNode } from "./types.js";
3
+ export declare const parse: (text: string, options: ParserOptions) => Promise<AnywhereNode>;
@@ -19,10 +19,8 @@ export const parse = async (text, options) => {
19
19
  formattedText = formattedText.replace(original, fixed);
20
20
  }
21
21
  return {
22
- type: "anywhere",
23
22
  body: formattedText,
24
- end: text.length,
25
- source: text,
26
23
  start: 0,
24
+ end: text.length,
27
25
  };
28
26
  };
@@ -0,0 +1,4 @@
1
+ export const print = (path) => {
2
+ const node = path.node;
3
+ return node.body;
4
+ };
@@ -0,0 +1,5 @@
1
+ export type AnywhereNode = {
2
+ body: string;
3
+ start: number;
4
+ end: number;
5
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttskch/prettier-plugin-tailwindcss-anywhere",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "A Prettier plugin for sorting TailwindCSS classes in any HTML-like language, like Twig etc.",
5
5
  "keywords": ["prettier", "tailwindcss", "formatter", "html", "twig"],
6
6
  "type": "module",
@@ -8,10 +8,10 @@
8
8
  "node": ">= 20.9 < 21"
9
9
  },
10
10
  "packageManager": "pnpm@9.12.3",
11
- "main": "dist/src/index.js",
11
+ "main": "dist/index.js",
12
12
  "exports": {
13
13
  ".": {
14
- "import": "./dist/src/index.js"
14
+ "import": "./dist/index.js"
15
15
  }
16
16
  },
17
17
  "files": ["dist", "src"],
@@ -35,7 +35,7 @@
35
35
  "prettier-plugin-tailwindcss": "^0.6"
36
36
  },
37
37
  "scripts": {
38
- "start": "node dist/src/main.js",
38
+ "start": "node dist/index.js",
39
39
  "clean": "rimraf coverage dist tmp",
40
40
  "prebuild": "biome lint",
41
41
  "build": "tsc -d -p tsconfig.json",
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ import type {
7
7
  } from "prettier";
8
8
  import { parse } from "./parser.js";
9
9
  import { print } from "./printer.js";
10
+ import type { AnywhereNode } from "./types.js";
10
11
 
11
12
  /**
12
13
  * @see https://prettier.io/docs/en/plugins#languages
@@ -15,7 +16,6 @@ export const languages: Partial<SupportLanguage>[] = [
15
16
  {
16
17
  name: "Any HTML-like Languages",
17
18
  parsers: ["anywhere"],
18
- aceMode: "text",
19
19
  },
20
20
  ];
21
21
 
@@ -26,13 +26,8 @@ export const parsers: Record<string, Parser> = {
26
26
  anywhere: {
27
27
  parse,
28
28
  astFormat: "anywhere",
29
- // there's only a single node
30
- locStart(node) {
31
- return node.start;
32
- },
33
- locEnd(node) {
34
- return node.end;
35
- },
29
+ locStart: (node: AnywhereNode) => node.start,
30
+ locEnd: (node: AnywhereNode) => node.end,
36
31
  },
37
32
  };
38
33
 
@@ -51,7 +46,7 @@ export const printers: Record<string, Printer> = {
51
46
  export const options: Record<string, SupportOption> = {
52
47
  regex: {
53
48
  type: "string",
54
- category: "Anywhere",
49
+ category: "Format",
55
50
  default: 'class="([^"]*)"',
56
51
  description: "regex to match class attribute",
57
52
  },
package/src/parser.ts CHANGED
@@ -1,14 +1,6 @@
1
- import type { ParserOptions } from "prettier";
2
- import { format } from "prettier";
1
+ import { type ParserOptions, format } from "prettier";
3
2
  import * as prettierPluginTailwindcss from "prettier-plugin-tailwindcss";
4
-
5
- type AnywhereNode = {
6
- type: "anywhere";
7
- body: string;
8
- source: string;
9
- start: number;
10
- end: number;
11
- };
3
+ import type { AnywhereNode } from "./types.js";
12
4
 
13
5
  export const parse = async (
14
6
  text: string,
@@ -42,10 +34,8 @@ export const parse = async (
42
34
  }
43
35
 
44
36
  return {
45
- type: "anywhere",
46
37
  body: formattedText,
47
- end: text.length,
48
- source: text,
49
38
  start: 0,
39
+ end: text.length,
50
40
  };
51
41
  };
package/src/printer.ts CHANGED
@@ -1,13 +1,7 @@
1
1
  import type { AstPath, Doc } from "prettier";
2
+ import type { AnywhereNode } from "./types.js";
2
3
 
3
4
  export const print = (path: AstPath): Doc => {
4
- const node = path.node;
5
-
6
- switch (node.type) {
7
- case "anywhere": {
8
- return node.body;
9
- }
10
- }
11
-
12
- throw new Error(`Unknown node type: ${node.type}`);
5
+ const node: AnywhereNode = path.node;
6
+ return node.body;
13
7
  };
package/src/types.ts ADDED
@@ -0,0 +1,6 @@
1
+ /* v8 ignore next */
2
+ export type AnywhereNode = {
3
+ body: string;
4
+ start: number;
5
+ end: number;
6
+ };
@@ -1,10 +0,0 @@
1
- import type { ParserOptions } from "prettier";
2
- type AnywhereNode = {
3
- type: "anywhere";
4
- body: string;
5
- source: string;
6
- start: number;
7
- end: number;
8
- };
9
- export declare const parse: (text: string, options: ParserOptions) => Promise<AnywhereNode>;
10
- export {};
@@ -1,9 +0,0 @@
1
- export const print = (path) => {
2
- const node = path.node;
3
- switch (node.type) {
4
- case "anywhere": {
5
- return node.body;
6
- }
7
- }
8
- throw new Error(`Unknown node type: ${node.type}`);
9
- };
File without changes
File without changes