profile
viewpoint
Prettier prettier https://prettier.io Prettier is an opinionated code formatter

prettier/prettier 36672

Prettier is an opinionated code formatter.

prettier/prettier-vscode 3304

Visual Studio Code extension for Prettier

prettier/prettier-eslint 2930

Code :arrow_right: prettier :arrow_right: eslint --fix :arrow_right: Formatted Code :sparkles:

prettier/eslint-config-prettier 2213

Turns off all rules that are unnecessary or might conflict with Prettier.

prettier/eslint-plugin-prettier 1518

ESLint plugin for Prettier formatting

prettier/tslint-config-prettier 1122

Use TSLint with Prettier without any conflict

prettier/plugin-php 1079

Prettier PHP Plugin

prettier/vim-prettier 1076

A Vim plugin for Prettier

prettier/plugin-ruby 837

Prettier Ruby Plugin

prettier/prettier-atom 737

An atom package for the prettier formatter.

startedprettier/prettier-chrome-extension

started time in 14 minutes

issue commentprettier/eslint-plugin-prettier

error Delete `·` prettier/prettier in a fresh Nuxt.js app with Prettier and Eslint

@phen0menon thanks for this solution it's saved my day!

jedrekdomanski

comment created time in 19 minutes

pull request commentprettier/prettier

Fix: don't wrap arrays in `test.each` template strings

Thanks for your help and patience, @thorn0 I have submitted the last commit with the changelog regarding this PR.

yogmel

comment created time in 34 minutes

fork AleksanderBodurri/prettier

Prettier is an opinionated code formatter.

https://prettier.io

fork in an hour

issue openedprettier/prettier-vscode

Java source code formatting stopped working (prettier 5.0.0)

Summary

prettier stopped working when set as default formatter in Settings / Text Editor / Formatting. I had to reset default formatter to none in order to bring back original Java source code formatting. I did not check whether problem happens on Java files only or also on some other files. Prettier generally throws an error: "Extension 'Prettier - Code formatter' can not format 'src\main\java...\file.java'". Short summary of what is going on or to provide context.

Github Repository to Reproduce Issue

Missing

Steps To Reproduce:

Install latest VSCode and latest extensions, enable prettier as default formatter

Expected result

Java source code formatted on "Format Source" action.

Actual result

No formatting happens - error "Extension 'Prettier - Code formatter' can not format 'src\main\java...\file.java'".

Additional information

VS Code Version: 1.51.1

Prettier Extension Version: 5.0.0

OS and version: Windows 10 Build 18363

Other VScode exentsions - note I am syncing settings (code-settings-sync v3.4.3 (latest)): azds v2.0.220200601 azure-account v0.8.11 code-settings-sync v3.4.3 csharp v1.22.0 dot v0.0.1 EditorConfig v0.15.1 fontawesome-autocomplete v1.0.1 ginfuru-vscode-jekyll-syntax v0.1.1 gitdownloadazurerepos v1.0.9 githistory v0.6.5 gitlens v10.2.1 Go v0.14.3 graphviz-preview v1.4.0 java v0.62.0 java-properties v0.0.2 mssql v1.9.0 plantuml v2.13.11 prettier-vscode v5.0.0 remote-containers v0.117.1 remote-ssh v0.51.0 remote-ssh-edit v0.51.0 remote-wsl v0.44.2 ruby v0.27.0 shopify-liquid v2.3.0 spellright v3.0.50 vscode-aks-tools v0.0.4 vscode-boot-dev-pack v0.0.8 vscode-checkstyle v1.3.3 vscode-concourse v1.18.0 vscode-docker v1.2.1 vscode-java-debug v0.26.0 vscode-java-debugger-azds v0.2.3 vscode-java-dependency v0.10.2 vscode-java-pack v0.9.1 vscode-java-test v0.22.4 vscode-javadoc v0.0.1 vscode-jekyll-snippets v0.9.3 vscode-JS-CSS-HTML-formatter v0.2.3 vscode-kubernetes-tools v1.2.0 vscode-lombok v1.0.1 vscode-manifest-yaml v1.18.0 vscode-maven v0.21.4 vscode-prettydiff v0.6.5 vscode-ruby v0.27.0 vscode-spring-boot v1.18.0 vscode-spring-boot-dashboard v0.1.10 vscode-spring-initializr v0.4.8 vscode-xml v0.11.0 vscode-yaml v0.8.0 vscodeintellicode v1.2.7 xml v2.5.0

