Skip to content

Commit

Permalink
chore(meta): add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Sep 27, 2017
1 parent 2116502 commit cce7649
Show file tree
Hide file tree
Showing 6 changed files with 631 additions and 215 deletions.
20 changes: 18 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
"build": "NODE_ENV=production babel src --out-dir lib --source-maps",
"watch": "babel src --out-dir lib --watch --source-maps",
"prepublish": "npm run --if-present build",
"test": "mocha"
"test": "mocha",
"precommit": "lint-staged",
"postcommit": "git reset",
"prettier": "prettier --write '**/*.{js,jsx,ts,tsx,css}'"
},
"keywords": [
"textlint",
Expand All @@ -42,12 +45,25 @@
"babel-preset-jsdoc-to-assert": "^4.0.0",
"babel-preset-power-assert": "^1.0.0",
"babel-register": "^6.26.0",
"husky": "^0.14.3",
"lint-staged": "^4.2.3",
"mocha": "^3.5.3",
"power-assert": "^1.4.4",
"prettier": "^1.7.0",
"textlint": "^8.2.1",
"textlint-tester": "^2.2.4"
},
"peerDependencies": {
"textlint": ">= 5.5.0"
},
"prettier": {
"printWidth": 120,
"tabWidth": 4
},
"lint-staged": {
"*.{js,jsx,ts,tsx,css}": [
"prettier --write",
"git add"
]
}
}
}
23 changes: 13 additions & 10 deletions src/textlint-rule-prh.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RuleHelper } from "textlint-rule-helper";

const prh = require("prh");
const path = require("path");
const untildify = require('untildify');
const untildify = require("untildify");

function createPrhEngine(rulePaths, baseDir) {
if (rulePaths.length === 0) {
Expand Down Expand Up @@ -41,7 +41,7 @@ function mergePrh(...engines) {
return mainEngine;
}

const assertOptions = (options) => {
const assertOptions = options => {
if (typeof options.ruleContents === "undefined" && typeof options.rulePaths === "undefined") {
throw new Error(`textlint-rule-prh require Rule Options.
Please set .textlinrc:
Expand Down Expand Up @@ -75,7 +75,7 @@ const forEachChange = (changeSet, str, onChangeOfMatch) => {
sortedDiffs.forEach(function(diff) {
const result = diff.expected.replace(/\$([0-9]{1,2})/g, function(match, g1) {
const index = parseInt(g1);
if (index === 0 || (diff.matches.length - 1) < index) {
if (index === 0 || diff.matches.length - 1 < index) {
return match;
}
return diff.matches[index] || "";
Expand All @@ -96,7 +96,7 @@ const forEachChange = (changeSet, str, onChangeOfMatch) => {
delta += result.length - diff.matches[0].length;
});
};
const getConfigBaseDir = (context) => {
const getConfigBaseDir = context => {
if (typeof context.getConfigBaseDir === "function") {
return context.getConfigBaseDir() || process.cwd();
}
Expand Down Expand Up @@ -137,16 +137,19 @@ function reporter(context, options = {}) {
}

const messages = actual + " => " + expected;
report(node, new RuleError(messages, {
index: matchStartIndex,
fix: fixer.replaceTextRange([matchStartIndex, matchEndIndex], expected)
}));
report(
node,
new RuleError(messages, {
index: matchStartIndex,
fix: fixer.replaceTextRange([matchStartIndex, matchEndIndex], expected)
})
);
});
}
}
};
}

module.exports = {
linter: reporter,
fixer: reporter
};
};
49 changes: 26 additions & 23 deletions test/prh-rule-test.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,75 @@
// LICENSE : MIT
"use strict";
import assert from "power-assert";
import {textlint} from "textlint";
import { textlint } from "textlint";
import rule from "../src/textlint-rule-prh";
describe("prh-rule-test", function () {
beforeEach(function () {
textlint.setupRules({
"prh": rule
}, {
"prh": {
"rulePaths": [__dirname + "/fixtures/rule.yaml"]
describe("prh-rule-test", function() {
beforeEach(function() {
textlint.setupRules(
{
prh: rule
},
{
prh: {
rulePaths: [__dirname + "/fixtures/rule.yaml"]
}
}
});
);
});
afterEach(function () {
afterEach(function() {
textlint.resetRules();
});
context("when match word", function () {
it("should report error", function () {
context("when match word", function() {
it("should report error", function() {
return textlint.lintMarkdown("テストjquery").then(result => {
assert(result.messages.length > 0);
assert(result.messages[0].line === 1);
assert(result.messages[0].column === 4);
});
});
});
context("when match word and s/) /)/ pattern", function () {
it("should report error", function () {
context("when match word and s/) /)/ pattern", function() {
it("should report error", function() {
return textlint.lintMarkdown("(図1) ").then(result => {
assert(result.messages.length > 0);
assert(result.messages[0].line === 1);
assert(result.messages[0].column === 4);
});
});
});
context("when match word but s/Web/Web/i pattern", function () {
context("when match word but s/Web/Web/i pattern", function() {
// fix ignore (the) case
it("should not report", function () {
it("should not report", function() {
return textlint.lintMarkdown("jQuery").then(result => {
assert(result.messages.length === 0);
});
});
});
context("when match word and s/ベンダ/ベンダー/ pattern", function () {
context("when match word and s/ベンダ/ベンダー/ pattern", function() {
// expected word contain actual word.
// s/ベンダ/ベンダー/ のようにexpectedがpatternを包含している場合のexpectedを除外
it("should not report", function () {
it("should not report", function() {
return textlint.lintMarkdown("ベンダー").then(result => {
assert(result.messages.length === 0);
});
});
});
context("when expected contain $1", function () {
context("when expected contain $1", function() {
// expected word contain actual word.
// s/ベンダ/ベンダー/ のようにexpectedがpatternを包含している場合のexpectedを除外
it("should convert expected", function () {
it("should convert expected", function() {
return textlint.lintMarkdown("広義のソフトウエアについて").then(result => {
assert(result.messages.length > 0);
var message = result.messages[0].message;
assert.equal(message, "のソフトウエア => のソフトウェア");
});
});
});
context("when fixer", function () {
context("when fixer", function() {
// expected word contain actual word.
// s/ベンダ/ベンダー/ のようにexpectedがpatternを包含している場合のexpectedを除外
it("should convert expected", function () {
return textlint.fixText("広義のソフトウエアについて", ".md").then(({output}) => {
it("should convert expected", function() {
return textlint.fixText("広義のソフトウエアについて", ".md").then(({ output }) => {
assert.equal(output, "広義のソフトウェアについて");
});
});
Expand Down
Loading

0 comments on commit cce7649

Please sign in to comment.