Skip to content

Commit

Permalink
feat(4.2.7): fixer support
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Mar 3, 2016
1 parent d127267 commit 8f8fb38
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
28 changes: 20 additions & 8 deletions src/4.2.7.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,32 @@
ただし和文でも、見出し語とその説明の間にコロンを使う場合があります。使用する場合は全角で表記します。
*/
import {isUserWrittenNode} from "./util/node-util";
export default function (context) {
let {Syntax, RuleError, report, getSource} = context;
import {matchCaptureGroupAll} from "./util/match-index";
import regx from 'regx';
import {japaneseRegExp} from "./util/regexp";
const rx = regx("g");
function reporter(context) {
let {Syntax, RuleError, report, fixer, getSource} = context;
return {
[Syntax.Str](node){
if (!isUserWrittenNode(node, context)) {
return;
}
let text = getSource(node);
const text = getSource(node);
// "和文:" というような半角:は使用しない
var matchHanQuestion = /([\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[ぁ-んァ-ヶ]):/;
var index = text.search(matchHanQuestion);
if (index !== -1) {
return report(node, new RuleError("コロン(:)を使用する場合は「全角」で表記します。", index + 1))
}

const matchHanQuestion = rx`(?:${japaneseRegExp})(:)`;
matchCaptureGroupAll(text, matchHanQuestion).forEach(match => {
const {index} = match;
report(node, new RuleError("コロン(:)を使用する場合は「全角」で表記します。", {
column: index,
fix: fixer.replaceTextRange([index, index + 1], ":")
}))
})
}
};
}
export default {
linter: reporter,
fixer: reporter
}
4 changes: 3 additions & 1 deletion test/4.2.7-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ tester.run("4.2.7.コロン(:)", rule, {
valid: [
"日時:3月16日午後 1 時",
"例:〜",
"1: これはペンです"// [^和文]: のパターン
"1: これはペンです",// [^和文]: のパターン,
"`this::method`"
],
invalid: [
{
text: "例:〜",
output: "例:〜",
errors: [
{
message: "コロン(:)を使用する場合は「全角」で表記します。",
Expand Down

0 comments on commit 8f8fb38

Please sign in to comment.