Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions etc/eslint/rules/stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@
* // Bad...
*
* /**
* * Fréchet distribution constructor.

Check warning on line 853 in etc/eslint/rules/stdlib.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "échet"
* *
* * @module @stdlib/stats/base/dists/frechet/ctor
* *
Expand All @@ -866,7 +866,7 @@
* // Good...
*
* /**
* * Fréchet distribution constructor.

Check warning on line 869 in etc/eslint/rules/stdlib.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unknown word: "échet"
* *
* * @module @stdlib/stats/base/dists/frechet/ctor
* *
Expand Down Expand Up @@ -4229,6 +4229,30 @@
*/
rules[ 'stdlib/no-multiple-empty-lines' ] = 'error';

/**
* Disallow usage of the built-in global `BigInt` literal syntax and constructor.
*
* @name no-builtin-big-int
* @memberof rules
* @type {string}
* @default 'error'
*
* @example
* // Bad...
* var x = BigInt( 123 );
* console.log( typeof x );
* // => 'bigint'
*
* @example
* // Good...
* var BigInt = require( '@stdlib/bigint/ctor' );
*
* var x = BigInt( 123 );
* console.log( typeof x );
* // => 'bigint'
*/
rules[ 'stdlib/no-builtin-big-int' ] = 'error';

/**
* Disallow usage of the built-in global `Math` object.
*
Expand Down
9 changes: 9 additions & 0 deletions lib/node_modules/@stdlib/_tools/eslint/rules/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,15 @@ setReadOnly( rules, 'new-cap-error', require( '@stdlib/_tools/eslint/rules/new-c
*/
setReadOnly( rules, 'new-cap-regexp', require( '@stdlib/_tools/eslint/rules/new-cap-regexp' ) );

/**
* @name no-builtin-big-int
* @memberof rules
* @readonly
* @type {Function}
* @see {@link module:@stdlib/_tools/eslint/rules/no-builtin-big-int}
*/
setReadOnly( rules, 'no-builtin-big-int', require( '@stdlib/_tools/eslint/rules/no-builtin-big-int' ) );

/**
* @name no-builtin-math
* @memberof rules
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<!--
@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.
-->

# no-builtin-big-int

> [ESLint rule][eslint-rules] disallowing the use of the built-in global `BigInt` literal syntax and constructor.
<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

```javascript
var rule = require( '@stdlib/_tools/eslint/rules/no-builtin-big-int' );
```

#### rule

[ESLint rule][eslint-rules] disallowing the use of the built-in global `BigInt` literal syntax and constructor.

**Bad**:

<!-- eslint-disable stdlib/no-builtin-big-int -->

<!-- eslint-disable stdlib/require-globals -->

```javascript
var x = BigInt( 123 );
console.log( typeof x );
// => 'bigint'
```

<!-- eslint-enable stdlib/require-globals -->

**Good**:

```javascript
var BigInt = require( '@stdlib/bigint/ctor' );

var x = BigInt( 123 );
console.log( typeof x );
// => 'bigint'
```

</section>

<!-- /.usage -->

<section class="examples">

## Examples

```javascript
var Linter = require( 'eslint' ).Linter;
var rule = require( '@stdlib/_tools/eslint/rules/no-builtin-big-int' );

var linter = new Linter();

var code = 'var x = 123n;';

linter.defineRule( 'no-builtin-big-int', rule );

var result = linter.verify( code, {
'rules': {
'no-builtin-big-int': 'error'
}
});
/* returns
[
{
'ruleId': 'no-builtin-big-int',
'severity': 2,
'message': 'Using the built-in global `BigInt` literal syntax is not allowed; use `@stdlib/bigint/ctor` instead.',
'line': 1,
'column': 9,
'nodeType': 'Literal',
'source': 'var x = 123n;',
'endLine': 1,
'endColumn': 13
}
]
*/
```

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @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 code = 'var x = 123n;';

linter.defineRule( 'no-builtin-big-int', rule );

var results = linter.verify( code, {
'rules': {
'no-builtin-big-int': 'error'
},
'parserOptions': {
'ecmaVersion': 2020
}
});
console.log( results );

/*
[
{
'ruleId': 'no-builtin-big-int',
'severity': 2,
'message': 'Using the built-in global `BigInt` literal syntax is not allowed; use `@stdlib/bigint/ctor` instead.',
'line': 1,
'column': 9,
'nodeType': 'Literal',
'source': 'var x = 123n;',
'endLine': 1,
'endColumn': 13
}
]
*/
Original file line number Diff line number Diff line change
@@ -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 built-in global `BigInt` literal syntax and constructor.
*
* @module @stdlib/_tools/eslint/rules/no-builtin-big-int
*
* @example
* var rule = require( '@stdlib/_tools/eslint/rules/no-builtin-big-int' );
*
* console.log( rule );
*/

// MODULES //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
Loading