Skip to content

Commit

Permalink
refactor(deps): update to sentence-spilitter@5
Browse files Browse the repository at this point in the history
**BREAKING CHANGES**

- Require Node.js 18+

**Enhancement**

- improve error location using `locator.range()`

**Dependencies**

- update to sentence-spilitter@5
  - https://github.com/textlint-rule/sentence-splitter/releases/tag/v5.0.0
  • Loading branch information
azu committed Nov 26, 2023
1 parent 631db63 commit 676ff6d
Show file tree
Hide file tree
Showing 4 changed files with 2,003 additions and 3,469 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@
"prepare": "git config --local core.hooksPath .githooks"
},
"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"
},
"prettier": {
"singleQuote": false,
Expand Down
9 changes: 5 additions & 4 deletions src/max-ten.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"use strict";
import { RuleHelper } from "textlint-rule-helper";
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";

const defaultOptions = {
Expand Down Expand Up @@ -66,16 +66,17 @@ function findSiblingMeaningToken({ tokens, currentIndex, direction }) {
}

/**
* @param {RuleContext} context
* @param {import("@textlint/types").TextlintRuleContext} context
* @param {typeof defaultOptions} [options]
* @return {import("@textlint/types").TextlintFilterRuleReportHandler}}
*/
module.exports = function (context, options = {}) {
const maxLen = options.max ?? defaultOptions.max;
const isStrict = options.strict ?? defaultOptions.strict;
const touten = options.touten ?? defaultOptions.touten;
const kuten = options.kuten ?? defaultOptions.kuten;
const helper = new RuleHelper(context);
const { Syntax, RuleError, report, getSource } = context;
const { Syntax, RuleError, report, locator } = context;
const separatorCharacters = [
"?", // question mark
"!", // exclamation mark
Expand Down Expand Up @@ -154,7 +155,7 @@ module.exports = function (context, options = {}) {
const ruleError = new context.RuleError(
`一つの文で"${touten}"を${maxLen + 1}つ以上使用しています`,
{
index
padding: locator.range([index, index + touten.length])
}
);
report(node, ruleError);
Expand Down
13 changes: 13 additions & 0 deletions test/max-ten-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ tester.run("max-ten", rule, {
}
]
},
{
text: `複数のセンテンスがある場合。これでも、columnが、ちゃんと計算、されているはず、そのためのテキストです。`,
// ^ 42
options: {
max: 3
},
errors: [
{
message: `一つの文で"、"を4つ以上使用しています`,
range: [41, 42]
}
]
},
{
text: `複数のセンテンスがあって、改行されている場合でも\n大丈夫です。これでも、lineとcolumnが、ちゃんと計算、されているはず、そのためのテキストです。`,
options: {
Expand Down
Loading

0 comments on commit 676ff6d

Please sign in to comment.