scss-lint 0.36.1 → 0.37.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3a2b1ee0f782f66cb555280a0b7be06a2a4ff5f
4
- data.tar.gz: 9b92adbf68a21311695432d0357ea6805b632be1
3
+ metadata.gz: 4643e39c19004b8de6167f9ad88d9aa9458c7152
4
+ data.tar.gz: 0500e517334acc90a14da0cf0f51b8dcd34f91b9
5
5
  SHA512:
6
- metadata.gz: 01b85e9caee70645b1cc8da766b24cf0a5db2bca10c0d5fe1fd004492c27605a8cf08b194298dc20e5f0e1d6f56376fc68f4a4889df62e90295f7be36e88e1ec
7
- data.tar.gz: 96aafd6d3d5a8fb34d99aebbf0f15ffe8216f482e785ff157266f9d1fa3dcff4014b53ef43aee95c11881d21a93cd047c6e3f767206c64e1ef62150c5b751fe5
6
+ metadata.gz: 5ca899f683ea5d88e5dbfb79bbeaccb8a41491870d8ead470495bd06b5e9c01a801f580b5b4a0df34ee1e43f31c397f39f5acadd9047cb5f59a8d9c2e8d5292b
7
+ data.tar.gz: 90783696031b8c29422d95dd35676bb9ce27addf33be7cf1e163509ab40bb60952b7ff83ec52b2d0b122825eaeeff0fcb01c4cf16205981bec88a6bd33df0116
@@ -84,7 +84,7 @@ linters:
84
84
  NameFormat:
85
85
  enabled: true
86
86
  allow_leading_underscore: true
87
- convention: hyphenated_lowercase # or 'BEM', or a regex pattern
87
+ convention: hyphenated_lowercase # or 'camel_case', or 'snake_case', or a regex pattern
88
88
 
89
89
  NestingDepth:
90
90
  enabled: true
@@ -133,7 +133,7 @@ linters:
133
133
 
134
134
  SelectorFormat:
135
135
  enabled: true
136
- convention: hyphenated_lowercase # or 'BEM', or 'hyphenated_BEM', or 'snake_case', or 'camel_case', or a regex pattern
136
+ convention: hyphenated_lowercase # or 'strict_BEM', or 'hyphenated_BEM', or 'snake_case', or 'camel_case', or a regex pattern
137
137
 
138
138
  Shorthand:
139
139
  enabled: true
@@ -1,6 +1,6 @@
1
1
  module SCSSLint
2
- # Checks that the declared names of functions, mixins, and variables are all
3
- # lowercase and use hyphens instead of underscores.
2
+ # Checks the format of declared names of functions, mixins, variables, and
3
+ # placeholders.
4
4
  class Linter::NameFormat < Linter
5
5
  include LinterRegistry
6
6
 
@@ -47,10 +47,10 @@ module SCSSLint
47
47
 
48
48
  def check_name(node, node_type, node_text = node.name)
49
49
  node_text = trim_underscore_prefix(node_text)
50
- return unless violation = violated_convention(node_text)
50
+ return unless violation = violated_convention(node_text, node_type)
51
51
 
52
- add_lint(node, "Name of #{node_type} `#{node_text}` should be " \
53
- "written #{violation[:explanation]}")
52
+ add_lint(node,
53
+ "Name of #{node_type} `#{node_text}` #{violation[:explanation]}")
54
54
  end
55
55
 
56
56
  # Removes underscore prefix from name if leading underscores are allowed.
@@ -70,26 +70,48 @@ module SCSSLint
70
70
  end
71
71
 
72
72
  CONVENTIONS = {
73
+ 'camel_case' => {
74
+ explanation: 'should be written in camelCase format',
75
+ validator: ->(name) { name =~ /^[a-z][a-zA-Z0-9]*$/ },
76
+ },
77
+ 'snake_case' => {
78
+ explanation: 'should be written in snake_case',
79
+ validator: ->(name) { name !~ /[^_a-z0-9]/ },
80
+ },
73
81
  'hyphenated_lowercase' => {
74
- explanation: 'in all lowercase letters with hyphens instead of underscores',
82
+ explanation: 'should be written in all lowercase letters with hyphens ' \
83
+ 'instead of underscores',
75
84
  validator: ->(name) { name !~ /[_A-Z]/ },
76
85
  },
77
- 'BEM' => {
78
- explanation: 'in BEM (Block Element Modifier) format',
79
- validator: ->(name) { name !~ /[A-Z]|-{3}|_{3}|[^_]_[^_]/ },
80
- },
81
86
  }
