Skip to content

Commit

Permalink
Merge pull request #19 from 0x6b/update-analyze-dearu-desumasu
Browse files Browse the repository at this point in the history
Update analyze-dearu-desumasu to 4.0.0
  • Loading branch information
azu authored Sep 29, 2018
2 parents 316e83f + 7c8a518 commit 55041b3
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 37 deletions.
25 changes: 23 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"build": "textlint-scripts build",
"watch": "textlint-scripts build --watch",
"prepublish": "npm run --if-present build",
"test": "textlint-scripts test"
"test": "textlint-scripts test",
"prettier": "prettier --write \"{src,test}/*.{js,jsx,ts,tsx,css}\""
},
"keywords": [
"japanese",
Expand All @@ -34,11 +35,31 @@
"textlintrule"
],
"devDependencies": {
"husky": "^1.0.1",
"lint-staged": "^7.3.0",
"prettier": "^1.14.3",
"textlint-scripts": "^1.2.2"
},
"dependencies": {
"analyze-desumasu-dearu": "^3.1.0",
"analyze-desumasu-dearu": "^4.0.0",
"textlint-rule-helper": "^2.0.0",
"unist-util-visit": "^1.1.0"
},
"prettier": {
"singleQuote": false,
"printWidth": 120,
"tabWidth": 4
},
"lint-staged": {
"*.{js,jsx,ts,tsx,css}": [
"prettier --write",
"git add"
]
},
"husky": {
"hooks": {
"post-commit": "git reset",
"pre-commit": "lint-staged"
}
}
}
4 changes: 2 additions & 2 deletions src/BodyMixedChecker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// LICENSE : MIT
"use strict";
import MixedChecker from "./MixedChecker"
import MixedChecker from "./MixedChecker";
export default class BodyMixedChecker extends MixedChecker {
outputMessage(token) {
return "本文: " + super.outputMessage(token);
}
}
}
4 changes: 2 additions & 2 deletions src/HeaderMixedChecker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// LICENSE : MIT
"use strict";
import MixedChecker from "./MixedChecker"
import MixedChecker from "./MixedChecker";
export default class HeaderMixedChecker extends MixedChecker {
outputMessage(token) {
return "見出し: " + super.outputMessage(token);
}
}
}
4 changes: 2 additions & 2 deletions src/ListMixedChecker.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// LICENSE : MIT
"use strict";
import MixedChecker from "./MixedChecker"
import MixedChecker from "./MixedChecker";
export default class ListMixedChecker extends MixedChecker {
outputMessage(token) {
return "箇条書き: " + super.outputMessage(token);
}
}
}
11 changes: 4 additions & 7 deletions src/MixedChecker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// LICENSE : MIT
"use strict";
import {analyze, isDearu, isDesumasu} from "analyze-desumasu-dearu";
import { analyze, isDearu, isDesumasu } from "analyze-desumasu-dearu";
export default class MixedChecker {
/**
* @param context
Expand Down Expand Up @@ -62,10 +62,7 @@ export default class MixedChecker {
const overType = this.getOverType();
const overHitList = this.overHitList(overType);
// List
overHitList.forEach(({
node,
matches
}) => {
overHitList.forEach(({ node, matches }) => {
// Node
const lastHitNode = node;
// Tokens
Expand All @@ -78,7 +75,7 @@ export default class MixedChecker {
const ruleError = new RuleError(this.outputMessage(token), {
index: token.index
});
report(lastHitNode, ruleError)
report(lastHitNode, ruleError);
});
});
});
Expand All @@ -94,7 +91,7 @@ export default class MixedChecker {
*/
getOverType() {
if (this.options.preferDearu) {
return "である"
return "である";
} else if (this.options.preferDesumasu) {
return "ですます";
}
Expand Down
24 changes: 12 additions & 12 deletions src/no-mix-dearu-desumasu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// LICENSE : MIT
"use strict";
import {RuleHelper, IgnoreNodeManager} from "textlint-rule-helper";
import { RuleHelper, IgnoreNodeManager } from "textlint-rule-helper";
import BodyMixedChecker from "./BodyMixedChecker";
import HeaderMixedChecker from "./HeaderMixedChecker";
import ListMixedChecker from "./ListMixedChecker";
Expand All @@ -11,15 +11,15 @@ export const PreferTypes = {
// デフォルトでその項目で多く出現している方を優先します。
// 明示的にpreferの設定した場合は、そちらを優先した内容をエラーとして表示します。
const defaultOptions = {
"preferInHeader": "", // "である" or "ですます"
"preferInBody": "", // "である" or "ですます"
"preferInList": "", // "である" or "ですます"
preferInHeader: "", // "である" or "ですます"
preferInBody: "", // "である" or "ですます"
preferInList: "", // "である" or "ですます"
// 文末以外でも、敬体(ですます調)と常体(である調)を厳しくチェックするかどうか
"strict": false
strict: false
};

module.exports = function noMixedDearuDesumasu(context, options = defaultOptions) {
const {Syntax, getSource} = context;
const { Syntax, getSource } = context;
const helper = new RuleHelper(context);
const ignoreManager = new IgnoreNodeManager();
const isStrict = options.strict !== undefined ? options.strict : defaultOptions.strict;
Expand All @@ -40,17 +40,17 @@ module.exports = function noMixedDearuDesumasu(context, options = defaultOptions
});
return {
// 見出し
[Syntax.Header](node){
[Syntax.Header](node) {
const text = getSource(node);
headerChecker.check(node, text);
},
// 箇条書き
[Syntax.ListItem](node){
[Syntax.ListItem](node) {
const text = getSource(node);
listChecker.check(node, text);
},
// 本文
[Syntax.Paragraph](node){
[Syntax.Paragraph](node) {
const ignoredNodeTypes = [Syntax.Link, Syntax.Code, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis];
// 無視リストのTypeが親にある場合は無視する
if (helper.isChildNode(node, ignoredNodeTypes)) {
Expand All @@ -66,12 +66,12 @@ module.exports = function noMixedDearuDesumasu(context, options = defaultOptions
const text = getSource(node);
bodyChecker.check(node, text);
},
[Syntax.Document + ":exit"](){
[Syntax.Document + ":exit"]() {
return Promise.all([
bodyChecker.checkout(ignoreManager),
headerChecker.checkout(ignoreManager),
listChecker.checkout(ignoreManager)
]);
}
}
};
};
};
Loading

0 comments on commit 55041b3

Please sign in to comment.