Follow-up to #4462: migrate remaining @var fixtures, DRY the prelude bare-@var scan, add warnings coverage#4469
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughLess parser fallback deprecation handling was adjusted, integration coverage was added for at-rule prelude variable warnings, and test fixtures now interpolate variables in ChangesAt-rule interpolation and deprecation parsing
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/less/lib/less/parser/parser.js`:
- Around line 118-132: Update hasTopLevelBareVariable to accept the incoming
parenthesis depth and return both the updated depth and whether a top-level bare
variable was found. In permissiveValue, initialize parenDepth before iterating
parsed fragments, pass it into hasTopLevelBareVariable for each unquoted item,
retain the returned depth for the next fragment, and use the returned found flag
for deprecation warnings.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6119c9cc-611f-4b83-a8c4-c4a23aa61e21
📒 Files selected for processing (11)
packages/less/lib/less/deprecation.jspackages/less/lib/less/parser/parser.jspackages/test-data/tests-config/at-rules-compressed-evaluation/at-rules-compressed-evaluation.lesspackages/test-data/tests-unit/at-rule-variable-deprecated/at-rule-variable-deprecated.csspackages/test-data/tests-unit/at-rule-variable-deprecated/at-rule-variable-deprecated.lesspackages/test-data/tests-unit/container/container.lesspackages/test-data/tests-unit/import/import/import-reference.lesspackages/test-data/tests-unit/layer/layer.lesspackages/test-data/tests-unit/media/media.lesspackages/test-data/tests-unit/permissive-parse/permissive-parse.lesspackages/test-data/tests-unit/variables-in-at-rules/variables-in-at-rules.less
31ee756 to
2c89713
Compare
Follow-up to less#4462, which deprecated bare @variable in non-value at-rule positions and migrated most fixtures to @{variable} but left two feature fixtures on the bare form: - tests-unit/layer/layer.less @layer @layer-name - tests-unit/import/import/import-reference.less @Keyframes @keyframeName Migrated to @{layer-name} / @{keyframeName} (byte-identical render). Also repairs pnpm-lock.yaml: master had a dangling `minimatch: 3.1.2` dependency edge with no package entry (bad-merge artifact), so `pnpm install --frozen-lockfile` failed for every PR. Repinned to the resolved 3.1.5 already present; no dependency version changes.
2c89713 to
92c62bb
Compare
f999e46 to
14e4a6e
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/less/test/less-test.js (1)
841-865: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winEnsure the logger listener is removed if an unexpected error occurs.
If an unexpected exception is thrown inside the test loop (e.g., from an assertion failure or an unhandled bug), the function will exit early and leave the listener attached to the global
less.logger. This can pollute subsequent tests. Wrapping the logic in atry...finallyblock guarantees that the listener is always removed.♻️ Proposed refactor
less.logger.addListener(listener); - const isPrelude = m => /A bare `@variable` in an at-rule prelude is deprecated/.test(m); - const cases = [ - ['`@bar`: x;\n@foo `@bar` { a: b }', 1, 'bare `@var` in an unknown at-rule prelude warns'], - ['`@a`: 1; `@b`: 2;\n@foo `@a` and `@b` { a: b }', 2, 'bare `@vars` around a keyword both warn'], - ['`@v`: 1px;\n@foo (x: `@v`) { a: b }', 0, '`@var` inside (...) is a declaration value — no warning'], - ['`@v`: x;\n@foo bar[`@v`] { a: b }', 0, '`@var` inside [...] is a lookup, not structural — no warning'], - ]; - for (const [src, expected, label] of cases) { - totalTests++; - captured.length = 0; - try { - await less.render(src); - } catch (e) { - fail('- Integration - at-rule prelude `@var` warning: ' + label + ' threw ' + e + '\n'); - continue; - } - const n = captured.filter(isPrelude).length; - if (n === expected) { - ok('- Integration - at-rule prelude `@var` warning: ' + label + ' OK\n'); - } else { - fail('- Integration - at-rule prelude `@var` warning: ' + label + ' — expected ' + expected + ', got ' + n + '\n'); - } - } - less.logger.removeListener(listener); + try { + const isPrelude = m => /A bare `@variable` in an at-rule prelude is deprecated/.test(m); + const cases = [ + ['`@bar`: x;\n@foo `@bar` { a: b }', 1, 'bare `@var` in an unknown at-rule prelude warns'], + ['`@a`: 1; `@b`: 2;\n@foo `@a` and `@b` { a: b }', 2, 'bare `@vars` around a keyword both warn'], + ['`@v`: 1px;\n@foo (x: `@v`) { a: b }', 0, '`@var` inside (...) is a declaration value — no warning'], + ['`@v`: x;\n@foo bar[`@v`] { a: b }', 0, '`@var` inside [...] is a lookup, not structural — no warning'], + ]; + for (const [src, expected, label] of cases) { + totalTests++; + captured.length = 0; + try { + await less.render(src); + } catch (e) { + fail('- Integration - at-rule prelude `@var` warning: ' + label + ' threw ' + e + '\n'); + continue; + } + const n = captured.filter(isPrelude).length; + if (n === expected) { + ok('- Integration - at-rule prelude `@var` warning: ' + label + ' OK\n'); + } else { + fail('- Integration - at-rule prelude `@var` warning: ' + label + ' — expected ' + expected + ', got ' + n + '\n'); + } + } + } finally { + less.logger.removeListener(listener); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/less/test/less-test.js` around lines 841 - 865, Wrap the at-rule prelude warning test setup and loop, beginning after less.logger.addListener(listener), in a try...finally block, and move less.logger.removeListener(listener) into the finally clause. Preserve the existing test counting, rendering, and pass/fail behavior while ensuring the listener is removed on every exit path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/less/test/less-test.js`:
- Around line 841-865: Wrap the at-rule prelude warning test setup and loop,
beginning after less.logger.addListener(listener), in a try...finally block, and
move less.logger.removeListener(listener) into the finally clause. Preserve the
existing test counting, rendering, and pass/fail behavior while ensuring the
listener is removed on every exit path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 84edc41c-caed-4727-917f-fc2b315264eb
📒 Files selected for processing (3)
packages/less/lib/less/parser/parser.jspackages/less/test/index.jspackages/less/test/less-test.js
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/less/lib/less/parser/parser.js
14e4a6e to
92c62bb
Compare
… output less.js asserts errors via tests-error/*.txt but had no coverage that warnings actually fire, so deprecation notices were unguarded (nothing would catch a regression that silently stopped emitting one). - Suppress warnings from normal test output (they are noise across the corpus); set LESS_TEST_SHOW_WARNINGS=1 to see them. - Add testWarnings() (run from index.js) which installs a capturing logger listener and asserts each render-reachable warning fires: variable-in-at-rule- prelude (incl. bar[@v] top-level -> warns and (x:@v) decl-value -> no warn), js-eval, mixin-call-whitespace, mixin-call-no-parens, variable-in-unknown-value, dot-slash-operator, complex-selector, extend-no-match, compress, at-plugin. Documented gaps (not render-reachable): property-in-unknown-value (a $prop ref resolves via the entity path before the permissive text scan), math-always and dumpLineNumbers (registered in deprecation.js but never emitted via warn()).
…eUntil (DRY) The at-rule-prelude deprecation detected a top-level bare @var two ways: the permissiveValue entity loop (structural), plus a standalone hasTopLevelBareVariable() that RE-SCANNED the same text $parseUntil had already walked, with its own hand-rolled paren counter (and no string/comment handling). Fold that second scan into $parseUntil's single pass: it already skips strings/comments/ escapes and tracks brackets, so add an opt-in `detectBareVar` that records the first bare @var (not @{interp}) seen at PAREN depth 0 — [...]/{...} don't shield a reference, only a declaration-value (...) does — exposed as `.bareVarIndex`. $parseUntil has a single caller (permissiveValue), so the extra arg/property is contained. Delete hasTopLevelBareVariable. Behaviour preserved (regression-guarded by testWarnings): @foo @bar -> 1, @A and @b -> 2, bar[@v] -> 1 (bracket is top-level), (x:@v) -> 0 (decl value), and the mixed (a:@x) y[@z] -> 1. Also drops the testWarnings 'variable-in-unknown-value' case: it only fires for the inconsistent bracket edge (--x: bar[@bar]) while --x: @bar / 1px @bar / foo(@bar) resolve silently, so asserting it would lock in an artifact (now documented).
Follow-up to #4462 (bare-
@variableat-rule deprecation). Four pieces:Fixture migration — feat: deprecate bare @variable in non-value at-rule positions #4462 left two fixtures on the bare form (
layer.less,import-reference.less); migrated to@{…}(byte-identical render).Warnings-assertion coverage (new) — less.js asserted errors (
tests-error/*.txt) but never that warnings fire, so deprecations were unguarded. AddstestWarnings()capturing logger warnings and asserting each render-reachable one, incl. the prelude semantics (bar[@v]→warns,(x:@v)→no warn). Warnings are now suppressed from normal output (LESS_TEST_SHOW_WARNINGS=1to see them). Documented gaps:variable-in-unknown-value(only fires for an inconsistent bracket edge),property-in-unknown-value(not render-reachable),math-always/dumpLineNumbers(registered but never emitted).DRY the prelude bare-
@vardetection — replaced the standalonehasTopLevelBareVariable()(which re-scanned text$parseUntilhad already walked, with a hand-rolled()-only counter and no string/comment handling) by folding an opt-indetectBareVarinto$parseUntil's single pass (it already skips strings/comments and tracks brackets;$parseUntilhas one caller). Guarded green-to-green by the new tests.Lockfile repair —
master'spnpm-lock.yamlhad a danglingminimatch: 3.1.2edge failing--frozen-lockfilefor every PR; repinned to3.1.5.Full
grunt testgreen; all 7 CI jobs pass.