erb_lint 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a211bea7ec247bcf1d79ede8f37db1b6b7d1b8c
4
- data.tar.gz: 362ca7b4ffb1f184818889166cb572198c1def7e
3
+ metadata.gz: 3e9127a9303ed73745516b7a4432e08f8f1e9cd5
4
+ data.tar.gz: 2c689a6e356cc463eb9f892294cf7d4c6ea5d1b9
5
5
  SHA512:
6
- metadata.gz: 45c2ff7d03c2ec43e37562887ad9cdc9f396b0084bf290036a848aa820fed661a0f99a49d120be62100aa15c640fa4374f5937c9accb0066a06028632ac56e8f
7
- data.tar.gz: 16279ef10a1f004fe97309dde027de0bf244ac0a9e047b9a0ff04be73d5d9d71494e1e2ab08d584b9123ee96f35a05525ff7b8ff09d005d3f75f000c009eacbf
6
+ metadata.gz: e9f5598858497fffa0217f7f8869184bdd27f3f034a2b080dec4666e1605d9d44a0d5fd5a1d2d44e50faa3802471d08cca79a995e28bfc849914cbd3deb3d6e6
7
+ data.tar.gz: eb350b03fd5dbe4e73b15417abe76e4674958dbc19b8381ad39c23177a2bddf193e406df28ebebe27e30548692facfc080695ba20449ad1757b55f937abf5a5e
@@ -62,7 +62,7 @@ module ERBLint
62
62
  each_element_with_index(iterator) do |element, index|
63
63
  type = element.find_attr('type')
64
64
  next unless type
65
- next unless 'text/html' == type.value_without_quotes
65
+ next unless type.value_without_quotes == 'text/html'
66
66
  next_node = iterator.nodes[index + 1]
67
67
 
68
68
  yield next_node if next_node&.text?
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'better_html'
4
+ require 'rubocop'
5
+ require 'tempfile'
6
+
7
+ module ERBLint
8
+ module Linters
9
+ # Run selected rubocop cops on Ruby code
10
+ class Rubocop < Linter
11
+ include LinterRegistry
12
+
13
+ # copied from Rails: action_view/template/handlers/erb/erubi.rb
14
+ BLOCK_EXPR = /\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z/
15
+
16
+ def initialize(config_hash)
17
+ @enabled_cops = config_hash.delete('only')
18
+ tempfile_from('.erblint-rubocop', config_hash.except('enabled').to_yaml) do |tempfile|
19
+ custom_config = RuboCop::ConfigLoader.load_file(tempfile.path)
20
+ @config = RuboCop::ConfigLoader.merge_with_default(custom_config, '')
21
+ end
22
+ end
23
+
24
+ def lint_file(file_content)
25
+ errors = []
26
+ erb = BetterHtml::NodeIterator::HtmlErb.new(file_content)
27
+ erb.tokens.each do |token|
28
+ next unless [:stmt, :expr_literal, :expr_escaped].include?(token.type)
29
+ ruby_code = token.code.sub(BLOCK_EXPR, '')
30
+ offenses = inspect_content(ruby_code)
31
+ offenses&.each do |offense|
32
+ errors << format_error(token, offense)
33
+ end
34
+ end
35
+ errors
36
+ end
37
+
38
+ private
39
+
40
+ def tempfile_from(filename, content)
41
+ Tempfile.create(File.basename(filename), Dir.pwd) do |tempfile|
42
+ tempfile.write(content)
43
+ tempfile.rewind
44
+
45
+ yield(tempfile)
46
+ end
47
+ end
48
+
49
+ def inspect_content(content)
50
+ source = processed_source(content)
51
+ return unless source.valid_syntax?
52
+ offenses = team.inspect_file(source)
53
+ offenses.reject(&:disabled?)
54
+ end
55
+
56
+ def processed_source(content)
57
+ RuboCop::ProcessedSource.new(
58
+ content,
59
+ @config.target_ruby_version,
60
+ '(erb)'
61
+ )
62
+ end
63
+
64
+ def team
65
+ selected_cops = RuboCop::Cop::Cop.all.select { |cop| cop.match?(@enabled_cops) }
66
+ cop_classes = RuboCop::Cop::Registry.new(selected_cops)
67
+ RuboCop::Cop::Team.new(cop_classes, @config, extra_details: true, display_cop_names: true)
68
+ end
69
+
70
+ def format_error(token, offense)
71
+ {
72
+ line: token.location.line + offense.line - 1,
73
+ message: offense.message.strip
74
+ }
75
+ end
76
+ end
77
+ end
78
+ end
@@ -15,7 +15,7 @@ module ERBLint
15
15
  end
16
16
 
17
17
  def run(filename, file_content)
18
- linters_for_file = @linters.select { |linter| !linter_excludes_file?(linter, filename) }
18
+ linters_for_file = @linters.reject { |linter| linter_excludes_file?(linter, filename) }
19
19
  linters_for_file.map do |linter|
20
20
  {
21
21
  linter_name: linter.class.simple_name,
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Chan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-31 00:00:00.000000000 Z
11
+ date: 2017-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: better_html
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.5
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: html_tokenizer
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -25,19 +39,19 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: better_html
42
+ name: rubocop
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - "~>"
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: 0.0.5
47
+ version: '0'
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - "~>"
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: 0.0.5
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -79,6 +93,7 @@ files:
79
93
  - lib/erb_lint/linters/deprecated_classes.rb
80
94
  - lib/erb_lint/linters/erb_safety.rb
81
95
  - lib/erb_lint/linters/final_newline.rb
96
+ - lib/erb_lint/linters/rubocop.rb
82
97
  - lib/erb_lint/runner.rb
83
98
  homepage: https://github.com/justinthec/erb-lint
84
99
  licenses: