plots2 icon indicating copy to clipboard operation
plots2 copied to clipboard

Ruby Style Guide [Rubocop]

Open siaw23-retired opened this issue 8 years ago • 24 comments

Plots2 has a .rubocop_todo.yml. Is someone willing to take up the following to fix them? If you need help with something please ask and we'll be happy to help.

For starters the following can be fixed first.

Layout/AccessModifierIndentation
Layout/AlignArray
Layout/AlignHash

Once you're done with your changes, please run rake test and rubocop. Create a PR when all passes.

siaw23-retired avatar Jan 26 '18 05:01 siaw23-retired

i got 140 offences after running rubocop i'll fix them all

namangupta01 avatar Jan 26 '18 05:01 namangupta01

Results: https://pastebin.com/raw/J2kxYX66

EDIT: Moved results to pastebin for keeping the conversation short and simple.

namangupta01 avatar Jan 26 '18 05:01 namangupta01

awesome, go for it! :)

siaw23-retired avatar Jan 26 '18 06:01 siaw23-retired

i am getting offences in public/lib but i'am not sure if we should correct it or not ? or should i simply add this folder in .rubocop.yml

namangupta01 avatar Jan 26 '18 06:01 namangupta01

In line : https://github.com/publiclab/plots2/blob/6b4726820e26cecf1acf379b2b62412928083bfa/app/services/typeahead_service.rb#L91 What does srchString == 0 suppose to do here?

namangupta01 avatar Jan 26 '18 09:01 namangupta01

unless srchString.nil? || srchString == 0 that line simply means if srchString is not nil (in other words if there's actually a srchString) OR if srchString is not the figure 0, do the following.

but since you pointed this out i think someone meant to compare length instead, if that's the case, .nil? would be enough. what do you think @jywarren

siaw23-retired avatar Jan 26 '18 10:01 siaw23-retired

so we are comparing string with a integer here? And i have open a pr for this issue can you please have a look at that. And i have also included public/lib files to exclude from rubocop offences because i was thinking it is not good to edit public/lib files what do you say?

namangupta01 avatar Jan 26 '18 10:01 namangupta01

for now i have left public/lib out until we fix all the offences, we'll enable the rest one by one while we progress with this. please show me your PR relating to this @namangupta01

siaw23-retired avatar Jan 26 '18 10:01 siaw23-retired

I don't get why we are comparing with 0, i mean what is the need of this. Can any one please tell me? @siaw23 @ryzokuken @jywarren @publiclab/reviewers

namangupta01 avatar Jan 26 '18 10:01 namangupta01

@siaw23 pr is #2127

namangupta01 avatar Jan 26 '18 10:01 namangupta01

I agree with @siaw23, I guess they wanted to check if its length is equal to zero and mistyped. If they wrote tests for each border case, then looking into those will give you a good idea of what they really intended.

ryzokuken avatar Jan 26 '18 10:01 ryzokuken

P.S. @david-days wrote this part 2 years ago.

ryzokuken avatar Jan 26 '18 10:01 ryzokuken

@ryzokuken i didn't find any tests. Can you please tell me where can i find it?

namangupta01 avatar Jan 26 '18 10:01 namangupta01

That part must be covered somewhere. Maybe try using CodeCov to find out the tests written against it?

ryzokuken avatar Jan 26 '18 11:01 ryzokuken

srchString == 0 is probably meant to check if srchString is blank as it is a url param (see test/functional/search_api_test.rb and test/functional/typeahead_api_test.rb)

seafr avatar Jan 26 '18 13:01 seafr

Good catch! That's probably it. @namangupta01 what was the original problem though? What was wrong with that particular line of code?

ryzokuken avatar Jan 26 '18 14:01 ryzokuken

@ryzokuken It's an rubocop offence screen shot 2018-01-26 at 7 57 30 pm

namangupta01 avatar Jan 26 '18 14:01 namangupta01

Indeed it is! That's because there's a method for this which happens to be much more readable. Switch to that method instead, please.

ryzokuken avatar Jan 26 '18 14:01 ryzokuken

Including that method is causing test failure . See pr #2127

namangupta01 avatar Jan 26 '18 14:01 namangupta01

Try using your_string_variable.empty? instead.

ryzokuken avatar Jan 26 '18 14:01 ryzokuken