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 erroneous changes for float property #4490

Closed
Tracked by #4574
wilhen01 opened this issue Dec 24, 2019 · 9 comments · Fixed by stylelint/postcss-css-in-js#172
Closed
Tracked by #4574

Fix autofix erroneous changes for float property #4490

wilhen01 opened this issue Dec 24, 2019 · 9 comments · Fixed by stylelint/postcss-css-in-js#172
Labels
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 upstream relates to an upstream package

Comments

@wilhen01
Copy link

Clearly describe the bug

I'm using Stylelint with a typescript project that contains styled components using the @emotion/styled library. When running styelint --fix on the codebase, instances of float are incorrectly changed to cssFloat, which breaks the styling. Weirdly, no warnings are emitted, either with or without the fix flag.

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

Not sure what rule causes this behaviour, haven't had any luck tracking it down in the docs.

What CSS is needed to reproduce the bug?

Example styled component

const StyledCloseBtn = styled(Btn)<Btn.propTypes>({
  float: 'right',
  minWidth: 'unset !important',
  position: 'relative',
  top: -2,
  svg: { fill: 'currentColor', width: 16, height: 16 }
});

after running the fix command it changes to:

const StyledCloseBtn = styled(Btn)<Btn.propTypes>({
  cssFloat: 'right',
  minWidth: 'unset !important',
  position: 'relative',
  top: -2,
  svg: { fill: 'currentColor', width: 16, height: 16 }
});

What stylelint configuration is needed to reproduce the bug?

Complete config below

module.exports = {
  extends: [
    'stylelint-config-standard',
    'stylelint-a11y/recommended',
    'stylelint-config-prettier'
  ],
  plugins: ['stylelint-no-unsupported-browser-features'],
  rules: {
    'plugin/no-unsupported-browser-features': [
      true,
      {
        browsers: ['last 1 edge version']
      }
    ],
    'color-named': 'never',
    'color-hex-case': 'upper',
    'color-hex-length': 'long',
    'declaration-no-important': true,
    'function-parentheses-space-inside': 'never',
    'function-comma-space-before': 'never',
    'function-comma-space-after': 'always',
    'declaration-empty-line-before': 'never',
    'declaration-block-single-line-max-declarations': null
  }
};

Which version of stylelint are you using?

12.0.0 (also occurs on 10.1.0, upgrade made no difference)

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

CLI with stylelint ./src --fix

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

Yes, styled components

What did you expect to happen?

No changes to be made to the file

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

float changed to cssFloat. No warnings are emitted, either with or without the fix flag.

@wilhen01 wilhen01 changed the title Using stylelint --fix erroneously changes styled component float property Using stylelint --fix erroneously changes styled component float property Dec 24, 2019
@hudochenkov hudochenkov added syntax: css-in-js relates to JS objects & template literals type: bug labels Dec 25, 2019
@hudochenkov
Copy link
Member

Thanks for the report and for using the template.

Most likely problem in postcss-jsx parser, which we use for CSS-in-JS.

@hudochenkov hudochenkov added the priority: high is impactful on users label Dec 27, 2019
@jeddy3
Copy link
Member

jeddy3 commented Jan 11, 2020

Labeling as "help wanted" if anyone has time to fix the issue upstream in the postcss-jsx parser.

@jeddy3 jeddy3 changed the title Using stylelint --fix erroneously changes styled component float property Fix autofix erroneous changes for float property Jan 11, 2020
@jeddy3 jeddy3 added the status: ready to implement is ready to be worked on by someone label Jan 11, 2020
@jeddy3 jeddy3 mentioned this issue Jan 29, 2020
23 tasks
@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 jeddy3 added the upstream relates to an upstream package label Feb 15, 2020
@jeddy3
Copy link
Member

jeddy3 commented Feb 15, 2020

I've labelled this as "upstream" as this is an issue in one of the syntaxes stylelint uses. Please consider contributing to that syntax if you'd like the see this issue resolved fully.

If you're unable to contribute to the syntax, please consider contributing a workaround to stylelint itself so that it won't attempt to autofix sources that contain float properties in JavaScript objects.

@guoyunhe
Copy link

I am having the same issue. Have to disable stylelint to make my code work...

@alzalabany
Copy link

this is still active problem :/;
to avoid i had to do

const styles = { };
styles.float = 'right';

<a style={ styles }> ....</a>

just to note, this is problem not just with styled-components; i'm facing this in jsx in general

rbong pushed a commit to rbong/postcss-css-in-js that referenced this issue Jun 5, 2021
The value should only be transformed if the raw value was also
"cssFloat". Otherwise, we should allow the user to use the "float"
keyword in the cases it is actually valid, which we can't easily detect.

Misuse of the keyword can be caught by Javascript code analysis tools.

Fixes: stylelint/stylelint#4490
rbong added a commit to rbong/postcss-css-in-js that referenced this issue Jun 5, 2021
The value should only be transformed if the raw value was also
"cssFloat". Otherwise, we should allow the user to use the "float"
keyword in the cases it is actually valid, which we can't easily detect.

Misuse of the keyword can be caught by Javascript code analysis tools.

Fixes: stylelint/stylelint#4490
@Avivhdr
Copy link

Avivhdr commented Jun 17, 2021

Any progress with @rbong's PR?

@jeddy3
Copy link
Member

jeddy3 commented Jan 18, 2022

Closing as the syntax option was removed for the 14.0.0 release. (See the migration guide.)

We'll also be deprecating our forked CSS-in-JS package, in favour of leaner custom syntaxes.

Please consider writing a custom syntax specific to the CSS-in-JS library in this issue and fixing the bug there.

@jeddy3 jeddy3 closed this as completed Jan 18, 2022
hudochenkov pushed a commit to stylelint/postcss-css-in-js that referenced this issue May 3, 2022
The value should only be transformed if the raw value was also
"cssFloat". Otherwise, we should allow the user to use the "float"
keyword in the cases it is actually valid, which we can't easily detect.

Misuse of the keyword can be caught by Javascript code analysis tools.

Fixes: stylelint/stylelint#4490
@hudochenkov
Copy link
Member

Fix released in @stylelint/postcss-css-in-js@0.38.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 upstream relates to an upstream package
Development

Successfully merging a pull request may close this issue.

6 participants