Skip to content

Commit 2116502

Browse files
authored
fix(prh): Update [email protected] (#17)
1 parent fcc5ea2 commit 2116502

File tree

3 files changed

+247
-126
lines changed

3 files changed

+247
-126
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@
3232
"prh"
3333
],
3434
"dependencies": {
35-
"prh": "^3.0.1",
35+
"prh": "^5.4.3",
3636
"textlint-rule-helper": "^2.0.0",
3737
"untildify": "^3.0.2"
3838
},
3939
"devDependencies": {
40-
"babel-cli": "^6.7.5",
40+
"babel-cli": "^6.26.0",
4141
"babel-preset-es2015": "^6.6.0",
4242
"babel-preset-jsdoc-to-assert": "^4.0.0",
4343
"babel-preset-power-assert": "^1.0.0",
44-
"babel-register": "^6.7.2",
45-
"mocha": "^3.1.2",
46-
"power-assert": "^1.3.1",
47-
"textlint": "^8.0.0",
48-
"textlint-tester": "^2.0.0"
44+
"babel-register": "^6.26.0",
45+
"mocha": "^3.5.3",
46+
"power-assert": "^1.4.4",
47+
"textlint": "^8.2.1",
48+
"textlint-tester": "^2.2.4"
4949
},
5050
"peerDependencies": {
5151
"textlint": ">= 5.5.0"

src/textlint-rule-prh.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { RuleHelper } from "textlint-rule-helper";
55
const prh = require("prh");
66
const path = require("path");
77
const untildify = require('untildify');
8+
89
function createPrhEngine(rulePaths, baseDir) {
910
if (rulePaths.length === 0) {
1011
return null;
@@ -17,17 +18,20 @@ function createPrhEngine(rulePaths, baseDir) {
1718
});
1819
return prhEngine;
1920
}
21+
2022
function createPrhEngineFromContents(yamlContents) {
2123
if (yamlContents.length === 0) {
2224
return null;
2325
}
24-
const prhEngine = prh.fromYAML(null, yamlContents[0]);
26+
const dummyFilePath = "";
27+
const prhEngine = prh.fromYAML(dummyFilePath, yamlContents[0]);
2528
yamlContents.slice(1).forEach(content => {
26-
const config = prh.fromYAML(null, content);
29+
const config = prh.fromYAML(dummyFilePath, content);
2730
prhEngine.merge(config);
2831
});
2932
return prhEngine;
3033
}
34+
3135
function mergePrh(...engines) {
3236
const engines_ = engines.filter(engine => !!engine);
3337
const mainEngine = engines_[0];
@@ -36,6 +40,7 @@ function mergePrh(...engines) {
3640
});
3741
return mainEngine;
3842
}
43+
3944
const assertOptions = (options) => {
4045
if (typeof options.ruleContents === "undefined" && typeof options.rulePaths === "undefined") {
4146
throw new Error(`textlint-rule-prh require Rule Options.
@@ -101,6 +106,7 @@ const getConfigBaseDir = (context) => {
101106
// .textlinrc directory
102107
return textlintRcFilePath ? path.dirname(textlintRcFilePath) : process.cwd();
103108
};
109+
104110
function reporter(context, options = {}) {
105111
assertOptions(options);
106112
// .textlinrc directory
@@ -115,13 +121,15 @@ function reporter(context, options = {}) {
115121
const helper = new RuleHelper(context);
116122
const { Syntax, getSource, report, fixer, RuleError } = context;
117123
return {
118-
[Syntax.Str](node){
124+
[Syntax.Str](node) {
119125
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
120126
return;
121127
}
122128
const text = getSource(node);
123129
// to get position from index
124-
const makeChangeSet = prhEngine.makeChangeSet(null, text);
130+
// https://github.com/prh/prh/issues/29
131+
const dummyFilePath = "";
132+
const makeChangeSet = prhEngine.makeChangeSet(dummyFilePath, text);
125133
forEachChange(makeChangeSet, text, ({ matchStartIndex, matchEndIndex, actual, expected }) => {
126134
// If result is not changed, should not report
127135
if (actual === expected) {
@@ -137,6 +145,7 @@ function reporter(context, options = {}) {
137145
}
138146
}
139147
}
148+
140149
module.exports = {
141150
linter: reporter,
142151
fixer: reporter

0 commit comments

Comments
 (0)