Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Replace usage of lodash with cache set #29

Merged
merged 1 commit into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/shared/deprecation-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//------------------------------------------------------------------------------

const path = require("path");
const lodash = require("lodash");

//------------------------------------------------------------------------------
// Private
Expand All @@ -28,6 +27,8 @@ const deprecationWarningMessages = {
"projects in order to avoid loading '~/.eslintrc.*' accidentally."
};

const sourceFileErrorCache = new Set();

/**
* Emits a deprecation warning containing a given filepath. A new deprecation warning is emitted
* for each unique file path, but repeated invocations with the same file path have no effect.
Expand All @@ -36,7 +37,14 @@ const deprecationWarningMessages = {
* @param {string} errorCode The warning message to show.
* @returns {void}
*/
const emitDeprecationWarning = lodash.memoize((source, errorCode) => {
function emitDeprecationWarning(source, errorCode) {
const cacheKey = JSON.stringify({ source, errorCode });

if (sourceFileErrorCache.has(cacheKey)) {
return;
}
sourceFileErrorCache.add(cacheKey);

const rel = path.relative(process.cwd(), source);
const message = deprecationWarningMessages[errorCode];

Expand All @@ -45,7 +53,7 @@ const emitDeprecationWarning = lodash.memoize((source, errorCode) => {
"DeprecationWarning",
errorCode
);
}, (...args) => JSON.stringify(args));
}

//------------------------------------------------------------------------------
// Public Interface
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"ignore": "^4.0.6",
"import-fresh": "^3.2.1",
"js-yaml": "^3.13.1",
"lodash": "^4.17.20",
"minimatch": "^3.0.4",
"strip-json-comments": "^3.1.1"
},
Expand Down