danger-stylelint 1.0.0

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
+ SHA256:
3
+ metadata.gz: ded5a9803e7b6b96a18500ba6e6a992cc88b4013ced414a42d6a4190ac1a360d
4
+ data.tar.gz: 21a218d102dbb9d1fd1c4b0ba0100745c5cc90db29e5bc6e04658699e8e42bda
5
+ SHA512:
6
+ metadata.gz: 0d55c4ae5cab67830437e3356ae87af82348a4538be236401092d53b2cd8301c8c51f5c2b20dfc38a4db4eae33959b5ed28902e7855b672b3cb3cd69729d7687
7
+ data.tar.gz: 127f31323be63997c23c15ebc08cbea399eec302c61442606afe4949617b26960b51bb2c4e96931eb95c6ba550da4cf4cd7a0171649f3bde1c73331c5a7a5cf6
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
4
+ .yardoc
data/.rubocop.yml ADDED
@@ -0,0 +1,148 @@
1
+ # Defaults can be found here: https://github.com/bbatsov/rubocop/blob/master/config/default.yml
2
+
3
+ # If you don't like these settings, just delete this file :)
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.6
7
+
8
+ Style/StringLiterals:
9
+ EnforcedStyle: double_quotes
10
+ Enabled: true
11
+
12
+ # kind_of? is a good way to check a type
13
+ Style/ClassCheck:
14
+ EnforcedStyle: kind_of?
15
+
16
+ # specs sometimes have useless assignments, which is fine
17
+ Lint/UselessAssignment:
18
+ Exclude:
19
+ - '**/spec/**/*'
20
+
21
+ # We could potentially enable the 2 below:
22
+ Layout/FirstHashElementIndentation:
23
+ Enabled: false
24
+
25
+ Layout/HashAlignment:
26
+ Enabled: false
27
+
28
+ # HoundCI doesn't like this rule
29
+ Layout/DotPosition:
30
+ Enabled: false
31
+
32
+ # We allow !! as it's an easy way to convert ot boolean
33
+ Style/DoubleNegation:
34
+ Enabled: false
35
+
36
+ # Cop supports --auto-correct.
37
+ Lint/UnusedBlockArgument:
38
+ Enabled: false
39
+
40
+ # We want to allow class Fastlane::Class
41
+ Style/ClassAndModuleChildren:
42
+ Enabled: false
43
+
44
+ Metrics/AbcSize:
45
+ Max: 60
46
+
47
+ # The %w might be confusing for new users
48
+ Style/WordArray:
49
+ MinSize: 19
50
+
51
+ # raise and fail are both okay
52
+ Style/SignalException:
53
+ Enabled: false
54
+
55
+ # Better too much 'return' than one missing
56
+ Style/RedundantReturn:
57
+ Enabled: false
58
+
59
+ # Having if in the same line might not always be good
60
+ Style/IfUnlessModifier:
61
+ Enabled: false
62
+
63
+ # and and or is okay
64
+ Style/AndOr:
65
+ Enabled: false
66
+
67
+ # Configuration parameters: CountComments.
68
+ Metrics/ClassLength:
69
+ Max: 350
70
+
71
+ Metrics/CyclomaticComplexity:
72
+ Max: 17
73
+
74
+ # Configuration parameters: AllowURI, URISchemes.
75
+ Layout/LineLength:
76
+ Max: 370
77
+
78
+ # Configuration parameters: CountKeywordArgs.
79
+ Metrics/ParameterLists:
80
+ Max: 10
81
+
82
+ Metrics/PerceivedComplexity:
83
+ Max: 18
84
+
85
+ # Sometimes it's easier to read without guards
86
+ Style/GuardClause:
87
+ Enabled: false
88
+
89
+ # something = if something_else
90
+ # that's confusing
91
+ Style/ConditionalAssignment:
92
+ Enabled: false
93
+
94
+ # Better to have too much self than missing a self
95
+ Style/RedundantSelf:
96
+ Enabled: false
97
+
98
+ Metrics/MethodLength:
99
+ Max: 60
100
+
101
+ # We're not there yet
102
+ Style/Documentation:
103
+ Enabled: false
104
+
105
+ # Adds complexity
106
+ Style/IfInsideElse:
107
+ Enabled: false
108
+
109
+ # danger specific
110
+
111
+ Style/BlockComments:
112
+ Enabled: false
113
+
114
+ Layout/MultilineMethodCallIndentation:
115
+ EnforcedStyle: indented
116
+
117
+ # FIXME: 25
118
+ Metrics/BlockLength:
119
+ Max: 345
120
+ Exclude:
121
+ - "**/*_spec.rb"
122
+
123
+ Style/MixinGrouping:
124
+ Enabled: false
125
+
126
+ Naming/FileName:
127
+ Enabled: false
128
+
129
+ Layout/HeredocIndentation:
130
+ Enabled: false
131
+
132
+ Style/SpecialGlobalVars:
133
+ Enabled: false
134
+
135
+ Style/PercentLiteralDelimiters:
136
+ PreferredDelimiters:
137
+ "%": ()
138
+ "%i": ()
139
+ "%q": ()
140
+ "%Q": ()
141
+ "%r": "{}"
142
+ "%s": ()
143
+ "%w": ()
144
+ "%W": ()
145
+ "%x": ()
146
+
147
+ Security/YAMLLoad:
148
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ cache:
3
+ directories:
4
+ - bundle
5
+
6
+ rvm:
7
+ - 2.6
8
+ - 2.7
9
+
10
+ script:
11
+ - bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in danger-stylelint.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,170 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-stylelint (0.0.1)
5
+ danger-plugin-api (~> 1.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.8.0)
11
+ public_suffix (>= 2.0.2, < 5.0)
12
+ ast (2.4.2)
13
+ claide (1.1.0)
14
+ claide-plugins (0.9.2)
15
+ cork
16
+ nap
17
+ open4 (~> 1.3)
18
+ coderay (1.1.3)
19
+ colored2 (3.1.2)
20
+ cork (0.3.0)
21
+ colored2 (~> 3.1)
22
+ danger (8.6.1)
23
+ claide (~> 1.0)
24
+ claide-plugins (>= 0.9.2)
25
+ colored2 (~> 3.1)
26
+ cork (~> 0.1)
27
+ faraday (>= 0.9.0, < 2.0)
28
+ faraday-http-cache (~> 2.0)
29
+ git (~> 1.7)
30
+ kramdown (~> 2.3)
31
+ kramdown-parser-gfm (~> 1.0)
32
+ no_proxy_fix
33
+ octokit (~> 4.7)
34
+ terminal-table (>= 1, < 4)
35
+ danger-plugin-api (1.0.0)
36
+ danger (> 2.0)
37
+ diff-lcs (1.5.0)
38
+ faraday (1.10.0)
39
+ faraday-em_http (~> 1.0)
40
+ faraday-em_synchrony (~> 1.0)
41
+ faraday-excon (~> 1.1)
42
+ faraday-httpclient (~> 1.0)
43
+ faraday-multipart (~> 1.0)
44
+ faraday-net_http (~> 1.0)
45
+ faraday-net_http_persistent (~> 1.0)
46
+ faraday-patron (~> 1.0)
47
+ faraday-rack (~> 1.0)
48
+ faraday-retry (~> 1.0)
49
+ ruby2_keywords (>= 0.0.4)
50
+ faraday-em_http (1.0.0)
51
+ faraday-em_synchrony (1.0.0)
52
+ faraday-excon (1.1.0)
53
+ faraday-http-cache (2.2.0)
54
+ faraday (>= 0.8)
55
+ faraday-httpclient (1.0.1)
56
+ faraday-multipart (1.0.3)
57
+ multipart-post (>= 1.2, < 3)
58
+ faraday-net_http (1.0.1)
59
+ faraday-net_http_persistent (1.2.0)
60
+ faraday-patron (1.0.0)
61
+ faraday-rack (1.0.0)
62
+ faraday-retry (1.0.3)
63
+ ffi (1.15.5)
64
+ formatador (1.1.0)
65
+ git (1.11.0)
66
+ rchardet (~> 1.8)
67
+ guard (2.18.0)
68
+ formatador (>= 0.2.4)
69
+ listen (>= 2.7, < 4.0)
70
+ lumberjack (>= 1.0.12, < 2.0)
71
+ nenv (~> 0.1)
72
+ notiffany (~> 0.0)
73
+ pry (>= 0.13.0)
74
+ shellany (~> 0.0)
75
+ thor (>= 0.18.1)
76
+ guard-compat (1.2.1)
77
+ guard-rspec (4.7.3)
78
+ guard (~> 2.1)
79
+ guard-compat (~> 1.1)
80
+ rspec (>= 2.99.0, < 4.0)
81
+ kramdown (2.4.0)
82
+ rexml
83
+ kramdown-parser-gfm (1.1.0)
84
+ kramdown (~> 2.0)
85
+ listen (3.0.7)
86
+ rb-fsevent (>= 0.9.3)
87
+ rb-inotify (>= 0.9.7)
88
+ lumberjack (1.2.8)
89
+ method_source (1.0.0)
90
+ multipart-post (2.1.1)
91
+ nap (1.1.0)
92
+ nenv (0.3.0)
93
+ no_proxy_fix (0.1.2)
94
+ notiffany (0.1.3)
95
+ nenv (~> 0.1)
96
+ shellany (~> 0.0)
97
+ octokit (4.22.0)
98
+ faraday (>= 0.9)
99
+ sawyer (~> 0.8.0, >= 0.5.3)
100
+ open4 (1.3.4)
101
+ parallel (1.22.1)
102
+ parser (3.1.2.0)
103
+ ast (~> 2.4.1)
104
+ pry (0.14.1)
105
+ coderay (~> 1.1)
106
+ method_source (~> 1.0)
107
+ public_suffix (4.0.7)
108
+ rainbow (3.1.1)
109
+ rake (10.5.0)
110
+ rb-fsevent (0.11.1)
111
+ rb-inotify (0.10.1)
112
+ ffi (~> 1.0)
113
+ rchardet (1.8.0)
114
+ regexp_parser (2.4.0)
115
+ rexml (3.2.5)
116
+ rspec (3.11.0)
117
+ rspec-core (~> 3.11.0)
118
+ rspec-expectations (~> 3.11.0)
119
+ rspec-mocks (~> 3.11.0)
120
+ rspec-core (3.11.0)
121
+ rspec-support (~> 3.11.0)
122
+ rspec-expectations (3.11.0)
123
+ diff-lcs (>= 1.2.0, < 2.0)
124
+ rspec-support (~> 3.11.0)
125
+ rspec-mocks (3.11.1)
126
+ diff-lcs (>= 1.2.0, < 2.0)
127
+ rspec-support (~> 3.11.0)
128
+ rspec-support (3.11.0)
129
+ rubocop (1.29.1)
130
+ parallel (~> 1.10)
131
+ parser (>= 3.1.0.0)
132
+ rainbow (>= 2.2.2, < 4.0)
133
+ regexp_parser (>= 1.8, < 3.0)
134
+ rexml (>= 3.2.5, < 4.0)
135
+ rubocop-ast (>= 1.17.0, < 2.0)
136
+ ruby-progressbar (~> 1.7)
137
+ unicode-display_width (>= 1.4.0, < 3.0)
138
+ rubocop-ast (1.18.0)
139
+ parser (>= 3.1.1.0)
140
+ ruby-progressbar (1.11.0)
141
+ ruby2_keywords (0.0.5)
142
+ sawyer (0.8.2)
143
+ addressable (>= 2.3.5)
144
+ faraday (> 0.8, < 2.0)
145
+ shellany (0.0.1)
146
+ terminal-table (3.0.2)
147
+ unicode-display_width (>= 1.1.1, < 3)
148
+ thor (1.2.1)
149
+ unicode-display_width (2.1.0)
150
+ webrick (1.7.0)
151
+ yard (0.9.27)
152
+ webrick (~> 1.7.0)
153
+
154
+ PLATFORMS
155
+ x86_64-darwin-18
156
+
157
+ DEPENDENCIES
158
+ bundler (~> 2.0)
159
+ danger-stylelint!
160
+ guard (~> 2.14)
161
+ guard-rspec (~> 4.7)
162
+ listen (= 3.0.7)
163
+ pry
164
+ rake (~> 10.0)
165
+ rspec (~> 3.4)
166
+ rubocop
167
+ yard
168
+
169
+ BUNDLED WITH
170
+ 2.3.8
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A guardfile for making Danger Plugins
4
+ # For more info see https://github.com/guard/guard#readme
5
+
6
+ # To run, use `bundle exec guard`.
7
+
8
+ guard :rspec, cmd: "bundle exec rspec" do
9
+ require "guard/rspec/dsl"
10
+ dsl = Guard::RSpec::Dsl.new(self)
11
+
12
+ # RSpec files
13
+ rspec = dsl.rspec
14
+ watch(rspec.spec_helper) { rspec.spec_dir }
15
+ watch(rspec.spec_support) { rspec.spec_dir }
16
+ watch(rspec.spec_files)
17
+
18
+ # Ruby files
19
+ ruby = dsl.ruby
20
+ dsl.watch_spec_files_for(ruby.lib_files)
21
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2022 Nimble
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.
23
+ `
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ <p align="center">
2
+ <img alt="Nimble logo" src="https://assets.nimblehq.co/logo/light/logo-light-text-320.png" />
3
+ </p>
4
+
5
+ <h2 align="center">Danger Stylelint</h3>
6
+ <p align="center">A Plugin for Ruby or Ruby on Rails projects to warn CSS issues. The checks are performed using <a href="https://stylelint.io/">Stylelint<a></p>
7
+
8
+ -------
9
+
10
+ ## Prerequisites
11
+
12
+ To use this plugin, your project must have successfully setup [Danger](https://danger.systems/guides/getting_started.html)
13
+
14
+ You would also need to install `stylelint` into your project
15
+
16
+ $ npm install -D stylelint
17
+
18
+ ## Installation
19
+
20
+ Simply run the following in your project.
21
+
22
+ $ gem install danger-stylelint
23
+
24
+
25
+ ## Usage
26
+
27
+ To use the extension, add the following to your Dangerfile
28
+
29
+ ```ruby
30
+ stylelint.lint
31
+ ```
32
+
33
+ ### Options
34
+
35
+ | Options | Required | Default Value | Description |
36
+ |----------------------- |---------- |------------------------------- |-------------------------------------------- |
37
+ | stylelint.config_file | No | nil | Path to a Stylelint configuration file. |
38
+ | stylelint.changes_only | No | false | Comment only on changed lines |
39
+ | stylelint.bin_path | No | ./node_modules/.bin/stylelint | Path to the node installation of Stylelint |
40
+
41
+ To use an option, add it before running stylelint
42
+
43
+ ```ruby
44
+ stylelint.config_file = "./.stylelintrc"
45
+ stylelint.lint
46
+ ```
47
+
48
+ ## Development
49
+
50
+ 1. Clone this repo
51
+ 2. Run `bundle install` to setup dependencies.
52
+ 3. Run `bundle exec rake spec` to run the tests.
53
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
54
+ 5. Make your changes.
55
+
56
+ ## License
57
+
58
+ This project is Copyright (c) 2014-2022 Nimble. It is free software,
59
+ and may be redistributed under the terms specified in the [LICENSE] file.
60
+
61
+ [LICENSE]: /LICENSE.txt
62
+
63
+ ## About
64
+
65
+ ![Nimble](https://assets.nimblehq.co/logo/dark/logo-dark-text-160.png)
66
+
67
+ This project is maintained and funded by Nimble.
68
+
69
+ We love open source and do our part in sharing our work with the community!
70
+ See [our other projects][community] or [hire our team][hire] to help build your product.
71
+
72
+ [community]: https://github.com/nimblehq
73
+ [hire]: https://nimblehq.co/
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new(:specs)
8
+
9
+ task default: :specs
10
+
11
+ task :spec do
12
+ Rake::Task["specs"].invoke
13
+ Rake::Task["rubocop"].invoke
14
+ Rake::Task["spec_docs"].invoke
15
+ end
16
+
17
+ desc "Run RuboCop on the lib/specs directory"
18
+ RuboCop::RakeTask.new(:rubocop) do |task|
19
+ task.patterns = ["lib/**/*.rb", "spec/**/*.rb"]
20
+ end
21
+
22
+ desc "Ensure that the plugin passes `danger plugins lint`"
23
+ task :spec_docs do
24
+ sh "bundle exec danger plugins lint"
25
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "stylelint/gem_version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "danger-stylelint"
9
+ spec.version = Stylelint::VERSION
10
+ spec.authors = ["Nimble"]
11
+ spec.email = ["dev@nimblehq.co"]
12
+ spec.description = "Report Stylelint issues to PRs"
13
+ spec.summary = "A Danger plugin for Ruby or Ruby on Rails projects to warn Stylelint issues"
14
+ spec.homepage = "https://github.com/nimblehq/danger-stylelint"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
23
+
24
+ # General ruby development
25
+ spec.add_development_dependency "bundler", "~> 2.0"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+
28
+ # Testing support
29
+ spec.add_development_dependency "rspec", "~> 3.4"
30
+
31
+ # Linting code and docs
32
+ spec.add_development_dependency "rubocop"
33
+ spec.add_development_dependency "yard"
34
+
35
+ # Makes testing easy via `bundle exec guard`
36
+ spec.add_development_dependency "guard", "~> 2.14"
37
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
38
+
39
+ # If you want to work on older builds of ruby
40
+ spec.add_development_dependency "listen", "3.0.7"
41
+
42
+ # This gives you the chance to run a REPL inside your tests
43
+ # via:
44
+ #
45
+ # require 'pry'
46
+ # binding.pry
47
+ #
48
+ # This will stop test execution and let you inspect the results
49
+ spec.add_development_dependency "pry"
50
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stylelint/plugin"
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stylelint/gem_version"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stylelint
4
+ VERSION = "1.0.0"
5
+ end
@@ -0,0 +1,124 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "json"
5
+
6
+ module Danger
7
+ # Lint stylesheets using [stylelint](http://stylelint.io/).
8
+ # Results are send as inline comment.
9
+ #
10
+ # @example Run stylelint with changed files only
11
+ #
12
+ # stylelint.changes_only = true
13
+ # stylelint.lint
14
+ #
15
+ # @see nimblehq/danger-stylelint
16
+ # @tags lint, stylelint, css, scss, sass
17
+ #
18
+ class DangerStylelint < Plugin
19
+ DEFAULT_BIN_PATH = "./node_modules/.bin/stylelint"
20
+
21
+ # An path to stylelint's config file
22
+ # @return [String]
23
+ attr_accessor :config_file
24
+
25
+ # Enable changes_only
26
+ # Only show messages within changed files.
27
+ # @return [Boolean]
28
+ attr_accessor :changes_only
29
+
30
+ # A path of stylelint's bin
31
+ # @return [String]
32
+ attr_writer :bin_path
33
+
34
+ def bin_path
35
+ @bin_path ||= DEFAULT_BIN_PATH
36
+ end
37
+
38
+ # Specify extensions of target file
39
+ # Default is [".css, .scss, .sass"]
40
+ # @return [Array]
41
+ attr_writer :target_extensions
42
+
43
+ def target_extensions
44
+ @target_extensions ||= %w(.css .scss .sass)
45
+ end
46
+
47
+ # Lints css files.
48
+ # Generates `errors` and `warnings` according to stylelint's config.
49
+ #
50
+ # @return [void]
51
+ #
52
+ def lint
53
+ lint_results
54
+ .reject { |result| result.nil? || result["warnings"].length.zero? }
55
+ .map { |result| send_comment result }
56
+ end
57
+
58
+ private
59
+
60
+ # Get stylelint bin path
61
+ #
62
+ # return [String]
63
+ def stylelint_path
64
+ raise "stylelint is not installed" unless File.exist?(bin_path)
65
+
66
+ bin_path
67
+ end
68
+
69
+ # Get all lintable files
70
+ #
71
+ # return [String]
72
+ def all_lintable_files
73
+ "**/*{#{target_extensions.join(',')}}"
74
+ end
75
+
76
+ # Get all the changed files
77
+ #
78
+ # return [Array]
79
+ def all_changed_files
80
+ ((git.modified_files - git.deleted_files - git.renamed_files.map { |r| r[:before] }) + git.added_files + git.renamed_files.map { |r| r[:after] })
81
+ end
82
+
83
+ # Get lint result with respect to the changes_only option
84
+ #
85
+ # return [Hash]
86
+ def lint_results
87
+ bin = stylelint_path
88
+ return run_lint(bin, all_lintable_files) unless changes_only
89
+
90
+ all_changed_files.select { |f| target_extensions.include?(File.extname(f)) }
91
+ .map { |f| f.gsub("#{Dir.pwd}/", "") }
92
+ .map { |f| run_lint(bin, f).first }
93
+ end
94
+
95
+ # Run stylelint against file(s).
96
+ #
97
+ # @param [String] bin
98
+ # The binary path of stylelint
99
+ #
100
+ # @param [String] file
101
+ # File to be linted
102
+ #
103
+ # return [Hash]
104
+ def run_lint(bin, file)
105
+ command = "#{bin} -f json"
106
+ command << " --config #{config_file}" if config_file
107
+ result = `#{command} "#{file}"`
108
+ JSON.parse(result)
109
+ end
110
+
111
+ # Send comment with danger's warn or fail method.
112
+ #
113
+ # @return [void]
114
+ def send_comment(result)
115
+ dir = "#{Dir.pwd}/"
116
+
117
+ result["warnings"].each do |warning|
118
+ filename = result["source"].gsub(dir, "")
119
+ method = warning["severity"] == "error" ? "fail" : "warn"
120
+ send(method, warning["text"], file: filename, line: warning["line"])
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,53 @@
1
+ [
2
+ {
3
+ "source": "danger-stylelint/spec/fixtures/error.scss",
4
+ "deprecations": [],
5
+ "invalidOptionWarnings": [],
6
+ "parseErrors": [],
7
+ "errored": true,
8
+ "warnings": [
9
+ {
10
+ "line": 7,
11
+ "column": 34,
12
+ "rule": "declaration-block-trailing-semicolon",
13
+ "severity": "error",
14
+ "text": "Expected a trailing semicolon (declaration-block-trailing-semicolon)"
15
+ },
16
+ {
17
+ "line": 11,
18
+ "column": 35,
19
+ "rule": "declaration-block-trailing-semicolon",
20
+ "severity": "error",
21
+ "text": "Expected a trailing semicolon (declaration-block-trailing-semicolon)"
22
+ },
23
+ {
24
+ "line": 17,
25
+ "column": 35,
26
+ "rule": "declaration-block-trailing-semicolon",
27
+ "severity": "error",
28
+ "text": "Expected a trailing semicolon (declaration-block-trailing-semicolon)"
29
+ },
30
+ {
31
+ "line": 1,
32
+ "column": 1,
33
+ "rule": "selector-class-pattern",
34
+ "severity": "error",
35
+ "text": "Selector should be written in lowercase with hyphens (selector-class-pattern)"
36
+ },
37
+ {
38
+ "line": 16,
39
+ "column": 5,
40
+ "rule": "selector-max-compound-selectors",
41
+ "severity": "error",
42
+ "text": "Expected \".slickDots :global li.slick-active button::before\" to have no more than 3 compound selectors (selector-max-compound-selectors)"
43
+ },
44
+ {
45
+ "line": 15,
46
+ "column": 22,
47
+ "rule": "selector-no-qualifying-type",
48
+ "severity": "error",
49
+ "text": "Unexpected qualifying type selector (selector-no-qualifying-type)"
50
+ }
51
+ ]
52
+ }
53
+ ]
@@ -0,0 +1,20 @@
1
+ .slickDots {
2
+ @apply fixed left-0 mb-[42px];
3
+
4
+ li {
5
+ button::before,
6
+ button:focus::before {
7
+ @apply text-white opacity-20
8
+ }
9
+
10
+ button:hover::before {
11
+ @apply text-white opacity-100
12
+ }
13
+ }
14
+
15
+ :global li.slick-active {
16
+ button::before {
17
+ @apply text-white opacity-100
18
+ }
19
+ }
20
+ }
File without changes
@@ -0,0 +1,10 @@
1
+ [
2
+ {
3
+ "source": "danger-stylelint/spec/fixtures/valid.scss",
4
+ "deprecations": [],
5
+ "invalidOptionWarnings": [],
6
+ "parseErrors": [],
7
+ "errored": false,
8
+ "warnings": []
9
+ }
10
+ ]
@@ -0,0 +1,5 @@
1
+ /* stylelint-disable selector-class-pattern */
2
+ .rangeSlider {
3
+ @apply h-0.5 w-full mt-[91px] appearance-none;
4
+ }
5
+ /* stylelint-enable selector-class-pattern */
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ ROOT = Pathname.new(File.expand_path("..", __dir__))
5
+ $:.unshift("#{ROOT}lib".to_s)
6
+ $:.unshift("#{ROOT}spec".to_s)
7
+
8
+ require "bundler/setup"
9
+ require "pry"
10
+
11
+ require "rspec"
12
+ require "danger"
13
+
14
+ if `git remote -v` == ""
15
+ puts "You cannot run tests without setting a local git remote on this repo"
16
+ puts "It's a weird side-effect of Danger's internals."
17
+ exit(0)
18
+ end
19
+
20
+ # Use coloured output, it's the best.
21
+ RSpec.configure do |config|
22
+ config.filter_gems_from_backtrace "bundler"
23
+ config.color = true
24
+ config.tty = true
25
+ end
26
+
27
+ require "danger_plugin"
28
+
29
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
30
+ # If you are expanding these files, see if it's already been done ^.
31
+
32
+ # A silent version of the user interface,
33
+ # it comes with an extra function `.string` which will
34
+ # strip all ANSI colours from the string.
35
+
36
+ # rubocop:disable Lint/NestedMethodDefinition
37
+ def testing_ui
38
+ @output = StringIO.new
39
+ def @output.winsize
40
+ [20, 9999]
41
+ end
42
+
43
+ cork = Cork::Board.new(out: @output)
44
+ def cork.string
45
+ out.string.gsub(/\e\[([;\d]+)?m/, "")
46
+ end
47
+ cork
48
+ end
49
+ # rubocop:enable Lint/NestedMethodDefinition
50
+
51
+ # Example environment (ENV) that would come from
52
+ # running a PR on TravisCI
53
+ def testing_env
54
+ {
55
+ "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
56
+ "TRAVIS_PULL_REQUEST" => "800",
57
+ "TRAVIS_REPO_SLUG" => "artsy/eigen",
58
+ "TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d",
59
+ "DANGER_GITHUB_API_TOKEN" => "123sbdq54erfsd3422gdfio"
60
+ }
61
+ end
62
+
63
+ # A stubbed out Dangerfile for use in tests
64
+ def testing_dangerfile
65
+ env = Danger::EnvironmentManager.new(testing_env)
66
+ Danger::Dangerfile.new(env, testing_ui)
67
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("spec_helper", __dir__)
4
+
5
+ module Danger
6
+ describe Danger::DangerStylelint do
7
+ it "should be a plugin" do
8
+ expect(Danger::DangerStylelint.new(nil)).to be_a Danger::Plugin
9
+ end
10
+
11
+ describe "with Dangerfile" do
12
+ let(:stylelint) { testing_dangerfile.stylelint }
13
+ let(:warnings) { stylelint.status_report[:warnings] }
14
+ let(:errors) { stylelint.status_report[:errors] }
15
+ let(:messages) { stylelint.status_report[:messages] }
16
+ let(:markdowns) { stylelint.status_report[:markdowns] }
17
+
18
+ before do
19
+ allow(stylelint.git).to receive(:deleted_files).and_return([])
20
+ allow(stylelint.git).to receive(:added_files).and_return([])
21
+ allow(stylelint.git).to receive(:modified_files).and_return([])
22
+ allow(stylelint.git).to receive(:renamed_files).and_return([])
23
+ stub_const("Danger::DangerStylelint::DEFAULT_BIN_PATH", "spec/fixtures/stylelint")
24
+ end
25
+
26
+ it "does not make an empty message" do
27
+ allow(stylelint).to receive(:lint).and_return("[]")
28
+
29
+ stylelint.lint
30
+
31
+ expect(warnings).to eq([])
32
+ expect(errors).to eq([])
33
+ expect(messages).to eq([])
34
+ expect(markdowns).to eq([])
35
+ end
36
+
37
+ it "fails if stylelint not installed" do
38
+ allow(stylelint).to receive(:bin_path).and_return("")
39
+
40
+ expect { stylelint.lint }.to raise_error("stylelint is not installed")
41
+ end
42
+
43
+ describe "#lint" do
44
+ let(:valid_result) { JSON.parse(File.read("spec/fixtures/valid.json")) }
45
+ let(:error_result) { JSON.parse(File.read("spec/fixtures/error.json")) }
46
+
47
+ it "lints all files when changes_only is disabled by default" do
48
+ allow(stylelint).to receive(:all_lintable_files).and_return("spec/fixtures/error.scss")
49
+ allow(stylelint).to receive(:run_lint)
50
+ .with(anything, /error.scss/).and_return(error_result)
51
+
52
+ stylelint.lint
53
+
54
+ expect(warnings.length).to eq(0)
55
+ expect(errors.length).to eq(6)
56
+ expect(messages.length).to eq(0)
57
+ expect(markdowns.length).to eq(0)
58
+ expect(errors).to eq(
59
+ [
60
+ "Expected a trailing semicolon (declaration-block-trailing-semicolon)",
61
+ "Expected a trailing semicolon (declaration-block-trailing-semicolon)",
62
+ "Expected a trailing semicolon (declaration-block-trailing-semicolon)",
63
+ "Selector should be written in lowercase with hyphens (selector-class-pattern)",
64
+ "Expected \".slickDots :global li.slick-active button::before\" to have no more than 3 compound selectors (selector-max-compound-selectors)",
65
+ "Unexpected qualifying type selector (selector-no-qualifying-type)"
66
+ ]
67
+ )
68
+ end
69
+
70
+ it "lints only changed files when changes_only is enabled" do
71
+ allow(stylelint.git).to receive(:modified_files)
72
+ .and_return(["spec/fixtures/valid.scss"])
73
+ allow(stylelint).to receive(:run_lint)
74
+ .with(anything, /valid.scss/).and_return(valid_result)
75
+
76
+ stylelint.changes_only = true
77
+ stylelint.lint
78
+
79
+ expect(warnings.length).to eq(0)
80
+ expect(errors.length).to eq(0)
81
+ expect(messages.length).to eq(0)
82
+ expect(markdowns.length).to eq(0)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-stylelint
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nimble
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: listen
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 3.0.7
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 3.0.7
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Report Stylelint issues to PRs
154
+ email:
155
+ - dev@nimblehq.co
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rubocop.yml"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - Gemfile.lock
165
+ - Guardfile
166
+ - LICENSE.txt
167
+ - README.md
168
+ - Rakefile
169
+ - danger-stylelint.gemspec
170
+ - lib/danger_plugin.rb
171
+ - lib/danger_stylelint.rb
172
+ - lib/stylelint/gem_version.rb
173
+ - lib/stylelint/plugin.rb
174
+ - spec/fixtures/error.json
175
+ - spec/fixtures/error.scss
176
+ - spec/fixtures/stylelint
177
+ - spec/fixtures/valid.json
178
+ - spec/fixtures/valid.scss
179
+ - spec/spec_helper.rb
180
+ - spec/stylelint_spec.rb
181
+ homepage: https://github.com/nimblehq/danger-stylelint
182
+ licenses:
183
+ - MIT
184
+ metadata: {}
185
+ post_install_message:
186
+ rdoc_options: []
187
+ require_paths:
188
+ - lib
189
+ required_ruby_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ requirements: []
200
+ rubygems_version: 3.2.15
201
+ signing_key:
202
+ specification_version: 4
203
+ summary: A Danger plugin for Ruby or Ruby on Rails projects to warn Stylelint issues
204
+ test_files:
205
+ - spec/fixtures/error.json
206
+ - spec/fixtures/error.scss
207
+ - spec/fixtures/stylelint
208
+ - spec/fixtures/valid.json
209
+ - spec/fixtures/valid.scss
210
+ - spec/spec_helper.rb
211
+ - spec/stylelint_spec.rb