Skip to content

Commit 6368217

Browse files
authored
chore(deps): update to sentence-splitter@5 (#18)
1 parent cdb4667 commit 6368217

File tree

7 files changed

+68
-152
lines changed

7 files changed

+68
-152
lines changed

.githooks/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
npx --no-install lint-staged

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,19 @@
2929
"build": "textlint-scripts build",
3030
"prepublish": "npm run --if-present build",
3131
"test": "textlint-scripts test",
32-
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
33-
"watch": "textlint-scripts build --watch"
32+
"watch": "textlint-scripts build --watch",
33+
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
34+
"prepare": "git config --local core.hooksPath .githooks"
3435
},
3536
"prettier": {
36-
"printWidth": 120,
3737
"singleQuote": false,
38-
"tabWidth": 4
38+
"printWidth": 120,
39+
"tabWidth": 4,
40+
"trailingComma": "none"
3941
},
4042
"devDependencies": {
41-
"husky": "^1.1.1",
4243
"lint-staged": "^7.3.0",
43-
"prettier": "^1.8.1",
44+
"prettier": "^3.1.0",
4445
"textlint-scripts": "^12.0.1",
4546
"textlint-tester": "12.0.0"
4647
},
@@ -54,8 +55,7 @@
5455
},
5556
"lint-staged": {
5657
"*.{js,jsx,ts,tsx,css}": [
57-
"prettier --write",
58-
"git add"
58+
"prettier --write"
5959
]
6060
},
6161
"dependencies": {

src/parser/PairMaker.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const PAIR_MARKS = [
7272
// create entries
7373
// [start.key, mark]
7474
// [end.key, mark]
75-
const PAIR_MARKS_ENTRIES = PAIR_MARKS.map(mark => {
75+
const PAIR_MARKS_ENTRIES = PAIR_MARKS.map((mark) => {
7676
return [
7777
[mark.start, mark],
7878
[mark.end, mark]
@@ -86,34 +86,34 @@ const PAIR_MARKS_ENTRIES = PAIR_MARKS.map(mark => {
8686
const PAIR_MARKS_KEY_Map = new Map(PAIR_MARKS_ENTRIES);
8787
const matchPair = (string) => {
8888
return PAIR_MARKS_KEY_Map.get(string);
89-
}
89+
};
9090
// For readme
9191
// console.log(PAIR_MARKS.map(pair => `- ${pair.key}: \`${pair.start}\` and \`${pair.end}\``).join("\n"));
9292
export class PairMaker {
9393
/**
94-
* @param {import("./SourceCode").SourceCode} sourceCode
95-
* @returns
94+
* @param {import("./SourceCode").SourceCode} sourceCode
95+
* @returns
9696
*/
9797
mark(sourceCode) {
9898
const string = sourceCode.read();
9999
if (!string) {
100100
return;
101101
}
102102

103-
const matchedPair = matchPair(string)
104-
if (!matchedPair){
103+
const matchedPair = matchPair(string);
104+
if (!matchedPair) {
105105
return;
106106
}
107107
// support nested pair
108108
// {"{test}"}
109109
if (sourceCode.isInContext(matchedPair)) {
110110
// check that string is end mark?
111-
const pair = PAIR_MARKS.find(pair => pair.end === string);
111+
const pair = PAIR_MARKS.find((pair) => pair.end === string);
112112
if (pair) {
113113
sourceCode.leaveContext(pair);
114114
}
115115
} else {
116-
const pair = PAIR_MARKS.find(pair => pair.start === string);
116+
const pair = PAIR_MARKS.find((pair) => pair.start === string);
117117
if (pair) {
118118
sourceCode.enterContext(pair);
119119
}

src/parser/SourceCode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class SourceCode {
1717
}
1818

1919
leaveContext(pairMark) {
20-
const index = this.contextLocations.findIndex(context => {
20+
const index = this.contextLocations.findIndex((context) => {
2121
return context.pairMark.key === pairMark.key;
2222
});
2323
if (index !== -1) {
@@ -29,7 +29,7 @@ export class SourceCode {
2929
if (!pairMark) {
3030
return this.contextLocations.length > 0;
3131
}
32-
return this.contextLocations.some(contextLocation => contextLocation.pairMark.key === pairMark.key);
32+
return this.contextLocations.some((contextLocation) => contextLocation.pairMark.key === pairMark.key);
3333
}
3434

3535
/**

src/textlint-rule-no-unmatched-pair.js

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { PairMaker } from "./parser/PairMaker.js";
44
import { SourceCode } from "./parser/SourceCode.js";
55
import { IgnoreNodeManager } from "textlint-rule-helper";
66

7-
const report = context => {
7+
const report = (context) => {
88
const { Syntax, report, RuleError } = context;
99
const ignoreNodeManager = new IgnoreNodeManager();
1010
return {
@@ -19,29 +19,37 @@ const report = context => {
1919
Syntax.BlockQuote,
2020
Syntax.Comment
2121
]);
22-
sentences.children.filter(node => node.type === SentenceSplitterSyntax.Sentence).forEach(sentence => {
23-
const source = new SourceCode(sentence.raw);
24-
const pairMaker = new PairMaker();
25-
const sentenceIndex = sentence.range[0];
26-
while (source.canRead) {
27-
// If the character is in ignored range, skip it
28-
const characterIndex = sentenceIndex + source.index;
29-
// console.log(characterIndex, source.text[source.index], ignoreNodeManager.isIgnoredIndex(characterIndex));
30-
if (!ignoreNodeManager.isIgnoredIndex(characterIndex)) {
31-
pairMaker.mark(source);
22+
sentences.children
23+
.filter((node) => node.type === SentenceSplitterSyntax.Sentence)
24+
.forEach((sentence) => {
25+
const source = new SourceCode(sentence.raw);
26+
const pairMaker = new PairMaker();
27+
const sentenceIndex = sentence.range[0];
28+
while (source.canRead) {
29+
// If the character is in ignored range, skip it
30+
const characterIndex = sentenceIndex + source.index;
31+
// console.log(characterIndex, source.text[source.index], ignoreNodeManager.isIgnoredIndex(characterIndex));
32+
if (!ignoreNodeManager.isIgnoredIndex(characterIndex)) {
33+
pairMaker.mark(source);
34+
}
35+
source.peek();
3236
}
33-
source.peek();
34-
}
35-
// Report Error for each existing context keys
36-
source.contextLocations.forEach((contextLocation) => {
37-
report(node, new RuleError(`Not found pair character for ${contextLocation.pairMark.start}.
37+
// Report Error for each existing context keys
38+
source.contextLocations.forEach((contextLocation) => {
39+
report(
40+
node,
41+
new RuleError(
42+
`Not found pair character for ${contextLocation.pairMark.start}.
3843
3944
You should close this sentence with ${contextLocation.pairMark.end}.
40-
This pair mark is called ${contextLocation.pairMark.key}.`, {
41-
index: (sentenceIndex - node.range[0]) + contextLocation.index
42-
}));
45+
This pair mark is called ${contextLocation.pairMark.key}.`,
46+
{
47+
index: sentenceIndex - node.range[0] + contextLocation.index
48+
}
49+
)
50+
);
51+
});
4352
});
44-
});
4553
}
4654
};
4755
};

test/textlint-rule-no-unmatched-pair-test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ tester.run("textlint-rule-no-unmatched-pair", rule, {
1111
'test {"{ABC`{"{ABC}"}`}"} ok.',
1212
"これは(秘密)です。",
1313
`John said "Hello World!".`,
14-
"`(` is ok.", "文字列リテラルには3種類ありますが、まずは`\"`(ダブルクオート)と`'`(シングルクオート)について見ていきます。",
14+
"`(` is ok.",
15+
"文字列リテラルには3種類ありますが、まずは`\"`(ダブルクオート)と`'`(シングルクオート)について見ていきます。",
1516
`a is b.
1617
1718
\`"\`(ダブルクオート)と\`'\`(シングルクオート)に意味的な違いはありません。
@@ -21,7 +22,8 @@ tester.run("textlint-rule-no-unmatched-pair", rule, {
2122
2223
また操作と表示が1対1で更新される場合、1つの操作に対して複数の箇所の表示が更新されることもあります。
2324
今回のTodoアプリでもTodoリスト(\`#js-todo-list\`)とTodoアイテム数(\`#js-todo-count\`)の2箇所を更新する必要があることからも分かります。
24-
`, `\`Object.assign\`メソッドは、\`target\`オブジェクトに対して、1つ以上の\`sources\`オブジェクトを指定します。
25+
`,
26+
`\`Object.assign\`メソッドは、\`target\`オブジェクトに対して、1つ以上の\`sources\`オブジェクトを指定します。
2527
\`sources\`オブジェクト自身がもつ列挙可能なプロパティを第一引数の\`target\`オブジェクトに対してコピーします。
2628
\`Object.assign\`メソッドの返り値は、\`target\`オブジェクトになります。`,
2729
// 箇条書き
@@ -63,14 +65,16 @@ This pair mark is called double quote.`
6365
]
6466
},
6567
{
66-
text: "`src/App.js`にファイルを作成し、次のような内容のJavaScriptモジュールとします。\n"
67-
+ "モジュールは、基本的には何かしらを外部に公開(`export`)します。",
68+
text:
69+
"`src/App.js`にファイルを作成し、次のような内容のJavaScriptモジュールとします。\n" +
70+
"モジュールは、基本的には何かしらを外部に公開(`export`)します。",
6871
errors: [
6972
{
7073
index: 74
7174
}
7275
]
73-
}, {
76+
},
77+
{
7478
text: `このように\`count\`変数が自動解放されずに保持できているのは「(\`increment\`)関数が外側のスコープにある(\`count\`)変数への参照を保持できる」ためです。このような性質のことをクロージャー(関数閉包)と呼びます。クロージャーは静的スコープと変数は参照され続けていればデータは保持されるという2つの性質によって成り立っています。`,
7579
errors: [
7680
{
@@ -79,7 +83,8 @@ This pair mark is called double quote.`
7983
index: 104
8084
}
8185
]
82-
},{
86+
},
87+
{
8388
text: `DUMMY DUUMY.
8489
8590
@@ -93,4 +98,3 @@ This pair mark is called double quote.`
9398
}
9499
]
95100
});
96-

0 commit comments

Comments
 (0)