-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fix SpaceBeforeFirstArg cop for multiline arguments #945
Conversation
Yep, you found a bug. My bad. Code looks good, @cschramm! Please add a spec example that fails before your fix, and an entry in |
Actually, I might have been too quick when endorsing the change. This cop, which is a lint cop, should not warn for setter calls without leading space ( So changing the regexp is good. We should keep that. But we also need examples saying that setter calls without space are accepted by this cop, and that a first argument that is preceded by a space and contains a non-space right after a line break within it, is accepted. We usually exclude setter calls by |
@jonas054 Won't it be simpler if we checked whether the method name ends with |
There's one more that is not in any big need of handling, but I though could tag along, and that's method"some string" I can't think of any others. Well, there's puts`ls` |
I can do so. Do you want to blacklist !, ?, " and ` or just whitelist =? |
Whilelist assignment. |
Done. |
@@ -26,6 +26,16 @@ | |||
inspect_source(cop, ['something[:x]']) | |||
expect(cop.offenses).to be_empty | |||
end | |||
|
|||
it 'accepts a method call with space before a multiline arg' do | |||
inspect_source(cop, "something [\n 'foo',\n 'bar'\n]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can make this a bit more readable like this:
inspect_source(cop, ['something [',
' foo',
' bar',
']'])
and exclude assignments
Squashed and rebased. |
👍 I'm happy with the changes. |
Fix SpaceBeforeFirstArg cop for multiline arguments
Thanks! |
You're welcome 😃 |
I have this code:
The cop treats everything after the equal sign as
arg1_with_space
and this does in fact start with a space, but the regular expression searches for any line not starting with a whitespace, not just the first one.