Skip to content

Commit 100e49f

Browse files
committed
initial commit
0 parents  commit 100e49f

File tree

10 files changed

+392
-0
lines changed

10 files changed

+392
-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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# textlint-rule-ja-no-abusage
2+
3+
よくある誤用をチェックするtextlintルール
4+
5+
- 「適応」と「適用」
6+
- [適用 vs 適応 - Qiita](http://qiita.com/magicant/items/229424403fee643b7075)
7+
- [設定は「適用」するものです。 - Qiita](http://qiita.com/yama-t/items/4f84ed6940682f62827f)
8+
9+
10+
## Install
11+
12+
Install with [npm](https://www.npmjs.com/):
13+
14+
npm install textlint-rule-ja-no-abusage
15+
16+
## Usage
17+
18+
Via `.textlintrc`(Recommended)
19+
20+
```json
21+
{
22+
"rules": {
23+
"ja-no-abusage": true
24+
}
25+
}
26+
```
27+
28+
Via CLI
29+
30+
```
31+
textlint --rule ja-no-abusage README.md
32+
```
33+
34+
35+
## Changelog
36+
37+
See [Releases page](https://github.com/textlint-ja/textlint-rule-ja-no-abusage/releases).
38+
39+
## Running tests
40+
41+
Install devDependencies and Run `npm test`:
42+
43+
npm i -d && npm test
44+
45+
## Contributing
46+
47+
Pull requests and stars are always welcome.
48+
49+
For bugs and feature requests, [please create an issue](https://github.com/textlint-ja/textlint-rule-ja-no-abusage/issues).
50+
51+
1. Fork it!
52+
2. Create your feature branch: `git checkout -b my-new-feature`
53+
3. Commit your changes: `git commit -am 'Add some feature'`
54+
4. Push to the branch: `git push origin my-new-feature`
55+
5. Submit a pull request :D
56+
57+
## Author
58+
59+
- [github/azu](https://github.com/azu)
60+
- [twitter/azu_re](https://twitter.com/azu_re)
61+
62+
## License
63+
64+
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-abusage",
3+
"repository": {
4+
"type": "git",
5+
"url": "https://github.com/textlint-ja/textlint-rule-ja-no-abusage.git"
6+
},
7+
"author": "azu",
8+
"email": "azuciao@gmail.com",
9+
"homepage": "https://github.com/textlint-ja/textlint-rule-ja-no-abusage",
10+
"license": "MIT",
11+
"bugs": {
12+
"url": "https://github.com/textlint-ja/textlint-rule-ja-no-abusage/issues"
13+
},
14+
"files": [
15+
"src/",
16+
"lib/"
17+
],
18+
"version": "1.0.0",
19+
"description": "よくある誤用をチェックするtextlintルール",
20+
"main": "lib/textlint-rule-ja-no-abusage.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": "^1.2.0"
42+
},
43+
"dependencies": {
44+
"kuromojin": "^1.3.1",
45+
"morpheme-match": "^1.0.1"
46+
}
47+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module.exports = [
2+
{
3+
// http://azu.github.io/morpheme-match/?text=今朝起きた事件に法律(を適応)する
4+
message: `"適用"の誤用である可能性があります。適応 => 適用`,
5+
expected: "を適用",
6+
tokens: [
7+
{
8+
"surface_form": "を",
9+
"pos": "助詞",
10+
"pos_detail_1": "格助詞",
11+
"pos_detail_2": "一般",
12+
"pos_detail_3": "*",
13+
"conjugated_type": "*",
14+
"conjugated_form": "*",
15+
"basic_form": "を",
16+
"reading": "ヲ",
17+
"pronunciation": "ヲ"
18+
},
19+
{
20+
"surface_form": "適応",
21+
"pos": "名詞",
22+
"pos_detail_1": "サ変接続",
23+
"pos_detail_2": "*",
24+
"pos_detail_3": "*",
25+
"conjugated_type": "*",
26+
"conjugated_form": "*",
27+
"basic_form": "適応",
28+
"reading": "テキオウ",
29+
"pronunciation": "テキオー"
30+
}
31+
]
32+
33+
}
34+
];

src/textlint-rule-ja-no-abusage.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
const tokenize = require("kuromojin").tokenize;
4+
const dictionaryList = require("./no-confusing-adjust-and-apply");
5+
const createTokenMatcher = require("morpheme-match");
6+
const reporter = (context) => {
7+
const {Syntax, RuleError, report, fixer, getSource} = context;
8+
const matcherList = dictionaryList.map(dict => {
9+
return {
10+
matcher: createTokenMatcher(dict["tokens"]),
11+
message: dict["message"],
12+
expected: dict["expected"]
13+
};
14+
});
15+
return {
16+
[Syntax.Str](node){
17+
const text = getSource(node);
18+
return tokenize(text).then(currentTokens => {
19+
currentTokens.forEach(token => {
20+
matcherList.forEach(({matcher, message, expected}) => {
21+
const {match, tokens} = matcher(token);
22+
if (!match) {
23+
return;
24+
}
25+
const firstToken = tokens[0];
26+
const index = Math.max(firstToken.word_position - 1, 0);
27+
if (expected) {
28+
report(node, new RuleError(message, {
29+
index: index,
30+
fix: fixer.replaceTextRange([index, index + expected.length], expected)
31+
}));
32+
} else {
33+
report(node, new RuleError(message, {
34+
index: index
35+
}));
36+
}
37+
});
38+
});
39+
});
40+
}
41+
}
42+
};
43+
module.exports = {
44+
linter: reporter,
45+
fixer: reporter
46+
};

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

0 commit comments

Comments
 (0)