This was a really challenging capstone, to be honest. But it worth it! write code in order to check code's proper indentation, elegance, order, and help to accomplish the best practices to keep projects clean, has been very excited and tricky, but in the end, I've managed to develop some of the most basic linter methods by watching rubocop's corrections.
The custom Ruby linter currently checks/detects for:
- Missing/unexpected tags such as parenthesis (), brackets [] and curly brackets {}
- Trailing spaces
- Empty line error
- Missing/unexpected end
- Wrong indentation
The following are images indicating good and bad way to code, in accordance to the mentioned methods:
# good
module Canvas
def parameters(a, b)
@a = a
@b = b
end
end
# bad
module Canvas
def parameters(a, b <- # Missing parenthesis here
@a = a
@b = b
end
end
Note the pipe "|" location to indicate the extra whitespace
# good
class Canvas|
def parameters(a, b)|
@a = a|
@b = b|
end|
end|
# bad
class Canvas |
def parameters(a, b) |
@a = a|
@b = b|
end|
end
# good
module Canvas
def parameters(a, b)
@a = a
@b = b
end
end
# bad
module Canvas
def parameters(a, b)
# <- empty line
@a = a
@b = b
end
end
# good
module Canvas
def parameters(a, b)
@a = a
@b = b
end
end
# bad
module Canvas
def parameters(a, b)
@a = a
@b = b
end
end
end # <- unexpected end
# good
module Canvas
def parameters(a, b)
@a = a
@b = b
end
end
# bad
module Canvas
def parameters(a, b)
@a = a
@b = b
end
end
- Ruby
- RSpec for Ruby Testing
Get a local copy from my repository using this command:
cd to the folder you will place the project
Once you are on the directory you want to set the project, run:
git clone https://github.com/mrigorir/custom-ruby-linter
Now, in the root of your project folder, run:
bundle install
So you can use Ruby dependencies
To use the tester file, for checking any errors
Write the following command in the project's root
ruby bin/main tester.rb
Install rubocop to correct the code you have made.
gem install rubocop
Then, run rubocop
in the terminal.
Install rspec for test porpuses and colorize (optional) so the errors have a better look.
gem install rspec
gem install colorize
Run rspec
on the terminal from the project's root.
To take into account: tester.rb file has been excluded from rubocop's corrections since this file contains on-purpose errors in order to test this tool.
👤 Marco Parra
- Github: @mrigorir
- Twitter: @marcoparra311
- Linkedin: marco-parra-leal
Contributions, issues and feature requests are welcome!
Give a ⭐️ if you like this project!