scss_lint 0.43.2 → 0.44.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/bin/scss-lint +2 -1
  3. data/config/default.yml +3 -0
  4. data/data/properties.txt +35 -0
  5. data/data/property-sort-orders/smacss.txt +9 -0
  6. data/data/pseudo-elements.txt +5 -0
  7. data/lib/scss_lint.rb +1 -0
  8. data/lib/scss_lint/cli.rb +50 -30
  9. data/lib/scss_lint/config.rb +28 -3
  10. data/lib/scss_lint/constants.rb +6 -4
  11. data/lib/scss_lint/control_comment_processor.rb +8 -7
  12. data/lib/scss_lint/engine.rb +1 -1
  13. data/lib/scss_lint/file_finder.rb +1 -1
  14. data/lib/scss_lint/linter.rb +8 -7
  15. data/lib/scss_lint/linter/bang_format.rb +2 -2
  16. data/lib/scss_lint/linter/border_zero.rb +2 -2
  17. data/lib/scss_lint/linter/color_variable.rb +1 -1
  18. data/lib/scss_lint/linter/declaration_order.rb +10 -8
  19. data/lib/scss_lint/linter/duplicate_property.rb +2 -2
  20. data/lib/scss_lint/linter/empty_line_between_blocks.rb +3 -1
  21. data/lib/scss_lint/linter/final_newline.rb +3 -3
  22. data/lib/scss_lint/linter/indentation.rb +20 -20
  23. data/lib/scss_lint/linter/leading_zero.rb +2 -2
  24. data/lib/scss_lint/linter/mergeable_selector.rb +3 -4
  25. data/lib/scss_lint/linter/name_format.rb +2 -1
  26. data/lib/scss_lint/linter/nesting_depth.rb +1 -1
  27. data/lib/scss_lint/linter/property_sort_order.rb +11 -13
  28. data/lib/scss_lint/linter/selector_depth.rb +9 -8
  29. data/lib/scss_lint/linter/selector_format.rb +1 -1
  30. data/lib/scss_lint/linter/shorthand.rb +1 -1
  31. data/lib/scss_lint/linter/single_line_per_selector.rb +3 -1
  32. data/lib/scss_lint/linter/space_around_operator.rb +4 -2
  33. data/lib/scss_lint/linter/space_before_brace.rb +8 -8
  34. data/lib/scss_lint/linter/space_between_parens.rb +11 -11
  35. data/lib/scss_lint/linter/string_quotes.rb +9 -10
  36. data/lib/scss_lint/linter/trailing_zero.rb +1 -1
  37. data/lib/scss_lint/linter/transition_all.rb +1 -1
  38. data/lib/scss_lint/linter/unnecessary_mantissa.rb +3 -1
  39. data/lib/scss_lint/linter/unnecessary_parent_reference.rb +9 -2
  40. data/lib/scss_lint/linter/url_quotes.rb +4 -2
  41. data/lib/scss_lint/linter/variable_for_property.rb +1 -1
  42. data/lib/scss_lint/linter/vendor_prefix.rb +3 -3
  43. data/lib/scss_lint/linter/zero_unit.rb +3 -1
  44. data/lib/scss_lint/location.rb +1 -1
  45. data/lib/scss_lint/logger.rb +149 -0
  46. data/lib/scss_lint/options.rb +5 -1
  47. data/lib/scss_lint/rake_task.rb +10 -3
  48. data/lib/scss_lint/reporter.rb +4 -2
  49. data/lib/scss_lint/reporter/default_reporter.rb +3 -3
  50. data/lib/scss_lint/version.rb +3 -1
  51. data/spec/scss_lint/cli_spec.rb +66 -14
  52. data/spec/scss_lint/config_spec.rb +25 -5
  53. data/spec/scss_lint/linter/name_format_spec.rb +10 -0
  54. data/spec/scss_lint/linter/property_sort_order_spec.rb +28 -0
  55. data/spec/scss_lint/linter/unnecessary_parent_reference_spec.rb +10 -0
  56. data/spec/scss_lint/linter/variable_for_property_spec.rb +10 -0
  57. data/spec/scss_lint/logger_spec.rb +27 -0
  58. data/spec/scss_lint/options_spec.rb +18 -0
  59. data/spec/scss_lint/plugins/linter_dir_spec.rb +1 -1
  60. data/spec/scss_lint/reporter/clean_files_reporter_spec.rb +1 -1
  61. data/spec/scss_lint/reporter/config_reporter_spec.rb +1 -1
  62. data/spec/scss_lint/reporter/default_reporter_spec.rb +2 -1
  63. data/spec/scss_lint/reporter/files_reporter_spec.rb +1 -1
  64. data/spec/scss_lint/reporter/json_reporter_spec.rb +5 -5
  65. metadata +10 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e6187740250928694fb6a0deda93e0d3c38019a
