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

Fix autofix for nested tagged template literals #4119

Closed
Tracked by #4574
hudochenkov opened this issue Jun 17, 2019 · 4 comments · Fixed by #4685
Closed
Tracked by #4574

Fix autofix for nested tagged template literals #4119

hudochenkov opened this issue Jun 17, 2019 · 4 comments · Fixed by #4685
Labels
help wanted is likely non-trival and help is wanted priority: high is impactful on users status: ready to implement is ready to be worked on by someone syntax: css-in-js relates to JS objects & template literals type: bug a problem with a feature or rule upstream relates to an upstream package

Comments

@hudochenkov
Copy link
Member

hudochenkov commented Jun 17, 2019

Clearly describe the bug

Incorrect output with --fix when CSS-in-JS has tagged template literal inside tagged template literal. It's a bug with postcss-jsx. I've opened issue in related repository. But it won't be fixed any time soon, because @gucong3000 currently is not available, and the fix will require a lot of time invested.

Which rule, if any, is the bug related to?

None.

What CSS is needed to reproduce the bug?

import styled, { css } from 'styled-components';
const Message = styled.p`
	padding: 10px;
	${(props) => css`
		color: #b02d00;
	`}
	${(props2) => css`
		border-color: red;
	`}
`;

What stylelint configuration is needed to reproduce the bug?

Any config as it's related to parser only.

{
  "rules": {
  }
}

Which version of stylelint are you using?

10.1.0

How are you running stylelint: CLI, PostCSS plugin, Node.js API?

stylelint "**/*.js" --fix

Does the bug relate to non-standard syntax (e.g. SCSS, Less etc.)?

Yes, CSS-in-JS.

What did you expect to happen?

Output is the same as input, because no rules were run.

What actually happened (e.g. what warnings or errors did you get)?

Output code is broken JavaScript:

import styled, { css } from 'styled-components';
const Message = styled.p`
	padding: 10px;
	${(props) => css`
		color: #b02d00;
	`}
	${(props2) => css`
		border-color: red;
	`}

		color: #b02d00;
	`}
	${(props2) => css`
		border-color: red;
	`}
`;

Temporary solution is to refactor input code to not have nested tagged template literals:

// Before
const Message = styled.p`
	padding: 10px;

	${(props) => css`
		color: #b02d00;
	`}
`;

// After
const Message = styled.p`
	padding: 10px;

	${variant}
`;

const variant = (props) => css`
	color: #b02d00;
`;
@hudochenkov hudochenkov added status: blocked is blocked by another issue or pr status: ready to implement is ready to be worked on by someone type: bug a problem with a feature or rule syntax: css-in-js relates to JS objects & template literals labels Jun 17, 2019
@hudochenkov hudochenkov pinned this issue Dec 27, 2019
@hudochenkov hudochenkov added the priority: high is impactful on users label Dec 27, 2019
@jeddy3 jeddy3 changed the title Incorrect output with autofixing when CSS-in-JS has nested tagged template literals Fix incorrect output with autofixing when CSS-in-JS has nested tagged template literals Jan 12, 2020
@jeddy3 jeddy3 added help wanted is likely non-trival and help is wanted and removed status: blocked is blocked by another issue or pr labels Jan 12, 2020
@jeddy3 jeddy3 mentioned this issue Jan 29, 2020
23 tasks
@jeddy3 jeddy3 unpinned this issue Jan 29, 2020
@jeddy3 jeddy3 changed the title Fix incorrect output with autofixing when CSS-in-JS has nested tagged template literals Fix autofix for nested tagged template literals Jan 29, 2020
@jeddy3
Copy link
Member

jeddy3 commented Jan 29, 2020

We've forked the parser we use for CSS-in-JS into stylelint organisation, and we're looking for help to fix our fork to close this issue.

See #4574.

@jeddy3
Copy link
Member

jeddy3 commented Feb 15, 2020

Since 13.2.0 stylelint will no longer attempt to autofix sources containing this pattern, making the autofix feature safer to use.

However, the underlying issue remains in the parser that stylelint uses to support this syntax. Please consider contributing to the parser if you'd like to see this issue resolved fully.

@row248-hola
Copy link

I don't get it. Was it fixed or just closed?

@isellsoap
Copy link

@row248-hola See #4119 (comment). It’s just closed, not fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted is likely non-trival and help is wanted priority: high is impactful on users status: ready to implement is ready to be worked on by someone syntax: css-in-js relates to JS objects & template literals type: bug a problem with a feature or rule upstream relates to an upstream package
Development

Successfully merging a pull request may close this issue.

4 participants