Skip to content

Commit 094a7fb

Browse files
committed
fix: update textlint and use locator
BREAKING CHANGE: Require:textlint [v12.2.0](https://github.com/textlint/textlint/releases/tag/v12.2.0)+ - Update textlint-rule-helper - Use locator instead of index
1 parent 3b4d3ba commit 094a7fb

File tree

5 files changed

+2184
-2879
lines changed

5 files changed

+2184
-2879
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ textlint --rule no-nfd README.md
3838

3939
`textlint --fix` での[自動修正](https://github.com/textlint/textlint/blob/master/docs/rule-fixer.md)に対応しています。
4040

41-
4241
## Example
4342

4443
゜or `\u309a`

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@
3131
"textlint"
3232
],
3333
"devDependencies": {
34-
"@textlint/types": "^1.2.2",
35-
"@types/node": "^12.11.1",
34+
"@textlint/types": "^13.0.2",
35+
"@types/node": "^18.11.18",
36+
"@types/unorm": "^1.3.28",
3637
"power-assert": "^1.3.1",
37-
"textlint-scripts": "^3.0.0",
38-
"ts-node": "^8.4.1",
39-
"typescript": "^3.6.4"
38+
"textlint-scripts": "^13.0.2",
39+
"ts-node": "^10.9.1",
40+
"typescript": "^4.9.4"
4041
},
4142
"dependencies": {
4243
"match-index": "^1.0.3",
43-
"textlint-rule-helper": "^2.1.1",
44+
"textlint-rule-helper": "^2.3.0",
4445
"unorm": "^1.4.1"
4546
}
4647
}

src/textlint-rule-no-nfd.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
// LICENSE : MIT
22
"use strict";
3-
import {matchCaptureGroupAll} from "match-index"
4-
import {RuleHelper} from "textlint-rule-helper";
5-
import {TextlintRuleReporter} from "@textlint/types";
6-
7-
const unorm = require("unorm");
3+
import { matchCaptureGroupAll } from "match-index"
4+
import { RuleHelper } from "textlint-rule-helper";
5+
import { TextlintRuleReporter } from "@textlint/types";
6+
import unorm from "unorm";
87

98
const reporter: TextlintRuleReporter = function (context) {
10-
const {Syntax, RuleError, report, fixer, getSource} = context;
9+
const { Syntax, RuleError, report, fixer, getSource, locator } = context;
1110
const helper = new RuleHelper(context);
1211
return {
1312
[Syntax.Str](node) {
1413
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
1514
return;
1615
}
1716
const text = getSource(node);
18-
matchCaptureGroupAll(text, /([\u309b\u309c\u309a\u3099])/g).forEach(({index}) => {
17+
matchCaptureGroupAll(text, /([\u309b\u309c\u309a\u3099])/g).forEach(({ index }) => {
1918
if (index === 0) {
2019
return;
2120
}
@@ -24,16 +23,15 @@ const reporter: TextlintRuleReporter = function (context) {
2423
const nfdlized = dakutenChars.replace("\u309B", "\u3099").replace("\u309C", "\u309A");
2524
const expectedText = unorm.nfc(nfdlized);
2625
const ruleError = new RuleError(`Disallow to use NFD(well-known as UTF8-MAC 濁点): "${dakutenChars}" => "${expectedText}"`, {
27-
index,
26+
padding: locator.at(index),
2827
fix: fixer.replaceTextRange([index - 1, index + 1], expectedText)
2928
});
3029
report(node, ruleError);
3130
});
3231
}
3332
}
3433
};
35-
36-
module.exports = {
34+
export default {
3735
linter: reporter,
3836
fixer: reporter
3937
};

test/textlint-rule-no-nfd-test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// LICENSE : MIT
22
"use strict";
3-
const TextLintTester = require("textlint-tester");
4-
const tester = new TextLintTester();
3+
import TextLintTester from "textlint-tester";
54
// rule
6-
const rule = require("../src/textlint-rule-no-nfd");
5+
import rule from "../src/textlint-rule-no-nfd";
6+
const tester = new TextLintTester();
77
// ruleName, rule, { valid, invalid }
88
tester.run("no-nfd", rule, {
99
valid: [

0 commit comments

Comments
 (0)