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

Commit baede85

Browse files
committed
Fix: Revert rule value deprecations (#2217)
- Not necessary to remove this now since we are merging with ESLint - it should allow users to not have to change their config when upgrading to 3.0.
1 parent b05dd8a commit baede85

15 files changed

+278
-68
lines changed

lib/rules/disallow-quoted-keys-in-objects.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* Values:
77
*
88
* - `true` for strict mode
9-
* - `Object`:
9+
* - `"allButReserved"` (*deprecated* use `"allExcept": ["reserved"]`)
10+
* - `Object`:
1011
* - `"allExcept"` array of exceptions:
1112
* - `"reserved"` allows ES3+ reserved words to remain quoted
1213
* which is helpful when using this option with JSHint's `es3` flag.
@@ -47,10 +48,11 @@ module.exports.prototype = {
4748

4849
configure: function(options) {
4950
assert(
50-
options === true || typeof options === 'object',
51+
options === true || options === 'allButReserved' || typeof options === 'object',
5152
this.getOptionName() + ' option requires a true value or an object'
5253
);
5354

55+
this._exceptReserved = options === 'allButReserved';
5456
if (Array.isArray(options.allExcept)) {
5557
this._exceptReserved = options.allExcept.indexOf('reserved') !== -1;
5658
}

lib/rules/disallow-space-after-object-keys.js

+35-17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
*
66
* Values:
77
* - `true`
8+
* - `"ignoreSingleLine"` ignores objects if the object only takes up a single line
9+
* (*deprecated* use `"allExcept": [ "singleline" ]`)
10+
* - `"ignoreMultiLine"` ignores objects if the object takes up multiple lines
11+
* (*deprecated* use `"allExcept": [ "multiline" ]`)
812
* - `Object`:
913
* - `"allExcept"`: array of exceptions:
1014
* - `"singleline"` ignores objects if the object only takes up a single line
@@ -77,33 +81,47 @@ module.exports.prototype = {
7781
configure: function(options) {
7882
if (typeof options !== 'object') {
7983
assert(
80-
options === true,
84+
options === true ||
85+
options === 'ignoreSingleLine' ||
86+
options === 'ignoreMultiLine',
8187
this.getOptionName() +
82-
' option requires a true value or an object'
88+
' option requires a true value, "ignoreSingleLine", "ignoreMultiLine", or an object'
8389
);
90+
91+
var _options = {
92+
allExcept: []
93+
};
94+
95+
if (options === 'ignoreSingleLine') {
96+
_options.allExcept.push('singleline');
97+
}
98+
if (options === 'ignoreMultiLine') {
99+
_options.allExcept.push('multiline');
100+
}
101+
102+
return this.configure(_options);
84103
} else {
85104
assert(
86105
Array.isArray(options.allExcept),
87106
this.getOptionName() +
88107
' option object requires allExcept array property'
89108
);
90-
91-
this._exceptSingleline = options.allExcept.indexOf('singleline') > -1;
92-
this._exceptMultiline = options.allExcept.indexOf('multiline') > -1;
93-
this._exceptAligned = options.allExcept.indexOf('aligned') > -1;
94-
this._exceptMethod = options.allExcept.indexOf('method') > -1;
95-
assert(
96-
!this._exceptMultiline || !this._exceptAligned,
97-
this.getOptionName() +
98-
' option allExcept property cannot contain `aligned` and `multiline` at the same time'
99-
);
100-
assert(
101-
!this._exceptMultiline || !this._exceptSingleline,
102-
this.getOptionName() +
103-
' option allExcept property cannot contain `singleline` and `multiline` at the same time'
104-
);
105109
}
106110

111+
this._exceptSingleline = options.allExcept.indexOf('singleline') > -1;
112+
this._exceptMultiline = options.allExcept.indexOf('multiline') > -1;
113+
this._exceptAligned = options.allExcept.indexOf('aligned') > -1;
114+
this._exceptMethod = options.allExcept.indexOf('method') > -1;
115+
assert(
116+
!this._exceptMultiline || !this._exceptAligned,
117+
this.getOptionName() +
118+
' option allExcept property cannot contain `aligned` and `multiline` at the same time'
119+
);
120+
assert(
121+
!this._exceptMultiline || !this._exceptSingleline,
122+
this.getOptionName() +
123+
' option allExcept property cannot contain `singleline` and `multiline` at the same time'
124+
);
107125
},
108126

109127
getOptionName: function() {

lib/rules/maximum-line-length.js

+14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* - `urlComments`: allows comments with long urls to break the rule
1515
* - `functionSignature`: allows function definitions to break the rule
1616
* - `require`: allows require expressions to break the rule
17+
* - `allowRegex`: *deprecated* use `allExcept: ["regex"]` instead
18+
* - `allowComments`: *deprecated* use `allExcept: ["comments"]` instead
19+
* - `allowUrlComments`: *deprecated* use `allExcept: ["urlComments"]` instead
1720
*
1821
* JSHint: [`maxlen`](http://jshint.com/docs/options/#maxlen)
1922
*
@@ -96,6 +99,17 @@ module.exports.prototype = {
9699
this._allowUrlComments = (exceptions.indexOf('urlComments') !== -1);
97100
this._allowFunctionSignature = (exceptions.indexOf('functionSignature') !== -1);
98101
this._allowRequire = (exceptions.indexOf('require') !== -1);
102+
103+
if (maximumLineLength.hasOwnProperty('allowRegex')) {
104+
this._allowRegex = (maximumLineLength.allowRegex === true);
105+
}
106+
if (maximumLineLength.hasOwnProperty('allowComments')) {
107+
this._allowComments = (maximumLineLength.allowComments === true);
108+
}
109+
if (maximumLineLength.hasOwnProperty('allowUrlComments')) {
110+
this._allowUrlComments = (maximumLineLength.allowUrlComments === true);
111+
}
112+
99113
} else {
100114
assert(
101115
typeof maximumLineLength === 'number',

lib/rules/require-camelcase-or-uppercase-identifiers.js

+44-37
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Values:
77
*
88
* - `true`
9+
* - `"ignoreProperties"` allows an exception for object property names. Deprecated, Please use the `Object` value
910
* - `Object`:
1011
* - `ignoreProperties`: boolean that allows an exception for object property names
1112
* - `strict`: boolean that forces the first character to not be capitalized
@@ -249,49 +250,55 @@ module.exports.prototype = {
249250
configure: function(options) {
250251
if (typeof options !== 'object') {
251252
assert(
252-
options === true,
253-
this.getOptionName() + ' option requires a true value or Object`'
253+
options === true || options === 'ignoreProperties',
254+
this.getOptionName() + ' option requires a true value or `ignoreProperties`'
254255
);
255-
} else {
256-
assert(
257-
!options.hasOwnProperty('ignoreProperties') || typeof options.ignoreProperties === 'boolean',
258-
this.getOptionName() + ' option should have boolean value for ignoreProperties'
259-
);
260-
this._ignoreProperties = options.ignoreProperties;
256+
var _options = {
257+
ignoreProperties: options === 'ignoreProperties' ? true : false,
258+
strict: false
259+
};
260+
return this.configure(_options);
261+
}
261262

262-
assert(
263-
!options.hasOwnProperty('strict') || typeof options.strict === 'boolean',
264-
this.getOptionName() + ' option should have boolean value for strict'
265-
);
266-
this._strict = options.strict;
263+
assert(
264+
!options.hasOwnProperty('ignoreProperties') || typeof options.ignoreProperties === 'boolean',
265+
this.getOptionName() + ' option should have boolean value for ignoreProperties'
266+
);
267+
this._ignoreProperties = options.ignoreProperties;
267268

268-
var asre = processArrayOfStringOrRegExp(options.allowedPrefixes);
269-
assert(
270-
!options.hasOwnProperty('allowedPrefixes') || asre,
271-
this.getOptionName() + ' option should have array of string or RegExp for allowedPrefixes'
272-
);
273-
if (asre) {
274-
this._allowedPrefixes = asre;
275-
}
269+
assert(
270+
!options.hasOwnProperty('strict') || typeof options.strict === 'boolean',
271+
this.getOptionName() + ' option should have boolean value for strict'
272+
);
273+
this._strict = options.strict;
276274

277-
asre = processArrayOfStringOrRegExp(options.allowedSuffixes);
278-
assert(
279-
!options.hasOwnProperty('allowedSuffixes') || asre,
280-
this.getOptionName() + ' option should have array of string or RegExp for allowedSuffixes'
281-
);
282-
if (asre) {
283-
this._allowedSuffixes = asre;
284-
}
275+
var asre = processArrayOfStringOrRegExp(options.allowedPrefixes);
276+
assert(
277+
!options.hasOwnProperty('allowedPrefixes') || asre,
278+
this.getOptionName() + ' option should have array of string or RegExp for allowedPrefixes'
279+
);
280+
if (asre) {
281+
this._allowedPrefixes = asre;
282+
}
285283

286-
asre = processArrayOfStringOrRegExp(options.allExcept);
287-
assert(
288-
!options.hasOwnProperty('allExcept') || asre,
289-
this.getOptionName() + ' option should have array of string or RegExp for allExcept'
290-
);
291-
if (asre) {
292-
this._allExcept = asre;
293-
}
284+
asre = processArrayOfStringOrRegExp(options.allowedSuffixes);
285+
assert(
286+
!options.hasOwnProperty('allowedSuffixes') || asre,
287+
this.getOptionName() + ' option should have array of string or RegExp for allowedSuffixes'
288+
);
289+
if (asre) {
290+
this._allowedSuffixes = asre;
291+
}
292+
293+
asre = processArrayOfStringOrRegExp(options.allExcept);
294+
assert(
295+
!options.hasOwnProperty('allExcept') || asre,
296+
this.getOptionName() + ' option should have array of string or RegExp for allExcept'
297+
);
298+
if (asre) {
299+
this._allExcept = asre;
294300
}
301+
295302
},
296303

297304
getOptionName: function() {

lib/rules/require-dot-notation.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
* Values:
77
* - `true`
8+
* - `"except_snake_case"` (*deprecated* use `"allExcept": ["snake_case"]`) allow quoted snake cased identifiers
89
* - `Object`:
910
* - `'allExcept'` array of exceptions:
1011
* - `'keywords'` allow quoted identifiers made of reserved words
@@ -108,19 +109,26 @@ module.exports.prototype = {
108109
configure: function(options) {
109110
if (typeof options !== 'object') {
110111
assert(
111-
options === true,
112+
options === true || options === 'except_snake_case',
112113
this.getOptionName() + ' option requires either a true value or an object'
113114
);
114-
} else {
115-
assert(
116-
!options.allExcept || Array.isArray(options.allExcept),
117-
'allExcept value of ' + this.getOptionName() + ' option requires an array with exceptions'
118-
);
119115

120-
if (Array.isArray(options.allExcept)) {
121-
this._exceptSnakeCase = options.allExcept.indexOf('snake_case') > -1;
122-
this._exceptKeywords = options.allExcept.indexOf('keywords') > -1;
116+
var _options = {};
117+
if (options === 'except_snake_case') {
118+
_options.allExcept = ['snake_case'];
123119
}
120+
121+
return this.configure(_options);
122+
}
123+
124+
assert(
125+
!options.allExcept || Array.isArray(options.allExcept),
126+
'allExcept value of ' + this.getOptionName() + ' option requires an array with exceptions'
127+
);
128+
129+
if (Array.isArray(options.allExcept)) {
130+
this._exceptSnakeCase = options.allExcept.indexOf('snake_case') > -1;
131+
this._exceptKeywords = options.allExcept.indexOf('keywords') > -1;
124132
}
125133
},
126134

lib/rules/require-space-after-line-comment.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
* Values:
77
* - `true`
8+
* - `"allowSlash"` (*deprecated* use `"allExcept": ["/"]`) allows `/// ` format
89
* - `Object`:
910
* - `allExcept`: array of allowed strings before space `//(here) `
1011
*
@@ -39,6 +40,7 @@ module.exports.prototype = {
3940
configure: function(options) {
4041
assert(
4142
options === true ||
43+
options === 'allowSlash' ||
4244
typeof options === 'object',
4345
this.getOptionName() + ' option requires a true value ' +
4446
'or an object with String[] `allExcept` property'
@@ -54,7 +56,9 @@ module.exports.prototype = {
5456

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

6064
getOptionName: function() {

lib/rules/validate-indentation.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* - `String`: `"\t"` for tab indentation
99
* - `Object`:
1010
* - `value`: (required) the same effect as the non-object values
11+
* - `includeEmptyLines` (*deprecated*): (default: `false`) require empty lines to be indented
1112
* - `'allExcept'` array of exceptions:
1213
* - `'comments'` ignores comments
1314
* - `'emptyLines'` ignore empty lines, included by default
@@ -301,6 +302,7 @@ module.exports.prototype = {
301302
this._exceptComments = false;
302303

303304
if (typeof options === 'object') {
305+
this._includeEmptyLines = (options.includeEmptyLines === true);
304306
if (Array.isArray(options.allExcept)) {
305307
this._exceptComments = options.allExcept.indexOf('comments') > -1;
306308
this._includeEmptyLines = options.allExcept.indexOf('emptyLines') === -1;

presets/grunt.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"preset": "google",
33
"maximumLineLength": 120,
4-
"requireCamelCaseOrUpperCaseIdentifiers": { "ignoreProperties": true },
4+
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
55
"validateQuoteMarks": { "mark": "'", "escape": true },
66
"disallowMultipleVarDecl": "exceptUndefined"
77
}

presets/wordpress.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
"requireCapitalizedComments": {
1919
"allExcept": ["global", "exported", "jshint", "eslint", "jslint"]
2020
},
21-
"requireCamelCaseOrUpperCaseIdentifiers": { "ignoreProperties": true },
21+
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
2222
"requireBlocksOnNewline": true
2323
}

test/specs/rules/disallow-space-after-object-keys.js

+16
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,22 @@ describe('rules/disallow-space-after-object-keys', function() {
190190
});
191191
});
192192

193+
describe('legacy options', function() {
194+
it('should accept ignoreSingleLine as an option', function() {
195+
checker.configure({disallowSpaceAfterObjectKeys: 'ignoreSingleLine'});
196+
expect(checker.checkString('var x = {a : 1, bcd : 2};')).to.have.no.errors();
197+
});
198+
199+
it('should accept ignoreMultiLine as an option', function() {
200+
checker.configure({disallowSpaceAfterObjectKeys: 'ignoreMultiLine'});
201+
expect(checker.checkString(
202+
'var x = {\n' +
203+
'a : 1,\n' +
204+
'};'
205+
)).to.have.no.errors();
206+
});
207+
});
208+
193209
it('should not report es5 getters/setters #1037', function() {
194210
checker.configure({ disallowSpaceAfterObjectKeys: true });
195211
expect(checker.checkString('var x = { get a() { } };')).to.have.no.errors();

0 commit comments

Comments
 (0)