Skip to content

Commit

Permalink
fix: remov default values for eslintPath and prettierPath (#93)
Browse files Browse the repository at this point in the history
* Removed default values for eslintPath and prettierPath

These values are not required by prettier-eslint-cli itself. They
are only passed to prettier-eslint, and even then, they're optional.
When using npm >3, passing the default value is optional, since
the node_modules directory is flattened, but for npm 2.x, the
default assumptions don't work.

People should be running npm >3 today, but for CI scenarios, npm 2
or downwards can still be used in combination with node 4.x (which
is going to be supported for a long time still).

In any case, not passing a default value seems to align better with
node's require algorithm - it will start where it needs to start
(in this case wherever the prettier-eslint dependency has been
installed), and then mimick find-up's logic.

* Removed superfluous imports
  • Loading branch information
fredrikekelund authored and Kent C. Dodds committed Aug 20, 2017
1 parent 87c0cf1 commit 8ffe4ad
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import path from 'path'
import getLogger from 'loglevel-colored-level-prefix'
import findUp from 'find-up'
import yargs from 'yargs'
import {oneLine, stripIndent} from 'common-tags'
import arrify from 'arrify'

const logger = getLogger({prefix: 'prettier-eslint-cli'})

const parser = yargs
.usage(
stripIndent`
Expand Down Expand Up @@ -49,7 +45,6 @@ const parser = yargs
},
// allow `--eslint-path` and `--eslintPath`
'eslint-path': {
default: getPathInHostNodeModules('eslint'),
describe: 'The path to the eslint module to use',
coerce: coercePath,
},
Expand All @@ -61,7 +56,6 @@ const parser = yargs
// allow `--prettier-path` and `--prettierPath`
'prettier-path': {
describe: 'The path to the prettier module to use',
default: getPathInHostNodeModules('prettier'),
coerce: coercePath,
},
ignore: {
Expand Down Expand Up @@ -160,23 +154,6 @@ const parser = yargs

export default parser

function getPathInHostNodeModules(module) {
logger.debug(`Looking for a local installation of the module "${module}"`)
const modulePath = findUp.sync(`node_modules/${module}`)

if (modulePath) {
return modulePath
}
logger.debug(
oneLine`
Local installation of "${module}" not found,
looking again starting in "${__dirname}"
`,
)

return findUp.sync(`node_modules/${module}`, {cwd: __dirname})
}

function coercePath(input) {
return path.isAbsolute(input) ? input : path.join(process.cwd(), input)
}

0 comments on commit 8ffe4ad

Please sign in to comment.