Skip to content

Commit

Permalink
Replace ESLint with Biome (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad committed Jan 31, 2024
1 parent 6f983ce commit 866a7df
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 95 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

23 changes: 0 additions & 23 deletions .eslintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 0 additions & 8 deletions .prettierrc.json

This file was deleted.

12 changes: 7 additions & 5 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
30 changes: 30 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -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 }
Expand Down
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/LruObjectHitStatistics.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions test/FifoMap.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
Expand All @@ -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)
Expand Down Expand Up @@ -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'")
Expand Down Expand Up @@ -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'")
Expand Down Expand Up @@ -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'")
Expand Down Expand Up @@ -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'")
Expand All @@ -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')
Expand Down
20 changes: 10 additions & 10 deletions test/FifoObject.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
Expand All @@ -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)
Expand Down Expand Up @@ -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'")
Expand Down Expand Up @@ -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'")
Expand Down Expand Up @@ -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'")
Expand Down Expand Up @@ -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'")
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion test/HitStatistics.spec.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/HitStatisticsRecord.spec.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
18 changes: 9 additions & 9 deletions test/LruMap.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'")
Expand Down Expand Up @@ -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'")
Expand Down

0 comments on commit 866a7df

Please sign in to comment.