Skip to content

Commit

Permalink
fixed hasOwnProperty conditional for import/paths setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Hargrove committed Feb 7, 2018
1 parent 815abf0 commit 275c6c7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ function getDependencies(context, packageDir) {
peerDependencies: {},
}

if (Object.prototype.hasOwnProperty(context.settings, 'import/paths')) {
if (Object.prototype.hasOwnProperty.call(context.settings, 'import/paths')) {
paths.push(
...context.settings['import/paths']
.map(path.resolve)
.map((dir) => path.resolve(dir))
)
}

Expand Down
14 changes: 11 additions & 3 deletions tests/src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ ruleTester.run('no-extraneous-dependencies', rule, {
test({
code: 'import react from "react";',
options: [{packageDir: packageDirMonoRepoWithNested}],
// filename: path.join(process.cwd(), 'foo.spec.js'),
}),
test({
code: 'import leftpad from "left-pad";',
options: [{packageDir: packageDirMonoRepoWithNested}],
settings: { 'import/paths': [packageDirMonoRepoRoot] },
// filename: path.join(process.cwd(), 'foo.spec.js'),
}),
test({
code: 'import leftpad from "left-pad";',
Expand All @@ -97,7 +95,17 @@ ruleTester.run('no-extraneous-dependencies', rule, {
invalid: [
test({
code: 'import "not-a-dependency"',
options: [{packageDir: packageDirMonoRepoWithNested}],
filename: path.join(packageDirMonoRepoRoot, 'foo.js'),
settings: { 'import/paths': [packageDirMonoRepoRoot] },
errors: [{
ruleId: 'no-extraneous-dependencies',
message: '\'not-a-dependency\' should be listed in the project\'s dependencies. Run \'npm i -S not-a-dependency\' to add it',
}],
}),
test({
code: 'import "not-a-dependency"',
filename: path.join(packageDirMonoRepoWithNested, 'foo.js'),
options: [{packageDir: packageDirMonoRepoRoot}],
settings: { 'import/paths': [packageDirMonoRepoRoot] },
errors: [{
ruleId: 'no-extraneous-dependencies',
Expand Down

0 comments on commit 275c6c7

Please sign in to comment.