diff --git a/src/rules/no-extraneous-dependencies.js b/src/rules/no-extraneous-dependencies.js index a14bb611d6..b7955bb9a8 100644 --- a/src/rules/no-extraneous-dependencies.js +++ b/src/rules/no-extraneous-dependencies.js @@ -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' @@ -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 = { diff --git a/tests/src/rules/no-extraneous-dependencies.js b/tests/src/rules/no-extraneous-dependencies.js index 1a743b545d..8bb632d017 100644 --- a/tests/src/rules/no-extraneous-dependencies.js +++ b/tests/src/rules/no-extraneous-dependencies.js @@ -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: [ @@ -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']}], @@ -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}],