Skip to content

Commit 78cc3e1

Browse files
keikazu
authored andcommitted
feat(rule): add space-after-exclamation (#6)
1 parent 19cd32d commit 78cc3e1

File tree

5 files changed

+158
-0
lines changed

5 files changed

+158
-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-exclamation
2+
3+
感嘆符前後のスペースについてのtexlintルール
4+
5+
## Install
6+
7+
Install with [npm](https://www.npmjs.com/):
8+
9+
npm install textlint-rule-ja-space-after-exclamation
10+
11+
## Usage
12+
13+
Via `.textlintrc`(Recommended)
14+
15+
```json
16+
{
17+
"rules": {
18+
"ja-space-after-exclamation": true
19+
}
20+
}
21+
```
22+
23+
Via CLI
24+
25+
```
26+
textlint --rule ja-space-after-exclamation 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-exclamation",
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: 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+
"【原文】Just plug it in, and coffee is ready in three minutes!",
9+
"【訳文】プラグを差し込めば、3 分でコーヒーができます。",
10+
"警告!",
11+
"驚きの速さ! これが新製品のキャッチコピーでした。"// 文末感嘆符+全角スペース
12+
],
13+
invalid: [
14+
{
15+
text: "驚きの速さ! これが新製品のキャッチコピーでした。半角 ",
16+
output: "驚きの速さ! これが新製品のキャッチコピーでした。半角 ",
17+
errors: [
18+
{
19+
message: "文末に感嘆符を使用し、後に別の文が続く場合は、直後に全角スペースを挿入します。",
20+
column: 7
21+
}
22+
]
23+
}
24+
]
25+
});

0 commit comments

Comments
 (0)