Skip to content

Commit

Permalink
chore(npm): add husky, lint-staged, and prettier
Browse files Browse the repository at this point in the history
Before contributing added house-keeping devDependencies.
  • Loading branch information
0x6b committed Sep 29, 2018
1 parent 316e83f commit db28871
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 37 deletions.
23 changes: 22 additions & 1 deletion 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",
"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)
]);
}
}
};
};
};
21 changes: 10 additions & 11 deletions test/no-mix-dearu-desumasu-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import rule from "../src/no-mix-dearu-desumasu"
import rule from "../src/no-mix-dearu-desumasu";
import TextLintTester from "textlint-tester";
var tester = new TextLintTester();
// ruleName, rule, expected[]
Expand Down Expand Up @@ -64,7 +64,6 @@ CはDです。`,
[今日はいい天気である。](http://example.com)
`
}

],
invalid: [
// 本文での混在
Expand Down Expand Up @@ -116,7 +115,6 @@ Total:
line: 5,
column: 8
}

]
},
// 見出し間での混在
Expand Down Expand Up @@ -212,18 +210,19 @@ Total:
options: {
strict: true
},
errors: [[
{
message: `本文: "である"調 と "ですます"調 が混在
errors: [
[
{
message: `本文: "である"調 と "ですます"調 が混在
=> "である。" がである調
Total:
である : 1
ですます: 1
`,
line: 1,
column: 18
}
]
line: 1,
column: 18
}
]
]
},
{
Expand Down Expand Up @@ -271,4 +270,4 @@ Total:
]
}
]
});
});

0 comments on commit db28871

Please sign in to comment.