@iceworks/doctor
Version:
Analyse and running codemods over react/rax projects, troubleshooting and automatically fixing errors
31 lines (30 loc) • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require("fs-extra");
var path_1 = require("path");
var parser_1 = require("@babel/parser");
var traverse_1 = require("@babel/traverse");
function getCustomESLintConfig(directory) {
var config = {};
var configFilePath = path_1.join(directory, '.eslintrc.js');
if (fs.existsSync(configFilePath)) {
var source_1 = fs.readFileSync(configFilePath, { encoding: 'utf-8' });
var ast = parser_1.parse(source_1, {
sourceType: 'module',
plugins: ['flow', 'exportDefaultFrom', 'exportNamespaceFrom'],
});
traverse_1.default(ast, {
CallExpression: function (nodePath) {
var node = nodePath.node;
if (node.callee.name === 'getESLintConfig' && node.arguments && node.arguments[1]) {
var configNode = node.arguments[1];
var configSource = source_1.substring(configNode.start, configNode.end);
// eslint-disable-next-line no-eval
config = eval("(" + configSource + ")");
}
},
});
}
return config;
}
exports.default = getCustomESLintConfig;