Skip to content

Commit

Permalink
test: add test for quoted text and skipPatterns (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
azu authored Feb 23, 2023
1 parent a067ba8 commit cb99b2d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Add "sentence-length" to your `.textlintrc`.
}
```


### Options

- `max`
Expand Down Expand Up @@ -54,12 +53,44 @@ Uncount `(...)` from `A sentence(...).`
"skipPatterns": [
"/\\(.*\\)$\\./"
]
}
}
}
```

## A "Sentence"

This rule use [sentence-splitter](https://github.com/textlint-rule/sentence-splitter) as library.
So the definition of "Sentence" is the same as sentence-splitter.

For example, the following text is 3 sentences.

```
We are talking about pens.
He said "This is a pen. I like it".
I could relate to that statement.
```

![Example sentences](./sentence.png)

Second line includes `"..."`, but this rule treat second line as a single sentence.

If you want to ignore `"..."`, you can use `skipPatterns` option.

```
{
"rules": {
"sentence-length": {
"max": 100,
"skipPatterns": [
"/\".*?\"/"
]
}
}
}
```


## Exception

- Except BlockQuote
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"dependencies": {
"@textlint/regexp-string-matcher": "^2.0.2",
"sentence-splitter": "^4.1.0",
"sentence-splitter": "^4.2.0",
"textlint-rule-helper": "^2.3.0",
"textlint-util-to-string": "^3.3.2"
},
Expand Down
Binary file added sentence.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions test/sentence-length-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ tester.run("textlint-rule-sentence-length", rule, {
text: `JavaScriptをWasmにして実行する仕組みについて。
QuickJSを使いJavaScriptをByteCodeにしたxxxxを作成し、\`QuickJS.wasm\`と動的にリンクして大部分を共有している。
Shopify Functionで利用されるが、非同期処理の制限や5ms未満での実行制限がある。`
},
// https://github.com/textlint-rule/textlint-rule-sentence-length/issues/18
{
// length: 35
// skip "..." -> `He said .`
text: `He said "This is a pen. I like it".`,
options: {
max: 10,
skipPatterns: ['/".*"/']
}
}
],
invalid: [
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3299,10 +3299,10 @@ sentence-case@^1.1.2:
dependencies:
lower-case "^1.1.1"

sentence-splitter@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/sentence-splitter/-/sentence-splitter-4.1.0.tgz#01a8e3e3da9bc2510407ca4c5d64e80b65c6a90b"
integrity sha512-qVfKdRwlMUQqGpkqEDx6+NoFp9OmBzi/LjOm1hN2SDzAuD05WBxmb5z4etgv8pVgKqvsquBkf/iv+A0vhq9/Sw==
sentence-splitter@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/sentence-splitter/-/sentence-splitter-4.2.0.tgz#40a959de0b5b41ee769d9f211ebd99f54248e2a8"
integrity sha512-1Ww0iofAbR56tu6lVJ9Yh8Sj5ukeVjikBQ4sR5sNWM0kc+2AJe3p5F2o2qyuf5dJ4KVs1RbJpNkwEiMBCz7pKg==
dependencies:
"@textlint/ast-node-types" "^13.2.0"
structured-source "^4.0.0"
Expand Down

0 comments on commit cb99b2d

Please sign in to comment.