execcsslint 12.03.19

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012, Mint Digital, Daniel Holz
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,68 @@
1
+ ExecCSSLint
2
+ ==========
3
+
4
+ ExecCSSLint is a thin Ruby wrapper that uses ExecJS to execute [csslint]. It is heavily inspired by Dean Strelau's [https://github.com/mintdigital/execjslint][ExecJSLint].
5
+
6
+ Install
7
+ -------
8
+
9
+ ```
10
+ $ gem install execcsslint
11
+ ```
12
+
13
+ Usage
14
+ -----
15
+
16
+ ```ruby
17
+ js = File.open('path/to/my.js')
18
+ results = csslint.run(js)
19
+ if result.valid?
20
+ puts "Great job pal"
21
+ else
22
+ puts "Check your CSS"
23
+ puts result.errors
24
+ end
25
+ ```
26
+
27
+ If you're looking to use this in a Rails app, take a look at
28
+ [examples/csslint.rake][rake].
29
+
30
+ Requirements
31
+ ------------
32
+
33
+ You'll need one of the [supported ExecJS runtimes][execjs-runtimes]. OS X
34
+ comes with JavaScriptCore by default, so you likely don't need to install
35
+ anything.
36
+
37
+ csslint Options
38
+ --------------
39
+
40
+ Right now, `ExecCSSLint` does not support setting global csslint options, so you'll
41
+ have to include them in a `/*csslint */` comment at the top of each file.
42
+ `csslint.js` will automatically parse and apply options specified like this. A
43
+ full list of options is available on [csslint.net][csslint-options].
44
+
45
+ Using an Alternate csslint.js
46
+ ----------------------------
47
+
48
+ ExecCSSLint depends on the `csslint-source` gem, which is a ruby packaging
49
+ of the official [csslint.js][csslintjs]. By default, ExecCSSLint depends on the
50
+ latest version of the `csslint-source` gem. As there are no official releases
51
+ of csslint, `csslint-source` is versioned according to [the date at the top of
52
+ csslint.js][csslint-date] (eg, `2012.03.16`). rubygems.org has a [full list of
53
+ `csslint-source` gem versions][source-versions].
54
+
55
+ To override this, you can specify an explicit dependency on `csslint-source`,
56
+ for example, using bundler:
57
+
58
+ ```
59
+ gem 'execcsslint'
60
+ gem 'csslint-source', '2012.03.17'
61
+ ```
62
+
63
+ You can also explicitly specify a local copy of `csslint.js` to use by setting
64
+ the `CSSLINT_PATH` env variable.
65
+
66
+ ```
67
+ $ CSSLINT_PATH=../lib/csslint.js rake csslint
68
+ ```
data/lib/csslint.rb ADDED
@@ -0,0 +1,82 @@
1
+ require 'execjs'
2
+ require 'csslint/source'
3
+
4
+ module CSSLint
5
+ # Internal: The ExecJS Context in which to run csslint().
6
+ #
7
+ # Provides a small helper function CSSLINTR to return both the CSSLint()
8
+ # return value and the CSSLint messages
9
+ def self.context
10
+ ExecJS.compile(
11
+ CSSLint::Source.contents + <<-EOW
12
+
13
+ function gatherRules(options){
14
+ var ruleset,
15
+ warnings = options.rules || options.warnings,
16
+ errors = options.errors;
17
+
18
+ if (warnings){
19
+ ruleset = ruleset || {};
20
+ for( var _i = 0, _len = warnings.length; _i < _len; _i++ ) {
21
+ ruleset[warnings[_i]] = 1;
22
+ };
23
+ }
24
+
25
+ if (errors){
26
+ ruleset = ruleset || {};
27
+ for( var _i = 0, _len = errors.length; _i < _len; _i++ ) {
28
+ ruleset[errors[_i]] = 2;
29
+ };
30
+ }
31
+
32
+ return ruleset;
33
+ }
34
+
35
+ function CSSLINTR(source, options) {
36
+ var result = CSSLint.verify( source, gatherRules( options ) );
37
+ var messages = result.messages || [];
38
+ return [ messages ];
39
+ };
40
+ EOW
41
+ )
42
+ end
43
+
44
+ # Public: Run CSSLint over some CSS text
45
+ #
46
+ # source - some String-like or IO-like CSS text
47
+ # options - Hash of options passed directly to csslint (default: {})
48
+ def self.run(source, options={})
49
+ source = source.respond_to?(:read) ? source.read : source
50
+ if source.respond_to?(:path)
51
+ options[:fullPath] = File.expand_path( source.path )
52
+ options[:filename] = source.path
53
+ end
54
+ Result.new(*context.call("CSSLINTR", source, options))
55
+ end
56
+
57
+ class Result
58
+ def initialize(messages)
59
+ @messages = messages
60
+ end
61
+
62
+ # Public: Did the CSS text pass CSSLint without messages?
63
+ #
64
+ # This is the return value of the CSSLint() function.
65
+ #
66
+ # Returns true iff CSSLint returned no error messages.
67
+ def valid?
68
+ @messages.select { |m| m['type'] == 'error' }.length == 0
69
+ end
70
+
71
+ # Public: A nicely formatted list of messages with their line number.
72
+ #
73
+ # Returns an Array of Strings.
74
+ def error_messages
75
+ # @messages may have a 'nil' as the last element if there was a catastrophic
76
+ # error, so we 'compact'.
77
+ @messages.compact.map {|e|
78
+ "#{e['line']}:#{e['col']}: [#{ e['type'] }] #{e['message']}#{ e['evidence'] and " (#{ e['evidence'] })"}"
79
+ }
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,61 @@
1
+ require 'rake'
2
+ require 'csslint'
3
+
4
+ module CSSLint
5
+ class TestTask
6
+ include Rake::DSL
7
+
8
+ # Public: Gets/Sets the Array of JavaScript filenames as Strings, each of
9
+ # which will be run through csslint. (default: Dir['**/*.css'])
10
+ attr_accessor :file_list
11
+
12
+ # Public: Gets/Sets the Hash of options that will be passed to each call
13
+ # of csslint. See http://www.csslint.com/lint.html for allowed options.
14
+ # (default: {})
15
+ attr_accessor :options
16
+
17
+ # Public: Define a new Rake task that runs CSSLint tests over several
18
+ # JavaScript files.
19
+ #
20
+ # name - the name of the defined Rake Task. (default: 'csslint')
21
+ #
22
+ # Yields itself for configuration if a block is given.
23
+ def initialize(name=:csslint)
24
+ @name = name
25
+ @file_list = Dir['**/*.css']
26
+ @options = {}
27
+ yield self if block_given?
28
+
29
+ define_task
30
+ end
31
+
32
+ # Internal: Define the actual Rake task.
33
+ def define_task
34
+ desc "Run #{@name == :csslint ? '' : @name + ' '}CSSLint tests"
35
+ task @name do
36
+ t0 = Time.now
37
+ errors = []
38
+
39
+ @file_list.each do |f|
40
+ result = CSSLint.run(File.open(f), @options )
41
+ if result.valid?
42
+ print '.'
43
+ else
44
+ errors << result.error_messages.map {|e| "#{f}:#{e}"}
45
+ print 'F'
46
+ end
47
+ end
48
+
49
+ puts
50
+ puts
51
+ if errors.any?
52
+ puts *errors
53
+ puts
54
+ end
55
+ puts "Finished in %.5f seconds" % [Time.now.to_f - t0.to_f]
56
+ puts "%d files, %d errors" % [@file_list.length, errors.length]
57
+ end
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1 @@
1
+ require 'csslint'
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: execcsslint
3
+ version: !ruby/object:Gem::Version
4
+ version: 12.03.19
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dean Strelau
9
+ - Daniel Holz
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-03-19 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: &21734580 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.8.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *21734580
26
+ - !ruby/object:Gem::Dependency
27
+ name: csslint-source
28
+ requirement: &21733944 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *21733944
37
+ - !ruby/object:Gem::Dependency
38
+ name: execjs
39
+ requirement: &21733356 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *21733356
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: &21732396 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *21732396
59
+ description: ! ' A bridge to run CSSLint from Ruby via ExecJS.
60
+
61
+ '
62
+ email: dgholz@gmail.com
63
+ executables: []
64
+ extensions: []
65
+ extra_rdoc_files: []
66
+ files:
67
+ - lib/execcsslint.rb
68
+ - lib/csslint.rb
69
+ - lib/csslint/testtask.rb
70
+ - LICENSE
71
+ - README.md
72
+ homepage: http://github.com/dgholz/execcsslint
73
+ licenses: []
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.16
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: ExecJS CSSLint Bridge
96
+ test_files: []