diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 2d9cc31..0000000 --- a/.eslintignore +++ /dev/null @@ -1 +0,0 @@ -rollup.config.js diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index f7d73ef..0000000 --- a/.eslintrc +++ /dev/null @@ -1,23 +0,0 @@ -{ - "extends": [ - "eslint:recommended", - "plugin:prettier/recommended" - ], - "plugins": [ - "prettier", - "import" - ], - "env": { - "node": true, - "es6": true - }, - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module" - }, - "rules": { - "prettier/prettier": "error", - "prefer-const": "off", - "no-var": "off", - } -} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 348879f..f5e9169 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: - name: Build run: npm run rollup - - name: Run Tests + - name: Run Tests and Linting run: npm run test:ci automerge: diff --git a/.prettierrc.json b/.prettierrc.json deleted file mode 100644 index dc2101e..0000000 --- a/.prettierrc.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "printWidth": 120, - "singleQuote": true, - "bracketSpacing": true, - "semi": false, - "arrowParens": "always", - "trailingComma": "all" -} diff --git a/benchmark.js b/benchmark.js index 39a428c..1b17146 100644 --- a/benchmark.js +++ b/benchmark.js @@ -1,9 +1,9 @@ -import { Lru } from './dist/toad-cache.mjs' import { precise } from 'precise' +import { Lru } from './dist/toad-cache.mjs' -const nth = 2e3, - cache = new Lru(nth), - data = new Array(nth) +const nth = 2e3 +const cache = new Lru(nth) +const data = new Array(nth) function seed() { let i = -1 @@ -40,7 +40,9 @@ function bench(n = 0, x = 1, type = 'set') { populate(cache, n) timer.stop() console.log( - `Run ${x} ${x === 1 ? 'Set' : 'Evict'} (${n === 0 ? 'Low Keys' : 'High Keys'}): ${timer.diff() / 1e6} ms`, + `Run ${x} ${x === 1 ? 'Set' : 'Evict'} (${n === 0 ? 'Low Keys' : 'High Keys'}): ${ + timer.diff() / 1e6 + } ms`, ) } else if (type === 'get') { const timer = precise().start() diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..7ac0bd4 --- /dev/null +++ b/biome.json @@ -0,0 +1,30 @@ +{ + "$schema": "./node_modules/@biomejs/biome/configuration_schema.json", + "javascript": { + "formatter": { + "arrowParentheses": "always", + "indentStyle": "space", + "semicolons": "asNeeded", + "trailingComma": "all", + "lineWidth": 100, + "quoteStyle": "single" + } + }, + "linter": { + "rules": { + "style": { + "useConst": "off", + "noVar": "off" + }, + "correctness": { + "noInnerDeclarations": "off" + }, + "suspicious": { + "noGlobalIsNan": "off" + }, + "complexity": { + "useLiteralKeys": "off" + } + } + } +} diff --git a/index.js b/index.js index 3dcc6a1..e85315b 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,9 @@ import { FifoMap } from './src/FifoMap.js' +import { FifoObject } from './src/FifoObject.js' +import { HitStatisticsRecord } from './src/HitStatisticsRecord.js' import { LruMap } from './src/LruMap.js' import { LruObject } from './src/LruObject.js' import { LruObjectHitStatistics } from './src/LruObjectHitStatistics.js' -import { FifoObject } from './src/FifoObject.js' -import { HitStatisticsRecord } from './src/HitStatisticsRecord.js' export { FifoObject } export { FifoMap } diff --git a/package.json b/package.json index 1584d60..b5ad747 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,8 @@ "build": "del-cli dist && del-cli coverage && npm run rollup", "benchmark": "npm run build && node benchmark.js", "changelog": "auto-changelog -p", - "lint": "eslint *.js src/*.js test/*.js", - "lint:fix": "eslint --fix *.js src/*.js test/*.js && prettier --write \"{src,test}/**/*.js\" benchmark.js", + "lint": "biome lint index.js benchmark.js src test biome.json", + "lint:fix": "biome check --apply index.js benchmark.js src test biome.json", "rollup": "rollup --config", "test": "vitest", "test:coverage": "npm run rollup && npm run test -- --coverage", @@ -53,19 +53,16 @@ "prepublishOnly": "npm run build" }, "devDependencies": { - "@vitest/coverage-v8": "^1.0.0", + "@biomejs/biome": "^1.5.3", + "@vitest/coverage-v8": "^1.2.2", "@rollup/plugin-terser": "^0.4.4", "auto-changelog": "^2.4.0", "del-cli": "^5.1.0", - "eslint": "^8.50.0", - "eslint-config-prettier": "^9.0.0", - "eslint-plugin-import": "^2.28.1", - "eslint-plugin-prettier": "^5.0.0", "precise": "^4.0.0", "rollup": "^4.6.0", - "vitest": "^1.1.3", - "tsd": "^0.30.0", - "typescript": "^5.3.2" + "vitest": "^1.2.2", + "tsd": "^0.30.4", + "typescript": "^5.3.3" }, "keywords": [ "LRU", diff --git a/src/LruObjectHitStatistics.js b/src/LruObjectHitStatistics.js index 755bcf7..7b50a83 100644 --- a/src/LruObjectHitStatistics.js +++ b/src/LruObjectHitStatistics.js @@ -1,5 +1,5 @@ -import { LruObject } from './LruObject.js' import { HitStatistics } from './HitStatistics.js' +import { LruObject } from './LruObject.js' export class LruObjectHitStatistics extends LruObject { constructor(max, ttlInMsecs, cacheId, globalStatisticsRecord, statisticTtlInHours) { diff --git a/test/FifoMap.spec.js b/test/FifoMap.spec.js index 452b004..8c57526 100644 --- a/test/FifoMap.spec.js +++ b/test/FifoMap.spec.js @@ -1,13 +1,13 @@ import assert from 'node:assert' -import { it, describe, beforeEach, expect } from 'vitest' +import { setTimeout } from 'timers/promises' +import { beforeEach, describe, expect, it } from 'vitest' import { FifoMap } from '../src/FifoMap.js' import { items, populateCache } from './utils/cachePopulator.js' -import { setTimeout } from 'timers/promises' -describe('FifoMap', function () { +describe('FifoMap', () => { let cache - beforeEach(function () { + beforeEach(() => { cache = new FifoMap(4) populateCache(cache) }) @@ -33,7 +33,7 @@ describe('FifoMap', function () { }) describe('evict', () => { - it('It should evict', function () { + it('It should evict', () => { expect(cache.first.key).toBe('b') expect(cache.last.key).toBe('e') expect(cache.size).toBe(4) @@ -115,7 +115,7 @@ describe('FifoMap', function () { }) describe('delete', () => { - it('It should delete', function () { + it('It should delete', () => { assert.strictEqual(cache.first.key, 'b', "Should be 'b'") assert.strictEqual(cache.last.key, 'e', "Should be 'e'") assert.strictEqual(cache.size, 4, "Should be '4'") @@ -165,7 +165,7 @@ describe('FifoMap', function () { }) describe('deleteMany', () => { - it('It should delete', function () { + it('It should delete', () => { assert.strictEqual(cache.first.key, 'b', "Should be 'b'") assert.strictEqual(cache.last.key, 'e', "Should be 'e'") assert.strictEqual(cache.size, 4, "Should be '4'") @@ -211,7 +211,7 @@ describe('FifoMap', function () { }) describe('core', () => { - it('It should handle a small evict', function () { + it('It should handle a small evict', () => { assert.strictEqual(cache.first.key, 'b', "Should be 'b'") assert.strictEqual(cache.last.key, 'e', "Should be 'e'") assert.strictEqual(cache.size, 4, "Should be '4'") @@ -247,7 +247,7 @@ describe('FifoMap', function () { assert.strictEqual(cache.size, 2, "Should be '2'") }) - it('It should handle an empty evict', function () { + it('It should handle an empty evict', () => { cache = new FifoMap(1) assert.strictEqual(cache.first, null, "Should be 'null'") assert.strictEqual(cache.last, null, "Should be 'null'") @@ -258,7 +258,7 @@ describe('FifoMap', function () { assert.strictEqual(cache.size, 0, "Should be 'null'") }) - it('It should expose expiration time', function () { + it('It should expose expiration time', () => { cache = new FifoMap(1, 6e4) cache.set(items[0], false) assert.strictEqual(typeof cache.expiresAt(items[0]), 'number', 'Should be a number') diff --git a/test/FifoObject.spec.js b/test/FifoObject.spec.js index 9c73a35..85c1b91 100644 --- a/test/FifoObject.spec.js +++ b/test/FifoObject.spec.js @@ -1,13 +1,13 @@ import assert from 'node:assert' -import { it, describe, beforeEach, expect } from 'vitest' +import { setTimeout } from 'timers/promises' +import { beforeEach, describe, expect, it } from 'vitest' import { FifoObject } from '../src/FifoObject.js' import { items, populateCache } from './utils/cachePopulator.js' -import { setTimeout } from 'timers/promises' -describe('FifoObject', function () { +describe('FifoObject', () => { let cache - beforeEach(function () { + beforeEach(() => { cache = new FifoObject(4) populateCache(cache) }) @@ -33,7 +33,7 @@ describe('FifoObject', function () { }) describe('evict', () => { - it('It should evict', function () { + it('It should evict', () => { expect(cache.first.key).toBe('b') expect(cache.last.key).toBe('e') expect(cache.size).toBe(4) @@ -115,7 +115,7 @@ describe('FifoObject', function () { }) describe('delete', () => { - it('It should delete', function () { + it('It should delete', () => { assert.strictEqual(cache.first.key, 'b', "Should be 'b'") assert.strictEqual(cache.last.key, 'e', "Should be 'e'") assert.strictEqual(cache.size, 4, "Should be '4'") @@ -165,7 +165,7 @@ describe('FifoObject', function () { }) describe('deleteMany', () => { - it('It should delete', function () { + it('It should delete', () => { assert.strictEqual(cache.first.key, 'b', "Should be 'b'") assert.strictEqual(cache.last.key, 'e', "Should be 'e'") assert.strictEqual(cache.size, 4, "Should be '4'") @@ -211,7 +211,7 @@ describe('FifoObject', function () { }) describe('core', () => { - it('It should handle a small evict', function () { + it('It should handle a small evict', () => { assert.strictEqual(cache.first.key, 'b', "Should be 'b'") assert.strictEqual(cache.last.key, 'e', "Should be 'e'") assert.strictEqual(cache.size, 4, "Should be '4'") @@ -247,7 +247,7 @@ describe('FifoObject', function () { assert.strictEqual(cache.size, 2, "Should be '2'") }) - it('It should handle an empty evict', function () { + it('It should handle an empty evict', () => { cache = new FifoObject(1) assert.strictEqual(cache.first, null, "Should be 'null'") assert.strictEqual(cache.last, null, "Should be 'null'") @@ -258,7 +258,7 @@ describe('FifoObject', function () { assert.strictEqual(cache.size, 0, "Should be 'null'") }) - it('It should expose expiration time', function () { + it('It should expose expiration time', () => { cache = new FifoObject(1, 6e4) cache.set(items[0], false) assert.strictEqual(typeof cache.expiresAt(items[0]), 'number', 'Should be a number') diff --git a/test/HitStatistics.spec.js b/test/HitStatistics.spec.js index d5b5e7e..de7ce7e 100644 --- a/test/HitStatistics.spec.js +++ b/test/HitStatistics.spec.js @@ -1,5 +1,5 @@ +import { afterEach, beforeEach, describe, expect, it, vitest } from 'vitest' import { HitStatistics } from '../src/HitStatistics.js' -import { it, describe, expect, beforeEach, afterEach, vitest } from 'vitest' import { HitStatisticsRecord } from '../src/HitStatisticsRecord.js' describe('HitStatistics', () => { diff --git a/test/HitStatisticsRecord.spec.js b/test/HitStatisticsRecord.spec.js index e2728e5..8e596ae 100644 --- a/test/HitStatisticsRecord.spec.js +++ b/test/HitStatisticsRecord.spec.js @@ -1,6 +1,6 @@ +import { describe, expect, it } from 'vitest' import { HitStatisticsRecord } from '../src/HitStatisticsRecord.js' import { getTimestamp } from '../src/utils/dateUtils.js' -import { it, describe, expect } from 'vitest' describe('HitStatisticsRecord', () => { describe('resetForCache', () => { diff --git a/test/LruMap.spec.js b/test/LruMap.spec.js index 9fb30bd..d25cf88 100644 --- a/test/LruMap.spec.js +++ b/test/LruMap.spec.js @@ -1,13 +1,13 @@ import assert from 'node:assert' -import { it, describe, beforeEach, expect } from 'vitest' +import { setTimeout } from 'timers/promises' +import { beforeEach, describe, expect, it } from 'vitest' import { LruMap } from '../src/LruMap.js' import { items, populateCache } from './utils/cachePopulator.js' -import { setTimeout } from 'timers/promises' -describe('LruMap', function () { +describe('LruMap', () => { let cache - beforeEach(function () { + beforeEach(() => { cache = new LruMap(4) populateCache(cache) }) @@ -33,7 +33,7 @@ describe('LruMap', function () { }) describe('evict', () => { - it('It should evict', function () { + it('It should evict', () => { expect(cache.first.key).toBe('b') expect(cache.last.key).toBe('e') expect(cache.size).toBe(4) @@ -143,7 +143,7 @@ describe('LruMap', function () { }) describe('delete', () => { - it('It should delete', function () { + it('It should delete', () => { expect(cache.first.key).toBe('b') expect(cache.last.key).toBe('e') expect(cache.size).toBe(4) @@ -193,7 +193,7 @@ describe('LruMap', function () { }) describe('deleteMany', () => { - it('It should delete', function () { + it('It should delete', () => { expect(cache.first.key).toBe('b') expect(cache.last.key).toBe('e') expect(cache.size).toBe(4) @@ -240,7 +240,7 @@ describe('LruMap', function () { }) describe('core', () => { - it('It should handle a small evict', function () { + it('It should handle a small evict', () => { assert.strictEqual(cache.first.key, 'b', "Should be 'b'") assert.strictEqual(cache.last.key, 'e', "Should be 'e'") assert.strictEqual(cache.size, 4, "Should be '4'") @@ -276,7 +276,7 @@ describe('LruMap', function () { assert.strictEqual(cache.size, 2, "Should be '2'") }) - it('It should handle an empty evict', function () { + it('It should handle an empty evict', () => { cache = new LruMap(1) assert.strictEqual(cache.first, null, "Should be 'null'") assert.strictEqual(cache.last, null, "Should be 'null'") diff --git a/test/LruObject.spec.js b/test/LruObject.spec.js index 042b4ad..c625139 100644 --- a/test/LruObject.spec.js +++ b/test/LruObject.spec.js @@ -1,13 +1,13 @@ import assert from 'node:assert' -import { it, describe, beforeEach, expect } from 'vitest' +import { setTimeout } from 'timers/promises' +import { beforeEach, describe, expect, it } from 'vitest' import { LruObject } from '../src/LruObject.js' import { items, populateCache } from './utils/cachePopulator.js' -import { setTimeout } from 'timers/promises' -describe('LruObject', function () { +describe('LruObject', () => { let cache - beforeEach(function () { + beforeEach(() => { cache = new LruObject(4) populateCache(cache) }) @@ -33,7 +33,7 @@ describe('LruObject', function () { }) describe('evict', () => { - it('It should evict', function () { + it('It should evict', () => { expect(cache.first.key).toBe('b') expect(cache.last.key).toBe('e') expect(cache.size).toBe(4) @@ -143,7 +143,7 @@ describe('LruObject', function () { }) describe('delete', () => { - it('It should delete', function () { + it('It should delete', () => { expect(cache.first.key).toBe('b') expect(cache.last.key).toBe('e') expect(cache.size).toBe(4) @@ -193,7 +193,7 @@ describe('LruObject', function () { }) describe('deleteMany', () => { - it('It should delete', function () { + it('It should delete', () => { expect(cache.first.key).toBe('b') expect(cache.last.key).toBe('e') expect(cache.size).toBe(4) @@ -240,7 +240,7 @@ describe('LruObject', function () { }) describe('core', () => { - it('It should handle a small evict', function () { + it('It should handle a small evict', () => { assert.strictEqual(cache.first.key, 'b', "Should be 'b'") assert.strictEqual(cache.last.key, 'e', "Should be 'e'") assert.strictEqual(cache.size, 4, "Should be '4'") @@ -276,7 +276,7 @@ describe('LruObject', function () { assert.strictEqual(cache.size, 2, "Should be '2'") }) - it('It should handle an empty evict', function () { + it('It should handle an empty evict', () => { cache = new LruObject(1) assert.strictEqual(cache.first, null, "Should be 'null'") assert.strictEqual(cache.last, null, "Should be 'null'") diff --git a/test/LruObjectHitStatistics.spec.js b/test/LruObjectHitStatistics.spec.js index c1917be..44f80af 100644 --- a/test/LruObjectHitStatistics.spec.js +++ b/test/LruObjectHitStatistics.spec.js @@ -1,13 +1,13 @@ -import { describe, expect, it } from 'vitest' -import { items, populateCache } from './utils/cachePopulator.js' -import { LruObjectHitStatistics } from '../src/LruObjectHitStatistics.js' import { setTimeout } from 'timers/promises' +import { describe, expect, it } from 'vitest' import { HitStatisticsRecord } from '../src/HitStatisticsRecord.js' +import { LruObjectHitStatistics } from '../src/LruObjectHitStatistics.js' import { getTimestamp } from '../src/utils/dateUtils.js' +import { items, populateCache } from './utils/cachePopulator.js' const timestamp = getTimestamp(new Date()) -describe('LruObjectHitStatistics', function () { +describe('LruObjectHitStatistics', () => { let cache1 describe('constructor validations', () => {