Skip to content

Commit 2f6a30e

Browse files
authored
refactor(deps): update to sentence-spilitter@5 (#28)
* refactor(deps): update to sentence-spilitter@5 **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 * CI: update node versions * Update package.json
1 parent 631db63 commit 2f6a30e

File tree

5 files changed

+2006
-3472
lines changed

5 files changed

+2006
-3472
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
node-version: [10, 12, 14]
11+
node-version: [ 18, 20 ]
1212
steps:
1313
- name: checkout
1414
uses: actions/checkout@v2

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,20 @@
3131
"watch": "textlint-scripts build --watch",
3232
"prepublish": "npm run --if-present build",
3333
"test": "textlint-scripts test",
34-
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
35-
"prepare": "git config --local core.hooksPath .githooks"
34+
"prepare": "git config --local core.hooksPath .githooks",
35+
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\""
3636
},
3737
"devDependencies": {
38-
"lint-staged": "^10.5.4",
39-
"prettier": "^2.2.1",
40-
"textlint-scripts": "^3.0.0"
38+
"@textlint/types": "^13.4.1",
39+
"lint-staged": "^15.1.0",
40+
"prettier": "^3.1.0",
41+
"textlint-scripts": "^13.4.1"
4142
},
4243
"dependencies": {
4344
"kuromojin": "^3.0.0",
44-
"sentence-splitter": "^3.2.0",
45-
"textlint-rule-helper": "^2.3.0",
46-
"textlint-util-to-string": "^3.3.0"
45+
"sentence-splitter": "^5.0.0",
46+
"textlint-rule-helper": "^2.3.1",
47+
"textlint-util-to-string": "^3.3.4"
4748
},
4849
"prettier": {
4950
"singleQuote": false,

src/max-ten.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"use strict";
33
import { RuleHelper } from "textlint-rule-helper";
44
import { tokenize } from "kuromojin";
5-
import { splitAST, Syntax as SentenceSyntax } from "sentence-splitter";
5+
import { splitAST, SentenceSplitterSyntax as SentenceSyntax } from "sentence-splitter";
66
import { StringSource } from "textlint-util-to-string";
77

88
const defaultOptions = {
@@ -66,16 +66,17 @@ function findSiblingMeaningToken({ tokens, currentIndex, direction }) {
6666
}
6767

6868
/**
69-
* @param {RuleContext} context
69+
* @param {import("@textlint/types").TextlintRuleContext} context
7070
* @param {typeof defaultOptions} [options]
71+
* @return {import("@textlint/types").TextlintFilterRuleReportHandler}}
7172
*/
7273
module.exports = function (context, options = {}) {
7374
const maxLen = options.max ?? defaultOptions.max;
7475
const isStrict = options.strict ?? defaultOptions.strict;
7576
const touten = options.touten ?? defaultOptions.touten;
7677
const kuten = options.kuten ?? defaultOptions.kuten;
7778
const helper = new RuleHelper(context);
78-
const { Syntax, RuleError, report, getSource } = context;
79+
const { Syntax, RuleError, report, locator } = context;
7980
const separatorCharacters = [
8081
"?", // question mark
8182
"!", // exclamation mark
@@ -154,7 +155,7 @@ module.exports = function (context, options = {}) {
154155
const ruleError = new context.RuleError(
155156
`一つの文で"${touten}"を${maxLen + 1}つ以上使用しています`,
156157
{
157-
index
158+
padding: locator.range([index, index + touten.length])
158159
}
159160
);
160161
report(node, ruleError);

test/max-ten-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ tester.run("max-ten", rule, {
134134
}
135135
]
136136
},
137+
{
138+
text: `複数のセンテンスがある場合。これでも、columnが、ちゃんと計算、されているはず、そのためのテキストです。`,
139+
// ^ 42
140+
options: {
141+
max: 3
142+
},
143+
errors: [
144+
{
145+
message: `一つの文で"、"を4つ以上使用しています`,
146+
range: [41, 42]
147+
}
148+
]
149+
},
137150
{
138151
text: `複数のセンテンスがあって、改行されている場合でも\n大丈夫です。これでも、lineとcolumnが、ちゃんと計算、されているはず、そのためのテキストです。`,
139152
options: {

0 commit comments

Comments
 (0)