Skip to content

Commit

Permalink
[Fix] detect extraneous deps even when there are none in the first place
Browse files Browse the repository at this point in the history
Fixes #1161
  • Loading branch information
ljharb committed Aug 17, 2018
1 parent 5931141 commit b0b6125
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 1 addition & 5 deletions src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,7 @@ module.exports = {
create: function (context) {
const options = context.options[0] || {}
const filename = context.getFilename()
const deps = getDependencies(context, options.packageDir)

if (!deps) {
return {}
}
const deps = getDependencies(context, options.packageDir) || extractDepFields({})

const depsOptions = {
allowDevDeps: testConfig(options.devDependencies, filename) !== false,
Expand Down
10 changes: 10 additions & 0 deletions tests/src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const packageFileWithSyntaxErrorMessage = (() => {
const packageDirWithFlowTyped = path.join(__dirname, '../../files/with-flow-typed')
const packageDirMonoRepoRoot = path.join(__dirname, '../../files/monorepo')
const packageDirMonoRepoWithNested = path.join(__dirname, '../../files/monorepo/packages/nested-package')
const packageDirWithEmpty = path.join(__dirname, '../../files/empty')

ruleTester.run('no-extraneous-dependencies', rule, {
valid: [
Expand Down Expand Up @@ -263,5 +264,14 @@ ruleTester.run('no-extraneous-dependencies', rule, {
message: "'react' should be listed in the project's dependencies. Run 'npm i -S react' to add it",
}],
}),
test({
code: 'import "react";',
filename: path.join(packageDirWithEmpty, 'index.js'),
options: [{packageDir: packageDirWithEmpty}],
errors: [{
ruleId: 'no-extraneous-dependencies',
message: "'react' should be listed in the project's dependencies. Run 'npm i -S react' to add it",
}],
}),
]
})

0 comments on commit b0b6125

Please sign in to comment.