Skip to content

Commit 456172a

Browse files
keikazu
authored andcommitted
feat(rule): add space-after-question (#5)
1 parent 0ebbf30 commit 456172a

File tree

5 files changed

+159
-0
lines changed

5 files changed

+159
-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-space-after-question
2+
3+
疑問符の直後のスペースについてのtexlintルール
4+
5+
## Install
6+
7+
Install with [npm](https://www.npmjs.com/):
8+
9+
npm install textlint-rule-ja-space-after-question
10+
11+
## Usage
12+
13+
Via `.textlintrc`(Recommended)
14+
15+
```json
16+
{
17+
"rules": {
18+
"ja-space-after-question": true
19+
}
20+
}
21+
```
22+
23+
Via CLI
24+
25+
```
26+
textlint --rule ja-space-after-question 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-space-after-question",
3+
"version": "1.0.0",
4+
"description": "疑問符の直後のスペースについてのtexlintルール",
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": "azuciao@gmail.com",
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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
/*
4+
疑問符(?)
5+
文末に疑問符を使用し、後に別の文が続く場合は、直後に全角スペースを挿入します。
6+
文中に疑問符を使用する場合はスペースを挿入しません。
7+
*/
8+
import {RuleHelper} from "textlint-rule-helper";
9+
import {matchCaptureGroupAll} from "match-index";
10+
function reporter(context) {
11+
const {Syntax, RuleError, report, fixer, getSource} = context;
12+
const helper = new RuleHelper();
13+
return {
14+
[Syntax.Str](node){
15+
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
16+
return;
17+
}
18+
let text = getSource(node);
19+
// ?の後ろは全角スペースが推奨
20+
// 半角スペースである場合はエラーとする
21+
const matchAfter = /( )[^\n]/;
22+
matchCaptureGroupAll(text, matchAfter).forEach(match => {
23+
const {index} = match;
24+
return report(node, new RuleError("文末に感嘆符を使用し、後に別の文が続く場合は、直後に全角スペースを挿入します。", {
25+
index: index,
26+
fix: fixer.replaceTextRange([index, index + 1], " ")
27+
}));
28+
});
29+
}
30+
};
31+
}
32+
export default {
33+
linter: reporter,
34+
fixer: reporter
35+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
"【原文】Does the reader understand the document?",
9+
"【訳文】読者は文書の内容を理解しているでしょうか。",
10+
"オプションを変更しますか?",
11+
"A 社の成功の秘密とは? この本ではそれをご紹介します。",
12+
"どう操作したらよいのか?というユーザーの疑問に答えます。"
13+
],
14+
invalid: [
15+
{
16+
text: "驚きの速さ!? これが新製品のキャッチコピーでした? これは問題なし",
17+
output: "驚きの速さ!? これが新製品のキャッチコピーでした? これは問題なし",
18+
errors: [
19+
{
20+
message: "文末に感嘆符を使用し、後に別の文が続く場合は、直後に全角スペースを挿入します。",
21+
column: 8
22+
}
23+
]
24+
}
25+
]
26+
});

0 commit comments

Comments
 (0)