SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Support tabs in vertical parameter alignment rule

Open DevAndArtist opened this issue 7 years ago • 16 comments

My swift files are formatted using AppCode and tabs. Therefore only a few spaces are added automatically when necessary:

private func snap(label: UILabel,
				  below otherView: UIView,
				  offsetBy value: CGFloat) -> [NSLayoutConstraintInterface] {

In Xcode, AppCode and SublimeText these labels are aligned. Tab and ident width is 4.

SwiftLint version: 0.18.1 If I'm not mistaken, GitHub uses a tab width of 8.

DevAndArtist avatar May 26 '17 16:05 DevAndArtist

Well I managed to solve the problem using smart tabs in AppCode which matches the behavior of Xcode as well. You can consider this issue as resolved. 🙈

DevAndArtist avatar May 26 '17 18:05 DevAndArtist

I'm glad that you figured this out, but anyway we probably should support tabs as well

marcelofabri avatar May 28 '17 11:05 marcelofabri

@marcelofabri I'm confused, some tabs works other don't. Now I bumped into that issue in Xcode as well.

New Issue Checklist

Bug Report

  • SwiftLint version: 0.24.0
  • Installation method used: CocoaPods
  • Configuration file:
opt_in_rules:
  - closure_end_indentation
  - closure_spacing
  - fatal_error_message
  - force_unwrapping
  - sorted_imports
  - operator_usage_whitespace
  - redundant_nil_coalescing
  - switch_case_on_newline
  - attributes
  - no_extension_access_modifier
  - implicit_return

# rule identifiers to exclude from running
disabled_rules: 
  - colon
  - closure_parameter_position
  - opening_brace
  - file_length
  - implicit_return
  - private_over_fileprivate

# paths to ignore during linting
excluded: 
  - Pods

identifier_name:
  # excluded via string array
  excluded: 
    - px
    - s
    - f
    - ec
    - wb
    - tv
    - av
    - fn

large_tuple: 4

cyclomatic_complexity: 20

nesting:
  type_level: 2

trailing_whitespace:
  ignores_empty_lines: true
  ignores_comments: true

attributes:
  always_on_same_line: ["@IBAction", "@IBOutlet", "@IBInspectable"]
  always_on_line_above: ["@IBDesignable", "@UIApplicationMain", "@discardableResult", "@objc"]
  • Xcode version: Version 9.1 (9B55)
  • Code that reproduces the issue:
struct Test {
	init(x _: Int,
		 y _: Int,
		 z _: Int) {
		print("""
		y and z lines are indeded by Xcode via `control + i`
		Vertical Parameter Alignment Violation: Function parameters should be aligned \
		vertically if they're in multiple lines in a declaration. (vertical_parameter_alignment)
		""")
	}
}

DevAndArtist avatar Nov 21 '17 20:11 DevAndArtist

I'm confused, this issue is closed but my linter is still throwing warning for this rule in both function and initializers.

  • SwiftLint version: 0.24.2
  • Installation method used: Homebrew
  • Configuration file:
# rule identifiers to exclude from running
disabled_rules:
    - trailing_whitespace
    - vertical_whitespace
    - void_return
    - trailing_newline


# paths to ignore during linting. Takes precedence over `included`.
excluded:
 - FieldEnvironmentExample
 - FieldEnvironmentKitTests


# custom rules and overrides
identifier_name:
 excluded:
  - id


line_length: 200


attributes:
    always_on_same_line: ["@IBAction", "@IBOutlet", "@IBInspectable"]
    always_on_line_above: ["@IBInspectable", "@UIApplicationMain", "@discardableResult", "@objc"]
  • Xcode version: Version 9.2 (9C40b) Code that reproduces the issue:
final internal class FieldEnvironment: FieldEnvironmentInterface {
    init(environment: Environment,
         sitesPersistence: SitesPersistenceInterface,
         sitesDownloader: SitesDownloaderInterface,
         plotsPersistence: PlotsPersistenceInterface,
         plotsDownloader: PlotsDownloaderInterface) {
            self.environment = environment
	    self.sitesPersistence = sitesPersistence
	    self.sitesDownloader = sitesDownloader
	    self.plotsPersistence = plotsPersistence
	    self.plotsDownloader = plotsDownloader
    }
}

im-jersh avatar Jan 29 '18 17:01 im-jersh

@oriyentel This issue is not closed 🤔

marcelofabri avatar Jan 29 '18 17:01 marcelofabri

@marcelofabri, any chances this is going to be resolved? The tabs also affect the line_length rule, which treats tab as a single character (which it is) but visually is shown as 4 spaces in Xcode (by default), see example below.

screen shot 2018-06-27 at 3 53 07 pm

Line with tabs has 61 characters, line with spaces has 67.

corcoja avatar Jun 27 '18 13:06 corcoja

@iuliancorcoja feel free to send a PR!

marcelofabri avatar Jun 27 '18 14:06 marcelofabri

This also applies to vertical_parameter_alignment_on_call rule.

ikesyo avatar Jul 25 '18 16:07 ikesyo

Hi! I'm trying to fix this bug but came across some problems, is there anyone I can reach out to who can help? I figured out that when tabs are in the string being validate the offset is wrong as in VerticalParameterAlignmentRule the lineAndCharacter function is called with the expandingTabsToWidth default value (1). But I have no idea where to go from now.

MichalAlgor avatar Oct 24 '18 10:10 MichalAlgor

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!

stale[bot] avatar Nov 08 '20 08:11 stale[bot]

@marcelofabri May I know if this issue will be fixed?

MaximillionMai avatar Apr 15 '21 00:04 MaximillionMai

Looks like this issue is closed, however it has not yet been fixed. Has anyone achieved a workaround in the meantime?

henryglendening-hh avatar Sep 16 '21 16:09 henryglendening-hh

Is there a way to reopen this? Or we should just open a new issue?

MaximillionMai avatar Sep 16 '21 16:09 MaximillionMai

Please reopen, @marcelofabri, I'm still affected, only using Xcode with tabs.

futuretap avatar Oct 11 '21 08:10 futuretap

Still having this issue

bwdavis11 avatar Aug 29 '22 16:08 bwdavis11

Likewise. Tabs == accessibility feature

importRyan avatar Oct 23 '23 17:10 importRyan