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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d4df17e0075935e288786dbcb1eb807eda3893465f5ae4b5976d97f48714310
4
- data.tar.gz: 32c498e301120b65351f78e83246561b42a9266434f168d107859ef6cf0835b4
3
+ metadata.gz: def91da3d189d60c41a79d2a2cbc3b9f6123bf128ae65ddd53d0d5875df056f4
4
+ data.tar.gz: 980a8eab47e8fc2bb221fcb35de26e39d5fd2fee49faef13c3f0ff587931b571
5
5
  SHA512:
6
- metadata.gz: 3a8662886fbc67a0f541bde696279d9c64a3c03ce66785c2d35df27ccb680d51e16d175e33ee59dfed4b8318fc80cf30aa089ac0122dbf8f426ec0b907c3169b
7
- data.tar.gz: 8a8f70af5c47cd87340f3e8b0283ba42e33ecb924fb795722e95f93f81f54fd8bb0f3524a501ed6311dfcf4f83f26ddde642ac6d2f2469b223dec78b250126bc
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.missed?(namespace:, const_name:)
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
- if namespace
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
- missed_const_name = e.message[/uninitialized constant (.+)$/, 1]
54
- if missed_const_name != const_name && !const_name.start_with?(missed_const_name) && !missed_const_name.delete_prefix(namespace) == const_name
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
- Dir.glob(glob).flat_map do |file_path|
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.constant_missed?(namespace: parsed_const.namespace, const_name: parsed_const.const_name)
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"].colorize(:light_blue)
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"].colorize(:yellow)
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].colorize(:light_magenta)} in #{parsed_const.namespace}
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
@@ -1,3 +1,3 @@
1
1
  module ConstStricter
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -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 constant_missed?(namespace:, const_name:) = ConstResolver.missed?(namespace:, const_name:)
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.1.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-03 00:00:00.000000000 Z
11
+ date: 2025-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize