slim_lint 0.26.0 → 0.28.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
  SHA256:
3
- metadata.gz: 007f6af5a15bd9858e04011b2fa0b604bc523148929b96852f44661b95fb1f66
4
- data.tar.gz: 156ad192dc47014b863c9be9840f2280ee3174aa98bb96588b34017ffa7d470e
3
+ metadata.gz: b7be0fb0eb28f9ecd303cae98461185de3e6778c8ac50230adf67cb5b741d432
4
+ data.tar.gz: 584e97fc7dd83fa5e71aeec357e365cc5c5fd23f16d2504a7e7b62fbacb64b0e
5
5
  SHA512:
6
- metadata.gz: 30e9a1af1ba6b00cdc64037fa862eb2b40789e81f6d846183d84755a37396de87a7606ef30b8c11955ca3dc41fe691a157b5b2e75b737b73a03dfaecde8279c3
7
- data.tar.gz: 2664127ced343842a71564c9be8b146f39a5d0374c48bb4c6f41fe764c021507542a81ddc24c9df3b12fab79d62408c2971179f9b57b02e5781846b31922c63d
6
+ metadata.gz: 7922b5927ef482197e73669568b8dbe3c676a590f98164a52a085b5312853be43439a3fe36641301c68e5621ea6f40cefb566c523b9d6327a349a5fd5989e9cb
7
+ data.tar.gz: 110fb1466b24a89d8e2868afbb8e1bb1540a575bd406a075a63a29f8d5aae28f06ec1e62512d3cb0ccd252f2e04cbabc97a8793ea9cd7ee917bb2673f4ab704a
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,9 +89,19 @@ 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
 
101
+ Tag:
102
+ enabled: false
103
+ forbidden_tags: []
104
+
89
105
  TagCase:
90
106
  enabled: true
91
107
 
@@ -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
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SlimLint
4
+ # Checks for forbidden tags.
5
+ class Linter::Tag < Linter
6
+ include LinterRegistry
7
+
8
+ on [:html, :tag] do |sexp|
9
+ _, _, name = sexp
10
+
11
+ forbidden_tags = config['forbidden_tags']
12
+ forbidden_tags.each do |forbidden_tag|
13
+ next unless name[/^#{forbidden_tag}$/i]
14
+
15
+ report_lint(sexp, "Forbidden tag `#{name}` found")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Defines the gem version.
4
4
  module SlimLint
5
- VERSION = '0.26.0'
5
+ VERSION = '0.28.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.26.0
4
+ version: 0.28.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-16 00:00:00.000000000 Z
11
+ date: 2024-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -114,10 +114,13 @@ 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
123
+ - lib/slim_lint/linter/tag.rb
121
124
  - lib/slim_lint/linter/tag_case.rb
122
125
  - lib/slim_lint/linter/trailing_blank_lines.rb
123
126
  - lib/slim_lint/linter/trailing_whitespace.rb
@@ -164,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
167
  - !ruby/object:Gem::Version
165
168
  version: '0'
166
169
  requirements: []
167
- rubygems_version: 3.4.10
170
+ rubygems_version: 3.5.9
168
171
  signing_key:
169
172
  specification_version: 4
170
173
  summary: Slim template linting tool