-
-
Notifications
You must be signed in to change notification settings - Fork 907
Description
Summary
Multiple example files under the @stdlib/assert/**/examples/index.js
path contain an unnecessary /* eslint-disable no-new-wrappers */
directive. Because CI runs ESLint with the --report-unused-disable-directives
flag, these unused directives are reported as errors when the files are randomly selected for linting. This results in non-deterministic CI build failures.
This issue is an extension of issue #8235, which fixed a single instance in the is-nonpositive-integer-array
package. However, the same pattern exists broadly across other example files within the @stdlib/assert
module. Because the lint_random_files
workflow lints a random subset of files on each run, leaving these other unused directives in place will lead to future intermittent failures. Therefore, this issue aims to track a systematic cleanup to eradicate this class of non-deterministic failures.
Root Cause
The no-new-wrappers
ESLint rule is intended to disallow using the new
operator with the global Number
, String
, and Boolean
wrapper constructors. In the affected example files, the disable directive is unused for one of two reasons:
- No Wrapper Constructors Used: The code does not use calls like
new Number(...)
at all. - Constructor Is Locally Shadowed: The code imports a local constructor via a statement like
var Number = require('@stdlib/number/ctor');
. Subsequent calls tonew Number(...)
invoke this local variable, not the global wrapper constructor, so theno-new-wrappers
rule is never triggered.
Affected Files
The pattern of unused no-new-wrappers
directives has been identified in the 38 files listed below within the @stdlib/assert
scope.
A representative subset includes:
lib/node_modules/@stdlib/assert/is-number/examples/index.js
lib/node_modules/@stdlib/assert/is-negative-integer-array/examples/index.js
lib/node_modules/@stdlib/assert/is-prime/examples/index.js
lib/node_modules/@stdlib/assert/is-finite/examples/index.js
(Special combined case)
Click to expand the full list of 38 affected files
lib/node_modules/@stdlib/assert/is-boolean-array/examples/index.js
lib/node_modules/@stdlib/assert/is-boolean/examples/index.js
lib/node_modules/@stdlib/assert/is-composite/examples/index.js
lib/node_modules/@stdlib/assert/is-cube-number/examples/index.js
lib/node_modules/@stdlib/assert/is-even/examples/index.js
lib/node_modules/@stdlib/assert/is-finite-array/examples/index.js
lib/node_modules/@stdlib/assert/is-finite/examples/index.js
lib/node_modules/@stdlib/assert/is-infinite/examples/index.js
lib/node_modules/@stdlib/assert/is-integer/examples/index.js
lib/node_modules/@stdlib/assert/is-nan-array/examples/index.js
lib/node_modules/@stdlib/assert/is-nan/examples/index.js
lib/node_modules/@stdlib/assert/is-negative-integer-array/examples/index.js
lib/node_modules/@stdlib/assert/is-negative-integer/examples/index.js
lib/node_modules/@stdlib/assert/is-negative-number-array/examples/index.js
lib/node_modules/@stdlib/assert/is-negative-number/examples/index.js
lib/node_modules/@stdlib/assert/is-negative-zero/examples/index.js
lib/node_modules/@stdlib/assert/is-nonnegative-integer-array/examples/index.js
lib/node_modules/@stdlib/assert/is-nonnegative-integer/examples/index.js
lib/node_modules/@stdlib/assert/is-nonnegative-number-array/examples/index.js
lib/node_modules/@stdlib/assert/is-nonnegative-number/examples/index.js
lib/node_modules/@stdlib/assert/is-nonpositive-integer/examples/index.js
lib/node_modules/@stdlib/assert/is-nonpositive-number-array/examples/index.js
lib/node_modules/@stdlib/assert/is-nonpositive-number/examples/index.js
lib/node_modules/@stdlib/assert/is-number-array/examples/index.js
lib/node_modules/@stdlib/assert/is-number/examples/index.js
lib/node_modules/@stdlib/assert/is-odd/examples/index.js
lib/node_modules/@stdlib/assert/is-positive-integer-array/examples/index.js
lib/node_modules/@stdlib/assert/is-positive-integer/examples/index.js
lib/node_modules/@stdlib/assert/is-positive-number-array/examples/index.js
lib/node_modules/@stdlib/assert/is-positive-number/examples/index.js
lib/node_modules/@stdlib/assert/is-positive-zero/examples/index.js
lib/node_modules/@stdlib/assert/is-prime/examples/index.js
lib/node_modules/@stdlib/assert/is-probability/examples/index.js
lib/node_modules/@stdlib/assert/is-safe-integer-array/examples/index.js
lib/node_modules/@stdlib/assert/is-safe-integer/examples/index.js
lib/node_modules/@stdlib/assert/is-square-number/examples/index.js
lib/node_modules/@stdlib/assert/is-square-triangular-number/examples/index.js
lib/node_modules/@stdlib/assert/is-triangular-number/examples/index.js
Proposal
- Remove Unused Directives: Remove the file-level
/* eslint-disable no-new-wrappers */
directive in all files where it is verifiably unused. - Handle Combined Directives: For combined disable directives, remove only the unused
no-new-wrappers
part.- Example: In
is-finite/examples/index.js
, change/* eslint-disable no-new-wrappers, stdlib/no-redeclare */
to/* eslint-disable stdlib/no-redeclare */
.
- Example: In
Selection Rules
-
Remove the directive when:
- No
new Number
,new String
, ornew Boolean
is present. new Number
ornew Boolean
is present, but its constructor has been locally shadowed by@stdlib/*/ctor
.
- No
-
Keep the directive when:
- The example uses a global wrapper constructor (e.g.,
new String(...)
without local shadowing), and removing the directive would cause an ESLint error.
- The example uses a global wrapper constructor (e.g.,
Execution Plan
To avoid triggering an "Argument list too long" error in CI, this work can be submitted via multiple small PRs, with each PR modifying a few packages.
References
- The
no-new-wrappers
rule is set to "warn" in the examples ESLint config:etc/eslint/.eslintrc.examples.js:44
- CI invokes ESLint with the
--report-unused-disable-directives
flag:tools/make/lib/lint/javascript/eslint.mk:50