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

startedprettier/prettier

started time in 2 hours

startedprettier/prettier

started time in 2 hours

startedprettier/tslint-config-prettier

started time in 2 hours

startedprettier/prettier-vscode

started time in 2 hours

startedprettier/prettier

started time in 3 hours

startedprettier/prettier-vscode

started time in 3 hours

startedprettier/prettier

started time in 3 hours

startedprettier/prettier-vscode

started time in 4 hours

startedprettier/prettier

started time in 4 hours

startedprettier/prettier-vscode

started time in 5 hours

startedprettier/prettier

started time in 5 hours

startedprettier/tslint-config-prettier

started time in 5 hours

startedprettier/prettier-vscode

started time in 8 hours

startedprettier/prettier

started time in 8 hours

startedprettier/prettier

started time in 9 hours

fork iheanyi/prettier

Prettier is an opinionated code formatter.

https://prettier.io

fork in 10 hours

CommitCommentEvent

startedprettier/prettier

started time in 12 hours

issue commentprettier/prettier-atom

Doesn't work with global ESLint config

This seems to be because prettier is looking for the eslint module which has been deprecated and can't now be installed, instead of the linter-eslint module.

I can't figure out how to get prettier to look for the correct module though

corysimmons

comment created time in 12 hours

pull request commentprettier/prettier

Consistently add quotes around numeric literal for object properties

If we do quote numbers, I think we have to unquote them as well.

I agree. That's why I want to keep this PR specifically about quote/unquote numbers

duailibe

comment created time in 12 hours

startedprettier/prettier

started time in 12 hours

pull request commentprettier/prettier

Consistently add quotes around numeric literal for object properties

I don't think we should turn strings with escapes into identifiers.

If we do quote numbers, I think we have to unquote them as well. Otherwise adding a line and then removing it again won't take you back to your initial code.

x = {
  1: 1,
}

edit →

 x = {
   1: 1,
+  "-": 1,
 }

prettier →

x = {
  "1": 1,
  "-": 1,
}

edit →

 x = {
   "1": 1,
-  "-": 1,
 }

prettier →

x = {
  "1": 1,
}
duailibe

comment created time in 13 hours

issue commentprettier/prettier

Improve formatting of chain of arrow functions

I'd probably prefer for such arrow chains to be formatted this way:

const getIconEngagementTypeFrom =
  (engagementTypes: Array<EngagementType>) => 
  iconEngagementType => 
  engagementTypes.includes(iconEngagementType);
const getIconEngagementTypeFrom =
  (
    engagementTypes: Array<EngagementType>,
    secondArg: Something
  ) => 
  iconEngagementType => 
  engagementTypes.includes(iconEngagementType);
mgtitimoli

comment created time in 15 hours

startedprettier/prettier

started time in 15 hours

issue commentprettier/prettier-vscode

Run prettier based on glob, not languageId

@remcohaszing I tried this trick yesterday and it works pretty well so far:

{
  "scripts": {
    "fix:prettier": "prettier --write \"**/*\"",
    "lint:prettier": "prettier --check \"**/*\""
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "**/*": [
      "prettier --write",
      "git add"
    ]
  },
}

↑ uses **/* everywhere

Then in .prettierignore I have:

## Please check .eslintignore and .gitignore when changing this file

## file extensions
*.*
LICENSE
!*.js
!*.jsx
!*.json
!*.md
!*.mdx
!*.ts
!*.tsx
!*.yml

## copied from .gitignore
## - npm / yarn
*-debug.log
node_modules
package-lock.json
yarn-error.log

## - temporary local files
build
lib


## shared between eslint and prettier
foo/bar

Having extensions (globs) whitelisted in .prettierignore instead of package.json helps the editor and other tools like lint-staged skip the same files. There is only one source of truth for what's handled by the tool and what's not, which makes things much easier to manage. Feel free to have a look at a project where I tried the above; it also applies the same trick for configuring ESLint: https://gitlab.com/kachkaev/website-graphql-server/

remcohaszing

comment created time in 15 hours

issue openedprettier/prettier-vscode

Run prettier based on glob, not languageId

When prettier is run in CI, it looks somewhat like this:

yarn prettier --check '**/*.{html,json,md,scss,yaml,yml}'

