Skip to content

Commit

Permalink
enable eslint-plugin-unicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Mar 31, 2019
1 parent f14006d commit e3b99db
Show file tree
Hide file tree
Showing 101 changed files with 328 additions and 295 deletions.
35 changes: 35 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,36 @@ const base = {

// require strict mode directives
strict: ['error', 'global'],

// unicorn
// enforce a specific parameter name in catch clauses
'unicorn/catch-error-name': ['error', { name: 'error', caughtErrorsIgnorePattern: '^err' }],
// enforce passing a message value when throwing a built-in error
'unicorn/error-message': 'error',
// require escape sequences to use uppercase values
'unicorn/escape-case': 'error',
// enforce a case style for filenames
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
// enforce importing index files with `.`
'unicorn/import-index': 'error',
// enforce specifying rules to disable in eslint-disable comments
'unicorn/no-abusive-eslint-disable': 'error',
// do not use leading/trailing space between `console.log` parameters
'unicorn/no-console-spaces': 'error',
// enforce the use of unicode escapes instead of hexadecimal escapes
'unicorn/no-hex-escape': 'error',
// disallow unreadable array destructuring
'unicorn/no-unreadable-array-destructuring': 'error',
// disallow unsafe regular expressions
'unicorn/no-unsafe-regex': 'error',
// disallow unused object properties
'unicorn/no-unused-properties': 'error',
// enforce lowercase identifier and uppercase value for number literals
'unicorn/number-literal-case': 'error',
// prefer the exponentiation operator over `Math.pow()`
'unicorn/prefer-exponentiation-operator': 'error',
// enforce the use of regex shorthands to improve readability
'unicorn/regex-shorthand': 'error',
};

const es3 = {
Expand All @@ -333,6 +363,8 @@ const es3 = {
'quote-props': ['error', 'as-needed', { keywords: true }],
// require strict mode directives
strict: 'off',
// prefer the exponentiation operator over `Math.pow()`
'unicorn/prefer-exponentiation-operator': 'off',
};

const unit = {
Expand Down Expand Up @@ -360,6 +392,8 @@ const unit = {
'no-unused-expressions': 'off',
// disallow unnecessary calls to `.call()` and `.apply()`
'no-useless-call': 'off',
// enforce passing a message value when throwing a built-in error
'unicorn/error-message': 'off',

// qunit:
// ensure the correct number of assert arguments is used
Expand Down Expand Up @@ -427,6 +461,7 @@ module.exports = {
plugins: [
'import',
'qunit',
'unicorn',
],
settings: {
'import/resolver': {
Expand Down
5 changes: 3 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable unicorn/filename-case */
'use strict';
const { banner } = require('./packages/core-js-builder/config');

Expand Down Expand Up @@ -159,9 +160,9 @@ module.exports = grunt => {
const builder = require('./packages/core-js-builder');
const done = this.async();

builder({ filename: './packages/core-js-bundle/index.js' }).then(done).catch(it => {
builder({ filename: './packages/core-js-bundle/index.js' }).then(done).catch(error => {
// eslint-disable-next-line no-console
console.error(it);
console.error(error);
process.exit(1);
});
});
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"eslint-import-resolver-webpack": "^0.11.0",
"eslint-plugin-import": "~2.16.0",
"eslint-plugin-qunit": "^4.0.0",
"eslint-plugin-unicorn": "^8.0.1",
"grunt": "^1.0.4",
"grunt-cli": "^1.3.2",
"grunt-contrib-clean": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/es/number/max-safe-integer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require('../../modules/es.number.max-safe-integer');

module.exports = 0x1fffffffffffff;
module.exports = 0x1FFFFFFFFFFFFF;
2 changes: 1 addition & 1 deletion packages/core-js/es/number/min-safe-integer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require('../../modules/es.number.min-safe-integer');

module.exports = -0x1fffffffffffff;
module.exports = -0x1FFFFFFFFFFFFF;
2 changes: 1 addition & 1 deletion packages/core-js/features/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('../');
module.exports = require('..');
2 changes: 1 addition & 1 deletion packages/core-js/internals/array-buffer-view-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var exportStatic = function (KEY, property, forced) {
// V8 ~ Chrome 49-50 `%TypedArray%` methods are non-writable non-configurable
try {
return redefine(TypedArray, KEY, forced ? property : NATIVE_ARRAY_BUFFER_VIEWS && Int8Array[KEY] || property);
} catch (e) { /* empty */ }
} catch (error) { /* empty */ }
} else return;
}
for (ARRAY in TypedArrayConstructorsList) {
Expand Down
6 changes: 3 additions & 3 deletions packages/core-js/internals/array-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ var unpackInt32 = function (buffer) {
};

var packInt8 = function (number) {
return [number & 0xff];
return [number & 0xFF];
};

var packInt16 = function (number) {
return [number & 0xff, number >> 8 & 0xff];
return [number & 0xFF, number >> 8 & 0xFF];
};

var packInt32 = function (number) {
return [number & 0xff, number >> 8 & 0xff, number >> 16 & 0xff, number >> 24 & 0xff];
return [number & 0xFF, number >> 8 & 0xFF, number >> 16 & 0xFF, number >> 24 & 0xFF];
};

var packFloat32 = function (number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module.exports = function (iterator, fn, value, ENTRIES) {
try {
return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);
// 7.4.6 IteratorClose(iterator, completion)
} catch (e) {
} catch (error) {
var returnMethod = iterator['return'];
if (returnMethod !== undefined) anObject(returnMethod.call(iterator));
throw e;
throw error;
}
};
4 changes: 2 additions & 2 deletions packages/core-js/internals/check-correctness-of-iteration.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ try {
};
// eslint-disable-next-line no-throw-literal
Array.from(iteratorWithReturn, function () { throw 2; });
} catch (e) { /* empty */ }
} catch (error) { /* empty */ }

module.exports = function (exec, SKIP_CLOSING) {
if (!SKIP_CLOSING && !SAFE_CLOSING) return false;
Expand All @@ -31,6 +31,6 @@ module.exports = function (exec, SKIP_CLOSING) {
};
};
exec(object);
} catch (e) { /* empty */ }
} catch (error) { /* empty */ }
return ITERATION_SUPPORT;
};
2 changes: 1 addition & 1 deletion packages/core-js/internals/classof.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Argu
var tryGet = function (it, key) {
try {
return it[key];
} catch (e) { /* empty */ }
} catch (error) { /* empty */ }
};

