Skip to content

Commit 6259e2c

Browse files
authored
Merge pull request #8 from azu/getConfigBaseDir
fix(textlint): support `config.getConfigBaseDir()`
2 parents 2420f7c + c009713 commit 6259e2c

File tree

3 files changed

+649
-414
lines changed

3 files changed

+649
-414
lines changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232
"textlint"
3333
],
3434
"devDependencies": {
35-
"babel-cli": "^6.10.1",
35+
"babel-cli": "^6.26.0",
3636
"babel-preset-es2015": "^6.9.0",
37-
"babel-preset-jsdoc-to-assert": "^2.0.1",
37+
"babel-preset-jsdoc-to-assert": "^4.0.0",
3838
"babel-preset-power-assert": "^1.0.0",
39-
"babel-register": "^6.9.0",
40-
"eslint": "^3.0.0",
41-
"mocha": "^2.5.3",
42-
"power-assert": "^1.4.1",
43-
"textlint-tester": "^2.0.0"
39+
"babel-register": "^6.26.0",
40+
"eslint": "^4.7.2",
41+
"mocha": "^3.5.3",
42+
"power-assert": "^1.4.4",
43+
"textlint-tester": "^2.2.4"
4444
},
4545
"peerDependencies": {
46-
"eslint": "^3.0.0"
46+
"eslint": "^3.0.0 || ^4.0.0"
4747
}
4848
}

src/textlint-rule-eslint.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1122
const 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

Comments
 (0)