From 699f2e7721355e88160db0b096aedf56f9f85368 Mon Sep 17 00:00:00 2001
From: Muhammad Haris <101793258+headlessNode@users.noreply.github.com>
Date: Thu, 27 Feb 2025 08:44:42 +0000
Subject: [PATCH 1/2] build: add ESLint rule to disallow new Array constructor
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
- task: lint_filenames
status: passed
- task: lint_editorconfig
status: passed
- task: lint_markdown
status: passed
- task: lint_package_json
status: passed
- task: lint_repl_help
status: na
- task: lint_javascript_src
status: passed
- task: lint_javascript_cli
status: na
- task: lint_javascript_examples
status: passed
- task: lint_javascript_tests
status: passed
- task: lint_javascript_benchmarks
status: na
- task: lint_python
status: na
- task: lint_r
status: na
- task: lint_c_src
status: na
- task: lint_c_examples
status: na
- task: lint_c_benchmarks
status: na
- task: lint_c_tests_fixtures
status: na
- task: lint_shell
status: na
- task: lint_typescript_declarations
status: na
- task: lint_typescript_tests
status: na
- task: lint_license_headers
status: passed
---
---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
- task: run_javascript_examples
status: na
- task: run_c_examples
status: na
- task: run_cpp_examples
status: na
- task: run_javascript_readme_examples
status: na
- task: run_c_benchmarks
status: na
- task: run_cpp_benchmarks
status: na
- task: run_fortran_benchmarks
status: na
- task: run_javascript_benchmarks
status: na
- task: run_julia_benchmarks
status: na
- task: run_python_benchmarks
status: na
- task: run_r_benchmarks
status: na
- task: run_javascript_tests
status: na
---
---
etc/eslint/rules/stdlib.js | 36 ++++
.../@stdlib/_tools/eslint/rules/lib/index.js | 9 +
.../eslint/rules/no-new-array/README.md | 136 +++++++++++++++
.../rules/no-new-array/examples/index.js | 51 ++++++
.../eslint/rules/no-new-array/lib/index.js | 39 +++++
.../eslint/rules/no-new-array/lib/main.js | 85 ++++++++++
.../eslint/rules/no-new-array/package.json | 54 ++++++
.../no-new-array/test/fixtures/invalid.js | 81 +++++++++
.../no-new-array/test/fixtures/unvalidated.js | 51 ++++++
.../rules/no-new-array/test/fixtures/valid.js | 159 ++++++++++++++++++
.../eslint/rules/no-new-array/test/test.js | 86 ++++++++++
11 files changed, 787 insertions(+)
create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/README.md
create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/examples/index.js
create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/lib/index.js
create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/lib/main.js
create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/package.json
create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/invalid.js
create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/unvalidated.js
create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/valid.js
create mode 100644 lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/test.js
diff --git a/etc/eslint/rules/stdlib.js b/etc/eslint/rules/stdlib.js
index ceacbd72d966..c09a1af29f03 100644
--- a/etc/eslint/rules/stdlib.js
+++ b/etc/eslint/rules/stdlib.js
@@ -4310,6 +4310,42 @@ rules[ 'stdlib/no-dynamic-exports' ] = 'error';
*/
rules[ 'stdlib/no-nested-require' ] = 'error';
+/**
+* Disallow the use of the `new Array()` constructor.
+*
+* @name no-new-array
+* @memberof rules
+* @type {string}
+* @default 'error'
+*
+* @example
+* // Bad...
+* var arr;
+* var i;
+*
+* arr = new Array( 5 );
+* for ( i = 0; i < 5; i++ ) {
+* arr[ i ] = i;
+* }
+*
+* console.log( arr );
+* // => [ 0, 1, 2, 3, 4 ]
+*
+* @example
+* // Good...
+* var arr;
+* var i;
+*
+* arr = [];
+* for ( var i = 0; i < 5; i++ ) {
+* arr.push( i );
+* }
+*
+* console.log( arr );
+* // => [ 0, 1, 2, 3, 4 ]
+*/
+rules[ 'stdlib/no-new-array' ] = 'error';
+
/**
* Never allow a variable to be declared multiple times within the same scope or for built-in globals to be redeclared.
*
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js
index 7611a92391a2..28356128cb79 100644
--- a/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js
@@ -909,6 +909,15 @@ setReadOnly( rules, 'no-multiple-empty-lines', require( '@stdlib/_tools/eslint/r
*/
setReadOnly( rules, 'no-nested-require', require( '@stdlib/_tools/eslint/rules/no-nested-require' ) );
+/**
+* @name no-new-array
+* @memberof rules
+* @readonly
+* @type {Function}
+* @see {@link module:@stdlib/_tools/eslint/rules/no-new-array}
+*/
+setReadOnly( rules, 'no-new-array', require( '@stdlib/_tools/eslint/rules/no-new-array' ) );
+
/**
* @name no-redeclare
* @memberof rules
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/README.md b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/README.md
new file mode 100644
index 000000000000..f918e984d442
--- /dev/null
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/README.md
@@ -0,0 +1,136 @@
+
+
+# no-new-array
+
+> [ESLint rule][eslint-rules] disallowing the use of the `new Array()` constructor.
+
+
+
+
+
+
+
+## Usage
+
+```javascript
+var rule = require( '@stdlib/_tools/eslint/rules/no-new-array' );
+```
+
+#### rule
+
+[ESLint rule][eslint-rules] disallowing the use of the `new Array()` constructor.
+
+**Bad**:
+
+
+
+```javascript
+var arr;
+var i;
+
+arr = new Array( 5 );
+
+for ( i = 0; i < 5; i++ ) {
+ arr[ i ] = i;
+}
+
+console.log( arr );
+// => [ 0, 1, 2, 3, 4 ]
+```
+
+**Good**:
+
+```javascript
+var arr;
+var i;
+
+arr = [];
+
+for ( i = 0; i < 5; i++ ) {
+ arr.push( i );
+}
+
+console.log( arr );
+// => [ 0, 1, 2, 3, 4 ]
+```
+
+
+
+
+
+
+
+## Examples
+
+```javascript
+var Linter = require( 'eslint' ).Linter;
+var rule = require( '@stdlib/_tools/eslint/rules/no-new-array' );
+
+var linter = new Linter();
+var result;
+
+var code = 'var arr = new Array( 5 );';
+
+linter.defineRule( 'no-new-array', rule );
+
+result = linter.verify( code, {
+ 'rules': {
+ 'no-new-array': 'error'
+ }
+});
+/* returns
+ [
+ {
+ 'ruleId': 'no-new-array',
+ 'severity': 2,
+ 'message': 'Using the `new Array()` constructor is not allowed; use an array literal with push instead.',
+ 'line': 1,
+ 'column': 14,
+ 'nodeType': 'CallExpression',
+ 'source': 'var arr = new Array( 5 );',
+ 'endLine': 1,
+ 'endColumn': 25
+ }
+ ]
+*/
+```
+
+
+
+
+
+
+
+
+
+
+
+
+
+[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules
+
+
+
+
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/examples/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/examples/index.js
new file mode 100644
index 000000000000..5d0f71d4c41e
--- /dev/null
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/examples/index.js
@@ -0,0 +1,51 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+var Linter = require( 'eslint' ).Linter;
+var rule = require( './../lib' );
+
+var linter = new Linter();
+var result;
+
+var code = 'var arr = new Array( 5 );';
+
+linter.defineRule( 'no-new-array', rule );
+
+result = linter.verify( code, {
+ 'rules': {
+ 'no-new-array': 'error'
+ }
+});
+console.log( result );
+/* =>
+ [
+ {
+ 'ruleId': 'no-new-array',
+ 'severity': 2,
+ 'message': 'Using the `new Array()` constructor is not allowed; use an array literal with push instead.',
+ 'line': 1,
+ 'column': 14,
+ 'nodeType': 'CallExpression',
+ 'source': 'var arr = new Array( 5 );',
+ 'endLine': 1,
+ 'endColumn': 25
+ }
+ ]
+*/
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/lib/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/lib/index.js
new file mode 100644
index 000000000000..dc731273e816
--- /dev/null
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/lib/index.js
@@ -0,0 +1,39 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+/**
+* ESLint rule disallowing the use of the `new Array()` constructor.
+*
+* @module @stdlib/_tools/eslint/rules/no-new-array
+*
+* @example
+* var rule = require( '@stdlib/_tools/eslint/rules/no-new-array' );
+*
+* console.log( rule );
+*/
+
+// MODULES //
+
+var main = require( './main.js' );
+
+
+// EXPORTS //
+
+module.exports = main;
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/lib/main.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/lib/main.js
new file mode 100644
index 000000000000..f55ea1d4d7cc
--- /dev/null
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/lib/main.js
@@ -0,0 +1,85 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// VARIABLES //
+
+var rule;
+
+
+// FUNCTIONS //
+
+/**
+* Rule for disallowing the use of the `new Array()` constructor.
+*
+* @param {Object} context - ESLint context
+* @returns {Object} validators
+*/
+function main( context ) {
+ /**
+ * Reports the error message.
+ *
+ * @private
+ * @param {ASTNode} node - node to report
+ */
+ function report( node ) {
+ context.report({
+ 'node': node,
+ 'message': 'Using the `new Array()` constructor is not allowed; use an array literal with push instead.'
+ });
+ }
+
+ /**
+ * Checks whether a node is a `new Array()` expression.
+ *
+ * @private
+ * @param {ASTNode} node - node to examine
+ */
+ function validate( node ) {
+ if (
+ node.callee &&
+ node.callee.name === 'Array'
+ ) {
+ report( node );
+ }
+ }
+
+ return {
+ 'NewExpression': validate
+ };
+}
+
+
+// MAIN //
+
+rule = {
+ 'meta': {
+ 'type': 'suggestion',
+ 'docs': {
+ 'description': 'disallow the use of the `new Array()` constructor'
+ },
+ 'schema': []
+ },
+ 'create': main
+};
+
+
+// EXPORTS //
+
+module.exports = rule;
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/package.json b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/package.json
new file mode 100644
index 000000000000..df135693657f
--- /dev/null
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/package.json
@@ -0,0 +1,54 @@
+{
+ "name": "@stdlib/_tools/eslint/rules/no-new-array",
+ "version": "0.0.0",
+ "description": "ESLint rule disallowing the use of the `new Array()` constructor.",
+ "license": "Apache-2.0",
+ "author": {
+ "name": "The Stdlib Authors",
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
+ },
+ "contributors": [
+ {
+ "name": "The Stdlib Authors",
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
+ }
+ ],
+ "bin": {},
+ "main": "./lib",
+ "directories": {
+ "example": "./examples",
+ "lib": "./lib",
+ "test": "./test"
+ },
+ "scripts": {},
+ "homepage": "https://github.com/stdlib-js/stdlib",
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/stdlib-js/stdlib.git"
+ },
+ "bugs": {
+ "url": "https://github.com/stdlib-js/stdlib/issues"
+ },
+ "dependencies": {},
+ "devDependencies": {},
+ "engines": {
+ "node": ">=0.10.0",
+ "npm": ">2.7.0"
+ },
+ "keywords": [
+ "stdlib",
+ "tools",
+ "tool",
+ "eslint",
+ "lint",
+ "custom",
+ "rules",
+ "rule",
+ "plugin",
+ "constructor",
+ "new",
+ "literal",
+ "sparse",
+ "array"
+ ]
+}
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/invalid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/invalid.js
new file mode 100644
index 000000000000..f44bf3c93425
--- /dev/null
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/invalid.js
@@ -0,0 +1,81 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+var invalid = [];
+var test;
+
+test = {
+ 'code': [
+ 'var arr = new Array();'
+ ].join( '\n' ),
+ 'errors': [
+ {
+ 'message': 'Using the `new Array()` constructor is not allowed; use an array literal with push instead.',
+ 'type': 'NewExpression'
+ }
+ ]
+};
+invalid.push( test );
+
+test = {
+ 'code': [
+ 'var arr = new Array(10);'
+ ].join( '\n' ),
+ 'errors': [
+ {
+ 'message': 'Using the `new Array()` constructor is not allowed; use an array literal with push instead.',
+ 'type': 'NewExpression'
+ }
+ ]
+};
+invalid.push( test );
+
+test = {
+ 'code': [
+ 'var arr = new Array(1, 2, 3, 4);'
+ ].join( '\n' ),
+ 'errors': [
+ {
+ 'message': 'Using the `new Array()` constructor is not allowed; use an array literal with push instead.',
+ 'type': 'NewExpression'
+ }
+ ]
+};
+invalid.push( test );
+
+test = {
+ 'code': [
+ 'function createArray() {',
+ ' return new Array(5);',
+ '}'
+ ].join( '\n' ),
+ 'errors': [
+ {
+ 'message': 'Using the `new Array()` constructor is not allowed; use an array literal with push instead.',
+ 'type': 'NewExpression'
+ }
+ ]
+};
+invalid.push( test );
+
+
+// EXPORTS //
+
+module.exports = invalid;
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/unvalidated.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/unvalidated.js
new file mode 100644
index 000000000000..17c2f85c5e26
--- /dev/null
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/unvalidated.js
@@ -0,0 +1,51 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+var valid = [];
+var test;
+
+test = {
+ 'code': [
+ 'var arr = [];'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ 'var arr = [1, 2, 3, 4];'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ 'var arr = [];',
+ 'for (var i = 0; i < 10; i++) {',
+ ' arr.push(i);',
+ '}'
+ ].join( '\n' )
+};
+valid.push( test );
+
+
+// EXPORTS //
+
+module.exports = valid;
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/valid.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/valid.js
new file mode 100644
index 000000000000..a4cef75d412f
--- /dev/null
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/fixtures/valid.js
@@ -0,0 +1,159 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+var valid = [];
+var test;
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var Float64Array = require( \'@stdlib/array/float64\' );',
+ '',
+ 'var arr = new Float64Array( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var Float32Array = require( \'@stdlib/array/float32\' );',
+ '',
+ 'var arr = new Float32Array( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var Complex64Array = require( \'@stdlib/array/complex64\' );',
+ '',
+ 'var arr = new Complex64Array( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var Complex128Array = require( \'@stdlib/array/complex128\' );',
+ '',
+ 'var arr = new Complex128Array( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var BooleanArray = require( \'@stdlib/array/bool\' );',
+ '',
+ 'var arr = new BooleanArray( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var Int8Array = require( \'@stdlib/array/int8\' );',
+ '',
+ 'var arr = new Int8Array( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var Uint8Array = require( \'@stdlib/array/uint8\' );',
+ '',
+ 'var arr = new Uint8Array( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var Uint8ClampedArray = require( \'@stdlib/array/uint8c\' );',
+ '',
+ 'var arr = new Uint8ClampedArray( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var Int16Array = require( \'@stdlib/array/int16\' );',
+ '',
+ 'var arr = new Int16Array( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var Uint16Array = require( \'@stdlib/array/uint16\' );',
+ '',
+ 'var arr = new Uint16Array( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var Int32Array = require( \'@stdlib/array/int32\' );',
+ '',
+ 'var arr = new Int32Array( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+test = {
+ 'code': [
+ '// MODULES //',
+ '',
+ 'var Uint32Array = require( \'@stdlib/array/uint32\' );',
+ '',
+ 'var arr = new Uint32Array( 5 );'
+ ].join( '\n' )
+};
+valid.push( test );
+
+
+// EXPORTS //
+
+module.exports = valid;
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/test.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/test.js
new file mode 100644
index 000000000000..782627ec4e00
--- /dev/null
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/test/test.js
@@ -0,0 +1,86 @@
+/**
+* @license Apache-2.0
+*
+* Copyright (c) 2025 The Stdlib Authors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+// MODULES //
+
+var tape = require( 'tape' );
+var RuleTester = require( 'eslint' ).RuleTester;
+var rule = require( './../lib' );
+
+
+// FIXTURES //
+
+var valid = require( './fixtures/valid.js' );
+var invalid = require( './fixtures/invalid.js' );
+var unvalidated = require( './fixtures/unvalidated.js' );
+
+
+// TESTS //
+
+tape( 'main export is an object', function test( t ) {
+ t.ok( true, __filename );
+ t.equal( typeof rule, 'object', 'main export is an object' );
+ t.end();
+});
+
+tape( 'the function positively validates code without `new Array()` constructor', function test( t ) {
+ var tester = new RuleTester();
+
+ try {
+ tester.run( 'no-new-array', rule, {
+ 'valid': valid,
+ 'invalid': []
+ });
+ t.pass( 'passed without errors' );
+ } catch ( err ) {
+ t.fail( 'encountered an error: ' + err.message );
+ }
+ t.end();
+});
+
+tape( 'the function negatively validates code with `new Array()` constructor', function test( t ) {
+ var tester = new RuleTester();
+
+ try {
+ tester.run( 'no-new-array', rule, {
+ 'valid': [],
+ 'invalid': invalid
+ });
+ t.pass( 'passed without errors' );
+ } catch ( err ) {
+ t.fail( 'encountered an error: ' + err.message );
+ }
+ t.end();
+});
+
+tape( 'the function does not validate code with array literals', function test( t ) {
+ var tester = new RuleTester();
+
+ try {
+ tester.run( 'no-new-array', rule, {
+ 'valid': unvalidated,
+ 'invalid': []
+ });
+ t.pass( 'passed without errors' );
+ } catch ( err ) {
+ t.fail( 'encountered an error: ' + err.message );
+ }
+ t.end();
+});
From d13a03ab5ca24f6cedc31528373f4182ec7f087a Mon Sep 17 00:00:00 2001
From: Athan
Date: Thu, 27 Feb 2025 01:19:29 -0800
Subject: [PATCH 2/2] Apply suggestions from code review
Signed-off-by: Athan
---
etc/eslint/rules/stdlib.js | 10 +++-------
.../_tools/eslint/rules/no-new-array/README.md | 13 +++----------
.../eslint/rules/no-new-array/examples/index.js | 3 +--
3 files changed, 7 insertions(+), 19 deletions(-)
diff --git a/etc/eslint/rules/stdlib.js b/etc/eslint/rules/stdlib.js
index c09a1af29f03..58bf584b845a 100644
--- a/etc/eslint/rules/stdlib.js
+++ b/etc/eslint/rules/stdlib.js
@@ -4320,10 +4320,8 @@ rules[ 'stdlib/no-nested-require' ] = 'error';
*
* @example
* // Bad...
-* var arr;
+* var arr = new Array( 5 );
* var i;
-*
-* arr = new Array( 5 );
* for ( i = 0; i < 5; i++ ) {
* arr[ i ] = i;
* }
@@ -4333,11 +4331,9 @@ rules[ 'stdlib/no-nested-require' ] = 'error';
*
* @example
* // Good...
-* var arr;
+* var arr = [];
* var i;
-*
-* arr = [];
-* for ( var i = 0; i < 5; i++ ) {
+* for ( i = 0; i < 5; i++ ) {
* arr.push( i );
* }
*
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/README.md b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/README.md
index f918e984d442..a16da76bc42a 100644
--- a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/README.md
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/README.md
@@ -45,11 +45,8 @@ var rule = require( '@stdlib/_tools/eslint/rules/no-new-array' );
```javascript
-var arr;
+var arr = new Array( 5 );
var i;
-
-arr = new Array( 5 );
-
for ( i = 0; i < 5; i++ ) {
arr[ i ] = i;
}
@@ -61,11 +58,8 @@ console.log( arr );
**Good**:
```javascript
-var arr;
+var arr = [];
var i;
-
-arr = [];
-
for ( i = 0; i < 5; i++ ) {
arr.push( i );
}
@@ -87,13 +81,12 @@ var Linter = require( 'eslint' ).Linter;
var rule = require( '@stdlib/_tools/eslint/rules/no-new-array' );
var linter = new Linter();
-var result;
var code = 'var arr = new Array( 5 );';
linter.defineRule( 'no-new-array', rule );
-result = linter.verify( code, {
+var result = linter.verify( code, {
'rules': {
'no-new-array': 'error'
}
diff --git a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/examples/index.js b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/examples/index.js
index 5d0f71d4c41e..e816226a9a85 100644
--- a/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/examples/index.js
+++ b/lib/node_modules/@stdlib/_tools/eslint/rules/no-new-array/examples/index.js
@@ -22,13 +22,12 @@ var Linter = require( 'eslint' ).Linter;
var rule = require( './../lib' );
var linter = new Linter();
-var result;
var code = 'var arr = new Array( 5 );';
linter.defineRule( 'no-new-array', rule );
-result = linter.verify( code, {
+var result = linter.verify( code, {
'rules': {
'no-new-array': 'error'
}