Prettier Log Output

workbench.desktop.main.js:sourcemap:1642   ERR The request (id: 174, method: 'textDocument/hover') has been cancelled: Error: The request (id: 174, method: 'textDocument/hover') has been cancelled
	at c:\Users\Pawel.EBSOFT\.vscode\extensions\redhat.java-0.62.0\dist\extension.js:1:73520
	at c:\Users\Pawel.EBSOFT\.vscode\extensions\redhat.java-0.62.0\dist\extension.js:1:73814
	at Immediate.<anonymous> (c:\Users\Pawel.EBSOFT\.vscode\extensions\redhat.java-0.62.0\dist\extension.js:1:74175)
	at processImmediate (internal/timers.js:439:21) 

created time in 2 hours

Pull request review commentprettier/prettier

JavaScript: Align indentation for binary/logical expression statements with trailing comments

 function printBinaryishExpressions(     parts.push(path.call(print));   } +  // For alignment expression statements with trailing comments like:+  //+  // foo ++  //   bar + // comment+  //   baz;+  const hasTrailingCommentInBinaryish = (node) => {+    if (isBinaryish(node) && !node.comments) {+      return hasTrailingCommentInBinaryish(node.left);+    }+    return isBinaryish(node) && hasTrailingComment(node);

Prettier pr-8476 Playground link

--parser babel

Input:

bifornCringerMoshedPerplexSawder(
  askTrovenaBeenaDependsRowans,
  glimseGlyphsHazardNoopsTieTie
)
|> foo
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;

bifornCringerMoshedPerplexSawder(
  askTrovenaBeenaDependsRowans,
  glimseGlyphsHazardNoopsTieTie
)
|> foo // comment
|> kochabCooieGameOnOboleUnweave
|> glimseGlyphsHazardNoopsTieTie;

Output:

bifornCringerMoshedPerplexSawder(
  askTrovenaBeenaDependsRowans,
  glimseGlyphsHazardNoopsTieTie
)
  |> foo
  |> kochabCooieGameOnOboleUnweave
  |> glimseGlyphsHazardNoopsTieTie;

bifornCringerMoshedPerplexSawder(
    askTrovenaBeenaDependsRowans,
    glimseGlyphsHazardNoopsTieTie
  )
  |> foo  // comment
  |> kochabCooieGameOnOboleUnweave
  |> glimseGlyphsHazardNoopsTieTie;

sosukesuzuki

comment created time in 2 hours

pull request commentprettier/prettier

JavaScript: Align indentation for binary/logical expression statements with trailing comments

@sosukesuzuki I'd try to do flattening where printComments is called. parts is an array everywhere, assigning it the result of the printComments call, which is a Doc { type: "concat" }, doesn't look right. See also https://github.com/prettier/prettier/issues/8451#issuecomment-637567706

sosukesuzuki

comment created time in 2 hours

issue commentprettier/prettier

P2.x - Make HTML class rewrite optional

@ozguruysal playground output from #7865 for your example is:

<div
  class="
    border-r border-b border-l border-gray-400
    lg:border-l-0 lg:border-t lg:border-gray-400
    bg-white
    rounded-b
    lg:rounded-b-none lg:rounded-r
    p-4
    flex flex-col
    justify-between
    leading-normal
  "
></div>

pburkindine

comment created time in 2 hours

pull request commentprettier/prettier

JavaScript: Align indentation for binary/logical expression statements with trailing comments

@fisker

I mean can we print the first part differently in that function?

I tried but I was not sure how to print it differently...

@thorn0

Performance-wise, it was better before the change. printBinaryishExpressions is recursive, and we don't need to do this flattening on each recursion level.

the flattening is actually done only when the parent node type is ExpressionStatement so I think this is no problem for performance.

sosukesuzuki

comment created time in 3 hours

pull request commentprettier/prettier

Fix: don't wrap arrays in `test.each` template strings

