Skip to content

[eslint-plugin] Fix single-value background: foo shorthand silently dropped — add lint error with autofix#1736

Open
alvinbillian wants to merge 1 commit into
facebook:mainfrom
alvinbillian:fix/eslint-plugin-background-shorthand
Open

[eslint-plugin] Fix single-value background: foo shorthand silently dropped — add lint error with autofix#1736
alvinbillian wants to merge 1 commit into
facebook:mainfrom
alvinbillian:fix/eslint-plugin-background-shorthand

Conversation

@alvinbillian

@alvinbillian alvinbillian commented Jun 24, 2026

Copy link
Copy Markdown

Problem

Single-value background shorthand like this:

image

is compiled without any linter warnings but produced no background: red style, ommitting that style entirely, giving false-positive result. (Reproduction in StyleX Playground)

The compiler requires the longhand syntaxes, e.g. background-color: red or background-image: url(image.jpg) instead.

Multi-token values like background: 'red no-repeat' are already caught by the linter:

image

What changed in the fix

  • The shorthand splitter already contains a full background token classifier that can identify colors, images, repeat keywords, attachment keywords, and position keywords. The fix routes single-token background values through this existing classifier instead of short-circuiting past it, so they are expanded to the correct longhand and flagged with an autofix.

  • One special case:
    In CSS, global keywords (inherit, initial, unset, revert, revert-layer) on the background shorthand apply to all sub-properties simultaneously:

    image

    There is no safe single-longhand expansion for this. Therefore, these are flagged as errors but with no autofix, leaving the developer to decide which specific longhands to set.

  • Added test cases

Example cases

Before (silent failure): image
After (lint error): image
After (autofix applied): image

Pre-flight checklist

@vercel

vercel Bot commented Jun 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
stylex Skipped Skipped Jun 24, 2026 1:58am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 24, 2026
@alvinbillian alvinbillian changed the title fix background shorthand linting Fix: background: foo shorthand silently dropped — add lint error with autofix Jun 24, 2026
@alvinbillian alvinbillian changed the title Fix: background: foo shorthand silently dropped — add lint error with autofix [eslint-plugin] Fix: background: foo shorthand silently dropped — add lint error with autofix Jun 24, 2026
@alvinbillian alvinbillian changed the title [eslint-plugin] Fix: background: foo shorthand silently dropped — add lint error with autofix [eslint-plugin] Fix single-value background: foo shorthand silently dropped — add lint error with autofix Jun 24, 2026
@alvinbillian alvinbillian marked this pull request as ready for review June 24, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant