Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested if else blocks are not properly indented #330

Open
Tofandel opened this issue Aug 26, 2020 · 0 comments
Open

Nested if else blocks are not properly indented #330

Tofandel opened this issue Aug 26, 2020 · 0 comments

Comments

@Tofandel
Copy link
Contributor

Tofandel commented Aug 26, 2020

Reproduction

=ltr-property($property, $spacing, $deprecated: null)
  @if $deprecated != null
    $pos: "left"
    @if $deprecated
      $pos: "right"
    @warn "The third argument of ltr-property was deprecated, use the full name of the property instead"
    +ltr-property($property+"-"+$pos, $spacing)
  @else
    @if $rtl
      @if str-index($property, 'left')
        #{str-replace($property, 'left', 'right')}: $spacing
      @else if str-index($property, 'right')
        #{str-replace($property, 'right', 'left')}: $spacing
      @else if str-index($property, 'border-radius')
        @if type-of($spacing) == 'list'
          @if length($spacing) == 2
            #{$property}: nth($spacing, 2) nth($spacing, 1)
          @else if length($spacing) == 3
            #{$property}: nth($spacing, 2) nth($spacing, 1) nth($spacing, 2) nth($spacing, 3)
          @else if length($spacing) == 4
            #{$property}: nth($spacing, 2) nth($spacing, 1) nth($spacing, 4) nth($spacing, 3)
          @else
            @warn "Invalid usage of ltr-property"
        @else
          @warn "Invalid usage of ltr-property"
      @else if type-of($spacing) == 'list' and length($spacing) == 4
        #{$property}: nth($spacing, 1) nth($spacing, 4) nth($spacing, 3) nth($spacing, 2)
      @else
        +ltr-property($property, $spacing, true)
      //Warn of deprecated use
    @else
      @if not str-index($property, 'left') and not str-index($property, 'right') and type-of($spacing) != 'list'
        +ltr-property($property, $spacing, true)
        //Warn of deprecated use
      @else
        #{$property}: $spacing

When lint fixing this file the output is

=ltr-property($property, $spacing, $deprecated: null)
  @if $deprecated != null
    $pos: "left"
    @if $deprecated
      $pos: "right"
    @warn "The third argument of ltr-property was deprecated, use the full name of the property instead"
    +ltr-property($property+"-"+$pos, $spacing)
  @else
    @if $rtl
      @if str-index($property, 'left')
        #{str-replace($property, 'left', 'right')}: $spacing
      @else if str-index($property, 'right')
        #{str-replace($property, 'right', 'left')}: $spacing
      @else if str-index($property, 'border-radius')
        @if type-of($spacing) == 'list'
          @if length($spacing) == 2
            #{$property}: nth($spacing, 2) nth($spacing, 1)
          @else if length($spacing) == 3
            #{$property}: nth($spacing, 2) nth($spacing, 1) nth($spacing, 2) nth($spacing, 3)
          @else if length($spacing) == 4
            #{$property}: nth($spacing, 2) nth($spacing, 1) nth($spacing, 4) nth($spacing, 3)
          @else
            @warn "Invalid usage of ltr-property"
@else
          @warn "Invalid usage of ltr-property"
      @else if type-of($spacing) == 'list' and length($spacing) == 4
        #{$property}: nth($spacing, 1) nth($spacing, 4) nth($spacing, 3) nth($spacing, 2)
      @else
        +ltr-property($property, $spacing, true)
      //Warn of deprecated use
    @else
      @if not str-index($property, 'left') and not str-index($property, 'right') and type-of($spacing) != 'list'
        +ltr-property($property, $spacing, true)
        //Warn of deprecated use
      @else
        #{$property}: $spacing

Notice how one else block lost it's indentation, this then causes a parse error

Edit:

Additional information, it seems this is caused by the warn block, I have found a workaround

Workaround

=ltr-property($property, $spacing, $deprecated: null)
  @if $deprecated != null
    $pos: "left"
    @if $deprecated
      $pos: "right"
    @warn "The third argument of ltr-property was deprecated, use the full name of the property instead"
    +ltr-property($property+"-"+$pos, $spacing)
  @else
    @if $rtl
      @if str-index($property, 'left')
        #{str-replace($property, 'left', 'right')}: $spacing
      @else if str-index($property, 'right')
        #{str-replace($property, 'right', 'left')}: $spacing
      @else if str-index($property, 'border-radius')
        @if type-of($spacing) == 'list'
          @if length($spacing) == 2
            #{$property}: nth($spacing, 2) nth($spacing, 1)
          @else if length($spacing) == 3
            #{$property}: nth($spacing, 2) nth($spacing, 1) nth($spacing, 2) nth($spacing, 3)
          @else if length($spacing) == 4
            #{$property}: nth($spacing, 2) nth($spacing, 1) nth($spacing, 4) nth($spacing, 3)
          @else
            @warn "Invalid usage of ltr-property"
            //We need a comment here or linter poops itself
        @else
          @warn "Invalid usage of ltr-property"
      @else if type-of($spacing) == 'list' and length($spacing) == 4
        #{$property}: nth($spacing, 1) nth($spacing, 4) nth($spacing, 3) nth($spacing, 2)
      @else
        +ltr-property($property, $spacing, true)
      //Warn of deprecated use
    @else
      @if not str-index($property, 'left') and not str-index($property, 'right') and type-of($spacing) != 'list'
        +ltr-property($property, $spacing, true)
        //Warn of deprecated use
      @else
        #{$property}: $spacing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant