Skip to content

[no-inline-styles] ternary style gets mistakenly reported #317

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

Open
uloco opened this issue May 13, 2022 · 3 comments
Open

[no-inline-styles] ternary style gets mistakenly reported #317

uloco opened this issue May 13, 2022 · 3 comments

Comments

@uloco
Copy link

uloco commented May 13, 2022

I get a warning on this inline style:

<View
  style={[
    styles.safeAreaTransparent,
    { height: props.insetsTop ? insets.top : 0, },  // <---- eslint(react-native/no-inline-styles)
  ]}
/>

Does this behaviour work as expected?
If so, how should we change these?

I think it should not report as a warning though ...

@nobi1007
Copy link

Yeah, all conditional expressions by default are considered invalid here. I think plugin should accept some pattern config to apply only certain validations and skip others.

@uloco
Copy link
Author

uloco commented Jun 1, 2022

I think it should be configureable, so that if there are variables in it, it should not report at all. Because it makes the code much more complicated with little benefit. If I am already using an inline style because of a conditional, I don't want to goo to the style definition and look up what style will be applied in the else case for example. But it totally makes sense for disabling inline styles in general for other cases

@ridvanaltun
Copy link

I think the plugin should accept conditional expressions etc.

devin-ai-integration bot added a commit to energyenables/eslint-plugin-react-native that referenced this issue Mar 14, 2025
This fixes issue Intellicode#317 where ternary expressions with variables were incorrectly flagged as inline style violations. The fix changes the condition to only mark ternary expressions as invalid if both the consequent and alternate are literals, allowing ternary expressions with variables to pass the linting rule.

Co-Authored-By: Jamie Williams <[email protected]>
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

3 participants