slim_lint 0.14.0 → 0.15.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: bf8c56ea545885c5a0214e60a865a266f4459ed5
4
- data.tar.gz: a8d108a971c36c77e507374a4aeffcbf5d188381
3
+ metadata.gz: 3b53d86d50248abbf43d79bb82e08889611d12c1
4
+ data.tar.gz: 99e7c30c6b6843400bcb349421b584580573d609
5
5
  SHA512:
6
- metadata.gz: 58880962969b559714aa8c51b406d92d8854da6bdc38a65f505c1f8192e96e09847c9bb361b379d3189b4dfd964762ab62599e1a8820a54f7cb50e20c75a3154
7
- data.tar.gz: 1cbe595ed72c75eee128580bbdcb59db30569593537b8b9a2c46f34c2c5ba2e182c25beb8df81a191fdbdecd7ec398bf0c3358aa86af3d5f55a766853493f33d
6
+ metadata.gz: 4aa7c7cb61b558f420aa8e1c898723e739d8db779030398461d2da7321cee45043b79d6221996a0a7ca10100b94a3fa0df575fbb575d3d9d7cbbfe1a26ebe568
7
+ data.tar.gz: f106cd4173dbaf08251ae20c687304e4adaecc700c556a74a21d9a0e20677d8fca94de3a75a6db401cd71019a7ba7dd97d12b4c67e8fa66810f5e45b0cba6cf7
@@ -3,9 +3,6 @@
3
3
  module SlimLint
4
4
  # Represents a parsed Slim document and its associated metadata.
5
5
  class Document
6
- # File name given to source code parsed from just a string.
7
- STRING_SOURCE = '(string)'.freeze
8
-
9
6
  # @return [SlimLint::Configuration] Configuration used to parse template
10
7
  attr_reader :config
11
8
 
@@ -29,7 +26,7 @@ module SlimLint
29
26
  # @raise [Slim::Parser::Error] if there was a problem parsing the document
30
27
  def initialize(source, options)
31
28
  @config = options[:config]
32
- @file = options.fetch(:file, STRING_SOURCE)
29
+ @file = options.fetch(:file, nil)
33
30
 
34
31
  process_source(source)
35
32
  end
@@ -1,7 +1,6 @@
1
1
  require 'slim_lint/ruby_extractor'
2
2
  require 'slim_lint/ruby_extract_engine'
3
3
  require 'rubocop'
4
- require 'tempfile'
5
4
 
6
5
  module SlimLint
7
6
  # Runs RuboCop on Ruby code extracted from Slim templates.
@@ -30,18 +29,10 @@ module SlimLint
30
29
  def find_lints(ruby, source_map)
31
30
  rubocop = ::RuboCop::CLI.new
32
31
 
33
- original_filename = document.file || 'ruby_script'
34
- filename = "#{File.basename(original_filename)}.slim_lint.tmp"
35
- directory = File.dirname(original_filename)
36
-
37
- Tempfile.open([filename, '.rb'], directory) do |f|
38
- begin
39
- f.write(ruby)
40
- f.close
41
- extract_lints_from_offenses(lint_file(rubocop, f.path), source_map)
42
- ensure
43
- f.unlink
44
- end
32
+ filename = document.file ? "#{document.file}.rb" : 'ruby_script.rb'
33
+
34
+ with_ruby_from_stdin(ruby) do
35
+ extract_lints_from_offenses(lint_file(rubocop, filename), source_map)
45
36
  end
46
37
  end
47
38
 
@@ -76,8 +67,25 @@ module SlimLint
76
67
  def rubocop_flags
77
68
  flags = %w[--format SlimLint::OffenseCollector]
78
69
  flags += ['--config', ENV['SLIM_LINT_RUBOCOP_CONF']] if ENV['SLIM_LINT_RUBOCOP_CONF']
70
+ flags += ['--stdin']
79
71
  flags
80
72
  end
73
+
74
+ # Overrides the global stdin to allow RuboCop to read Ruby code from it.
75
+ #
76
+ # @param ruby [String] the Ruby code to write to the overridden stdin
77
+ # @param _block [Block] the block to perform with the overridden stdin
78
+ # @return [void]
79
+ def with_ruby_from_stdin(ruby, &_block)
80
+ original_stdin = $stdin
81
+ stdin = StringIO.new
82
+ stdin.write(ruby)
83
+ stdin.rewind
84
+ $stdin = stdin
85
+ yield
86
+ ensure
87
+ $stdin = original_stdin
88
+ end
81
89
  end
82
90
 
83
91
  # Collects offenses detected by RuboCop.
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module SlimLint
5
- VERSION = '0.14.0'.freeze
5
+ VERSION = '0.15.0'.freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane da Silva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-20 00:00:00.000000000 Z
11
+ date: 2017-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slim