at-if-no-null
What it does
Section titled “What it does”Reports an @if that compares with null (== null, != null).
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”With this configuration:
no-global-function-names: warnat-mixin-argumentless-call-parentheses: warnat-rule-conditional-no-parentheses: warnat-extend-no-missing-placeholder: warnat-if-no-null: warnload-no-partial-leading-underscore: warndollar-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-]+$" } }... @else if $a != null { top: 1; } @else if $a != null and $b { top: 2; } @if $a == null { top: 3; }}Configuration
Section titled “Configuration”css: lint: rules: at-if-no-null: warn # off (default), warn, errorless: lint: rules: at-if-no-null: warn # off (default), warn, errorscss: lint: rules: at-if-no-null: warn # off (default), warn, errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| stylelint-scss | scss/at-if-no-null |
full |