Skip to content

allowオプション追加 #7

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

Merged
merged 2 commits into from
Sep 21, 2020
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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ textlint --rule ja-no-successive-word README.md
// 制限: オノマトペを判定する方法がないため、同じカタカナの語が連続したものをオノマトペとして扱う
// 例) カクカク、ドキドキ、ビリビリ
// https://ja.wikipedia.org/wiki/%E6%93%AC%E5%A3%B0%E8%AA%9E
allowOnomatopee: true
allowOnomatopee: true,

// 許可する単語
// RegExp-like Stringを使用可能
allow: []
}
}
}
Expand All @@ -68,6 +72,10 @@ textlint --rule ja-no-successive-word README.md
-`allowOnomatopee: boolean`
- Default: `true`
- **カクカク**などの[オノマトペ](https://ja.wikipedia.org/wiki/%E6%93%AC%E5%A3%B0%E8%AA%9E)を許可するかのオプションです。
- `allow`: `string[]`
- Default: `[]`
- 許可する単語を指定するオプションです。
- [RegExp-like String](https://github.com/textlint/textlint-filter-rule-allowlist#regexp-like-string)を使用できます。

## Changelog

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"textlint-scripts": "^3.0.0"
},
"dependencies": {
"@textlint/regexp-string-matcher": "^1.1.0",
"kuromojin": "^2.0.0"
}
}
11 changes: 10 additions & 1 deletion src/textlint-rule-ja-no-successive-word.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
// LICENSE : MIT
"use strict";
const matchPatterns = require("@textlint/regexp-string-matcher").matchPatterns;
const tokenize = require("kuromojin").tokenize;
const DefaultOptions = {
// オノマトペを許可する
// 制限: オノマトペを判定する方法がないため、同じカタカナの語が連続したものをオノマトペとして扱う
// 例) カクカク、ドキドキ、ビリビリ
// https://ja.wikipedia.org/wiki/%E6%93%AC%E5%A3%B0%E8%AA%9E
allowOnomatopee: true
allowOnomatopee: true,

// 許可する単語
// RegExp-like Stringを使用可能
allow: []
};

