diff --git a/index.js b/index.js index f75b348..07a7da9 100644 --- a/index.js +++ b/index.js @@ -5,8 +5,8 @@ module.exports.linter = Linter const os = require('os') const path = require('path') -const pkgConf = require('pkg-conf') const fs = require('fs') +const { cosmiconfigSync } = require('cosmiconfig') const CACHE_HOME = require('xdg-basedir').cache || os.tmpdir() @@ -151,9 +151,12 @@ Linter.prototype.parseOpts = function (opts) { let packageOpts = {} let rootPath = null + // try default search places up to ~ + const explorerRes = cosmiconfigSync(self.cmd).search(opts.cwd) + if (opts.usePackageJson || opts.useGitIgnore) { - packageOpts = pkgConf.sync(self.cmd, { cwd: opts.cwd }) - const packageJsonPath = pkgConf.filepath(packageOpts) + packageOpts = explorerRes ? explorerRes.config : {} + const packageJsonPath = explorerRes && explorerRes.filepath if (packageJsonPath) rootPath = path.dirname(packageJsonPath) } @@ -202,7 +205,7 @@ Linter.prototype.parseOpts = function (opts) { if (self.customParseOpts) { let rootDir if (opts.usePackageJson) { - const filePath = pkgConf.filepath(packageOpts) + const filePath = explorerRes.filepath rootDir = filePath ? path.dirname(filePath) : opts.cwd } else { rootDir = opts.cwd diff --git a/package.json b/package.json index 454e807..ec8b1d5 100644 --- a/package.json +++ b/package.json @@ -38,10 +38,9 @@ "test": "standard && tape test/clone.js test/api.js" }, "dependencies": { + "cosmiconfig": "^7.0.0", "get-stdin": "^8.0.0", - "minimist": "^1.2.5", - "pkg-conf": "^3.1.0", - "xdg-basedir": "^4.0.0" + "minimist": "^1.2.5" }, "devDependencies": { "cross-spawn": "^7.0.3", diff --git a/test/api.js b/test/api.js index a09c0c2..258430b 100644 --- a/test/api.js +++ b/test/api.js @@ -12,6 +12,17 @@ function getStandard () { }) } +function getStandardRcConfig () { + return new Linter({ + // start in dir containing rc file + cwd: path.resolve(__dirname, 'lib'), + cmd: 'pocketlint', + version: '0.0.0', + eslint: eslint, + eslintConfig: require('../tmp/standard/options').eslintConfig + }) +} + test('api: lintFiles', function (t) { t.plan(3) const standard = getStandard() @@ -55,3 +66,11 @@ test('api: parseOpts -- avoid self.eslintConfig global mutation', function (t) { t.deepEqual(opts.globals, ['what']) t.deepEqual(standard.eslintConfig.globals, []) }) + +test('api: parseOpts -- load config from rc file', function (t) { + t.plan(2) + var standard = getStandardRcConfig() + var opts = standard.parseOpts() + t.deepEqual(opts.globals, undefined) + t.deepEqual(opts.eslintConfig.globals, ['foorc']) +}) diff --git a/test/lib/.pocketlintrc.js b/test/lib/.pocketlintrc.js new file mode 100644 index 0000000..61ed106 --- /dev/null +++ b/test/lib/.pocketlintrc.js @@ -0,0 +1,3 @@ +module.exports = { + globals: ['foorc'] +} \ No newline at end of file