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

Rule request: [Wrapped Vertical Parameter Alignment (On Call)] #2144

Open
DevAndArtist opened this issue Apr 5, 2018 · 1 comment
Open

Comments

@DevAndArtist
Copy link

DevAndArtist commented Apr 5, 2018

Rule Request

1. Why should this rule be added?

I'm following this code style because my line width is forced to 80 chars (one tab are two whitespaces) and the simple Vertical Parameter Alignment (On Call) does not work in most cases.

2. Provide several examples of what would and wouldn't trigger violations.

Non Triggering Examples
func foo(bar: Int)
func foo(bar: Int) -> String 
func foo(
  bar: Int
) -> String 
func validateFunction(
   _ file: File, kind: SwiftDeclarationKind,
   dictionary: [String: SourceKitRepresentable]
) -> [StyleViolation]
func regex(
  _ pattern: String,
  options: NSRegularExpression.Options = [
    .anchorsMatchLines,
    .dotMatchesLineSeparators
  ]
) -> NSRegularExpression
func foo(
  a: Void,
  b: [String: String] =
    [:]
) {
  ...
}
func foo(
  data: (
    size: CGSize, 
    identifier: String
  )
) {}
UIView.animate(
  withDuration: 0.4, 
  animations: {  blurredImageView.alpha = 1 }, 
  completion: { _ in
    self.hideLoading()
  }
)
Triggering Examples
foo(param1: 1, param2: bar
    param3: false, param4: true)
foo(param1: 1, param2: bar
    param3: false,
    param4: true)
func validateFunction(_ file: File, kind: SwiftDeclarationKind,
                      dictionary: [String: SourceKitRepresentable]) { }
func validateFunction(_ file: File, kind: SwiftDeclarationKind,
                      dictionary: [String: SourceKitRepresentable]) -> [StyleViolation]
func validateFunction(_ file: File, kind: SwiftDeclarationKind,
                      dictionary: [String: SourceKitRepresentable])
                      -> [StyleViolation]
func validateFunction(
   _ file: File, kind: SwiftDeclarationKind,
   dictionary: [String: SourceKitRepresentable]) -> [StyleViolation]
func validateFunction(_ file: File, kind: SwiftDeclarationKind,
                  dictionary: [String: SourceKitRepresentable]) { }
func validateFunction(_ file: File, kind: SwiftDeclarationKind,
                       dictionary: [String: SourceKitRepresentable]) { }
func validateFunction(_ file: File,
                  kind: SwiftDeclarationKind,
                  dictionary: [String: SourceKitRepresentable]) { }
func validateFunction(
  _ file: File,
      kind: SwiftDeclarationKind,
dictionary: [String: SourceKitRepresentable]) { }
func validateFunction(
  _ file: File,
  kind: SwiftDeclarationKind,
  dictionary: [String: SourceKitRepresentable]) { }
UIView.animate(withDuration: 0.4, animations: {
    blurredImageView.alpha = 1
}, completion: { _ in
    self.hideLoading()
})
func foo(
   label param1: Type, label param2: Type
)

3. Should the rule be configurable, if so what parameters should be configurable?

This can be an opt-in extension on the exiting two rules to force wrapping the first label / parameter.

4. Should the rule be opt-in or enabled by default? Why?

Opt-in in both cases:

  • Standalone rules
  • Extension on exiting rules
@DevAndArtist
Copy link
Author

DevAndArtist commented Apr 5, 2018

To add on this. This rule is similar to the string literals in Swift. You either don't wrap any expression " ...." or you wrap everything in respect to the indent rules:

let something = """
    
   """

Analogy

func application(
  _ application: UIApplication,
  didFinishLaunchingWithOptions launchOptions:
    [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {

cc. @marcelofabri @jpsim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants