noScssNullComparison (CSS)
Language CSS
Summary
Section titled “Summary”- Rule available since:
v2.6.7 - Diagnostic Category:
lint/nursery/noScssNullComparison - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Inspired from
scss/at-if-no-null
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noScssNullComparison": "error" } } }}Description
Section titled “Description”Disallow comparing values to null in Sass @if conditions.
In Sass, null counts as false in a condition. Writing $value == null or $value != null
in an @if condition is longer than needed: not $value and $value check the same thing
in most cases.
The rule checks the conditions of @if and @else if, including comparisons combined
with and, or and not.
A != null check followed by and, as in $value != null and $value > 1, isn’t reported.
This is a common way to check that a value exists before using it in the rest of the
condition.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”a { @if $value == null {}}code-block.scss:2:7 lint/nursery/noScssNullComparison ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This condition compares a value to null.
1 │ a {
> 2 │ @if $value == null {}
│ ^^^^^^^^^^^^^^
3 │ }
4 │
ℹ In Sass, null counts as false in a condition, so the comparison isn't needed.
ℹ Check the value with not instead, as in @if not $value.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
a { @if $value != null {}}code-block.scss:2:7 lint/nursery/noScssNullComparison ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This condition compares a value to null.
1 │ a {
> 2 │ @if $value != null {}
│ ^^^^^^^^^^^^^^
3 │ }
4 │
ℹ In Sass, null counts as false in a condition, so the comparison isn't needed.
ℹ Use the value as the condition instead, as in @if $value.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
a { @if $value {} @if not $value {} @if $value != null and $value > 1 {}}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.