@@ -8,20 +8,30 @@ const defaultOptions = {
88 // recognize lang of CodeBlock
99 "langs" : [ "js" , "javascript" , "node" , "jsx" ]
1010} ;
11+ const getConfigBaseDir = ( context ) => {
12+ if ( typeof context . getConfigBaseDir === "function" ) {
13+ return context . getConfigBaseDir ( ) ;
14+ }
15+ // Fallback that use deprecated `config` value
16+ // https://github.com/textlint/textlint/issues/294
17+ const textlintRcFilePath = context . config ? context . config . configFile : null ;
18+ // .textlinrc directory
19+ return textlintRcFilePath ? path . dirname ( textlintRcFilePath ) : process . cwd ( ) ;
20+ } ;
21+
1122const reporter = ( context , options ) => {
12- const { Syntax, RuleError, report, fixer, getSource} = context ;
23+ const { Syntax, RuleError, report, fixer, getSource } = context ;
1324 if ( ! options . configFile ) {
1425 throw new Error ( `Require options: { "configFile": "path/to/.eslintrc" }` ) ;
1526 }
1627 const availableLang = options . langs || defaultOptions . langs ;
17- const textlintRcFilePath = context . config ? context . config . configFile : null ;
18- const textlintRCDir = textlintRcFilePath ? path . dirname ( textlintRcFilePath ) : process . cwd ( ) ;
28+ const textlintRCDir = getConfigBaseDir ( context ) ;
1929 const ESLintOptions = {
2030 configFile : path . resolve ( textlintRCDir , options . configFile )
2131 } ;
2232 const engine = new CLIEngine ( ESLintOptions ) ;
2333 return {
24- [ Syntax . CodeBlock ] ( node ) {
34+ [ Syntax . CodeBlock ] ( node ) {
2535 if ( availableLang . indexOf ( node . lang ) === - 1 ) {
2636 return ;
2737 }
@@ -85,10 +95,10 @@ function getUntrimmedCode(node, raw) {
8595
8696 // https://github.com/wooorm/remark/issues/207#issuecomment-244620590
8797 const lines = raw . split ( "\n" ) ;
88-
98+
8999 // code lines without the first line and the last line
90100 const codeLines = lines . slice ( 1 , lines . length - 1 ) ;
91-
101+
92102 // add last new line
93103 // \n```
94104 return codeLines . join ( "\n" ) + "\n" ;
0 commit comments