textlint-rule-max-ten
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -10,24 +10,25 @@ // LICENSE : MIT | ||
var _structuredSource = require("structured-source"); | ||
var _structuredSource = _interopRequireDefault(require("structured-source")); | ||
var _structuredSource2 = _interopRequireDefault(_structuredSource); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var defaultOptions = { | ||
max: 3, | ||
// 1文に利用できる最大の、の数 | ||
strict: false // 例外ルールを適応するかどうか | ||
var defaultOptions = { | ||
max: 3, // 1文に利用できる最大の、の数 | ||
strict: false // 例外ルールを適応するかどうか | ||
}; | ||
function isSandwichedMeishi(_ref) { | ||
var before = _ref.before, | ||
token = _ref.token, | ||
after = _ref.after; | ||
var { | ||
before, | ||
token, | ||
after | ||
} = _ref; | ||
if (before === undefined || after === undefined || token === undefined) { | ||
return false; | ||
} | ||
return before.pos === "名詞" && after.pos === "名詞"; | ||
if (before === undefined || after === undefined || token === undefined) { | ||
return false; | ||
} | ||
return before.pos === "名詞" && after.pos === "名詞"; | ||
} | ||
@@ -41,8 +42,12 @@ /** | ||
*/ | ||
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 | ||
}; | ||
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 | ||
}; | ||
} | ||
@@ -53,76 +58,88 @@ /** | ||
*/ | ||
module.exports = function (context) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var maxLen = options.max || defaultOptions.max; | ||
var isStrict = options.strict || defaultOptions.strict; | ||
var helper = new _textlintRuleHelper.RuleHelper(context); | ||
var { | ||
Syntax, | ||
RuleError, | ||
report, | ||
getSource | ||
} = context; | ||
return { | ||
[Syntax.Paragraph](node) { | ||
if (helper.isChildNode(node, [Syntax.BlockQuote])) { | ||
return; | ||
} | ||
var maxLen = options.max || defaultOptions.max; | ||
var isStrict = options.strict || defaultOptions.strict; | ||
var helper = new _textlintRuleHelper.RuleHelper(context); | ||
var Syntax = context.Syntax, | ||
RuleError = context.RuleError, | ||
report = context.report, | ||
getSource = context.getSource; | ||
var sentences = (0, _sentenceSplitter.split)(getSource(node), { | ||
charRegExp: /[。\?\!?!]/, | ||
newLineCharacters: "\n\n" | ||
}); | ||
/* | ||
<p> | ||
<str><code><img><str> | ||
<str> | ||
</p> | ||
*/ | ||
return _defineProperty({}, Syntax.Paragraph, function (node) { | ||
if (helper.isChildNode(node, [Syntax.BlockQuote])) { | ||
return; | ||
} | ||
var sentences = (0, _sentenceSplitter.split)(getSource(node), { | ||
charRegExp: /[。\?\!?!]/, | ||
newLineCharacters: "\n\n" | ||
/* | ||
# workflow | ||
1. split text to sentences | ||
2. sentence to tokens | ||
3. check tokens | ||
*/ | ||
return (0, _kuromojin.getTokenizer)().then(tokenizer => { | ||
sentences.forEach(sentence => { | ||
var text = sentence.value; | ||
var source = new _structuredSource.default(text); | ||
var currentTenCount = 0; | ||
var tokens = tokenizer.tokenizeForSentence(text); | ||
var lastToken = null; | ||
tokens.forEach((token, index) => { | ||
var surface = token.surface_form; | ||
if (surface === "、") { | ||
// 名詞に囲まわれている場合は例外とする | ||
var isSandwiched = isSandwichedMeishi({ | ||
before: tokens[index - 1], | ||
token: token, | ||
after: tokens[index + 1] | ||
}); // strictなら例外を例外としない | ||
if (!isStrict && isSandwiched) { | ||
return; | ||
} | ||
currentTenCount++; | ||
lastToken = token; | ||
} | ||
if (surface === "。") { | ||
// reset | ||
currentTenCount = 0; | ||
} // report | ||
if (currentTenCount >= maxLen) { | ||
var positionInSentence = source.indexToPosition(lastToken.word_position - 1); | ||
var positionInNode = addPositions(sentence.loc.start, positionInSentence); | ||
var ruleError = new context.RuleError("\u4E00\u3064\u306E\u6587\u3067\"\u3001\"\u3092".concat(maxLen, "\u3064\u4EE5\u4E0A\u4F7F\u7528\u3057\u3066\u3044\u307E\u3059"), { | ||
line: positionInNode.line - 1, | ||
column: positionInNode.column | ||
}); | ||
report(node, ruleError); | ||
currentTenCount = 0; | ||
} | ||
}); | ||
}); | ||
/* | ||
<p> | ||
<str><code><img><str> | ||
<str> | ||
</p> | ||
*/ | ||
/* | ||
# workflow | ||
1. split text to sentences | ||
2. sentence to tokens | ||
3. check tokens | ||
*/ | ||
return (0, _kuromojin.getTokenizer)().then(function (tokenizer) { | ||
sentences.forEach(function (sentence) { | ||
var text = sentence.value; | ||
var source = new _structuredSource2.default(text); | ||
var currentTenCount = 0; | ||
var tokens = tokenizer.tokenizeForSentence(text); | ||
var lastToken = null; | ||
tokens.forEach(function (token, index) { | ||
var surface = token.surface_form; | ||
if (surface === "、") { | ||
// 名詞に過去まわれている場合は例外とする | ||
var isSandwiched = isSandwichedMeishi({ | ||
before: tokens[index - 1], | ||
token: token, | ||
after: tokens[index + 1] | ||
}); | ||
// strictなら例外を例外としない | ||
if (!isStrict && isSandwiched) { | ||
return; | ||
} | ||
currentTenCount++; | ||
lastToken = token; | ||
} | ||
if (surface === "。") { | ||
// reset | ||
currentTenCount = 0; | ||
} | ||
// report | ||
if (currentTenCount >= maxLen) { | ||
var positionInSentence = source.indexToPosition(lastToken.word_position - 1); | ||
var positionInNode = addPositions(sentence.loc.start, positionInSentence); | ||
var ruleError = new context.RuleError("\u4E00\u3064\u306E\u6587\u3067\"\u3001\"\u3092" + maxLen + "\u3064\u4EE5\u4E0A\u4F7F\u7528\u3057\u3066\u3044\u307E\u3059", { | ||
line: positionInNode.line - 1, | ||
column: positionInNode.column | ||
}); | ||
report(node, ruleError); | ||
currentTenCount = 0; | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
}; | ||
}; | ||
//# sourceMappingURL=max-ten.js.map |
@@ -19,3 +19,3 @@ { | ||
}, | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "textlint rule that limit maxinum ten(、) count of sentence.", | ||
@@ -31,20 +31,12 @@ "main": "lib/max-ten.js", | ||
"scripts": { | ||
"build": "NODE_ENV=production babel src --out-dir lib --source-maps", | ||
"watch": "babel src --out-dir lib --watch --source-maps", | ||
"build": "textlint-scripts build", | ||
"watch": "textlint-scripts build --watch", | ||
"prepublish": "npm run --if-present build", | ||
"test": "mocha && npm run build && textlint --rulesdir lib/ README.md" | ||
"test": "textlint-scripts test" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.10.1", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-jsdoc-to-assert": "^4.0.0", | ||
"babel-preset-power-assert": "^1.0.0", | ||
"babel-register": "^6.9.0", | ||
"mocha": "^3.2.0", | ||
"power-assert": "^1.4.1", | ||
"textlint": "^7.0.1", | ||
"textlint-tester": "^2.0.0" | ||
"textlint-scripts": "^3.0.0" | ||
}, | ||
"dependencies": { | ||
"kuromojin": "^1.0.2", | ||
"kuromojin": "^2.0.0", | ||
"sentence-splitter": "^2.0.0", | ||
@@ -51,0 +43,0 @@ "structured-source": "^3.0.2", |
@@ -24,3 +24,3 @@ # textlint-rule-max-ten [![Build Status](https://travis-ci.org/textlint-ja/textlint-rule-max-ten.svg?branch=master)](https://travis-ci.org/textlint-ja/textlint-rule-max-ten) [![Gitter](https://badges.gitter.im/textlint-ja/textlint-ja.svg)](https://gitter.im/textlint-ja/textlint-ja) | ||
- デフォルト: 3 | ||
- 一文に許可される読点の数 | ||
- 一文に許可される読点の数 + 1 | ||
@@ -56,2 +56,2 @@ ```json | ||
MIT | ||
MIT |
@@ -76,3 +76,3 @@ // LICENSE : MIT | ||
if (surface === "、") { | ||
// 名詞に過去まわれている場合は例外とする | ||
// 名詞に囲まわれている場合は例外とする | ||
let isSandwiched = isSandwichedMeishi({ | ||
@@ -110,2 +110,2 @@ before: tokens[index - 1], | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
224
56
19535
+ Addedkuromojin@2.1.1(transitive)
- Removedkuromojin@1.5.1(transitive)
Updatedkuromojin@^2.0.0