Skip to content

Commit

Permalink
Update: remove invalid defaults from core rules (fixes #11415) (#11427)
Browse files Browse the repository at this point in the history
Ajv ignores the `default` property in JSON schemas when it appears inside `oneOf`, `anyOf`, or `not`. This commit removes ignored `default` properties and fixes a few bugs in rules that were incorrectly assuming the `default` properties would get processed.
  • Loading branch information
not-an-aardvark committed Feb 25, 2019
1 parent eb0650b commit de5cbc5
Show file tree
Hide file tree
Showing 36 changed files with 188 additions and 206 deletions.
6 changes: 2 additions & 4 deletions lib/rules/array-bracket-newline.js
Expand Up @@ -34,13 +34,11 @@ module.exports = {
type: "object",
properties: {
multiline: {
type: "boolean",
default: true
type: "boolean"
},
minItems: {
type: ["integer", "null"],
minimum: 0,
default: null
minimum: 0
}
},
additionalProperties: false
Expand Down
6 changes: 2 additions & 4 deletions lib/rules/array-element-newline.js
Expand Up @@ -34,13 +34,11 @@ module.exports = {
type: "object",
properties: {
multiline: {
type: "boolean",
default: false
type: "boolean"
},
minItems: {
type: ["integer", "null"],
minimum: 0,
default: null
minimum: 0
}
},
additionalProperties: false
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/arrow-body-style.js
Expand Up @@ -46,7 +46,7 @@ module.exports = {
{
type: "object",
properties: {
requireReturnForObjectLiteral: { type: "boolean", default: false }
requireReturnForObjectLiteral: { type: "boolean" }
},
additionalProperties: false
}
Expand Down
21 changes: 8 additions & 13 deletions lib/rules/capitalized-comments.js
Expand Up @@ -28,27 +28,22 @@ const SCHEMA_BODY = {
type: "object",
properties: {
ignorePattern: {
type: "string",
default: ""
type: "string"
},
ignoreInlineComments: {
type: "boolean",
default: false
type: "boolean"
},
ignoreConsecutiveComments: {
type: "boolean",
default: false
type: "boolean"
}
},
additionalProperties: false
};
const DEFAULTS = Object.keys(SCHEMA_BODY.properties).reduce(
(obj, current) => {
obj[current] = SCHEMA_BODY.properties[current].default;
return obj;
},
{}
);
const DEFAULTS = {
ignorePattern: "",
ignoreInlineComments: false,
ignoreConsecutiveComments: false
};

/**
* Get normalized options for either block or line comments from the given
Expand Down
11 changes: 6 additions & 5 deletions lib/rules/complexity.js
Expand Up @@ -41,13 +41,11 @@ module.exports = {
properties: {
maximum: {
type: "integer",
minimum: 0,
default: 20
minimum: 0
},
max: {
type: "integer",
minimum: 0,
default: 20
minimum: 0
}
},
additionalProperties: false
Expand All @@ -65,7 +63,10 @@ module.exports = {
const option = context.options[0];
let THRESHOLD = 20;

if (typeof option === "object") {
if (
typeof option === "object" &&
(Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
) {
THRESHOLD = option.maximum || option.max;
} else if (typeof option === "number") {
THRESHOLD = option;
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/eqeqeq.js
Expand Up @@ -38,8 +38,7 @@ module.exports = {
type: "object",
properties: {
null: {
enum: ["always", "never", "ignore"],
default: "always"
enum: ["always", "never", "ignore"]
}
},
additionalProperties: false
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/func-call-spacing.js
Expand Up @@ -50,8 +50,7 @@ module.exports = {
type: "object",
properties: {
allowNewlines: {
type: "boolean",
default: false
type: "boolean"
}
},
additionalProperties: false
Expand Down
3 changes: 1 addition & 2 deletions lib/rules/init-declarations.js
Expand Up @@ -75,8 +75,7 @@ module.exports = {
type: "object",
properties: {
ignoreForLoopInit: {
type: "boolean",
default: false
type: "boolean"
}
},
additionalProperties: false
Expand Down
81 changes: 27 additions & 54 deletions lib/rules/key-spacing.js
Expand Up @@ -148,37 +148,30 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"],
default: "strict"
enum: ["strict", "minimum"]
},
on: {
enum: ["colon", "value"],
default: "colon"
enum: ["colon", "value"]
},
beforeColon: {
type: "boolean",
default: false
type: "boolean"
},
afterColon: {
type: "boolean",
default: true
type: "boolean"
}
},
additionalProperties: false
}
]
},
mode: {
enum: ["strict", "minimum"],
default: "strict"
enum: ["strict", "minimum"]
},
beforeColon: {
type: "boolean",
default: false
type: "boolean"
},
afterColon: {
type: "boolean",
default: true
type: "boolean"
}
},
additionalProperties: false
Expand All @@ -190,16 +183,13 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"],
default: "strict"
enum: ["strict", "minimum"]
},
beforeColon: {
type: "boolean",
default: false
type: "boolean"
},
afterColon: {
type: "boolean",
default: true
type: "boolean"
}
},
additionalProperties: false
Expand All @@ -216,37 +206,30 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"],
default: "strict"
enum: ["strict", "minimum"]
},
on: {
enum: ["colon", "value"],
default: "colon"
enum: ["colon", "value"]
},
beforeColon: {
type: "boolean",
default: false
type: "boolean"
},
afterColon: {
type: "boolean",
default: true
type: "boolean"
}
},
additionalProperties: false
}
]
},
mode: {
enum: ["strict", "minimum"],
default: "strict"
enum: ["strict", "minimum"]
},
beforeColon: {
type: "boolean",
default: false
type: "boolean"
},
afterColon: {
type: "boolean",
default: true
type: "boolean"
}
},
additionalProperties: false
Expand All @@ -261,16 +244,13 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"],
default: "strict"
enum: ["strict", "minimum"]
},
beforeColon: {
type: "boolean",
default: false
type: "boolean"
},
afterColon: {
type: "boolean",
default: true
type: "boolean"
}
},
additionalProperties: false
Expand All @@ -279,16 +259,13 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"],
default: "strict"
enum: ["strict", "minimum"]
},
beforeColon: {
type: "boolean",
default: false
type: "boolean"
},
afterColon: {
type: "boolean",
default: true
type: "boolean"
}
},
additionalProperties: false
Expand All @@ -297,20 +274,16 @@ module.exports = {
type: "object",
properties: {
mode: {
enum: ["strict", "minimum"],
default: "strict"
enum: ["strict", "minimum"]
},
on: {
enum: ["colon", "value"],
default: "colon"
enum: ["colon", "value"]
},
beforeColon: {
type: "boolean",
default: false
type: "boolean"
},
afterColon: {
type: "boolean",
default: true
type: "boolean"
}
},
additionalProperties: false
Expand Down
8 changes: 3 additions & 5 deletions lib/rules/line-comment-position.js
Expand Up @@ -38,12 +38,10 @@ module.exports = {
type: "string"
},
applyDefaultPatterns: {
type: "boolean",
default: true
type: "boolean"
},
applyDefaultIgnorePatterns: {
type: "boolean",
default: true
type: "boolean"
}
},
additionalProperties: false
Expand Down Expand Up @@ -74,7 +72,7 @@ module.exports = {
if (Object.prototype.hasOwnProperty.call(options, "applyDefaultIgnorePatterns")) {
applyDefaultIgnorePatterns = options.applyDefaultIgnorePatterns;
} else {
applyDefaultIgnorePatterns = options.applyDefaultPatterns;
applyDefaultIgnorePatterns = options.applyDefaultPatterns !== false;
}
}

Expand Down
11 changes: 6 additions & 5 deletions lib/rules/max-depth.js
Expand Up @@ -32,13 +32,11 @@ module.exports = {
properties: {
maximum: {
type: "integer",
minimum: 0,
default: 4
minimum: 0
},
max: {
type: "integer",
minimum: 0,
default: 4
minimum: 0
}
},
additionalProperties: false
Expand All @@ -61,7 +59,10 @@ module.exports = {
option = context.options[0];
let maxDepth = 4;

if (typeof option === "object") {
if (
typeof option === "object" &&
(Object.prototype.hasOwnProperty.call(option, "maximum") || Object.prototype.hasOwnProperty.call(option, "max"))
) {
maxDepth = option.maximum || option.max;
}
if (typeof option === "number") {
Expand Down
11 changes: 4 additions & 7 deletions lib/rules/max-lines.js
Expand Up @@ -38,16 +38,13 @@ module.exports = {
properties: {
max: {
type: "integer",
minimum: 0,
default: 300
minimum: 0
},
skipComments: {
type: "boolean",
default: false
type: "boolean"
},
skipBlankLines: {
type: "boolean",
default: false
type: "boolean"
}
},
additionalProperties: false
Expand All @@ -64,7 +61,7 @@ module.exports = {
const option = context.options[0];
let max = 300;

if (typeof option === "object") {
if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max")) {
max = option.max;
} else if (typeof option === "number") {
max = option;
Expand Down

0 comments on commit de5cbc5

Please sign in to comment.