textlint-rule-max-ten
Advanced tools
Comparing version 4.0.2 to 4.0.3
@@ -12,2 +12,6 @@ // LICENSE : MIT | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
var defaultOptions = { | ||
@@ -142,7 +146,7 @@ // 1文に利用できる最大の、の数 | ||
return (0, _kuromojin.getTokenizer)().then(tokenizer => { | ||
sentences.forEach(sentence => { | ||
var checkSentence = /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator(function* (sentence) { | ||
var source = new _textlintUtilToString.StringSource(sentence); | ||
var text = source.toString(); | ||
var tokens = tokenizer.tokenizeForSentence(text); | ||
var tokens = yield (0, _kuromojin.tokenize)(text); | ||
var currentTenCount = 0; | ||
@@ -197,3 +201,9 @@ var lastToken = null; | ||
}); | ||
}); | ||
return function checkSentence(_x) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(); | ||
return Promise.all(sentences.map(checkSentence)); | ||
} | ||
@@ -200,0 +210,0 @@ |
@@ -19,3 +19,3 @@ { | ||
}, | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"description": "textlint rule that limit maxinum ten(、) count of sentence.", | ||
@@ -36,3 +36,3 @@ "main": "lib/max-ten.js", | ||
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", | ||
"prepare": "git config --local core.hooksPath .githook" | ||
"prepare": "git config --local core.hooksPath .githooks" | ||
}, | ||
@@ -39,0 +39,0 @@ "devDependencies": { |
// LICENSE : MIT | ||
"use strict"; | ||
import { RuleHelper } from "textlint-rule-helper"; | ||
import { getTokenizer } from "kuromojin"; | ||
import { tokenize } from "kuromojin"; | ||
import { splitAST, Syntax as SentenceSyntax } from "sentence-splitter"; | ||
@@ -106,57 +106,56 @@ import { StringSource } from "textlint-util-to-string"; | ||
*/ | ||
return getTokenizer().then((tokenizer) => { | ||
sentences.forEach((sentence) => { | ||
const source = new StringSource(sentence); | ||
const text = source.toString(); | ||
const tokens = tokenizer.tokenizeForSentence(text); | ||
let currentTenCount = 0; | ||
let lastToken = null; | ||
tokens.forEach((token, index) => { | ||
const surface = token.surface_form; | ||
if (surface === touten) { | ||
// 名詞に囲まわれている場合は例外とする | ||
const isSandwiched = isSandwichedMeishi({ | ||
before: findSiblingMeaningToken({ | ||
tokens, | ||
currentIndex: index, | ||
direction: "prev" | ||
}), | ||
token: token, | ||
after: findSiblingMeaningToken({ | ||
tokens, | ||
currentIndex: index, | ||
direction: "next" | ||
}) | ||
}); | ||
// strictなら例外を例外としない | ||
if (!isStrict && isSandwiched) { | ||
return; | ||
const checkSentence = async (sentence) => { | ||
const source = new StringSource(sentence); | ||
const text = source.toString(); | ||
const tokens = await tokenize(text); | ||
let currentTenCount = 0; | ||
let lastToken = null; | ||
tokens.forEach((token, index) => { | ||
const surface = token.surface_form; | ||
if (surface === touten) { | ||
// 名詞に囲まわれている場合は例外とする | ||
const isSandwiched = isSandwichedMeishi({ | ||
before: findSiblingMeaningToken({ | ||
tokens, | ||
currentIndex: index, | ||
direction: "prev" | ||
}), | ||
token: token, | ||
after: findSiblingMeaningToken({ | ||
tokens, | ||
currentIndex: index, | ||
direction: "next" | ||
}) | ||
}); | ||
// strictなら例外を例外としない | ||
if (!isStrict && isSandwiched) { | ||
return; | ||
} | ||
currentTenCount++; | ||
lastToken = token; | ||
} | ||
if (surface === kuten) { | ||
// reset | ||
currentTenCount = 0; | ||
} | ||
// report | ||
if (currentTenCount > maxLen) { | ||
const positionInSentence = source.originalIndexFromIndex(lastToken.word_position - 1); | ||
// relative index from Paragraph Node | ||
// Sentence start(relative) + word position(relative) | ||
const index = sentence.range[0] - node.range[0] + positionInSentence; | ||
const ruleError = new context.RuleError( | ||
`一つの文で"${touten}"を${maxLen + 1}つ以上使用しています`, | ||
{ | ||
index | ||
} | ||
currentTenCount++; | ||
lastToken = token; | ||
} | ||
if (surface === kuten) { | ||
// reset | ||
currentTenCount = 0; | ||
} | ||
// report | ||
if (currentTenCount > maxLen) { | ||
const positionInSentence = source.originalIndexFromIndex(lastToken.word_position - 1); | ||
// relative index from Paragraph Node | ||
// Sentence start(relative) + word position(relative) | ||
const index = sentence.range[0] - node.range[0] + positionInSentence; | ||
const ruleError = new context.RuleError( | ||
`一つの文で"${touten}"を${maxLen + 1}つ以上使用しています`, | ||
{ | ||
index | ||
} | ||
); | ||
report(node, ruleError); | ||
currentTenCount = 0; | ||
} | ||
}); | ||
); | ||
report(node, ruleError); | ||
currentTenCount = 0; | ||
} | ||
}); | ||
}); | ||
}; | ||
return Promise.all(sentences.map(checkSentence)); | ||
} | ||
}; | ||
}; |
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
28657
329