Skip to content

Commit 0338d8e

Browse files
keikazu
authored andcommitted
feat(rule): add ja-nakaguro-or-halfwidth-space-between-katakana (#1)
1 parent 62be3a1 commit 0338d8e

File tree

5 files changed

+154
-0
lines changed

5 files changed

+154
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["es2015"]
3+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# textlint-rule-ja-nakaguro-or-halfwidth-space-between-katakana
2+
3+
カタカナ語間の区切り文字についてのtextlintルール
4+
5+
## Install
6+
7+
Install with [npm](https://www.npmjs.com/):
8+
9+
npm install textlint-rule-ja-nakaguro-or-halfwidth-space-between-katakana
10+
11+
## Usage
12+
13+
Via `.textlintrc`(Recommended)
14+
15+
```json
16+
{
17+
"rules": {
18+
"ja-nakaguro-or-halfwidth-space-between-katakana": true
19+
}
20+
}
21+
```
22+
23+
Via CLI
24+
25+
```
26+
textlint --rule ja-nakaguro-or-halfwidth-space-between-katakana README.md
27+
```
28+
29+
30+
## Changelog
31+
32+
See [Releases page](https://github.com/extlint-ja/textlint-rule-spacing/releases).
33+
34+
## Running tests
35+
36+
Install devDependencies and Run `npm test`:
37+
38+
npm i -d && npm test
39+
40+
## Contributing
41+
42+
Pull requests and stars are always welcome.
43+
44+
For bugs and feature requests, [please create an issue](https://github.com/extlint-ja/textlint-rule-spacing/issues).
45+
46+
1. Fork it!
47+
2. Create your feature branch: `git checkout -b my-new-feature`
48+
3. Commit your changes: `git commit -am 'Add some feature'`
49+
4. Push to the branch: `git push origin my-new-feature`
50+
5. Submit a pull request :D
51+
52+
## Author
53+
54+
- [github/azu](https://github.com/azu)
55+
- [twitter/azu_re](https://twitter.com/azu_re)
56+
57+
## License
58+
59+
MIT © azu
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "textlint-rule-ja-nakaguro-or-halfwidth-space-between-katakana",
3+
"version": "1.0.0",
4+
"description": "カタカナ語間の区切り文字についてのtextlintルール",
5+
"main": "lib/index.js",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/textlint-ja/textlint-rule-spacing.git"
9+
},
10+
"author": "azu",
11+
"email": "[email protected]",
12+
"homepage": "https://github.com/extlint-ja/textlint-rule-spacing",
13+
"license": "MIT",
14+
"bugs": {
15+
"url": "https://github.com/extlint-ja/textlint-rule-spacing/issues"
16+
},
17+
"scripts": {
18+
"build": "NODE_ENV=production babel src --out-dir lib --source-maps",
19+
"watch": "babel src --out-dir lib --watch --source-maps",
20+
"prepublish": "npm run --if-present build",
21+
"test": "mocha"
22+
},
23+
"keywords": [
24+
"textlint"
25+
],
26+
"devDependencies": {
27+
"babel-cli": "^6.0.0",
28+
"babel-preset-es2015": "^6.0.0",
29+
"textlint-tester": "^2.0.0",
30+
"mocha": "^2.3.3"
31+
},
32+
"dependencies": {
33+
"match-index": "^1.0.1",
34+
"textlint-rule-helper": "^2.0.0"
35+
}
36+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
/*
4+
カタカナ語間のスペースの有無
5+
中黒または半角スペースを用いてカタカナ語を区切ります。
6+
*/
7+
import {RuleHelper} from "textlint-rule-helper";
8+
import {matchCaptureGroupAll} from "match-index";
9+
export default function (context) {
10+
const {Syntax, RuleError, report, getSource} = context;
11+
const helper = new RuleHelper();
12+
return {
13+
[Syntax.Str](node){
14+
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
15+
return;
16+
}
17+
const text = getSource(node);
18+
// カタカナ(カタカナ以外)カタカナ のパターンを取り出す
19+
matchCaptureGroupAll(text, /[-]([^[-])[-]/).forEach(match => {
20+
// カタカナの間を全角スペースでは区切らない
21+
const {text} = match;
22+
if (text === " ") {
23+
report(node, new RuleError("カタカナ語間は中黒(・)または半角スペースを用いてカタカナ語を区切ります", {
24+
index: match.index
25+
}));
26+
}
27+
});
28+
29+
}
30+
};
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
import TextLintTester from "textlint-tester";
4+
import rule from "../src/index";
5+
var tester = new TextLintTester();
6+
tester.run("カタカナ語間のスペースの有無", rule, {
7+
valid: [
8+
"カタカナ・カタカナ",
9+
"カタカナ カタカナ",
10+
"カタカナ、カタカナ",// 例外としてしょうがない気がする
11+
"あいう えお",
12+
"インターフェース ブラウザ"
13+
],
14+
invalid: [
15+
{
16+
text: "カタカナ カタカナ",
17+
errors: [
18+
{
19+
message: "カタカナ語間は中黒(・)または半角スペースを用いてカタカナ語を区切ります",
20+
column: 5
21+
}
22+
]
23+
}
24+
]
25+
});

0 commit comments

Comments
 (0)