// getting tag from ES6+ `Object.prototype.toString`
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/internals/fails.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function (exec) {
try {
return !!exec();
} catch (e) {
} catch (error) {
return true;
}
};
2 changes: 1 addition & 1 deletion packages/core-js/internals/flatten-into-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var flattenIntoArray = function (target, original, source, sourceLen, start, dep
if (depth > 0 && isArray(element)) {
targetIndex = flattenIntoArray(target, original, element, toLength(element.length), targetIndex, depth - 1) - 1;
} else {
if (targetIndex >= 0x1fffffffffffff) throw TypeError();
if (targetIndex >= 0x1FFFFFFFFFFFFF) throw TypeError('Exceed the acceptable array length');
target[targetIndex] = element;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/internals/forced-string-trim-method.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var fails = require('../internals/fails');
var whitespaces = require('../internals/whitespaces');
var non = '\u200b\u0085\u180e';
var non = '\u200B\u0085\u180E';

// check that a method works with the correct list
// of whitespaces and has a correct name
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/internals/microtask.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ if (!queueMicrotask) {
head = head.next;
try {
fn();
} catch (e) {
} catch (error) {
if (head) notify();
else last = undefined;
throw e;
throw error;
}
} last = undefined;
if (parent) parent.enter();
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/internals/object-define-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.f = DESCRIPTORS ? nativeDefineProperty : function defineProperty(O, P, A
anObject(Attributes);
if (IE8_DOM_DEFINE) try {
return nativeDefineProperty(O, P, Attributes);
} catch (e) { /* empty */ }
} catch (error) { /* empty */ }
if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
if ('value' in Attributes) O[P] = Attributes.value;
return O;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ exports.f = DESCRIPTORS ? nativeGetOwnPropertyDescriptor : function getOwnProper
P = toPrimitive(P, true);
if (IE8_DOM_DEFINE) try {
return nativeGetOwnPropertyDescriptor(O, P);
} catch (e) { /* empty */ }
} catch (error) { /* empty */ }
if (has(O, P)) return createPropertyDescriptor(!propertyIsEnumerableModule.f.call(O, P), O[P]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNa
var getWindowNames = function (it) {
try {
return nativeGetOwnPropertyNames(it);
} catch (e) {
} catch (error) {
return windowNames.slice();
}
};
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/internals/object-set-prototype-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
/* eslint-disable no-proto */
var validateSetPrototypeOfArguments = require('../internals/validate-set-prototype-of-arguments');

module.exports = Object.setPrototypeOf || ('__proto__' in {} ? function () { // eslint-disable-line
module.exports = Object.setPrototypeOf || ('__proto__' in {} ? function () {
var correctSetter = false;
var test = {};
var setter;
try {
setter = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
setter.call(test, []);
correctSetter = test instanceof Array;
} catch (e) { /* empty */ }
} catch (error) { /* empty */ }
return function setPrototypeOf(O, proto) {
validateSetPrototypeOfArguments(O, proto);
if (correctSetter) setter.call(O, proto);
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/internals/perform.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function (exec) {
try {
return { e: false, v: exec() };
} catch (e) {
return { e: true, v: e };
} catch (error) {
return { e: true, v: error };
}
};
6 changes: 3 additions & 3 deletions packages/core-js/internals/punycode-to-ascii.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ var damp = 700;
var initialBias = 72;
var initialN = 128; // 0x80
var delimiter = '-'; // '\x2D'
var regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
var regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
var regexNonASCII = /[^\0-\u007E]/; // non-ASCII chars
var regexSeparators = /[\u002E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
var OVERFLOW_ERROR = 'Overflow: input needs wider integers to process';
var baseMinusTMin = base - tMin;
var floor = Math.floor;
Expand Down Expand Up @@ -160,7 +160,7 @@ var encode = function (input) {

module.exports = function (input) {
var encoded = [];
var labels = input.toLowerCase().replace(regexSeparators, '\x2E').split('.');
var labels = input.toLowerCase().replace(regexSeparators, '\u002E').split('.');
var i, label;
for (i = 0; i < labels.length; i++) {
label = labels[i];
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/internals/set-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var hide = require('../internals/hide');
module.exports = function (key, value) {
try {
hide(global, key, value);
} catch (e) {
} catch (error) {
global[key] = value;
} return value;
};
4 changes: 2 additions & 2 deletions packages/core-js/internals/sloppy-array-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var fails = require('../internals/fails');
module.exports = function (METHOD_NAME, argument) {
var method = [][METHOD_NAME];
return !method || !fails(function () {
// eslint-disable-next-line no-useless-call
method.call(null, argument || function () { throw Error(); }, 1);
// eslint-disable-next-line no-useless-call,no-throw-literal
method.call(null, argument || function () { throw 1; }, 1);
});
};
6 changes: 3 additions & 3 deletions packages/core-js/internals/string-at.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module.exports = function (that, pos, CONVERT_TO_STRING) {
var first, second;
if (position < 0 || position >= size) return CONVERT_TO_STRING ? '' : undefined;
first = S.charCodeAt(position);
return first < 0xd800 || first > 0xdbff || position + 1 === size
|| (second = S.charCodeAt(position + 1)) < 0xdc00 || second > 0xdfff
return first < 0xD800 || first > 0xDBFF || position + 1 === size
|| (second = S.charCodeAt(position + 1)) < 0xDC00 || second > 0xDFFF
? CONVERT_TO_STRING ? S.charAt(position) : first
: CONVERT_TO_STRING ? S.slice(position, position + 2) : (first - 0xd800 << 10) + (second - 0xdc00) + 0x10000;
: CONVERT_TO_STRING ? S.slice(position, position + 2) : (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000;
};
2 changes: 1 addition & 1 deletion packages/core-js/internals/to-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ var min = Math.min;
// `ToLength` abstract operation
// https://tc39.github.io/ecma262/#sec-tolength
module.exports = function (argument) {
return argument > 0 ? min(toInteger(argument), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
return argument > 0 ? min(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
};
2 changes: 1 addition & 1 deletion packages/core-js/internals/typed-array-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ if (require('../internals/descriptors')) {

var setter = function (that, index, value) {
var data = getInternalState(that);
if (CLAMPED) value = (value = Math.round(value)) < 0 ? 0 : value > 0xff ? 0xff : value & 0xff;
if (CLAMPED) value = (value = Math.round(value)) < 0 ? 0 : value > 0xFF ? 0xFF : value & 0xFF;
data.view[SETTER](index * BYTES + data.byteOffset, value, true);
};

Expand Down
5 changes: 5 additions & 0 deletions packages/core-js/internals/webkit-string-pad-bug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// https://github.com/zloirock/core-js/issues/280
var userAgent = require('../internals/user-agent');

// eslint-disable-next-line unicorn/no-unsafe-regex
module.exports = /Version\/10\.\d+(\.\d+)?( Mobile\/\w+)? Safari\//.test(userAgent);
2 changes: 1 addition & 1 deletion packages/core-js/internals/whitespaces.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// a string of all valid unicode whitespaces
// eslint-disable-next-line max-len
module.exports = '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF';
module.exports = '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF';
2 changes: 1 addition & 1 deletion packages/core-js/modules/es.array.concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var toLength = require('../internals/to-length');
var createProperty = require('../internals/create-property');
var arraySpeciesCreate = require('../internals/array-species-create');
var IS_CONCAT_SPREADABLE = require('../internals/well-known-symbol')('isConcatSpreadable');
var MAX_SAFE_INTEGER = 0x1fffffffffffff;
var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF;
var MAXIMUM_ALLOWED_INDEX_EXCEEDED = 'Maximum allowed index exceeded';

var IS_CONCAT_SPREADABLE_SUPPORT = !require('../internals/fails')(function () {
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/modules/es.array.splice.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var arraySpeciesCreate = require('../internals/array-species-create');
var createProperty = require('../internals/create-property');
var max = Math.max;
var min = Math.min;
var MAX_SAFE_INTEGER = 0x1fffffffffffff;
var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF;
var MAXIMUM_ALLOWED_LENGTH_EXCEEDED = 'Maximum allowed length exceeded';

var SPECIES_SUPPORT = require('../internals/array-method-has-species-support')('splice');
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/modules/es.function.name.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if (DESCRIPTORS && !(NAME in FunctionPrototype)) {
get: function () {
try {
return FunctionPrototypeToString.call(this).match(nameRE)[1];
} catch (e) {
} catch (error) {
return '';
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/modules/es.math.imul.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var nativeImul = Math.imul;

var FORCED = require('../internals/fails')(function () {
return nativeImul(0xffffffff, 5) != -5 || nativeImul.length != 2;
return nativeImul(0xFFFFFFFF, 5) != -5 || nativeImul.length != 2;
});

// `Math.imul` method
// https://tc39.github.io/ecma262/#sec-math.imul
// some WebKit versions fails with big numbers, some has wrong arity
require('../internals/export')({ target: 'Math', stat: true, forced: FORCED }, {
imul: function imul(x, y) {
var UINT16 = 0xffff;
var UINT16 = 0xFFFF;
var xn = +x;
var yn = +y;
var xl = UINT16 & xn;
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/modules/es.number.is-safe-integer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ var abs = Math.abs;
// https://tc39.github.io/ecma262/#sec-number.issafeinteger
require('../internals/export')({ target: 'Number', stat: true }, {
isSafeInteger: function isSafeInteger(number) {
return isInteger(number) && abs(number) <= 0x1fffffffffffff;
return isInteger(number) && abs(number) <= 0x1FFFFFFFFFFFFF;
}
});
2 changes: 1 addition & 1 deletion packages/core-js/modules/es.number.max-safe-integer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// `Number.MAX_SAFE_INTEGER` constant
// https://tc39.github.io/ecma262/#sec-number.max_safe_integer
require('../internals/export')({ target: 'Number', stat: true }, { MAX_SAFE_INTEGER: 0x1fffffffffffff });
require('../internals/export')({ target: 'Number', stat: true }, { MAX_SAFE_INTEGER: 0x1FFFFFFFFFFFFF });
Loading

0 comments on commit e3b99db

Please sign in to comment.