@yogmel Looks good. 👍 Please add a changelog entry (to changelog_unreleased/*/pr-XXXX.md file following changelog_unreleased/TEMPLATE.md).

yogmel

comment created time in 3 hours

issue commentprettier/prettier

P2.x - Make HTML class rewrite optional

@ozguruysal What is the expected output? Does #7865 look good to you?

pburkindine

comment created time in 3 hours

issue commentprettier/prettier

P2.x - Make HTML class rewrite optional

Formatting classes can be the area of plugins as there may be lots of different requirements based on how you write css or what framework/library you use, as in the example plugin mentioned above.

I use Tailwind CSS and, in my opinion formatting following:

<div class="border-r border-b border-l border-gray-400 lg:border-l-0 lg:border-t lg:border-gray-400 bg-white rounded-b lg:rounded-b-none lg:rounded-r p-4 flex flex-col justify-between leading-normal"></div>

to this:

<div
  class="border-r border-b border-l border-gray-400 lg:border-l-0 lg:border-t lg:border-gray-400 bg-white rounded-b lg:rounded-b-none lg:rounded-r p-4 flex flex-col justify-between leading-normal"
></div>

doesn't make sense at all and it looks uglier than prettier to me.

Prettier's goal is to liberate the developer's brain from formatting-related concerns.

Yes that's why I like Prettier, and I try not to change any config provided, but if the decision is to format like one class per line, please add an option to disable it. I'd even fancy a config to disable the current formatting.

pburkindine

comment created time in 3 hours

startedprettier/plugin-php

started time in 3 hours

Pull request review commentprettier/prettier

Fix: don't wrap arrays in `test.each` template strings

 function printPathNoParens(path, options, print, args) {             return element[itemsKey] && element[itemsKey].length > 1;           }); +        if (n.type === "ArrayExpression") {+          let i = 0;+          let node = path.getNode(i);+          while (node) {
          while (node && shouldBreak) {
yogmel

comment created time in 4 hours

pull request commentprettier/prettier

Fix: don't wrap arrays in `test.each` template strings

Oh, I see what I did. Hopefully, everything passes now.

yogmel

comment created time in 4 hours

startedprettier/vim-prettier

started time in 4 hours

issue commentprettier/prettier-vscode

How can I prevent prettier from taking multi-line array to a single line?

You're completely right about the usefulness of tools like prettier. I'm not advocating against a formatting tool, my disappointment is rather focused against the biased opinion of what the limited set of rules prettier allows us to customise, supposedly meant to be for our own good: It is not, and contributes deeply to decrease code quality and make code reviews harder.

When you see issues like this one, sometimes open in 2017, you can see what I'm talking about. So many devs being limited by the limited set of option, and wasting years of discussions on stuff that would increase code quality. That's such a waste.

When I build open source, I don't expect people to be grateful for it, I expect them to be grateful for it, if it helps them, if it fits the needs.

And Prettier doesn't fit this need. How many people have above mentioned trying it out and quitting Prettier because of this?

Prettier has become some sort of a standard for code formatting, and is being enforced more and more, and it's saddening to see, from my point of view, considering how hard it has become to configure it properly, and still doesn't answer the needs of so many.

My feedback is that I've wasted days on trying to configure Prettier, and ended up in a situation where I'm not satisfied by its implementation and limitations.

Don't get me wrong, the purpose and vision behind Prettier are great. The implementation isn't. Yes, it's free. Yes, it's open source. That doesn't mean it cannot become better. And it should, or it'll eventually be replaced by something better.

kdawg1406

comment created time in 4 hours

startedprettier/prettier

started time in 4 hours

pull request commentprettier/prettier

Fix: don't wrap arrays in `test.each` template strings

The test is failing for a natural reason: something isn't right with the code being tested.

yogmel

comment created time in 5 hours

issue commentprettier/prettier-vscode

How can I prevent prettier from taking multi-line array to a single line?

I randomly went here to figure out how tweak array breaks myself and was just about to leave accepting it can't be done. Not a big deal.

But then I saw your comment @Vadorequest.

I am sorry but I just feel like this is so out of touch and that the contributors of this AMAZING tool doesn't deserve this.

I think your message is the best of proofs why we need tools like prettier; the toxicity around what pretty code is and what makes code good is usually fought by a very selected few where the rest of us just want to code and create awesome stuff.

I will not enforce such a tool in my company.

Instead you are enforcing your own view of what pretty code is on the entire company. I promise you the majority of your buddies at work rather have prettier running then having to be afraid of being rejected by the CTO because one array wasn't newlined.

I wonder how many hours were wasted by devs on Prettier worldwide, but it surely ain't pretty.

I promise you it ain't more than the amount of hours, stress and overal mental sanity saved by not having to have these stupid syntax rage wars.

kdawg1406

comment created time in 6 hours

startedprettier/eslint-plugin-prettier

started time in 6 hours

startedprettier/prettier

started time in 6 hours

startedprettier/eslint-config-prettier

started time in 6 hours

startedprettier/prettier

started time in 6 hours

startedprettier/prettier

started time in 6 hours

Pull request review commentprettier/prettier

Fix: don't wrap arrays in `test.each` template strings

 function printPathNoParens(path, options, print, args) {           n.elements.length > 1 &&           n.elements.every((element, i, elements) => {             const elementType = element && element.type;++            if (n.type === "ArrayExpression") {+              let i = 0;+              let node = path.getNode(i);+              while (node) {+                const parent = path.getParentNode(i++);+                if (parent && isJestEachTemplateLiteral(node, parent)) {+                  return false;+                }+                node = parent;

@fisker by root, do you mean moving this logic outside printPathNoParens() function?

yogmel

comment created time in 6 hours

pull request commentprettier/prettier

Fix: don't wrap arrays in `test.each` template strings

Hi everyone, sorry I am late.

I have extracted the test to another file, but I can't make yarn test pass for some reason.

Summary of all failing tests
 FAIL  tests/js/test-declarations/jsfmt.spec.js (6.307 s)
  ● template-literal.js › encountered a declaration exception

    Value false is not a valid document

      20 |     !(typeof val === "string" || (val != null && typeof val.type === "string"))
      21 |   ) {
    > 22 |     throw new Error(
         |           ^
      23 |       "Value " + JSON.stringify(val) + " is not a valid document"
      24 |     );
      25 |   }

      at assertDoc (src/document/doc-builders.js:22:11)
          at Array.forEach (<anonymous>)
      at concat (src/document/doc-builders.js:34:11)
      at Object.genericPrint [as print] (src/language-js/printer-estree.js:227:10)
      at callPluginPrintFunction (src/main/ast-to-doc.js:127:18)
      at comments.printComments (src/main/ast-to-doc.js:64:16)
      at Object.printComments (src/main/comments.js:502:19)
      at printGenerically (src/main/ast-to-doc.js:62:22)
      at FastPath.map (src/common/fast-path.js:124:21)
      at printPathNoParens (src/language-js/printer-estree.js:2451:30)
yogmel

comment created time in 6 hours

issue openedprettier/prettier

prettier ignores html inside markdown files

<!--

BEFORE SUBMITTING AN ISSUE:

  1. Search for your issue on GitHub: https://github.com/prettier/prettier/issues A large number of opened issues are duplicates of existing issues. If someone has already opened an issue for what you are experiencing, you do not need to open a new issue — please add a 👍 reaction to the existing issue instead.

  2. We get a lot of requests for adding options, but Prettier is built on the principle of being opinionated about code formatting. This means we have a very high bar for adding new options. Find out more: https://prettier.io/docs/en/option-philosophy.html

Tip! Don't write this stuff manually.

  1. Go to https://prettier.io/playground
  2. Paste your code and set options
  3. Press the "Report issue" button in the lower right

-->

This might be more of a feature request than a bug report, but I would expect Prettier to be able to parse html inside of a markdown file as if it were an html code snippet or .html file.

Prettier 2.0.5 Playground link

# Options (if any):
--parser markdown
--prose-wrap 80

Input:

I like writing html inside my markdown files for various reasons:

<ul>
<li>sometimes it's easier</li>
<li>sometimes I need to put in a <span style="color:red">different color</span> for some reason</li>
<li>sometimes there isn't a good reason</li>
</ul>

Output:

I like writing html inside my markdown files for various reasons:

<ul>
<li>sometimes it's easier</li>
<li>sometimes I need to put in a <span style="color:red">different color</span> for some reason</li>
<li>sometimes there isn't a good reason</li>
</ul>

Expected behavior:

I like writing html inside my markdown files for various reasons:

<ul>
  <li>sometimes it's easier</li>
  <li>
    sometimes I need to put in a
    <span style="color:red">different color</span> for some reason
  </li>
  <li>sometimes there isn't a good reason</li>
</ul>

created time in 6 hours

startedprettier/prettier

started time in 8 hours

issue commentprettier/prettier

Support golang template/html

<!-- --> worked for me! Use it to split the code blocks that would otherwise be split by the Prettier formatting.

That doesn't work if the code block is a conditional and you end up with only half the comment rendering

lucacasonato

comment created time in 8 hours

more