slim_lint 0.14.0 → 0.15.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/slim_lint/document.rb +1 -4
- data/lib/slim_lint/linter/rubocop.rb +21 -13
- data/lib/slim_lint/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b53d86d50248abbf43d79bb82e08889611d12c1
|
4
|
+
data.tar.gz: 99e7c30c6b6843400bcb349421b584580573d609
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aa7c7cb61b558f420aa8e1c898723e739d8db779030398461d2da7321cee45043b79d6221996a0a7ca10100b94a3fa0df575fbb575d3d9d7cbbfe1a26ebe568
|
7
|
+
data.tar.gz: f106cd4173dbaf08251ae20c687304e4adaecc700c556a74a21d9a0e20677d8fca94de3a75a6db401cd71019a7ba7dd97d12b4c67e8fa66810f5e45b0cba6cf7
|
data/lib/slim_lint/document.rb
CHANGED
@@ -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,
|
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
|
-
|
34
|
-
|
35
|
-
|
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.
|
data/lib/slim_lint/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: slim
|