@@ -5,6 +5,7 @@ import { RuleHelper } from "textlint-rule-helper";
55const prh = require ( "prh" ) ;
66const path = require ( "path" ) ;
77const untildify = require ( 'untildify' ) ;
8+
89function 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+
2022function 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+
3135function 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+
3944const 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+
104110function 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+
140149module . exports = {
141150 linter : reporter ,
142151 fixer : reporter
0 commit comments