Skip to content

Commit

Permalink
Update: no-unsupported-features got grouping value of the `"ignore"…
Browse files Browse the repository at this point in the history
…` option (fixes #18)
  • Loading branch information
mysticatea committed Jan 21, 2016
1 parent b323378 commit 65b5e4e
Show file tree
Hide file tree
Showing 4 changed files with 563 additions and 422 deletions.
195 changes: 105 additions & 90 deletions docs/rules/no-unsupported-features.md
Expand Up @@ -105,96 +105,111 @@ This rule has `"ignores"` option to ignore to use the specified features.
Features which are specified by this `"ignores"` option are not warned.
This `"ignores"` option accepts an array of the following strings.

- `"defaultParameters"`
- `"restParameters"`
- `"spreadOperators"`
- `"objectLiteralExtensions"`
- `"forOf"`
- `"binaryNumberLiterals"`
- `"octalNumberLiterals"`
- `"templateStrings"`
- `"regexpY"`
- `"regexpU"`
- `"destructuring"`
- `"unicodeCodePointEscapes"`
- `"new.target"`
- `"const"`
- `"let"`
- `"blockScopedFunctions"`
- `"arrowFunctions"`
- `"generatorFunctions"`
- `"classes"`
- `"modules"`
- `"Object.assign"`
- `"Object.is"`
- `"Object.getOwnPropertySymbols"`
- `"Object.setPrototypeOf"`
- `"String.raw"`
- `"String.fromCodePoint"`
- `"Array.from"`
- `"Array.of"`
- `"Number.isFinite"`
- `"Number.isInteger"`
- `"Number.isSafeInteger"`
- `"Number.isNaN"`
- `"Number.EPSILON"`
- `"Number.MIN_SAFE_INTEGER"`
- `"Number.MAX_SAFE_INTEGER"`
- `"Math.clz32"`
- `"Math.imul"`
- `"Math.sign"`
- `"Math.log10"`
- `"Math.log2"`
- `"Math.log1p"`
- `"Math.expm1"`
- `"Math.cosh"`
- `"Math.sinh"`
- `"Math.tanh"`
- `"Math.acosh"`
- `"Math.asinh"`
- `"Math.atanh"`
- `"Math.trunc"`
- `"Math.fround"`
- `"Math.cbrt"`
- `"Math.hypot"`
- `"Int8Array"`
- `"Uint8Array"`
- `"Uint8ClampedArray"`
- `"Int16Array"`
- `"Uint16Array"`
- `"Int32Array"`
- `"Uint32Array"`
- `"Float32Array"`
- `"Float64Array"`
- `"DataView"`
- `"Map"`
- `"Set"`
- `"WeakMap"`
- `"WeakSet"`
- `"Proxy"`
- `"Reflect"`
- `"Promise"`
- `"Symbol"`
- `"Symbol.hasInstance"`
- `"Symbol.isConcatSpreadablec"`
- `"Symbol.iterator"`
- `"Symbol.species"`
- `"Symbol.replace"`
- `"Symbol.search"`
- `"Symbol.split"`
- `"Symbol.match"`
- `"Symbol.toPrimitive"`
- `"Symbol.toStringTag"`
- `"Symbol.unscopables"`
- `"extendsArray"`
- `"extendsRegExp"`
- `"extendsFunction"`
- `"extendsPromise"`
- `"extendsBoolean"`
- `"extendsNumber"`
- `"extendsString"`
- `"extendsMap"`
- `"extendsSet"`
- `"syntax"` (group)
- `"defaultParameters"`
- `"restParameters"`
- `"spreadOperators"`
- `"objectLiteralExtensions"`
- `"forOf"`
- `"binaryNumberLiterals"`
- `"octalNumberLiterals"`
- `"templateStrings"`
- `"regexpY"`
- `"regexpU"`
- `"destructuring"`
- `"unicodeCodePointEscapes"`
- `"new.target"`
- `"const"`
- `"let"`
- `"blockScopedFunctions"`
- `"arrowFunctions"`
- `"generatorFunctions"`
- `"classes"`
- `"modules"`
- `"runtime"` (group)
- `"globalObjects"` (group)
- `"typedArrays"` (group)
- `"Int8Array"`
- `"Uint8Array"`
- `"Uint8ClampedArray"`
- `"Int16Array"`
- `"Uint16Array"`
- `"Int32Array"`
- `"Uint32Array"`
- `"Float32Array"`
- `"Float64Array"`
- `"DataView"`
- `"Map"`
- `"Set"`
- `"WeakMap"`
- `"WeakSet"`
- `"Proxy"`
- `"Reflect"`
- `"Promise"`
- `"Symbol"`
- `"staticMethods"` (group)
- `"Object.*"` (group)
- `"Object.assign"`
- `"Object.is"`
- `"Object.getOwnPropertySymbols"`
- `"Object.setPrototypeOf"`
- `"String.*"` (group)
- `"String.raw"`
- `"String.fromCodePoint"`
- `"Array.*"` (group)
- `"Array.from"`
- `"Array.of"`
- `"Number.*"` (group)
- `"Number.isFinite"`
- `"Number.isInteger"`
- `"Number.isSafeInteger"`
- `"Number.isNaN"`
- `"Number.EPSILON"`
- `"Number.MIN_SAFE_INTEGER"`
- `"Number.MAX_SAFE_INTEGER"`
- `"Math.*"` (group)
- `"Math.clz32"`
- `"Math.imul"`
- `"Math.sign"`
- `"Math.log10"`
- `"Math.log2"`
- `"Math.log1p"`
- `"Math.expm1"`
- `"Math.cosh"`
- `"Math.sinh"`
- `"Math.tanh"`
- `"Math.acosh"`
- `"Math.asinh"`
- `"Math.atanh"`
- `"Math.trunc"`
- `"Math.fround"`
- `"Math.cbrt"`
- `"Math.hypot"`
- `"Symbol.*"` (group)
- `"Symbol.hasInstance"`
- `"Symbol.isConcatSpreadablec"`
- `"Symbol.iterator"`
- `"Symbol.species"`
- `"Symbol.replace"`
- `"Symbol.search"`
- `"Symbol.split"`
- `"Symbol.match"`
- `"Symbol.toPrimitive"`
- `"Symbol.toStringTag"`
- `"Symbol.unscopables"`
- `"extends"` (group)
- `"extendsArray"`
- `"extendsRegExp"`
- `"extendsFunction"`
- `"extendsPromise"`
- `"extendsBoolean"`
- `"extendsNumber"`
- `"extendsString"`
- `"extendsMap"`
- `"extendsSet"`

If a group value is given, all sub items of the value are ignored.
e.g. if `"String.*"` is given then `"String.raw"` and `"String.fromCodePoint"` are ignored.

The following patterns are considered not problems when it's using `"ignores"`:

Expand Down
38 changes: 36 additions & 2 deletions lib/rules/no-unsupported-features.js
Expand Up @@ -53,6 +53,40 @@ var PROPERTY_TEST_TARGETS = {
]
};

