realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.59k stars 2.22k forks source link

switch/case alignment violation when using tabs #1902

Closed DG0BAB closed 3 years ago

DG0BAB commented 6 years ago

New Issue Checklist

Bug Report

Since version 0.23.0 switch/case alignment violations are issued when using tabs for indenting the source code. In our project we always use Tabs for indentation. This worked fine with version 0.21.0 and 0.22.0

Environment

line_length:
  warning: 180
  ignores_comments: true

colon:
  apply_to_dictionaries: false

identifier_name:
  min_length:
    error: 3
  max_length:
    warning: 60
  excluded:     # excluded via string array
    - qa
    - QA
    - id
    - i
    - iD
  allowed_symbols:
    - _

vertical_whitespace:
    max_empty_lines: 5

function_body_length:
    warning: 80
    error: 150

disabled_rules:
    todo

excluded: # paths to ignore during linting. overridden by `included`.
  - Carthage
                for result in results {
                    switch result {
                    case .fulfilled(let config):
                        if let c = config, c.enabled == true {
                            configurations.append(c)
                        }
                    case .rejected(let error):
                        self.logger?.error(error)
                    }
                }

The above code is indented with tabs and triggers an alignment violation even switch and case are correctly aligned.

mrcljx commented 6 years ago

Maybe related to #1893

mrcljx commented 6 years ago

Hey @DG0BAB,

would you happen to have the exact lint message on this one? Would like to verify whether that's a regression of my PR on SourceKitten.

Thanks!

DG0BAB commented 6 years ago

Hey! @sirlantis sorry for the delay. Currently I can't reproduce this anymore. The code above doesn't exist in that way any longer. Other switch case constructs, indented with tabs, don't trigger the alignment violation. As soon as I have another example I post it here including the lint message.

dregatos commented 6 years ago

Hi! I think that I am suffering the same issue...a switch case, constructed with tabs, triggers alignment violation for same of the cases 😳. Example:

screen shot 2018-04-25 at 16 27 59

I am seeing the issue in several switches. Any idea?

Thx!

SDGGiesbrecht commented 6 years ago

@dregatos, in your screenshot, only some cases caused errors. Are all of them tabulated, or just some?

What are the exact scalars preceding switch, and preceding each failing case?

For example, maybe one is [SP][HT] while another is [HT]. That would line up visually, but not logically.

dregatos commented 6 years ago

@SDGGiesbrecht, thank you for your time.

I created all the cases by pressing enter on the previous line, so all of them should have the same indentention. In any case, I solved the issue by aligning to the left all the lines of the switch, using control+[, and then re-indenting them, using control+i.

Regards, David

SDGGiesbrecht commented 6 years ago

@dregatos,

In any case, I solved the issue by aligning to the left all the lines of the switch, using control+[, and then re-indenting them, using control+i.

If that fixed it then there was something unusual about the whitespace in the source.

I should have mentioned it the first time, but if it happens again you can copy and paste the source into this online tool to inspect the scalars and better see what whitespace you actually have:

https://r12a.github.io/uniview/?charlist=%09switch%20{%0A%20%09case%20%2E%2E%2E

That information might help you discover how the oddities are creeping in.

Alegre que podo axudar./Alegre que puedo ajudar.

masters3d commented 6 years ago

So is this a confirmed bug?

on a side note: @SDGGiesbrecht, is this spanish? "Alegre que puedo ajudar"? If so, Are you saying "Happy to help" ? then you probably want to say "Alegre de poder ajudarte", then I again I could be wrong since spanish is not really portable across all cultures. :)

SDGGiesbrecht commented 6 years ago

@masters3d,

So is this a confirmed bug?

Hard to tell for sure.

However, @DG0BAB, who opened the issue, stated in November 2017 that he could no longer reproduce it. The only comments since then had to do with unexpected whitespace in the source file—SwiftLint was behaving properly.

The bug most likely is gone. (Or it may even have merely been whitespace confusion from the beginning.)


You probably want to say, «Alegre de poder ajudarte.»

Sí. Gracias. Solo hablo un poco español.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!