Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking Change: Be compatible with Prettier CLI #59

Merged
merged 5 commits into from May 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .all-contributorsrc
Expand Up @@ -102,6 +102,16 @@
"code",
"test"
]
},
{
"login": "tunnckoCore",
"name": "Charlike Mike Reagent",
"avatar_url": "https://avatars0.githubusercontent.com/u/5038030?v=3",
"profile": "https://i.am.charlike.online",
"contributions": [
"code",
"test"
]
}
]
}
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -9,7 +9,7 @@ CLI for [`prettier-eslint`][prettier-eslint]
[![downloads][downloads-badge]][npm-stat]
[![MIT License][license-badge]][LICENSE]

[![All Contributors](https://img.shields.io/badge/all_contributors-10-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Donate][donate-badge]][donate]
[![Code of Conduct][coc-badge]][coc]
Expand Down Expand Up @@ -183,7 +183,7 @@ Thanks goes to these people ([emoji key][emojis]):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[馃捇](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Code") [馃摉](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Documentation") [馃殗](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [鈿狅笍](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Tests") | [<img src="https://avatars3.githubusercontent.com/u/3266363?v=3" width="100px;"/><br /><sub>Adam Harris</sub>](https://github.com/aharris88)<br />[馃捇](https://github.com/prettier/prettier-eslint-cli/commits?author=aharris88 "Code") [馃摉](https://github.com/prettier/prettier-eslint-cli/commits?author=aharris88 "Documentation") [馃憖](#review-aharris88 "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/622118?v=3" width="100px;"/><br /><sub>Eric McCormick</sub>](https://ericmccormick.io)<br />[馃憖](#review-edm00se "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/12389411?v=3" width="100px;"/><br /><sub>Joel Sequeira</sub>](https://github.com/joelseq)<br />[馃摉](https://github.com/prettier/prettier-eslint-cli/commits?author=joelseq "Documentation") | [<img src="https://avatars.githubusercontent.com/u/103008?v=3" width="100px;"/><br /><sub>Frank Taillandier</sub>](https://frank.taillandier.me)<br /> | [<img src="https://avatars3.githubusercontent.com/u/292365?v=3" width="100px;"/><br /><sub>Adam Stankiewicz</sub>](http://sheerun.net)<br />[馃捇](https://github.com/prettier/prettier-eslint-cli/commits?author=sheerun "Code") | [<img src="https://avatars3.githubusercontent.com/u/487068?v=3" width="100px;"/><br /><sub>Stephen John Sorensen</sub>](http://www.stephenjohnsorensen.com/)<br />[馃捇](https://github.com/prettier/prettier-eslint-cli/commits?author=spudly "Code") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars0.githubusercontent.com/u/11560964?v=3" width="100px;"/><br /><sub>Gandem</sub>](https://github.com/Gandem)<br />[馃捇](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Code") [鈿狅笍](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Tests") | [<img src="https://avatars0.githubusercontent.com/u/129991?v=3" width="100px;"/><br /><sub>Matteo Ronchi</sub>](https://github.com/cef62)<br />[馃悰](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Acef62 "Bug reports") [馃捇](https://github.com/prettier/prettier-eslint-cli/commits?author=cef62 "Code") | [<img src="https://avatars2.githubusercontent.com/u/61787?v=3" width="100px;"/><br /><sub>Beno卯t Zugmeyer</sub>](https://github.com/BenoitZugmeyer)<br />[馃捇](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Code") [鈿狅笍](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Tests") |
| [<img src="https://avatars0.githubusercontent.com/u/11560964?v=3" width="100px;"/><br /><sub>Gandem</sub>](https://github.com/Gandem)<br />[馃捇](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Code") [鈿狅笍](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Tests") | [<img src="https://avatars0.githubusercontent.com/u/129991?v=3" width="100px;"/><br /><sub>Matteo Ronchi</sub>](https://github.com/cef62)<br />[馃悰](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Acef62 "Bug reports") [馃捇](https://github.com/prettier/prettier-eslint-cli/commits?author=cef62 "Code") | [<img src="https://avatars2.githubusercontent.com/u/61787?v=3" width="100px;"/><br /><sub>Beno卯t Zugmeyer</sub>](https://github.com/BenoitZugmeyer)<br />[馃捇](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Code") [鈿狅笍](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Tests") | [<img src="https://avatars0.githubusercontent.com/u/5038030?v=3" width="100px;"/><br /><sub>Charlike Mike Reagent</sub>](https://i.am.charlike.online)<br />[馃捇](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Code") [鈿狅笍](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Tests") |
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome!
Expand Down
14 changes: 9 additions & 5 deletions cli-test/tests/index.js
Expand Up @@ -4,6 +4,7 @@ import path from 'path'
import fs from 'fs'
import spawn from 'spawn-command'
import pify from 'pify'
import {oneLine} from 'common-tags'
import stripIndent from 'strip-indent'

const pWriteFile = pify(fs.writeFile)
Expand All @@ -27,10 +28,13 @@ test('help outputs usage information and flags', async () => {
expect(stdout).toContain('Options:\n')
// just a sanity check.
// If it's ever longer than 2000 then we've probably got a problem...
if (stdout.length > 2000) {
if (stdout.length > 4100) {
console.error(stdout)
throw new Error(
'We probably have a problem. The --help output is probably too long...',
oneLine`
We probably have a problem.
The --help output is probably too long (${stdout.length})...
`,
)
}
})
Expand All @@ -45,9 +49,9 @@ test('formats files and outputs to stdout', async () => {
stripIndent(
`
import baz, {stuff} from 'fdjakfdlfw-baz'

export {bazzy}

function bazzy(something) {
return baz(stuff(something))
}
Expand All @@ -58,7 +62,7 @@ test('formats files and outputs to stdout', async () => {
stripIndent(
`
export default foo

function foo(thing) {
return thing
}
Expand Down
4 changes: 2 additions & 2 deletions src/format-files.js
Expand Up @@ -37,15 +37,15 @@ function formatFilesFromArgv({
ignore: ignoreGlobs = [],
eslintIgnore: applyEslintIgnore = true,
prettierLast,
prettier,
...prettierOptions
}) {
logger.setLevel(logLevel)
const prettierESLintOptions = {
logLevel,
eslintPath,
prettierPath,
prettierLast,
prettierOptions: prettier,
prettierOptions,
}
const cliOptions = {write, listDifferent}
if (stdin) {
Expand Down
2 changes: 1 addition & 1 deletion src/format-files.test.js
Expand Up @@ -139,7 +139,7 @@ test('forwards prettierLast onto prettier-eslint', async () => {
test('forwards prettierOptions onto prettier-eslint', async () => {
await formatFiles({
_: ['src/**/1*.js'],
prettier: {trailingComma: 'es5'},
trailingComma: 'es5',
})
expect(formatMock).toHaveBeenCalledWith(
expect.objectContaining({prettierOptions: {trailingComma: 'es5'}}),
Expand Down
105 changes: 79 additions & 26 deletions src/parser.js
Expand Up @@ -2,16 +2,19 @@ import path from 'path'
import getLogger from 'loglevel-colored-level-prefix'
import findUp from 'find-up'
import yargs from 'yargs'
import {oneLine} from 'common-tags'
import {oneLine, stripIndent} from 'common-tags'
import arrify from 'arrify'
import camelcaseKeys from 'camelcase-keys'
import chalk from 'chalk'
import boolify from 'boolify'

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

const parser = yargs
.usage('Usage: $0 <globs>... [--option-1 option-1-value --option-2]')
.usage(
stripIndent`Usage: $0 <globs>... [--option-1 option-1-value --option-2]

Prefix an option with "no-" to set it to false, such as --no-semi to
disable semicolons and --no-eslint-ignore to disable default ignores.
`,
)
.help('h')
.alias('h', 'help')
.version()
Expand All @@ -21,7 +24,11 @@ const parser = yargs
describe: 'Edit the file in-place (beware!)',
type: 'boolean',
},
stdin: {default: false, describe: 'Read input via stdin', type: 'boolean'},
stdin: {
default: false,
describe: 'Read input via stdin',
type: 'boolean',
},
'eslint-ignore': {
default: true,
type: 'boolean',
Expand All @@ -39,12 +46,14 @@ const parser = yargs
from Prettier + Eslint formatting.
`,
},
eslintPath: {
// allow `--eslint-path` and `--eslintPath`
'eslint-path': {
default: getPathInHostNodeModules('eslint'),
describe: 'The path to the eslint module to use',
coerce: coercePath,
},
prettierPath: {
// allow `--prettier-path` and `--prettierPath`
'prettier-path': {
describe: 'The path to the prettier module to use',
default: getPathInHostNodeModules('prettier'),
coerce: coercePath,
Expand All @@ -68,13 +77,71 @@ const parser = yargs
default: false,
type: 'boolean',
},
prettier: {
'use-tabs': {
default: false,
type: 'boolean',
describe: 'Indent lines with tabs instead of spaces.',
},
'print-width': {
default: 80,
type: 'number',
describe: 'Specify the length of line that the printer will wrap on.',
},
'tab-width': {
default: 2,
type: 'number',
describe: 'Specify the number of spaces per indentation-level.',
},
'trailing-comma': {
default: 'none',
type: 'string',
describe: stripIndent`
Print trailing commas wherever possible.

Valid options:
- "none" - no trailing commas
- "es5" - trailing commas where valid in ES5 (objects, arrays, etc)
- "all" - trailing commas wherever possible (function arguments)
`,
},

'bracket-spacing': {
default: true,
type: 'boolean',
describe: stripIndent`Print spaces between brackets in object literals.
Can use --no-bracket-spacing for "false" to disable it.

Valid options:
- true - Example: { foo: bar }
- false - Example: {foo: bar}
`,
},
'jsx-bracket-same-line': {
default: false,
type: 'boolean',
describe: oneLine`
Prettier configuration options
to be passed to prettier-eslint
using dot-notation
Put the > of a multi-line JSX element at
the end of the last line instead of
being alone on the next line
`,
},
parser: {
default: 'babylon',
type: 'string',
describe: 'Specify which parser to use.',
},
semi: {
default: true,
type: 'boolean',
describe: stripIndent`Print semicolons at the ends of statements.
Can use --no-semi to be compatible with StandardJS.

Valid options:
- true - add a semicolon at the end of every statement
- false - only add semicolons at the beginning of lines
that may introduce ASI failures
`,
},
// TODO: if we allow people to to specify a config path,
// we need to read that somehow. These can come invarious
// formats and we'd have to work out `extends` somehow as well.
Expand All @@ -84,20 +151,6 @@ const parser = yargs
// describe: 'Path to the eslint config to use for eslint --fix',
// },
})
.coerce('prettier', config => {
if (typeof config === 'object') {
return boolify(camelcaseKeys(config))
} else {
throw Error(
chalk.red(
oneLine`
You should use dot-notation with
the --prettier flag, for example, --prettier.singleQuote
`,
),
)
}
})
.strict()

export default parser
Expand Down