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

createGlobalStyle not being auto formatted #175

Closed
mkvlrn opened this issue May 29, 2019 · 22 comments
Closed

createGlobalStyle not being auto formatted #175

mkvlrn opened this issue May 29, 2019 · 22 comments

Comments

@mkvlrn
Copy link

mkvlrn commented May 29, 2019

Anything inside another styled tag will be properly formatted, for example a styled.div. But a createGlobaStyle function will not have it's contents formatted. Color is still being applied, but formatting won't happen.

@danielmahon
Copy link

Same issue, not sure of any side-effects yet but as a workaround, I'm just wrapping the whole thing in the css function, which seems to re-enable the auto-formatting.

import { createGlobalStyle, css } from 'styled-components';

export default createGlobalStyle`${css`
  html,
  body,
  #root {
    padding: 0px;
    margin: 0px;
    width: 100vw;
    height: 100vh;
  }
`}`;

@shmilyoo
Copy link

shmilyoo commented Jul 8, 2019

Same issue, not sure of any side-effects yet but as a workaround, I'm just wrapping the whole thing in the css function, which seems to re-enable the auto-formatting.

import { createGlobalStyle, css } from 'styled-components';

export default createGlobalStyle`${css`
  html,
  body,
  #root {
    padding: 0px;
    margin: 0px;
    width: 100vw;
    height: 100vh;
  }
`}`;

it works

@alikadir
Copy link

Same issue, not sure of any side-effects yet but as a workaround, I'm just wrapping the whole thing in the css function, which seems to re-enable the auto-formatting.

import { createGlobalStyle, css } from 'styled-components';

export default createGlobalStyle`${css`
  html,
  body,
  #root {
    padding: 0px;
    margin: 0px;
    width: 100vw;
    height: 100vh;
  }
`}`;

it works

it not works currently 🙁

@alikadir
Copy link

flowing code works 💪

import * as styled from 'styled-components';

export default styled.createGlobalStyle`
  body {
    margin: 0;
  }
  code {
    font-family: source-code-pro;
  }
`;

@adi518
Copy link

adi518 commented Feb 20, 2020

@alikadir That's the best solution thus far. It looks like Prettier is looking for the styled identifier.

@gurmiguel
Copy link

gurmiguel commented Jun 3, 2020

With typescript, if I try to pass the props type definition, createGlobalStyle loses the formatting

const GlobalStyles = createGlobalStyle<{prop: any}>`
  body {
    ...
  }
`

without the props type the formatting works normally

@jasonwilliams
Copy link
Collaborator

fixed in 1.0.0

@webdevelukas
Copy link

Doesn't work for me in VS-Code (1.50.1) on macOS (10.15.7) and with vscode-styled-components (1.2). Actually I'm using the ${css``} workaround.

@jasonwilliams
Copy link
Collaborator

jasonwilliams commented Oct 26, 2020

@webdevelukas could you paste a snippet of code you would expect to work? (Without the workaround)

This will make it easier for me to see the issue

@lucasengel
Copy link

@webdevelukas could you paste a snippet of code you would expect to work? (Without the workaround)

This won't get formatted:

import { createGlobalStyle } from "styled-components"

const GlobalStyles = createGlobalStyle`
  * {box-sizing: border-box;
    margin: 0;    padding: 0;
  }
`

export default GlobalStyles

@Nytheneals
Copy link

I'm late to the party but this will also work fine

import * as styled from 'styled-components';

const GlobalStyles = styled.createGlobalStyle`
  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
`;

export default GlobalStyles;

@ibqn
Copy link

ibqn commented Feb 16, 2021

This bug ist still not addressed, why is issue marked as resolved?

The following block ist not formatted in vscode:

import { createGlobalStyle } from 'styled-components'

const GlobalStyle =  createGlobalStyle`
  html,
  body {
    padding: 0px;
    margin: 0px;
    width: 100vw;
    height: 100vh;
  }
`
export default GlobalStyle

@luizwhite
Copy link

luizwhite commented Feb 23, 2021

flowing code works 💪

import * as styled from 'styled-components';

export default styled.createGlobalStyle`
  body {
    margin: 0;
  }
  code {
    font-family: source-code-pro;
  }
`;

It bugs my Next.js when using that solution, because babel-plugin-styled-components doesn't quite understand that.
So my workaworkaround is just type styled. before createGlobalStyle, and my formatter already shows me the linting, and i can push my format/fix keyboard shortcut, then save the file after removing the typed styled.

@ibqn
Copy link

ibqn commented Mar 13, 2021

@luizwhite in nextjs one can write something like this as a workaround

import { createGlobalStyle } from 'styled-components'

const styled = { createGlobalStyle }

const GlobalStyle = styled.createGlobalStyle`
  body {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  ...
`

export default GlobalStyle

but well I mean...

@jasonwilliams jasonwilliams reopened this Mar 13, 2021
@jasonwilliams jasonwilliams added this to the v1.6.0 milestone Apr 29, 2021
@jasonwilliams
Copy link
Collaborator

jasonwilliams commented Apr 30, 2021

This is definitely working for me (as of v1.5.2), we even have it passing in our fixtures https://github.com/styled-components/vscode-styled-components/blob/27a0ab882628646d775989075cfb270085e011f2/src/tests/suite/colorize-fixtures/createGlobalStyle.js

Could someone confirm this is still broken and show their extension version?

@ibqn I see this when using your example.

image

@ibqn
Copy link

ibqn commented May 2, 2021

@jasonwilliams no, it's still no working, i.e. code is colorized colorized, but styles are not formatted.
I have even uninstalled and reinstalled this extension again, to double check.

Version: 1.55.2
Commit: 3c4e3df9e89829dce27b7b5c24508306b151f30d
Date: 2021-04-13T09:37:02.931Z
Electron: 11.3.0
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Linux x64 5.4.0-72-generic

Screenshot from 2021-05-02 12-45-05
Screenshot from 2021-05-02 12-44-43
Screenshot from 2021-05-02 12-48-47

Feel free to let me know, if I somehow can assist here.

@luizwhite
Copy link

still no auto formatting here

The workaround I am using in my projects is this, as suggested by @ibqn:

image

@jasonwilliams
Copy link
Collaborator

@luizwhite this extension does not do formatting, its a prettier (or whatever formatter you use) issue

@rensvis
Copy link

rensvis commented Jan 26, 2022

Issue for me was that multiple formatters were active and I just had to pick a default. You can do so by hitting Shift + Option + F and you'll get a window asking to select a default. Simply selecting Prettier here solved the non-formatting issue for me.

@dminkovsky
Copy link

dminkovsky commented May 1, 2022

flowing code works 💪

import * as styled from 'styled-components';

export default styled.createGlobalStyle`
  body {
    margin: 0;
  }
  code {
    font-family: source-code-pro;
  }
`;

Why does this work?

And then is there a way to access the factories?

@IamKennedyKambo
Copy link

renvis's answer fixed it for me. Apparently vscode needs you to choose a default formatter for it, then it knows what to do. Shift + Alt + F on Windows.

Seo0H added a commit to SobiSa-Expense-Hunter/SobiSa that referenced this issue May 10, 2023
스타일가이드에 추가된 임명장 폰트 작업
px -> pt 수정
GlobalStyle 코드 포메팅이 되지 않는 문제 -> css 서식 불러와서 해결
styled-components/vscode-styled-components#175 (comment)
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

No branches or pull requests