Skip to content

Gd config updater #184

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
Feb 28, 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
2 changes: 1 addition & 1 deletion bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function analyzeFiles() {
if (validateConfig(options.configFile)) {
console.error("ESLint is running with the " + cli.getConfigForFile(null).parser + " parser.");

for (const line of ConfigUpgrader.upgradeInstructions(analysisFiles, process.cwd())) {
for (const line of ConfigUpgrader.upgradeInstructions(options.configFile, analysisFiles, process.cwd())) {
console.error(line);
}

Expand Down
25 changes: 18 additions & 7 deletions lib/config_upgrader.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,23 @@ class ConfigUpgrader {
return Array.from(configs);
}

static upgradeInstructions(analysisFiles, root) {
const reports = this.configs(analysisFiles).map(function(configFile) {
static upgradeInstructions(configFile, analysisFiles, root) {
let configs;
if (configFile) {
configs = [configFile];
}
else {
configs = this.configs(analysisFiles);
}

const reports = configs.map(function(configFile) {
let report = [];

const upgrader = new ConfigUpgrader();
const config = new Config({configFile: configFile});
const config = new Config({
configFile: configFile,
cwd: process.cwd()
});
upgrader.upgrade(config.useSpecificConfig);

if (path.extname(configFile) === '') {
Expand All @@ -269,11 +280,11 @@ class ConfigUpgrader {
return report;
});

if (reports.length > 0) {
return reports.reduce(function(a, b) { return a.concat([""]).concat(b); });
} else {
return reports;
if (reports.length === 0) {
reports.push([]);
}

return reports.reduce(function(a, b) { return a.concat([""]).concat(b); });
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/validate_config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
var CLIEngine = require("eslint").CLIEngine
, cli = new CLIEngine()
, fs = require("fs");

module.exports = function(configPath) {
if (configPath) {
return true;
} else {
var config = cli.getConfigForFile(null);
let cli = new CLIEngine();
let config = cli.getConfigForFile(null);

return Object.keys(config.rules).length > 0;
}
Expand Down
25 changes: 17 additions & 8 deletions test/config_upgrater_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("ConfigUpgrader", function() {


let report = ConfigUpgrader
.upgradeInstructions([directory + '/file.js'], directory);
.upgradeInstructions(null, [directory + '/file.js'], directory);
expect(report).to.deep.eq([
".eslintrc appears to be incompatible with ESLint 3.",
"To upgrade it do the following:\n",
Expand Down Expand Up @@ -47,7 +47,7 @@ describe("ConfigUpgrader", function() {
if (err) { throw err; }

let report = ConfigUpgrader
.upgradeInstructions([directory + '/file.js'], directory);
.upgradeInstructions(null, [directory + '/file.js'], directory);
expect(report).to.deep.eq([]);
done();
});
Expand All @@ -56,16 +56,25 @@ describe("ConfigUpgrader", function() {
});
});

it("doesn't care if there aren't any configs", function(done) {
temp.mkdir("code ", function(err, directory) {
it("uses specific configs", function(done) {
temp.mkdir("code", function(err, directory) {
if (err) { throw err; }

process.chdir(directory);

let report = ConfigUpgrader
.upgradeInstructions([directory + '/file.js'], directory);
expect(report).to.deep.eq([]);
done();
const configPath = path.join(directory, "codeclimate-eslint");
fs.writeFile(configPath, "{}", function(err) {
if (err) { throw err; }

let report = ConfigUpgrader
.upgradeInstructions("codeclimate-eslint", [directory + '/file.js'], directory);
expect(report).to.deep.eq([
"codeclimate-eslint appears to be incompatible with ESLint 3.",
"To upgrade it do the following:\n",
"* Add .yml or .json to the config file name. Extension-less config file names are deprecated."
]);
done();
});
});
});
});
Expand Down