haml_lint 0.63.0 → 0.64.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 +4 -4
- data/lib/haml_lint/document.rb +5 -0
- data/lib/haml_lint/linter/rubocop.rb +20 -5
- data/lib/haml_lint/runner.rb +1 -0
- data/lib/haml_lint/source.rb +5 -0
- data/lib/haml_lint/utils.rb +0 -28
- data/lib/haml_lint/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73a515adb6ca4915d07c747133e7a657e04bd8d6a5c41cf5cd63a0adf3e03316
|
4
|
+
data.tar.gz: efb5d688d181d7906a28bef3f25b1080e1e38e2461d9343db554ed5a98037296
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a6c42a2be6709314fb8bff476e8a0ff80f0054895eeaa795b8fd741039a580bfb6ced6b0a45b293cdbe0641676a412909363b99f3638a5f8f4f5dd910de736a
|
7
|
+
data.tar.gz: 7165be1ef28719e4a08ad60a26aa6d0a8f8e1ca0507c5376cbfa776e813320fbb3fbd4357c7d74809393cd9c676ca009bab3d8d36b48770de7ffda4c680ed3a2
|
data/lib/haml_lint/document.rb
CHANGED
@@ -14,6 +14,9 @@ module HamlLint
|
|
14
14
|
# @return [String] Haml template file path
|
15
15
|
attr_reader :file
|
16
16
|
|
17
|
+
# @return [Boolean] true if source was read directly from `file` on-disk (rather than from stdin)
|
18
|
+
attr_reader :file_on_disk
|
19
|
+
|
17
20
|
# @return [Boolean] true if source changes (from autocorrect) should be written to stdout instead of disk
|
18
21
|
attr_reader :write_to_stdout
|
19
22
|
|
@@ -39,12 +42,14 @@ module HamlLint
|
|
39
42
|
# @param source [String] Haml code to parse
|
40
43
|
# @param options [Hash]
|
41
44
|
# @option options :file [String] file name of document that was parsed
|
45
|
+
# @option options :file_on_disk [Boolean] true if source was read straight from `file` on disk
|
42
46
|
# @option options :write_to_stdout [Boolean] true if source changes should be written to stdout
|
43
47
|
# @raise [Haml::Parser::Error] if there was a problem parsing the document
|
44
48
|
def initialize(source, options)
|
45
49
|
@config = options[:config]
|
46
50
|
@file = options.fetch(:file, STRING_SOURCE)
|
47
51
|
@write_to_stdout = options[:write_to_stdout]
|
52
|
+
@file_on_disk = options[:file_on_disk] && @file != STRING_SOURCE
|
48
53
|
@source_was_changed = false
|
49
54
|
process_source(source)
|
50
55
|
end
|
@@ -20,11 +20,12 @@ module HamlLint
|
|
20
20
|
class Runner < ::RuboCop::Runner
|
21
21
|
attr_reader :offenses
|
22
22
|
|
23
|
-
def run(
|
23
|
+
def run(haml_path, ruby_code, config:, allow_cache: false)
|
24
|
+
@allow_cache = allow_cache
|
24
25
|
@offenses = []
|
25
|
-
@options[:stdin] = code
|
26
26
|
@config_store.instance_variable_set(:@options_config, config)
|
27
|
-
|
27
|
+
@options[:stdin] = ruby_code
|
28
|
+
super([haml_path])
|
28
29
|
end
|
29
30
|
|
30
31
|
def corrected_code
|
@@ -39,6 +40,20 @@ module HamlLint
|
|
39
40
|
def file_finished(_file, offenses)
|
40
41
|
@offenses = offenses
|
41
42
|
end
|
43
|
+
|
44
|
+
# RuboCop caches results by taking a hash of the file contents & path, among other things.
|
45
|
+
# It disables its cache when working on file-content from stdin.
|
46
|
+
# Unfortunately we always use RuboCop's stdin, even when we're linting a file on-disk.
|
47
|
+
# So, override RuboCop::Runner#cached_run? so that it'll allow caching results, so long
|
48
|
+
# as haml-lint itself isn't being invoked with files on stdin.
|
49
|
+
def cached_run?
|
50
|
+
return false unless @allow_cache
|
51
|
+
|
52
|
+
@cached_run ||=
|
53
|
+
(@options[:cache] == 'true' ||
|
54
|
+
(@options[:cache] != 'false' && @config_store.for_pwd.for_all_cops['UseCache'])) &&
|
55
|
+
!@options[:auto_gen_config]
|
56
|
+
end
|
42
57
|
end
|
43
58
|
|
44
59
|
include LinterRegistry
|
@@ -227,7 +242,7 @@ module HamlLint
|
|
227
242
|
# @param path [String] the path to tell RuboCop we are running
|
228
243
|
# @return [Array<RuboCop::Cop::Offense>, String]
|
229
244
|
def run_rubocop(rubocop_runner, ruby_code, path) # rubocop:disable Metrics
|
230
|
-
rubocop_runner.run(path, ruby_code, config: rubocop_config_for(path))
|
245
|
+
rubocop_runner.run(path, ruby_code, config: rubocop_config_for(path), allow_cache: @document&.file_on_disk)
|
231
246
|
|
232
247
|
if ENV['HAML_LINT_INTERNAL_DEBUG'] == 'true'
|
233
248
|
if rubocop_runner.offenses.empty?
|
@@ -298,6 +313,7 @@ module HamlLint
|
|
298
313
|
end
|
299
314
|
|
300
315
|
# rubocop:disable Style/MutableConstant
|
316
|
+
# Using BaseFormatter suppresses any default output
|
301
317
|
DEFAULT_FLAGS = %w[--format RuboCop::Formatter::BaseFormatter]
|
302
318
|
begin
|
303
319
|
::RuboCop::Options.new.parse(['--raise-cop-error'])
|
@@ -312,7 +328,6 @@ module HamlLint
|
|
312
328
|
#
|
313
329
|
# @return [Hash]
|
314
330
|
def rubocop_options
|
315
|
-
# using BaseFormatter suppresses any default output
|
316
331
|
flags = DEFAULT_FLAGS
|
317
332
|
flags += ignored_cops_flags
|
318
333
|
flags += rubocop_autocorrect_flags
|
data/lib/haml_lint/runner.rb
CHANGED
@@ -89,6 +89,7 @@ module HamlLint
|
|
89
89
|
begin
|
90
90
|
document = HamlLint::Document.new source.contents, file: source.path,
|
91
91
|
config: config,
|
92
|
+
file_on_disk: !source.stdin?,
|
92
93
|
write_to_stdout: @autocorrect_stdout
|
93
94
|
rescue HamlLint::Exceptions::ParseError => e
|
94
95
|
return [HamlLint::Lint.new(HamlLint::Linter::Syntax.new(config), source.path,
|
data/lib/haml_lint/source.rb
CHANGED
data/lib/haml_lint/utils.rb
CHANGED
@@ -249,34 +249,6 @@ module HamlLint
|
|
249
249
|
$!
|
250
250
|
end
|
251
251
|
|
252
|
-
# Overrides the global stdin, stdout and stderr while within the block, to
|
253
|
-
# push a string in stdin, and capture both stdout and stderr which are returned.
|
254
|
-
#
|
255
|
-
# @param stdin_str [String] the string to push in as stdin
|
256
|
-
# @param _block [Block] the block to perform with the overridden std streams
|
257
|
-
# @return [String, String]
|
258
|
-
def with_captured_streams(stdin_str, &_block)
|
259
|
-
original_stdin = $stdin
|
260
|
-
# The dup is needed so that stdin_data isn't altered (encoding-wise at least)
|
261
|
-
$stdin = StringIO.new(stdin_str.dup)
|
262
|
-
begin
|
263
|
-
original_stdout = $stdout
|
264
|
-
$stdout = StringIO.new
|
265
|
-
begin
|
266
|
-
original_stderr = $stderr
|
267
|
-
$stderr = StringIO.new
|
268
|
-
yield
|
269
|
-
[$stdout.string, $stderr.string]
|
270
|
-
ensure
|
271
|
-
$stderr = original_stderr
|
272
|
-
end
|
273
|
-
ensure
|
274
|
-
$stdout = original_stdout
|
275
|
-
end
|
276
|
-
ensure
|
277
|
-
$stdin = original_stdin
|
278
|
-
end
|
279
|
-
|
280
252
|
def regexp_for_parts(parts, join_regexp, prefix: nil, suffix: nil)
|
281
253
|
regexp_code = parts.map { |c| Regexp.quote(c) }.join(join_regexp)
|
282
254
|
regexp_code = "#{prefix}#{regexp_code}#{suffix}"
|
data/lib/haml_lint/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haml_lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.64.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane da Silva
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-06-
|
10
|
+
date: 2025-06-29 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: haml
|