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
Merged

fmt: respect prettierrc and prettierignore #3346

merged 13 commits into from
Nov 16, 2019

Conversation

axetroy
Copy link
Contributor

@axetroy 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 axetroy changed the title respect prettierrc/prettierignore for deno fmt fmt: respect prettierrc/prettierignore Nov 14, 2019
cli/flags.rs Show resolved Hide resolved
break;
case ".yml":
case ".yaml":
// TODO: Unimplemented loading yaml / yml configuration file yet.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 changed the title [WIP] fmt: respect prettierrc/prettierignore fmt: respect prettierrc/prettierignore Nov 16, 2019
@axetroy
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref #3355

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ry ry merged commit cb00fd6 into denoland:master Nov 16, 2019
@axetroy axetroy deleted the prettier_config branch November 16, 2019 16:51
bartlomieju pushed a commit to bartlomieju/deno that referenced this pull request Dec 28, 2019
@oscrx
Copy link

oscrx commented May 24, 2020

A small headsup for people ending up here while searching for a way to modify deno fmt behaviour. Prettier seems to no longer be used: #3820

caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 21, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 24, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Jan 31, 2021
caspervonb pushed a commit to caspervonb/deno_std that referenced this pull request Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deno fmt ignores .prettierrc.json file
3 participants