Skip to content

Commit

Permalink
fix: avoid using bigint literal syntax (#542)
Browse files Browse the repository at this point in the history
* fix: avoid using bigint literal syntax

* simplify

* fix: Add custom eslint plugin with no-big-int rule

* fix: Migrate .eslintrc.js to flat format eslint.config.mjs

* fix(gh): exclude node 12.x, 14.x on macos-latest
  • Loading branch information
mman authored Dec 19, 2024
1 parent 837ec9e commit c14d358
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 25 deletions.
23 changes: 0 additions & 23 deletions .eslintrc.js

This file was deleted.

4 changes: 4 additions & 0 deletions .github/workflows/bundlers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
node-version: 12.x
- os: windows-latest
node-version: 14.x
- os: macos-latest
node-version: 12.x
- os: macos-latest
node-version: 14.x
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
node-version: 12.x
- os: windows-latest
node-version: 14.x
- os: macos-latest
node-version: 12.x
- os: macos-latest
node-version: 14.x
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
9 changes: 9 additions & 0 deletions eslint-plugin-local/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

import nbi from './no-big-int.mjs'

export default {
rules: {
'no-big-int': nbi,
},
}
26 changes: 26 additions & 0 deletions eslint-plugin-local/no-big-int.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

export default {
meta: {
docs: {
description: 'disallow `bigint` syntax',
category: 'ES2020',
recommended: false,
},
fixable: null,
messages: {
forbidden: 'ES2020 `bigint` syntax is forbidden.',
},
schema: [],
type: 'problem',
},
create(context) {
return {
Literal(node) {
if (node.bigint != null) {
context.report({ messageId: 'forbidden', node })
}
},
}
},
}
27 changes: 27 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { FlatCompat } from '@eslint/eslintrc'
const compat = new FlatCompat()

import eslintPluginLocal from './eslint-plugin-local/index.mjs'

export default [
// standard,
...compat.extends('eslint-config-standard'),
{
files: ['**/**.js', '**/**.mjs'],
languageOptions: {
sourceType: 'module',
ecmaVersion: 'latest',
},
plugins: { 'local': eslintPluginLocal },
rules: {
/*
This is inserted to make this compatible with prettier.
Once https://github.com/prettier/prettier/issues/3845 and https://github.com/prettier/prettier/issues/3847 are solved this might be not needed any more.
*/
'space-before-function-paren': 0,
curly: [2, 'all'],
'local/no-big-int': 'error',
},
},
]

4 changes: 2 additions & 2 deletions src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ E(
received = addNumericalSeparator(String(input))
} else if (typeof input === 'bigint') {
received = String(input)

if (input > 2n ** 32n || input < -(2n ** 32n)) {
const limit = BigInt(2) ** BigInt(32)
if (input > limit || input < -limit) {
received = addNumericalSeparator(received)
}

Expand Down

0 comments on commit c14d358

Please sign in to comment.