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

Add RuboCop testing #112

Closed
wants to merge 5 commits into from

Conversation

shortdudey123
Copy link
Contributor

Adds rubocop to standardize syntax
Let me know if there is anything you don't agree with

else
break
end
break unless answer.empty? || answer == 'y'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually refrain from using unless with multiple conditions as I think it's more difficult to read (I usually have to read an unless statement with multiple conditions multiple times before actually understanding it).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple conditions

I would agree is this was an if/elsif block, but its an if/else block so there is only one condition to chef, not multiple

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there are multiple conditions in the unless part answer.empty? OR answer == 'y', but for this one I'll actually consider the unless variant as it's easy to grip, so ignore my comment :).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah i gotcha

%(#{prefix}.#{camelcase(key)}=#{value.call})
else
%(#{prefix}.#{camelcase(key)}=#{value})
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I think that the changed version is more difficult to read, and it hurts my eyes :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/ConditionalAssignment can force the original with EnforcedStyle: assign_inside_condition if you would like :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please.

@mthssdrbrg
Copy link
Contributor

Things I don't agree with:

  • Removal of trailing commas. I prefer them as they make diffs easier to read through when items are added to arrays and/or hashes.
  • %w() over %w[]. Using brackets makes it obvious (or at least more so) that one is dealing with an array than parentheses does.
  • backticks over %x(). This might be a weird one, but when writing bash scripts I use $() over backticks as backticks are considered legacy, see SC1077 and SC2006.
  • Spaces before/after {} for one-line hashes. Don't really see the benefit of adding spaces?
  • Opening/closing {} for method calls where they're actually not needed. Very much a personal preference without any real motivation for it, but I prefer to have them as it's appealing :).

I'd also prefer if each "rule" change had its own commit as it would make it easier to discard certain changes.

@shortdudey123
Copy link
Contributor Author

Removal of trailing commas. I prefer them as they make diffs easier to read through when items are added to arrays and/or hashes.

This was inconsistent throughout so i picked one, will force a trailing comma

%w() over %w[]

This will affect all % shortcuts, not just %w

backticks over %x()

The 2 links you mentioned are on the shell side, not ruby side

Spaces before/after {} for one-line hashes

forces consistency, i can force Style/SpaceBeforeBlockBraces either way

Opening/closing {} for method calls where they're actually not needed.

Can you elaborate on this? not following what you are referring too
Hash.new vs {}?

I'd also prefer if each "rule" change had its own commit as it would make it easier to discard certain changes.

Thought about it, but sometimes a line is affected by several rules so its hard to revert a commit in the middle

@mthssdrbrg
Copy link
Contributor

This was inconsistent throughout so i picked one, will force a trailing comma

Ah :)

This will affect all % shortcuts, not just %w

That's unfortunate :/.

The 2 links you mentioned are on the shell side, not ruby side.

I know, which is why I said it was weird :). I don't agree with the motivation for using %x() though, and would prefer %x|<command>| over <command>.

forces consistency, i can force Style/SpaceBeforeBlockBraces either way

Not really sure what this means? Is there a rule for forcing spaces before block braces but not for hashes? If so that sounds fine.

Can you elaborate on this? not following what you are referring too
Hash.new vs{}?

Sure. What I was referring to was method calls as:

opts[:env_path] = value_for_platform_family({
  'debian' => '/etc/default/kafka',
   'default' => '/etc/sysconfig/kafka',
})

Whereas the rubocop rules suggests that the {} should be stripped. Does that make sense?

@shortdudey123
Copy link
Contributor Author

That's unfortunate :/.

scratch that... looks like Style/PercentLiteralDelimiters allows config per % shortcut, force %w to be []? or stay consistent with everything else with ()

I know, which is why I said it was weird :). I don't agree with the motivation for using %x() though, and would prefer %x|| over <command>.

will look more at this

Not really sure what this means? Is there a rule for forcing spaces before block braces but not for hashes? If so that sounds fine.

I can force a space or no space, (actually the cop is Style/SpaceInsideBlockBraces)
Will look more if i can only force inside blocks and not hashes

Whereas the rubocop rules suggests that the {} should be stripped. Does that make sense?

Gotcha, this is Style/BracesAroundHashParameters. It suggests removing them since they are redundant.

@mthssdrbrg
Copy link
Contributor

scratch that... looks like Style/PercentLiteralDelimiters allows config per % shortcut, force %w to be[]? or stay consistent with everything else with ()

Right now I'm leaning towards having anything that creates arrays/lists use [] and use () for the rest. Including %x(), so there doesn't have to be some weird special case for that :).

Gotcha, this is Style/BracesAroundHashParameters. It suggests removing them since they are redundant.

Yeah. On second thought I don't really have a strong preference for this, so it's okay to include that rule (i.e. remove the redundant braces).

@shortdudey123
Copy link
Contributor Author

Cool, thanks for all the feedback! i will work on updates today

@shortdudey123
Copy link
Contributor Author

The the spaces after { and before } i can do a couple different things

  • Force no spaces for both hashes and block params
  • Force no spaces for hashes and no space after { in a block but a space before } in a block

The way the SpaceInsideBlockBraces cop works, is no space for everything, or spaces for everything except the { of a block

@shortdudey123
Copy link
Contributor Author

Besides the formatting in the last comment, i think i addressed the feedback

@shortdudey123
Copy link
Contributor Author

@mthssdrbrg any further thoughts?

Copy link
Contributor

@mthssdrbrg mthssdrbrg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general, but there are some inconsistencies especially with trailing commas, that rubocop doesn't complain about when I run it locally (which is really weird...).

%(#{prefix}.#{camelcase(key)}=#{value.call})
else
%(#{prefix}.#{camelcase(key)}=#{value})
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please.

daemon_name: 'kafka',
port: node['kafka']['broker']['port'],
user: node['kafka']['user'],
env_path: kafka_init_opts[:env_path],
ulimit: node['kafka']['ulimit_file'],
kill_timeout: node['kafka']['kill_timeout'],
})
kill_timeout: node['kafka']['kill_timeout']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened to the trailing comma here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed per Style/TrailingCommaInArguments

owner: 'root',
group: 'root',
mode: script_permissions,
source: source_template,
})
source: source_template
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with trailing comma here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed per Style/TrailingCommaInArguments

})
expect(chef_run).to run_execute('extract-kafka').with(
cwd: %(#{Dir.tmpdir}/kafka-build)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this could be collapsed to a single line, i.e.

expect(chef_run).to run_execute('extract-kafka').with(cwd: %(#{Dir.tmpdir}/kafka-build))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently, this is consistent style
I can make it inconsistent if you prefer

cookbook = Stove::Cookbook.new(Dir.pwd)
version = cookbook.tag_version
release_name = %(kafka-cookbook-#{version})
archive_path = ::File.join('pkg', sprintf('kafka-cookbook-%s.tar.gz', version))
archive_path = ::File.join('pkg', "#{release_name}.tar.gz")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer if this was switched out to a format(...).

'default' => 'systemd/default.erb'
})
)
Copy link
Contributor

@mthssdrbrg mthssdrbrg Oct 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are quite some inconsistencies in this method with regards to trailing commas, though rubocop doesn't complain when I check this file locally which I think is quite weird?

Copy link
Contributor Author

@shortdudey123 shortdudey123 Oct 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing comma only applies to multiline hashes, not method calls

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me know if you want Style/TrailingCommaInArguments disabled anyway

@shortdudey123
Copy link
Contributor Author

addressed all feedback

@shortdudey123
Copy link
Contributor Author

You want me to squash the commits or are you good with the history?

@mthssdrbrg
Copy link
Contributor

I'm good with the history, and I was hoping to merge this yesterday but I wanted to go through the changes one more time but ran out of time, will get to it tonight.

Thanks a lot for the contribution (and your patience!) @shortdudey123.

@shortdudey123
Copy link
Contributor Author

Cool and no problem! :)

@mthssdrbrg
Copy link
Contributor

Merged in 584b40e.

@mthssdrbrg mthssdrbrg closed this Oct 27, 2016
@shortdudey123 shortdudey123 deleted the add_rubocop branch October 27, 2016 19:27
@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants