Skip to content

Commit

Permalink
📜 Eslint fixes for repo (#39)
Browse files Browse the repository at this point in the history
* 🔧 update eslint to enforce no semi-colon

* maple_leaf: repo lint fix

* 🍁 repo lint fix
  • Loading branch information
akashchouhan16 authored Nov 14, 2023
1 parent ad7c829 commit 60133c8
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
},
"ignorePatterns": ["/dist/", "/tests/", "/*.mjs"],
"rules": {
quotes: ["error", "double", { "allowTemplateLiterals": true }]
quotes: ["error", "double", { "allowTemplateLiterals": true }],
"semi": ["warn", "never"]
}
}
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ const config = {
bail: 1,
forceCoverageMatch: ["**/*.test.js"],
testEnvironment: "node",
};
}

module.exports = config;
module.exports = config
2 changes: 1 addition & 1 deletion src/config/cacheConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ let cacheConfig = {
keyCount: 0,
}

module.exports = cacheConfig;
module.exports = cacheConfig
10 changes: 5 additions & 5 deletions src/nodecache.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ class NodeCache {
}

if (!this.cache[key])
return false;
return false

const newTTL = Date.now() + Math.abs(ttl)
this.cache[key].ttl = newTTL
return true;
return true
}

async refresh() {
Expand Down Expand Up @@ -173,9 +173,9 @@ class NodeCache {
}

flush() {
cacheConfig.cacheHit = 0;
cacheConfig.cacheMiss = 0;
cacheConfig.keyCount = 0;
cacheConfig.cacheHit = 0
cacheConfig.cacheMiss = 0
cacheConfig.keyCount = 0
this.cache = {}
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Logger {

log(message, options = {}) {
if (!message || this.mode === "none")
return;
return
if (typeof message !== "string") {
if (typeof message === "object") {
message = JSON.stringify(message)
Expand All @@ -44,7 +44,7 @@ class Logger {
type: this.type,
path: this.path,
...options
};
}


const date = new Date().toLocaleString("en-US", this.formatOptions)
Expand Down
4 changes: 2 additions & 2 deletions src/worker/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* *****************************************
*/

const { parentPort, isMainThread, threadId } = require("worker_threads");
const { parentPort, isMainThread, threadId } = require("worker_threads")
// Listen for most recent cache context from the Main Thread.
if (!isMainThread) {
parentPort.on("message", ({ cache }) => {
Expand All @@ -13,7 +13,7 @@ if (!isMainThread) {
for (const [key, cacheItem] of Object.entries(cache)) {
if (cacheItem.ttl && Number(cacheItem.ttl) < Number(now)) {
// Send key with expired ttl to Main Thread for cache eviction.
parentPort.postMessage({ key });
parentPort.postMessage({ key })
}
}
} catch (error) {
Expand Down
20 changes: 10 additions & 10 deletions test/nodecache.config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const NodeCache = require("../index")

describe("NodeCache params for instance config", () => {
describe("StdTTL config checks", () => {
let cache;
let cache
afterEach(() => {
cache.close()
})
Expand Down Expand Up @@ -40,7 +40,7 @@ describe("NodeCache params for instance config", () => {
stdTTL: true
})
// expect the stdTTL to be 0 => Infinite.
cache.set("k1", "boolean-ttl-check");
cache.set("k1", "boolean-ttl-check")
expect(cache.cache["k1"]).toHaveProperty("ttl")
expect(cache.cache["k1"]).toMatchObject({
value: expect.anything(),
Expand All @@ -54,7 +54,7 @@ describe("NodeCache params for instance config", () => {
stdTTL: "15000" // 15seconds
})
// expect the stdTTL to be 0 => Infinite.
cache.set("k2", "string-ttl-check");
cache.set("k2", "string-ttl-check")
expect(cache.cache["k2"]).toHaveProperty("ttl")
expect(cache.cache["k2"]).toMatchObject({
value: expect.anything(),
Expand All @@ -68,7 +68,7 @@ describe("NodeCache params for instance config", () => {
stdTTL: NaN // falsy values: 0, false, null, undefined, NaN, ''
})
// expect the stdTTL to be 0 => Infinite.
cache.set("k3", "falsy-check");
cache.set("k3", "falsy-check")
expect(cache.cache["k3"]).toHaveProperty("ttl")
expect(cache.cache["k3"]).toMatchObject({
value: expect.anything(),
Expand All @@ -93,7 +93,7 @@ describe("NodeCache params for instance config", () => {
createAt: Date.now()
})

let { value } = cache.cache["key1"];
let { value } = cache.cache["key1"]

expect(value).not.toBeUndefined()
expect(value).toEqual(expect.any(String)) // not an object anymore
Expand All @@ -109,7 +109,7 @@ describe("NodeCache params for instance config", () => {
createAt: Date.now()
})

let { value } = cache.cache["key2"];
let { value } = cache.cache["key2"]

expect(value).not.toBeUndefined()
expect(value).toEqual(expect.any(Object))
Expand All @@ -125,7 +125,7 @@ describe("NodeCache params for instance config", () => {

test("maxKeys not provided, defaults to -1 (No Limit)", () => {
cache = new NodeCache()
let flag = true;
let flag = true
for (let i = 1; i <= 6; i++) {
let success = cache.set(i, `value-${i}`)
flag = flag & success
Expand Down Expand Up @@ -159,7 +159,7 @@ describe("NodeCache params for instance config", () => {
})
})
afterAll(() => {
cache.close();
cache.close()
})

test("NodeCache instance to be not null", () => {
Expand All @@ -180,7 +180,7 @@ describe("NodeCache params for instance config", () => {
describe("Custom Logger prompt check for the instance on mode = std", () => {

afterAll(() => {
cache.close();
cache.close()
})
let cache = new NodeCache({
mode: "std",
Expand Down Expand Up @@ -210,7 +210,7 @@ describe("NodeCache params for instance config", () => {
})
})
afterAll(() => {
cache.close();
cache.close()
})

test("Valid Instance with default params for logger", () => {
Expand Down
6 changes: 3 additions & 3 deletions test/nodecache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("NodeCache instance creation", () => {
cache = new NodeCache()
})
afterAll(() => {
cache.close();
cache.close()
})

test("NodeCache instance to be defined and not falsy", () => {
Expand Down Expand Up @@ -36,7 +36,7 @@ describe("NodeCache public APIs", () => {
})

afterAll(() => {
cache.close();
cache.close()
})

test("NodeCache::global", () => {
Expand All @@ -56,7 +56,7 @@ describe("NodeCache public APIs", () => {
1, "2", "key"
])
// expect(cache.global()).toEqual({ cacheHit: 2, cacheMiss: 1, keyCount: 2 })
cache.flush();
cache.flush()
expect(cache.global()).toEqual({ cacheHit: 0, cacheMiss: 0, keyCount: 0 })
})

Expand Down

0 comments on commit 60133c8

Please sign in to comment.