Skip to content

Commit

Permalink
feat(packages/eslint-plugin-sui): several fixes
Browse files Browse the repository at this point in the history
* Really use the class as singleton

 * avoid missleading warning when the relative import is for

the same package
  • Loading branch information
carlosvillu committed May 7, 2024
1 parent 07cd08b commit 5906840
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/eslint-plugin-sui/src/rules/commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
15 changes: 14 additions & 1 deletion packages/eslint-plugin-sui/src/utils/monorepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 5906840

Please sign in to comment.