csslint_ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b17ba1e8fee39d351de42a8e96b950d0b70bb8c0
4
+ data.tar.gz: cc7f1d01caf0958e2751771386446ef25a1b42ee
5
+ SHA512:
6
+ metadata.gz: 3f038b60d20349828b9aa2a1a990d38a917f3a5af507a6e65feca5bb5f860a8ba70ffba5676e4010c42214194c4cdc445e92a9d41638d840d96bd3a8d89406ec
7
+ data.tar.gz: cc93d22832e05fac2844ced0e487a6d9dadfa5505aade68ec65a684b589d277839e1de6719048dc64797b1ad0a4140f3041e3abde8ba4df5e9045d912223ec94
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - ruby-head
7
+ - jruby-head
8
+ before_install:
9
+ - gem update --system
10
+ - gem --version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in csslint_ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yann
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # CsslintRuby
2
+
3
+ API to lint your css source code from ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'csslint_ruby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install csslint_ruby
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ source = "body { background: red;}"
23
+ CsslintRuby.run(source) # => <CsslintRuby::Result:0x007ff7629b4018 @errors=[], @warnings=[]>
24
+ ```
25
+
26
+ You can also provide pass an option hash to provide CSSLint with a custom set of rules. You can check the full list [here](https://github.com/stubbornella/csslint/wiki/Rules)
27
+
28
+ ```ruby
29
+ options = {errors: ['known-properties', 'display-property-grouping'], warnings: ['box-model'], ignore: ['import']}
30
+ result = CsslintRuby.run(source, options) # => <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=[]>
31
+ 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"}}]
32
+ result.warnings # => []
33
+ ```
34
+
35
+ Alternatively ``` CsslintRuby.run``` can accept anything the acts like in ```IO``` object.
36
+ ```ruby
37
+ source = File.open('/path/to/my/css/file.css')
38
+ CsslintRuby.run(source) # => <CsslintRuby::Result:0x007ff7629b4018 @errors=[], @warnings=[]>
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( http://github.com/<my-github-username>/csslint_ruby/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'csslint_ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'csslint_ruby'
8
+ spec.version = CsslintRuby::VERSION
9
+ spec.authors = ['StupidCodefactory']
10
+ spec.email = ['ymarquet@gmail.com']
11
+ spec.summary = %q{Provide an interface to lint css with CSSLint from ruby}
12
+ spec.description = %q{Provide an interface to lint css with CSSLint from ruby}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'execjs'
22
+ spec.add_development_dependency 'byebug'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'bundler', '~> 1.5'
25
+ spec.add_development_dependency 'rake'
26
+ end
@@ -0,0 +1,14 @@
1
+ module CsslintRuby
2
+ class Source
3
+
4
+ def self.path
5
+ ENV['CSSLINT_PATH'] ||
6
+ File.expand_path("../../../vendor/csslint/csslint.js", __FILE__)
7
+ end
8
+
9
+ def self.contents
10
+ @contents ||= File.read(path)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module CsslintRuby
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,68 @@
1
+ require 'csslint_ruby/version'
2
+ require 'csslint_ruby/source'
3
+ require 'execjs'
4
+
5
+ module CsslintRuby
6
+
7
+ def self.context
8
+ ExecJS.compile(
9
+ Source.contents + <<-EOJS
10
+ function gatherRules(options){
11
+ var ruleset,
12
+ ignores = options.ignores,
13
+ warnings = options.rules || options.warnings,
14
+ errors = options.errors;
15
+
16
+ if (ignores) {
17
+ ruleset = ruleset || {};
18
+ for( var _i = 0, _len = ignores.length; _i < _len; _i++ ) {
19
+ ruleset[ignores[_i]] = 0;
20
+ };
21
+ }
22
+
23
+ if (warnings) {
24
+ ruleset = ruleset || {};
25
+ for( var _i = 0, _len = warnings.length; _i < _len; _i++ ) {
26
+ ruleset[warnings[_i]] = 1;
27
+ };
28
+ }
29
+
30
+ if (errors) {
31
+ ruleset = ruleset || {};
32
+ for( var _i = 0, _len = errors.length; _i < _len; _i++ ) {
33
+ ruleset[errors[_i]] = 2;
34
+ };
35
+ }
36
+
37
+ return ruleset;
38
+ };
39
+
40
+ function CSSLINTER(source, options) {
41
+ var result = CSSLint.verify( source, gatherRules( options ) );
42
+ var messages = result.messages || [];
43
+ return [ messages ];
44
+ };
45
+ EOJS
46
+ )
47
+ end
48
+
49
+ def self.run(source, options = {})
50
+ source = source.respond_to?(:read) ? source.read : source
51
+ Result.new(*context.call('CSSLINTER', source, options))
52
+ end
53
+
54
+ class Result
55
+
56
+ TYPE_ERROR = "error".freeze
57
+
58
+ attr_reader :errors, :warnings
59
+
60
+ def initialize(errors)
61
+ @errors, @warnings = errors.partition {|error| error['type'] == TYPE_ERROR }
62
+ end
63
+
64
+ def valid?
65
+ errors.empty?
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ background {
2
+ display: ;
3
+ }
@@ -0,0 +1,3 @@
1
+ body {
2
+ display: unkown-property;
3
+ }
@@ -0,0 +1,3 @@
1
+ body {
2
+ color: red;
3
+ }
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe CsslintRuby do
4
+
5
+
6
+ describe "When no linting errors are returned" do
7
+
8
+ let(:source) { File.open('spec/fixtures/source.css') }
9
+
10
+ it 'is valid' do
11
+ expect(CsslintRuby.run(source)).to be_valid
12
+ end
13
+
14
+ end
15
+
16
+ describe "When linting errors are returned" do
17
+
18
+ let(:source) { File.open('spec/fixtures/errors.css') }
19
+ let(:result) { CsslintRuby.run(source, {}) }
20
+
21
+ it 'is not valid' do
22
+ expect(result).not_to be_valid
23
+ end
24
+
25
+ describe '#errors' do
26
+ it 'have an expected structure' do
27
+ expect(result.errors.first).to include('type', 'line', 'col', 'message', 'evidence', 'rule')
28
+ end
29
+
30
+ it 'have rule description on' do
31
+ expect(result.errors.first['rule']).to include('id', 'name', 'desc', 'browsers')
32
+ end
33
+ end
34
+ end
35
+
36
+ describe "When passing options" do
37
+ let(:options) { {errors: ['known-properties']} }
38
+ let(:source) { File.open('spec/fixtures/errors_with_options.css') }
39
+
40
+ it 'passes the options to CSSLint correctly' do
41
+ result = CsslintRuby.run(source, options)
42
+ expect(result).not_to be_valid
43
+ expect(result.errors.first).to include(
44
+ 'type' => 'error',
45
+ 'rule' => {
46
+ 'id' => 'known-properties',
47
+ 'name' => 'Require use of known properties',
48
+ 'desc' => 'Properties should be known (listed in CSS3 specification) or be a vendor-prefixed property.',
49
+ 'browsers'=>'All'
50
+ })
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ require 'csslint_ruby'
4
+ require 'byebug'