CsslintRuby
API to lint your css source code from ruby.
Installation
Add this line to your application's Gemfile:
gem 'csslint_ruby'
And then execute:
$ bundle
Or install it yourself as:
$ gem install csslint_ruby
Usage
source = "body { background: red;}"
CsslintRuby.run(source) # => <CsslintRuby::Result:0x007ff7629b4018 @errors=[], @warnings=[]>
You can also provide pass an option hash to provide CSSLint with a custom set of rules. You can check the full list here
= {errors: ['known-properties', 'display-property-grouping'], warnings: ['box-model'], ignore: ['import']}
result = CsslintRuby.run(source, ) # => <CsslintRuby::Result:0x007ff76287b160 @errors=[{"type"=>"error", "line"=>2, "col"=>8, "message"=>"Expected (inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | box | inline-box | grid | inline-grid | none | inherit | -moz-box | -moz-inline-block | -moz-inline-box | -moz-inline-grid | -moz-inline-stack | -moz-inline-table | -moz-grid | -moz-grid-group | -moz-grid-line | -moz-groupbox | -moz-deck | -moz-popup | -moz-stack | -moz-marker | -webkit-box | -webkit-inline-box) but found 'asdas'.", "evidence"=>"body { display: asdas;}", "rule"=>{"id"=>"known-properties", "name"=>"Require use of known properties", "desc"=>"Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property.", "browsers"=>"All"}}], @warnings=[]>
result.errors # => [{"type"=>"error", "line"=>2, "col"=>8, "message"=>"Expected (inline | block | list-item | inline-block | table | inline-table | table-row-group | table-header-group | table-footer-group | table-row | table-column-group | table-column | table-cell | table-caption | box | inline-box | grid | inline-grid | none | inherit | -moz-box | -moz-inline-block | -moz-inline-box | -moz-inline-grid | -moz-inline-stack | -moz-inline-table | -moz-grid | -moz-grid-group | -moz-grid-line | -moz-groupbox | -moz-deck | -moz-popup | -moz-stack | -moz-marker | -webkit-box | -webkit-inline-box) but found 'asdas'.", "evidence"=>"body { display: asdas;}", "rule"=>{"id"=>"known-properties", "name"=>"Require use of known properties", "desc"=>"Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property.", "browsers"=>"All"}}]
result.warnings # => []
Alternatively CsslintRuby.run
can accept anything the acts like in IO
object.
source = File.open('/path/to/my/css/file.css')
CsslintRuby.run(source) # => <CsslintRuby::Result:0x007ff7629b4018 @errors=[], @warnings=[]>
Contributing
- Fork it ( http://github.com/
/csslint_ruby/fork ) - Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request