Skip to content

Commit 1a2a5c8

Browse files
committed
refactor: 💡 tweak
1 parent aa2b599 commit 1a2a5c8

4 files changed

Lines changed: 15 additions & 31 deletions

File tree

‎src/index.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
} from "prettier";
88
import { parse } from "./parser.js";
99
import { print } from "./printer.js";
10+
import type { AnywhereNode } from "./types.js";
1011

1112
/**
1213
* @see https://prettier.io/docs/en/plugins#languages
@@ -15,7 +16,6 @@ export const languages: Partial<SupportLanguage>[] = [
1516
{
1617
name: "Any HTML-like Languages",
1718
parsers: ["anywhere"],
18-
aceMode: "text",
1919
},
2020
];
2121

@@ -26,13 +26,8 @@ export const parsers: Record<string, Parser> = {
2626
anywhere: {
2727
parse,
2828
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,
3631
},
3732
};
3833

@@ -51,7 +46,7 @@ export const printers: Record<string, Printer> = {
5146
export const options: Record<string, SupportOption> = {
5247
regex: {
5348
type: "string",
54-
category: "Anywhere",
49+
category: "Format",
5550
default: 'class="([^"]*)"',
5651
description: "regex to match class attribute",
5752
},

‎src/parser.ts‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
import type { ParserOptions } from "prettier";
2-
import { format } from "prettier";
1+
import { type ParserOptions, format } from "prettier";
32
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";
124

135
export const parse = async (
146
text: string,
@@ -42,10 +34,8 @@ export const parse = async (
4234
}
4335

4436
return {
45-
type: "anywhere",
4637
body: formattedText,
47-
end: text.length,
48-
source: text,
4938
start: 0,
39+
end: text.length,
5040
};
5141
};

‎src/printer.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import type { AstPath, Doc } from "prettier";
2+
import type { AnywhereNode } from "./types.js";
23

34
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;
137
};

‎src/types.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export type AnywhereNode = {
2+
body: string;
3+
start: number;
4+
end: number;
5+
};

0 commit comments

Comments
 (0)