Skip to content

Commit 3774544

Browse files
authored
chore(eslint): speed up no-imports-from-self rule by ensuring cache is used (#11483)
Our `no-imports-from-self` eslint rule was supposed to cache the package.json name to ensure it doesn't try to find and read the package.json for every single import statement. Turns out that cache was never used. Credits to @etrepum for [finding this issue](facebook/lexical#7272 (comment))
1 parent cd29978 commit 3774544

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

packages/eslint-plugin/customRules/no-imports-from-self.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export const rule = {
1818
return {
1919
ImportDeclaration(node) {
2020
const importPath = node.source.value
21-
const pkgName = getPackageName(context, packageName)
22-
if (pkgName && importPath.startsWith(pkgName)) {
21+
packageName = getPackageName(context, packageName)
22+
if (packageName && importPath.startsWith(packageName)) {
2323
context.report({
2424
node,
25-
message: `Package "${pkgName}" should not import from itself. Use relative instead.`,
25+
message: `Package "${packageName}" should not import from itself. Use relative instead.`,
2626
})
2727
}
2828
},
@@ -41,8 +41,7 @@ function getPackageName(context, packageName) {
4141
return packageName
4242
}
4343

44-
const fileName = context.getFilename()
45-
const pkg = findNearestPackageJson(path.dirname(fileName))
44+
const pkg = findNearestPackageJson(path.dirname(context.filename))
4645
if (pkg) {
4746
return pkg.name
4847
}

0 commit comments

Comments
 (0)