fisker Cheung
d4fd92e266
Bundle "Experimental CLI" ( #17396 )
2025-05-06 10:34:05 +08:00
fisker
9e2c61817a
Change default CLI to legacy
2025-02-19 00:21:29 +08:00
fisker
9c06bb2d01
Merge branch 'main' into cli-next
2025-02-19 00:14:32 +08:00
fisker Cheung
11520b714e
Use compile cache ( #16818 )
...
* Use compile cache
* Only enable for production
* Revert
2024-11-24 19:08:39 +09:00
fisker
d5cdb3560a
Renamed @prettier/cli
2023-11-30 14:37:41 +08:00
fisker Cheung
e8d787ce79
Use @prettier/next ( #15732 )
2023-11-30 13:34:09 +08:00
fisker Cheung
37139afeaa
Meta tweak ( #15331 )
2023-09-04 19:54:16 +08:00
fisker Cheung
2052ce5cb8
Bundle CLI as ES Module ( #13091 )
2022-08-11 14:08:08 +08:00
fisker Cheung
3cbee742a7
Add please-upgrade-node back to CLI ( #12448 )
2022-04-03 00:04:45 +08:00
fisker Cheung
be0739ec22
Add type:"module" to package.json ( #12272 )
2022-02-12 15:39:16 +08:00
fisker Cheung
491825dd9b
Migrate CLI to ES Module ( #11903 )
2022-02-11 09:56:58 +08:00
fisker Cheung
894f841fbd
Style: Enforce extensions ( #11227 )
2021-07-21 09:10:34 +08:00
164a6e2351
Switch CLI to async ( #10804 )
...
* Switch CLI to async
* Rewrite test
* Fix tests
* Comment out failed test
* Comment out failed test
* Fix test
Co-authored-by: Connor Peet <connor@peet.io >
* Update patterns-dirs.js
* Fix `hasRunningCli` flag
* Fix grammar
* Update tests/integration/runPrettier.js
Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com >
Co-authored-by: Connor Peet <connor@peet.io >
Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com >
2021-05-09 15:43:10 +03:00
Ika
c4e5463514
refactor(cli): separate files and make it pure as possible ( #2730 )
...
* refactor(bin): resolveConfig
* refactor(bin): getOptionsForFile
* refactor(bin): remove `mapSeries`
* refactor: move content from bin to src/cli
* refactor: wrap content with function
* refactor: move constants to another file
* refactor: move utils to another file
* refactor: move functions
* refactor: extract functions
* refactor: remove unnecessary variable
* refactor: move `src/cli` to `src` with prefix `cli`
* refactor: use template literal
* refactor: remove unnecessary variable
* refactor: extract `listDifferent`
* refactor: extract `format`
* refactor: change error message `Invalid configuration:`
* refactor: bind args with argv
* refactor: extract `getOptionsForFile`
* refactor: extract `formatStdin`
* refactor: extract `eachFilename`
* refactor: extract `formatFiles`
* refactor: remove unnecessary export
* refactor: use `globby.sync()`
* refactor: add `runPrettier.sync()` helper
* refactor: fix linting
* refactor: mock `process.argv`
* chore: use `--forceExit` to avoid process hanging
* refactor: mock `get-stream`
* refactor: remove unnecessary stuff
* refactor: fix linting
* refactor: wrap `run` with `try..catch.finally`
* refactor: restore `process.exitCode` after testing
2017-09-03 19:21:06 +10:00
Ika
8a6b56be41
refactor(bin): use resolveConfigFile.sync() ( #2728 )
...
* refactor(bin): resolveConfig
* refactor(bin): getOptionsForFile
* refactor(bin): remove `mapSeries`
2017-09-02 22:17:23 +10:00
Simon Lydell
7c9e589323
Fix CLI option parsing ( #2684 )
...
Fixes #2683
2017-08-29 08:16:04 +02:00
Simon Lydell
cd9ad2c57c
Clarify --trailing-comma a bit
...
Refs. #2655
2017-08-23 17:44:07 +02:00
Lucas Azzola
3eed1933e1
Don't pass config path through to cosmiconfig ( #2547 )
2017-07-27 21:59:57 +10:00
Jared Anderson
2d97f0d0cc
Add graphql to parser options in help output ( #2519 )
2017-07-19 18:33:39 +02:00
Evilebot Tnawi
c1874c70ea
refactor(cli): simplify ignore logic ( #2455 )
2017-07-12 00:36:16 +10:00
Lucas Azzola
1c806f81b2
Rename --resolve-config to --find-config-path ( #2453 )
2017-07-11 23:57:26 +10:00
Evilebot Tnawi
469059dc20
CLI: Support .ignore files ( #2412 )
...
Closes #2294
2017-07-11 23:33:46 +10:00
Lucas Azzola
25a5e3ffe3
Fix ignore unknown --no-semi, fixes #2448 ( #2450 )
2017-07-11 19:52:47 +10:00
Lucas Azzola
dcccfed366
Implement cosmiconfig for workspace configuration ( #2434 )
...
* Implement cosmiconfig
* Add resolveOptions API and extname support
* Add --resolve-config and --config, rename resolveOptions to resolveConfig
* Move color to top-level CLI options
* Fix unknown param warning
* Change from {} to null when no config is found
* Change override API to emulate eslint
* Add test for eslint-style overrides
* Delete overrides from resolveConfig
2017-07-10 22:26:36 +10:00
Simen Bekkhus
1b4846b67d
Format prettier with newer prettier ( #2431 )
2017-07-08 14:07:39 +02:00
Joseph Frazier
9290dd8803
Add some standardjs-esque eslint rules ( #2401 )
...
I experimented with simplifying the eslint config to just use eslint-config-standard and eslint-config-prettier. There were too many errors to make it a quick change, but I did find a few useful rules we could adopt instead.
---
* lint: Remove useless return statements
http://eslint.org/docs/rules/no-useless-return
* lint: Split declarations into multiple statements
http://eslint.org/docs/rules/one-var
* lint: Remove unneeded ternary operators
http://eslint.org/docs/rules/no-unneeded-ternary
* lint: Require symbol descriptions
http://eslint.org/docs/rules/symbol-description
* lint: Disallow declarations in nested blocks
http://eslint.org/docs/rules/no-inner-declarations
* lint: Disallow yoda conditions
http://eslint.org/docs/rules/yoda
* Revert "lint: Disallow yoda conditions"
See discussion at https://github.com/prettier/prettier/pull/2401#discussion_r125750068
This reverts commit f3b568d5bd48a742460cb0f805d1be38d8f61a40.
2017-07-05 16:54:46 -04:00
Joseph Frazier
16bc297572
Fix --debug-print-doc ( #2400 )
...
* Add test of --debug-print-doc
See https://github.com/prettier/prettier/issues/2396
* Pass test of --debug-print-doc
See https://github.com/prettier/prettier/issues/2396
2017-07-05 18:25:51 +02:00
Joseph Frazier
e82a774568
Make --list-different to work with --stdin ( #2393 )
...
* Add test for `prettier --stdin --list-different`
See https://github.com/prettier/prettier/issues/2389
* Pass test for `prettier --stdin --list-different`
This fixes https://github.com/prettier/prettier/issues/2389
* Deduplicate --list-different handling
* Exit-early to reduce nesting in listDifferent()
* Simplify condition in listDifferent()
2017-07-04 14:41:46 -04:00
Evilebot Tnawi
a0cadad222
feat(cli): support multiple patterns with ignore pattern ( #2356 )
2017-07-04 17:55:06 +02:00
Lucas Azzola
21f913cb6e
CLI: ignore node_modules with ./**-style glob, fixes #2110 ( #2185 )
2017-06-18 14:35:42 +10:00
Joseph Frazier
a42db30946
Add JSON support ( #2173 )
...
* Add JSON support
This fixes https://github.com/prettier/prettier/issues/1973 by using
[json-to-ast] to parse JSON, then converting the AST into a
mostly-Babylon AST, so as to piggyback on the existing printer logic.
Identifiers and literals are currently printed verbatim from the input,
but this could be improved upon later (at least for literals, not sure
about identifiers).
[json-to-ast]: https://github.com/vtrushin/json-to-ast
* Rename `json-to-ast` parser to `json`
See https://github.com/prettier/prettier/pull/2173#discussion_r122574644
* json: Use createError to have a pretty error
See https://github.com/prettier/prettier/pull/2173#discussion_r122574748
* json: Transform AST without mutations
See https://github.com/prettier/prettier/pull/2173#discussion_r122574690
2017-06-17 10:36:42 -10:00
Joseph Frazier
cb44125a21
Let prettier --stdin work with keyboard input ( #2147 )
...
This uses [get-stream] instead of [get-stdin], since the latter just
gives an empty string if process.stdin is a TTY
(see https://github.com/sindresorhus/get-stdin/issues/21 )
[get-stream]: https://github.com/sindresorhus/get-stream
[get-stdin]: https://github.com/sindresorhus/get-stdin
2017-06-15 09:57:29 +10:00
Lucas Azzola
364c38de0d
Implement custom parser API ( #1783 )
...
* feat(api): add custom parser API
* test(api): add integration test for parser resolution
* chore(api): fix build after resolving conflicts
* docs(api): document custom parser API
* docs(api): fix typo
* chore(build): add parse5 to build and support yarn test --prod
2017-06-12 16:51:12 +10:00
Lucas Azzola
d00956d51d
feat(html): add parse5/htmlparser2 printer ( #2083 )
2017-06-09 19:22:59 -07:00
Joseph Frazier
552ceb30e8
Allow --debug-check to work with stdin ( #2013 )
...
* Allow --debug-check to work with stdin
This makes it easier to quickly test formatting code snippets with e.g.
pbpaste | prettier --debug-check
Before, the following would happen:
$ pbpaste | prettier --debug-check
stdin: TypeError: Invalid data, chunk must be a string or buffer, not undefined
at WriteStream.Socket.write (net.js:693:11)
at writeOutput (/Users/josephfrazier/workspace/prettier/bin/prettier.js:375:18)
at getStdin.then.input (/Users/josephfrazier/workspace/prettier/bin/prettier.js:275:7)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:169:7)
$
Now, it looks like this:
$ pbpaste | prettier --debug-check
(stdin)
$
* Test that --debug-check still prints filenames
See https://github.com/prettier/prettier/pull/2013#discussion_r120499306
2017-06-06 16:10:24 -07:00
Philipp Spieß
d679f235ed
Also infer parser when using --list-different ( #1997 )
...
* Also infer parser when using `--list-different`
* Add integration tests for parser inference
2017-06-06 08:24:56 -07:00
Jon Wong
e33d6773d6
Adding support for graphql ( #1982 )
...
* Initial GraphQL implementation
This is the bare minimum amount of code to make graphql work. Turns out it's pretty easy to add support for other languages :)
* Fixing support for `graphql` parsing
There was a few structural changes with the addition of CSS and Typescript that we had to take into account.
* Fixing file glob, adding `graphql` to yarn.lock
* Removing extraneous file
* Adding `graphql` parser, style changes
* Splitting out graphql printer
* Removing merge conflict
* Fixing yarn.lock
* Addressing code review, using `createError`
* Adding release config
* Using exact version
* Removing destructuring
2017-06-05 12:34:08 -07:00
Christopher Chedeau
620119d9d4
Fix --debug-check ( #1916 )
...
This got broken with the cursor commit.
cc @josephfrazier, would be nice to add some end to end test here :)
2017-06-02 15:10:08 -07:00
Simen Bekkhus
6a2c964b22
Include typescript and postcss in parser help ( #1906 )
2017-06-02 13:42:20 -07:00
Joseph Frazier
4bfeb9064d
Add cursorOffset option for cursor translation ( #1637 )
...
* Add `formatWithCursor` API with `cursorOffset` option
This addresses https://github.com/prettier/prettier/issues/93 by
adding a new option, `cursorOffset`, that tells prettier to determine
the location of the cursor after the code has been formatted. This is
accessible through the API via a new function, `formatWithCursor`, which
returns a `{formatted: string, cursorOffset: ?number}`.
Here's a usage example:
```js
require("prettier").formatWithCursor(" 1", { cursorOffset: 2 });
// -> { formatted: '1;\n', cursorOffset: 1 }
```
* Add `--cursor-offset` CLI option
It will print out the offset instead of the formatted output. This
makes it easier to test. For example:
echo ' 1' | prettier --stdin --cursor-offset 2
# prints 1
* Add basic test of cursor translation
* Document `cursorOffset` option and `formatWithCursor()`
* Print translated cursor offset to stderr when --cursor-offset is given
This lets us continue to print the formatted code, while also
communicating the updated cursor position.
See https://github.com/prettier/prettier/pull/1637#discussion_r119735496
* doc-print cursor placeholder in comments.printComments()
See https://github.com/prettier/prettier/pull/1637#discussion_r119735149
* Compare array index to -1 instead of >= 0 to determine element presence
See https://github.com/prettier/prettier/pull/1637#discussion_r119736623
* Return {formatted, cursor} from printDocToString() instead of mutating options
See https://github.com/prettier/prettier/pull/1637#discussion_r119737354
2017-06-01 15:52:29 -07:00
Jake
5d63d34b77
Add an option to include "dot" directories. ( #1844 )
...
* Add an option to include "dot" directories.
We have some files in directories that start with a `.` that we want prettified. This PR adds the `include-dot-directories` flag to let the glob match dot directories.
* always include dot directories
2017-06-01 12:27:56 -07:00
Mitermayer Reis
8fdf398e27
Making cli infer parser based on filetype ( #1837 )
...
* Adding --stdin-filepath option in order to enable filetype inference from
stdin
* Making CLI auto infer parser based on filename passed
2017-05-31 14:42:04 -07:00
Mitermayer Reis
0d9b04bc94
Adding --stdin-filepath option in order to enable filetype inference … ( #1835 )
...
* Adding --stdin-filepath option in order to enable filetype inference from stdin to allow chosing css parser
* Adding readme information on the filepath option
* Also including support for typescript parser inference.
* Running linter
2017-05-31 12:26:22 -07:00
Christopher Chedeau
05b921efdd
Build the dist/ with rollup ( #1794 )
2017-05-28 21:49:41 -07:00
Christopher Chedeau
3d6acd8648
Fix log issue
2017-05-28 13:54:54 -07:00
Christopher Chedeau
882b712c5f
Update typescript-eslint ( #1787 )
...
It improves a few things.
2017-05-28 13:18:29 -07:00
Christopher Chedeau
78ba808322
Initial CSS support ( #1636 )
...
I wanted to see how hard it would be to add support for CSS inside of prettier. Turns out, it's not that hard. I spent a few hours printing post-css values and getting all the stylefmt unit tests to not throw.
2017-05-24 10:52:12 -07:00
Michał Pierzchała
3a431d3fe7
Document --with-node-modules flag ( #1701 )
2017-05-24 03:25:45 -07:00
Michał Pierzchała
7a0df958dc
Ignore node_modules when running prettier from CLI ( #1683 )
...
* Ignore node_modules by default
* Add integration test suite for --with-node-modules CLI arg
* Refactor tests to snapshots
* Disable eslint for purposely faulty files
* Fix node 4
* Fix prettier
* Gitignore only top-level node_modules
2017-05-23 14:19:04 -07:00
Joseph Frazier
330601c77d
Find nearest node when formatting range ( #1659 )
...
* Move range extension code into helper functions
* Add findNodeByOffset() helper
This was adapted from https://github.com/prettier/prettier/pull/1637/commits/cbc1929c64db558b4e444500bca3d2ce1d550359
* Test extending formatted range to entire node
* Fix extending formatted range to entire node
* Fix style errors
* Add run_file test function
This makes it possible to use different options on a per-file basis,
which is useful for things like range formatting tests.
* Test extending the format range to nearest parseable node
This means you can select the range of a `catch` clause, attempt to
format it, and have the `try` formatted as well, rather than throwing an
error.
* Fix extending the format range to nearest parseable node
This means you can select the range of a `catch` clause, attempt to
format it, and have the `try` formatted as well, rather than throwing an
error.
* Test that external indentation is left alone when formatting a range
* Preserve external indentation when formatting a range
* Dedupe range formatting traversal callbacks
* Simplify range formatting traversal using ast-types
See https://github.com/prettier/prettier/pull/1659#issuecomment-302974798
* Make range formatting traversal more efficient
There's less unnecessary parsing now.
* Fix style errors
* Add test where range expanding fails
* Fix test where range expanding fails
This makes sure that the range contains the entirety of the nodes
containing each of the range's endpoints.
* Add test for expanding range to beginning of line
* Pass test for expanding range to beginning of line
This makes it so that indentation before the range is added to the
formatted range.
* Don't parse/stringify AST to detect pre-range indentation
See https://github.com/prettier/prettier/pull/1659#discussion_r117790671
* When formatting a range, find closest statement rather than parsing
The `isStatement` implementation came from `docs/prettier.min.js`.
See https://github.com/prettier/prettier/pull/1659#issuecomment-303154770
* Add test for range-formatting a FunctionDeclaration's argument object
* Include FunctionDeclaration when searching for nearest node to range-format
From the spec, a Program is a series of SourceElements, each of which is
either a Statement or a FunctionDeclaration. See
https://www.ecma-international.org/ecma-262/5.1/#sec-A.5
* Remove unnecessary try-catch
See https://github.com/prettier/prettier/pull/1659#discussion_r117810096
* Add tests with multiple statements
See https://github.com/prettier/prettier/pull/1659#discussion_r117810753
* Remove unnecessary arguments from findNodeByOffset()
* Contract format range to ensure it starts/ends on nodes
* Specify test ranges in the fixtures
See https://github.com/prettier/prettier/pull/1659#discussion_r117811186
* Remove unnecessary comments from range fixtures
* Remove run_file test function
It's no longer used. This essentially reverts
8241216e68f2e0da997a4f558b03658d642c89a2
* Update range formatting docs
Clarify that the range expands to the nearest statement, and not to the
end of the line.
* Don't overwrite test options when detecting range
Now that multiple files share the same object again, we shouldn't be
re-assigning to it.
* Reuse already-read fixtures for AST_COMPARE=1 tests
* Remove `run_file` global from test eslintrc
* Undo package.json churn
`yarn` reformatted it before, but the whitespace visually sets off the
comment, so let's put it back how it was before.
See https://github.com/prettier/prettier/pull/1659#discussion_r117864655
* Remove misleading comments from isSourceElement
See https://github.com/prettier/prettier/pull/1659#discussion_r117865196
* Loop backwards through string instead of reversing it
See https://github.com/prettier/prettier/pull/1659#discussion_r117865759
* Don't recompute indent string when formatting range
See https://github.com/prettier/prettier/pull/1659#discussion_r117867268
* Rename findNodeByOffset to findNodeAtOffset
"Find x by y" is the common usage for finding an `x` by a key `y`.
However, since "by" has positional meaning, let's use "at" instead.
See https://github.com/prettier/prettier/pull/1659#discussion_r117865121
* Always trimRight() in formatRange and explain why
See https://github.com/prettier/prettier/pull/1659#discussion_r117864635
* Test formatting a range that crosses AST levels
See https://github.com/prettier/prettier/pull/1659#issuecomment-303243688
* Fix formatting a range that crosses AST levels
See https://github.com/prettier/prettier/pull/1659#issuecomment-303243688
* Remove unnecessary try-catch
See https://github.com/prettier/prettier/pull/1659/files/e52db5e9f9ec4af599f658da03739e206dd4578c#r117878763
* Add test demonstrating range formatting indent detection
* Detect alignment from text on line before range, but don't reformat it
This avoids reformatting non-indentation that happens to precede the
range on the same line, while still correctly indenting the range based
on it.
See https://github.com/prettier/prettier/pull/1659#discussion_r117881430
2017-05-23 07:43:58 -07:00