slim_lint 0.25.0 → 0.27.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 58c99ab50012a0f3475e6518e69bade743b55e6ed5eb4f5dd25a98ea1b7a617e
4
- data.tar.gz: 4593348af814f4bce1bd240d4982eec2acd9d4c7bbda5f5ccc231a3a51b8c148
3
+ metadata.gz: b4318d25d9325fb30a43a2db83a14aca0002c83960dc7edb0e8a5c87eaa59e64
4
+ data.tar.gz: 7ae359e3575cdae4293216064fc6a4bc0a07bd9d6ebb5b5688949634ae1ccbf1
5
5
  SHA512:
6
- metadata.gz: 53ea008e7e03d7261af22c33e098be489096299117b9ec103406382568af8b8b3c10e0a77a3e97e9848c88a57d04d2f5a6b7998b48555d7ea205ceb136f95cdb
7
- data.tar.gz: 1e5e98f7d7e6eacc805a85451b8428f2f746b91b5b3433ce5262779d6bd9285b6db00e463c3d1b79912e9b93b677b5f12f0bf0e50613f284b8b482732fc7e552
6
+ metadata.gz: 6a03e56f04fefa1fc83f95356bcb2bbe5b13db122140aa34afda23809cfd1af6469bed95c681436f4ec7230deebf3b7f932cbbff21423eba88b61bd107006029
7
+ data.tar.gz: d59790c900df3af0486a8c4b636bf970ef9b35932e67342b3d9fb3b8a8dee779016fb0ab8d65ebcd1f9fadb26fa14149da771499159686bc665b0a56608b1774
data/config/default.yml CHANGED
@@ -32,6 +32,12 @@ linters:
32
32
  enabled: false
33
33
  max: 300
34
34
 
35
+ InstanceVariables:
36
+ enabled: false
37
+ include:
38
+ # Include only partial templates by default
39
+ - app/views/**/_*.html.slim
40
+
35
41
  LineLength:
36
42
  enabled: true
37
43
  max: 80
@@ -83,6 +89,12 @@ linters:
83
89
  - Style/WhileUntilDo
84
90
  - Style/WhileUntilModifier
85
91
 
92
+ StrictLocalsMissing:
93
+ enabled: false
94
+ include:
95
+ # Include only Rails partial templates by default
96
+ - app/views/**/_*.html.slim
97
+
86
98
  Tab:
87
99
  enabled: true
88
100
 
@@ -9,14 +9,8 @@ module SlimLint
9
9
 
10
10
  on [:html, :tag, anything, [],
11
11
  [:slim, :output, anything, capture(:ruby, anything)]] do |sexp|
12
- # Process original slim code so that multi-line attributes become single line.
13
- # And store the correction line count
14
- source = merge_multiline_attributes(document.source_lines)
15
-
16
- # Fetch processed Slim code that contains an element with a control statement.
17
- line = source[sexp.line - 1][:line]
18
- # Apply correction to the line count.
19
- sexp.line += source[sexp.line - 1][:line_count]
12
+ # Fetch original Slim code that contains an element with a control statement.
13
+ line = document.source_lines[sexp.line - 1]
20
14
 
21
15
  # Remove any Ruby code, because our regexp below must not match inside Ruby.
22
16
  ruby = captures[:ruby]
@@ -26,29 +20,5 @@ module SlimLint
26
20
 
27
21
  report_lint(sexp, MESSAGE)
28
22
  end
29
-
30
- private
31
-
32
- def merge_multiline_attributes(source_lines)
33
- result = []
34
- memo = ''
35
- correction_line_count = 0
36
-
37
- source_lines.each do |line|
38
- memo += line.chomp('\\')
39
-
40
- # Lines ending in a backslash are concatenated with the next line
41
- # And count the number of lines to correct the sexp line count.
42
- if line.match?(/\\$/)
43
- correction_line_count += 1
44
- next
45
- end
46
-
47
- # Add merged rows and correction line count to the result and reset the memo
48
- result << { line: memo, line_count: correction_line_count }
49
- memo = ''
50
- end
51
- result
52
- end
53
23
  end
54
24
  end
@@ -12,7 +12,7 @@ module SlimLint
12
12
  dummy_node = Struct.new(:line)
13
13
  document.source_lines.each_with_index do |line, index|
14
14
  forbidden_engines.each do |forbidden_engine|
15
- next unless line =~ /^#{forbidden_engine}.*:\s*$/
15
+ next unless line =~ /^\s*#{forbidden_engine}.*:\s*$/
16
16
 
17
17
  report_lint(dummy_node.new(index + 1), MESSAGE % forbidden_engine)
18
18
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlimLint
4
+ # Searches for instance variables in partial or other templates.
5
+ class Linter::InstanceVariables < Linter
6
+ include LinterRegistry
7
+
8
+ on_start do |_sexp|
9
+ processed_sexp = SlimLint::RubyExtractEngine.new.call(document.source)
10
+
11
+ extractor = SlimLint::RubyExtractor.new
12
+ extracted_source = extractor.extract(processed_sexp)
13
+ next if extracted_source.source.empty?
14
+
15
+ parsed_ruby = parse_ruby(extracted_source.source)
16
+ next unless parsed_ruby
17
+
18
+ report_instance_variables(parsed_ruby, extracted_source.source_map)
19
+ end
20
+
21
+ private
22
+
23
+ def report_instance_variables(parsed_ruby, source_map)
24
+ parsed_ruby.each_node do |node|
25
+ next unless node.ivar_type?
26
+
27
+ dummy_node = Struct.new(:line)
28
+ report_lint(dummy_node.new(source_map[node.loc.line]),
29
+ 'Avoid instance variables in the configured ' \
30
+ "view templates (found `#{node.source}`)")
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlimLint
4
+ # Reports on missing strict locals magic line in Slim templates.
5
+ class Linter::StrictLocalsMissing < Linter
6
+ include LinterRegistry
7
+
8
+ on_start do |_sexp|
9
+ unless document.source =~ %r{/#\s+locals:\s+\(.*\)}
10
+ dummy_node = Struct.new(:line)
11
+ report_lint(dummy_node.new(1), 'Strict locals magic line is missing')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module SlimLint
5
- VERSION = '0.25.0'
5
+ VERSION = '0.27.0'
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.25.0
4
+ version: 0.27.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: 2024-01-10 00:00:00.000000000 Z
11
+ date: 2024-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -114,9 +114,11 @@ files:
114
114
  - lib/slim_lint/linter/empty_control_statement.rb
115
115
  - lib/slim_lint/linter/empty_lines.rb
116
116
  - lib/slim_lint/linter/file_length.rb
117
+ - lib/slim_lint/linter/instance_variables.rb
117
118
  - lib/slim_lint/linter/line_length.rb
118
119
  - lib/slim_lint/linter/redundant_div.rb
119
120
  - lib/slim_lint/linter/rubocop.rb
121
+ - lib/slim_lint/linter/strict_locals_missing.rb
120
122
  - lib/slim_lint/linter/tab.rb
121
123
  - lib/slim_lint/linter/tag_case.rb
122
124
  - lib/slim_lint/linter/trailing_blank_lines.rb