function isOnomatopee(str) {
Expand All @@ -16,6 +21,7 @@ function isOnomatopee(str) {
module.exports = function(context, options = {}) {
const allowOnomatopee = options.allowOnomatopee !== undefined ? options.allowOnomatopee
: DefaultOptions.allowOnomatopee;
const allow = options.allow || DefaultOptions.allow;
const { Syntax, RuleError, report, getSource } = context;
return {
[Syntax.Str](node) {
Expand All @@ -25,6 +31,9 @@ module.exports = function(context, options = {}) {
const reportIfMatch = (prevToken, nextToken) => {
const prevWord = prevToken.surface_form;
const currentWord = nextToken.surface_form;
if (0 < allow.length && 0 < matchPatterns(currentWord, allow).length) {
return;
}
if (prevWord !== currentWord) {
return;
}
Expand Down
24 changes: 23 additions & 1 deletion test/textlint-rule-ja-no-successive-word-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ tester.run("ja-no-successive-word", rule, {
"すもももももももものうち",
"111回目の問題",
"11,11回目の問題",
"フレームレートが落ちて動作がカクカクしてきた"
"フレームレートが落ちて動作がカクカクしてきた",
{
text: "_人人人人人人_",
options: {
allow: ["人人"]
}
}
],
invalid: [
// single match
Expand Down Expand Up @@ -53,6 +59,22 @@ tester.run("ja-no-successive-word", rule, {
column: 17
}
]
},
{
text: "_人人人人人人_",
errors: [
{
message: "\"人人\" が連続して2回使われています。",
line: 1,
column: 4
},
{
message: "\"人人\" が連続して2回使われています。",
line: 1,
column: 6
}

]
}
]
});
52 changes: 52 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,18 @@
resolved "https://registry.yarnpkg.com/@textlint/module-interop/-/module-interop-1.1.4.tgz#d8cb10e5bd1d4d31998c95fb0a52ad8100d6e18a"
integrity sha512-9M3kYG5nBoD2lhp05sqi6fieNU6rBcf+A8Trp+4d8o5uJ4RRsWeRtAQMWM7Tv15onqIITRq7fm3la7xovVB9KA==

"@textlint/regexp-string-matcher@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@textlint/regexp-string-matcher/-/regexp-string-matcher-1.1.0.tgz#e19975029ce228a214d50c6a7e9dbcbef29ad8cd"
integrity sha512-uTPnE1Dw1j+9clXPn61ZUdtg+WyhbgeXHwCTfBev7quHjeCP9PS8NdRkR6wEgmjuLg+xZlI4r/e1r6Bd0xyusQ==
dependencies:
escape-string-regexp "^1.0.5"
execall "^1.0.0"
lodash.sortby "^4.7.0"
lodash.uniq "^4.5.0"
lodash.uniqwith "^4.5.0"
to-regex "^3.0.2"

"@textlint/text-to-ast@^3.2.4":
version "3.2.4"
resolved "https://registry.yarnpkg.com/@textlint/text-to-ast/-/text-to-ast-3.2.4.tgz#a1ccb1ad2a561d93291c9f73d9c2376ddb701a5b"
Expand Down Expand Up @@ -1319,6 +1331,14 @@ cliui@^5.0.0:
strip-ansi "^5.2.0"
wrap-ansi "^5.1.0"

clone-regexp@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/clone-regexp/-/clone-regexp-1.0.1.tgz#051805cd33173375d82118fc0918606da39fd60f"
integrity sha512-Fcij9IwRW27XedRIJnSOEupS7RVcXtObJXbcUOX93UCLqqOdRpkvzKywOOSizmEK/Is3S/RHX9dLdfo6R1Q1mw==
dependencies:
is-regexp "^1.0.0"
is-supported-regexp-flag "^1.0.0"

co@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
Expand Down Expand Up @@ -1600,6 +1620,13 @@ events@^1.1.0:
resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924"
integrity sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=

execall@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/execall/-/execall-1.0.0.tgz#73d0904e395b3cab0658b08d09ec25307f29bb73"
integrity sha1-c9CQTjlbPKsGWLCNCewlMH8pu3M=
dependencies:
clone-regexp "^1.0.0"

expand-brackets@^2.1.4:
version "2.1.4"
resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-2.1.4.tgz#b77735e315ce30f6b6eff0f83b04151a22449622"
Expand Down Expand Up @@ -2122,6 +2149,16 @@ is-regex@^1.0.4, is-regex@^1.1.0:
dependencies:
has-symbols "^1.0.1"

is-regexp@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-regexp/-/is-regexp-1.0.0.tgz#fd2d883545c46bac5a633e7b9a09e87fa2cb5069"
integrity sha1-/S2INUXEa6xaYz57mgnof6LLUGk=

is-supported-regexp-flag@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/is-supported-regexp-flag/-/is-supported-regexp-flag-1.0.1.tgz#21ee16518d2c1dd3edd3e9a0d57e50207ac364ca"
integrity sha512-3vcJecUUrpgCqc/ca0aWeNu64UGgxcvO60K/Fkr1N6RSvfGCTU60UKN68JDmKokgba0rFFJs12EnzOQa14ubKQ==

is-symbol@^1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.3.tgz#38e1014b9e6329be0de9d24a414fd7441ec61937"
Expand Down Expand Up @@ -2323,6 +2360,21 @@ locate-path@^3.0.0:
p-locate "^3.0.0"
path-exists "^3.0.0"

lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=

lodash.uniq@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=

lodash.uniqwith@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.uniqwith/-/lodash.uniqwith-4.5.0.tgz#7a0cbf65f43b5928625a9d4d0dc54b18cadc7ef3"
integrity sha1-egy/ZfQ7WShiWp1NDcVLGMrcfvM=

lodash@^4.0.0, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19:
version "4.17.19"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b"
Expand Down