@@ -8,20 +8,30 @@ const defaultOptions = {
8
8
// recognize lang of CodeBlock
9
9
"langs" : [ "js" , "javascript" , "node" , "jsx" ]
10
10
} ;
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
+
11
22
const reporter = ( context , options ) => {
12
- const { Syntax, RuleError, report, fixer, getSource} = context ;
23
+ const { Syntax, RuleError, report, fixer, getSource } = context ;
13
24
if ( ! options . configFile ) {
14
25
throw new Error ( `Require options: { "configFile": "path/to/.eslintrc" }` ) ;
15
26
}
16
27
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 ) ;
19
29
const ESLintOptions = {
20
30
configFile : path . resolve ( textlintRCDir , options . configFile )
21
31
} ;
22
32
const engine = new CLIEngine ( ESLintOptions ) ;
23
33
return {
24
- [ Syntax . CodeBlock ] ( node ) {
34
+ [ Syntax . CodeBlock ] ( node ) {
25
35
if ( availableLang . indexOf ( node . lang ) === - 1 ) {
26
36
return ;
27
37
}
@@ -85,10 +95,10 @@ function getUntrimmedCode(node, raw) {
85
95
86
96
// https://github.com/wooorm/remark/issues/207#issuecomment-244620590
87
97
const lines = raw . split ( "\n" ) ;
88
-
98
+
89
99
// code lines without the first line and the last line
90
100
const codeLines = lines . slice ( 1 , lines . length - 1 ) ;
91
-
101
+
92
102
// add last new line
93
103
// \n```
94
104
return codeLines . join ( "\n" ) + "\n" ;
0 commit comments