Skip to content

at-if-no-null

Reports an @if that compares with null (== null, != null).

In Sass null and false are falsy and everything else is truthy, so $a == null is written more directly as not $a, and $a != null as $a. The shorter form also treats false the way a condition does.

To fix, use @if not $a or @if $a.

With this configuration:

no-global-function-names: warn
at-mixin-argumentless-call-parentheses: warn
at-rule-conditional-no-parentheses: warn
at-extend-no-missing-placeholder: warn
at-if-no-null: warn
load-no-partial-leading-underscore: warn
dollar-variable-pattern: { level: warn, options: { pattern: "^[a-z-]+$" } }
at-mixin-pattern: { level: warn, options: { pattern: "^[a-z-]+$" } }
at-function-pattern: { level: warn, options: { pattern: "^[a-z-]+$" } }
Reported
...
@else if $a != null { top: 1; }
@else if $a != null and $b { top: 2; }
@if $a == null { top: 3; }
}
css:
lint:
rules:
at-if-no-null: warn # off (default), warn, error
less:
lint:
rules:
at-if-no-null: warn # off (default), warn, error
scss:
lint:
rules:
at-if-no-null: warn # off (default), warn, error

Enabled by the presets: css/stylelint-standard.

Suppress one line with sudsy-disable-next-line at-if-no-null in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
stylelint-scss scss/at-if-no-null full