Skip to content

Commit

Permalink
Look for linters in dependencies as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike authored and Mike Engel committed Jul 25, 2016
1 parent 2206cb6 commit 3ad0cb2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Custom parsers currently supported:
## Settings

### checkStyleDevDependencies (default: false)
Check code style in package.json `devDependencies`. If a valid style is not found it won't lint.
Check code style in package.json `devDependencies` or `dependencies`. If a valid style is not found it won't lint.

> Note: This will use the nearest package.json.
Expand Down
2 changes: 1 addition & 1 deletion lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
checkStyleDevDependencies: {
type: 'boolean',
title: 'Check for standard',
description: 'Only run if standard, semistandard or happiness present in package.json `devDependencies`',
description: 'Only run if standard, semistandard or happiness present in package.json `devDependencies` or `dependencies`',
default: false
},
honorStyleSettings: {
Expand Down
12 changes: 7 additions & 5 deletions lib/utils/select-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,32 @@ function getStyleThroughDevDeps (filePath) {
var options = { cwd: filePath, root: 'devDependencies', cache: false }
var noStyle = { cmd: 'no-style' }
var devDeps = pkgConfig(null, options)
var prodDeps = pkgConfig(null, Object.assign({}, options, { root: 'dependencies' }))

// No devDependencies found
if (!devDeps) return noStyle

// Check if there are linters defined in
// package.json devDependencies
var knownLinters = ['standard', 'semistandard', 'happiness', 'uber-standard']
var foundLinters = intersection(Object.keys(devDeps), knownLinters)
var hasKnownLinter = Boolean(foundLinters.length)
var foundDevLinters = intersection(Object.keys(devDeps), knownLinters)
var foundProdLinters = intersection(Object.keys(prodDeps), knownLinters)
var hasKnownLinter = Boolean(foundDevLinters.length) || Boolean(foundProdLinters.length)
if (hasKnownLinter) {
var dir = dirname(filePath)

// standard style
if (devDeps.standard) {
if (devDeps.standard || prodDeps.standard) {
return pickStandard('standard', dir)
}

// happiness style
if (devDeps.happiness) {
if (devDeps.happiness || prodDeps.happiness) {
return pickStandard('happiness', dir)
}

// uber-standard
if (devDeps['uber-standard']) {
if (devDeps['uber-standard'] || prodDeps['uber-standard']) {
return pickStandard('uber-standard', dir)
}

Expand Down

0 comments on commit 3ad0cb2

Please sign in to comment.