const_stricter 1.1.1 → 1.2.0
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/docs/lint_dummy.jpg +0 -0
- data/lib/const_stricter/const_resolver.rb +11 -8
- data/lib/const_stricter/tasks/lint.rake +13 -5
- data/lib/const_stricter/version.rb +1 -1
- data/lib/const_stricter.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: def91da3d189d60c41a79d2a2cbc3b9f6123bf128ae65ddd53d0d5875df056f4
|
4
|
+
data.tar.gz: 980a8eab47e8fc2bb221fcb35de26e39d5fd2fee49faef13c3f0ff587931b571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46c68bda0085075cc86d994b4b537511e8c939d69447a5b9b92872097f6e61fee93943b573eb66e7f264acfb3848fb4166ae580d17280596af27be22cd3a6eee
|
7
|
+
data.tar.gz: 995a34e863408121b2b9f4bd0cc1ce062485f8317f534e58ec48f21b803d0dcac49bf59cd609a3000f51df72f3b9e9f1d7b6420bb79c8b15681683d4f04007d7
|
data/docs/lint_dummy.jpg
CHANGED
Binary file
|
@@ -8,7 +8,7 @@ module ConstStricter
|
|
8
8
|
@cache = {}
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.
|
11
|
+
def self.missing?(namespace:, const_name:)
|
12
12
|
evaluate(namespace:, const_name:) != nil
|
13
13
|
end
|
14
14
|
|
@@ -44,14 +44,17 @@ module ConstStricter
|
|
44
44
|
|
45
45
|
resolved_paths << cache_key
|
46
46
|
|
47
|
-
|
48
|
-
Object.const_get(namespace).const_get(const_name, inherit)
|
49
|
-
else
|
50
|
-
Object.const_get(const_name, inherit)
|
51
|
-
end
|
47
|
+
(namespace ? Object.const_get(namespace) : Object).const_get(const_name, inherit)
|
52
48
|
rescue NameError => e
|
53
|
-
|
54
|
-
|
49
|
+
missing_name =
|
50
|
+
if e.respond_to?(:missing_name)
|
51
|
+
# activesupport/lib/active_support/core_ext/name_error.rb
|
52
|
+
e.missing_name
|
53
|
+
else
|
54
|
+
e.message[/uninitialized constant (.+)$/, 1]
|
55
|
+
end
|
56
|
+
|
57
|
+
if missing_name != const_name && !const_name.start_with?(missing_name) && !missing_name.delete_prefix(namespace) == const_name
|
55
58
|
# срабатывание может быть вызвано не тем, что не существует искомая константа,
|
56
59
|
# а тем, что есть несвязанная ошибка в коде вызываемого класса/модуля
|
57
60
|
raise
|
@@ -5,8 +5,10 @@ namespace :const_stricter do
|
|
5
5
|
task :lint, [:glob] => :environment do |_t, args|
|
6
6
|
glob = args[:glob] || "{app,lib}/**/*.rb"
|
7
7
|
|
8
|
+
file_paths = Dir.glob(glob)
|
9
|
+
|
8
10
|
constants =
|
9
|
-
|
11
|
+
file_paths.flat_map do |file_path|
|
10
12
|
ConstStricter.constants_in_file(file_path:)
|
11
13
|
end
|
12
14
|
|
@@ -16,24 +18,30 @@ namespace :const_stricter do
|
|
16
18
|
constants.each do |parsed_const|
|
17
19
|
if parsed_const.dynamic
|
18
20
|
dynamic_constants[parsed_const] << parsed_const.location
|
19
|
-
elsif !ConstStricter.
|
21
|
+
elsif !ConstStricter.constant_missing?(namespace: parsed_const.namespace, const_name: parsed_const.const_name)
|
20
22
|
missed_constants[parsed_const] << parsed_const.location
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
26
|
unless dynamic_constants.empty?
|
25
|
-
puts ColorizedString["Dynamic constants"].
|
27
|
+
puts ColorizedString["Dynamic constants"].light_blue
|
26
28
|
dynamic_constants.each_key.with_index do |parsed_const, idx|
|
27
29
|
pretty_print(parsed_const, locations: dynamic_constants[parsed_const], number: idx + 1)
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
33
|
unless missed_constants.empty?
|
32
|
-
puts ColorizedString["Missed constants"].
|
34
|
+
puts ColorizedString["Missed constants"].yellow
|
33
35
|
missed_constants.each_key.with_index do |parsed_const, idx|
|
34
36
|
pretty_print(parsed_const, locations: missed_constants[parsed_const], number: idx + 1)
|
35
37
|
end
|
36
38
|
end
|
39
|
+
|
40
|
+
if dynamic_constants.empty? && missed_constants.empty?
|
41
|
+
puts "No problems found"
|
42
|
+
end
|
43
|
+
|
44
|
+
puts ColorizedString["#{file_paths.size} files scanned"].green
|
37
45
|
end
|
38
46
|
end
|
39
47
|
|
@@ -41,7 +49,7 @@ LOCATION_SEPARATOR = "\n ↳ "
|
|
41
49
|
|
42
50
|
def pretty_print(parsed_const, locations:, number:)
|
43
51
|
puts <<~TEXT
|
44
|
-
#{number}. #{ColorizedString[parsed_const.const_name].
|
52
|
+
#{number}. #{ColorizedString[parsed_const.const_name].light_magenta} in #{parsed_const.namespace}
|
45
53
|
↳ #{locations.join(LOCATION_SEPARATOR)}
|
46
54
|
TEXT
|
47
55
|
end
|
data/lib/const_stricter.rb
CHANGED
@@ -13,5 +13,5 @@ module ConstStricter
|
|
13
13
|
def constants_in_file(file_path:) = ConstParser.in_file(file_path:)
|
14
14
|
def constants_in_code(code:) = ConstParser.in_code(code:)
|
15
15
|
|
16
|
-
def
|
16
|
+
def constant_missing?(namespace:, const_name:) = ConstResolver.missing?(namespace:, const_name:)
|
17
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: const_stricter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergei Malykh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-09-
|
11
|
+
date: 2025-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|