textlint-rule-max-ten
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -39,2 +39,16 @@ // LICENSE : MIT | ||
/** | ||
* add two positions. | ||
* note: line starts with 1, column starts with 0. | ||
* @param {Position} base | ||
* @param {Position} relative | ||
* @return {Position} | ||
*/ | ||
function addPositions(base, relative) { | ||
return { | ||
line: base.line + relative.line - 1, // line 1 + line 1 should be line 1 | ||
column: relative.line == 1 ? base.column + relative.column // when the same line | ||
: relative.column // when another line | ||
}; | ||
} | ||
/** | ||
* @param {RuleContext} context | ||
@@ -104,6 +118,7 @@ * @param {object} options | ||
if (currentTenCount >= maxLen) { | ||
var position = source.indexToPosition(lastToken.word_position - 1); | ||
var positionInSentence = source.indexToPosition(lastToken.word_position - 1); | ||
var positionInNode = addPositions(sentence.loc.start, positionInSentence); | ||
var ruleError = new context.RuleError("一つの文で\"、\"を" + maxLen + "つ以上使用しています", { | ||
line: position.line - 1, | ||
column: position.column | ||
line: positionInNode.line - 1, | ||
column: positionInNode.column | ||
}); | ||
@@ -110,0 +125,0 @@ report(node, ruleError); |
@@ -18,3 +18,3 @@ { | ||
}, | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "textlint rule that limit maxinum ten(、) count of sentence.", | ||
@@ -21,0 +21,0 @@ "main": "lib/max-ten.js", |
# textlint-rule-max-ten [![Build Status](https://travis-ci.org/azu/textlint-rule-max-ten.svg?branch=master)](https://travis-ci.org/azu/textlint-rule-max-ten) | ||
[textlint](https://github.com/azu/textlint "textlint") rule is that limit maximum ten(、) count of sentence. | ||
[textlint](https://github.com/textlint/textlint "textlint") rule is that limit maximum ten(、) count of sentence. | ||
@@ -25,3 +25,2 @@ ## Installation | ||
"max-ten": { | ||
// 1文で利用できる"、"の最大数 | ||
"max" : 3 | ||
@@ -33,14 +32,2 @@ } | ||
## Example | ||
> これは、長文の例ですが、読点の数が3つ以上あるので、エラーが報告されます。 | ||
=> error 一つの文で"、"を3つ以上使用しています | ||
> ビスケットの主な材料は(1)小麦粉、(2)牛乳、(3)ショートニング、(4)バター、(5)砂糖である。 | ||
- No error: 名詞同士で囲まれている `、` はカウントされない | ||
- 設定で `{ strict: true }` とした場合はこの例外は適応されずエラーとします | ||
## Tests | ||
@@ -47,0 +34,0 @@ |
@@ -23,2 +23,16 @@ // LICENSE : MIT | ||
/** | ||
* add two positions. | ||
* note: line starts with 1, column starts with 0. | ||
* @param {Position} base | ||
* @param {Position} relative | ||
* @return {Position} | ||
*/ | ||
function addPositions(base, relative) { | ||
return { | ||
line: base.line + relative.line - 1, // line 1 + line 1 should be line 1 | ||
column: relative.line == 1 ? base.column + relative.column // when the same line | ||
: relative.column // when another line | ||
}; | ||
} | ||
/** | ||
* @param {RuleContext} context | ||
@@ -82,6 +96,7 @@ * @param {object} options | ||
if (currentTenCount >= maxLen) { | ||
let position = source.indexToPosition(lastToken.word_position - 1); | ||
let positionInSentence = source.indexToPosition(lastToken.word_position - 1); | ||
let positionInNode = addPositions(sentence.loc.start, positionInSentence); | ||
let ruleError = new context.RuleError(`一つの文で"、"を${maxLen}つ以上使用しています`, { | ||
line: position.line - 1, | ||
column: position.column | ||
line: positionInNode.line - 1, | ||
column: positionInNode.column | ||
}); | ||
@@ -88,0 +103,0 @@ report(node, ruleError); |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19156
224
0
45