Skip to content

Commit be97680

Browse files
committed
feat(rule): add ないと(は/も)かぎらない
close #1
1 parent 6931e4f commit be97680

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

src/no-doubled-negative-ja.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ import ないものではない from "./rules/naimonodeha-nai";
88
import ないことはない from "./rules/naikotoha-nai";
99
import ないわけではない from "./rules/naiwakedeha-nai";
1010
import ないとはいいきれない from "./rules/naitohaiikire-nai";
11+
import ないとはかぎらない from "./rules/naitohakagira-nai";
1112
export default function (context) {
1213
const {Syntax,getSource, report,RuleError} = context;
14+
// initialize each rules
1315
const ruleなくもない = なくはない(context);
1416
const ruleないでもない = ないでもない(context);
1517
const ruleないものではない = ないものではない(context);
1618
const ruleないことはない = ないことはない(context);
1719
const ruleないわけではない = ないわけではない(context);
1820
const ruleないとはいいきれない = ないとはいいきれない(context);
21+
const ruleないとはかぎらない = ないとはかぎらない(context);
1922
return {
2023
[Syntax.Str](node){
2124
const text = getSource(node);
@@ -35,6 +38,7 @@ export default function (context) {
3538
pushError(ruleないことはない(token));
3639
pushError(ruleないわけではない(token));
3740
pushError(ruleないとはいいきれない(token));
41+
pushError(ruleないとはかぎらない(token));
3842
});
3943
}).then(()=> {
4044
results.forEach(error => {

src/rules/naitohakagira-nai.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// LICENSE : MIT
2+
"use strict";
3+
/*
4+
(g) ないと(は/も)かぎらない
5+
*/
6+
import matchTokenStream from "./../matchTokenStream";
7+
export default function (context) {
8+
const {RuleError} = context;
9+
const matchPatternないとはかぎらない = matchTokenStream([
10+
{
11+
"basic_form": ["ない", "無い"]
12+
},
13+
{
14+
"surface_form": "と",
15+
"pos": "助詞"
16+
},
17+
{
18+
"surface_form": "は",
19+
"pos": "助詞"
20+
},
21+
{
22+
"reading": "カギラ",
23+
"pos": "動詞"
24+
},
25+
{
26+
"basic_form": ["ない", "無い"]
27+
}
28+
]);
29+
const matchPatternないともかぎらない = matchTokenStream([
30+
{
31+
"basic_form": ["ない", "無い"]
32+
},
33+
{
34+
"surface_form": "と",
35+
"pos": "助詞"
36+
},
37+
{
38+
"surface_form": "も",
39+
"pos": "助詞"
40+
},
41+
{
42+
"reading": "カギラ",
43+
"pos": "動詞"
44+
},
45+
{
46+
"basic_form": ["ない", "無い"],
47+
}
48+
]);
49+
return (token) => {
50+
if (matchPatternないとはかぎらない(token)) {
51+
return new RuleError("二重否定: 〜ないとはかぎらない", {
52+
column: token.word_position - 1
53+
});
54+
}
55+
if (matchPatternないともかぎらない(token)) {
56+
return new RuleError("二重否定: 〜ないともかぎらない", {
57+
column: token.word_position - 1
58+
});
59+
}
60+
};
61+
}

test/no-doubled-negative-ja-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,25 @@ tester.run("no-doubled-negative", rule, {
180180
column: 11
181181
}
182182
]
183+
},
184+
// g
185+
{
186+
text: "問題ないとは限らない",
187+
errors: [
188+
{
189+
message: "二重否定: 〜ないとはかぎらない",
190+
column: 9
191+
}
192+
]
193+
},
194+
{
195+
text: "問題ないとも限らない",
196+
errors: [
197+
{
198+
message: "二重否定: 〜ないともかぎらない",
199+
column: 9
200+
}
201+
]
183202
}
184203
]
185204
});

0 commit comments

Comments
 (0)