guard-sass-lint 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 24f41fb1829db2288ba8e50aebe76b1b67aba875
4
+ data.tar.gz: ce474b4bd7a2861259e68aa6cbe97041101f8ebb
5
+ SHA512:
6
+ metadata.gz: dddea4b7fc6957fbdd7448aa68b415eefd5fc845d96a17b336073924fce3281559d8639444b21e519bfa3f1c41d8a2c0778e2e8cb8d3e7d74436dd5ca51e64b5
7
+ data.tar.gz: c22528f74dfbb52172d66a30265e3efac8ca5ef87afb61295f9285c84b2d2479fdcdd04277611fea27fa03952aa6f2ec4445927e35546d75f86b925234099c4e
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /node_modules/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in guard-sass-lint.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Daniel Hanson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Guard::Sass::Lint
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/guard/sass/lint`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'guard-sass-lint'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install guard-sass-lint
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/guard-sass-lint.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "guard/sass/lint"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'guard/sass/lint/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'guard-sass-lint'
8
+ spec.version = Guard::Sass::Lint::VERSION
9
+ spec.authors = ['Daniel Hanson']
10
+ spec.email = ['hansondr@gmail.com']
11
+
12
+ spec.summary = 'Guard sass-lint wrapper'
13
+ spec.description = 'Automatically run sass-lint on your SASS'
14
+ spec.homepage = 'https://github.com/hansondr/guard-sass-lint'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'guard-compat', '~> 1.2'
25
+ spec.add_dependency 'colorize', '~> 0.8'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.14'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ end
@@ -0,0 +1,5 @@
1
+ require 'guard/sass/lint/version'
2
+ require 'guard/sass/lint/linter'
3
+ require 'guard/sass/lint/runner'
4
+ require 'guard/sass/lint/all_runner'
5
+ require 'guard/sass/lint/railtie' if defined?(Rails)
@@ -0,0 +1 @@
1
+ require 'sasslint'
@@ -0,0 +1,57 @@
1
+ require 'colorize'
2
+
3
+ module Guard
4
+ module Sass
5
+ module Lint
6
+ class AllRunner
7
+ def initialize(linter)
8
+ @linter = linter
9
+ @results = {}
10
+ end
11
+
12
+ def run
13
+ $stdout.sync = true
14
+
15
+ sass_files.each do |file|
16
+ calculate_result @linter.lint(file)
17
+ print '.'
18
+ end
19
+
20
+ display_final_result
21
+ end
22
+
23
+ def lint(filename)
24
+ calculate_result
25
+ end
26
+
27
+ private
28
+
29
+ def sass_files
30
+ @sass_files ||= Dir.glob('*/**/*.scss').sort
31
+ end
32
+
33
+ def calculate_result(result_data)
34
+ if !result_data.nil? && !result_data.empty?
35
+ data = result_data.first
36
+ file_path = data['filePath']
37
+ warnings = data['warningCount'].to_i
38
+ errors = data['errorCount'].to_i
39
+ @results[file_path] = { warn: warnings, error: errors }
40
+ end
41
+ end
42
+
43
+ def display_final_result
44
+ puts "\n"
45
+ puts ' Error Warn' if @results.present?
46
+ @results.each do |file, counts|
47
+ errors = sprintf('%4d', counts[:error]).red
48
+ warns = sprintf('%4d', counts[:warn]).yellow
49
+ puts " #{errors} #{warns} - #{file}"
50
+ end
51
+
52
+ @results = {}
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,79 @@
1
+ module Guard
2
+ module Sass
3
+ module Lint
4
+ class Linter
5
+ OUTPUT_FILE = 'tmp/sass_lint_results.json'.freeze
6
+
7
+ def initialize(config_location = nil)
8
+ @config_location = config_location
9
+ @results = {}
10
+ end
11
+
12
+ def lint(file)
13
+ clear_results
14
+ system lint_command(file)
15
+ result_data
16
+ end
17
+
18
+ private
19
+
20
+ def root
21
+ File.expand_path('../../../../..', __FILE__)
22
+ end
23
+
24
+ def sass_lint_dir
25
+ @sass_lint_dir ||= File.join(root, 'node_modules', 'sass-lint')
26
+ end
27
+
28
+ def lint_command(filename)
29
+ [linter, config, format, output, additional, filename, quiet].join(' ')
30
+ end
31
+
32
+ def linter
33
+ File.join(sass_lint_dir, 'bin', 'sass-lint.js')
34
+ end
35
+
36
+ def config
37
+ "-c #{config_file}"
38
+ end
39
+
40
+ def config_file
41
+ @config_location || default_config
42
+ end
43
+
44
+ def default_config
45
+ File.join(sass_lint_dir, 'docs', 'sass-lint.yml')
46
+ end
47
+
48
+ def format
49
+ '-f json'
50
+ end
51
+
52
+ def additional
53
+ '--no-exit --verbose'
54
+ end
55
+
56
+ def output
57
+ "-o #{OUTPUT_FILE}"
58
+ end
59
+
60
+ def quiet
61
+ ' >/dev/null 2>&1'
62
+ end
63
+
64
+ def result_data
65
+ @result_data ||= result_json_file || []
66
+ end
67
+
68
+ def clear_results
69
+ File.delete(OUTPUT_FILE) if File.exists?(OUTPUT_FILE)
70
+ @result_data = nil
71
+ end
72
+
73
+ def result_json_file
74
+ JSON.parse(File.new(OUTPUT_FILE).read) if File.exists?(OUTPUT_FILE)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,11 @@
1
+ module Guard
2
+ module Sass
3
+ module Lint
4
+ class Railtie < Rails::Railtie
5
+ rake_tasks do
6
+ load 'tasks/sasslint.rake'
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,49 @@
1
+ require 'colorize'
2
+
3
+ module Guard
4
+ module Sass
5
+ module Lint
6
+ class Runner
7
+ def initialize(file, linter)
8
+ @file = file
9
+ @linter = linter
10
+ end
11
+
12
+ def run
13
+ display_result @linter.lint(@file)
14
+ end
15
+
16
+ def display_result(result_data)
17
+ result_data.each do |data|
18
+ if data['warningCount'] > 0 || data['errorCount'] > 0
19
+ puts "⌕ #{data['filePath']}"
20
+ data['messages'].each { |msg| puts format_message(msg) }
21
+ end
22
+ end
23
+
24
+ puts clean_message if result_data.empty?
25
+ end
26
+
27
+ private
28
+
29
+ def format_message(data)
30
+ location = [sprintf("%4d", data['line']), sprintf("%-4d", data['column'])].join(':')
31
+ rule = sprintf("%-25s", "(#{data['ruleId']})")
32
+ message = " #{rule} #{location} - #{data['message']}"
33
+ case data['severity']
34
+ when 1
35
+ message.green
36
+ when 2
37
+ message.yellow
38
+ else
39
+ message
40
+ end
41
+ end
42
+
43
+ def clean_message
44
+ ['✓'.green, @file].join(' ')
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ module Guard
2
+ module Sass
3
+ module Lint
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,69 @@
1
+ require 'guard/compat/plugin'
2
+ require 'rake'
3
+ require 'mkmf'
4
+
5
+ module Guard
6
+ class Sasslint < Plugin
7
+ RAKETASK = 'sasslint:run'.freeze
8
+
9
+ def initialize(options = {})
10
+ enforce_js_dependencies!
11
+
12
+ @config = options.fetch(:config, nil)
13
+ @run_at_start = options.fetch(:run_at_start, false)
14
+ load 'Rakefile'
15
+
16
+ super options
17
+ end
18
+
19
+ def start
20
+ UI.info 'sasslint starting...'
21
+ run_all if @run_at_start
22
+ end
23
+
24
+ def run_all
25
+ UI.info 'sasslint ⇒ all sass'
26
+ lint
27
+ end
28
+
29
+ def run_on_changes(paths)
30
+ paths.each { |path| lint path }
31
+ end
32
+
33
+ private
34
+
35
+ def lint(file = nil)
36
+ ::Rake::Task[RAKETASK].reenable
37
+ ::Rake::Task[RAKETASK].invoke(file, @config)
38
+ end
39
+
40
+ def enforce_js_dependencies!
41
+ if !find_dependency 'yarnpkg'
42
+ UI.error 'Unable to locate the yarnpkg library'
43
+ UI.error 'To install yarn visit: https://yarnpkg.com/en/docs/install'
44
+ exit 1
45
+ end
46
+
47
+ if !find_dependency 'node'
48
+ UI.error 'Unable to locate the node binary'
49
+ UI.error 'Depending on OS and install method used you may need to symlink node to nodejs'
50
+ exit 1
51
+ end
52
+ end
53
+
54
+ # this hacky workaround prevents mkmf from polluting the project with
55
+ # mkmf.log files
56
+ def find_dependency(executable)
57
+ old_mkmf_log = MakeMakefile::Logging.instance_variable_get(:@logfile)
58
+ set_mkmf_log(nil)
59
+ path_to_cmd = find_executable0(executable)
60
+ set_mkmf_log(old_mkmf_log)
61
+
62
+ path_to_cmd
63
+ end
64
+
65
+ def set_mkmf_log(logfile = File::NULL)
66
+ MakeMakefile::Logging.instance_variable_set(:@logfile, logfile)
67
+ end
68
+ end
69
+ end