/**
* Gets values of the `ignores` option.
*
* @returns {string[]} Values of the `ignores` option.
*/
function getIgnoresEnum() {
return Object.keys(OPTIONS.reduce(
function(retv, key) {
features[key].alias.forEach(function(alias) {
retv[alias] = true;
});
retv[key] = true;
return retv;
},
Object.create(null)
));
}

/**
* Checks whether a given key should be ignored or not.
*
* @param {string} key - A key to check.
* @param {string[]} ignores - An array of keys and aliases to be ignored.
* @returns {boolean} `true` if the key should be ignored.
*/
function isIgnored(key, ignores) {
return (
ignores.indexOf(key) !== -1 ||
features[key].alias.some(function(alias) {
return ignores.indexOf(alias) !== -1;
})
);
}

/**
* Parses the options.
*
Expand All @@ -77,7 +111,7 @@ function parseOptions(options) {
function(retv, key) {
var feature = features[key];

if (ignores.indexOf(key) !== -1) {
if (isIgnored(key, ignores)) {
retv[key] = Object.freeze({
name: feature.name,
singular: Boolean(feature.singular),
Expand Down Expand Up @@ -467,7 +501,7 @@ module.exports.schema = [
},
ignores: {
type: "array",
items: {enum: OPTIONS},
items: {enum: getIgnoresEnum()},
uniqueItems: true
}
},
Expand Down

0 comments on commit 65b5e4e

Please sign in to comment.