platformos-check 0.4.12 → 0.4.14

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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/CONTRIBUTING.md +20 -18
  4. data/README.md +108 -57
  5. data/RELEASING.md +14 -7
  6. data/TROUBLESHOOTING.md +19 -10
  7. data/data/platformos_liquid/documentation/filters.json +1 -1
  8. data/data/platformos_liquid/documentation/latest.json +1 -1
  9. data/data/platformos_liquid/documentation/tags.json +1 -1
  10. data/docs/api/check.md +7 -6
  11. data/docs/api/html_check.md +12 -13
  12. data/docs/api/liquid_check.md +17 -21
  13. data/docs/api/yaml_check.md +3 -3
  14. data/docs/checks/TEMPLATE.md.erb +16 -11
  15. data/docs/checks/convert_include_to_render.md +29 -13
  16. data/docs/checks/deprecated_filter.md +5 -9
  17. data/docs/checks/form_action.md +12 -12
  18. data/docs/checks/form_authenticity_token.md +21 -15
  19. data/docs/checks/graphql_in_for_loop.md +15 -13
  20. data/docs/checks/html_parsing_error.md +12 -12
  21. data/docs/checks/img_lazy_loading.md +13 -11
  22. data/docs/checks/img_width_and_height.md +21 -23
  23. data/docs/checks/include_in_render.md +11 -11
  24. data/docs/checks/invalid_args.md +11 -11
  25. data/docs/checks/liquid_tag.md +12 -12
  26. data/docs/checks/missing_enable_comment.md +7 -7
  27. data/docs/checks/missing_template.md +14 -13
  28. data/docs/checks/parse_json_format.md +15 -14
  29. data/docs/checks/parser_blocking_javascript.md +19 -14
  30. data/docs/checks/required_layout_object.md +5 -7
  31. data/docs/checks/space_inside_braces.md +12 -12
  32. data/docs/checks/syntax_error.md +10 -10
  33. data/docs/checks/template_length.md +12 -12
  34. data/docs/checks/translation_files_match.md +10 -11
  35. data/docs/checks/translation_key_exists.md +10 -11
  36. data/docs/checks/undefined_object.md +11 -13
  37. data/docs/checks/unknown_filter.md +11 -11
  38. data/docs/checks/unreachable_code.md +11 -11
  39. data/docs/checks/unused_assign.md +11 -11
  40. data/docs/checks/unused_partial.md +7 -11
  41. data/docs/checks/valid_yaml.md +11 -11
  42. data/docs/language_server/how_to_correct_code_with_code_actions_and_execute_command.md +62 -70
  43. data/lib/platformos_check/app.rb +23 -14
  44. data/lib/platformos_check/app_file.rb +25 -4
  45. data/lib/platformos_check/asset_file.rb +1 -1
  46. data/lib/platformos_check/file_system_storage.rb +1 -1
  47. data/lib/platformos_check/form_file.rb +1 -1
  48. data/lib/platformos_check/graphql_file.rb +1 -1
  49. data/lib/platformos_check/language_server/completion_context.rb +2 -0
  50. data/lib/platformos_check/language_server/handler.rb +6 -6
  51. data/lib/platformos_check/language_server/variable_lookup_finder.rb +8 -10
  52. data/lib/platformos_check/layout_file.rb +1 -1
  53. data/lib/platformos_check/partial_file.rb +1 -1
  54. data/lib/platformos_check/platformos_liquid/documentation.rb +2 -2
  55. data/lib/platformos_check/translation_file.rb +1 -1
  56. data/lib/platformos_check/version.rb +1 -1
  57. data/platformos-check.gemspec +1 -1
  58. metadata +5 -5
@@ -6,20 +6,20 @@ require "pathname"
6
6
 
7
7
  module PlatformosCheck
8
8
  class App
9
- API_CALLS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(notifications/api_call_notifications|api_calls)/(.+)\.liquid\z}
10
- ASSETS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)assets/}
11
- EMAILS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(notifications/email_notifications|emails)/(.+)\.liquid\z}
12
- GRAPHQL_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(graph_queries|graphql)s?/(.+)\.graphql\z}
13
-
14
- MIGRATIONS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)migrations/(.+)\.liquid\z}
15
- PAGES_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(pages|views/pages)/(.+).liquid\z}
16
- PARTIALS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(views/partials|lib)/(.+)\.liquid\z}
17
- FORMS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(form_configurations|forms)/(.+)\.liquid\z}
18
- LAYOUTS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(views/layouts)/(.+).liquid\z}
19
- SCHEMA_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(custom_model_types|model_schemas|schema)/(.+)\.yml\z}
20
- SMSES_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)(notifications/sms_notifications|smses)/(.+)\.liquid\z}
9
+ API_CALLS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)(notifications/api_call_notifications|api_calls)/(.+)\.liquid\z}
10
+ ASSETS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)assets/}
11
+ EMAILS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)(notifications/email_notifications|emails)/(.+)\.liquid\z}
12
+ GRAPHQL_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)(graph_queries|graphql)s?/(.+)\.graphql\z}
13
+
14
+ MIGRATIONS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)migrations/(.+)\.liquid\z}
15
+ PAGES_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)(pages|views/pages)/(.+).liquid\z}
16
+ PARTIALS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)(views/partials|lib)/(.+)\.liquid\z}
17
+ FORMS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)(form_configurations|forms)/(.+)\.liquid\z}
18
+ LAYOUTS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)(views/layouts)/(.+).liquid\z}
19
+ SCHEMA_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)(custom_model_types|model_schemas|schema)/(.+)\.yml\z}
20
+ SMSES_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)(notifications/sms_notifications|smses)/(.+)\.liquid\z}
21
21
  USER_SCHEMA_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/)?)user.yml}
22
- TRANSLATIONS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|modules/(.+)(private|public|marketplace_builder|app)/)?)translations/(.+)\.yml}
22
+ TRANSLATIONS_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/|(app/)?modules/(.+)(private|public|marketplace_builder|app)/)?)translations/(.+)\.yml}
23
23
  CONFIG_REGEX = %r{\A(?-mix:^/?((marketplace_builder|app)/)?)config.yml}
24
24
 
25
25
  REGEXP_MAP = {
@@ -60,10 +60,19 @@ module PlatformosCheck
60
60
  next unless regexp
61
61
 
62
62
  f = klass.new(path, storage)
63
+
63
64
  if remove
64
65
  @grouped_files[klass].delete(f.name)
66
+ if f.module_overwrite_file? && storage.files.include?(f.module_original_file_path)
67
+ original_file = klass.new(f.module_original_file_path, storage)
68
+ @grouped_files[klass][original_file.name] = original_file
69
+ elsif f.module_original_file? && storage.files.include?(f.module_overwrite_file_path)
70
+ overwrite_file = klass.new(f.module_overwrite_file_path, storage)
71
+ @grouped_files[klass][overwrite_file.name] = overwrite_file
72
+ end
65
73
  else
66
- @grouped_files[klass][f.name] = f
74
+ # we want to keep the reference to a module overwrite, if exists
75
+ @grouped_files[klass][f.name] = f unless f.module_original_file? && @grouped_files[klass][f.name] && @grouped_files[klass][f.name].module_overwrite_file?
67
76
  end
68
77
  end
69
78
  @grouped_files
@@ -48,10 +48,31 @@ module PlatformosCheck
48
48
  end
49
49
 
50
50
  def module_name
51
- @module_name ||= begin
52
- dir_names = @relative_path.split(File::SEPARATOR).reject(&:empty?)
53
- dir_names.first == 'modules' ? dir_names[1] : nil
54
- end
51
+ @module_name ||= if module_original_file?
52
+ dir_names[1]
53
+ elsif module_overwrite_file?
54
+ return dir_names[2]
55
+ end
56
+ end
57
+
58
+ def module_original_file?
59
+ dir_names[0] == 'modules'
60
+ end
61
+
62
+ def module_overwrite_file?
63
+ dir_names[0] == 'app' && dir_names[1] == 'modules'
64
+ end
65
+
66
+ def module_overwrite_file_path
67
+ @module_overwrite_file_path ||= module_original_file? ? 'app/' + relative_path.to_s : nil
68
+ end
69
+
70
+ def module_original_file_path
71
+ @module_original_file_path ||= module_overwrite_file? ? dir_names[1..].join(File::SEPARATOR) : nil
72
+ end
73
+
74
+ def dir_names
75
+ @dir_names ||= @relative_path.split(File::SEPARATOR).reject(&:empty?)
55
76
  end
56
77
 
57
78
  # For the corrector to work properly, we should have a
@@ -4,7 +4,7 @@ require "zlib"
4
4
 
5
5
  module PlatformosCheck
6
6
  class AssetFile < AppFile
7
- DIR_PREFIX = %r{\A/?((marketplace_builder|app)/assets/|modules/((\w|-)*)/(private|public)/assets/)}
7
+ DIR_PREFIX = %r{\A/?((marketplace_builder|app)/assets/|(app/)?modules/((\w|-)*)/(private|public)/assets/)}
8
8
 
9
9
  def initialize(relative_path, storage)
10
10
  super
@@ -31,7 +31,7 @@ module PlatformosCheck
31
31
 
32
32
  file(relative_path).dirname.mkpath unless file(relative_path).dirname.directory?
33
33
  file(relative_path).write(content, mode: 'w+b', encoding: 'UTF-8')
34
- @platformos_app&.update([relative_path])
34
+ @platformos_app&.update([relative_path], remove: !file_exists?(relative_path))
35
35
  end
36
36
 
37
37
  def remove(relative_path)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module PlatformosCheck
4
4
  class FormFile < LiquidFile
5
- DIR_PREFIX = %r{\A/?((marketplace_builder|app)/(form_configurations|forms)/|modules/((\w|-)*)/(private|public)/(form_configurations|forms)/)}
5
+ DIR_PREFIX = %r{\A/?((marketplace_builder|app)/(form_configurations|forms)/|(app/)?modules/((\w|-)*)/(private|public)/(form_configurations|forms)/)}
6
6
 
7
7
  def form?
8
8
  true
@@ -4,7 +4,7 @@ require 'graphql'
4
4
 
5
5
  module PlatformosCheck
6
6
  class GraphqlFile < AppFile
7
- DIR_PREFIX = %r{\A/?((marketplace_builder|app)/(graph_queries|graphql)s?/|modules/((\w|-)*)/(private|public)/(graph_queries|graphql)s?/)}
7
+ DIR_PREFIX = %r{\A/?((marketplace_builder|app)/(graph_queries|graphql)s?/|(app/)?modules/((\w|-)*)/(private|public)/(graph_queries|graphql)s?/)}
8
8
 
9
9
  def write
10
10
  content = rewriter.to_s
@@ -28,6 +28,8 @@ module PlatformosCheck
28
28
 
29
29
  def cursor
30
30
  @cursor ||= (absolute_cursor - token&.start) || 0
31
+ rescue StandardError
32
+ 0
31
33
  end
32
34
 
33
35
  def content
@@ -169,8 +169,8 @@ module PlatformosCheck
169
169
 
170
170
  def on_workspace_did_create_files(_id, params)
171
171
  paths = params[:files]
172
- &.map { |file| file[:uri] }
173
- &.map { |uri| file_path(uri) }
172
+ &.map { |file| file[:uri] }
173
+ &.map { |uri| file_path(uri) }
174
174
  return unless paths
175
175
 
176
176
  paths.each do |path|
@@ -184,8 +184,8 @@ module PlatformosCheck
184
184
 
185
185
  def on_workspace_did_delete_files(_id, params)
186
186
  absolute_paths = params[:files]
187
- &.map { |file| file[:uri] }
188
- &.map { |uri| file_path(uri) }
187
+ &.map { |file| file[:uri] }
188
+ &.map { |uri| file_path(uri) }
189
189
 
190
190
  return unless absolute_paths
191
191
 
@@ -202,8 +202,8 @@ module PlatformosCheck
202
202
  # (which might trigger another platformos_app analysis).
203
203
  def on_workspace_will_rename_files(id, params)
204
204
  relative_paths = params[:files]
205
- &.map { |file| [file[:oldUri], file[:newUri]] }
206
- &.map { |(old_uri, new_uri)| [relative_path_from_uri(old_uri), relative_path_from_uri(new_uri)] }
205
+ &.map { |file| [file[:oldUri], file[:newUri]] }
206
+ &.map { |(old_uri, new_uri)| [relative_path_from_uri(old_uri), relative_path_from_uri(new_uri)] }
207
207
  return @bridge.send_response(id, nil) unless relative_paths
208
208
 
209
209
  relative_paths.each do |(old_path, new_path)|
@@ -75,11 +75,10 @@ module PlatformosCheck
75
75
  is_liquid_variable = content =~ Liquid::VariableStart
76
76
  is_in_variable_segment = previous_char =~ VARIABLE_LOOKUP_CHARACTERS
77
77
  is_on_blank_variable_lookup_position = content[0..cursor - 1] =~ /[{:,-]\s+$/
78
- (
79
- is_liquid_variable && (
80
- is_in_variable_segment ||
81
- is_on_blank_variable_lookup_position
82
- )
78
+
79
+ is_liquid_variable && (
80
+ is_in_variable_segment ||
81
+ is_on_blank_variable_lookup_position
83
82
  )
84
83
  end
85
84
 
@@ -162,11 +161,10 @@ module PlatformosCheck
162
161
  is_liquid_tag = content.match?(Liquid::TagStart)
163
162
  is_in_variable_segment = markup =~ ENDS_WITH_POTENTIAL_LOOKUP
164
163
  is_on_blank_variable_lookup_position = markup =~ ENDS_WITH_BLANK_POTENTIAL_LOOKUP
165
- (
166
- is_liquid_tag && (
167
- is_in_variable_segment ||
168
- is_on_blank_variable_lookup_position
169
- )
164
+
165
+ is_liquid_tag && (
166
+ is_in_variable_segment ||
167
+ is_on_blank_variable_lookup_position
170
168
  )
171
169
  end
172
170
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module PlatformosCheck
4
4
  class LayoutFile < LiquidFile
5
- DIR_PREFIX = %r{\A/?((marketplace_builder|app)/(views/layouts)/|modules/((\w|-)*)/(private|public)/(views/layouts)/)}
5
+ DIR_PREFIX = %r{\A/?((marketplace_builder|app)/(views/layouts)/|(app/)?modules/((\w|-)*)/(private|public)/(views/layouts)/)}
6
6
 
7
7
  def layout?
8
8
  true
@@ -2,7 +2,7 @@
2
2
 
3
3
  module PlatformosCheck
4
4
  class PartialFile < LiquidFile
5
- DIR_PREFIX = %r{\A/?((marketplace_builder|app)/(views/partials|liquid_views|views|lib)/|modules/((\w|-)*)/(private|public)/(views/partials|liquid_views|views|lib)/)}
5
+ DIR_PREFIX = %r{\A/?((marketplace_builder|app)/(views/partials|liquid_views|views|lib)/|(app/)?modules/((\w|-)*)/(private|public)/(views/partials|liquid_views|views|lib)/)}
6
6
 
7
7
  def partial?
8
8
  true
@@ -22,8 +22,8 @@ module PlatformosCheck
22
22
  property_entry = SourceIndex
23
23
  .objects
24
24
  .find { |entry| entry.name == object_name }
25
- &.properties
26
- &.find { |prop| prop.name == property_name }
25
+ &.properties
26
+ &.find { |prop| prop.name == property_name }
27
27
 
28
28
  render_doc(property_entry)
29
29
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module PlatformosCheck
4
4
  class TranslationFile < YamlFile
5
- DIR_PREFIX = %r{\A/?((marketplace_builder|app)/(translations)/|modules/((\w|-)*)/(private|public)/(translations)/)}
5
+ DIR_PREFIX = %r{\A/?((marketplace_builder|app)/(translations)/|(app/)?modules/((\w|-)*)/(private|public)/(translations)/)}
6
6
  TRANSLATION_FILTERS = Set.new(%w[t t_escape translate translate_escape]).freeze
7
7
  attr_reader :language
8
8
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlatformosCheck
4
- VERSION = "0.4.12"
4
+ VERSION = "0.4.14"
5
5
  end
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  spec.add_dependency('graphql', '~> 2.0.0')
31
- spec.add_dependency('liquid', '>= 5.4.0')
31
+ spec.add_dependency('liquid', '5.4.0')
32
32
  spec.add_dependency('nokogiri', '>= 1.12')
33
33
  spec.add_dependency('parser', '~> 3')
34
34
 
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.4.12
4
+ version: 0.4.14
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: 2024-04-13 00:00:00.000000000 Z
13
+ date: 2024-10-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: graphql
@@ -30,14 +30,14 @@ dependencies:
30
30
  name: liquid
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ">="
33
+ - - '='
34
34
  - !ruby/object:Gem::Version
35
35
  version: 5.4.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ">="
40
+ - - '='
41
41
  - !ruby/object:Gem::Version
42
42
  version: 5.4.0
43
43
  - !ruby/object:Gem::Dependency
@@ -373,7 +373,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
373
373
  - !ruby/object:Gem::Version
374
374
  version: '0'
375
375
  requirements: []
376
- rubygems_version: 3.5.7
376
+ rubygems_version: 3.5.18
377
377
  signing_key:
378
378
  specification_version: 4
379
379
  summary: A platformOS App Linter