Skip to content

Commit 5a3cd56

Browse files
committed
feat: add option to configure standard via rc config file
1 parent f2f766e commit 5a3cd56

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
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
@@ -7,10 +7,10 @@
77
"url": "https://github.com/flet/standard-engine/issues"
88
},
99
"dependencies": {
10+
"cosmiconfig": "^6.0.0",
1011
"deglob": "^4.0.0",
1112
"get-stdin": "^7.0.0",
12-
"minimist": "^1.1.0",
13-
"pkg-conf": "^3.1.0"
13+
"minimist": "^1.1.0"
1414
},
1515
"devDependencies": {
1616
"babel-eslint": "^10.0.2",

test/api.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var path = require('path')
12
var eslint = require('eslint')
23
var Linter = require('../').linter
34
var test = require('tape')
@@ -11,6 +12,16 @@ function getStandard () {
1112
})
1213
}
1314

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+
1425
test('api: lintFiles', function (t) {
1526
t.plan(3)
1627
var standard = getStandard()
@@ -54,3 +65,11 @@ test('api: parseOpts -- avoid self.eslintConfig global mutation', function (t) {
5465
t.deepEqual(opts.globals, ['what'])
5566
t.deepEqual(standard.eslintConfig.globals, [])
5667
})
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)