However, in VSCode, prettier runs based on the languageId. This means there is an inconsistent behaviour between running prettier in CI and in the editor. (This applies on other plugins, such as ESLint, as well. IMHO this is incorrect behaviour.)

A practical example:

I recently installed the Kubernetes extension. This means prettier VSCode no longer runs on my Helm chart files, as their language id is now helm. In CI, Prettier is being run, because the files are named Foo.yaml.

I suggest to add a glob option. This makes prettier run based on file globs instead of language ids. This will allow VSCode prettier to run on files, even if plugins use different language ids. This would also implicitly fix #757.

created time in 16 hours

pull request commentprettier/prettier

Consistently add quotes around numeric literal for object properties

This one is interesting too:

Prettier pr-6132 Playground link

--parser babylon
--quote-props consistent

Input:

x = {
  "\u1111": 1,
}

x = {
  "\u1111": 1,
  "needs-quotes": 1
}

Output:

x = {
  ᄑ: 1
};

x = {
  "\u1111": 1,
  "needs-quotes": 1
};

duailibe

comment created time in 16 hours

pull request commentprettier/prettier

Prevent adding quotes if there's a numeric literal as key

Note: this still happens

// input
foo = {
  a: 1,
  "1": 1,
};

// output
foo = {
  "a": 1,
  "1": 1,
};
duailibe

comment created time in 16 hours

push eventprettier/prettier

Lucas Duailibe

commit sha 7e47b4ea26ebb01658dcc8e214e3582f59ed2cc5