4
- data.tar.gz: 5e779311f77ca29e8f2e1ddbafc1ad4c41650351
3
+ metadata.gz: 7a86d234a01ef87070b4fd7889111970e80def37
4
+ data.tar.gz: 2a461b84b74cc8728e64dc9366a67be4df308c10
5
5
  SHA512:
6
- metadata.gz: fe7b37e6ad330637fe0a6266fd5695fa2c8ae84e47426b0f77b28c599694e1cc81df334308380f447ccffa13a668264e665ef2936e12e3741f27c73b68d1f350
7
- data.tar.gz: b9773b48c133d3c02e91446a150b595a95941c52301957548a13a6e9e3d1f21148c63dff87d0773e9d72279af13127818c1f105dd0261efa57f344176847aa64
6
+ metadata.gz: a0badb74dbb5f26d727b38dd71319b8429c35f23602bb73c30a7d197100a4d16f61df75604a4b19992aa1237d1d226b5941e786efe7c459bbde18f4a71b36a76
7
+ data.tar.gz: 4059abd1bac9430f32af1f7b125fe22a5a3ae24b146e026283648a4bfb7623453df0eb111cc9659b6f6e1866e3248425574617cef14662f5e1e32732851dc962
data/bin/scss-lint CHANGED
@@ -3,4 +3,5 @@
3
3
  require 'scss_lint'
4
4
  require 'scss_lint/cli'
5
5
 
6
- exit SCSSLint::CLI.new.run(ARGV)
6
+ logger = SCSSLint::Logger.new(STDOUT)
7
+ exit SCSSLint::CLI.new(logger).run(ARGV)
data/config/default.yml CHANGED
@@ -7,6 +7,9 @@ plugin_directories: ['.scss-linters']
7
7
  # installed)
8
8
  plugin_gems: []
9
9
 
10
+ # Default severity of all linters.
11
+ severity: warning
12
+
10
13
  linters:
11
14
  BangFormat:
12
15
  enabled: true
data/data/properties.txt CHANGED
@@ -17,6 +17,7 @@ animation-timing-function
17
17
  app-region
18
18
  appearance
19
19
  aspect-ratio
20
+ backdrop-filter
20
21
  backface-visibility
21
22
  background
22
23
  background-attachment
@@ -34,6 +35,7 @@ background-repeat-x
34
35
  background-repeat-y
35
36
  background-size
36
37
  baseline-shift
38
+ block-size
37
39
  bookmark-label
38
40
  bookmark-level
39
41
  bookmark-target
@@ -46,6 +48,14 @@ border-before
46
48
  border-before-color
47
49
  border-before-style
48
50
  border-before-width
51
+ border-block-end
52
+ border-block-end-color
53
+ border-block-end-style
54
+ border-block-end-width
55
+ border-block-start
56
+ border-block-start-color
57
+ border-block-start-style
58
+ border-block-start-width
49
59
  border-bottom
50
60
  border-bottom-color
51
61
  border-bottom-left-radius
@@ -66,6 +76,14 @@ border-image-repeat
66
76
  border-image-slice
67
77
  border-image-source
68
78
  border-image-width
79
+ border-inline-end
80
+ border-inline-end-color
81
+ border-inline-end-style
82
+ border-inline-end-width
83
+ border-inline-start
84
+ border-inline-start-color
85
+ border-inline-start-style
86
+ border-inline-start-width
69
87
  border-left
70
88
  border-left-color
71
89
  border-left-style
@@ -213,6 +231,7 @@ image-orientation
213
231
  image-rendering
214
232
  image-resolution
215
233
  inline-box-align
234
+ inline-size
216
235
  isolation
217
236
  justify-content
218
237
  justify-self
@@ -243,10 +262,14 @@ margin-after
243
262
  margin-after-collapse
244
263
  margin-before
245
264
  margin-before-collapse
265
+ margin-block-end
266
+ margin-block-start
246
267
  margin-bottom
247
268
  margin-bottom-collapse
248
269
  margin-collapse
249
270
  margin-end
271
+ margin-inline-end
272
+ margin-inline-start
250
273
  margin-left
251
274
  margin-right
252
275
  margin-start
@@ -287,12 +310,16 @@ mask-repeat-y
287
310
  mask-size
288
311
  mask-source-type
289
312
  mask-type
313
+ max-block-size
290
314
  max-height
315
+ max-inline-size
291
316
  max-logical-height
292
317
  max-logical-width
293
318
  max-width
294
319
  max-zoom
320
+ min-block-size
295
321
  min-height
322
+ min-inline-size
296
323
  min-logical-height
297
324
  min-logical-width
298
325
  min-width
@@ -306,6 +333,10 @@ nav-right
306
333
  nav-up
307
334
  object-fit
308
335
  object-position
336
+ offset-block-end
337
+ offset-block-start
338
+ offset-inline-end
339
+ offset-inline-start
309
340
  opacity
310
341
  order
311
342
  orientation
@@ -323,8 +354,12 @@ overflow-y
323
354
  padding
324
355
  padding-after
325
356
  padding-before
357
+ padding-block-end
358
+ padding-block-start
326
359
  padding-bottom
327
360
  padding-end
361
+ padding-inline-end
362
+ padding-inline-start
328
363
  padding-left
329
364
  padding-right
330
365
  padding-start
@@ -55,7 +55,15 @@ column-count
55
55
  column-width
56
56
 
57
57
  transform
58
+ transform-box
59
+ transform-origin
60
+ transform-style
61
+
58
62
  transition
63
+ transition-delay
64
+ transition-duration
65
+ transition-property
66
+ transition-timing-function
59
67
 
60
68
  # Border
61
69
 
@@ -97,6 +105,7 @@ outline-width
97
105
  # Background
98
106
 
99
107
  background
108
+ background-attachment
100
109
  background-color
101
110
  background-image
102
111
  background-repeat
@@ -54,6 +54,7 @@
54
54
  -webkit-datetime-edit-text
55
55
  -webkit-datetime-edit-year-field
56
56
  -webkit-file-upload-button
57
+ -webkit-full-page-media
57
58
  -webkit-inner-spin-button
58
59
  -webkit-input-placeholder
59
60
  -webkit-keygen-select
@@ -73,7 +74,9 @@
73
74
  -webkit-scrollbar-track
74
75
  -webkit-scrollbar-track-piece
75
76
  -webkit-search-cancel-button
77
+ -webkit-search-decoration
76
78
  -webkit-search-results-button
79
+ -webkit-search-results-decoration
77
80
  -webkit-slider-runnable-track
78
81
  -webkit-slider-thumb
79
82
  -webkit-textfield-decoration-container
@@ -86,7 +89,9 @@
86
89
  after
87
90
  backdrop
88
91
  before
92
+ content
89
93
  first-letter
90
94
  first-line
91
95
  placeholder
92
96
  selection
97
+ shadow
data/lib/scss_lint.rb CHANGED
@@ -5,6 +5,7 @@ require 'scss_lint/engine'
5
5
  require 'scss_lint/location'
6
6
  require 'scss_lint/lint'
7
7
  require 'scss_lint/linter_registry'
8
+ require 'scss_lint/logger'
8
9
  require 'scss_lint/file_finder'
9
10
  require 'scss_lint/runner'
10
11
  require 'scss_lint/selector_visitor'
data/lib/scss_lint/cli.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'rainbow'
2
- require 'rainbow/ext/string'
3
1
  require 'scss_lint/options'
4
2
 
5
3
  module SCSSLint
@@ -20,7 +18,14 @@ module SCSSLint
20
18
  config: 78, # Configuration error
21
19
  no_files: 80, # No files matched by specified glob patterns
22
20
  plugin: 82, # Plugin loading error
23
- }
21
+ }.freeze
22
+
23
+ # Create a CLI that outputs to the specified logger.
24
+ #
25
+ # @param logger [SCSSLint::Logger]
26
+ def initialize(logger)
27
+ @log = logger
28
+ end
24
29
 
25
30
  def run(args)
26
31
  options = SCSSLint::Options.new.parse(args)
@@ -31,7 +36,10 @@ module SCSSLint
31
36
 
32
37
  private
33
38
 
39
+ attr_reader :log
40
+
34
41
  def act_on_options(options)
42
+ log.color_enabled = options.fetch(:color, log.tty?)
35
43
  load_required_paths(options)
36
44
  load_reporters(options)
37
45
 
@@ -77,40 +85,47 @@ module SCSSLint
77
85
  def handle_runtime_exception(exception, options) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/LineLength, Metrics/MethodLength
78
86
  case exception
79
87
  when SCSSLint::Exceptions::InvalidCLIOption
