diff --git a/.all-contributorsrc b/.all-contributorsrc
index 1cc7fbd..aae37f7 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -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"
+ ]
}
]
}
diff --git a/README.md b/README.md
index 36e4f53..158e4b2 100644
--- a/README.md
+++ b/README.md
@@ -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]
@@ -183,7 +183,7 @@ Thanks goes to these people ([emoji key][emojis]):
| [
Kent C. Dodds](https://kentcdodds.com)
[๐ป](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") | [
Adam Harris](https://github.com/aharris88)
[๐ป](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") | [
Eric McCormick](https://ericmccormick.io)
[๐](#review-edm00se "Reviewed Pull Requests") | [
Joel Sequeira](https://github.com/joelseq)
[๐](https://github.com/prettier/prettier-eslint-cli/commits?author=joelseq "Documentation") | [
Frank Taillandier](https://frank.taillandier.me)
| [
Adam Stankiewicz](http://sheerun.net)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=sheerun "Code") | [
Stephen John Sorensen](http://www.stephenjohnsorensen.com/)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=spudly "Code") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
-| [
Gandem](https://github.com/Gandem)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Tests") | [
Matteo Ronchi](https://github.com/cef62)
[๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Acef62 "Bug reports") [๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=cef62 "Code") | [
Benoรฎt Zugmeyer](https://github.com/BenoitZugmeyer)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Tests") |
+| [
Gandem](https://github.com/Gandem)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Tests") | [
Matteo Ronchi](https://github.com/cef62)
[๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Acef62 "Bug reports") [๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=cef62 "Code") | [
Benoรฎt Zugmeyer](https://github.com/BenoitZugmeyer)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Tests") | [
Charlike Mike Reagent](https://i.am.charlike.online)
[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Tests") |
This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome!
diff --git a/cli-test/tests/index.js b/cli-test/tests/index.js
index cee8234..7653c6e 100644
--- a/cli-test/tests/index.js
+++ b/cli-test/tests/index.js
@@ -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)
@@ -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})...
+ `,
)
}
})
@@ -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))
}
@@ -58,7 +62,7 @@ test('formats files and outputs to stdout', async () => {
stripIndent(
`
export default foo
-
+
function foo(thing) {
return thing
}
diff --git a/src/format-files.js b/src/format-files.js
index c6b497c..5b9805e 100644
--- a/src/format-files.js
+++ b/src/format-files.js
@@ -37,7 +37,7 @@ function formatFilesFromArgv({
ignore: ignoreGlobs = [],
eslintIgnore: applyEslintIgnore = true,
prettierLast,
- prettier,
+ ...prettierOptions
}) {
logger.setLevel(logLevel)
const prettierESLintOptions = {
@@ -45,7 +45,7 @@ function formatFilesFromArgv({
eslintPath,
prettierPath,
prettierLast,
- prettierOptions: prettier,
+ prettierOptions,
}
const cliOptions = {write, listDifferent}
if (stdin) {
diff --git a/src/format-files.test.js b/src/format-files.test.js
index 54e389d..edb1dc6 100644
--- a/src/format-files.test.js
+++ b/src/format-files.test.js
@@ -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'}}),
diff --git a/src/parser.js b/src/parser.js
index db3e01b..e77cb21 100644
--- a/src/parser.js
+++ b/src/parser.js
@@ -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 ... [--option-1 option-1-value --option-2]')
+ .usage(
+ stripIndent`Usage: $0 ... [--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()
@@ -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',
@@ -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,
@@ -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.
@@ -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