Skip to content

Commit da0fe1b

Browse files
committed
Fix 'require-dependency' rule for non workspace files
1 parent 3d2c772 commit da0fe1b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/rules/require-dependency.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ module.exports.meta = {
1212

1313
module.exports.create = context =>
1414
getImport(context, ({ node, value, path }) => {
15-
const {
16-
dependencies,
17-
devDependencies,
18-
name: currentPackage,
19-
} = packages.find(({ location }) =>
15+
const currentPackage = packages.find(({ location }) =>
2016
isSubPath(location, context.getFilename()),
2117
);
2218

19+
if (!currentPackage) return;
20+
21+
const { dependencies, devDependencies } = currentPackage;
22+
2323
packages.forEach(({ name, location }) => {
2424
if (
25-
name !== currentPackage &&
25+
name !== currentPackage.name &&
2626
(isSubPath(name, value) || isSubPath(location, path)) &&
2727
!Object.keys(dependencies).includes(name) &&
2828
!Object.keys(devDependencies).includes(name)

tests/rules/require-dependency.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ ruleTester.run('require-dependency', rule, {
99
filename: '/test/another-workspace/index.js',
1010
code: "import '../workspace';",
1111
},
12+
{
13+
filename: '/index.js',
14+
code: "import '../workspace';",
15+
},
1216
],
1317
invalid: [
1418
{

0 commit comments

Comments
 (0)