Skip to content

Commit

Permalink
[New] no-extraneous-dependencies: check both the absolute and relat…
Browse files Browse the repository at this point in the history
…ive filename.

Fixes import-js#602.
  • Loading branch information
ljharb committed Oct 18, 2016
1 parent d9605a0 commit 2ba174d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs'
import path from 'path'
import pkgUp from 'pkg-up'
import minimatch from 'minimatch'
import importType from '../core/importType'
Expand Down Expand Up @@ -78,7 +79,10 @@ function testConfig(config, filename) {
return config
}
// Array of globs.
return config.some(c => minimatch(filename, c))
return config.some(c => (
minimatch(filename, c) ||
minimatch(filename, path.join(process.cwd(), c))
))
}

module.exports = {
Expand Down
28 changes: 28 additions & 0 deletions tests/src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@ ruleTester.run('no-extraneous-dependencies', rule, {
options: [{devDependencies: ['*.spec.js']}],
filename: 'foo.spec.js',
}),
test({
code: 'import chai from "chai"',
options: [{devDependencies: ['*.spec.js']}],
filename: path.join(process.cwd(), 'foo.spec.js'),
}),
test({
code: 'import chai from "chai"',
options: [{devDependencies: ['*.test.js', '*.spec.js']}],
filename: 'foo.spec.js',
}),
test({
code: 'import chai from "chai"',
options: [{devDependencies: ['*.test.js', '*.spec.js']}],
filename: path.join(process.cwd(), 'foo.spec.js'),
}),
test({ code: 'require(6)' }),
],
invalid: [
Expand Down Expand Up @@ -109,6 +119,15 @@ ruleTester.run('no-extraneous-dependencies', rule, {
message: '\'chai\' should be listed in the project\'s dependencies, not devDependencies.',
}],
}),
test({
code: 'import chai from "chai"',
options: [{devDependencies: ['*.test.js']}],
filename: path.join(process.cwd(), 'foo.tes.js'),
errors: [{
ruleId: 'no-extraneous-dependencies',
message: '\'chai\' should be listed in the project\'s dependencies, not devDependencies.',
}],
}),
test({
code: 'import chai from "chai"',
options: [{devDependencies: ['*.test.js', '*.spec.js']}],
Expand All @@ -118,6 +137,15 @@ ruleTester.run('no-extraneous-dependencies', rule, {
message: '\'chai\' should be listed in the project\'s dependencies, not devDependencies.',
}],
}),
test({
code: 'import chai from "chai"',
options: [{devDependencies: ['*.test.js', '*.spec.js']}],
filename: path.join(process.cwd(), 'foo.tes.js'),
errors: [{
ruleId: 'no-extraneous-dependencies',
message: '\'chai\' should be listed in the project\'s dependencies, not devDependencies.',
}],
}),
test({
code: 'var eslint = require("lodash.isarray")',
options: [{optionalDependencies: false}],
Expand Down

0 comments on commit 2ba174d

Please sign in to comment.