Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New] no-extraneous-dependencies: check both the absolute and relative filename #630

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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