haml_lint 0.20.0 → 0.21.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: 7636e69c61d23c04c8398619c24288620f15881d
4
- data.tar.gz: 73c113c20a5f3369791efb9ff5db4e54e4ebd852
3
+ metadata.gz: 9343eacc913a5864ba1b9537bffc6bdcd657deaf
4
+ data.tar.gz: 1aa917703eea3279812a58dfea38a4f342078bd7
5
5
  SHA512:
6
- metadata.gz: fa7801c662223e5e38f88d8dcd3b8d083ce67ccc68c2cab14de2d1031389a9af0f254e470e3c96ea7e315b619e819b21ef5e54879947dc0f843c81731c140abd
7
- data.tar.gz: a12121c2349a5a77a0aa1f7d821baeaee82b9b18a5e67bd935c73c4f9e7ba4b19aff9f0818f1b5a0ab1bfe2855b34ab69c6f0ca82cd68ded4444c65a2961aaa9
6
+ metadata.gz: 0915d21c8eb959014d5253dde8a71fc4b24b11146f02a1562abc47c38ec94da67ae829991131e27a029c8f3809cc4c2de1e2e05379c2093530063678ff2583d4
7
+ data.tar.gz: a890450c449514de7114891ce762354652ffb1b6d5a9811844906022706f6017a73fc296e7e0fe35622c0565e2e5dde95dc782d0ff544d64044eaa097f5a7e1b
@@ -1,6 +1,5 @@
1
1
  require 'haml_lint/ruby_extractor'
2
2
  require 'rubocop'
3
- require 'tempfile'
4
3
 
5
4
  module HamlLint
6
5
  # Runs RuboCop on Ruby code contained within HAML templates.
@@ -27,18 +26,10 @@ module HamlLint
27
26
  def find_lints(ruby, source_map)
28
27
  rubocop = ::RuboCop::CLI.new
29
28
 
30
- original_filename = document.file || 'ruby_script'
31
- filename = "#{File.basename(original_filename)}.haml_lint.tmp"
32
- directory = File.dirname(original_filename)
33
-
34
- Tempfile.open(filename, directory) do |f|
35
- begin
36
- f.write(ruby)
37
- f.close
38
- extract_lints_from_offenses(lint_file(rubocop, f.path), source_map)
39
- ensure
40
- f.unlink
41
- end
29
+ filename = document.file || 'ruby_script'
30
+
31
+ with_ruby_from_stdin(ruby) do
32
+ extract_lints_from_offenses(lint_file(rubocop, filename), source_map)
42
33
  end
43
34
  end
44
35
 
@@ -72,8 +63,25 @@ module HamlLint
72
63
  def rubocop_flags
73
64
  flags = %w[--format HamlLint::OffenseCollector]
74
65
  flags += ['--config', ENV['HAML_LINT_RUBOCOP_CONF']] if ENV['HAML_LINT_RUBOCOP_CONF']
66
+ flags += ['--stdin']
75
67
  flags
76
68
  end
69
+
70
+ # Overrides the global stdin to allow RuboCop to read Ruby code from it.
71
+ #
72
+ # @param ruby [String] the Ruby code to write to the overridden stdin
73
+ # @param _block [Block] the block to perform with the overridden stdin
74
+ # @return [void]
75
+ def with_ruby_from_stdin(ruby, &_block)
76
+ original_stdin = $stdin
77
+ stdin = StringIO.new
78
+ stdin.write(ruby)
79
+ stdin.rewind
80
+ $stdin = stdin
81
+ yield
82
+ ensure
83
+ $stdin = original_stdin
84
+ end
77
85
  end
78
86
 
79
87
  # Collects offenses detected by RuboCop.
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module HamlLint
5
- VERSION = '0.20.0'.freeze
5
+ VERSION = '0.21.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.20.0
4
+ version: 0.21.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-01-16 00:00:00.000000000 Z
12
+ date: 2017-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
@@ -165,8 +165,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  version: '0'
166
166
  requirements: []
167
167
  rubyforge_project:
168
- rubygems_version: 2.5.2
168
+ rubygems_version: 2.4.5.1
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: HAML lint tool
172
172
  test_files: []
173
+ has_rdoc: