|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# no-builtin-big-int |
| 22 | + |
| 23 | +> [ESLint rule][eslint-rules] disallowing the use of the built-in global `BigInt` literal syntax and constructor. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +</section> |
| 28 | + |
| 29 | +<!-- /.intro --> |
| 30 | + |
| 31 | +<section class="usage"> |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +```javascript |
| 36 | +var rule = require( '@stdlib/_tools/eslint/rules/no-builtin-big-int' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### rule |
| 40 | + |
| 41 | +[ESLint rule][eslint-rules] disallowing the use of the built-in global `BigInt` literal syntax and constructor. |
| 42 | + |
| 43 | +**Bad**: |
| 44 | + |
| 45 | +<!-- eslint-disable stdlib/no-builtin-big-int --> |
| 46 | + |
| 47 | +<!-- eslint-disable stdlib/require-globals --> |
| 48 | + |
| 49 | +```javascript |
| 50 | +var x = BigInt( 123 ); |
| 51 | +console.log( typeof x ); |
| 52 | +// => 'bigint' |
| 53 | +``` |
| 54 | + |
| 55 | +<!-- eslint-enable stdlib/require-globals --> |
| 56 | + |
| 57 | +**Good**: |
| 58 | + |
| 59 | +```javascript |
| 60 | +var BigInt = require( '@stdlib/bigint/ctor' ); |
| 61 | + |
| 62 | +var x = BigInt( 123 ); |
| 63 | +console.log( typeof x ); |
| 64 | +// => 'bigint' |
| 65 | +``` |
| 66 | + |
| 67 | +</section> |
| 68 | + |
| 69 | +<!-- /.usage --> |
| 70 | + |
| 71 | +<section class="examples"> |
| 72 | + |
| 73 | +## Examples |
| 74 | + |
| 75 | +```javascript |
| 76 | +var Linter = require( 'eslint' ).Linter; |
| 77 | +var rule = require( '@stdlib/_tools/eslint/rules/no-builtin-big-int' ); |
| 78 | + |
| 79 | +var linter = new Linter(); |
| 80 | + |
| 81 | +var code = 'var x = 123n;'; |
| 82 | + |
| 83 | +linter.defineRule( 'no-builtin-big-int', rule ); |
| 84 | + |
| 85 | +var result = linter.verify( code, { |
| 86 | + 'rules': { |
| 87 | + 'no-builtin-big-int': 'error' |
| 88 | + } |
| 89 | +}); |
| 90 | +/* returns |
| 91 | + [ |
| 92 | + { |
| 93 | + 'ruleId': 'no-builtin-big-int', |
| 94 | + 'severity': 2, |
| 95 | + 'message': 'Using the built-in global `BigInt` literal syntax is not allowed; use `@stdlib/bigint/ctor` instead.', |
| 96 | + 'line': 1, |
| 97 | + 'column': 9, |
| 98 | + 'nodeType': 'Literal', |
| 99 | + 'source': 'var x = 123n;', |
| 100 | + 'endLine': 1, |
| 101 | + 'endColumn': 13 |
| 102 | + } |
| 103 | + ] |
| 104 | +*/ |
| 105 | +``` |
| 106 | + |
| 107 | +<!-- /.examples --> |
| 108 | + |
| 109 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 110 | + |
| 111 | +<section class="related"> |
| 112 | + |
| 113 | +</section> |
| 114 | + |
| 115 | +<!-- /.related --> |
| 116 | + |
| 117 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 118 | + |
| 119 | +<section class="links"> |
| 120 | + |
| 121 | +[eslint-rules]: https://eslint.org/docs/developer-guide/working-with-rules |
| 122 | + |
| 123 | +</section> |
| 124 | + |
| 125 | +<!-- /.links --> |
0 commit comments