Skip to content

Commit ec2a851

Browse files
committed
fix(rule): use index-based padding
1 parent 9eafd53 commit ec2a851

File tree

4 files changed

+58
-675
lines changed

4 files changed

+58
-675
lines changed

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,12 @@
3333
"textlintrule"
3434
],
3535
"devDependencies": {
36-
"espower-babel": "^4.0.0",
37-
"power-assert": "^1.1.0",
38-
"textlint": "^6.0.3",
3936
"textlint-scripts": "^2.1.0"
4037
},
4138
"dependencies": {
4239
"kuromojin": "^1.2.1",
4340
"sentence-splitter": "^2.2.0",
44-
"textlint-rule-helper": "^1.1.4",
45-
"textlint-util-to-string": "^1.1.0"
41+
"textlint-rule-helper": "^2.1.1",
42+
"textlint-util-to-string": "^2.1.1"
4643
}
4744
}

src/no-doubled-joshi.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
createKeyFromKey,
1111
restoreToSurfaceFromKey
1212
} from "./token-utils";
13+
1314
/**
1415
* Create token map object
1516
* {
@@ -30,6 +31,7 @@ function createSurfaceKeyMap(tokens) {
3031
return keyMap;
3132
}, {});
3233
}
34+
3335
function matchExceptionRule(tokens) {
3436
let token = tokens[0];
3537
// "の" の重なりは例外
@@ -46,6 +48,7 @@ function matchExceptionRule(tokens) {
4648
}
4749
return false;
4850
}
51+
4952
/*
5053
default options
5154
*/
@@ -64,7 +67,7 @@ const defaultOptions = {
6467
6568
TODO: need abstraction
6669
*/
67-
module.exports = function(context, options = {}) {
70+
module.exports = function (context, options = {}) {
6871
const helper = new RuleHelper(context);
6972
// 最低間隔値
7073
const minInterval = options.min_interval || defaultOptions.min_interval;
@@ -73,7 +76,7 @@ module.exports = function(context, options = {}) {
7376
const separatorChars = options.separatorChars || defaultOptions.separatorChars;
7477
const {Syntax, report, RuleError} = context;
7578
return {
76-
[Syntax.Paragraph](node){
79+
[Syntax.Paragraph](node) {
7780
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
7881
return;
7982
}
@@ -136,15 +139,13 @@ module.exports = function(context, options = {}) {
136139
// 助詞token同士の距離が設定値以下ならエラーを報告する
137140
const differenceIndex = otherPosition - startPosition;
138141
if (differenceIndex <= minInterval) {
139-
const originalIndex = source.originalIndexFromPosition({
140-
line: sentence.loc.start.line,
141-
column: sentence.loc.start.column + (current.word_position - 1)
142-
});
143142
// padding positionを計算する
144-
const padding = {
143+
const originalIndex = source.originalIndexFromIndex(
144+
sentence.range[0] + (current.word_position - 1)
145+
);
146+
report(node, new RuleError(`一文に二回以上利用されている助詞 "${joshiName}" がみつかりました。`, {
145147
index: originalIndex
146-
};
147-
report(node, new RuleError(`一文に二回以上利用されている助詞 "${joshiName}" がみつかりました。`, padding));
148+
}));
148149
}
149150
return current;
150151
});

test/no-doubled-joshi-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,21 @@ tester.run("no-double-joshi", rule, {
179179
column: 8
180180
}
181181
]
182+
},
183+
//
184+
{
185+
text: `今まで「サイトはNetlify」「スライドはGitLab Pages」といった配信分けをしていたのですが、
186+
「 \`/slides\` にビルドしたスライドを置きたい」という動機のものと、こんな構成を検討しています。
187+
188+
* 最初にtextlintで文法チェック
189+
* ドキュメントを別にビルドしてarticle化
190+
* 複数articleを束ねてFirebaseへデプロイ`,
191+
errors: [
192+
{
193+
message: `一文に二回以上利用されている助詞 "は" がみつかりました。`,
194+
index: 21
195+
}
196+
]
182197
}
183198
]
184199
});

0 commit comments

Comments
 (0)