Skip to content

Commit

Permalink
lint実行時に、特定のシンタックスを校正対象から除外できるようにしました。 (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
shohei-yamashit authored Jan 24, 2025
1 parent 3dbaa6a commit cb2238e
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lint.ts
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,
Expand Down Expand Up @@ -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);

0 comments on commit cb2238e

Please sign in to comment.