82
87
 
83
- # Checks the given name and returns the violated convention if it failed.
84
- def violated_convention(name_string)
85
- convention_name = config['convention'] || 'hyphenated_lowercase'
88
+ def violated_convention(name_string, type)
89
+ convention_name = convention_name(type)
86
90
 
87
- convention = CONVENTIONS[convention_name] || {
88
- explanation: "must match regex /#{convention_name}/",
91
+ existing_convention = CONVENTIONS[convention_name]
92
+
93
+ convention = (existing_convention || {
89
94
  validator: ->(name) { name =~ /#{convention_name}/ }
90
- }
95
+ }).merge(
96
+ explanation: convention_explanation(type), # Allow explanation to be customized
97
+ )
91
98
 
92
99
  convention unless convention[:validator].call(name_string)
93
100
  end
101
+
102
+ def convention_name(type)
103
+ config["#{type}_convention"] ||
104
+ config['convention'] ||
105
+ 'hyphenated_lowercase'
106
+ end
107
+
108
+ def convention_explanation(type)
109
+ existing_convention = CONVENTIONS[convention_name(type)]
110
+
111
+ config["#{type}_convention_explanation"] ||
112
+ config['convention_explanation'] ||
113
+ (existing_convention && existing_convention[:explanation]) ||
114
+ "should match regex /#{convention_name(type)}/"
115
+ end
94
116
  end
95
117
  end
@@ -57,7 +57,7 @@ module SCSSLint
57
57
  explanation: 'should be written in hyphenated BEM (Block Element Modifier) format',
58
58
  validator: ->(name) { name !~ /[A-Z]|-{3}|_{3}|[^_]_[^_]/ },
59
59
  },
