Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(deps): update to sentence-spilitter@5 #28

Merged
merged 3 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10, 12, 14]
node-version: [ 18, 20 ]
steps:
- name: checkout
uses: actions/checkout@v2
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@
"watch": "textlint-scripts build --watch",
"prepublish": "npm run --if-present build",
"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"
},
"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
Loading