diff --git a/packages/eslint-plugin-sui/src/rules/commonjs.js b/packages/eslint-plugin-sui/src/rules/commonjs.js index 88d6dacf0..6192539d7 100644 --- a/packages/eslint-plugin-sui/src/rules/commonjs.js +++ b/packages/eslint-plugin-sui/src/rules/commonjs.js @@ -52,7 +52,7 @@ module.exports = { const isModule = node.callee?.object?.name === 'module' && node.callee?.property?.name === 'require' const isRequireFormCreateRequire = node.parent?.parent?.body - ?.filter(node => node.type === 'ImportDeclaration') + ?.filter?.(node => node.type === 'ImportDeclaration') ?.some( node => node.source?.value === 'module' && node.specifiers?.some(spec => spec.imported?.name === 'createRequire') diff --git a/packages/eslint-plugin-sui/src/utils/monorepo.js b/packages/eslint-plugin-sui/src/utils/monorepo.js index 5522d4880..775cce383 100644 --- a/packages/eslint-plugin-sui/src/utils/monorepo.js +++ b/packages/eslint-plugin-sui/src/utils/monorepo.js @@ -7,7 +7,8 @@ class MonoRepo { static create(root) { if (instance) return instance - return new MonoRepo(root) + instance = new MonoRepo(root) + return instance } constructor(root) { @@ -25,8 +26,20 @@ class MonoRepo { return this._root } + belongSamePackage(filePath, relativeImport) { + return ( + path.normalize(filePath)?.replace(this.root, '')?.split('/')?.at(1) === + path + .normalize(path.dirname(filePath) + '/' + relativeImport) + ?.replace(this.root, '') + ?.split('/') + ?.at(1) + ) + } + isPackage(filePath, relativeImport) { if (!relativeImport.startsWith('../')) return false + if (this.belongSamePackage(filePath, relativeImport)) return false const pkgName = path .normalize(path.dirname(filePath) + '/' + relativeImport)