Skip to content

fix(textlint): support config.getConfigBaseDir() #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
"textlint"
],
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-jsdoc-to-assert": "^2.0.1",
"babel-preset-jsdoc-to-assert": "^4.0.0",
"babel-preset-power-assert": "^1.0.0",
"babel-register": "^6.9.0",
"eslint": "^3.0.0",
"mocha": "^2.5.3",
"power-assert": "^1.4.1",
"textlint-tester": "^2.0.0"
"babel-register": "^6.26.0",
"eslint": "^4.7.2",
"mocha": "^3.5.3",
"power-assert": "^1.4.4",
"textlint-tester": "^2.2.4"
},
"peerDependencies": {
"eslint": "^3.0.0"
"eslint": "^3.0.0 || ^4.0.0"
}
}
22 changes: 16 additions & 6 deletions src/textlint-rule-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@ const defaultOptions = {
// recognize lang of CodeBlock
"langs": ["js", "javascript", "node", "jsx"]
};
const getConfigBaseDir = (context) => {
if (typeof context.getConfigBaseDir === "function") {
return context.getConfigBaseDir();
}
// Fallback that use deprecated `config` value
// https://github.com/textlint/textlint/issues/294
const textlintRcFilePath = context.config ? context.config.configFile : null;
// .textlinrc directory
return textlintRcFilePath ? path.dirname(textlintRcFilePath) : process.cwd();
};

const reporter = (context, options) => {
const {Syntax, RuleError, report, fixer, getSource} = context;
const { Syntax, RuleError, report, fixer, getSource } = context;
if (!options.configFile) {
throw new Error(`Require options: { "configFile": "path/to/.eslintrc" }`);
}
const availableLang = options.langs || defaultOptions.langs;
const textlintRcFilePath = context.config ? context.config.configFile : null;
const textlintRCDir = textlintRcFilePath ? path.dirname(textlintRcFilePath) : process.cwd();
const textlintRCDir = getConfigBaseDir(context);
const ESLintOptions = {
configFile: path.resolve(textlintRCDir, options.configFile)
};
const engine = new CLIEngine(ESLintOptions);
return {
[Syntax.CodeBlock](node){
[Syntax.CodeBlock](node) {
if (availableLang.indexOf(node.lang) === -1) {
return;
}
Expand Down Expand Up @@ -85,10 +95,10 @@ function getUntrimmedCode(node, raw) {

// https://github.com/wooorm/remark/issues/207#issuecomment-244620590
const lines = raw.split("\n");

// code lines without the first line and the last line
const codeLines = lines.slice(1, lines.length - 1);

// add last new line
// \n```
return codeLines.join("\n") + "\n";
Expand Down
Loading