un_used_methods 0.1.2 → 0.1.3
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 +4 -4
- data/lib/un_used_methods/analyzer.rb +18 -3
- data/lib/un_used_methods/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 165752d3ad48f228b8dc3314fb55c847df1669e46779fab24cd7ae22ee79c4fb
|
4
|
+
data.tar.gz: 17a1e0d278cbe0af632f040851401e7c62d7c08b262639ed522e6615ab128121
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d412e91fc1ff54838afcc323a46ac6156f5427abc167a9bf7201d563f0ea4be8c1d1d7b1d8e7c7737c38116cb9b431557855784253b9f99f6f3828877ece2f2
|
7
|
+
data.tar.gz: 734cdc3cd74a4f26d3470231942e7a9a97b18475aee25ecd344cdce55d75ff2c50fa875c6a66ff1d1017ae218b444fad0bf7473d7062cdc8eaeaea5df18f15ef
|
@@ -54,6 +54,9 @@ module UnUsedMethods
|
|
54
54
|
# Check if method is used in any file other than its own definition file
|
55
55
|
return true if file_contains_method_call?(files, definition_file, method_call_patterns)
|
56
56
|
|
57
|
+
# Check if the method is used in callbacks like `before_action` or `after_action`
|
58
|
+
return true if method_used_in_callback?(method, files)
|
59
|
+
|
57
60
|
# Check method usage within its own file
|
58
61
|
method_called_in_own_file?(definition_file, method_call_patterns)
|
59
62
|
end
|
@@ -61,7 +64,9 @@ module UnUsedMethods
|
|
61
64
|
def build_method_call_patterns(method)
|
62
65
|
[
|
63
66
|
/(\.|^|\s)#{method}\s*\(/, # Matches method calls with parameters
|
64
|
-
/(\.|^|\s)#{method}\b(?!\()
|
67
|
+
/(\.|^|\s)#{method}\b(?!\()/, # Matches method calls without parameters
|
68
|
+
/(\.|^|\s):#{method}\b/, # Matches method references as symbols (e.g., :method_name)
|
69
|
+
/\b#{method}\b/ # Matches method as a standalone word, e.g., when passed as an argument
|
65
70
|
]
|
66
71
|
end
|
67
72
|
|
@@ -79,6 +84,16 @@ module UnUsedMethods
|
|
79
84
|
patterns.any? { |pattern| content.scan(pattern).count > 1 }
|
80
85
|
end
|
81
86
|
|
87
|
+
def method_used_in_callback?(method, files)
|
88
|
+
# Create a dynamic regex pattern to match any Rails callback with the given method
|
89
|
+
callback_pattern = /\b(before|after|around|validate|commit|save|create|update|destroy)\w*\s*:#{method}\b/
|
90
|
+
|
91
|
+
files.any? do |file|
|
92
|
+
content = read_file(file)
|
93
|
+
content.match?(callback_pattern)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
82
97
|
def read_file(file)
|
83
98
|
content = File.read(file)
|
84
99
|
strip_comments(content, file)
|
@@ -87,8 +102,8 @@ module UnUsedMethods
|
|
87
102
|
def strip_comments(content, file)
|
88
103
|
case File.extname(file)
|
89
104
|
when ".rb"
|
90
|
-
# Remove Ruby comments
|
91
|
-
content.gsub(/#.*$/, "")
|
105
|
+
# Remove Ruby comments and strings
|
106
|
+
content.gsub(/#.*$/, "").gsub(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/, "")
|
92
107
|
when ".erb", ".html", ".haml", ".slim"
|
93
108
|
# Remove HTML, ERB, HAML, SLIM comments
|
94
109
|
content.gsub(/<!--.*?-->/m, "").gsub(/<%#.*?%>/m, "")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: un_used_methods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dhamo1107
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|