AYDT - 04 ( Are You Doing This ) - Top 5 lint issues we fail to notice.
Tags: ruby, bestpractice, beginners, tutorial
Published: 2019-07-26 17:00:21

---
title: AYDT - 04 ( Are You Doing This ❓ ) - Top 5 lint issues we fail to notice.
published: true
description: AYDT - ( Are You Doing This❓ ) is a coding series that explains the common coding mistakes people make while learning to code.
cover_image: https://thepracticaldev.s3.amazonaws.com/i/1zbwq7dodwl34d1rmwex.png
---

In a long-forgotten kingdom, there lived three people called Jackie and July along with their uncle.

![jackie chan adventures](https://thepracticaldev.s3.amazonaws.com/i/n9ritukrz5gukqkk68d2.jpg)

Uncle being an old man, he always tries to teach Julie the art of living life. But Julie, on the other hand, thought that her uncle was an old man and he doesn't know anything about life.

But Julie respects Jackie. At least in our fantasy story.😝 Jackie always corrected whenever she does something that's not cool. This is what our 'lint' does when he was introduced into the ruby code.

Just like our uncle, the rubocop does his job in correcting the people whenever he finds a non-standard code.

This guy is called as " The Rubocop. "
![rubocop image](https://thepracticaldev.s3.amazonaws.com/i/hhifafsvtw9hsjf2ytlz.png)

Welcome to the fourth episode of the series: Are You Doing This❓. In case you haven't read the previous articles, I highly recommend you to have a look at those. Sure you'll love it 💙. Happy coding 👨🏻‍💻.

Previous week link :
https://dev.to/chintukarthi/aydt-03-are-you-doing-this-programming-and-cases-1enj

**Are You Doing This❓- Top 5 lint issues we fail to notice.**

In today's series, I'll walk you through the most frequently occurring 5 lint issues and their explanation followed by the link, at the end, where you can learn more about the coding standards.

In the previous episode, I've mentioned a code snippet which had lint issues. I would like to recollect the same snippet here so that it would be easier for you to follow up.

**1) Redundant 'return' detected**

This is the most frequently occurring lint issue. which people often fail to address.
```
# Example method

def first_omnitrix
  return true
end
```
at the end of the function in ruby, you aren't expected to use the return keyword. You can use it, but it is not a good practice.

The snippet should look like this,
```
# Example method

def first_omnitrix
  true
end
```

To learn more about this, you can find a separate article that I have written over here. (https://dev.to/chintukarthi/redundant-return-detected---ruby-programming-gac)

**2) Use snake_case for method names.**

While defining a method, use snake_case for the method name. Snake case is nothing but all small case with a delimiter of '_'.

Example :
```
# Example snake_case method

def snake_case
  true
end
```


To learn more about the use of cases, you can find a separate article that I have written over here. (https://dev.to/chintukarthi/aydt-03-are-you-doing-this-programming-and-cases-1enj)

**3) Don't use parentheses around the condition of an ' if '**

If you are from c or c++ background and started learning and using ruby, sure you might have come across this,
```
# assume the value of a and b are already initialized and b is less than a.
def first_omnitrix
  if (a>b)
    a = 5
  end
end
```

use of parentheses around the if condition is not recommended in ruby. So remove it. To avoid this lint, modify the code as shown in the below snippet.

```
def first_omnitrix
  if a>b
    a = 5
  end
end
```

**4) Use a guard clause instead of wrapping the code inside a conditional expression.**

Hmmm 🤔 sounds odd right?

Nothing odd, It's just simple. Look at the below code snippet,
```
# assume the value of a and b are already initialized and b is less than a.
def first_omnitrix
  if a>b
    a = 5
  end
end
```
Here we used an ' if ' condition to set the value of 'a', to check if it is greater than b.

It might feel correct and is also valid. But the thing is, it's not a correct way to write this piece of code.

You might want to rewrite that to something like this,

```
# assume the value of a and b are already initialized, and b is less than a.
def first_omnitrix
  a = 5 if a>b
end
```

**5) Trailing whitespace detected.**

I can't wait to share this 😇. This one is my personal favorite Because I often make this 😂.

While writing code for some functionalities, we use enter/return to navigate to the next line. But what we don't realize is, it will introduce whitespace around the new line something like this.

```
def whitespace
  if a>b
    if a < c
      true
    end
  end.. (some extra code) 
end
```
what happens here is, you navigated to a new line to write some extra code over there and then deleted the code. But you might forget to delete the two extra space(denoted as '.' dots in the snippet) which will create this ' trailing white space ' lint issue.

After solving the lint, the above method will look like this,

```
def whitespace
  if a>b
    if a < c
      true
    end
  end
end
```

to avoid this issue, just remove the extra spacing in the code which isn't necessary.

So, these are the Top 5 lint issues, that I wish to share with you. If you want to improve your coding skills, you can go ahead over here (https://rubocop.readthedocs.io/) to learn more things about ruby lint.

So that's a wrap for this week. See you people around 🧙🏻‍♂️.

![see you around gif](https://thepracticaldev.s3.amazonaws.com/i/7aumbl5t4huv7o3y4mof.gif)

Cover image courtesy: https://www.codeninja.com.sg/