rubocop-jbuilder 0.1.1 → 0.1.2

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: 65d8956a31b6c1e7a41da5b6f141d6e87ad3c57aaaf177001a309309966cb1f1
4
- data.tar.gz: 3aecca35e0f09f13d09336918a3d4337f9f5968434cf2cba837489ef6a7a0b10
3
+ metadata.gz: 7643a97e9b823f3197b2c8b1330dc168860c864d8c24fd07e7c3cca98d9d63fe
4
+ data.tar.gz: e92acc7906a5b0e4d1a5eecdb939bab8e1318540da1025b3c5fa80b056f67d6b
5
5
  SHA512:
6
- metadata.gz: 93dc1a5baab5301e85af4f4261d22dbda7c100a8f01160fbbc750666aa3a297d0db6916436e70aea7bcee874479010fc6c2ad752e6150be474dd096bc4d3fb70
7
- data.tar.gz: 420c7475ea90388c43174aa979bd71c61e6aceb1a37668d47cdb372b4f6d87078cab6bd6924f7fcfb537ef9fcf107a101045c5b3bfa213258ea3323ca6b680db
6
+ metadata.gz: 7ea81e6dc735622da7c99d21b5c0c4d8cc9b92f930aba1faa3d00947d06250269cbe32d7d20ec072146985111a46316e7c240d2477617270b551ea38a555824c
7
+ data.tar.gz: 2862246d08ca05e6e155bb7facc515cba9d59e41a21586004c2318197af217541c318470bf19e5c267d7f83d0b7d71322651b94298a2036794fa3b86af7ccc9a
data/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
1
  ## [Unreleased]
2
+ - Fix PartialExists to search for multiple local paths
3
+ - Fix PartialExists to search partials without `.json`
2
4
 
3
5
  ## [0.1.0] - 2024-01-08
4
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
3
+ require "pathname"
4
4
 
5
5
  TEST_FILENAME = File.join(Dir.pwd, "app/views/testing/nested/show.json.jbuilder")
6
6
 
@@ -19,37 +19,37 @@ module RuboCop
19
19
 
20
20
  def on_send(node)
21
21
  has_partial?(node) do |actual|
22
- all_paths = get_view_paths_from(actual)
22
+ all_globs = get_view_globs_from(actual)
23
23
 
24
- return if all_paths.any? { |full_path| File.exist?(full_path) }
24
+ return if all_globs.any? { |glob| Dir.glob(glob).any? }
25
25
 
26
26
  base_path = rails_root_dirname(node)
27
- relative_paths = all_paths.map { |full_path| relative_path(full_path, base_path) }
27
+ relative_paths = all_globs.map { |glob| relative_path(glob, base_path) }
28
28
  add_offense(actual, message: format(MSG, paths: relative_paths.join(", ")))
29
29
  end
30
30
  end
31
31
 
32
32
  private
33
33
 
34
- def get_view_paths_from(node)
34
+ def get_view_globs_from(node)
35
35
  partial = node.source[1..-2]
36
36
  segments = partial.split("/")
37
- segments.last.sub!(/.*/, '_\&.json.jbuilder')
37
+ segments.last.sub!(/.*/, '_\&*.jbuilder')
38
38
 
39
39
  specific_path = segments.count != 1
40
40
  return [File.join(rails_views_dirname(node), *segments)] if specific_path
41
41
 
42
- paths = []
42
+ globs = []
43
43
  current_dirname = sut_dirname(node)
44
44
  while current_dirname != rails_views_dirname(node)
45
- paths << File.join(current_dirname, *segments)
45
+ globs << File.join(current_dirname, *segments)
46
46
  current_dirname = File.expand_path("..", current_dirname)
47
47
  end
48
- paths
48
+ globs
49
49
  end
50
50
 
51
- def relative_path(full_path, base_path)
52
- full = Pathname.new(full_path)
51
+ def relative_path(glob, base_path)
52
+ full = Pathname.new(glob.sub("*", ""))
53
53
  base = Pathname.new(base_path)
54
54
  full.relative_path_from(base).to_s
55
55
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Jbuilder
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-jbuilder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carlos Molina A
@@ -41,7 +41,7 @@ files:
41
41
  - LICENSE.txt
42
42
  - README.md
43
43
  - Rakefile
44
- - app/views/testing/_exists.json.jbuilder
44
+ - app/views/testing/_exists.jbuilder
45
45
  - config/default.yml
46
46
  - lib/rubocop-jbuilder.rb
47
47
  - lib/rubocop/cop/jbuilder/partial_exists.rb