-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlint.ts
77 lines (70 loc) · 2.25 KB
/
lint.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { createLinter, loadLinterFormatter } from "npm:[email protected]";
import {
TextlintKernelDescriptor,
TextlintResult,
} from "npm:@textlint/[email protected]";
import { moduleInterop } from "npm:@textlint/[email protected]";
import * as jpPreset from "npm:[email protected]";
import * as proofdict from "npm:@proofdict/textlint-rule-proofdict@^3.1.2";
import * as aws from "npm:textlint-rule-aws-spellcheck@^1.3.0";
import * as markdownProcessor from "npm:@textlint/[email protected]";
import * as allowlistFilter from "npm:textlint-filter-rule-allowlist";
const excludes = ["ja-no-weak-phrase"];
const filterRuleAllowExpressions = ["/:::/"];
const presetRules = Object.entries(jpPreset.rules).map(([id, module]) => ({
ruleId: id,
rule: module as any,
options: {
...jpPreset.rulesConfig[id],
},
})).filter((rule) => !excludes.includes(rule.ruleId));
const descriptor: TextlintKernelDescriptor = new TextlintKernelDescriptor({
rules: [
{
ruleId: "aws-spellcheck",
rule: moduleInterop(aws.default),
},
{
ruleId: "@proofdict/proofdict",
rule: moduleInterop(proofdict.default),
options: {
dictURL: "https://azu.github.io/proof-dictionary/",
denyTags: ["opinion"],
},
},
...presetRules,
],
plugins: [{
pluginId: "@textlint/markdown",
plugin: moduleInterop(markdownProcessor.default) as any,
options: {
extensions: ".md",
},
}],
filterRules: [
{
ruleId: "filter-rule-allowlist",
rule: moduleInterop(allowlistFilter.default),
options: {
allow: filterRuleAllowExpressions,
},
},
],
});
const linter = createLinter({
descriptor: descriptor,
});
const results = await linter.lintFiles([...Deno.args]);
// resultsの中にある改行や連続空白を、半角スペースに置き換える
const resultsFormatted = results.map((result: TextlintResult) => {
return {
...result,
messages: result.messages.map((message) => ({
...message,
message: message.message.replace(/[\n\t]/g, " ").replace(/\s+/g, " "),
})),
};
});
const formatter = await loadLinterFormatter({ formatterName: "stylish" });
const output = formatter.format(resultsFormatted);
console.log(output);