Skip to content

Commit

Permalink
chore: prefer strict Node assert (#618)
Browse files Browse the repository at this point in the history
This change should have no impact on functionality.

`node:assert` has two modes: [strict] and [legacy]. The latter can have
some strange behavior. This adds an [ESLint rule][no-restricted-imports]
to prefer the strict mode, and fixes all violations.

I think this is a useful change on its own but it should make it a
little easier to drop Brittle in the future.

[strict]: https://nodejs.org/api/assert.html#strict-assertion-mode
[legacy]: https://nodejs.org/api/assert.html#legacy-assertion-mode
[no-restricted-imports]: https://eslint.org/docs/latest/rules/no-restricted-imports
  • Loading branch information
EvanHahn authored May 7, 2024
1 parent bcf1de1 commit a84e89a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@
"varsIgnorePattern": "^_",
"argsIgnorePattern": "^_"
}
],
"no-restricted-imports": [
"error",
{
"paths": [
{
"name": "assert",
"message": "Prefer importing node:assert/strict."
},
{
"name": "node:assert",
"message": "Prefer importing node:assert/strict."
}
]
}
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/core-manager/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
import { TypedEmitter } from 'tiny-typed-emitter'
import Corestore from 'corestore'
import assert from 'node:assert'
import assert from 'node:assert/strict'
import { sql, eq } from 'drizzle-orm'
import { discoveryKey } from 'hypercore-crypto'
import Hypercore from 'hypercore'
Expand Down
2 changes: 1 addition & 1 deletion src/core-ownership.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { verifySignature, sign } from '@mapeo/crypto'
import { parseVersionId } from '@mapeo/schema'
import { defaultGetWinner } from '@mapeo/sqlite-indexer'
import assert from 'node:assert'
import assert from 'node:assert/strict'
import sodium from 'sodium-universal'
import { kTable, kSelect, kCreateWithDocId } from './datatype/index.js'
import { eq, or } from 'drizzle-orm'
Expand Down
2 changes: 1 addition & 1 deletion tests/core-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
kCoreManagerReplicate,
} from '../src/core-manager/index.js'
import RemoteBitfield from '../src/core-manager/remote-bitfield.js'
import assert from 'assert'
import assert from 'node:assert/strict'
import { once } from 'node:events'
import { temporaryDirectoryTask } from 'tempy'
import { exec } from 'child_process'
Expand Down

0 comments on commit a84e89a

Please sign in to comment.