Skip to content

Commit cd4c8af

Browse files
committed
feat(3.1.1): fixer support
1 parent 8124850 commit cd4c8af

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

src/3.1.1.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,31 @@
77
。ただしカタカナ複合語の場合を除きます。「2.1.7 カタカナ複合語」を参照してください。
88
*/
99
import {isUserWrittenNode} from "./util/node-util";
10-
export default function (context) {
11-
let {Syntax, RuleError, report, getSource} = context;
10+
import {matchCaptureGroupAll} from "./util/match-index";
11+
function reporter(context) {
12+
let {Syntax, RuleError, report, fixer, getSource} = context;
1213
return {
1314
[Syntax.Str](node){
1415
if (!isUserWrittenNode(node, context)) {
1516
return;
1617
}
1718
let text = getSource(node);
1819
// アルファベットと全角の間は半角スペースではない
19-
let betweenHanAndZen = /[A-Za-z0-9]( )(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])/;
20-
let betweenZenAndHan = /(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])( )[A-Za-z0-9]/;
21-
var match = text.match(betweenZenAndHan) || text.match(betweenHanAndZen);
22-
if (match) {
23-
report(node, new RuleError("原則として、全角文字と半角文字の間にスペースを入れません。", match.index + 1));
24-
}
20+
let betweenHanAndZen = matchCaptureGroupAll(text, /[A-Za-z0-9]( )(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])/);
21+
let betweenZenAndHan = matchCaptureGroupAll(text, /(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[--])( )[A-Za-z0-9]/);
22+
const reportMatch = (match) => {
23+
const {index} = match;
24+
report(node, new RuleError("原則として、全角文字と半角文字の間にスペースを入れません。", {
25+
column: match.index,
26+
fix: fixer.replaceTextRange([index, index + 1], "")
27+
}));
28+
};
29+
betweenHanAndZen.forEach(reportMatch);
30+
betweenZenAndHan.forEach(reportMatch);
2531
}
2632
}
33+
}
34+
export default {
35+
linter: reporter,
36+
fixer: reporter
2737
}

test/3.1.1-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Pull Request、コミットのやりかたなどが書かれています。`
1414
invalid: [
1515
{
1616
text: "JTF 標準",
17+
output: "JTF標準",
1718
errors: [
1819
{
1920
message: "原則として、全角文字と半角文字の間にスペースを入れません。",
@@ -23,12 +24,14 @@ Pull Request、コミットのやりかたなどが書かれています。`
2324
},
2425
{
2526
text: "これは Unicode",
27+
output: "これはUnicode",
2628
errors: [
2729
{message: "原則として、全角文字と半角文字の間にスペースを入れません。"}
2830
]
2931
},
3032
{
3133
text: "これは Unicode",
34+
output: "これはUnicode",
3235
errors: [
3336
{message: "原則として、全角文字と半角文字の間にスペースを入れません。"}
3437
]

0 commit comments

Comments
 (0)