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 Mar 29, 2015
1 parent 06927ee commit b50018d
Show file tree
Hide file tree
Showing 30 changed files with 440 additions and 11 deletions.
2 changes: 1 addition & 1 deletion conf/eslint.json
Expand Up @@ -136,7 +136,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"],
"padded-blocks": 0,
Expand Down
18 changes: 16 additions & 2 deletions lib/eslint.js
Expand Up @@ -18,7 +18,8 @@ var estraverse = require("estraverse-fb"),
timing = require("./timing"),
createTokenStore = require("./token-store.js"),
EventEmitter = require("events").EventEmitter,
escapeRegExp = require("escape-string-regexp");
escapeRegExp = require("escape-string-regexp"),
validate = require("./validate-options");

//------------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -632,9 +633,22 @@ module.exports = (function() {
var ruleCreator = rules.get(key),
severity = getRuleSeverity(config.rules[key]),
options = getRuleOptions(config.rules[key]),
rule;
rule, valid;

if (ruleCreator) {
if (ruleCreator.schema) {
valid = validate(key, ruleCreator.schema, options);
if (valid !== true) {
messages.push({
ruleId: key,
fatal: true,
severity: severity,
message: "Invalid configuration: " + JSON.stringify(options) + " " + valid[0].message
});
return messages;
}
}

try {
rule = ruleCreator(new RuleContext(
key, api, severity, options,
Expand Down
20 changes: 20 additions & 0 deletions lib/rules/brace-style.js
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
Expand Up @@ -92,3 +92,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
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
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
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
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
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
Expand Up @@ -218,3 +218,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
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
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
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
Expand Up @@ -70,3 +70,14 @@ module.exports = function(context) {
};

};

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

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "string",
"enum": ["smart-tabs", true, false]
}
],
"maxItems": 1
};
22 changes: 22 additions & 0 deletions lib/rules/no-multi-spaces.js
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
Expand Up @@ -170,3 +170,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
Expand Up @@ -65,3 +65,13 @@ module.exports = function(context) {
"ArrowFunctionExpression": findVariables
};
};

module.exports.schema = {
"type": "array",
"items": [
{
"enum": ["nofunc"]
}
],
"maxItems": 1
};
16 changes: 16 additions & 0 deletions lib/rules/quotes.js
Expand Up @@ -76,3 +76,19 @@ module.exports = function(context) {
};

};

module.exports.schema = {
"type": "array",
"items": [
{
"type": "string",
"enum": ["single", "double"]
},
{
"type": "string",
"enum": ["avoid-escape"]
}
],
"minItems": 1,
"maxItems": 2
};

0 comments on commit b50018d

Please sign in to comment.