Skip to content

Commit

Permalink
feat: add option to configure standard via rc config file
Browse files Browse the repository at this point in the history
  • Loading branch information
TillaTheHun0 committed Mar 25, 2020
1 parent f2f766e commit e812986
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports.linter = Linter
var deglob = require('deglob')
var os = require('os')
var path = require('path')
var pkgConf = require('pkg-conf')
var { cosmiconfigSync } = require('cosmiconfig')

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

Expand Down Expand Up @@ -151,8 +151,10 @@ Linter.prototype.parseOpts = function (opts) {
? opts.usePackageJson
: true

var explorerRes = cosmiconfigSync(self.cmd).search(opts.cwd)

var packageOpts = usePackageJson
? pkgConf.sync(self.cmd, { cwd: opts.cwd })
? explorerRes ? explorerRes.config : {}
: {}

if (!opts.ignore) opts.ignore = []
Expand All @@ -175,7 +177,7 @@ Linter.prototype.parseOpts = function (opts) {
if (self.customParseOpts) {
var rootDir
if (usePackageJson) {
var filePath = pkgConf.filepath(packageOpts)
var filePath = explorerRes && explorerRes.filepath
rootDir = filePath ? path.dirname(filePath) : opts.cwd
} else {
rootDir = opts.cwd
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"url": "https://github.com/flet/standard-engine/issues"
},
"dependencies": {
"cosmiconfig": "^6.0.0",
"deglob": "^4.0.0",
"get-stdin": "^7.0.0",
"minimist": "^1.1.0",
"pkg-conf": "^3.1.0"
"minimist": "^1.1.0"
},
"devDependencies": {
"babel-eslint": "^10.0.2",
Expand Down
19 changes: 19 additions & 0 deletions test/api.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var path = require('path')
var eslint = require('eslint')
var Linter = require('../').linter
var test = require('tape')
Expand All @@ -11,6 +12,16 @@ function getStandard () {
})
}

function getStandardRcConfig () {
return new Linter({
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)
var standard = getStandard()
Expand Down Expand Up @@ -54,3 +65,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'])
})
3 changes: 3 additions & 0 deletions test/lib/.pocketlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
globals: ['foorc']
}

0 comments on commit e812986

Please sign in to comment.