Skip to content

Rule Request: Multiline Function Chains #2214

Closed
@erichoracek

Description

@erichoracek

Rule Request

Summary

Chained function calls should be either on the same line, or one per line.

This is similar to the existing "Multiline Arguments" and "Multiline Parameters" rules.

Q&A

  1. Why should this rule be added? Share links to existing discussion about what
    the community thinks about this.

It's easier to follow control flow through long function chains when each call has the same indentation.

  1. Provide several examples of what would and wouldn't trigger violations.
  • Triggering:
return match(pattern: pattern, with: [.comment]).flatMap { range in
   return Command(string: contents, range: range)
}.flatMap { command in
   return command.expand()
}

let evenSquaresSum = [20, 17, 35, 4]
    .filter { $0 % 2 == 0 }.map { $0 * $0 }
    .reduce(0, +)
  • Non-triggering
return match(pattern: pattern, with: [.comment])
    .flatMap { range in
        return Command(string: contents, range: range)
    }
    .flatMap { command in
        return command.expand()
    }

let evenSquaresSum = [20, 17, 35, 4].filter { $0 % 2 == 0 }.map { $0 * $0 }.reduce(0, +)

let evenSquaresSum = [20, 17, 35, 4]
    .filter { $0 % 2 == 0 }
    .map { $0 * $0 }
    .reduce(0, +)
  1. Should the rule be configurable, if so what parameters should be configurable?

No configuration necessary

  1. Should the rule be opt-in or enabled by default? Why?
    See README.md for guidelines on when to mark a
    rule as opt-in.

Disabled by default

Activity

changed the title Rule Request: [Multiline Function Chains] Rule Request: Multiline Function Chains on May 18, 2018
freak4pc

freak4pc commented on May 23, 2018

@freak4pc
Contributor

@erichoracek I like this and it's also useful to me and many friends in the Realm (😉) of Rx.
Do you want to tackle this or are you OK with me giving it a go?

erichoracek

erichoracek commented on May 24, 2018

@erichoracek
ContributorAuthor

@freak4pc Thanks for the interest! I'm pretty close to having a working implementation—feel free to take a shot at this if you'd like to too though 😄

freak4pc

freak4pc commented on May 24, 2018

@freak4pc
Contributor

@erichoracek oh not at all! Just wanted
To help out :) feel free to take your time with this

added a commit that references this issue on May 25, 2018
marcelofabri

marcelofabri commented on Jun 11, 2018

@marcelofabri
Collaborator

Implemented in #2221 🚀

added a commit that references this issue on Jun 25, 2018
added a commit that references this issue on Mar 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    rule-requestRequests for a new rules.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @erichoracek@freak4pc@marcelofabri

      Issue actions

        Rule Request: Multiline Function Chains · Issue #2214 · realm/SwiftLint