@ttskch/prettier-plugin-tailwindcss-anywhere 0.0.2 → 0.0.3
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/dist/src/index.js +3 -8
- package/dist/src/parser.d.ts +2 -9
- package/dist/src/parser.js +1 -3
- package/dist/src/printer.js +1 -6
- package/dist/src/types.d.ts +5 -0
- package/dist/src/types.js +1 -0
- package/package.json +1 -1
- package/src/index.ts +4 -9
- package/src/parser.ts +3 -13
- package/src/printer.ts +3 -9
- package/src/types.ts +5 -0
package/dist/src/index.js
CHANGED
|
@@ -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
|
-
|
|
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: "
|
|
25
|
+
category: "Format",
|
|
31
26
|
default: 'class="([^"]*)"',
|
|
32
27
|
description: "regex to match class attribute",
|
|
33
28
|
},
|
package/dist/src/parser.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import type
|
|
2
|
-
type AnywhereNode
|
|
3
|
-
type: "anywhere";
|
|
4
|
-
body: string;
|
|
5
|
-
source: string;
|
|
6
|
-
start: number;
|
|
7
|
-
end: number;
|
|
8
|
-
};
|
|
1
|
+
import { type ParserOptions } from "prettier";
|
|
2
|
+
import type { AnywhereNode } from "./types.js";
|
|
9
3
|
export declare const parse: (text: string, options: ParserOptions) => Promise<AnywhereNode>;
|
|
10
|
-
export {};
|
package/dist/src/parser.js
CHANGED
|
@@ -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
|
};
|
package/dist/src/printer.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.0.3",
|
|
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",
|
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
|
-
|
|
30
|
-
|
|
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: "
|
|
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
|
|
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
|
};
|