80
- puts exception.message
81
- puts 'Run `scss-lint --help` for usage documentation'
88
+ log.error exception.message
89
+ log.info 'Run `scss-lint --help` for usage documentation'
82
90
  halt :usage
83
91
  when SCSSLint::Exceptions::InvalidConfiguration
84
- puts exception.message
92
+ log.error exception.message
85
93
  halt :config
86
94
  when SCSSLint::Exceptions::RequiredLibraryMissingError
87
- puts exception.message
95
+ log.error exception.message
88
96
  halt :unavailable
89
97
  when SCSSLint::Exceptions::NoFilesError
90
- puts exception.message
98
+ log.error exception.message
91
99
  halt :no_files
92
100
  when SCSSLint::Exceptions::PluginGemLoadError
93
- puts exception.message
101
+ log.error exception.message
94
102
  halt :plugin
95
103
  when Errno::ENOENT
96
- puts exception.message
104
+ log.error exception.message
97
105
  halt :no_input
98
106
  when NoSuchLinter
99
- puts exception.message
107
+ log.error exception.message
100
108
  halt :usage
101
109
  else
102
110
  config_file = relevant_configuration_file(options) if options
103
111
 
104
- puts exception.message
105
- puts exception.backtrace
106
- puts 'Report this bug at '.color(:yellow) + BUG_REPORT_URL.color(:cyan)
107
- puts
108
- puts 'To help fix this issue, please include:'.color(:green)
109
- puts '- The above stack trace'
110
- puts "- SCSS-Lint version: #{SCSSLint::VERSION.color(:cyan)}"
111
- puts "- Sass version: #{Gem.loaded_specs['sass'].version.to_s.color(:cyan)}"
112
- puts "- Ruby version: #{RUBY_VERSION.color(:cyan)}"
113
- puts "- Contents of #{File.expand_path(config_file).color(:cyan)}" if config_file
112
+ log.bold_error exception.message
113
+ log.error exception.backtrace.join("\n")
114
+ log.warning 'Report this bug at ', false
115
+ log.info BUG_REPORT_URL
116
+ log.newline
117
+ log.success 'To help fix this issue, please include:'
118
+ log.log '- The above stack trace'
119
+ log.log '- SCSS-Lint version: ', false
120
+ log.info SCSSLint::VERSION
121
+ log.log '- Sass version: ', false
122
+ log.info Gem.loaded_specs['sass'].version.to_s
123
+ log.log '- Ruby version: ', false
124
+ log.info RUBY_VERSION
125
+ if config_file
126
+ log.log '- Contents of ', false
127
+ log.info File.expand_path(config_file)
128
+ end
114
129
  halt :software
115
130
  end
116
131
  end
@@ -167,9 +182,14 @@ module SCSSLint
167
182
  def report_lints(options, lints, files)
168
183
  sorted_lints = lints.sort_by { |l| [l.filename, l.location] }
169
184
  options.fetch(:reporters).each do |reporter, output|
170
- results = reporter.new(sorted_lints, files).report_lints
171
- io = (output == :stdout ? $stdout : File.new(output, 'w+'))
172
- io.print results if results
185
+ results = reporter.new(sorted_lints, files, log).report_lints
186
+ next unless results
187
+
188
+ if output == :stdout
189
+ log.log results
190
+ else
191
+ File.new(output, 'w+').print results
192
+ end
173
193
  end
174
194
  end
175
195
 
@@ -195,26 +215,26 @@ module SCSSLint
195
215
  end
196
216
 
197
217
  def print_formatters
198
- puts 'Installed formatters:'
218
+ log.log 'Installed formatters:'
199
219
 
200
220
  reporter_names = SCSSLint::Reporter.descendants.map do |reporter|
201
221
  reporter.name.split('::').last.split('Reporter').first
202
222
  end
203
223
 
204
224
  reporter_names.sort.each do |reporter_name|
205
- puts " - #{reporter_name}"
225
+ log.log " - #{reporter_name}"
206
226
  end
207
227
 
208
228
  halt
209
229
  end
210
230
 
211
231
  def print_linters
212
- puts 'Installed linters:'
232
+ log.log 'Installed linters:'
213
233
 
214
234
  linter_names = LinterRegistry.linters.map(&:simple_name)
215
235
 
216
236
  linter_names.sort.each do |linter_name|
217
- puts " - #{linter_name}"
237
+ log.log " - #{linter_name}"
218
238
  end
219
239
 
220
240
  halt
@@ -222,13 +242,13 @@ module SCSSLint
222
242
 
