Skip to content

Commit

Permalink
Ignore workspaces without names
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuajaco committed Jun 10, 2023
1 parent 302a28b commit 307781a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/no-absolute-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports.create = (context) => {
const filename = context.getFilename();
return getImport(workspaces, filename, ({ node, path, start, end }) => {
workspaces.forEach(({ package: { name }, location }) => {
if (isSubPath(location, filename) && isSubPath(name, path)) {
if (name && isSubPath(location, filename) && isSubPath(name, path)) {
context.report({
node,
messageId: "noAbsoluteImports",
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-cross-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module.exports.create = (context) => {
)
.forEach(({ package: { name }, location }) => {
if (
name &&
name !== currentWorkspace.package.name &&
(isSubPath(name, value) || isSubPath(location, path))
) {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/require-dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports.create = (context) => {
currentWorkspace.package;

if (
name &&
name !== currentWorkspace.package.name &&
(isSubPath(name, value) || isSubPath(location, path)) &&
!Object.keys(dependencies).includes(name) &&
Expand Down
6 changes: 6 additions & 0 deletions tests/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ module.exports.findWorkspacesMock = () => [
name: "@test/scoped-workspace",
},
},
{
location: "/test/undefined-workspace",
package: {
name: undefined,
},
},
{
location: "root",
package: { name: "root" },
Expand Down
4 changes: 4 additions & 0 deletions tests/rules/no-absolute-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ describe("no-absolute-imports", () => {
code: "import workspace from '@test/workspace';",
filename: "/some/path.js",
},
{
code: "import '@test/undefined-workspace';",
filename: "/test/undefined-workspace/some/path.js",
},
],

invalid: [
Expand Down

0 comments on commit 307781a

Please sign in to comment.