-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from codeclimate/gd-no-config
Error if there is not a valid configuration file
- Loading branch information
Showing
5 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
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); | ||
|
||
return Object.keys(config.rules).length > 0; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
"rules": { | ||
"strict": 0 | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
var expect = require("chai").expect | ||
, fs = require("fs") | ||
, path = require("path") | ||
, temp = require('temp') | ||
, validateConfig = require("../lib/validate_config"); | ||
|
||
temp.track(); | ||
|
||
describe("validateConfig", function() { | ||
it("returns true if given a file", function() { | ||
expect(validateConfig("foo.config")).to.eq(true); | ||
}); | ||
|
||
it("returns false if no files exist", function(done) { | ||
temp.mkdir("no-config", function(err, directory) { | ||
if (err) throw err; | ||
|
||
process.chdir(directory); | ||
|
||
expect(validateConfig(null)).to.eq(false); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("returns true if an eslintrc exists", function(done) { | ||
temp.mkdir("config", function(err, directory) { | ||
if (err) throw err; | ||
|
||
process.chdir(directory); | ||
|
||
var configPath = path.join(directory, ".eslintrc.json"); | ||
var config = { | ||
rules: { | ||
strict: 0 | ||
} | ||
}; | ||
|
||
fs.writeFile(configPath, JSON.stringify(config), function(err) { | ||
if (err) throw err; | ||
|
||
expect(validateConfig(null)).to.eq(true); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |