Skip to content

Commit

Permalink
chore: eslint for typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Jun 17, 2024
1 parent 1ff5491 commit 9c1f639
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 203 deletions.
7 changes: 6 additions & 1 deletion eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommen
const globals = require('globals');
const js = require('@eslint/js');
const neostandard = require('neostandard')({ semi: true, noStyle: true });
const tseslint = require('typescript-eslint');

module.exports = [
js.configs.recommended,
...tseslint.configs.recommended,
...neostandard,
eslintPluginPrettierRecommended,
{
Expand All @@ -19,17 +21,20 @@ module.exports = [
...globals.node,
msCrypto: true,
},
parser: babelParser,
},
},
{
rules: {
'@typescript-eslint/no-redeclare': 'error',
'@typescript-eslint/no-require-imports': 'off',
'no-redeclare': 'off',
'no-var': ['error'],
curly: ['error', 'all'],
},
},
{
ignores: [
'eslint.config.cjs',
'!.babelrc.js',
'.local/',
'**/dist/',
Expand Down
2 changes: 1 addition & 1 deletion examples/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function benchmark(uuid, Benchmark) {
.add('uuid.v1() fill existing array', function () {
try {
uuid.v1(null, array, 0);
} catch (err) {
} catch {
// The spec (https://datatracker.ietf.org/doc/html/rfc9562#name-timestamp-considerations) defines that only 10M/s v1
// UUIDs can be generated on a single node. This library throws an error if we hit that limit
// (which can happen on modern hardware and modern Node.js versions).
Expand Down
320 changes: 151 additions & 169 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"@babel/preset-env": "7.24.6",
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@eslint/js": "9.5.0",
"@types/eslint__js": "8.42.3",
"@types/random-seed": "0.3.5",
"@wdio/browserstack-service": "7.16.10",
"@wdio/cli": "7.16.10",
Expand All @@ -64,7 +66,7 @@
"@wdio/spec-reporter": "7.16.9",
"@wdio/static-server-service": "7.16.6",
"bundlewatch": "0.3.3",
"eslint": "9.4.0",
"eslint": "9.5.0",
"eslint-plugin-prettier": "5.1.3",
"globals": "15.3.0",
"husky": "9.0.11",
Expand All @@ -76,7 +78,9 @@
"prettier": "3.3.0",
"random-seed": "0.3.0",
"runmd": "1.3.9",
"standard-version": "9.5.0"
"standard-version": "9.5.0",
"typescript": "5.4.5",
"typescript-eslint": "8.0.0-alpha.30"
},
"optionalDevDependencies": {
"@wdio/browserstack-service": "7.16.10",
Expand All @@ -92,8 +96,8 @@
"bundlewatch": "npm run pretest:browser && bundlewatch --config bundlewatch.config.json",
"docs:diff": "npm run docs && git diff --quiet README.md",
"docs": "npm run build && npx runmd --output=README.md README_js.md",
"eslint:check": "eslint src/ test/ examples/ *.js",
"eslint:fix": "eslint --fix src/ test/ examples/ *.js",
"eslint:check": "eslint src/ test/ examples/ *.[jt]s",
"eslint:fix": "eslint --fix src/ test/ examples/ *.[jt]s",
"examples:browser:rollup:build": "cd examples/browser-rollup && npm install && npm run build",
"examples:browser:webpack:build": "cd examples/browser-webpack && npm install && npm run build",
"examples:node:commonjs:test": "cd examples/node-commonjs && npm install && npm test",
Expand Down
4 changes: 2 additions & 2 deletions src/test/parse.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as assert from 'assert';
import test, { describe } from 'node:test';
// @ts-ignore random-seed is an old CJS module. we should update an ESM seeded
// @ts-expect-error random-seed is an old CJS module. we should update an ESM seeded
// RNG at some point, but keeping this for now to ensure the TS port works with
// the legacy tests here.
import gen from 'random-seed';
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('parse', () => {
});

test('UUID validation', () => {
// @ts-expect-error
// @ts-expect-error testing invalid input
assert.throws(() => parse());

assert.throws(() => parse('invalid uuid'));
Expand Down
2 changes: 1 addition & 1 deletion src/test/v1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ describe('v1', () => {
});

test('msec', () => {
// eslint-disable-next-line no-self-compare
assert.ok(
// eslint-disable-next-line no-self-compare
v1({ msecs: TIME }) !== v1({ msecs: TIME }),
'IDs created at same msec are different'
);
Expand Down
20 changes: 10 additions & 10 deletions src/test/v35.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ describe('v35', () => {
});

HASH_SAMPLES.forEach(function (sample, i) {
test('sha1(browser) HASH_SAMPLES[${i}]', () => {
test(`sha1(browser) HASH_SAMPLES[${i}]`, () => {
assert.equal(hashToHex(sha1Browser(sample.input)), sample.sha1);
});
});

HASH_SAMPLES.forEach(function (sample, i) {
test('md5(node) HASH_SAMPLES[${i}]', () => {
test(`md5(node) HASH_SAMPLES[${i}]`, () => {
assert.equal(hashToHex(md5(sample.input)), sample.md5);
});
});
Expand Down Expand Up @@ -162,13 +162,13 @@ describe('v35', () => {
});

test('v3 undefined/null', () => {
// @ts-expect-error
// @ts-expect-error testing invalid input
assert.throws(() => v3());
// @ts-expect-error
// @ts-expect-error testing invalid input
assert.throws(() => v3('hello'));
// @ts-expect-error
// @ts-expect-error testing invalid input
assert.throws(() => v3('hello.example.com', undefined));
// @ts-expect-error
// @ts-expect-error testing invalid input
assert.throws(() => v3('hello.example.com', null, new Uint8Array(16)));
});

Expand Down Expand Up @@ -267,13 +267,13 @@ describe('v35', () => {
});

test('v5 undefined/null', () => {
// @ts-expect-error
// @ts-expect-error testing invalid input
assert.throws(() => v5());
// @ts-expect-error
// @ts-expect-error testing invalid input
assert.throws(() => v5('hello'));
// @ts-expect-error
// @ts-expect-error testing invalid input
assert.throws(() => v5('hello.example.com', undefined));
// @ts-expect-error
// @ts-expect-error testing invalid input
assert.throws(() => v5('hello.example.com', null, new Uint8Array(16)));
});

Expand Down
4 changes: 2 additions & 2 deletions src/test/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ describe('version()', () => {
test('TESTS cases', () => {
for (const { value, expectedValidate, expectedVersion } of TESTS) {
try {
// @ts-expect-error
// @ts-expect-error testing invalid input
const actualVersion = version(value);

assert.ok(expectedValidate, `version(${value}) should throw`);
assert.strictEqual(actualVersion, expectedVersion);
} catch (err) {
} catch {
assert.ok(!expectedValidate, `version(${value}) threw unexpectedly`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/v1ToV6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function v1ToV6(uuid: string | Uint8Array): UUIDTypes {
}

// Do the field transformation needed for v1 -> v6
function _v1ToV6(v1Bytes: Uint8Array, randomize = false) {
function _v1ToV6(v1Bytes: Uint8Array) {
return Uint8Array.of(
((v1Bytes[6] & 0x0f) << 4) | ((v1Bytes[7] >> 4) & 0x0f),
((v1Bytes[7] & 0x0f) << 4) | ((v1Bytes[4] & 0xf0) >> 4),
Expand Down
7 changes: 0 additions & 7 deletions src/v35.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ export const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';

type HashFunction = (bytes: Uint8Array) => Uint8Array;

type NamespaceUuidFunction<BufType, ReturnType> = (
value: string | Uint8Array,
namespace: string | Uint8Array,
buf?: BufType,
offset?: number
) => ReturnType;

export default function v35(
version: 0x30 | 0x50,
hash: HashFunction,
Expand Down
5 changes: 0 additions & 5 deletions src/v6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,4 @@ function v6(options?: Version6Options, buf?: Uint8Array, offset?: number): UUIDT
return unsafeStringify(bytes);
}

const a = v6();
const b = v6({ msecs: 0 });
const c = v6({ msecs: 1 }, new Uint8Array(16));
const d = v6({ msecs: 1 }, new Uint8Array(16), 1);

export default v6;

0 comments on commit 9c1f639

Please sign in to comment.