Skip to content

Commit 1177f57

Browse files
committed
initial commit
0 parents  commit 1177f57

File tree

9 files changed

+319
-0
lines changed

9 files changed

+319
-0
lines changed

.babelrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"presets": [
3+
"es2015"
4+
],
5+
"env": {
6+
"development": {
7+
"presets": [
8+
"jsdoc-to-assert",
9+
"power-assert"
10+
]
11+
}
12+
}
13+
}

.gitignore

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Node.gitignore
2+
3+
# Logs
4+
logs
5+
*.log
6+
7+
# Runtime data
8+
pids
9+
*.pid
10+
*.seed
11+
12+
# Directory for instrumented libs generated by jscoverage/JSCover
13+
lib-cov
14+
15+
# Coverage directory used by tools like istanbul
16+
coverage
17+
18+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
19+
.grunt
20+
21+
# node-waf configuration
22+
.lock-wscript
23+
24+
# Compiled binary addons (http://nodejs.org/api/addons.html)
25+
build/Release
26+
27+
# Dependency directory
28+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
29+
node_modules
30+
31+
# Debug log from npm
32+
npm-debug.log
33+
34+
35+
### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Global/JetBrains.gitignore
36+
37+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
38+
39+
*.iml
40+
41+
## Directory-based project format:
42+
.idea/
43+
# if you remove the above rule, at least ignore the following:
44+
45+
# User-specific stuff:
46+
# .idea/workspace.xml
47+
# .idea/tasks.xml
48+
# .idea/dictionaries
49+
50+
# Sensitive or high-churn files:
51+
# .idea/dataSources.ids
52+
# .idea/dataSources.xml
53+
# .idea/sqlDataSources.xml
54+
# .idea/dynamic.xml
55+
# .idea/uiDesigner.xml
56+
57+
# Gradle:
58+
# .idea/gradle.xml
59+
# .idea/libraries
60+
61+
# Mongo Explorer plugin:
62+
# .idea/mongoSettings.xml
63+
64+
## File-based project format:
65+
*.ipr
66+
*.iws
67+
68+
## Plugin-specific files:
69+
70+
# IntelliJ
71+
out/
72+
73+
# mpeltonen/sbt-idea plugin
74+
.idea_modules/
75+
76+
# JIRA plugin
77+
atlassian-ide-plugin.xml
78+
79+
# Crashlytics plugin (for Android Studio and IntelliJ)
80+
com_crashlytics_export_strings.xml
81+
crashlytics.properties
82+
crashlytics-build.properties
83+
84+
85+
/lib

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
sudo: false
2+
language: node_js
3+
node_js: "stable"

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2016 azu
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# textlint-rule-no-nfd
2+
3+
textlint rule that disallow to use NFD like UTF8-MAC 濁点.
4+
5+
## Install
6+
7+
Install with [npm](https://www.npmjs.com/):
8+
9+
npm install textlint-rule-no-nfd
10+
11+
## Usage
12+
13+
Via `.textlintrc`(Recommended)
14+
15+
16+
```json
17+
{
18+
"rules": {
19+
"no-nfd": true
20+
}
21+
}
22+
```
23+
24+
Via CLI
25+
26+
```
27+
textlint --rule no-nfd README.md
28+
```
29+
30+
## Example
31+
32+
゜(`\u309a`)
33+
34+
NG: ホ゜ケット
35+
: ホ\u309aケット
36+
OK: ポケット
37+
38+
゛(`\u3099`)
39+
40+
NG: エンシ゛ン
41+
: エンシ\u3099ン
42+
OK: エンジン
43+
44+
45+
## Changelog
46+
47+
See [Releases page](https://github.com/azu/textlint-rule-no-nfd/releases).
48+
49+
## Running tests
50+
51+
Install devDependencies and Run `npm test`:
52+
53+
npm i -d && npm test
54+
55+
## Further Reading
56+
57+
- [String.prototype.normalize() - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/normalize)
58+
- [walling/unorm: JavaScript Unicode 8.0 Normalization - NFC, NFD, NFKC, NFKD.](https://github.com/walling/unorm)
59+
- [UTF-8にもいろいろある - ザリガニが見ていた...。](http://d.hatena.ne.jp/zariganitosh/20131124/utf8_nfd_nfc_bom)
60+
- [[JavaScript]\uXXXX形式にunicodeエスケープする関数 / LiosK-free Blog](http://liosk.blog103.fc2.com/blog-entry-67.html)
61+
- [unoh.github.com by unoh](http://unoh.github.io/2007/09/04/unicode-on-mac.html)
62+
- [正規化 - odz buffer](http://d.hatena.ne.jp/odz/20070904/1188884960)
63+
64+
## Contributing
65+
66+
Pull requests and stars are always welcome.
67+
For bugs and feature requests, [please create an issue](https://github.com/azu/textlint-rule-no-nfd/issues).
68+
69+
1. Fork it!
70+
2. Create your feature branch: `git checkout -b my-new-feature`
71+
3. Commit your changes: `git commit -am 'Add some feature'`
72+
4. Push to the branch: `git push origin my-new-feature`
73+
5. Submit a pull request :D
74+
75+
## Author
76+
77+
- [github/azu](https://github.com/azu)
78+
- [twitter/azu_re]http://twitter.com/azu_re)
79+
80+
## License
81+
82+
MIT © azu

package.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "textlint-rule-no-nfd",
3+
"repository": {
4+
"type": "git",
5+
"url": "https://github.com/azu/textlint-rule-no-nfd.git"
6+
},
7+
"author": "azu",
8+
"email": "[email protected]",
9+
"homepage": "https://github.com/azu/textlint-rule-no-nfd",
10+
"license": "MIT",
11+
"bugs": {
12+
"url": "https://github.com/azu/textlint-rule-no-nfd/issues"
13+
},
14+
"files": [
15+
"src/",
16+
"lib/"
17+
],
18+
"version": "1.0.0",
19+
"description": "textlint rule that disallow to use NFD like 濁点.",
20+
"main": "lib/textlint-rule-no-nfd.js",
21+
"directories": {
22+
"test": "test"
23+
},
24+
"scripts": {
25+
"test": "mocha test/",
26+
"build": "NODE_ENV=production babel src --out-dir lib --source-maps",
27+
"watch": "babel src --out-dir lib --watch --source-maps",
28+
"prepublish": "npm run --if-present build"
29+
},
30+
"keywords": [
31+
"textlint"
32+
],
33+
"devDependencies": {
34+
"babel-cli": "^6.8.0",
35+
"babel-preset-es2015": "^6.6.0",
36+
"babel-preset-jsdoc-to-assert": "^1.0.1",
37+
"babel-preset-power-assert": "^1.0.0",
38+
"babel-register": "^6.8.0",
39+
"mocha": "^2.4.5",
40+
"power-assert": "^1.3.1",
41+
"textlint-tester": "^1.2.0"
42+
},
43+
"dependencies": {
44+
"match-index": "^1.0.1",
45+
"textlint-rule-helper": "^1.1.5",
46+
"unorm": "^1.4.1"
47+
}
48+
}

src/textlint-rule-no-nfd.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
import {RuleHelper} from "textlint-rule-helper";
4+
import {matchCaptureGroupAll} from "match-index"
5+
const unorm = require("unorm");
6+
function reporter(context) {
7+
const {Syntax, RuleError, report, fixer, getSource} = context;
8+
const helper = new RuleHelper(context);
9+
return {
10+
[Syntax.Str](node){
11+
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
12+
return;
13+
}
14+
const text = getSource(node);
15+
matchCaptureGroupAll(text, /([\u309a\u3099])/g).forEach(({index}) => {
16+
const dakutenChars = text.slice(index - 1, index + 1);
17+
const expectedText = unorm.nfc(dakutenChars);
18+
const ruleError = new RuleError(`Disallow to use NFD(well-known as Mac濁点): "${dakutenChars}" => "${expectedText}"`, {
19+
index,
20+
fix: fixer.replaceTextRange([index - 1, index + 1], expectedText)
21+
});
22+
report(node, ruleError);
23+
});
24+
}
25+
}
26+
}
27+
module.exports = {
28+
linter: reporter,
29+
fixer: reporter
30+
};

test/mocha.opts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--compilers js:babel-register

test/textlint-rule-no-nfd-test.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
const TextLintTester = require("textlint-tester");
4+
const tester = new TextLintTester();
5+
// rule
6+
import rule from "../src/textlint-rule-no-nfd";
7+
// ruleName, rule, { valid, invalid }
8+
tester.run("no-todo", rule, {
9+
valid: [
10+
"ポケット",
11+
"エンジン"
12+
],
13+
invalid: [
14+
// single match
15+
{
16+
text: "ホ\u309aケット",
17+
output: "ポケット",
18+
errors: [
19+
{
20+
message: `Disallow to use NFD(well-known as Mac濁点): "ホ\u309a" => "ポ"`,
21+
line: 1,
22+
column: 2
23+
}
24+
]
25+
},
26+
{
27+
text: "エンシ\u3099ン",
28+
output:"エンジン",
29+
errors: [
30+
{
31+
message: `Disallow to use NFD(well-known as Mac濁点): "シ\u3099" => "ジ"`,
32+
line: 1,
33+
column: 4
34+
}
35+
]
36+
}
37+
]
38+
});

0 commit comments

Comments
 (0)