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

Proposal: SA1118 (ParameterMustNotSpanMultipleLines) exception for method invocations #1597

Closed
sharwell opened this issue Oct 5, 2015 · 4 comments
Assignees
Milestone

Comments

@sharwell
Copy link
Member

sharwell commented Oct 5, 2015

Currently SA1118 documents two exceptions: the first parameter, and any parameter which is an anonymous method.

To prevent method calls from becoming excessively complicated and unreadable, only the first parameter to a method or indexer call is allowed to span across multiple lines. The exception is an anonymous method passed as a parameter, which is always allowed to span multiple lines.

To improve support for constructing types like XElement, I propose adding an additional exception to this rule for method invocations, indexer expressions, and object initializer expressions. Note that the arguments passed to the method, indexer, or constructor must still adhere to this rule.

📝 This exception would provide us with an easily-documented resolution to #1596.

@vweijsters
Copy link
Contributor

👍

@grokys
Copy link

grokys commented Oct 9, 2015

👍 PLEASE!!!

@sharwell
Copy link
Member Author

It appears this exception was implemented but not documented in StyleCop Classic.

@martincostello
Copy link
Contributor

In addition to XElement, another use case is Moq's It.Is<T>(Expression<Func<T, bool>> match) method used for setting up instances of Mock<T>.

For example:

var mock = new Mock<MyClass>();

mock.Setup(
     (p) => p.MyMethod(
         "MyValue",
         It.Is<Foo>(
             (r) => r.Bar == "Buzz" &&
                    r.Frob == 2)))
    .Returns(() => new FooBar());

I've got a few occurrences in code where the expression tree is quite complex, so is split over multiple lines. In StyleCop classic this didn't raise a warning, but does using the new analysers.

Splitting it into a single line creates a ridiculously long line, and pulling the It.Is<T>() call out into a variable causes the test to no longer work, presumably because of something to do with the way Moq handles expression trees.

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

4 participants