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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt: respect prettierrc and prettierignore #3346

Merged
merged 13 commits into from Nov 16, 2019

Conversation

@axetroy
Copy link
Contributor

axetroy commented Nov 14, 2019

close #3276

Docs

https://prettier.io/docs/en/configuration.html

https://prettier.io/docs/en/ignore.html

Goal

  • Respect prettierrc file by default
    • .prettierrc.json
    • .prettierrc.yaml
    • .prettierrc.yml
    • .prettierrc.js
    • .prettierrc.ts
    • prettier.config.js
    • prettier.config.ts
    • .prettierrc.toml
  • Load the specified prettierrc file
./target/release/deno fmt *.ts --prettierrc=./path/to/.prettierrc.json
  • Respect prettierignore file by default
./target/release/deno fmt *.ts --ignore-path=./path/to/.prettierignore

What's new?

1. add --prettierrc flag for deno fmt

with optional value: auto/disable/filepath.

auto: Auto detect prettier configuration file in current working dir.
disable: Disable load configuration file.
filepath: Load specified prettier configuration file. support .json/.toml/.js/.ts file

Defaults to auto

2. add --ignore-path flag for deno fmt

with optional value: auto/disable/filepath.

auto: Auto detect .pretierignore file in current working dir.
disable: Disable load .prettierignore file.
filepath: Load specified prettier ignore file.

Defaults to auto

Current deno fmt --help output

$ ./target/release/deno fmt --help
deno-fmt 
Auto-format JavaScript/TypeScript source code using Prettier

Automatically downloads Prettier dependencies on first run.

  deno fmt myfile1.ts myfile2.ts

USAGE:
    deno fmt [OPTIONS] <files>...

OPTIONS:
        --arrow-parens=<avoid|always>
            Include parentheses around a sole arrow function parameter. [possible values: avoid, always]

    -c, --config <FILE>                                  
            Load tsconfig.json configuration file

        --current-thread                                 
            Use tokio::runtime::current_thread

        --end-of-line=<auto|lf|crlf|cr>
            Which end of line characters to apply. [possible values: auto, lf, crlf, cr]

    -h, --help                                           
            Prints help information

        --ignore-path=<auto|disable|FILE>
            Path to a file containing patterns that describe files to ignore.
              auto: Auto detect .pretierignore file in current working dir.
              disable: Disable load .prettierignore file.
              FILE: Load specified prettier ignore file.
              [default: auto]
        --importmap <FILE>                               
            Load import map file
            Specification: https://wicg.github.io/import-maps/
            Examples: https://github.com/WICG/import-maps#the-import-map
        --jsx-bracket-same-line
            Put the > of a multi-line JSX element at the end of the last line
            instead of being alone on the next line (does not apply to self closing elements).
        --jsx-single-quote                               
            Use single quotes instead of double quotes in JSX.

        --lock <FILE>                                    
            Check the specified lock file

        --lock-write                                     
            Write lock file. Use with --lock.

    -L, --log-level <log-level>                          
            Set log level [possible values: debug, info]

        --no-bracket-spacing                             
            Print spaces between brackets in object literals.

        --no-semi                                        
            Print semicolons at the ends of statements.

        --prettierrc=<auto|disable|FILE>
            Specify the configuration file of the prettier.
              auto: Auto detect prettier configuration file in current working dir.
              disable: Disable load configuration file.
              FILE: Load specified prettier configuration file. support .json/.toml/.js/.ts file
              [default: auto]
        --print-width=<int>                              
            Specify the line length that the printer will wrap on.

        --prose-wrap=<always|never|preserve>             
            How to wrap prose. [possible values: always, never, preserve]

        --quote-props=<as-needed|consistent|preserve>
            Change when properties in objects are quoted. [possible values: as-needed, consistent, preserve]

    -r, --reload=<CACHE_BLACKLIST>                       
            Reload source code cache (recompile TypeScript)
                      --reload
                        Reload everything
                      --reload=https://deno.land/std
                        Reload all standard modules
                      --reload=https://deno.land/std/fs/utils.ts,https://deno.land/std/fmt/colors.ts
                        Reloads specific modules
        --seed <NUMBER>                                  
            Seed Math.random()

        --single-quote                                   
            Use single quotes instead of double quotes.

        --stdout                                         
            Output formated code to stdout

        --tab-width=<int>                                
            Specify the number of spaces per indentation-level.

        --trailing-comma                                 
            Print trailing commas wherever possible when multi-line.

        --use-tabs                                       
            Indent lines with tabs instead of spaces.

        --v8-flags=<v8-flags>                            
            Set V8 command line options

        --v8-options                                     
            Print V8 command line options


ARGS:
    <files>...    
            
axetroy added 2 commits Nov 14, 2019
@axetroy axetroy changed the title respect prettierrc/prettierignore for deno fmt fmt: respect prettierrc/prettierignore Nov 14, 2019
axetroy added 3 commits Nov 14, 2019
fix
cli/flags.rs Show resolved Hide resolved
break;
case ".yml":
case ".yaml":
// TODO: Unimplemented loading yaml / yml configuration file yet.

This comment has been minimized.

Copy link
@axetroy

axetroy Nov 15, 2019

Author Contributor

There are currently no libraries for yml parser in std.

@axetroy axetroy changed the title fmt: respect prettierrc/prettierignore [WIP] fmt: respect prettierrc/prettierignore Nov 15, 2019
@axetroy axetroy force-pushed the axetroy:prettier_config branch 2 times, most recently from 402ab18 to d7b2d36 Nov 15, 2019
@axetroy axetroy force-pushed the axetroy:prettier_config branch from d7b2d36 to 84288aa Nov 15, 2019
@axetroy axetroy changed the title [WIP] fmt: respect prettierrc/prettierignore fmt: respect prettierrc/prettierignore Nov 16, 2019
@axetroy

This comment has been minimized.

Copy link
Contributor Author

axetroy commented Nov 16, 2019

/cc @ry I think it is ready for review.

@axetroy axetroy changed the title fmt: respect prettierrc/prettierignore fmt: respect prettierrc and prettierignore Nov 16, 2019
try {
const output = await import(
// TODO: Remove platform condition
// after https://github.com/denoland/deno/issues/3355 fixed

This comment has been minimized.

Copy link
@axetroy

axetroy Nov 16, 2019

Author Contributor

ref #3355

std/prettier/main.ts Show resolved Hide resolved
std/prettier/main.ts Show resolved Hide resolved
@ry
ry approved these changes Nov 16, 2019
Copy link
Collaborator

ry left a comment

LGTM

@ry ry merged commit cb00fd6 into denoland:master Nov 16, 2019
7 checks passed
7 checks passed
test macOS-latest
Details
test windows-2019
Details
test ubuntu-16.04
Details
test_debug ubuntu-16.04
Details
bench ubuntu-16.04
Details
lint ubuntu-16.04
Details
license/cla Contributor License Agreement is signed.
Details
@axetroy axetroy deleted the axetroy:prettier_config branch Nov 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.