middleman-scss-lint 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7ced6cb64fd1fc67f72b822d36bd843cfb3caf17
4
+ data.tar.gz: 53a3decae36a0972724579040e018802487fb58e
5
+ SHA512:
6
+ metadata.gz: a292db3d03697c40393a2dbac678a449eeea366ef5299d6fdea7551cb25f8cf52fe50cf46c42222786bf659ee2d23ef2c075a8ed6fbf10a3937c60b7875c6960
7
+ data.tar.gz: 96701362cd916a9592ffd05a6523439cc7e80a7b4c0370517b4eed3306f44937ba8abba49900e5d2a6cf8b9cdd6f16aa8d76713f79730be534e2cb1e018c0106
@@ -0,0 +1,20 @@
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
18
+ .DS_Store
19
+ .sass-cache
20
+ build
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+ rvm:
4
+ - ruby-head
5
+ - 2.2
6
+ - 2.1
7
+ - 2.0
8
+ - 1.9.3
9
+ os:
10
+ - linux
11
+ - osx
12
+ cache: bundler
13
+ sudo: false
14
+ matrix:
15
+ fast_finish: true
16
+ allow_failures:
17
+ - rvm: ruby-head
18
+ env: TEST=true
19
+ script: bundle exec rake test
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'middleman-core', github: 'middleman/middleman', branch: 'master'
6
+ gem 'middleman-cli', github: 'middleman/middleman', branch: 'master'
7
+
8
+ gem 'cucumber', '~> 2.0'
9
+ gem 'aruba', '~> 0.6'
10
+
11
+ gem 'bundler', '>= 1.6'
12
+ gem 'rake', '>= 10.3'
File without changes
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'cucumber/rake/task'
3
+
4
+ task :default => :test
5
+
6
+ Cucumber::Rake::Task.new(:test, 'Run features that should pass') do |task|
7
+ task.cucumber_opts = '--color --tags ~@wip --strict --format pretty'
8
+ end
@@ -0,0 +1 @@
1
+ Feature: Scss Lint
@@ -0,0 +1,7 @@
1
+ PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+ ENV['TEST'] = 'true'
3
+ ENV['CONTRACTS'] = 'true'
4
+
5
+ # require 'middleman'
6
+ require 'middleman-core/step_definitions'
7
+ require File.join(PROJECT_ROOT_PATH, 'lib', 'middleman-scss-lint')
@@ -0,0 +1 @@
1
+ activate :scss_lint#, fail_build: true, config: 'empty-config.yaml'
@@ -0,0 +1,10 @@
1
+ ---
2
+ linters:
3
+ ColorKeyword:
4
+ enabled: false
5
+ ColorVariable:
6
+ enabled: false
7
+ FinalNewline:
8
+ enabled: false
9
+ ImportantRule:
10
+ enabled: false
@@ -0,0 +1,3 @@
1
+ body {
2
+ background: black !important;
3
+ }
@@ -0,0 +1,7 @@
1
+ require 'middleman-core'
2
+ require_relative 'middleman-scss-lint/version'
3
+
4
+ ::Middleman::Extensions.register(:scss_lint) do
5
+ require_relative 'middleman-scss-lint/extension'
6
+ ::Middleman::ScssLint::Extension
7
+ end
@@ -0,0 +1,102 @@
1
+ module Middleman
2
+ module ScssLint
3
+ class Extension < ::Middleman::Extension
4
+ option :config, nil, 'Path to config file'
5
+ option :fail_build, false, 'If the build should fail if lint does not pass.'
6
+
7
+ def ready
8
+ require 'rainbow'
9
+ require 'rainbow/ext/string'
10
+
11
+ result = run_once
12
+
13
+ if app.build?
14
+ if options[:fail_build] && !result
15
+ logger.error "== SCSSLint failed"
16
+ exit(1)
17
+ end
18
+ else
19
+ logger.info "== SCSSLint succeeded" if result
20
+ watch_and_run
21
+ end
22
+ end
23
+
24
+ def run_once
25
+ paths = app.sitemap.resources
26
+ .select { |r| File.extname(r.source_file) == '.scss' }
27
+ .map { |r| r.source_file }
28
+
29
+ run_linter(paths)
30
+ end
31
+
32
+ def watch_and_run
33
+ app.files.on_change :source do |changed|
34
+ changed_scss = changed.select do |f|
35
+ f[:full_path].extname == '.scss'
36
+ end
37
+
38
+ if changed_scss.length > 0
39
+ result = run_linter(changed_scss.map { |r| r[:full_path].to_s })
40
+ logger.info "== SCSSLint succeeded" if result
41
+ end
42
+ end
43
+ end
44
+
45
+ def run_linter(files_to_lint)
46
+ logger.info "== Linting SCSS"
47
+
48
+ cli_args = ['--format', 'JSON']
49
+ cli_args = cli_args + ['--config', options[:config]] if options[:config]
50
+ cli_args = cli_args + files_to_lint
51
+
52
+ begin
53
+ output = ""
54
+
55
+ ::IO.popen("bundle exec scss-lint #{cli_args.join(' ')}", 'r') do |pipe|
56
+ while buf = pipe.gets
57
+ output << buf
58
+ end
59
+ end
60
+
61
+ error_count = 0
62
+
63
+ result = ::JSON.parse(output)
64
+
65
+ result.each do |file_path, lints|
66
+ relative_path = file_path.sub(app.root, '')
67
+
68
+ lints.each do |descr|
69
+ msg = "#{location(relative_path, descr)} #{type(descr)} #{message(descr)}"
70
+
71
+ error_count += 1
72
+
73
+ if descr["severity"] == "warning"
74
+ logger.warn msg
75
+ else
76
+ logger.error msg
77
+ end
78
+ end
79
+ end
80
+
81
+ error_count <= 0
82
+ rescue ::Errno::ENOENT => e
83
+ logger.error "== SCSSLint: Command failed with message: #{e.message}"
84
+ exit(1)
85
+ end
86
+ end
87
+
88
+ def location(path, descr)
89
+ "#{path.color(:cyan)}:#{descr["line"].to_s.color(:magenta)}"
90
+ end
91
+
92
+ def type(descr)
93
+ descr["severity"] == "error" ? '[E]'.color(:red) : '[W]'.color(:yellow)
94
+ end
95
+
96
+ def message(descr)
97
+ linter_name = "#{descr["linter"]}: ".color(:green)
98
+ "#{linter_name}#{descr["reason"]}"
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module ScssLint
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'middleman-scss-lint/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'middleman-scss-lint'
8
+ spec.version = Middleman::ScssLint::VERSION
9
+ spec.authors = ['Thomas Reynolds']
10
+ spec.email = ['me@tdreyno.com']
11
+ spec.summary = 'ScssLint integration with Middleman'
12
+ spec.homepage = 'https://github.com/middleman/middleman-scss-lint'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.test_files = `git ls-files -- {features,fixtures}/*`.split($/)
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'middleman-core', '>= 4.0.0'
20
+ spec.add_dependency 'scss_lint', '~> 0.40'
21
+ spec.add_dependency 'rainbow'
22
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-scss-lint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Thomas Reynolds
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: scss_lint
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.40'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.40'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - me@tdreyno.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - features/lint.feature
68
+ - features/support/env.rb
69
+ - fixtures/lint-app/config.rb
70
+ - fixtures/lint-app/empty-config.yaml
71
+ - fixtures/lint-app/source/stylesheets/site.css.scss
72
+ - lib/middleman-scss-lint.rb
73
+ - lib/middleman-scss-lint/extension.rb
74
+ - lib/middleman-scss-lint/version.rb
75
+ - middleman-scss-lint.gemspec
76
+ homepage: https://github.com/middleman/middleman-scss-lint
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.8
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: ScssLint integration with Middleman
100
+ test_files:
101
+ - features/lint.feature
102
+ - features/support/env.rb
103
+ - fixtures/lint-app/config.rb
104
+ - fixtures/lint-app/empty-config.yaml
105
+ - fixtures/lint-app/source/stylesheets/site.css.scss