Skip to content

Commit 632ab62

Browse files
committed
initial commit
0 parents  commit 632ab62

File tree

9 files changed

+379
-0
lines changed

9 files changed

+379
-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: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# textlint-rule-ja-no-mixed-period
2+
3+
文末の句点(。)の統一 OR 抜けをチェックするtextlintルール
4+
5+
```
6+
OK: これは問題ない文章です。
7+
NG: これは問題ある文章です
8+
```
9+
パラグラフの末尾に必ず句点記号を付けていることをチェックするルールです。
10+
11+
12+
## Install
13+
14+
Install with [npm](https://www.npmjs.com/):
15+
16+
npm install textlint-rule-ja-no-mixed-period
17+
18+
## Usage
19+
20+
Via `.textlintrc`(Recommended)
21+
22+
```json
23+
{
24+
"rules": {
25+
"ja-no-mixed-period": true
26+
}
27+
}
28+
```
29+
30+
Via CLI
31+
32+
```
33+
textlint --rule ja-no-mixed-period README.md
34+
```
35+
36+
## Options
37+
38+
- `periodMark`(string):
39+
- 文末に使用する句点文字
40+
- デフォルト: "。"
41+
42+
```json
43+
{
44+
"rules": {
45+
"ja-no-mixed-period": {
46+
"periodMark": ""
47+
}
48+
}
49+
}
50+
```
51+
52+
## 参考情報
53+
54+
- [句点 - Wikipedia](https://ja.wikipedia.org/wiki/%E5%8F%A5%E7%82%B9 "句点 - Wikipedia")
55+
- [小説家になろう Hint&Tips - 区切り符号について](http://ncode.syosetu.com/n8977bb/12/ "小説家になろう Hint&Tips - 区切り符号について")
56+
57+
末尾に``がない場合でも、代わりに感嘆符や疑問符、括弧などがある場合は例外として扱います。
58+
59+
> これは問題ない文章ですか!?
60+
> 「会話文は括弧で括れば末尾に。がなくても問題ありません」
61+
62+
## Changelog
63+
64+
See [Releases page](https://github.com/azu/textlint-rule-ja-no-mixed-period/releases).
65+
66+
## Running tests
67+
68+
Install devDependencies and Run `npm test`:
69+
70+
npm i -d && npm test
71+
72+
## Contributing
73+
74+
Pull requests and stars are always welcome.
75+
76+
For bugs and feature requests, [please create an issue](https://github.com/azu/textlint-rule-ja-no-mixed-period/issues).
77+
78+
1. Fork it!
79+
2. Create your feature branch: `git checkout -b my-new-feature`
80+
3. Commit your changes: `git commit -am 'Add some feature'`
81+
4. Push to the branch: `git push origin my-new-feature`
82+
5. Submit a pull request :D
83+
84+
## Author
85+
86+
- [github/azu](https://github.com/azu)
87+
- [twitter/azu_re](https://twitter.com/azu_re)
88+
89+
## License
90+
91+
MIT © azu

package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "textlint-rule-ja-no-mixed-period",
3+
"repository": {
4+
"type": "git",
5+
"url": "https://github.com/azu/textlint-rule-ja-no-mixed-period.git"
6+
},
7+
"author": "azu",
8+
"email": "azuciao@gmail.com",
9+
"homepage": "https://github.com/azu/textlint-rule-ja-no-mixed-period",
10+
"license": "MIT",
11+
"bugs": {
12+
"url": "https://github.com/azu/textlint-rule-ja-no-mixed-period/issues"
13+
},
14+
"files": [
15+
"src/",
16+
"lib/"
17+
],
18+
"version": "1.0.0",
19+
"description": "文末の句点(。)の統一 OR 抜けをチェックするtextlintルール",
20+
"main": "lib/textlint-rule-ja-no-mixed-period.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.10.1",
35+
"babel-preset-es2015": "^6.9.0",
36+
"babel-preset-jsdoc-to-assert": "^2.0.1",
37+
"babel-preset-power-assert": "^1.0.0",
38+
"babel-register": "^6.9.0",
39+
"mocha": "^2.5.3",
40+
"power-assert": "^1.4.1",
41+
"textlint-tester": "^2.0.0"
42+
}
43+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
const exceptionMarkRegExp = /[!?\) ]/;
4+
const defaultPeriodMark = /[\.]/;
5+
const defaultOptions = {
6+
// 優先する句点文字
7+
periodMark: "。"
8+
};
9+
const reporter = (context, options = {}) => {
10+
const {Syntax, RuleError, report, fixer, getSource} = context;
11+
const periodMark = options.periodMark || defaultOptions.periodMark;
12+
return {
13+
[Syntax.Paragraph](node){
14+
const lastNode = node.children[node.children.length - 1];
15+
if (lastNode === undefined || lastNode.type !== Syntax.Str) {
16+
return;
17+
}
18+
const lastStrText = getSource(lastNode);
19+
const lastIndex = lastStrText.length - 1;
20+
const lastChar = lastStrText[lastIndex];
21+
if (lastChar === undefined) {
22+
return;
23+
}
24+
// 例外: 感嘆符
25+
// 例外: 「」 () ()『』
26+
// http://ncode.syosetu.com/n8977bb/12/
27+
// https://ja.wikipedia.org/wiki/%E7%B5%82%E6%AD%A2%E7%AC%A6
28+
if (exceptionMarkRegExp.test(lastChar)) {
29+
return;
30+
}
31+
if (lastChar === periodMark) {
32+
return;
33+
}
34+
35+
let fix = null;
36+
if (defaultPeriodMark.test(lastChar)) {
37+
fix = fixer.replaceTextRange([lastIndex, lastIndex + 1], periodMark);
38+
} else {
39+
fix = fixer.replaceTextRange([lastIndex + 1, lastIndex + 1], periodMark);
40+
}
41+
report(lastNode, new RuleError(`文末が"${periodMark}"で終わっていません。`, {
42+
index: lastIndex,
43+
fix
44+
}));
45+
46+
}
47+
}
48+
};
49+
50+
module.exports = {
51+
linter: reporter,
52+
fixer: reporter
53+
};

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
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const TextLintTester = require("textlint-tester");
2+
const tester = new TextLintTester();
3+
import rule from "../src/textlint-rule-ja-no-mixed-period";
4+
tester.run("textlint-rule-ja-no-mixed-period", rule, {
5+
valid: [
6+
"これは問題ないです。",
7+
"1行目。\n2行目。\n3行目。",
8+
"1行目。 \nHard Breakを入れるパターン。",
9+
"1行目 空白はあるけど末尾に句点はある。",
10+
// 感嘆符などが末尾にある場合は問題なし
11+
"末尾に句点はある!"
12+
],
13+
invalid: [
14+
// single match
15+
{
16+
text: "これは句点がありません",
17+
output: "これは句点がありません。",
18+
errors: [
19+
{
20+
message: `文末が"。"で終わっていません。`,
21+
line: 1,
22+
column: 11
23+
}
24+
]
25+
},
26+
// multiple match in multiple lines
27+
{
28+
text: "これは句点がありません\n\nこれは句点がありません",
29+
output: "これは句点がありません。\n\nこれは句点がありません。",
30+
errors: [
31+
{
32+
message: `文末が"。"で終わっていません。`,
33+
line: 1,
34+
column: 11
35+
},
36+
{
37+
message: `文末が"。"で終わっていません。`,
38+
line: 3,
39+
column: 11
40+
}
41+
]
42+
},
43+
// multiple hit items in a line
44+
{
45+
text: "これは句点がありません、これは句点がありません",
46+
output: "これは句点がありません、これは句点がありません。",
47+
errors: [
48+
{
49+
message: `文末が"。"で終わっていません。`,
50+
line: 1,
51+
column: 23
52+
}
53+
]
54+
},
55+
// options
56+
{
57+
text: "This is error",
58+
output: "This is error.",
59+
options: {
60+
periodMark: "."
61+
},
62+
errors: [
63+
{
64+
message: `文末が"."で終わっていません。`,
65+
line: 1,
66+
column: 13
67+
}
68+
]
69+
}
70+
]
71+
});

0 commit comments

Comments
 (0)