Skip to content

Commit

Permalink
WIP: Validate rule options
Browse files Browse the repository at this point in the history
  • Loading branch information
btmills committed Apr 7, 2015
1 parent 9ecefa3 commit 212cff7
Show file tree
Hide file tree
Showing 31 changed files with 484 additions and 17 deletions.
2 changes: 1 addition & 1 deletion conf/eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
"max-statements": [0, 10],
"new-cap": 2,
"new-parens": 2,
"newline-after-var": 0,
"newline-after-var": 0,
"one-var": 0,
"operator-assignment": [0, "always"],
"operator-linebreak": 0,
Expand Down
22 changes: 15 additions & 7 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@
// Requirements
//------------------------------------------------------------------------------

var fs = require("fs"),
path = require("path"),
var assign = require("object-assign"),
debug = require("debug"),
environments = require("../conf/environments"),
util = require("./util"),
FileFinder = require("./file-finder"),
fs = require("fs"),
path = require("path"),
rules = require('./rules'),
stripComments = require("strip-json-comments"),
assign = require("object-assign"),
debug = require("debug"),
yaml = require("js-yaml"),
userHome = require("user-home");
userHome = require("user-home"),
util = require("./util"),
validate = require("./validate-options"),
yaml = require("js-yaml");

//------------------------------------------------------------------------------
// Constants
Expand Down Expand Up @@ -61,6 +63,12 @@ function loadConfig(filePath) {
}
}

if (config.rules) {
Object.keys(config.rules).forEach(function (name) {
validate(name, config.rules[name], filePath);
});
}

return config;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ module.exports = (function() {
var ruleCreator = rules.get(key),
severity = getRuleSeverity(config.rules[key]),
options = getRuleOptions(config.rules[key]),
rule;
rule, valid;

if (ruleCreator) {
try {
Expand Down
20 changes: 20 additions & 0 deletions lib/rules/brace-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,23 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "string",
"enum": ["1tbs", "stroustrup"]
},
{
"type": "object",
"properties": {
"allowSingleLine": {
"type": "boolean"
}
},
"additionalProperties": false
}
],
"maxItems": 2
};
17 changes: 17 additions & 0 deletions lib/rules/camelcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,20 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"properties": {
"type": "string",
"enum": ["always", "never"]
}
},
"additionalProperties": false
}
],
"maxItems": 1
};
11 changes: 11 additions & 0 deletions lib/rules/comma-dangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@ module.exports = function (context) {
"ArrayExpression": checkForTrailingComma
};
};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "string",
"enum": ["always", "always-multiline", "never"]
}
],
"maxItems": 1
};
19 changes: 19 additions & 0 deletions lib/rules/comma-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,22 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"before": {
"type": "boolean"
},
"after": {
"type": "boolean"
}
},
"additionalProperties": false
}
],
"maxItems": 1
};
11 changes: 11 additions & 0 deletions lib/rules/curly.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,14 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "string",
"enum": ["all", "multi", "multi-line"]
}
],
"maxItems": 1
};
19 changes: 19 additions & 0 deletions lib/rules/dot-notation.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,22 @@ module.exports = function(context) {
}
};
};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"allowKeywords": {
"type": "boolean"
},
"allowPattern": {
"type": "string"
}
},
"additionalProperties": false
}
],
"maxItems": 1
};
11 changes: 11 additions & 0 deletions lib/rules/eqeqeq.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,14 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "string",
"enum": ["smart", "allow-null"]
}
],
"maxItems": 1
};
23 changes: 23 additions & 0 deletions lib/rules/key-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,26 @@ module.exports = function(context) {
}

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"align": {
"type": "string",
"enum": ["colon", "value"]
},
"beforeColon": {
"type": "boolean"
},
"afterColon": {
"type": "boolean"
}
},
"additionalProperties": false
}
],
"maxItems": 1
};
16 changes: 16 additions & 0 deletions lib/rules/max-len.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,19 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "integer",
"minimum": 0
},
{
"type": "integer",
"minimum": 0
}
],
"minItems": 2,
"maxItems": 2
};
31 changes: 31 additions & 0 deletions lib/rules/new-cap.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,34 @@ module.exports = function(context) {

return listeners;
};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"newIsCap": {
"type": "boolean"
},
"capIsNew": {
"type": "boolean"
},
"newIsCapExceptions": {
"type": "array",
"items": {
"type": "string"
}
},
"capIsNewExceptions": {
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
}
],
"maxItems": 1
};
11 changes: 11 additions & 0 deletions lib/rules/no-cond-assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,14 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "string",
"enum": ["except-parens", "always"]
}
],
"maxItems": 1
};
11 changes: 11 additions & 0 deletions lib/rules/no-inner-declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,14 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "string",
"enum": ["functions", "both"]
}
],
"maxItems": 1
};
10 changes: 10 additions & 0 deletions lib/rules/no-mixed-spaces-and-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"enum": ["smart-tabs", true, false]
}
],
"maxItems": 1
};
22 changes: 22 additions & 0 deletions lib/rules/no-multi-spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,25 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"exceptions": {
"type": "object",
"patternProperties": {
"^([A-Z][a-z]*)+$": {
"type": "boolean"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"maxItems": 1
};
25 changes: 25 additions & 0 deletions lib/rules/no-unused-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,28 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"oneOf": [
{
"enum": ["all", "local"]
},
{
"type": "object",
"properties": {
"vars": {
"enum": ["all", "local"]
},
"args": {
"enum": ["all", "after-used", "none"]
}
}
}
]
}
],
"maxItems": 1
};
10 changes: 10 additions & 0 deletions lib/rules/no-use-before-define.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@ module.exports = function(context) {
"ArrowFunctionExpression": findVariables
};
};

module.exports.schema = {
"type": "array",
"items": [
{
"enum": ["nofunc"]
}
],
"maxItems": 1
};
Loading

0 comments on commit 212cff7

Please sign in to comment.