Skip to content

Commit

Permalink
Fix wrong error for relative imports (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
jj-ivx committed Oct 8, 2021
1 parent 048ad5d commit 8b214e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/rules/no-relative-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ module.exports.meta = {
module.exports.create = (context) =>
getImport(context, ({ node, path, start, end, currentPackage }) => {
packages.forEach(({ name, location }) => {
if (name !== currentPackage.name && isSubPath(location, path)) {
if (
name !== path &&
name !== currentPackage.name &&
isSubPath(location, path)
) {
context.report({
node,
messageId: 'noRelativeImports',
Expand Down
4 changes: 4 additions & 0 deletions tests/rules/no-relative-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ ruleTester.run('no-relative-imports', rule, {
"import '@test/workspace';",
"import '../some/relative/path';",
'someFunction();',
{
filename: '/test/workspace/test.js',
code: "import 'root';",
},
{
filename: '/test/workspace/test.js',
code: "import '../workspace';",
Expand Down
4 changes: 4 additions & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ mock('@joshuajaco/get-monorepo-packages', () => [
name: '@test/scoped-workspace',
},
},
{
location: 'root',
package: { name: 'root' },
},
]);

0 comments on commit 8b214e0

Please sign in to comment.