-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lint実行時に、特定のシンタックスを校正対象から除外できるようにしました。 (#1675)
- Loading branch information
1 parent
3dbaa6a
commit cb2238e
Showing
1 changed file
with
26 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { createLinter, loadLinterFormatter } from "npm:[email protected]"; | ||
import { TextlintKernelDescriptor } from "npm:@textlint/[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, | ||
|
@@ -38,14 +41,34 @@ const descriptor: TextlintKernelDescriptor = new TextlintKernelDescriptor({ | |
extensions: ".md", | ||
}, | ||
}], | ||
filterRules: [], | ||
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(results); | ||
const output = formatter.format(resultsFormatted); | ||
|
||
console.log(output); |