A Linter developed in Ruby - Capstone Project from Microverse
Linter is a static analysis tool such as RuboCop. It checks the written code and makes suggestions based on pre-defined rules by community-driven coding style guides and common idioms. Most definitions of linter default behavior can be changed for the needs of your team and project via various configuration options.
Linter-On-Ruby is a beginner level linter that checks ruby .rb code files for the following rules:
To get a local copy of this repository up and running, follow these steps:
Click the "Clone or download" button or run the follwing command
Remeber to change the extentions of files present in lib/students codes to following :-
Type ruby bin/main.rb and press [Enter] and for
Type main.rb file/path/you/want/to/check.rb on command line and press [Enter].
To run Test cases just run RSPEC and press [Enter]
Detects indentation with the rules of two spaces indentation.
def my_method(arg1, arg2)
variables = 12
end
def my_method(arg1, arg2)
variables = 12
end
if extra_large_condition1 && extra_large_condition2 && extra_large_condition3 && extra_large_condition4
if extra_large_condition1 && extra_large_condition2 &&
extra_large_condition3 && extra_large_condition4
Calculates the total number of soft parantheses and returns the line number if closing and opening parantheses numbers doesn't match.
def my_method(arg1, arg2)
variables = 12
end
def my_method(arg1, arg2
variables = 12
end
name = 'Carlos'
if name.length > 4
puts "Hello #{name}!" # tab or more than 2 spaces
end
name = 'Carlos'
if name.length > 4
puts "Hello #{name}!"
end
Does the same for square brackets.
def my_method(arg1, arg2)
variables = [12]
end
def my_method(arg1, arg2)
variables = [12
end
return unless File.exists?('file_name')
# empty line indentation can be 0 even if previous line is 4
some other code
Does the same for curly brackets.
def my_method(arg1, arg2)
variables = { symbol: "sample" }
end
def my_method(arg1, arg2)
variables = { symbol: "sample"
end
name = 'Carlos'
if name.length > 4
puts "Hello #{name}!"
end # file ends here
name = 'Carlos'
if name.length > 4
puts "Hello #{name}!"
end
# file ends here
It scans the lines and returns a note if it finds a bigger space than 1 character.
def my_method(arg1, arg2)
variables = { symbol: "sample" }
end
def my_method(arg1, arg2)
variables = { symbol: "sample" }
end
puts 'Hello, world!' # invisible trailing space here
puts 'Hello, world!' # the line ends with the last single quote
If there is a keyword immediately before the 'end' keyword it returns an error message.
def my_method(arg1, arg2)
variables = { symbol: "sample" }
end
def my_method2(arg1, arg2)
variables = { symbol: "sample" }
end
def my_method(arg1, arg2)
variables = { symbol: "sample" }
end
def my_method2(arg1, arg2)
variables = { symbol: "sample" }
end
If the keywords numbers doesn't match with the end numbers it returns an error message with the line number of the latest end.
def my_method(arg1, arg2)
variables = { symbol: "sample" }
end
def my_method(arg1, arg2)
variables = { symbol: "sample" }
You must have Ruby installed on your computer
Code in White Colors shows error for :-
Code in other Colors (Red, Yellow,etc) shows error for :-
Shubham Raj
Contributions, issues and feature requests are welcome!
Feel free to check the issues page.
This project is MIT licensed.