Skip to content

fix: stop CSS lint errors for the fr unit and custom properties - #639

Merged
imantsk merged 1 commit into
codesnippetspro:release/v4.1.2/corefrom
theluckystrike:fix/css-lint-modern-syntax
Nov 27, 2026
Merged

imantsk merged 1 commit into
codesnippetspro:release/v4.1.2/corefrom
theluckystrike:fix/css-lint-modern-syntax

Conversation

@theluckystrike

Copy link
Copy Markdown

Fixes #380, #171 and #143.

CSS snippets show lint errors for valid CSS. WordPress ships CSSLint 1.0.5, and its parser predates the fr unit and custom properties:

  • grid-template-columns: 1fr 2fr gives "Unexpected token '1fr'".
  • --main-color: #fff gives "Expected RBRACE".
  • color: var(--main-color) gives "Expected () but found 'var(--main-color)'".

What I changed:

  • src/js/utils/cssLint.ts runs CSSLint on a copy of the code where 1fr becomes 1px and --name becomes -xname. Both rewrites keep every character position, so the markers stay on the right line and column. CSSLint reads -xname as a vendor-prefixed property and does not validate it.
  • The known-properties warnings for a value that uses var() are dropped, because CSSLint cannot resolve a variable.
  • src/js/entries/editor.ts registers this as the CodeMirror css lint helper, in place of the one from the WordPress CodeMirror bundle. It takes the same options, so the CSSLint ruleset from the WordPress settings still applies.

Real problems are still reported: an unknown property such as colr and a missing closing brace.

Tests: tests/e2e/css-lint.spec.ts calls the registered helper on the Add Snippet screen for the fr unit, custom properties with var(), and two real errors. I checked the same cases against CSSLint 1.0.5 in Node: without the change the first two cases give the errors above, with the change they give none, and the real errors stay. I could not run the wp-env suite on this machine. ESLint and tsc pass on the changed files. The spec passes the CSSLint ruleset from wp.codeEditor.defaultSettings, as the editor does.

WordPress ships CSSLint 1.0.5, whose parser predates the fr unit and custom
properties. Lint a copy of the code where 1fr becomes 1px and --name becomes
-xname (same positions), and drop var() value warnings from known-properties.

Fixes codesnippetspro#380, codesnippetspro#171, codesnippetspro#143.
@imantsk
imantsk changed the base branch from core to release/v4.1.2/core November 27, 2026 17:22
@imantsk imantsk added the run-tests Trigger automated tests label Nov 27, 2026
@imantsk
imantsk merged commit 127fc71 into codesnippetspro:release/v4.1.2/core Nov 27, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-tests Trigger automated tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants