Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Revert rule value deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo committed Apr 15, 2016
1 parent ca68499 commit 6b8e17e
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 68 deletions.
6 changes: 4 additions & 2 deletions lib/rules/disallow-quoted-keys-in-objects.js
Expand Up @@ -6,7 +6,8 @@
* Values:
*
* - `true` for strict mode
* - `Object`:
* - `"allButReserved"` (*deprecated* use `"allExcept": ["reserved"]`)
* - `Object`:
* - `"allExcept"` array of exceptions:
* - `"reserved"` allows ES3+ reserved words to remain quoted
* which is helpful when using this option with JSHint's `es3` flag.
Expand Down Expand Up @@ -47,10 +48,11 @@ module.exports.prototype = {

configure: function(options) {
assert(
options === true || typeof options === 'object',
options === true || options === 'allButReserved' || typeof options === 'object',
this.getOptionName() + ' option requires a true value or an object'
);

this._exceptReserved = options === 'allButReserved';
if (Array.isArray(options.allExcept)) {
this._exceptReserved = options.allExcept.indexOf('reserved') !== -1;
}
Expand Down
52 changes: 35 additions & 17 deletions lib/rules/disallow-space-after-object-keys.js
Expand Up @@ -5,6 +5,10 @@
*
* Values:
* - `true`
* - `"ignoreSingleLine"` ignores objects if the object only takes up a single line
* (*deprecated* use `"allExcept": [ "singleline" ]`)
* - `"ignoreMultiLine"` ignores objects if the object takes up multiple lines
* (*deprecated* use `"allExcept": [ "multiline" ]`)
* - `Object`:
* - `"allExcept"`: array of exceptions:
* - `"singleline"` ignores objects if the object only takes up a single line
Expand Down Expand Up @@ -77,33 +81,47 @@ module.exports.prototype = {
configure: function(options) {
if (typeof options !== 'object') {
assert(
options === true,
options === true ||
options === 'ignoreSingleLine' ||
options === 'ignoreMultiLine',
this.getOptionName() +
' option requires a true value or an object'
' option requires a true value, "ignoreSingleLine", "ignoreMultiLine", or an object'
);

var _options = {
allExcept: []
};

if (options === 'ignoreSingleLine') {
_options.allExcept.push('singleline');
}
if (options === 'ignoreMultiLine') {
_options.allExcept.push('multiline');
}

return this.configure(_options);
} else {
assert(
Array.isArray(options.allExcept),
this.getOptionName() +
' option object requires allExcept array property'
);

this._exceptSingleline = options.allExcept.indexOf('singleline') > -1;
this._exceptMultiline = options.allExcept.indexOf('multiline') > -1;
this._exceptAligned = options.allExcept.indexOf('aligned') > -1;
this._exceptMethod = options.allExcept.indexOf('method') > -1;
assert(
!this._exceptMultiline || !this._exceptAligned,
this.getOptionName() +
' option allExcept property cannot contain `aligned` and `multiline` at the same time'
);
assert(
!this._exceptMultiline || !this._exceptSingleline,
this.getOptionName() +
' option allExcept property cannot contain `singleline` and `multiline` at the same time'
);
}

this._exceptSingleline = options.allExcept.indexOf('singleline') > -1;
this._exceptMultiline = options.allExcept.indexOf('multiline') > -1;
this._exceptAligned = options.allExcept.indexOf('aligned') > -1;
this._exceptMethod = options.allExcept.indexOf('method') > -1;
assert(
!this._exceptMultiline || !this._exceptAligned,
this.getOptionName() +
' option allExcept property cannot contain `aligned` and `multiline` at the same time'
);
assert(
!this._exceptMultiline || !this._exceptSingleline,
this.getOptionName() +
' option allExcept property cannot contain `singleline` and `multiline` at the same time'
);
},

getOptionName: function() {
Expand Down
14 changes: 14 additions & 0 deletions lib/rules/maximum-line-length.js
Expand Up @@ -14,6 +14,9 @@
* - `urlComments`: allows comments with long urls to break the rule
* - `functionSignature`: allows function definitions to break the rule
* - `require`: allows require expressions to break the rule
* - `allowRegex`: *deprecated* use `allExcept: ["regex"]` instead
* - `allowComments`: *deprecated* use `allExcept: ["comments"]` instead
* - `allowUrlComments`: *deprecated* use `allExcept: ["urlComments"]` instead
*
* JSHint: [`maxlen`](http://jshint.com/docs/options/#maxlen)
*
Expand Down Expand Up @@ -96,6 +99,17 @@ module.exports.prototype = {
this._allowUrlComments = (exceptions.indexOf('urlComments') !== -1);
this._allowFunctionSignature = (exceptions.indexOf('functionSignature') !== -1);
this._allowRequire = (exceptions.indexOf('require') !== -1);

if (maximumLineLength.hasOwnProperty('allowRegex')) {
this._allowRegex = (maximumLineLength.allowRegex === true);
}
if (maximumLineLength.hasOwnProperty('allowComments')) {
this._allowComments = (maximumLineLength.allowComments === true);
}
if (maximumLineLength.hasOwnProperty('allowUrlComments')) {
this._allowUrlComments = (maximumLineLength.allowUrlComments === true);
}

} else {
assert(
typeof maximumLineLength === 'number',
Expand Down
81 changes: 44 additions & 37 deletions lib/rules/require-camelcase-or-uppercase-identifiers.js
Expand Up @@ -6,6 +6,7 @@
* Values:
*
* - `true`
* - `"ignoreProperties"` allows an exception for object property names. Deprecated, Please use the `Object` value
* - `Object`:
* - `ignoreProperties`: boolean that allows an exception for object property names
* - `strict`: boolean that forces the first character to not be capitalized
Expand Down Expand Up @@ -249,49 +250,55 @@ module.exports.prototype = {
configure: function(options) {
if (typeof options !== 'object') {
assert(
options === true,
this.getOptionName() + ' option requires a true value or Object`'
options === true || options === 'ignoreProperties',
this.getOptionName() + ' option requires a true value or `ignoreProperties`'
);
} else {
assert(
!options.hasOwnProperty('ignoreProperties') || typeof options.ignoreProperties === 'boolean',
this.getOptionName() + ' option should have boolean value for ignoreProperties'
);
this._ignoreProperties = options.ignoreProperties;
var _options = {
ignoreProperties: options === 'ignoreProperties' ? true : false,
strict: false
};
return this.configure(_options);
}

assert(
!options.hasOwnProperty('strict') || typeof options.strict === 'boolean',
this.getOptionName() + ' option should have boolean value for strict'
);
this._strict = options.strict;
assert(
!options.hasOwnProperty('ignoreProperties') || typeof options.ignoreProperties === 'boolean',
this.getOptionName() + ' option should have boolean value for ignoreProperties'
);
this._ignoreProperties = options.ignoreProperties;

var asre = processArrayOfStringOrRegExp(options.allowedPrefixes);
assert(
!options.hasOwnProperty('allowedPrefixes') || asre,
this.getOptionName() + ' option should have array of string or RegExp for allowedPrefixes'
);
if (asre) {
this._allowedPrefixes = asre;
}
assert(
!options.hasOwnProperty('strict') || typeof options.strict === 'boolean',
this.getOptionName() + ' option should have boolean value for strict'
);
this._strict = options.strict;

asre = processArrayOfStringOrRegExp(options.allowedSuffixes);
assert(
!options.hasOwnProperty('allowedSuffixes') || asre,
this.getOptionName() + ' option should have array of string or RegExp for allowedSuffixes'
);
if (asre) {
this._allowedSuffixes = asre;
}
var asre = processArrayOfStringOrRegExp(options.allowedPrefixes);
assert(
!options.hasOwnProperty('allowedPrefixes') || asre,
this.getOptionName() + ' option should have array of string or RegExp for allowedPrefixes'
);
if (asre) {
this._allowedPrefixes = asre;
}

asre = processArrayOfStringOrRegExp(options.allExcept);
assert(
!options.hasOwnProperty('allExcept') || asre,
this.getOptionName() + ' option should have array of string or RegExp for allExcept'
);
if (asre) {
this._allExcept = asre;
}
asre = processArrayOfStringOrRegExp(options.allowedSuffixes);
assert(
!options.hasOwnProperty('allowedSuffixes') || asre,
this.getOptionName() + ' option should have array of string or RegExp for allowedSuffixes'
);
if (asre) {
this._allowedSuffixes = asre;
}

asre = processArrayOfStringOrRegExp(options.allExcept);
assert(
!options.hasOwnProperty('allExcept') || asre,
this.getOptionName() + ' option should have array of string or RegExp for allExcept'
);
if (asre) {
this._allExcept = asre;
}

},

getOptionName: function() {
Expand Down
26 changes: 17 additions & 9 deletions lib/rules/require-dot-notation.js
Expand Up @@ -5,6 +5,7 @@
*
* Values:
* - `true`
* - `"except_snake_case"` (*deprecated* use `"allExcept": ["snake_case"]`) allow quoted snake cased identifiers
* - `Object`:
* - `'allExcept'` array of exceptions:
* - `'keywords'` allow quoted identifiers made of reserved words
Expand Down Expand Up @@ -108,19 +109,26 @@ module.exports.prototype = {
configure: function(options) {
if (typeof options !== 'object') {
assert(
options === true,
options === true || options === 'except_snake_case',
this.getOptionName() + ' option requires either a true value or an object'
);
} else {
assert(
!options.allExcept || Array.isArray(options.allExcept),
'allExcept value of ' + this.getOptionName() + ' option requires an array with exceptions'
);

if (Array.isArray(options.allExcept)) {
this._exceptSnakeCase = options.allExcept.indexOf('snake_case') > -1;
this._exceptKeywords = options.allExcept.indexOf('keywords') > -1;
var _options = {};
if (options === 'except_snake_case') {
_options.allExcept = ['snake_case'];
}

return this.configure(_options);
}

assert(
!options.allExcept || Array.isArray(options.allExcept),
'allExcept value of ' + this.getOptionName() + ' option requires an array with exceptions'
);

if (Array.isArray(options.allExcept)) {
this._exceptSnakeCase = options.allExcept.indexOf('snake_case') > -1;
this._exceptKeywords = options.allExcept.indexOf('keywords') > -1;
}
},

Expand Down
6 changes: 5 additions & 1 deletion lib/rules/require-space-after-line-comment.js
Expand Up @@ -5,6 +5,7 @@
*
* Values:
* - `true`
* - `"allowSlash"` (*deprecated* use `"allExcept": ["/"]`) allows `/// ` format
* - `Object`:
* - `allExcept`: array of allowed strings before space `//(here) `
*
Expand Down Expand Up @@ -39,6 +40,7 @@ module.exports.prototype = {
configure: function(options) {
assert(
options === true ||
options === 'allowSlash' ||
typeof options === 'object',
this.getOptionName() + ' option requires a true value ' +
'or an object with String[] `allExcept` property'
Expand All @@ -54,7 +56,9 @@ module.exports.prototype = {

// don't check triple slashed comments, microsoft js doc convention. see #593
// exceptions. see #592
this._allExcept = options.allExcept || [];
// need to drop allowSlash support in 2.0. Fixes #697
this._allExcept = options === 'allowSlash' ? ['/'] :
options.allExcept || [];
},

getOptionName: function() {
Expand Down
2 changes: 2 additions & 0 deletions lib/rules/validate-indentation.js
Expand Up @@ -8,6 +8,7 @@
* - `String`: `"\t"` for tab indentation
* - `Object`:
* - `value`: (required) the same effect as the non-object values
* - `includeEmptyLines` (*deprecated*): (default: `false`) require empty lines to be indented
* - `'allExcept'` array of exceptions:
* - `'comments'` ignores comments
* - `'emptyLines'` ignore empty lines, included by default
Expand Down Expand Up @@ -301,6 +302,7 @@ module.exports.prototype = {
this._exceptComments = false;

if (typeof options === 'object') {
this._includeEmptyLines = (options.includeEmptyLines === true);
if (Array.isArray(options.allExcept)) {
this._exceptComments = options.allExcept.indexOf('comments') > -1;
this._includeEmptyLines = options.allExcept.indexOf('emptyLines') === -1;
Expand Down
2 changes: 1 addition & 1 deletion presets/grunt.json
@@ -1,7 +1,7 @@
{
"preset": "google",
"maximumLineLength": 120,
"requireCamelCaseOrUpperCaseIdentifiers": { "ignoreProperties": true },
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
"validateQuoteMarks": { "mark": "'", "escape": true },
"disallowMultipleVarDecl": "exceptUndefined"
}
2 changes: 1 addition & 1 deletion presets/wordpress.json
Expand Up @@ -18,6 +18,6 @@
"requireCapitalizedComments": {
"allExcept": ["global", "exported", "jshint", "eslint", "jslint"]
},
"requireCamelCaseOrUpperCaseIdentifiers": { "ignoreProperties": true },
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
"requireBlocksOnNewline": true
}
16 changes: 16 additions & 0 deletions test/specs/rules/disallow-space-after-object-keys.js
Expand Up @@ -190,6 +190,22 @@ describe('rules/disallow-space-after-object-keys', function() {
});
});

describe('legacy options', function() {
it('should accept ignoreSingleLine as an option', function() {
checker.configure({disallowSpaceAfterObjectKeys: 'ignoreSingleLine'});
expect(checker.checkString('var x = {a : 1, bcd : 2};')).to.have.no.errors();
});

it('should accept ignoreMultiLine as an option', function() {
checker.configure({disallowSpaceAfterObjectKeys: 'ignoreMultiLine'});
expect(checker.checkString(
'var x = {\n' +
'a : 1,\n' +
'};'
)).to.have.no.errors();
});
});

it('should not report es5 getters/setters #1037', function() {
checker.configure({ disallowSpaceAfterObjectKeys: true });
expect(checker.checkString('var x = { get a() { } };')).to.have.no.errors();
Expand Down

0 comments on commit 6b8e17e

Please sign in to comment.