Skip to content

Omit prelude requirement for SCSS @else #46

@mrtnvh

Description

@mrtnvh

Problem

Snippet: https://github.com/csstree/stylelint-validator/blob/v2.0.0/lib/syntax-extension/sass/index.js

is causing the error

At-rule '@else' should contain a prelude (csstree/validator)

with code

  @if ($value == 0) {
    @return 0;
  } @else if ($value == 1) {
    @return 10;
  } @else {
    @return $delta;
  }
}

Analysis

As the else scss at-rule, doesn`t have a prelude, it looked like the simple solution would be:

// /lib/syntax-extension/sass/index.js#L56
syntaxConfig.atrules.else = {
    prelude: null
};
// /test/preprocessors.js#L80

// Add braces to ensure xxx is or is not seen as prelude
tr.ok('@else {}');
// Add missing else if
tr.ok('@else if {}');

But then the tr.ok('@else if {}'); assertion fails with At-rule '@else' should not contain a prelude (csstree/validator).

If we analyse the AST of the first code snippet (available here), the else if at-rule takes everything starting from if as prelude.

What should be the correct configuration for the else and else-if at-rule?

I've already forked the repo and tinkered with, without any success. Can you be of further assistance?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions