Plots2: Ruby Style Guide [Rubocop]

Created on 26 Jan 2018  路  24Comments  路  Source: publiclab/plots2

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.

All 24 comments

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

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

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

awesome, go for it! :)

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

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

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?

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

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

@siaw23 pr is #2127

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.

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

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

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

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)

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

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

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.

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

Try using your_string_variable.empty? instead.

Oh! thank you @ryzokuken I will update it!

@seafr if the param isn't passed at all, it is nil. If it is, but there's no value, it's probably empty. So I think @david-days wanted to check if it's length was zero and used this accidentally, thus trying to compare a string variable to a numeric literal.

@ryzokuken yes, this is what I think, else comparing a string to an integer - as @namangupta01 mentioned above - doesn't make sense.
As for the .empty? method, what do you think of using Rails' .blank? method, just in case a string of white spaces is passed?

Hmm, that does make sense. Searching a blank (whitespace-only) string doesn't make sense.

@namangupta01 while this specific example will work better with .blank?, please use the best possible method for each one of the cases, I will look into them while reviewing your PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

milaaraujo picture milaaraujo  路  3Comments

jywarren picture jywarren  路  3Comments

grvsachdeva picture grvsachdeva  路  3Comments

grvsachdeva picture grvsachdeva  路  3Comments

grvsachdeva picture grvsachdeva  路  3Comments