Skip to content

Commit

Permalink
feat(rule): VOICED SOUND MARK \u309b \u309c support
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed May 4, 2016
1 parent 1177f57 commit d3ddb4a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/textlint-rule-no-nfd.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ function reporter(context) {
return;
}
const text = getSource(node);
matchCaptureGroupAll(text, /([\u309a\u3099])/g).forEach(({index}) => {
matchCaptureGroupAll(text, /([\u309b\u309c\u309a\u3099])/g).forEach(({index}) => {
// \u309b\u309c => \u309a\u3099
const dakutenChars = text.slice(index - 1, index + 1);
const expectedText = unorm.nfc(dakutenChars);
const nfdlized = dakutenChars.replace("\u309B", "\u3099").replace("\u309C", "\u309A")
const expectedText = unorm.nfc(nfdlized);
const ruleError = new RuleError(`Disallow to use NFD(well-known as Mac濁点): "${dakutenChars}" => "${expectedText}"`, {
index,
fix: fixer.replaceTextRange([index - 1, index + 1], expectedText)
Expand Down
24 changes: 23 additions & 1 deletion test/textlint-rule-no-nfd-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ tester.run("no-todo", rule, {
"エンジン"
],
invalid: [
// single match
{
text: "ホ\u309aケット",
output: "ポケット",
Expand All @@ -23,6 +22,17 @@ tester.run("no-todo", rule, {
}
]
},
{
text: "ホ゜ケット",
output: "ポケット",
errors: [
{
message: `Disallow to use NFD(well-known as Mac濁点): "ホ\u309c" => "ポ"`,
line: 1,
column: 2
}
]
},
{
text: "エンシ\u3099ン",
output:"エンジン",
Expand All @@ -33,6 +43,18 @@ tester.run("no-todo", rule, {
column: 4
}
]
},

{
text: "エンシ゛ン",
output:"エンジン",
errors: [
{
message: `Disallow to use NFD(well-known as Mac濁点): "シ\u309b" => "ジ"`,
line: 1,
column: 4
}
]
}
]
});

0 comments on commit d3ddb4a

Please sign in to comment.