Skip to content

Commit 058d116

Browse files
committed
refactor(rule): extract filter function
1 parent 943d94f commit 058d116

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/no-doubled-joshi.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ const defaultOptions = {
4242

4343

4444
/*
45-
1. Paragraph Node -> text
46-
2. text -> sentences
47-
3. tokenize sentence
48-
4. report error if found word that match the rule.
45+
1. Paragraph Node -> text
46+
2. text -> sentences
47+
3. tokenize sentence
48+
4. report error if found word that match the rule.
4949
50+
TODO: need abstraction
5051
*/
5152
export default function (context, options = {}) {
5253
const helper = new RuleHelper(context);
@@ -60,18 +61,20 @@ export default function (context, options = {}) {
6061
return;
6162
}
6263
const source = new StringSource(node);
63-
let text = source.toString();
64+
const text = source.toString();
65+
const isSentenceNode = node => {
66+
return node.type === SentenceSyntax.Sentence;
67+
};
6468
let sentences = splitSentences(text, {
6569
charRegExp: /[\?\!]/
66-
}).filter(node => {
67-
return node.type === SentenceSyntax.Sentence;
68-
});
70+
}).filter(isSentenceNode);
6971
return getTokenizer().then(tokenizer => {
7072
const checkSentence = (sentence) => {
7173
let tokens = tokenizer.tokenizeForSentence(sentence.raw);
72-
let joshiTokens = tokens.filter(token => {
74+
const isJoshiToken = token => {
7375
return token.pos === "助詞";
74-
});
76+
};
77+
let joshiTokens = tokens.filter(isJoshiToken);
7578
let joshiTokenSurfaceKeyMap = createSurfaceKeyMap(joshiTokens);
7679
/*
7780
# Data Structure

0 commit comments

Comments
 (0)