Skip to content

Commit c33e7f4

Browse files
committed
fix(rule): fix exception rule
1 parent b7e0786 commit c33e7f4

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/no-doubled-joshi.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ function createSurfaceKeyMap(tokens) {
2222
return keyMap;
2323
}, {});
2424
}
25-
function exceptionRule(token) {
25+
function matchExceptionRule(tokens) {
26+
let token = tokens[0];
2627
if (token.pos_detail_1 === "連体化") {
27-
return false;
28+
return true;
2829
}
2930
if (token.pos_detail_1 === "格助詞" && token.surface_form === "を") {
30-
return false;
31+
return true;
3132
}
32-
return true;
33+
return false;
3334
}
3435
const defaultOptions = {
3536
min_interval: 2,
@@ -56,10 +57,6 @@ export default function (context, options = {}) {
5657
let joshiTokens = tokens.filter(token => {
5758
return token.pos === "助詞";
5859
});
59-
// strict mode ではない時例外を除去する
60-
if (!isStrict) {
61-
joshiTokens = joshiTokens.filter(exceptionRule);
62-
}
6360
let joshiTokenSurfaceKeyMap = createSurfaceKeyMap(joshiTokens);
6461
/*
6562
# Data Structure
@@ -72,6 +69,12 @@ export default function (context, options = {}) {
7269
*/
7370
Object.keys(joshiTokenSurfaceKeyMap).forEach(key => {
7471
let tokens = joshiTokenSurfaceKeyMap[key];
72+
// strict mode ではない時例外を除去する
73+
if (!isStrict) {
74+
if(matchExceptionRule(tokens)) {
75+
return;
76+
}
77+
}
7578
if (tokens.length <= 1) {
7679
return;// no duplicated token
7780
}

test/no-doubled-joshi-test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ tester.run("no-double-joshi", rule, {
66
valid: [
77
"私は彼が好きだ",
88
"既存のコードの利用", // "の" の例外
9-
"オブジェクトを返す関数を公開した" // "を" の例外
9+
"オブジェクトを返す関数を公開した", // "を" の例外
10+
{
11+
text: "私は彼の鼻は好きだ",
12+
options: {
13+
"min_interval": 1
14+
}
15+
}
1016
],
1117
invalid: [
1218
{
@@ -87,8 +93,8 @@ tester.run("no-double-joshi", rule, {
8793
},
8894
{
8995
text: "既存のコードの利用",
90-
options:{
91-
strict :true
96+
options: {
97+
strict: true
9298
},
9399
errors: [
94100
{

0 commit comments

Comments
 (0)