Preserve parens around expressions in default export declaration that start with function or class (#6133)

view details

push time in 16 hours

issue closedprettier/prettier

Parens incorrectly dropped when trying to type a function expression

Prettier 1.17.0 Playground link

--parser typescript

Input:

export default (function log() {

} as typeof console.log)

Output:

export default function log() {} as typeof console.log;

Second Output:

SyntaxError: ';' expected. (1:37)
> 1 | export default function log() {} as typeof console.log;
    |                                     ^
  2 | 

Expected behavior:

Parens should not be dropped as they are required in this case. Workaround is to use an arrow function:

export default const log: typeof console.log = () => {}

closed time in 16 hours

MarkKahn

fork kevinlogan94/prettier

Prettier is an opinionated code formatter.

https://prettier.io

fork in 16 hours

pull request commentprettier/prettier

Consistently add quotes around numeric literal for object properties

I think it might make sense taking a step back and fixing all the quote-props stuff in one branch.

@lydell I disagree because I'm not yet convinced we should quote/unquote numeric literals, and having "small" commits helps if we decide to revert this in the future.

The other PR is a necessary bug fix, regardless of the decision on this PR.

duailibe

comment created time in 16 hours

pull request commentprettier/prettier

Preserve parens around expressions in default export declaration that start with function or class

@thorn0 Thanks for beta testing!

After years of Prettier this is the first bug report we've had, I think we're on the safe side now. From a practical point of view, we've covered enough cases IMO.

duailibe

comment created time in 16 hours

startedprettier/prettier

started time in 16 hours

startedprettier/prettier

started time in 17 hours

startedprettier/vim-prettier

started time in 17 hours

startedprettier/prettier-eslint

started time in 19 hours

startedprettier/prettier

started time in 19 hours

issue commentprettier/prettier

Using stylelint on Less with prettier integration gives "CssSyntaxError Unknown word" for "each"

Also have this issue, is there any known work-around?

Xotic750

comment created time in 20 hours

pull request commentprettier/prettier

Preserve parens around expressions in default export declaration that start with function or class

Overall looks great, but I did manage to produce superfluous parens:

Prettier pr-6133 Playground link

--parser babel

Input:

export default (function(){} |> a)``;

Output:

export default ((function() {} |> a)``);
duailibe

comment created time in 20 hours

fork Deeema/prettier

Prettier is an opinionated code formatter.

https://prettier.io

fork in 20 hours

Pull request review commentprettier/prettier

Preserve parens around expressions in default export declaration that start with function or class

 function isFollowedByRightBracket(path) {   return false; } +function shouldWrapFunctionForExportDefault(path, options) {+  const node = path.getValue();+  const parent = path.getParentNode();++  if (node.type === "FunctionExpression" || node.type === "ClassExpression") {+    return (+      // prevent infinite loop in the check below+      parent.type === "ExportDefaultDeclaration" ||+      // in some cases the function is already wrapped+      // (e.g. `export default (function() {})();`)+      // in this case we don't need to add extra parens+      !needsParens(path, options)+    );+  }++  if (!hasNakedLeftSide(node)) {+    return false;+  }++  return path.call.apply(

Why not use spread syntax here instead of apply and concat?

duailibe

comment created time in 20 hours

startedprettier/prettier

started time in 20 hours

startedprettier/prettier

started time in 21 hours

Pull request review commentprettier/prettier

Preserve parens around expressions in default export declaration that start with function or class

 export default (class {}[1] = 1);  ================================================================================ `;++exports[`class_instance.js 1`] = `+====================================options=====================================+parsers: ["flow", "typescript"]+printWidth: 80+                                                                                | printWidth+=====================================input======================================+export default (class {}.getInstance());++=====================================output=====================================+export default (class {}.getInstance());++================================================================================+`;++exports[`function_in_template.js 1`] = `+====================================options=====================================+parsers: ["flow", "typescript"]

I wonder why these tests aren't run using babel.

duailibe

comment created time in 21 hours

delete branch prettier/plugin-php

delete branch : dependabot/npm_and_yarn/rollup-1.12.1

delete time in a day

PR closed prettier/plugin-php

chore(deps-dev): Bump rollup from 1.9.0 to 1.12.1 dependencies

Bumps rollup from 1.9.0 to 1.12.1. <details> <summary>Release notes</summary>

Sourced from rollup's releases.

v1.12.1

2019-05-16

Bug Fixes

  • Extend file name sanitation to also replace "?" and "*" e.g. when preserving modules with the updated commonjs plugin (#2860)
  • Do not ignore module transformer that return an empty string (#2861)

Pull Requests

v1.12.0

2019-05-15

Features

  • Add treeshake.moduleSideEffects option to allow removing empty imports without a side-effect check (#2844)
  • Extend plugin API to allow marking modules as side-effect-free (#2844)
  • Extend this.resolve plugin context function with an option to skip the resolveId hook of the calling plugin (#2844)
  • Add isEntry flag to this.getModuleInfo plugin context function (#2844)
  • Distribute Rollup as optimized ES2015 code (#2851)

Pull Requests

v1.11.3

2019-05-05

Bug Fixes

  • Quote es3 keywords in namespace objects (#2825)

Pull Requests

v1.11.2

2019-05-04

Bug Fixes

  • Prevent a crash when handling circular namespace exports (#2836)

Pull Requests

v1.11.1

2019-05-04

Bug Fixes

  • Fix an issue where rendered exports were reported as "removed" in the bundle information (#2835)

</tr></table> ... (truncated) </details> <details> <summary>Changelog</summary>

Sourced from rollup's changelog.

1.12.1

2019-05-16

Bug Fixes

  • Extend file name sanitation to also replace "?" and "*" e.g. when preserving modules with the updated commonjs plugin (#2860)
  • Do not ignore module transformer that return an empty string (#2861)

Pull Requests

1.12.0

2019-05-15

Features

  • Add treeshake.moduleSideEffects option to allow removing empty imports without a side-effect check (#2844)
  • Extend plugin API to allow marking modules as side-effect-free (#2844)
  • Extend this.resolve plugin context function with an option to skip the resolveId hook of the calling plugin (#2844)
  • Add isEntry flag to this.getModuleInfo plugin context function (#2844)
  • Distribute Rollup as optimized ES2015 code (#2851)

Pull Requests

1.11.3

2019-05-05

Bug Fixes

  • Quote es3 keywords in namespace objects (#2825)

Pull Requests

1.11.2

2019-05-04

Bug Fixes

  • Prevent a crash when handling circular namespace exports (#2836)

Pull Requests

1.11.1

2019-05-04

Bug Fixes

  • Fix an issue where rendered exports were reported as "removed" in the bundle information (#2835)

Pull Requests

</tr></table> ... (truncated) </details> <details> <summary>Commits</summary>

Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


<details> <summary>Dependabot commands and options</summary> <br />

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
  • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
  • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
  • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
  • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

Additionally, you can set the following in your Dependabot dashboard:

  • Update frequency (including time of day and day of week)
  • Automerge options (never/patch/minor, and dev/runtime dependencies)
  • Pull request limits (per update run and/or open at any time)
  • Out-of-range updates (receive only lockfile updates, if desired)
  • Security updates (receive only security updates, if desired)

Finally, you can contact us by mentioning @dependabot.

</details>

+8 -8

1 comment

1 changed file

dependabot[bot]

pr closed time in a day

pull request commentprettier/plugin-php

chore(deps-dev): Bump rollup from 1.9.0 to 1.12.1

Superseded by #1056.

dependabot[bot]

comment created time in a day

PR opened prettier/plugin-php

chore(deps-dev): Bump rollup from 1.9.0 to 1.12.3

Bumps rollup from 1.9.0 to 1.12.3. <details> <summary>Release notes</summary>

Sourced from rollup's releases.

v1.12.3

2019-05-19

Bug Fixes

  • Prevent duplicate imports when exports are reexported as default exports (#2866)

Pull Requests

v1.12.2

2019-05-17

Bug Fixes

  • Do not fail when using clearScreen:false in watchMode (#2858)
  • Properly resolve star reexports when preserving modules (#2860)

Pull Requests

v1.12.1

2019-05-16

Bug Fixes

  • Extend file name sanitation to also replace "?" and "*" e.g. when preserving modules with the updated commonjs plugin (#2860)
  • Do not ignore module transformer that return an empty string (#2861)

Pull Requests

v1.12.0

2019-05-15

Features

  • Add treeshake.moduleSideEffects option to allow removing empty imports without a side-effect check (#2844)
  • Extend plugin API to allow marking modules as side-effect-free (#2844)
  • Extend this.resolve plugin context function with an option to skip the resolveId hook of the calling plugin (#2844)
  • Add isEntry flag to this.getModuleInfo plugin context function (#2844)
  • Distribute Rollup as optimized ES2015 code (#2851)

Pull Requests

v1.11.3

2019-05-05 </tr></table> ... (truncated) </details> <details> <summary>Changelog</summary>

Sourced from rollup's changelog.

1.12.3

2019-05-19

Bug Fixes

  • Prevent duplicate imports when exports are reexported as default exports (#2866)

Pull Requests

1.12.2

2019-05-17

Bug Fixes

  • Do not fail when using clearScreen:false in watchMode (#2858)
  • Properly resolve star reexports when preserving modules (#2860)

Pull Requests

1.12.1

2019-05-16

Bug Fixes

  • Extend file name sanitation to also replace "?" and "*" e.g. when preserving modules with the updated commonjs plugin (#2860)
  • Do not ignore module transformer that return an empty string (#2861)

Pull Requests

1.12.0

2019-05-15

Features

  • Add treeshake.moduleSideEffects option to allow removing empty imports without a side-effect check (#2844)
  • Extend plugin API to allow marking modules as side-effect-free (#2844)
  • Extend this.resolve plugin context function with an option to skip the resolveId hook of the calling plugin (#2844)
  • Add isEntry flag to this.getModuleInfo plugin context function (#2844)
  • Distribute Rollup as optimized ES2015 code (#2851)

Pull Requests

1.11.3

2019-05-05

</tr></table> ... (truncated) </details> <details> <summary>Commits</summary>

Dependabot compatibility score

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


<details> <summary>Dependabot commands and options</summary> <br />

You can trigger Dependabot actions by commenting on this PR:

  • @dependabot rebase will rebase this PR
  • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
  • @dependabot merge will merge this PR after your CI passes on it
  • @dependabot squash and merge will squash and merge this PR after your CI passes on it
  • @dependabot cancel merge will cancel a previously requested merge and block automerging
  • @dependabot reopen will reopen this PR if it is closed
  • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
  • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
  • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
  • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
  • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language
  • @dependabot badge me will comment on this PR with code to add a "Dependabot enabled" badge to your readme

Additionally, you can set the following in your Dependabot dashboard:

  • Update frequency (including time of day and day of week)
  • Automerge options (never/patch/minor, and dev/runtime dependencies)
  • Pull request limits (per update run and/or open at any time)
  • Out-of-range updates (receive only lockfile updates, if desired)
  • Security updates (receive only security updates, if desired)

Finally, you can contact us by mentioning @dependabot.

</details>

+8 -8

0 comment

1 changed file

pr created time in a day

create barnchprettier/plugin-php

branch : dependabot/npm_and_yarn/rollup-1.12.3

created branch time in a day

pull request commentprettier/prettier

Consistently add quotes around numeric literal for object properties

I think it might make sense taking a step back and fixing all the quote-props stuff in one branch.

One of the basic rules of Prettier is: We don't transform the AST.

But we've always turned string literals used as keys and that contain only a valid identifier into identifiers. On the other hand, we've never turned number-looking strings into numbers.

Then we added --quote-props.

  • preserve is easy. Simply do not transform the AST.
  • consistent now asks to quote numbers to be ... consistent.
  • If so, as-needed should unquote numbers as well, I think. Something like this: const shouldUnquoteNumber = String(Number(key)) === key.

I would like to see this test case:

x = {
  a: 1,
  a() {},
  "a": 1,
  "a"() {},
  NaN: 1,
  "NaN": 1,
  NaN() {},
  "NaN"() {},
  1: 1,
  1() {},
  "1": 1,
  "1"() {},
  "1": 1,
  "1"() {},
  "1.0": 1,
  "1.0"() {},
  1e3: 1,
  1e3() {},
  "1e3": 1,
  "1e3"() {},
  0xa: 1,
  0xa() {},
  "0xa": 1,
  "0xa"() {},
  0b10: 1,
  0b10() {},
  "0b10": 1,
  "0b10"() {},
  [a]: 1,
  [a]() {},
}

x = {
  "needs-quotes": 1,
  a: 1,
  a() {},
  "a": 1,
  "a"() {},
  1: 1,
  1() {},
  "1": 1,
  "1"() {},
  "1": 1,
  "1"() {},
  "1.0": 1,
  "1.0"() {},
  1e3: 1,
  1e3() {},
  "1e3": 1,
  "1e3"() {},
  0xa: 1,
  0xa() {},
  "0xa": 1,
  "0xa"() {},
  0b10: 1,
  0b10() {},
  "0b10": 1,
  "0b10"() {},
  [a]: 1,
  [a]() {},
}
duailibe

comment created time in a day

startedprettier/prettier

started time in a day

startedprettier/prettier

started time in a day

startedprettier/prettier

started time in a day

startedprettier/prettier

started time in a day

issue commentprettier/prettier-atom

new error with typescript project

I recently encountered a very similar issue. A relaunch of Atom solved the issue.

jasonkuhrt

comment created time in a day

pull request commentprettier/prettier

Preserve parens around expressions in default export declaration that start with function or class

@thorn0 Thank you for testing!

Now it only wraps the expression being exported if the function or class isn't already wrapped.

duailibe

comment created time in a day

Pull request review commentprettier/prettier

Preserve parens around expressions in default export declaration that start with function or class

 function needsParens(path, options) {     return true;   } +  // `export default function` or `export default class` can't be followed by+  // anything after. So an expression like `export default (function(){}).toString()`+  // needs to be followed by a parentheses+  if (parent.type === "ExportDefaultDeclaration") {+    // IIFE already include parenthesis between the expression and invocation+    // so we don't need to handle here.

I was already adding those 👍 Thanks for the suggestion

duailibe

comment created time in a day

Pull request review commentprettier/prettier

Preserve parens around expressions in default export declaration that start with function or class

 function needsParens(path, options) {     return true;   } +  // `export default function` or `export default class` can't be followed by+  // anything after. So an expression like `export default (function(){}).toString()`+  // needs to be followed by a parentheses+  if (parent.type === "ExportDefaultDeclaration") {+    // IIFE already include parenthesis between the expression and invocation+    // so we don't need to handle here.

Would be good to have a test with IIFE.

duailibe

comment created time in a day

pull request commentprettier/prettier

Preserve parens around expressions in default export declaration that start with function or class

Tagged template literals get extra parens:

Prettier pr-6133 Playground link

--parser babylon

Input:

export default (function() {})`a`;

Output:

export default ((function() {})`a`);

duailibe

comment created time in a day

pull request commentprettier/prettier

Preserve parens around expressions in default export declaration that start with function or class

@lydell @thorn0 What do you think of this solution now?

duailibe

comment created time in a day

push eventprettier/prettier

Lucas Duailibe

commit sha e222562b582dd67be360d1697cee0ebadf8d40e1

Update CHANGELOG.unreleased.md

view details

push time in a day

startedprettier/prettier-vscode

started time in a day

startedprettier/prettier

started time in a day

pull request commentprettier/prettier

Preserve parens around TsAsExpression inside default export declaration

Thanks @thorn0, those are more practical use cases.

Unfortunately because of the format of the AST it's a bit hard to detect when there's a function or class keyword in the start of the expression.

We do have some code to try and guess what is the "left most" node in an expression to add ASI protection. I'll see if we can reuse some of the code for that. Otherwise, we have to manually handle all possible cases.

duailibe

comment created time in a day

PR opened prettier/prettier

Prevent adding quotes if there's a numeric literal as key
// input
foo = {
  a: 1,
  1: 1,
};

// output (before)
foo = {
  "a": 1,
  1: 1,
};

Try the playground for this PR

+187 -7

0 comment

5 changed files

pr created time in a day

pull request commentprettier/prettier

Consistently add quotes around numeric literal for object properties

Side note and probably not related to this PR – with --quote-props consistent, why is it that adding 1: "x" to an object literal causes all props to be quoted?

It wasn't related. It's similar to #6119.. the heuristics of what "needs" props is wrong. I'll fix in another PR, since that's more straightforward than this PR

duailibe

comment created time in a day

fork yarikc/prettier

Prettier is an opinionated code formatter.

https://prettier.io

fork in a day

pull request commentprettier/prettier

Consistently add quotes around numeric literal for object properties

@lydell wow that was unexpected.

I started to wonder if we should do this at all, but maybe this falls in the "Prettier makes quirks in your code more explicit" bucket

duailibe

comment created time in a day

pull request commentprettier/prettier

Preserve parens around TsAsExpression inside default export declaration

It surely feels like a stretch, but still, I can imagine somebody doing things like these:

export default (function(){  /* ... */ }.toString());
export default (class WeirdSingleton { /* ... */ }.getInstance());

And don't forget about the upcoming pipeline operator. It totally makes sense for a function or a class expression to be its left-hand operand.

duailibe

comment created time in a day

startedprettier/prettier

started time in a day

pull request commentprettier/prettier

Preserve parens around TsAsExpression inside default export declaration

@thorn0 Can you think of practical cases that aren't yet covered?

The one you mentioned is correct per the spec, but doesn't happen in practice because isn't valid in the runtime, so we shouldn't need to worry about that.

duailibe

comment created time in a day

push eventprettier/prettier

Rich Hong

commit sha 906d33749b658c9fa9e24510b768c51337ab0ea2

Add support for styled-jsx external styles (#6089)

view details

push time in a day

PR merged prettier/prettier

Add support for styled-jsx external styles

Supports all 3 tags in styled-jsx/css: css, css.global, and css.resolve. https://github.com/zeit/styled-jsx/#external-css-and-styles-outside-of-the-component

Fixes https://github.com/zeit/styled-jsx/issues/548

Formatting template literal with css was already working because it happens to be the same as what styled-components was using. https://www.styled-components.com/docs/api#css

So this change just adds support for css.global and css.resolve.

<!-- Please provide a brief summary of your changes: -->

<!-- Please ensure you’ve done all of these things (if applicable). --> <!-- You can replace the [ ] with [x] to mark each task as done. -->

  • [x] I’ve added tests to confirm my change works.
  • [x] (If the change is user-facing) I’ve added my changes to the CHANGELOG.unreleased.md file following the template.
  • [x] I’ve read the contributing guidelines.

Try the playground for this PR

+231 -9

8 comments

4 changed files

hongrich

pr closed time in a day

pull request commentprettier/prettier

Add support for styled-jsx external styles

The css`` check is now duplicated... I'll merge this as-is and refactor

hongrich

comment created time in a day

Pull request review commentprettier/prettier

Add support for styled-jsx external styles

 function printGraphqlComments(lines) { }  /**- * Template literal in this context:+ * Template literal in these contexts:  * <style jsx>{`div{color:red}`}</style>+ * css``+ * css.global``+ * css.resolve``  */ function isStyledJsx(path) {   const node = path.getValue();   const parent = path.getParentNode();   const parentParent = path.getParentNode(1);   return (-    parentParent &&-    node.quasis &&-    parent.type === "JSXExpressionContainer" &&-    parentParent.type === "JSXElement" &&-    parentParent.openingElement.name.name === "style" &&-    parentParent.openingElement.attributes.some(-      attribute => attribute.name.name === "jsx"-    )+    (parentParent &&+      node.quasis &&+      parent.type === "JSXExpressionContainer" &&+      parentParent.type === "JSXElement" &&+      parentParent.openingElement.name.name === "style" &&+      parentParent.openingElement.attributes.some(+        attribute => attribute.name.name === "jsx"+      )) ||+    (parent &&+      parent.type === "TaggedTemplateExpression" &&+      parent.tag.type === "Identifier" &&+      parent.tag.name === "css") ||

FTR css`` was already supported because of styled components

hongrich

comment created time in a day

push eventprettier/prettier

Sosuke Suzuki

commit sha 3b3c411642f66420367302234fe4e0abcccaf892

TypeScript: Keep parentheses around a function called with non-null assertion. (#6136)

view details

push time in a day

PR merged prettier/prettier

TypeScript: Keep parentheses around a function called with non-null assertion.

<!-- Please provide a brief summary of your changes: --> Fix #6076

Previously, Prettier removes necessary parentheses around the function called with nun-null assertion. It happens when it's return value is called as function.

<!-- Please ensure you’ve done all of these things (if applicable). --> <!-- You can replace the [ ] with [x] to mark each task as done. -->

  • [x] I’ve added tests to confirm my change works.
  • [ ] (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory)
  • [x] (If the change is user-facing) I’ve added my changes to the CHANGELOG.unreleased.md file following the template.
  • [x] I’ve read the contributing guidelines.

Try the playground for this PR

+41 -0

0 comment

4 changed files

sosukesuzuki

pr closed time in a day

issue closedprettier/prettier

TypeScript: parentheses around function invocation with non-null assertion removed incorrectly

<!--

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

-->

Prettier 1.17.0 Playground link

# Options (if any):
--parser typescript

Input:

declare function getCtorOrNull(): { new (): any } | null;

new (getCtorOrNull()!)();

Output:

declare function getCtorOrNull(): { new (): any } | null;

new getCtorOrNull()!();

The output is the invalid TS code. Proof: https://www.typescriptlang.org/play/index.html#src=declare%20function%20getCtorOrNull()%3A%20%7B%20new%20()%3A%20any%20%7D%20%7C%20null%3B%0D%0A%0D%0Anew%20getCtorOrNull()!()%3B%0D%0A%0D%0Anew%20(getCtorOrNull()!)()%3B%0D%0A

Expected behavior:

declare function getCtorOrNull(): { new (): any } | null;

new (getCtorOrNull()!)();

closed time in a day

vkrol

startedprettier/prettier

started time in 2 days

startedprettier/prettier-eslint

started time in 2 days

startedprettier/prettier

started time in 2 days

startedprettier/prettier

started time in 2 days

issue openedprettier/prettier

Keep parens for multi-line logical expressions

Prettier 1.17.1 Playground link

--parser babylon

Input:

const hasNativeLazyLoadSupport = (
  typeof HTMLImageElement !== `undefined` &&
  `loading` in HTMLImageElement.prototype
)

const isBrowser = typeof window !== `undefined`
const hasIOSupport = (
  isBrowser &&
  window.IntersectionObserver
)

const useIOSupport = (
  !hasNativeLazyLoadSupport &&
  hasIOSupport && !props.critical && !seenBefore
)

const isVisible = (
  props.critical ||
  isBrowser && (hasNativeLazyLoadSupport || !useIOSupport)
)

Output:

const hasNativeLazyLoadSupport =
  typeof HTMLImageElement !== `undefined` &&
  `loading` in HTMLImageElement.prototype;

const isBrowser = typeof window !== `undefined`;
const hasIOSupport = isBrowser && window.IntersectionObserver;

const useIOSupport =
  !hasNativeLazyLoadSupport && hasIOSupport && !props.critical && !seenBefore;

const isVisible =
  props.critical || (isBrowser && (hasNativeLazyLoadSupport || !useIOSupport));

Expected behavior:

hasIOSupport is fine, but as hasNativeLazyLoadSupport is too long, it just removes the parens but this seems to reduce clarity. Ideally the parens would be left alone for both in this situation, more so with hasNativeLazyLoadSupport.

useIOSupport and isVisible are too long and get treated similar to hasNativeLazyLoadSupport, however compressed to a single line(well isVisible added some paren). The line separation was intentional for better grokking. I understand prettier's take on this though.

Doesn't seem like there is any config/option for handling this. I did see a related PR for similar regarding math expressions, released in 1.13.

A related issue #2065, ended up being more focused on arrow function parens, specifically for JSX, that issue is now locked. I think this is a case where keeping parens can be valid. Another issue points out:

Which personally reminds me if of an unbraced if statement and, rightly or wrongly, sets off alarm bells.

airbnb guide states:

In case the expression spans over multiple lines, wrap it in parentheses for better readability.

created time in 2 days

startedprettier/prettier-eslint

started time in 2 days

startedprettier/prettier-vscode

started time in 2 days

startedprettier/prettier-eslint-cli

started time in 2 days

startedprettier/stylelint-config-prettier

started time in 2 days

startedprettier/eslint-config-prettier

started time in 2 days

startedprettier/tslint-config-prettier

started time in 2 days

startedprettier/eslint-plugin-prettier

started time in 2 days

startedprettier/prettier

started time in 2 days

startedprettier/prettier

started time in 2 days

startedprettier/prettier

started time in 2 days

issue commentprettier/prettier-vscode

how to enable formatting of Markdown files

i've enabled the Pret. and "MAIO" and the Format Document worked, @alexilyaev , but adding this line to settings didn't help the selection formatting (it still shows the message), also, while the "FD" works, the markdown tables are not auto-formatted (as they should, following the Pret. doc.)

mvolkmann

comment created time in 2 days

issue commentprettier/prettier-vscode

how to enable formatting of Markdown files

Had the same issue, didn't work for me because I had "Markdown All in One" extension installed.
I ran "Format Document" and it told it has several formatters for Markdown and I need to choose one, so I chose Prettier.
It added this to my settings:

"[markdown]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }

So now when I save Markdown files they are formatted with Prettier.

mvolkmann

comment created time in 2 days

startedprettier/eslint-config-prettier

started time in 2 days

startedprettier/prettier-eslint

started time in 2 days

startedprettier/prettier

started time in 2 days

more