haml_lint 0.24.0 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe12a287eaf253fd83053061ac62a26b908918e6
4
- data.tar.gz: cf8bae7a2e75dde6befbe09a9764fb223ea72583
3
+ metadata.gz: 2ec594ab38cde43b4bfc77c30d2d01cdaa8efcce
4
+ data.tar.gz: 91068f84316b31511721b023a677609085796314
5
5
  SHA512:
6
- metadata.gz: 55334bc83c7c8f377c78b290db34ba08a2939bd9179e06541d27f3919118d3942500c85a5028ad2dde31a868ac82c4bd49b7ebf6492ec14400ae0f8b213e72d5
7
- data.tar.gz: 84e178971e6068b40dd896f49efac863a244a8ed952b4d4d45d93872d6a2030a68134721c2cffbba94cffc5d3b11b88283b487c35a1d3907132eab86df44eb26
6
+ metadata.gz: 4d852491b8757d078d5285d18a54017d70589fc98cc4d68e30e6d73be239e704dcf5fd0575fd7756bbfb4807fa68abdfe4fb361636e712423ad4614b9964e8df
7
+ data.tar.gz: 775dc9d01056561a235508e7d4dee8af74fff6484424270796ecb2ab1fb2c0e17d61917d3ad6c2d8358b9688d88e84851e7e71678476d42f0ccad7c7e76f7d31
data/config/default.yml CHANGED
@@ -22,6 +22,7 @@ linters:
22
22
 
23
23
  ConsecutiveComments:
24
24
  enabled: true
25
+ max_consecutive: 1
25
26
 
26
27
  ConsecutiveSilentScripts:
27
28
  enabled: true
@@ -52,6 +53,9 @@ linters:
52
53
  character: space # or tab
53
54
  width: 2 # ignored if character == tab
54
55
 
56
+ InlineStyles:
57
+ enabled: true
58
+
55
59
  InstanceVariables:
56
60
  enabled: true
57
61
  file_types: partials
@@ -17,6 +17,7 @@ module HamlLint
17
17
  version = haml_version
18
18
  case version
19
19
  when '~> 4.0' then HamlLint::Adapter::Haml4
20
+ when '~> 4.1' then HamlLint::Adapter::Haml4
20
21
  when '~> 5.0' then HamlLint::Adapter::Haml5
21
22
  else fail HamlLint::Exceptions::UnknownHamlVersion, "Cannot handle Haml version: #{version}"
22
23
  end
@@ -16,7 +16,7 @@ module HamlLint
16
16
  class Linter::ClassAttributeWithStaticValue < Linter
17
17
  include LinterRegistry
18
18
 
19
- STATIC_TYPES = [:str, :sym].freeze
19
+ STATIC_TYPES = %i[str sym].freeze
20
20
 
21
21
  VALID_CLASS_REGEX = /^-?[_a-zA-Z]+[_a-zA-Z0-9-]*$/
22
22
 
@@ -11,6 +11,7 @@ module HamlLint
11
11
  HamlLint::Utils.for_consecutive_items(
12
12
  possible_group(node),
13
13
  COMMENT_DETECTOR,
14
+ config['max_consecutive'] + 1,
14
15
  ) do |group|
15
16
  group.each { |group_node| reported_nodes << group_node }
16
17
  record_lint(group.first,
@@ -0,0 +1,14 @@
1
+ module HamlLint
2
+ # Detects use of inline `style` attributes on any tag
3
+ class Linter::InlineStyles < Linter
4
+ include LinterRegistry
5
+
6
+ MESSAGE = 'Do not use inline style attributes'.freeze
7
+
8
+ def visit_tag(node)
9
+ if node.has_hash_attribute?(:style)
10
+ record_lint(node, MESSAGE)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -51,7 +51,7 @@ module HamlLint
51
51
  def extract_lints_from_offenses(offenses, source_map)
52
52
  dummy_node = Struct.new(:line)
53
53
 
54
- offenses.select { |offense| !Array(config['ignored_cops']).include?(offense.cop_name) }
54
+ offenses.reject { |offense| Array(config['ignored_cops']).include?(offense.cop_name) }
55
55
  .each do |offense|
56
56
  record_lint(dummy_node.new(source_map[offense.line]), offense.message)
57
57
  end
@@ -3,13 +3,15 @@ module HamlLint
3
3
  class Linter::TrailingWhitespace < Linter
4
4
  include LinterRegistry
5
5
 
6
+ DummyNode = Struct.new(:line)
7
+
6
8
  def visit_root(root)
7
9
  document.source_lines.each_with_index do |line, index|
8
10
  next unless line =~ /\s+$/
9
11
 
10
12
  node = root.node_for_line(index + 1)
11
13
  unless node.disabled?(self)
12
- record_lint node, 'Line contains trailing whitespace'
14
+ record_lint DummyNode.new(index + 1), 'Line contains trailing whitespace'
13
15
  end
14
16
  end
15
17
  end
@@ -33,7 +33,7 @@ module HamlLint
33
33
 
34
34
  def outputs_string_literal?(script_node)
35
35
  return unless tree = parse_ruby(script_node.script)
36
- [:str, :dstr].include?(tree.type) &&
36
+ %i[str dstr].include?(tree.type) &&
37
37
  !starts_with_reserved_character?(tree.children.first)
38
38
  rescue ::Parser::SyntaxError # rubocop:disable Lint/HandleExceptions
39
39
  # Gracefully ignore syntax errors, as that's managed by a different linter
@@ -21,7 +21,7 @@ module HamlLint
21
21
  end.parse!(args)
22
22
 
23
23
  # Any remaining arguments are assumed to be files
24
- @options[:files] = args.empty? ? ["."] : args
24
+ @options[:files] = args.empty? ? ['.'] : args
25
25
 
26
26
  @options
27
27
  rescue OptionParser::InvalidOption => ex
@@ -56,12 +56,12 @@ module HamlLint
56
56
  @options[:reporter] = load_reporter_class(reporter.capitalize)
57
57
  end
58
58
 
59
- parser.on('--fail-fast', 'Fail after the first file with lint above the fail level') do
59
+ parser.on('--fail-fast', 'Fail after the first file with lint at or above the fail level') do
60
60
  @options[:fail_fast] = true
61
61
  end
62
62
 
63
63
  parser.on('--fail-level fail_level', String,
64
- 'Specify which level you want the suite to fail') do |fail_level|
64
+ 'Specify which level (warning or error) you want the suite to fail') do |fail_level|
65
65
  @options[:fail_level] = HamlLint::Severity.new(fail_level.to_sym)
66
66
  end
67
67
  end
@@ -39,7 +39,7 @@ module HamlLint
39
39
  @reporter.display_report(self)
40
40
  end
41
41
 
42
- # Checks whether any lints were over the fail level
42
+ # Checks whether any lints were at or above the fail level
43
43
  #
44
44
  # @return [Boolean]
45
45
  def failed?
@@ -7,9 +7,20 @@ module HamlLint::Tree
7
7
  # different attribute setting syntaxes (`{...}`/`(...)`), converted into
8
8
  # Ruby code.
9
9
  #
10
+ # @note This has to be memoized because of a design decision in Haml 5. When
11
+ # calling `DynamicAttributes#to_literal`, they mutate the "old" parameter using
12
+ # `String#sub!` instead of returning a new string. This means that any subsequent
13
+ # calls can return a nil instead of a string for that attribute, which causes
14
+ # any subsequent calls to the method to raise an error.
15
+ #
10
16
  # @return [Array<String>]
11
17
  def dynamic_attributes_sources
12
- @value[:attributes_hashes]
18
+ @dynamic_attributes_sources ||=
19
+ if Gem::Version.new(Haml::VERSION) < Gem::Version.new('5')
20
+ @value[:attributes_hashes]
21
+ else
22
+ Array(@value[:dynamic_attributes].to_literal).reject(&:empty?)
23
+ end
13
24
  end
14
25
 
15
26
  # Returns whether this tag contains executable script (e.g. is followed by a
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.24.0'.freeze
5
+ VERSION = '0.25.0'.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.24.0
4
+ version: 0.25.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: 2017-03-28 00:00:00.000000000 Z
12
+ date: 2017-05-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
@@ -133,6 +133,7 @@ files:
133
133
  - lib/haml_lint/linter/id_names.rb
134
134
  - lib/haml_lint/linter/implicit_div.rb
135
135
  - lib/haml_lint/linter/indentation.rb
136
+ - lib/haml_lint/linter/inline_styles.rb
136
137
  - lib/haml_lint/linter/instance_variables.rb
137
138
  - lib/haml_lint/linter/leading_comment_space.rb
138
139
  - lib/haml_lint/linter/line_length.rb
@@ -203,9 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
204
  version: '0'
204
205
  requirements: []
205
206
  rubyforge_project:
206
- rubygems_version: 2.4.5.1
207
+ rubygems_version: 2.5.2
207
208
  signing_key:
208
209
  specification_version: 4
209
210
  summary: HAML lint tool
210
211
  test_files: []
211
- has_rdoc: