haml_lint 0.18.3 → 0.18.4

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: 4615a213ff3d87b4d05a6e7455f253563862506b
4
- data.tar.gz: c7c3c9355d79429eab84513b8fd41c134c31f69f
3
+ metadata.gz: a141a32ca4f42038548109417fc4ce7e48cb04e5
4
+ data.tar.gz: 3cd8985abe66dd3164e0f61a76f55abddf2b3f54
5
5
  SHA512:
6
- metadata.gz: 05e2289d369fcd2709a4f99d8ddbb3fdef1c34016c65df8e239ab50e7c107b9c0947654615f2bab1d673b89e1f1f6d079a50e423cf88d3813ca70677964f2abd
7
- data.tar.gz: b4c4d6034bc65f380dbd84eb5a28072ecfccb379b62442c4d55a7675a9b434576c23410f208db58e71a3c9a3599ab57e139b9598833aee2eb69b722e1b777dfb
6
+ metadata.gz: d4d2b851b17f04696979385e41f8a8b9c699cbe7db29bd497e130d64f465c54cc29945126a53eec6d4dc5e99f5b96e89bf623b597ae02294a5af62d0b1021827
7
+ data.tar.gz: 389f9c938a65d66368de138aa56cc1a63eb26e70da3e97463f0f3a890aa9a59e3964e51dfc80d3c032ca5130b76541b2ee5247078841df15251c5015d61aa7b9
@@ -9,18 +9,20 @@ module HamlLint
9
9
  '#' => :id,
10
10
  }.freeze
11
11
 
12
+ MSG = '%s should be listed before %s (%s should precede %s)'.freeze
13
+
12
14
  def visit_tag(node)
13
15
  # Convert ".class#id" into [.class, #id] (preserving order)
14
16
  components = node.static_attributes_source.scan(/[.#][^.#]+/)
15
17
 
16
18
  first, second = attribute_prefix_order
17
19
 
18
- (1...components.count).each do |index|
19
- next unless components[index].start_with?(first) &&
20
- components[index - 1].start_with?(second)
20
+ components.each_cons(2) do |current_val, next_val|
21
+ next unless next_val.start_with?(first) &&
22
+ current_val.start_with?(second)
21
23
 
22
- record_lint(node, 'Classes should be listed before IDs '\
23
- "(#{components[index]} should precede #{components[index - 1]})")
24
+ failure_message = format(MSG, *(attribute_type_order + [next_val, current_val]))
25
+ record_lint(node, failure_message)
24
26
  break
25
27
  end
26
28
  end
@@ -28,13 +30,23 @@ module HamlLint
28
30
  private
29
31
 
30
32
  def attribute_prefix_order
31
- enforced_style = config.fetch('EnforcedStyle', 'class')
32
- case enforced_style
33
- when 'id'
34
- ['#', '.']
35
- else
36
- ['.', '#']
37
- end
33
+ default = %w[. #]
34
+ default.reverse! if ids_first?
35
+ default
36
+ end
37
+
38
+ def attribute_type_order
39
+ default = %w[Classes IDs]
40
+ default.reverse! if ids_first?
41
+ default
42
+ end
43
+
44
+ def enforced_style
45
+ config.fetch('EnforcedStyle', 'class')
46
+ end
47
+
48
+ def ids_first?
49
+ enforced_style == 'id'
38
50
  end
39
51
  end
40
52
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.18.3'.freeze
5
+ VERSION = '0.18.4'.freeze
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.3
4
+ version: 0.18.4
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: 2016-10-25 00:00:00.000000000 Z
12
+ date: 2016-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml