Skip to content

Commit 2433b8e

Browse files
committed
initial commit
0 parents  commit 2433b8e

File tree

9 files changed

+300
-0
lines changed

9 files changed

+300
-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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# textlint-rule-ja-no-successive-word
2+
3+
同一の単語を間違えて連続しているのを見つけるtextlintルール
4+
5+
## Install
6+
7+
Install with [npm](https://www.npmjs.com/):
8+
9+
npm install textlint-rule-ja-no-successive-word
10+
11+
## Usage
12+
13+
Via `.textlintrc`(Recommended)
14+
15+
```json
16+
{
17+
"rules": {
18+
"ja-no-successive-word": true
19+
}
20+
}
21+
```
22+
23+
Via CLI
24+
25+
```
26+
textlint --rule ja-no-successive-word README.md
27+
```
28+
29+
30+
## Changelog
31+
32+
See [Releases page](https://github.com/azu/textlint-rule-ja-no-successive-word/releases).
33+
34+
## Running tests
35+
36+
Install devDependencies and Run `npm test`:
37+
38+
npm i -d && npm test
39+
40+
## 参考
41+
42+
- [RedPen 1.6 ドキュメント](http://redpen.cc/docs/latest/index_ja.html#successiveword)
43+
- [redpen/SuccessiveWordValidator.java at master · redpen-cc/redpen](https://github.com/redpen-cc/redpen/blob/master/redpen-core/src/main/java/cc/redpen/validator/sentence/SuccessiveWordValidator.java#L29)
44+
45+
46+
## Contributing
47+
48+
Pull requests and stars are always welcome.
49+
50+
For bugs and feature requests, [please create an issue](https://github.com/azu/textlint-rule-ja-no-successive-word/issues).
51+
52+
1. Fork it!
53+
2. Create your feature branch: `git checkout -b my-new-feature`
54+
3. Commit your changes: `git commit -am 'Add some feature'`
55+
4. Push to the branch: `git push origin my-new-feature`
56+
5. Submit a pull request :D
57+
58+
## Author
59+
60+
- [github/azu](https://github.com/azu)
61+
- [twitter/azu_re](https://twitter.com/azu_re)
62+
63+
## License
64+
65+
MIT © azu

package.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "textlint-rule-ja-no-successive-word",
3+
"repository": {
4+
"type": "git",
5+
"url": "https://github.com/azu/textlint-rule-ja-no-successive-word.git"
6+
},
7+
"author": "azu",
8+
"email": "[email protected]",
9+
"homepage": "https://github.com/azu/textlint-rule-ja-no-successive-word",
10+
"license": "MIT",
11+
"bugs": {
12+
"url": "https://github.com/azu/textlint-rule-ja-no-successive-word/issues"
13+
},
14+
"files": [
15+
"src/",
16+
"lib/"
17+
],
18+
"version": "1.0.0",
19+
"description": "同一の単語を間違えて連続しているのを見つけるtextlintルール",
20+
"main": "lib/textlint-rule-ja-no-successive-word.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+
"redpen"
33+
],
34+
"devDependencies": {
35+
"babel-cli": "^6.10.1",
36+
"babel-preset-es2015": "^6.9.0",
37+
"babel-preset-jsdoc-to-assert": "^2.0.1",
38+
"babel-preset-power-assert": "^1.0.0",
39+
"babel-register": "^6.9.0",
40+
"mocha": "^2.5.3",
41+
"power-assert": "^1.4.1",
42+
"textlint-tester": "^2.0.0"
43+
},
44+
"dependencies": {
45+
"kuromojin": "^1.3.1"
46+
}
47+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
const tokenize = require("kuromojin").tokenize;
4+
module.exports = function(context) {
5+
const {Syntax, RuleError, report, getSource} = context;
6+
return {
7+
[Syntax.Str](node){
8+
const text = getSource(node);
9+
return tokenize(text).then(tokens => {
10+
let prevToken = {};
11+
tokens.forEach(token => {
12+
if (prevToken.surface_form === token.surface_form) {
13+
const index = Math.max(token.word_position - 1, 0);
14+
report(node, new RuleError(`"${token.surface_form}" が連続して2回使われています。`, {
15+
index
16+
}));
17+
}
18+
prevToken = token;
19+
});
20+
});
21+
}
22+
}
23+
};

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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const TextLintTester = require("textlint-tester");
2+
const tester = new TextLintTester();
3+
// rule
4+
import rule from "../src/textlint-rule-ja-no-successive-word";
5+
// ruleName, rule, { valid, invalid }
6+
tester.run("ja-no-successive-word", rule, {
7+
valid: [
8+
"これは問題ない文章です。",
9+
"すもももももももものうち",
10+
"111回目の問題",
11+
"11,11回目の問題",
12+
],
13+
invalid: [
14+
// single match
15+
{
16+
text: "これはは問題ある文章です。",
17+
errors: [
18+
{
19+
message: `"は" が連続して2回使われています。`,
20+
line: 1,
21+
column: 4
22+
}
23+
]
24+
},
25+
// multiple match in multiple lines
26+
{
27+
text: `これはは問題ある文章です。
28+
29+
これは問題あるある文章です`,
30+
errors: [
31+
{
32+
message: `"は" が連続して2回使われています。`,
33+
line: 1,
34+
column: 4
35+
},
36+
{
37+
message: `"ある" が連続して2回使われています。`,
38+
line: 3,
39+
column: 8
40+
}
41+
]
42+
}
43+
]
44+
});

0 commit comments

Comments
 (0)