60
- 'BEM' => {
60
+ 'strict_BEM' => {
61
61
  explanation: 'should be written in BEM (Block Element Modifier) format',
62
62
  validator: lambda do |name|
63
63
  name =~ /
@@ -71,16 +71,32 @@ module SCSSLint
71
71
 
72
72
  # Checks the given name and returns the violated convention if it failed.
73
73
  def violated_convention(name_string, type)
74
- convention_name = config["#{type}_convention"] ||
75
- config['convention'] ||
76
- 'hyphenated_lowercase'
74
+ convention_name = convention_name(type)
77
75
 
78
- convention = CONVENTIONS[convention_name] || {
79
- explanation: "should match regex /#{convention_name}/",
76
+ existing_convention = CONVENTIONS[convention_name]
77
+
78
+ convention = (existing_convention || {
80
79
  validator: ->(name) { name =~ /#{convention_name}/ }
81
- }
80
+ }).merge(
81
+ explanation: convention_explanation(type), # Allow explanation to be customized
82
+ )
82
83
 
83
84
  convention unless convention[:validator].call(name_string)
84
85
  end
86
+
87
+ def convention_name(type)
88
+ config["#{type}_convention"] ||
89
+ config['convention'] ||
90
+ 'hyphenated_lowercase'
91
+ end
92
+
93
+ def convention_explanation(type)
94
+ existing_convention = CONVENTIONS[convention_name(type)]
95
+
96
+ config["#{type}_convention_explanation"] ||
97
+ config['convention_explanation'] ||
98
+ (existing_convention && existing_convention[:explanation]) ||
99
+ "should match regex /#{convention_name(type)}/"
100
+ end
85
101
  end
86
102
  end
@@ -1,4 +1,4 @@
1
1
  # Defines the gem version.
2
2
  module SCSSLint
3
- VERSION = '0.36.1'
3
+ VERSION = '0.37.0'
4
4
  end
@@ -194,75 +194,87 @@ describe SCSSLint::Linter::NameFormat do
194
194
  end
195
195
  end
196
196
 
197
- context 'when the BEM convention is specified' do
198
- let(:linter_config) { { 'convention' => 'BEM' } }
197
+ context 'when the camel_case convention is specified' do
198
+ let(:linter_config) { { 'convention' => 'camel_case' } }
199
199
 
200
- context 'when a name contains no underscores or hyphens' do
201
- let(:scss) { '@extend %block;' }
200
+ context 'when a name contains all lowercase letters' do
201
+ let(:scss) { '$variable: 1;' }
202
202
 
203
203
  it { should_not report_lint }
204
204
  end
205
205
 
206
- context 'when a name contains a single underscore' do
207
- let(:scss) { '@extend %block_thing;' }
206
+ context 'when a name contains all lowercase letters and underscores' do
207
+ let(:scss) { '$my_variable: 1;' }
208
208
 
209
209
  it { should report_lint }
210
210
  end
211
211
 
212
- context 'when a name contains a single hyphen' do
213
- let(:scss) { '@extend %block-thing;' }
212
+ context 'when a name contains all lowercase letters and hyphens' do
213
+ let(:scss) { '$my-variable: 1;' }
214
214
 
215
- it { should_not report_lint }
215
+ it { should report_lint }
216
216
  end
217
217
 
218
- context 'when a name contains a double hyphen' do
219
- let(:scss) { '@extend %block--thing;' }
218
+ context 'when a name is written in camelCase' do
219
+ let(:scss) { '$myVariable: 1;' }
220
220
 
221
221
  it { should_not report_lint }
222
222
  end
223
+ end
223
224
 
224
- context 'when a name contains a double underscore' do
225
- let(:scss) { '@extend %block__thing;' }
225
+ context 'when the snake_case convention is specified' do
226
+ let(:linter_config) { { 'convention' => 'snake_case' } }
227
+
228
+ context 'when a name contains all lowercase letters' do
229
+ let(:scss) { '$variable: 1;' }
226
230
 
227
231
  it { should_not report_lint }
228
232
  end
229
233
 
230
- context 'when a name contains a double underscore and double hyphen' do
231
- let(:scss) { '@extend %block--thing__word;' }
234
+ context 'when a name contains all lowercase letters and underscores' do
235
+ let(:scss) { '$my_variable: 1;' }
232
236
 
233
237
  it { should_not report_lint }
234
238
  end
235
- end
236
239
 
237
- context 'when a regexp convention is specified' do
238
- let(:linter_config) { { 'convention' => '^[a-v_-]+$' } }
240
+ context 'when a name contains all lowercase letters and hyphens' do
241
+ let(:scss) { '$my-variable: 1;' }
239
242
 
240
- context 'when a name contains no underscores or hyphens' do
241
- let(:scss) { '@extend %block;' }
242
-
243
- it { should_not report_lint }
243
+ it { should report_lint }
244
244
  end
245
245
 
246
- context 'when a name contains a single underscore' do
247
- let(:scss) { '@extend %block_thing;' }
246
+ context 'when a name contains any uppercase letters' do
247
+ let(:scss) { '$myVariable: 1;' }
248
248
 
249
- it { should_not report_lint }
249
+ it { should report_lint }
250
+ end
251
+ end
252
+
253
+ context 'when type-specific convention is defined with a global convention' do
254
+ let(:linter_config) do
255
+ { 'convention' => 'camel_case', 'variable_convention' => 'snake_case' }
250
256
  end
251
257
 
252
- context 'when a name contains a single hyphen' do
253
- let(:scss) { '@extend %block-thing;' }
258
+ context 'when specific type satisfies the type-specific convention' do
259
+ let(:scss) { '$my_variable: 1;' }
254
260
 
255
261
  it { should_not report_lint }
256
262
  end
257
263
 
258
- context 'when a name contains a uppercase character' do
259
- let(:scss) { '@extend Block-thing;' }
264
+ context 'when specific type does not satisfy the type-specific convention' do
265
+ let(:scss) { '$myVariable: 1;' }
260
266
 
261
267
  it { should report_lint }
262
268
  end
263
269
 
264
- context 'when a name contains an unallowed character' do
265
- let(:scss) { '@extend zoo;' }
270
+ context 'when other type satisfies the global convention' do
271
+ let(:scss) { '@function myFunction() {}' }
272
+
273
+ it { should_not report_lint }
274
+ end
275
+
276
+ context 'when other type does not satisfy the global convention' do
277
+ let(:scss) { '@function my_function() {}' }
266
278
 
267
279
  it { should report_lint }
268
280
  end
@@ -454,8 +454,8 @@ describe SCSSLint::Linter::SelectorFormat do
454
454
  end
455
455
  end
456
456
 
457
- context 'when the BEM convention is specified' do
458
- let(:linter_config) { { 'convention' => 'BEM' } }
457
+ context 'when the strict_BEM convention is specified' do
458
+ let(:linter_config) { { 'convention' => 'strict_BEM' } }
459
459
 
460
460
  context 'when a name contains no underscores or hyphens' do
461
461
  let(:scss) { '.block {}' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scss-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.36.1
4
+ version: 0.37.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brigade Engineering
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-08 00:00:00.000000000 Z
12
+ date: 2015-04-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
@@ -256,14 +256,18 @@ signing_key:
256
256
  specification_version: 4
257
257
  summary: SCSS lint tool
258
258
  test_files:
259
+ - spec/scss_lint/cli_spec.rb
259
260
  - spec/scss_lint/config_spec.rb
260
261
  - spec/scss_lint/engine_spec.rb
262
+ - spec/scss_lint/file_finder_spec.rb
261
263
  - spec/scss_lint/linter/bang_format_spec.rb
262
264
  - spec/scss_lint/linter/border_zero_spec.rb
263
265
  - spec/scss_lint/linter/color_keyword_spec.rb
266
+ - spec/scss_lint/linter/color_variable_spec.rb
264
267
  - spec/scss_lint/linter/comment_spec.rb
265
268
  - spec/scss_lint/linter/compass/property_with_mixin_spec.rb
266
269
  - spec/scss_lint/linter/debug_statement_spec.rb
270
+ - spec/scss_lint/linter/declaration_order_spec.rb
267
271
  - spec/scss_lint/linter/duplicate_property_spec.rb
268
272
  - spec/scss_lint/linter/else_placement_spec.rb
269
273
  - spec/scss_lint/linter/empty_line_between_blocks_spec.rb
@@ -284,6 +288,7 @@ test_files:
284
288
  - spec/scss_lint/linter/property_count_spec.rb
285
289
  - spec/scss_lint/linter/property_sort_order_spec.rb
286
290
  - spec/scss_lint/linter/property_spelling_spec.rb
291
+ - spec/scss_lint/linter/property_units_spec.rb
287
292
  - spec/scss_lint/linter/qualifying_element_spec.rb
288
293
  - spec/scss_lint/linter/selector_depth_spec.rb
289
294
  - spec/scss_lint/linter/selector_format_spec.rb
@@ -305,9 +310,6 @@ test_files:
305
310
  - spec/scss_lint/linter/variable_for_property_spec.rb
306
311
  - spec/scss_lint/linter/vendor_prefix_spec.rb
307
312
  - spec/scss_lint/linter/zero_unit_spec.rb
308
- - spec/scss_lint/linter/color_variable_spec.rb
309
- - spec/scss_lint/linter/declaration_order_spec.rb
310
- - spec/scss_lint/linter/property_units_spec.rb
311
313
  - spec/scss_lint/linter_registry_spec.rb
312
314
  - spec/scss_lint/linter_spec.rb
313
315
  - spec/scss_lint/location_spec.rb
@@ -319,10 +321,8 @@ test_files:
319
321
  - spec/scss_lint/reporter/json_reporter_spec.rb
320
322
  - spec/scss_lint/reporter/xml_reporter_spec.rb
321
323
  - spec/scss_lint/reporter_spec.rb
322
- - spec/scss_lint/selector_visitor_spec.rb
323
- - spec/scss_lint/file_finder_spec.rb
324
324
  - spec/scss_lint/runner_spec.rb
325
- - spec/scss_lint/cli_spec.rb
325
+ - spec/scss_lint/selector_visitor_spec.rb
326
326
  - spec/spec_helper.rb
327
327
  - spec/support/isolated_environment.rb
328
328
  - spec/support/matchers/report_lint.rb