Skip to content

Commit cce7649

Browse files
committed
chore(meta): add prettier
1 parent 2116502 commit cce7649

File tree

6 files changed

+631
-215
lines changed

6 files changed

+631
-215
lines changed

package.json

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
"build": "NODE_ENV=production babel src --out-dir lib --source-maps",
2626
"watch": "babel src --out-dir lib --watch --source-maps",
2727
"prepublish": "npm run --if-present build",
28-
"test": "mocha"
28+
"test": "mocha",
29+
"precommit": "lint-staged",
30+
"postcommit": "git reset",
31+
"prettier": "prettier --write '**/*.{js,jsx,ts,tsx,css}'"
2932
},
3033
"keywords": [
3134
"textlint",
@@ -42,12 +45,25 @@
4245
"babel-preset-jsdoc-to-assert": "^4.0.0",
4346
"babel-preset-power-assert": "^1.0.0",
4447
"babel-register": "^6.26.0",
48+
"husky": "^0.14.3",
49+
"lint-staged": "^4.2.3",
4550
"mocha": "^3.5.3",
4651
"power-assert": "^1.4.4",
52+
"prettier": "^1.7.0",
4753
"textlint": "^8.2.1",
4854
"textlint-tester": "^2.2.4"
4955
},
5056
"peerDependencies": {
5157
"textlint": ">= 5.5.0"
58+
},
59+
"prettier": {
60+
"printWidth": 120,
61+
"tabWidth": 4
62+
},
63+
"lint-staged": {
64+
"*.{js,jsx,ts,tsx,css}": [
65+
"prettier --write",
66+
"git add"
67+
]
5268
}
53-
}
69+
}

src/textlint-rule-prh.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { RuleHelper } from "textlint-rule-helper";
44

55
const prh = require("prh");
66
const path = require("path");
7-
const untildify = require('untildify');
7+
const untildify = require("untildify");
88

99
function createPrhEngine(rulePaths, baseDir) {
1010
if (rulePaths.length === 0) {
@@ -41,7 +41,7 @@ function mergePrh(...engines) {
4141
return mainEngine;
4242
}
4343

44-
const assertOptions = (options) => {
44+
const assertOptions = options => {
4545
if (typeof options.ruleContents === "undefined" && typeof options.rulePaths === "undefined") {
4646
throw new Error(`textlint-rule-prh require Rule Options.
4747
Please set .textlinrc:
@@ -75,7 +75,7 @@ const forEachChange = (changeSet, str, onChangeOfMatch) => {
7575
sortedDiffs.forEach(function(diff) {
7676
const result = diff.expected.replace(/\$([0-9]{1,2})/g, function(match, g1) {
7777
const index = parseInt(g1);
78-
if (index === 0 || (diff.matches.length - 1) < index) {
78+
if (index === 0 || diff.matches.length - 1 < index) {
7979
return match;
8080
}
8181
return diff.matches[index] || "";
@@ -96,7 +96,7 @@ const forEachChange = (changeSet, str, onChangeOfMatch) => {
9696
delta += result.length - diff.matches[0].length;
9797
});
9898
};
99-
const getConfigBaseDir = (context) => {
99+
const getConfigBaseDir = context => {
100100
if (typeof context.getConfigBaseDir === "function") {
101101
return context.getConfigBaseDir() || process.cwd();
102102
}
@@ -137,16 +137,19 @@ function reporter(context, options = {}) {
137137
}
138138

139139
const messages = actual + " => " + expected;
140-
report(node, new RuleError(messages, {
141-
index: matchStartIndex,
142-
fix: fixer.replaceTextRange([matchStartIndex, matchEndIndex], expected)
143-
}));
140+
report(
141+
node,
142+
new RuleError(messages, {
143+
index: matchStartIndex,
144+
fix: fixer.replaceTextRange([matchStartIndex, matchEndIndex], expected)
145+
})
146+
);
144147
});
145148
}
146-
}
149+
};
147150
}
148151

149152
module.exports = {
150153
linter: reporter,
151154
fixer: reporter
152-
};
155+
};

test/prh-rule-test.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,75 @@
11
// LICENSE : MIT
22
"use strict";
33
import assert from "power-assert";
4-
import {textlint} from "textlint";
4+
import { textlint } from "textlint";
55
import rule from "../src/textlint-rule-prh";
6-
describe("prh-rule-test", function () {
7-
beforeEach(function () {
8-
textlint.setupRules({
9-
"prh": rule
10-
}, {
11-
"prh": {
12-
"rulePaths": [__dirname + "/fixtures/rule.yaml"]
6+
describe("prh-rule-test", function() {
7+
beforeEach(function() {
8+
textlint.setupRules(
9+
{
10+
prh: rule
11+
},
12+
{
13+
prh: {
14+
rulePaths: [__dirname + "/fixtures/rule.yaml"]
15+
}
1316
}
14-
});
17+
);
1518
});
16-
afterEach(function () {
19+
afterEach(function() {
1720
textlint.resetRules();
1821
});
19-
context("when match word", function () {
20-
it("should report error", function () {
22+
context("when match word", function() {
23+
it("should report error", function() {
2124
return textlint.lintMarkdown("テストjquery").then(result => {
2225
assert(result.messages.length > 0);
2326
assert(result.messages[0].line === 1);
2427
assert(result.messages[0].column === 4);
2528
});
2629
});
2730
});
28-
context("when match word and s/) /)/ pattern", function () {
29-
it("should report error", function () {
31+
context("when match word and s/) /)/ pattern", function() {
32+
it("should report error", function() {
3033
return textlint.lintMarkdown("(図1) ").then(result => {
3134
assert(result.messages.length > 0);
3235
assert(result.messages[0].line === 1);
3336
assert(result.messages[0].column === 4);
3437
});
3538
});
3639
});
37-
context("when match word but s/Web/Web/i pattern", function () {
40+
context("when match word but s/Web/Web/i pattern", function() {
3841
// fix ignore (the) case
39-
it("should not report", function () {
42+
it("should not report", function() {
4043
return textlint.lintMarkdown("jQuery").then(result => {
4144
assert(result.messages.length === 0);
4245
});
4346
});
4447
});
45-
context("when match word and s/ベンダ/ベンダー/ pattern", function () {
48+
context("when match word and s/ベンダ/ベンダー/ pattern", function() {
4649
// expected word contain actual word.
4750
// s/ベンダ/ベンダー/ のようにexpectedがpatternを包含している場合のexpectedを除外
48-
it("should not report", function () {
51+
it("should not report", function() {
4952
return textlint.lintMarkdown("ベンダー").then(result => {
5053
assert(result.messages.length === 0);
5154
});
5255
});
5356
});
54-
context("when expected contain $1", function () {
57+
context("when expected contain $1", function() {
5558
// expected word contain actual word.
5659
// s/ベンダ/ベンダー/ のようにexpectedがpatternを包含している場合のexpectedを除外
57-
it("should convert expected", function () {
60+
it("should convert expected", function() {
5861
return textlint.lintMarkdown("広義のソフトウエアについて").then(result => {
5962
assert(result.messages.length > 0);
6063
var message = result.messages[0].message;
6164
assert.equal(message, "のソフトウエア => のソフトウェア");
6265
});
6366
});
6467
});
65-
context("when fixer", function () {
68+
context("when fixer", function() {
6669
// expected word contain actual word.
6770
// s/ベンダ/ベンダー/ のようにexpectedがpatternを包含している場合のexpectedを除外
68-
it("should convert expected", function () {
69-
return textlint.fixText("広義のソフトウエアについて", ".md").then(({output}) => {
71+
it("should convert expected", function() {
72+
return textlint.fixText("広義のソフトウエアについて", ".md").then(({ output }) => {
7073
assert.equal(output, "広義のソフトウェアについて");
7174
});
7275
});

0 commit comments

Comments
 (0)