223
243
  # @param options [Hash]
224
244
  def print_help(options)
225
- puts options[:help]
245
+ log.log options[:help]
226
246
  halt :ok
227
247
  end
228
248
 
229
249
  # @param options [Hash]
230
250
  def print_version
231
- puts "scss-lint #{SCSSLint::VERSION}"
251
+ log.log "scss-lint #{SCSSLint::VERSION}"
232
252
  halt :ok
233
253
  end
234
254
 
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
 
3
5
  module SCSSLint
4
6
  # Loads and manages application configuration.
5
7
  class Config
6
- FILE_NAME = '.scss-lint.yml'
8
+ FILE_NAME = '.scss-lint.yml'.freeze
7
9
  DEFAULT_FILE = File.join(SCSS_LINT_HOME, 'config', 'default.yml')
8
10
 
9
11
  attr_reader :options, :warnings
@@ -71,6 +73,7 @@ module SCSSLint
71
73
  options = merge_wildcard_linter_options(options)
72
74
  options = ensure_exclude_paths_are_absolute(options, file)
73
75
  options = ensure_linter_exclude_paths_are_absolute(options, file)
76
+ ensure_severities_are_valid(options)
74
77
  options
75
78
  end
76
79
 
@@ -149,6 +152,27 @@ module SCSSLint
149
152
  options
150
153
  end
151
154
 
155
+ def ensure_severities_are_valid(options)
156
+ unless severity_is_valid?(options)
157
+ raise SCSSLint::Exceptions::InvalidConfiguration,
158
+ 'Global `severity` configuration option must be one of [' \
159
+ "#{SEVERITIES.join(' | ')}]"
160
+ end
161
+
162
+ options['linters'].each do |linter_name, linter_options|
163
+ next if severity_is_valid?(linter_options)
164
+
165
+ raise SCSSLint::Exceptions::InvalidConfiguration,
166
+ "#{linter_name} `severity` configuration option must be one " \
167
+ "of [#{SEVERITIES.join(' | ')}]"
168
+ end
169
+ end
170
+
171
+ SEVERITIES = %w[error warning].freeze
172
+ def severity_is_valid?(options)
173
+ SEVERITIES.include?(options.fetch('severity', 'warning'))
174
+ end
175
+
152
176
  def path_relative_to_config(relative_include_path, base_config_path)
153
177
  if relative_include_path.start_with?('/')
154
178
  relative_include_path
@@ -195,7 +219,6 @@ module SCSSLint
195
219
  def ==(other)
196
220
  super || @options == other.options
197
221
  end
198
- alias_method :eql?, :==
199
222
 
200
223
  # Extend this {Config} with another configuration.
201
224
  #
@@ -246,7 +269,9 @@ module SCSSLint
246
269
  end
247
270
 
248
271
  def linter_options(linter)
249
- @options['linters'].fetch(self.class.linter_name(linter), {})
272
+ { 'severity' => @options['severity'] }.merge(
273
+ @options['linters'].fetch(self.class.linter_name(linter), {})
274
+ )
250
275
  end
251
276
 
252
277
  def excluded_file?(file_path)
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Global application constants.
2
4
  module SCSSLint
3
- SCSS_LINT_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
4
- SCSS_LINT_DATA = File.join(SCSS_LINT_HOME, 'data')
5
+ SCSS_LINT_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..')).freeze
6
+ SCSS_LINT_DATA = File.join(SCSS_LINT_HOME, 'data').freeze
5
7
 
6
- REPO_URL = 'https://github.com/brigade/scss-lint'
7
- BUG_REPORT_URL = "#{REPO_URL}/issues"
8
+ REPO_URL = 'https://github.com/brigade/scss-lint'.freeze
9
+ BUG_REPORT_URL = "#{REPO_URL}/issues".freeze
8
10
  end
@@ -96,13 +96,14 @@ module SCSSLint
96
96
 
97
97
  comment_node = command[:node]
98
98
  start_line = command[:line]
99
- if comment_node.class.node_name == :rule
100
- end_line = start_line
101
- elsif node.class.node_name == :root
102
- end_line = @linter.engine.lines.length
103
- else
104
- end_line = end_line(node)
105
- end
99
+ end_line =
100
+ if comment_node.class.node_name == :rule
101
+ start_line
102
+ elsif node.class.node_name == :root
103
+ @linter.engine.lines.length
104
+ else
105
+ end_line(node)
106
+ end
106
107
 
107
108
  @disabled_lines.merge(start_line..end_line)
108
109
  end