Skip to content

Commit 3fcd31a

Browse files
committed
initial commit
0 parents  commit 3fcd31a

File tree

9 files changed

+374
-0
lines changed

9 files changed

+374
-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: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# textlint-rule-max-kanji-continuous-len
2+
3+
[textlint](https://textlint.github.io/ "textlint") rule that limit max continuous length of kanji(漢字).
4+
5+
漢字が連続する最大文字数を制限する[textlint](https://textlint.github.io/ "textlint")ルールです。
6+
7+
## Install
8+
9+
Install with [npm](https://www.npmjs.com/):
10+
11+
npm install textlint-rule-max-kanji-continuous-len
12+
13+
## Usage
14+
15+
Via `.textlintrc`(Recommended)
16+
17+
18+
```json
19+
{
20+
"rules": {
21+
"max-kanji-continuous-len": true
22+
}
23+
}
24+
```
25+
26+
Via CLI
27+
28+
```
29+
textlint --rule max-kanji-continuous-len README.md
30+
```
31+
32+
## Options
33+
34+
- `max`
35+
- default: 5
36+
- `一二三四五六`は6文字なのでエラーとなります。
37+
- 最大の漢字長
38+
39+
40+
```json
41+
{
42+
"rules": {
43+
"max-kanji-continuous-len": {
44+
// 最大の漢字長
45+
// Allow max continuous length of kanji
46+
// If {current} > max(5), report Error.
47+
max: 5
48+
}
49+
}
50+
}
51+
```
52+
53+
## Further Reading
54+
55+
デフォルト値である漢字の連続調が6文字以上だとエラーとする根拠は今のところありません。
56+
57+
> 漢字連続長はこの印象に影響が無かったことから、漢字連続長を短くすることで「子ども向けの文章」という印象を与えず、先行研究で指摘される読みやすい文章が実現できると示唆された。
58+
> -- [日本心理学会第79回大会 漢字含有率と漢字連続長が文章の印象に与える影響](http://www.myschedule.jp/jpa2015/search/detail_program/id:602)
59+
60+
漢字の連続長が長くしすぎないことが、読みやすさに繋がることは既存研究にて実証されています。
61+
62+
おおまかに4文字と5文字に壁があり、そこにバッファをもたせて6文字以上は、デフォルトではエラーとしています。
63+
64+
- [日本心理学会第79回大会 漢字含有率と漢字連続長が文章の印象に与える影響](http://www.myschedule.jp/jpa2015/search/detail_program/id:602)
65+
- [漢字含有率と漢字連続長が文章の印象に与える影響.pdf](http://www.myschedule.jp/jpa2015/img/figure/90737.pdf)
66+
- [02Shibasaki.pdf](http://www.jels.info/REPL/02/02Shibasaki.pdf)
67+
- [signl136.PDF - signl136-slides.pdf](http://www.nori.jp/publications/SIGNL136/signl136-slides.pdf)
68+
69+
## Changelog
70+
71+
See [Releases page](https://github.com/azu/textlint-rule-max-kanji-continuous-len/releases).
72+
73+
## Running tests
74+
75+
Install devDependencies and Run `npm test`:
76+
77+
npm i -d && npm test
78+
79+
## Contributing
80+
81+
Pull requests and stars are always welcome.
82+
For bugs and feature requests, [please create an issue](https://github.com/azu/textlint-rule-max-kanji-continuous-len/issues).
83+
84+
1. Fork it!
85+
2. Create your feature branch: `git checkout -b my-new-feature`
86+
3. Commit your changes: `git commit -am 'Add some feature'`
87+
4. Push to the branch: `git push origin my-new-feature`
88+
5. Submit a pull request :D
89+
90+
## Author
91+
92+
- [github/azu](https://github.com/azu)
93+
- [twitter/azu_re](http://twitter.com/azu_re)
94+
95+
## License
96+
97+
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-max-kanji-continuous-len",
3+
"repository": {
4+
"type": "git",
5+
"url": "https://github.com/azu/textlint-rule-max-kanji-continuous-len.git"
6+
},
7+
"author": "azu",
8+
"email": "[email protected]",
9+
"homepage": "https://github.com/azu/textlint-rule-max-kanji-continuous-len",
10+
"license": "MIT",
11+
"bugs": {
12+
"url": "https://github.com/azu/textlint-rule-max-kanji-continuous-len/issues"
13+
},
14+
"files": [
15+
"src/",
16+
"lib/"
17+
],
18+
"version": "1.0.0",
19+
"description": "textlint rule that limit max continuous length of kanji(漢字).",
20+
"main": "lib/textlint-rule-max-kanji-continuous-len.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.8.0",
35+
"babel-preset-es2015": "^6.6.0",
36+
"babel-preset-jsdoc-to-assert": "^1.0.1",
37+
"babel-preset-power-assert": "^1.0.0",
38+
"babel-register": "^6.8.0",
39+
"mocha": "^2.4.5",
40+
"power-assert": "^1.3.1",
41+
"textlint-tester": "^1.2.0"
42+
},
43+
"dependencies": {
44+
"match-index": "^1.0.1",
45+
"textlint-rule-helper": "^1.1.5"
46+
}
47+
}
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+
import {RuleHelper} from "textlint-rule-helper";
4+
import {matchCaptureGroupAll} from "match-index"
5+
6+
const KanjiRegExp = /((?:[\u3400-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF])+)/g;
7+
const defaultOptions = {
8+
// 最大の漢字長
9+
// Allow max continuous length of kanji
10+
// If {current} > max(5), report Error.
11+
max: 5
12+
};
13+
14+
module.exports = function reporter(context, options = defaultOptions) {
15+
const {Syntax, RuleError, report, fixer, getSource} = context;
16+
const helper = new RuleHelper(context);
17+
const maxLength = options.max || defaultOptions.max;
18+
return {
19+
[Syntax.Str](node){
20+
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
21+
return;
22+
}
23+
const text = getSource(node);
24+
matchCaptureGroupAll(text, KanjiRegExp).forEach(({text, index}) => {
25+
// max より 大きい場合はエラー
26+
if (text.length > maxLength) {
27+
const ruleError = new RuleError(`漢字が${maxLength + 1}つ以上連続しています: ${text}`, {
28+
index
29+
});
30+
report(node, ruleError);
31+
}
32+
});
33+
}
34+
}
35+
};

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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const TextLintTester = require("textlint-tester");
2+
const tester = new TextLintTester();
3+
// rule
4+
import rule from "../src/textlint-rule-max-kanji-continuous-len";
5+
// ruleName, rule, { valid, invalid }
6+
tester.run("max-kanji-continuous-len", rule, {
7+
valid: [
8+
// no match
9+
"漢字",
10+
"漢字連続調",
11+
{
12+
text: "一二三四五六",
13+
options: {
14+
max: 6 // 6 is ok, 7 is ng
15+
}
16+
}
17+
],
18+
invalid: [
19+
{
20+
text: "漢字連続調複雑性が高い",
21+
errors: [
22+
{
23+
message: "漢字が6つ以上連続しています: 漢字連続調複雑性",
24+
line: 1,
25+
column: 1
26+
}
27+
]
28+
},
29+
{
30+
text: `#一二三四五六`,
31+
errors: [
32+
{
33+
message: "漢字が6つ以上連続しています: 一二三四五六",
34+
line: 1,
35+
column: 2
36+
}
37+
]
38+
},
39+
// multiple match in multiple lines
40+
{
41+
text: `一二三四五六です。一二三四五六です。`,
42+
errors: [
43+
{
44+
message: "漢字が6つ以上連続しています: 一二三四五六",
45+
line: 1,
46+
column: 1
47+
},
48+
49+
{
50+
message: "漢字が6つ以上連続しています: 一二三四五六",
51+
line: 1,
52+
column: 10
53+
}
54+
]
55+
},
56+
// multiple hit items in a line
57+
{
58+
text: `一二三四五六\n一二三四五六`,
59+
errors: [
60+
{
61+
message: "漢字が6つ以上連続しています: 一二三四五六",
62+
line: 1,
63+
column: 1
64+
},
65+
66+
{
67+
message: "漢字が6つ以上連続しています: 一二三四五六",
68+
line: 2,
69+
column: 1
70+
}
71+
]
72+
}
73+
]
74+
});

0 commit comments

Comments
 (0)