haml_lint 0.26.0 → 0.27.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: fd94eae8ee22841c46e2d3af6beb0a8b3083c305
4
- data.tar.gz: 209d59375ccc51443638795414ca08cbb15a9ce1
3
+ metadata.gz: 63d9c83c6270872c9610d48ba7991a6abfab6136
4
+ data.tar.gz: 4872ffed9f0136ef62050079f44afc0071991ae2
5
5
  SHA512:
6
- metadata.gz: 37f51cc96857c95b8e32eab1cdc8bd992f8264c371869e56ce8b3eb304e80f0a8c90a313b9ad4ca2f1c8879a4a7e713d23a7c8cba38e0752c4b4ee6c75112f5f
7
- data.tar.gz: affb71eddfa8eaf47096af284fa57c4d115072904e0c4b78934df1e0dc3eb4675a864b02b0d8343e0d80be6982456266c51c1a0dd12700dbd0619c629fc0bce8
6
+ metadata.gz: 22cd935ac273c2fbba890698ef0f472107fdbf65c33e6ba1cf7369ff58a31d73cf3380b14e5307669d3ac8bd7ee72a8d922afe64a15e30a0666a0d79e688282b
7
+ data.tar.gz: 119c20bece39c162f7e1c17c17dfcee007892003cb6b0eb0cf38b2637008a571015d3f5973e12f463c44524d1d79b33b39717b6ee5d310ad83b18ebc67e6063f
@@ -92,16 +92,15 @@ linters:
92
92
  - Lint/EndAlignment
93
93
  - Lint/Void
94
94
  - Layout/AlignParameters
95
+ - Layout/ElseAlignment
96
+ - Layout/EndOfLine
95
97
  - Layout/IndentationWidth
96
98
  - Layout/TrailingBlankLines
97
99
  - Layout/TrailingWhitespace
98
100
  - Metrics/BlockLength
101
+ - Metrics/BlockNesting
99
102
  - Metrics/LineLength
100
- - Style/BlockNesting
101
- - Style/ElseAlignment
102
- - Style/EndOfLine
103
- - Style/FileName
104
- - Style/FinalNewline
103
+ - Naming/FileName
105
104
  - Style/FrozenStringLiteralComment
106
105
  - Style/IfUnlessModifier
107
106
  - Style/Next
@@ -21,7 +21,7 @@ module HamlLint
21
21
  def run(args)
22
22
  options = HamlLint::Options.new.parse(args)
23
23
  act_on_options(options)
24
- rescue => ex
24
+ rescue StandardError => ex
25
25
  handle_exception(ex)
26
26
  end
27
27
 
@@ -97,7 +97,7 @@ module HamlLint
97
97
  # Ensure `include` and `exclude` options for linters are arrays
98
98
  # (since users can specify a single string glob pattern for convenience)
99
99
  def ensure_linter_include_exclude_arrays_exist
100
- @hash['linters'].keys.each do |linter_name|
100
+ @hash['linters'].each_key do |linter_name|
101
101
  %w[include exclude].each do |option|
102
102
  linter_config = @hash['linters'][linter_name]
103
103
  linter_config[option] = Array(linter_config[option])
@@ -6,6 +6,16 @@ module HamlLint
6
6
  class Linter::RuboCop < Linter
7
7
  include LinterRegistry
8
8
 
9
+ # Maps the ::RuboCop::Cop::Severity levels to our own levels.
10
+ SEVERITY_MAP = {
11
+ error: :error,
12
+ fatal: :error,
13
+
14
+ convention: :warning,
15
+ refactor: :warning,
16
+ warning: :warning,
17
+ }.freeze
18
+
9
19
  def visit_root(_node)
10
20
  extractor = HamlLint::RubyExtractor.new
11
21
  extracted_source = extractor.extract(document)
@@ -58,10 +68,21 @@ module HamlLint
58
68
 
59
69
  offenses.reject { |offense| Array(config['ignored_cops']).include?(offense.cop_name) }
60
70
  .each do |offense|
61
- record_lint(dummy_node.new(source_map[offense.line]), offense.message)
71
+ record_lint(dummy_node.new(source_map[offense.line]), offense.message,
72
+ offense.severity.name)
62
73
  end
63
74
  end
64
75
 
76
+ # Record a lint for reporting back to the user.
77
+ #
78
+ # @param node [#line] node to extract the line number from
79
+ # @param message [String] error/warning to display to the user
80
+ # @param severity [Symbol] RuboCop severity level for the offense
81
+ def record_lint(node, message, severity)
82
+ @lints << HamlLint::Lint.new(self, @document.file, node.line, message,
83
+ SEVERITY_MAP.fetch(severity, :warning))
84
+ end
85
+
65
86
  # Returns flags that will be passed to RuboCop CLI.
66
87
  #
67
88
  # @return [Array<String>]
@@ -16,7 +16,7 @@ module HamlLint
16
16
  # @param files [Array<String>] files that were linted
17
17
  # @param fail_level [Symbol] the severity level to fail on
18
18
  # @param reporter [HamlLint::Reporter] the reporter for the report
19
- def initialize(lints = [], files = [], fail_level = :warning, reporter: nil)
19
+ def initialize(lints: [], files: [], fail_level: :warning, reporter: nil)
20
20
  @lints = lints.sort_by { |l| [l.filename, l.line] }
21
21
  @files = files
22
22
  @fail_level = Severity.new(fail_level)
@@ -29,7 +29,7 @@ module HamlLint
29
29
  # @return [void]
30
30
  def add_lint(lint)
31
31
  lints << lint
32
- @reporter.added_lint(lint)
32
+ @reporter.added_lint(lint, self)
33
33
  end
34
34
 
35
35
  # Displays the report via the configured reporter.
@@ -6,8 +6,8 @@ module HamlLint
6
6
  class Reporter::DefaultReporter < Reporter
7
7
  include Reporter::Utils
8
8
 
9
- def added_lint(lint)
10
- print_lint(lint)
9
+ def added_lint(lint, report)
10
+ print_lint(lint) if lint.severity >= report.fail_level
11
11
  end
12
12
 
13
13
  def display_report(report)
@@ -5,8 +5,9 @@ module HamlLint
5
5
  # A hook that is called for each lint as it is detected.
6
6
  #
7
7
  # @param _lint [HamlLint::Lint] the lint added to the report
8
+ # @param _report [HamlLint::Report] the report that contains the lint
8
9
  # @return [void]
9
- def added_lint(_lint); end
10
+ def added_lint(_lint, _report); end
10
11
 
11
12
  # A hook that is called for each file as it is finished processing.
12
13
  #
@@ -173,7 +173,7 @@ module HamlLint
173
173
 
174
174
  indent = (' ' * 2 * indent_level)
175
175
 
176
- @source_lines << indent + code
176
+ @source_lines << indent_code(code, indent)
177
177
 
178
178
  original_line =
179
179
  node_or_line.respond_to?(:line) ? node_or_line.line : node_or_line
@@ -187,6 +187,11 @@ module HamlLint
187
187
  end
188
188
  end
189
189
 
190
+ def indent_code(code, indent)
191
+ codes = code.split("\n")
192
+ codes.map { |c| indent + c }.join("\n")
193
+ end
194
+
190
195
  def anonymous_block?(text)
191
196
  text =~ /\bdo\s*(\|\s*[^\|]*\s*\|)?(\s*#.*)?\z/
192
197
  end
@@ -127,7 +127,7 @@ module HamlLint
127
127
  # @option options :reporter [HamlLint::Reporter] the reporter to report with
128
128
  # @return [HamlLint::Report]
129
129
  def report(options)
130
- report = HamlLint::Report.new(reporter: options[:reporter])
130
+ report = HamlLint::Report.new(reporter: options[:reporter], fail_level: options[:fail_level])
131
131
  report.start(@files)
132
132
  process_files(report)
133
133
  report
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.26.0'.freeze
5
+ VERSION = '0.27.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.26.0
4
+ version: 0.27.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-06-02 00:00:00.000000000 Z
12
+ date: 2017-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
@@ -71,14 +71,14 @@ dependencies:
71
71
  requirements:
72
72
  - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 0.49.0
74
+ version: 0.50.0
75
75
  type: :runtime
76
76
  prerelease: false
77
77
  version_requirements: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: 0.49.0
81
+ version: 0.50.0
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: sysexits
84
84
  requirement: !ruby/object:Gem::Requirement
@@ -197,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
197
197
  requirements:
198
198
  - - ">="
199
199
  - !ruby/object:Gem::Version
200
- version: 1.9.3
200
+ version: 2.1.0
201
201
  required_rubygems_version: !ruby/object:Gem::Requirement
202
202
  requirements:
203
203
  - - ">="
@@ -205,9 +205,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
205
  version: '0'
206
206
  requirements: []
207
207
  rubyforge_project:
208
- rubygems_version: 2.4.5.1
208
+ rubygems_version: 2.6.14
209
209
  signing_key:
210
210
  specification_version: 4
211
211
  summary: HAML lint tool
212
212
  test_files: []
213
- has_rdoc: