Skip to content

Commit c8e8cd7

Browse files
committed
satisfies
1 parent 09a1aec commit c8e8cd7

File tree

5 files changed

+42
-46
lines changed

5 files changed

+42
-46
lines changed

package-lock.json

Lines changed: 22 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"@textlint/types": "^1.3.1",
2626
"@types/mocha": "^10.0.1",
2727
"@types/node": "^14.0.22",
28-
"prettier": "^2.0.5",
28+
"prettier": "^3.5.3",
2929
"textlint-scripts": "^13.3.1",
30-
"typescript": "^4.9.5"
30+
"typescript": "^5.8.3"
3131
},
3232
"peerDependencies": {
3333
"typescript": "*"

src/JSXProcessor.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as ts from "typescript";
1313
const extractCommentNodes = (node: ts.Node): TxtNode[] => {
1414
const commentRanges = ts.getLeadingCommentRanges(
1515
node.getSourceFile().getFullText(),
16-
node.pos
16+
node.pos,
1717
);
1818

1919
if (!commentRanges) {
@@ -24,13 +24,13 @@ const extractCommentNodes = (node: ts.Node): TxtNode[] => {
2424
const text = node.getSourceFile().getFullText().slice(range.pos, range.end);
2525
const start = ts.getLineAndCharacterOfPosition(
2626
node.getSourceFile(),
27-
range.pos
27+
range.pos,
2828
);
2929
const end = ts.getLineAndCharacterOfPosition(
3030
node.getSourceFile(),
31-
range.end
31+
range.end,
3232
);
33-
let comment: string = text;
33+
let comment = text;
3434

3535
if (text.startsWith("//")) {
3636
// single line comment
@@ -108,40 +108,35 @@ const jsxToAST = (node: ts.Node) => {
108108
// TODO: Implement map for all SyntaxKinds.
109109
switch (node.kind) {
110110
case ts.SyntaxKind.SourceFile: {
111-
const txtNode: TxtParentNode = {
111+
return {
112112
...txtPartialNode,
113113
type: ASTNodeTypes.Document,
114114
children,
115-
};
116-
117-
return txtNode;
115+
} satisfies TxtParentNode;
118116
}
117+
119118
case ts.SyntaxKind.JsxText: {
120-
const txtNode: TxtTextNode = {
119+
return {
121120
...txtPartialNode,
122121
type: ASTNodeTypes.Str,
123122
value: node.getText(),
124-
};
125-
126-
return txtNode;
123+
} satisfies TxtTextNode;
127124
}
125+
128126
case ts.SyntaxKind.StringLiteral: {
129-
const txtNode: TxtTextNode = {
127+
return {
130128
...txtPartialNode,
131129
type: ASTNodeTypes.Str,
132130
value: node.getText(),
133-
};
134-
135-
return txtNode;
131+
} satisfies TxtTextNode;
136132
}
133+
137134
default: {
138-
const txtNode: TxtParentNode = {
135+
return {
139136
...txtPartialNode,
140137
type: ASTNodeTypes.HtmlBlock,
141138
children,
142-
};
143-
144-
return txtNode;
139+
} satisfies TxtParentNode;
145140
}
146141
}
147142
};
@@ -164,7 +159,7 @@ class JSXProcessor implements TextlintPluginProcessor {
164159
"foo.tsx",
165160
text,
166161
ts.ScriptTarget.Latest,
167-
true
162+
true,
168163
);
169164

170165
return jsxToAST(sourceFile) as TxtParentNode;

src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import type { TextlintPluginCreator } from "@textlint/types";
22
import Processor from "./JSXProcessor";
33

4-
const creator: TextlintPluginCreator = {
5-
Processor,
6-
};
7-
8-
export default creator;
4+
export default { Processor } satisfies TextlintPluginCreator;

test/JSXProcessor-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("processor()", () => {
5050
} else {
5151
// compare input and output
5252
const expected = JSON.parse(
53-
fs.readFileSync(expectedFilePath, "utf-8")
53+
fs.readFileSync(expectedFilePath, "utf-8"),
5454
);
5555
assert.deepStrictEqual(actual, expected);
5656
}

0 commit comments

Comments
 (0)