facebook / stylex

StyleX is the styling system for ambitious user interfaces.
https://stylexjs.com
MIT License
8.38k stars 310 forks source link

@stylexjs/eslint-plugin shows error for @stylexjs/valid-styles when using stylex.firstThatWorks #699

Open lifeiscontent opened 2 weeks ago

lifeiscontent commented 2 weeks ago

Describe the issue

when using stylex.firstThatWorks on a property, I'm seeing ESLint errors for @stylexjs/valid-styles

e.g.

const styles = stylex.create({
  example: {
    position: stylex.firstThatWorks("sticky", "fixed") // errors, but shouldn't
  }
})

Expected behavior

using the above code should work with ESLint Rule

Steps to reproduce

  1. use the example
  2. see ESLint showing error, even though the styles are valid.

Test case

No response

Additional comments

No response

RavenColEvol commented 2 weeks ago

Thinking out loud here on possible solution, ofc there could be problems with it but still it's better to initiate a thought process on it. From my assumption firstThatWorks may receive 2 types of values either variables or absolute values. I have not seen code but 2 things might change

  1. firstThatWorks method: to have generic return type based on input. So it will make sure that scenarios like above are solved and it won't harm properties which don't expect strict unions ( like string | number )
  2. eslint valid-styles: we could have a case where position may receive value in form of variable. In that case it's a valid situation but still as a code we are unsure so maybe we can provide warning that it may not be the proper value or bypass variables from it.

What you say @nmn ?

nmn commented 2 weeks ago

This is an issue in the ESLint valid-styles rule. It is not correctly parsing firstThatWork and checking the arguments passed it.