Skip to content

ESLint valid-styles rule rejects nested conditions inside stylex.when.*() computed keys #1614

Description

@skovhus

Describe the issue

The stylex-valid-styles ESLint rule rejects a media query (or other condition) nested inside a stylex.when.ancestor() / stylex.when.descendant() / etc.
computed key, even though the Babel compiler handles it correctly and produces valid CSS.

Expected behavior

The ESLint rule should accept stylex.when.*() as a condition key even when its value is a nested condition object, matching the compiler behavior.

@stylexjs/eslint-plugin — all versions since stylex.when support was added (#1270).

Steps to reproduce

import * as stylex from '@stylexjs/stylex';

  const styles = stylex.create({
    icon: {
      transitionDuration: {
        default: vars.slow,
        [stylex.when.ancestor(":active")]: vars.fast, // OK
        [stylex.when.ancestor(":hover")]: {
          default: null,
          "@media (hover: hover)": vars.fast, // ERROR
        },
      },
    },
  });

Test case

No response

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions