Commit 409260b
Refactor var() parsing logic for improved clarity (#66)
## Summary
Refactored the `collect_var_usages` function to simplify the logic for
detecting CSS custom property usages within `var()` functions. The new
implementation is more concise and easier to understand while
maintaining the same functionality.
## Key Changes
- **Simplified var() detection logic**: Replaced nested loops and
conditional checks with early returns, reducing cognitive complexity
- **Direct property access**: Changed from iterating through
`node.children` to directly accessing `first_child` and `next_sibling`
properties
- **Cleaner fallback detection**: Simplified `has_fallback` detection by
checking if `first_sibling` exists rather than iterating through
children
- **Added test coverage**: Added comprehensive tests for `var()` usages
inside `light-dark()` function in both rule test files and utility test
file
## Implementation Details
The refactored code maintains identical behavior:
- Still correctly identifies custom property names (those starting with
`--`)
- Still detects whether a fallback value is present
- Still works with nested functions like `light-dark(var(...),
var(...))`
- Early return pattern improves readability and reduces nesting depth
All existing tests pass, and new tests verify the functionality works
correctly with the `light-dark()` CSS function.
https://claude.ai/code/session_012pu1Bv9AuopQ9ExG87ZSe5
Co-authored-by: Claude <noreply@anthropic.com>1 parent bfb2360 commit 409260b
4 files changed
Lines changed: 72 additions & 17 deletions
File tree
- src
- rules
- no-unknown-custom-property
- no-unused-custom-properties
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
402 | 428 | | |
403 | 429 | | |
404 | 430 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
337 | 337 | | |
338 | 338 | | |
339 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
340 | 366 | | |
341 | 367 | | |
342 | 368 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
108 | 118 | | |
109 | 119 | | |
110 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
56 | 49 | | |
57 | 50 | | |
58 | 51 | | |
| |||
0 commit comments