Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

textlint-rule-max-ten

Package Overview
Dependencies
Maintainers
5
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

textlint-rule-max-ten - npm Package Compare versions

Comparing version 4.0.4 to 5.0.0

71

lib/max-ten.js

@@ -5,13 +5,7 @@ // LICENSE : MIT

var _textlintRuleHelper = require("textlint-rule-helper");
var _kuromojin = require("kuromojin");
var _sentenceSplitter = require("sentence-splitter");
var _textlintUtilToString = require("textlint-util-to-string");
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 = {

@@ -29,3 +23,2 @@ // 1文に利用できる最大の、の数

};
function isSandwichedMeishi(_ref) {

@@ -37,9 +30,8 @@ var {

} = _ref;
if (before === undefined || after === undefined || token === undefined) {
return false;
}
return before.pos === "名詞" && after.pos === "名詞";
}
/**

@@ -50,4 +42,2 @@ * 括弧のトークンかどうか

*/
function is括弧(token) {

@@ -57,9 +47,8 @@ if (token.pos === "記号" && /^括弧/.test(token.pos_detail_1)) {

}
if (token.surface_form === "(" || token.surface_form === ")") {
return true;
}
return false;
}
/**

@@ -73,4 +62,2 @@ * 括弧などの記号的なTokenはスキップとして隣接するTokenを探す

*/
function findSiblingMeaningToken(_ref2) {

@@ -84,8 +71,6 @@ var {

var sibilingToken = tokens[currentIndex + delta];
if (!sibilingToken) {
return;
} // 括弧はスキップして、隣接Nodeを探す
}
// 括弧はスキップして、隣接Nodeを探す
if (is括弧(sibilingToken)) {

@@ -98,14 +83,12 @@ return findSiblingMeaningToken({

}
return sibilingToken;
}
/**
* @param {RuleContext} context
* @param {import("@textlint/types").TextlintRuleContext} context
* @param {typeof defaultOptions} [options]
* @return {import("@textlint/types").TextlintFilterRuleReportHandler}}
*/
module.exports = function (context) {
var _options$max, _options$strict, _options$touten, _options$kuten;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -121,7 +104,10 @@ var maxLen = (_options$max = options.max) !== null && _options$max !== void 0 ? _options$max : defaultOptions.max;

report,
getSource
locator
} = context;
var separatorCharacters = ["?", // question mark
"!", // exclamation mark
"?", // (ja) zenkaku question mark
var separatorCharacters = ["?",
// question mark
"!",
// exclamation mark
"?",
// (ja) zenkaku question mark
"!" // (ja) zenkaku exclamation mark

@@ -134,3 +120,2 @@ ].concat(kuten);

}
var resultNode = (0, _sentenceSplitter.splitAST)(node, {

@@ -141,3 +126,3 @@ SeparatorParser: {

});
var sentences = resultNode.children.filter(childNode => childNode.type === _sentenceSplitter.Syntax.Sentence);
var sentences = resultNode.children.filter(childNode => childNode.type === _sentenceSplitter.SentenceSplitterSyntax.Sentence);
/*

@@ -149,3 +134,2 @@ <p>

*/
/*

@@ -157,3 +141,2 @@ # workflow

*/
var checkSentence = /*#__PURE__*/function () {

@@ -167,3 +150,2 @@ var _ref3 = _asyncToGenerator(function* (sentence) {

} = _ref4;
if (node.type === Syntax.Code) {

@@ -173,3 +155,2 @@ return maskValue("_");

}
});

@@ -182,3 +163,2 @@ var text = source.toString();

var surface = token.surface_form;
if (surface === touten) {

@@ -198,26 +178,22 @@ // 名詞に囲まわれている場合は例外とする

})
}); // strictなら例外を例外としない
});
// strictなら例外を例外としない
if (!isStrict && isSandwiched) {
return;
}
currentTenCount++;
lastToken = token;
}
if (separatorCharacters.includes(surface)) {
// reset
currentTenCount = 0;
} // report
}
// report
if (currentTenCount > maxLen) {
var positionInSentence = source.originalIndexFromIndex(lastToken.word_position - 1); // relative index from Paragraph Node
var positionInSentence = source.originalIndexFromIndex(lastToken.word_position - 1);
// relative index from Paragraph Node
// Sentence start(relative) + word position(relative)
var _index = sentence.range[0] - node.range[0] + positionInSentence;
var ruleError = new context.RuleError("\u4E00\u3064\u306E\u6587\u3067\"".concat(touten, "\"\u3092").concat(maxLen + 1, "\u3064\u4EE5\u4E0A\u4F7F\u7528\u3057\u3066\u3044\u307E\u3059"), {
index: _index
padding: locator.range([_index, _index + touten.length])
});

@@ -229,3 +205,2 @@ report(node, ruleError);

});
return function checkSentence(_x) {

@@ -235,8 +210,6 @@ return _ref3.apply(this, arguments);

}();
return Promise.all(sentences.map(checkSentence));
}
};
};
//# sourceMappingURL=max-ten.js.map

@@ -19,3 +19,3 @@ {

},
"version": "4.0.4",
"version": "5.0.0",
"description": "textlint rule that limit maxinum ten(、) count of sentence.",

@@ -35,15 +35,16 @@ "main": "lib/max-ten.js",

"test": "textlint-scripts test",
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
"prepare": "git config --local core.hooksPath .githooks"
"prepare": "git config --local core.hooksPath .githooks",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\""
},
"devDependencies": {
"lint-staged": "^10.5.4",
"prettier": "^2.2.1",
"textlint-scripts": "^3.0.0"
"@textlint/types": "^13.4.1",
"lint-staged": "^15.1.0",
"prettier": "^3.1.0",
"textlint-scripts": "^13.4.1"
},
"dependencies": {
"kuromojin": "^3.0.0",
"sentence-splitter": "^3.2.0",
"textlint-rule-helper": "^2.3.0",
"textlint-util-to-string": "^3.3.0"
"sentence-splitter": "^5.0.0",
"textlint-rule-helper": "^2.3.1",
"textlint-util-to-string": "^3.3.4"
},

@@ -50,0 +51,0 @@ "prettier": {

@@ -5,3 +5,3 @@ // LICENSE : MIT

import { tokenize } from "kuromojin";
import { splitAST, Syntax as SentenceSyntax } from "sentence-splitter";
import { splitAST, SentenceSplitterSyntax as SentenceSyntax } from "sentence-splitter";
import { StringSource } from "textlint-util-to-string";

@@ -70,4 +70,5 @@

/**
* @param {RuleContext} context
* @param {import("@textlint/types").TextlintRuleContext} context
* @param {typeof defaultOptions} [options]
* @return {import("@textlint/types").TextlintFilterRuleReportHandler}}
*/

@@ -80,3 +81,3 @@ module.exports = function (context, options = {}) {

const helper = new RuleHelper(context);
const { Syntax, RuleError, report, getSource } = context;
const { Syntax, RuleError, report, locator } = context;
const separatorCharacters = [

@@ -160,3 +161,3 @@ "?", // question mark

{
index
padding: locator.range([index, index + touten.length])
}

@@ -163,0 +164,0 @@ );

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc