Skip to content

Commit

Permalink
WIP: Breaking: Default to --reset behavior (fixes #2100)
Browse files Browse the repository at this point in the history
  • Loading branch information
btmills committed Jul 10, 2015
1 parent ffbceec commit 68c4b3b
Show file tree
Hide file tree
Showing 21 changed files with 334 additions and 567 deletions.
15 changes: 15 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
root: true

env:
node: true

extends:
"./conf/eslint.json"

rules:
indent: 2
brace-style: [2, "1tbs"]
Expand All @@ -21,3 +26,13 @@ rules:
strict: [2, "global"]
valid-jsdoc: [2, { prefer: { "return": "returns"}}]
wrap-iife: 2

# Previously on by default in node environment
no-catch-shadow: 0
no-console: 0
no-mixed-requires: 2
no-new-require: 2
no-path-concat: 2
no-process-exit: 2
global-strict: [0, "always"]
handle-callback-err: [2, "err"]
85 changes: 19 additions & 66 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,7 @@ target.checkRuleFiles = function() {

echo("Validating rules");

var eslintConf = require("./conf/eslint.json");
var environmentsConf = require("./conf/environments");

var confRules = {};
confRules.default = eslintConf.rules;
Object.keys(environmentsConf).forEach(function (env) {
confRules[env] = environmentsConf[env].rules;
});
var eslintConf = require("./conf/eslint.json").rules;

var ruleFiles = find("lib/rules/").filter(fileType("js")),
rulesIndexText = cat("docs/rules/README.md"),
Expand All @@ -592,33 +585,25 @@ target.checkRuleFiles = function() {
indexLine = indexLine ? indexLine[0] : "";


function isInConfig(env) {
return confRules[env] && confRules[env].hasOwnProperty(basename);
function isInConfig() {
return eslintConf.hasOwnProperty(basename);
}

function isOffInConfig(env) {
var envRule = confRules[env][basename];
return envRule === 0 || (envRule && envRule[0] === 0);
function isOffInConfig() {
var rule = eslintConf[basename];
return rule === 0 || (rule && rule[0] === 0);
}

function isOnInConfig(env) {
return !isOffInConfig(env);
function isOnInConfig() {
return !isOffInConfig();
}

function isOffInIndex(env) {
if (env === "default") {
return indexLine.indexOf("(off by default)") !== -1;
} else {
return indexLine.indexOf("(off by default in the " + env + " environment)") !== -1;
}
function isNotRecommended() {
return indexLine.indexOf("(recommended)") === -1;
}

function isOnInIndex(env) {
if (env === "default") {
return indexLine.indexOf("(off by default)") === -1;
} else {
return indexLine.indexOf("(on by default in the " + env + " environment)") !== -1;
}
function isRecommended() {
return !isNotRecommended();
}

function hasIdInTitle(id) {
Expand Down Expand Up @@ -647,55 +632,23 @@ target.checkRuleFiles = function() {
}

// check for default configuration
if (!isInConfig("default")) {
if (!isInConfig()) {
console.error("Missing default setting for %s in eslint.json", basename);
errors++;
}

// check that rule is not on in docs but off in default config
if (isOnInIndex("default") && isOffInConfig("default")) {
console.error("Missing '(off by default)' for rule %s in index", basename);
// check that rule is not recommended in docs but off in default config
if (isRecommended() && isOffInConfig()) {
console.error("Rule documentation says that %s is recommended, but it is disabled in eslint.json.", basename);
errors++;
}

// check that rule is not off in docs but on in default config
if (isOffInIndex("default") && isOnInConfig("default")) {
console.error("Rule documentation says that %s is off by default but it is enabled in eslint.json.", basename);
// check that rule is not on in default config but not recommended
if (isOnInConfig("default") && isNotRecommended("default")) {
console.error("Missing '(recommended)' for rule %s in index", basename);
errors++;
}

// check rule config for each environment
Object.keys(confRules).forEach(function (env) {
if (env === "default") {
return;
}

// only check if rule has been explicitly set for environment
if (isInConfig(env)) {

// check that rule is not on in docs but off in environment config
if (isOnInIndex(env)) {
if (isOffInConfig(env)) {
console.error("Rule documentation says that %s is off in environment %s but it is enabled in eslint.json.", basename, env);
errors++;
}

// check that rule is not off in docs but on in default config
} else if (isOffInIndex(env)) {
if (isOnInConfig(env)) {
console.error("Rule documentation says that %s is on in environment %s but it is disabled in eslint.json.", basename, env);
errors++;
}

// rule has been overridden in environment but is not in docs
} else {
console.error("Missing '(%s by default in the %s environment)' for rule %s in index", isOnInConfig(env) ? "on" : "off", env, basename);
errors++;
}

}
});

// check for tests
if (!test("-f", "tests/lib/rules/" + basename + ".js")) {
console.error("Missing tests for rule %s", basename);
Expand Down
14 changes: 14 additions & 0 deletions ast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var espree = require('espree');
var fs = require('fs');
var inspect = require('util').inspect;
var ecmaFeatures = require('./config.json').ecmaFeatures;

var src = fs.readFileSync('test.js', 'utf-8');

try {
var ast = espree.parse(src, { ecmaFeatures: ecmaFeatures, range: true, tokens: true });

console.log(inspect(ast, { colors: true, depth: 99 }));
} catch (ex) {
console.error(ex.toString());
}
10 changes: 0 additions & 10 deletions conf/environments.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ module.exports = {
globals: globals.node,
ecmaFeatures: {
globalReturn: true
},
rules: {
"no-catch-shadow": 0,
"no-console": 0,
"no-mixed-requires": 2,
"no-new-require": 2,
"no-path-concat": 2,
"no-process-exit": 2,
"global-strict": [0, "always"],
"handle-callback-err": [2, "err"]
}
},
worker: {
Expand Down
9 changes: 0 additions & 9 deletions conf/eslint.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"ecmaFeatures": {},
"parser": "espree",
"env": {
"browser": false,
"node": false,
"amd": false,
"mocha": false,
"jasmine": false
},

"rules": {
"no-alert": 2,
"no-array-constructor": 2,
Expand Down
11 changes: 11 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"env": {
"es6": true
},
"rules": {
"one-var": [2, {
"uninitialized": "always",
"initialized": "never"
}]
}
}
1 change: 0 additions & 1 deletion docs/developer-guide/nodejs-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ The `CLIEngine` is a constructor, and you can create a new instance by passing i
* `globals` - An array of global variables to declare (default: empty array). Corresponds to `--global`.
* `ignore` - False disables use of `.eslintignore` (default: true). Corresponds to `--no-ignore`.
* `ignorePath` - The ignore file to use instead of `.eslintignore` (default: null). Corresponds to `--ignore-path`.
* `reset` - True disables all default rules and environments (default: false). Corresponds to `--reset`.
* `baseConfig` - Set to false to disable use of base config. Could be set to an object to override default base config as well.
* `rulePaths` - An array of directories to load custom rules from (default: empty array). Corresponds to `--rulesdir`.
* `rules` - An object of rules to use (default: null). Corresponds to `--rule`.
Expand Down
Loading

0 comments on commit 68c4b3b

Please sign in to comment.