platformos-check 0.3.3 → 0.4.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: ea3d461ba94a5e68217d4c8ce7143172fbc2a1c47e22b634f75e9895b2448906
4
- data.tar.gz: 69cb278ff4ac062866d0d9aea988e1df20a43b2fb401df8d804965ede6502d3e
3
+ metadata.gz: b962e236b71ab785e3e566413ae86c64c6d767d26d8871606cc639b1eae7023e
4
+ data.tar.gz: 0df29d550f5779ebe29ac285809144998d49cd7a8d8049769ac023d65cdde3de
5
5
  SHA512:
6
- metadata.gz: fe07f6ef18cfe1fffb5216799c69557f01e95b86feb6d55543ab1012051c428a6d56902df123d8c1a034d4f2f8de5e662c1053192b0e4870d3e4d221df6a21e2
7
- data.tar.gz: 5f957eebbbb846239191230408645c0487e8a9da01f6d3be5d79d8c173402718cda2ff6a1ad2bc6c077d0a007871d99e2a4daf23ae1b0fb42a76fc8f505ca73f
6
+ metadata.gz: a8bcd3931092d2621dd74f174790ecc13213db17c56d11a9a174bdda6b5e7e22f8526b93553225fa6d884eb4af74e5249c2f78da2e88ad794f3b4064f935be33
7
+ data.tar.gz: ba1ca314fc5d0a154f2f74f52002204da03ce80edae7763e633b46fca31e56329f63f8e7343c52093c081c304c31e9462e5c8f52add1d328cf372e63005826fb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ v0.4.0 / 2023-09-17
2
+ ==================
3
+
4
+ * Add unused attributes messages in render/function/background tags invocations
5
+
1
6
  v0.3.3 / 2023-09-16
2
7
  ==================
3
8
 
@@ -4,12 +4,11 @@ This check prevents errors by making sure that no undefined variables are being
4
4
 
5
5
  ## Check Details
6
6
 
7
- This check is aimed at eliminating undefined object errors.
7
+ This check is aimed at eliminating undefined object errors. Additionally it reports any missing or unused attributes in render, function and background tags.
8
8
 
9
9
  :-1: Examples of **incorrect** code for this check:
10
10
 
11
11
  ```liquid
12
- {% assign greetings = "Hello" %}
13
12
  {% if greeting == "Hello" %}
14
13
  Hello
15
14
  {% endif %}
@@ -31,7 +30,7 @@ This check is aimed at eliminating undefined object errors.
31
30
  ```liquid
32
31
  {% liquid
33
32
  # my_function body
34
- assign my_arg = my_arg: default nil
33
+ assign my_arg = my_arg | default: nil
35
34
  return my_arg
36
35
  %}
37
36
  ```
@@ -196,9 +196,12 @@ module PlatformosCheck
196
196
 
197
197
  def check_undefined(info, all_global_objects, render_node)
198
198
  all_variables = info.all_variables
199
-
199
+ potentially_unused_variables = render_node.value.attributes.keys if render_node
200
200
  info.each_variable_lookup(!!render_node) do |(key, node)|
201
201
  name, line_number = key
202
+
203
+ potentially_unused_variables&.delete(name)
204
+
202
205
  next if all_variables.include?(name)
203
206
  next if all_global_objects.include?(name)
204
207
 
@@ -213,6 +216,11 @@ module PlatformosCheck
213
216
  add_offense("Undefined object `#{name}`", node:, line_number:)
214
217
  end
215
218
  end
219
+
220
+ potentially_unused_variables -= render_node.value.internal_attributes if render_node && render_node.value.respond_to?(:internal_attributes)
221
+ potentially_unused_variables&.each do |name|
222
+ add_offense("Unused argument `#{name}`", node: render_node)
223
+ end
216
224
  end
217
225
  end
218
226
  end
@@ -5,6 +5,7 @@ module PlatformosCheck
5
5
  class Background < Base
6
6
  PARTIAL_SYNTAX = /(#{Liquid::VariableSignature}+)\s*=\s*(.*)\s*/om
7
7
  CLOSE_TAG_SYNTAX = /\A(.*)(?-mix:\{%-?)\s*(\w+)\s*(.*)?(?-mix:%\})\z/m # based on Liquid::Raw::FullTokenPossiblyInvalid
8
+ INTERNAL_ATTRIBUTES = %w[delay priority max_attempts source_name]
8
9
 
9
10
  attr_reader :to, :from, :attributes, :value_expr, :partial_syntax, :partial_name
10
11
 
@@ -27,6 +28,10 @@ module PlatformosCheck
27
28
  @attributes = attributes_expr
28
29
  end
29
30
 
31
+ def internal_attributes
32
+ INTERNAL_ATTRIBUTES
33
+ end
34
+
30
35
  def parse(tokens)
31
36
  return super if @partial_syntax
32
37
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlatformosCheck
4
- VERSION = "0.3.3"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: platformos-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Bliszczyk
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2023-09-16 00:00:00.000000000 Z
13
+ date: 2023-09-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: graphql