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

perf: 72 times faster to check no-unused-selector #285

Merged
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
5 changes: 5 additions & 0 deletions .changeset/warm-cooks-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-vue-scoped-css": patch
---

Improve `no-unused-selector` performance
15 changes: 15 additions & 0 deletions lib/styles/context/vue-components/find-vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ function getVueComponentObject(
return null;
}

const vueComponentCache = new WeakMap<
RuleContext,
{ component: AST.ESLintObjectExpression | null; cachedAt: number }
>();

/**
* Find Vue component of the current file.
* @param {RuleContext} context The ESLint rule context object.
Expand All @@ -63,6 +68,11 @@ function getVueComponentObject(
function findVueComponent(
context: RuleContext
): AST.ESLintObjectExpression | null {
const cached = vueComponentCache.get(context);
if (cached !== undefined && cached.cachedAt > Date.now() - 1000) {
return cached.component;
}

const sourceCode = context.getSourceCode();
const componentComments = sourceCode
.getAllComments()
Expand Down Expand Up @@ -118,6 +128,11 @@ function findVueComponent(
// noop
},
});

vueComponentCache.set(context, {
component: result,
cachedAt: Date.now(),
});
return result;
}

Expand Down