Skip to content

Commit d22f7df

Browse files
committed
feat: add option to configure standard via rc config file
1 parent 460f258 commit d22f7df

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports.linter = Linter
55
var deglob = require('deglob')
66
var os = require('os')
77
var path = require('path')
8-
var pkgConf = require('pkg-conf')
8+
var { cosmiconfigSync } = require('cosmiconfig')
99

1010
var HOME_OR_TMP = os.homedir() || os.tmpdir()
1111

@@ -151,8 +151,10 @@ Linter.prototype.parseOpts = function (opts) {
151151
? opts.usePackageJson
152152
: true
153153

154+
var explorerRes = cosmiconfigSync(self.cmd).search(opts.cwd)
155+
154156
var packageOpts = usePackageJson
155-
? pkgConf.sync(self.cmd, { cwd: opts.cwd })
157+
? explorerRes ? explorerRes.config : {}
156158
: {}
157159

158160
if (!opts.ignore) opts.ignore = []
@@ -175,7 +177,7 @@ Linter.prototype.parseOpts = function (opts) {
175177
if (self.customParseOpts) {
176178
var rootDir
177179
if (usePackageJson) {
178-
var filePath = pkgConf.filepath(packageOpts)
180+
var filePath = explorerRes && explorerRes.filepath
179181
rootDir = filePath ? path.dirname(filePath) : opts.cwd
180182
} else {
181183
rootDir = opts.cwd

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
"test": "standard && tape test/clone.js test/api.js"
3535
},
3636
"dependencies": {
37+
"cosmiconfig": "^6.0.0",
3738
"deglob": "^4.0.1",
3839
"get-stdin": "^7.0.0",
39-
"minimist": "^1.2.5",
40-
"pkg-conf": "^3.1.0"
40+
"minimist": "^1.2.5"
4141
},
4242
"devDependencies": {
4343
"babel-eslint": "^10.1.0",

test/api.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
var path = require('path')
12
var eslint = require('eslint')
23
var Linter = require('../').linter
3-
var path = require('path')
44
var test = require('tape')
55

66
function getStandard () {
@@ -12,6 +12,16 @@ function getStandard () {
1212
})
1313
}
1414

15+
function getStandardRcConfig () {
16+
return new Linter({
17+
cwd: path.resolve(__dirname, 'lib'),
18+
cmd: 'pocketlint',
19+
version: '0.0.0',
20+
eslint: eslint,
21+
eslintConfig: require('../tmp/standard/options').eslintConfig
22+
})
23+
}
24+
1525
test('api: lintFiles', function (t) {
1626
t.plan(3)
1727
var standard = getStandard()
@@ -55,3 +65,11 @@ test('api: parseOpts -- avoid self.eslintConfig global mutation', function (t) {
5565
t.deepEqual(opts.globals, ['what'])
5666
t.deepEqual(standard.eslintConfig.globals, [])
5767
})
68+
69+
test('api: parseOpts -- load config from rc file', function (t) {
70+
t.plan(2)
71+
var standard = getStandardRcConfig()
72+
var opts = standard.parseOpts()
73+
t.deepEqual(opts.globals, undefined)
74+
t.deepEqual(opts.eslintConfig.globals, ['foorc'])
75+
})

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)