Skip to content

Commit

Permalink
review eslint core rules: enable some rules for preferring literals
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Aug 18, 2023
1 parent 7e3f3c4 commit 505f464
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tests/compat/tests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
/* eslint-disable radix, regexp/no-empty-capturing-group, regexp/no-lazy-ends, regexp/no-useless-quantifier -- required for testing */
/* eslint-disable prefer-regex-literals, radix -- required for testing */
/* eslint-disable regexp/no-empty-capturing-group, regexp/no-lazy-ends, regexp/no-useless-quantifier -- required for testing */
var GLOBAL = typeof global != 'undefined' ? global : Function('return this')();
var WHITESPACES = '\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';
Expand Down
6 changes: 6 additions & 0 deletions tests/eslint/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ const base = {
'no-new': ERROR,
// disallow use of new operator for Function object
'no-new-func': ERROR,
// disallow Object constructors
'no-new-object': ERROR,
// disallows creating new instances of String, Number, and Boolean
'no-new-wrappers': ERROR,
// disallow `\8` and `\9` escape sequences in string literals
Expand Down Expand Up @@ -262,8 +264,12 @@ const base = {
'prefer-destructuring': ERROR,
// prefer the exponentiation operator over `Math.pow()`
'prefer-exponentiation-operator': ERROR,
// disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals
'prefer-numeric-literals': ERROR,
// prefer `Object.hasOwn`
'prefer-object-has-own': ERROR,
// disallow use of the `RegExp` constructor in favor of regular expression literals
'prefer-regex-literals': [ERROR, { disallowRedundantWrapping: true }],
// require rest parameters instead of `arguments`
'prefer-rest-params': ERROR,
// require spread operators instead of `.apply()`
Expand Down
1 change: 1 addition & 0 deletions tests/unit-global/es.number.parse-int.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prefer-numeric-literals -- required for testing */
import { GLOBAL, WHITESPACES } from '../helpers/constants';

QUnit.test('Number.parseInt', assert => {
Expand Down
1 change: 1 addition & 0 deletions tests/unit-global/es.parse-int.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prefer-numeric-literals -- required for testing */
import { WHITESPACES } from '../helpers/constants';

/* eslint-disable radix -- required for testing */
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-global/es.regexp.constructor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable regexp/no-invalid-regexp, regexp/sort-flags -- required for testing */
/* eslint-disable prefer-regex-literals, regexp/no-invalid-regexp, regexp/sort-flags -- required for testing */
/* eslint-disable regexp/no-useless-character-class, regexp/no-useless-flag -- required for testing */
import { DESCRIPTORS, GLOBAL } from '../helpers/constants';
import { nativeSubclass } from '../helpers/helpers';
Expand Down
1 change: 1 addition & 0 deletions tests/unit-global/es.regexp.dot-all.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prefer-regex-literals -- required for testing */
import { DESCRIPTORS } from '../helpers/constants';

if (DESCRIPTORS) {
Expand Down
1 change: 1 addition & 0 deletions tests/unit-global/es.regexp.exec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prefer-regex-literals -- required for testing */
import { DESCRIPTORS } from '../helpers/constants';

QUnit.test('RegExp#exec lastIndex updating', assert => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-global/es.regexp.flags.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable regexp/sort-flags, regexp/no-useless-flag -- required for testing */
/* eslint-disable prefer-regex-literals, regexp/sort-flags, regexp/no-useless-flag -- required for testing */
import { DESCRIPTORS } from '../helpers/constants';

if (DESCRIPTORS) {
Expand Down
1 change: 1 addition & 0 deletions tests/unit-global/es.regexp.sticky.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prefer-regex-literals -- required for testing */
import { DESCRIPTORS } from '../helpers/constants';

if (DESCRIPTORS) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-global/es.regexp.to-string.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable regexp/sort-flags, regexp/no-useless-flag -- required for testing */
/* eslint-disable prefer-regex-literals, regexp/sort-flags, regexp/no-useless-flag -- required for testing */
import { STRICT } from '../helpers/constants';

QUnit.test('RegExp#toString', assert => {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-global/es.string.match.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: fix escaping in regexps
/* eslint-disable regexp/prefer-regexp-exec -- required for testing */
/* eslint-disable prefer-regex-literals, regexp/prefer-regexp-exec -- required for testing */
import { GLOBAL, NATIVE, STRICT } from '../helpers/constants';
import { patchRegExp$exec } from '../helpers/helpers';

Expand Down
2 changes: 1 addition & 1 deletion tests/unit-global/es.string.replace.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable regexp/no-unused-capturing-group -- required for testing */
/* eslint-disable prefer-regex-literals, regexp/no-unused-capturing-group -- required for testing */
import { GLOBAL, NATIVE, STRICT } from '../helpers/constants';
import { patchRegExp$exec } from '../helpers/helpers';

Expand Down
1 change: 1 addition & 0 deletions tests/unit-global/es.string.search.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prefer-regex-literals -- required for testing */
import { GLOBAL, STRICT } from '../helpers/constants';
import { patchRegExp$exec } from '../helpers/helpers';

Expand Down
1 change: 1 addition & 0 deletions tests/unit-global/es.string.split.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prefer-regex-literals -- required for testing */
/* eslint-disable regexp/no-empty-group, regexp/no-empty-capturing-group -- required for testing */
/* eslint-disable regexp/optimal-lookaround-quantifier, regexp/no-lazy-ends -- required for testing */
import { GLOBAL, NATIVE, STRICT } from '../helpers/constants';
Expand Down
1 change: 1 addition & 0 deletions tests/unit-pure/es.number.parse-int.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prefer-numeric-literals -- required for testing */
import { WHITESPACES } from '../helpers/constants';

import parseInt from 'core-js-pure/es/number/parse-int';
Expand Down
1 change: 1 addition & 0 deletions tests/unit-pure/es.parse-int.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prefer-numeric-literals -- required for testing */
import { WHITESPACES } from '../helpers/constants';
import parseInt from 'core-js-pure/es/parse-int';

Expand Down

0 comments on commit 505f464

Please sign in to comment.