This idea of making your workflow easier and reduce mistakes during coding is amazing and believing you can create your own error checker is amazing.
This project is about creating a linter for ruby files using ruby
The Ruby linter currently detects for the following errors.
- check for missing emptyline at the end
- check for trailing spaces
- check for long lines that need to be shortened
- check for empty startline
- check empty line error
Below are demonstrations of good and bad code for the above cases. I will use the pipe '|' symbol to indicate cursor position where necessary.
class Calculator
attr_accessor :x, :y
puts 'an example of how the calculator class works you call the method outside the class.'
def initialize(num1, num2)
@x = num1
@y = num2
end
-----
class Calculator
attr_accessor :x, :y
puts 'an example of how the calculator class works you call the method outside the class.'
def initialize(num1, num2)
@x = num1
@y = num2
end
Error empty startline above the class Calculator denoted by ----
def sub
puts x - y
end
def mul
puts x * y
end
def sub
puts x - y
end
-----
def mul
puts x * y
end
Error empty line denoted by ----
puts 'an example of how the calculator class works,
you call the method outside the class.'
def initialize(num1, num2)
@x = num1
@y = num2
end
attr_accessor :x, :y
puts 'an example of how the calculator class works you call the method outside the class.'
def initialize(num1, num2)
@x = num1
@y = num2
end
Error in the line beginning with puts its too long
def sub
puts x - y
end
def sub ||
puts x - y
end
Error Trailing space denoted by || indicating pisition of cursor
def sub
puts x - y
end
--------
def sub
puts x - y
end
Error detected by lack of ---- denoting the empty lastline
- Ruby
- RSpec for Ruby Testing
To get a local copy up and running follow these simple example steps:
- Click here
- Run git clone https://github.com/danmainah/ruby_linter
- For usage ensure you have ruby installed
- Text editor
- GitHub
- Git
ensure they are installed before trying to run the program
- bundler
- colorize
- rspec
- Run gem install bundler
- Run gem install rspec
- Run gem install colorize
- In the downloader main Dir
- Add the file in the main Dir
- In the main.rb file line 3 change the ('testfile.rb') to ('yourfile.rb')
- Run bin/main.rb
To Test the code
- Ensure you are in the main Dir
- Run rspec
Note: testfile.rb
has been excluded from rubocop checks to allow RSpec testing without interfering with Gitflow actions
- GitHub: @danmainah
- Twitter: @Danmainah
- LinkedIn: @Daniel-Maina
Contributions, issues, and feature requests are welcome!
Give a ⭐️ if you like this project!