A simple CSS Linter built with Ruby.
A CSS linter that checks for the following errors
- Checks for trailing semi-colon after setting a CSS property.
- Checks for missing end-of-source newline.
- Checks if double indentation is followed by a valid CSS rule.
- Checks for newline and no leading or trailing spaces surrounding closing curly bracket.
- Checks for newline after single line declaration.
- Checks if single line declaration has only 1 declaration.
- Checks for too many spaces at end or at start.
# Good example
There's a semi-colon after the css property is set.
.container {
color: blue;
}
# Bad example
Missing semi-colon.
.container {
color: blue
}
# Good example
section {
color: blue;
}
/* file ends here with final empty line */
# Bad example
section {
color: blue;
} /* file ends here without final empty line */
# Good example
The closing bracket has no leading or trailing spaces.
div {
font-size: 12px; # double indent
}
# Bad example
The closing bracket has leading and trailing spaces.
section {
color: blue;
}
# Good example
The closing bracket no leading spaces.
div { font-size: 12px; }
.new-rule {
color: #fff;
font-size: 11px;
}
# Bad example
The closing bracket has empty spaces after the closing bracket.
div { font-size: 12px; } |
.new-rule {
color: #fff;
font-size: 11px;
}
# Good example
Maximum of 2 spaces at start of line.
div { font-size: 12px; }
.new-rule {
color: #fff;
font-size: 11px;
}
# Bad examples
The code has too many spaces at the start of the lines.
div { font-size: 12px; }
.new-rule {
color: #fff;
font-size: 11px;
}
- Ruby
- CSS
- Rainbow
Click on the link below to watch a video introduction of this project
To get a local copy up and running follow these simple example steps.
- You need to have Ruby installed on your computer to run this project.
- You should be able to run
terminal
,command prompt
,bash
orPowershell
to open your command line. - Run
git clone https://github.com/m15e/ruby-capstone-linter
to clone this repository to your local machine. - Run
cd ruby-capstone-linter
to go to the project folder. - Drag the css file(s) you would like the linter to inspect into the projects folder, the linter will scan and check all files ending with
.css
. - Run
bin/main.rb
to start the linter and the flaws in your code will be revealed. - (Optional) If you don't want the linter to ignore specific files run
bin/main.rb ignore <filename.css>
. If you would like more than 1 file to be ignored add more filenames (separated by spaces) to the end of the command.
- Ruby
- Commandline, Terminal, Prompt, Bash or Powershell
- Rspec for testing
- Rainbow Gem
- Installing Rainbow
Run the command below in your project's root folder to install the rainbow gem, this gem is used to print the linter output in color.
$ gem install rainbow
Click here for additional resources and information for installing Ruby gems
Run Tests using Rspec
- Installing Rspec
$ gem install rspec
- Running tests with Rspec
To run tests run the following code in the command line from the root directory.
$ rspec
👤 Mark Rode
- Github: @m15e
Give a ⭐️ if you like this project!
- Microverse
- Stylelint
This project is MIT licensed.