Skip to content

Commit 632fef0

Browse files
committed
feat: add option to configure standard via rc config file
1 parent b695a02 commit 632fef0

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ module.exports.linter = Linter
55

66
const os = require('os')
77
const path = require('path')
8-
const pkgConf = require('pkg-conf')
98
const fs = require('fs')
9+
const { cosmiconfigSync } = require('cosmiconfig')
1010

1111
const CACHE_HOME = require('xdg-basedir').cache || os.tmpdir()
1212

@@ -151,9 +151,12 @@ Linter.prototype.parseOpts = function (opts) {
151151
let packageOpts = {}
152152
let rootPath = null
153153

154+
// try default search places up to ~
155+
const explorerRes = cosmiconfigSync(self.cmd).search(opts.cwd)
156+
154157
if (opts.usePackageJson || opts.useGitIgnore) {
155-
packageOpts = pkgConf.sync(self.cmd, { cwd: opts.cwd })
156-
const packageJsonPath = pkgConf.filepath(packageOpts)
158+
packageOpts = explorerRes ? explorerRes.config : {}
159+
const packageJsonPath = explorerRes && explorerRes.filepath
157160
if (packageJsonPath) rootPath = path.dirname(packageJsonPath)
158161
}
159162

@@ -202,7 +205,7 @@ Linter.prototype.parseOpts = function (opts) {
202205
if (self.customParseOpts) {
203206
let rootDir
204207
if (opts.usePackageJson) {
205-
const filePath = pkgConf.filepath(packageOpts)
208+
const filePath = explorerRes.filepath
206209
rootDir = filePath ? path.dirname(filePath) : opts.cwd
207210
} else {
208211
rootDir = opts.cwd

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
"test": "standard && tape test/clone.js test/api.js"
3939
},
4040
"dependencies": {
41+
"cosmiconfig": "^7.0.0",
4142
"get-stdin": "^8.0.0",
4243
"minimist": "^1.2.5",
43-
"pkg-conf": "^3.1.0",
4444
"xdg-basedir": "^4.0.0"
4545
},
4646
"devDependencies": {

test/api.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ function getStandard () {
1212
})
1313
}
1414

15+
function getStandardRcConfig () {
16+
return new Linter({
17+
// start in dir containing rc file
18+
cwd: path.resolve(__dirname, 'lib'),
19+
cmd: 'pocketlint',
20+
version: '0.0.0',
21+
eslint: eslint,
22+
eslintConfig: require('../tmp/standard/options').eslintConfig
23+
})
24+
}
25+
1526
test('api: lintFiles', function (t) {
1627
t.plan(3)
1728
const standard = getStandard()
@@ -55,3 +66,11 @@ test('api: parseOpts -- avoid self.eslintConfig global mutation', function (t) {
5566
t.deepEqual(opts.globals, ['what'])
5667
t.deepEqual(standard.eslintConfig.globals, [])
5768
})
69+
70+
test('api: parseOpts -- load config from rc file', function (t) {
71+
t.plan(2)
72+
var standard = getStandardRcConfig()
73+
var opts = standard.parseOpts()
74+
t.deepEqual(opts.globals, undefined)
75+
t.deepEqual(opts.eslintConfig.globals, ['foorc'])
76+
})

test/lib/.pocketlintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
globals: ['foorc']
3+
}

0 commit comments

Comments
 (0)