From d5cc8b0a7645ec913b6b625abbb96b27150312b5 Mon Sep 17 00:00:00 2001 From: Taymoor Khan Date: Thu, 12 May 2022 01:39:53 -0700 Subject: [PATCH 1/2] feat: add support for Node 18 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 306108c..22a1756 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [14, 16] + node: [14, 16, 18] name: Node ${{ matrix.node }} steps: - uses: actions/checkout@v2 From 4d194990e7f1a929b4a00f968255f0a3b4b12bbb Mon Sep 17 00:00:00 2001 From: Taymoor Khan Date: Thu, 12 May 2022 01:40:12 -0700 Subject: [PATCH 2/2] refactor: switch from ramda to rambda --- benchmarks/measure.js | 5 +---- benchmarks/runtime.bench.js | 4 +--- lib/rules/handle-done-callback.js | 2 +- lib/rules/max-top-level-suites.js | 2 +- lib/rules/no-synchronous-tests.js | 3 +-- lib/util/ast.js | 7 +------ lib/util/memoizeWith.js | 28 ++++++++++++++++++++++++++ lib/util/names.js | 33 +++++++++++++++++-------------- package-lock.json | 24 ++++++++++------------ package.json | 2 +- 10 files changed, 63 insertions(+), 47 deletions(-) create mode 100644 lib/util/memoizeWith.js diff --git a/benchmarks/measure.js b/benchmarks/measure.js index d3717c4..06a7e49 100644 --- a/benchmarks/measure.js +++ b/benchmarks/measure.js @@ -2,10 +2,7 @@ const os = require('os'); const { performance: performanceHooks } = require('perf_hooks'); -const times = require('ramda/src/times'); -const median = require('ramda/src/median'); -const map = require('ramda/src/map'); -const prop = require('ramda/src/prop'); +const { times, median, map, prop } = require('rambda'); const semver = require('semver'); const [ { speed: cpuSpeed } ] = os.cpus(); diff --git a/benchmarks/runtime.bench.js b/benchmarks/runtime.bench.js index 41d1929..5290ff8 100644 --- a/benchmarks/runtime.bench.js +++ b/benchmarks/runtime.bench.js @@ -2,9 +2,7 @@ const { expect } = require('chai'); const { Linter } = require('eslint'); -const times = require('ramda/src/times'); -const toPairs = require('ramda/src/toPairs'); -const fromPairs = require('ramda/src/fromPairs'); +const { times, toPairs, fromPairs } = require('rambda'); const { runBenchmark, cpuSpeed, diff --git a/lib/rules/handle-done-callback.js b/lib/rules/handle-done-callback.js index 29a7d6b..242dbed 100644 --- a/lib/rules/handle-done-callback.js +++ b/lib/rules/handle-done-callback.js @@ -1,6 +1,6 @@ 'use strict'; -const find = require('ramda/src/find'); +const { find } = require('rambda'); const createAstUtils = require('../util/ast'); module.exports = { diff --git a/lib/rules/max-top-level-suites.js b/lib/rules/max-top-level-suites.js index c86cd8f..5465379 100644 --- a/lib/rules/max-top-level-suites.js +++ b/lib/rules/max-top-level-suites.js @@ -5,7 +5,7 @@ * @author Alexander Afanasyev */ -const isNil = require('ramda/src/isNil'); +const { isNil } = require('rambda'); const createAstUtils = require('../util/ast'); const defaultSuiteLimit = 1; diff --git a/lib/rules/no-synchronous-tests.js b/lib/rules/no-synchronous-tests.js index 77e9c71..dfe856a 100644 --- a/lib/rules/no-synchronous-tests.js +++ b/lib/rules/no-synchronous-tests.js @@ -1,7 +1,6 @@ 'use strict'; -const isNil = require('ramda/src/isNil'); -const find = require('ramda/src/find'); +const { isNil, find } = require('rambda'); const createAstUtils = require('../util/ast'); const asyncMethods = [ 'async', 'callback', 'promise' ]; diff --git a/lib/util/ast.js b/lib/util/ast.js index 3552d03..a731a51 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -1,11 +1,6 @@ 'use strict'; -const complement = require('ramda/src/complement'); -const both = require('ramda/src/both'); -const isNil = require('ramda/src/isNil'); -const propEq = require('ramda/src/propEq'); -const pathEq = require('ramda/src/pathEq'); -const find = require('ramda/src/find'); +const { complement, both, isNil, propEq, pathEq, find } = require('rambda'); const { getTestCaseNames, getSuiteNames } = require('./names'); const { getAddtionalNames } = require('./settings'); diff --git a/lib/util/memoizeWith.js b/lib/util/memoizeWith.js new file mode 100644 index 0000000..d9f5d27 --- /dev/null +++ b/lib/util/memoizeWith.js @@ -0,0 +1,28 @@ +/* eslint-disable prefer-rest-params */ +'use strict'; + +/** Memoize a function using a custom cache and a key formatter + * + * (rambda does not include a memoizeWith function) + * + * @param {Function} keyGen The function to generate the cache key. + * @param {Function} fn The function to memoize. + * @return {Function} Memoized version of `fn`. + */ +const memoizeWith = (keyGen, fn) => { + const cache = new Map(); + + return function () { + const key = keyGen(arguments); + + if (!cache.has(key)) { + cache.set(key, fn.apply(this, arguments)); + } + + return cache.get(key); + }; +}; + +module.exports = { + memoizeWith +}; diff --git a/lib/util/names.js b/lib/util/names.js index 229676b..04bbb2a 100644 --- a/lib/util/names.js +++ b/lib/util/names.js @@ -1,20 +1,22 @@ 'use strict'; -const where = require('ramda/src/where'); -const includes = require('ramda/src/includes'); -const intersection = require('ramda/src/intersection'); -const pipe = require('ramda/src/pipe'); -const isEmpty = require('ramda/src/isEmpty'); -const complement = require('ramda/src/complement'); -const flip = require('ramda/src/flip'); -const filter = require('ramda/src/filter'); -const over = require('ramda/src/over'); -const lensProp = require('ramda/src/lensProp'); -const map = require('ramda/src/map'); -const view = require('ramda/src/view'); -const assoc = require('ramda/src/assoc'); -const allPass = require('ramda/src/allPass'); -const memoizeWith = require('ramda/src/memoizeWith'); +const { + where, + includes, + intersection, + pipe, + isEmpty, + complement, + flip, + filter, + over, + lensProp, + map, + view, + assoc, + allPass +} = require('rambda'); +const { memoizeWith } = require('./memoizeWith'); const INTERFACES = { BDD: 'BDD', @@ -130,3 +132,4 @@ module.exports = { getTestCaseNames, getSuiteNames }; + diff --git a/package-lock.json b/package-lock.json index 9f87938..9f5cbbe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,11 +6,11 @@ "packages": { "": { "name": "eslint-plugin-mocha", - "version": "10.0.3", + "version": "10.0.4", "license": "MIT", "dependencies": { "eslint-utils": "^3.0.0", - "ramda": "^0.28.0" + "rambda": "^7.1.0" }, "devDependencies": { "chai": "^4.3.6", @@ -4634,14 +4634,10 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/ramda": { - "version": "0.28.0", - "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.28.0.tgz", - "integrity": "sha512-9QnLuG/kPVgWvMQ4aODhsBUFKOUmnbUnsSXACv+NCQZcHbeb+v8Lodp8OVxtRULN1/xOyYLLaL6npE6dMq5QTA==", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/ramda" - } + "node_modules/rambda": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/rambda/-/rambda-7.1.0.tgz", + "integrity": "sha512-HkqheuvgfSxj+Pyg4yT1fpX1KzPL9ghG5z5lAfbkwRcwIVx8P657MgrGWGaHRNI+j2Mr1d88AdHKgm8Qy0I10w==" }, "node_modules/randombytes": { "version": "2.1.0", @@ -9180,10 +9176,10 @@ "strict-uri-encode": "^2.0.0" } }, - "ramda": { - "version": "0.28.0", - "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.28.0.tgz", - "integrity": "sha512-9QnLuG/kPVgWvMQ4aODhsBUFKOUmnbUnsSXACv+NCQZcHbeb+v8Lodp8OVxtRULN1/xOyYLLaL6npE6dMq5QTA==" + "rambda": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/rambda/-/rambda-7.1.0.tgz", + "integrity": "sha512-HkqheuvgfSxj+Pyg4yT1fpX1KzPL9ghG5z5lAfbkwRcwIVx8P657MgrGWGaHRNI+j2Mr1d88AdHKgm8Qy0I10w==" }, "randombytes": { "version": "2.1.0", diff --git a/package.json b/package.json index a2fa5b8..c293d31 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ }, "dependencies": { "eslint-utils": "^3.0.0", - "ramda": "^0.28.0" + "rambda": "^7.1.0" }, "devDependencies": { "chai": "^4.3.6",