lhj-tools 0.2.75 → 0.2.76

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: 5e5b22cf3aed7dd2a1da0fa7815a55275c0118d3ae130bab1ad44afea25f81e2
4
- data.tar.gz: b833c76e141e5b0ffa0037aad3f943b3c86d8ee5f6303c183150644b13269ebc
3
+ metadata.gz: 0ff453988d6ea9c2bb877d84e1ecf252763a5255cd40f037f11fccc343fb29b7
4
+ data.tar.gz: ff065515c59fd2b7fd2bbc1dd9d6797b095b7568f74d16c67466e495b398585e
5
5
  SHA512:
6
- metadata.gz: b3e75769782d140d16ca06b5e0518c9f0a5d8657fb0f88eb012913674734c11026e22c630b951449629e8a3ca94bc0220f1302c599b82a1630acaaaef2bb6940
7
- data.tar.gz: d49c7806545e0ab67b843f933663f588ed9f2ab2c14f918487c286844891cb932a827cd373e0fb66a0be8e7548e1e90a5eb97ea46bd5ab32e4b5dcc3b1621a71
6
+ metadata.gz: 7c57ef0fa0e8efe87101e22717836e7da3bb61c7b2e05bc731f09989042f65f03d5d16229fa03f7dde3439ae77db3ec170c0aa442ccc116d437b83029a215e7c
7
+ data.tar.gz: 99009572f8b1a2880fd5f85458b360edc625f84fd32a40c6a8ed28b93df971a1428a066a0d3180f6bfbc0293f9493e99b0fff78e73a5211b2ca940593d23c6ba
@@ -2,7 +2,8 @@
2
2
  module Lhj
3
3
  class IosApiAvailableCheckHelper
4
4
 
5
- API_AVAILABLE_KEY_BEGIN_REGEX = /@available\(/.freeze
5
+ API_AVAILABLE_KEY_BEGIN_REGEX = /@available/.freeze
6
+ BLOCK_KEY_BEGIN_REGEX = /\^/.freeze
6
7
 
7
8
  def self.check(path, type = 'm')
8
9
  all_files = Dir.glob("#{path}/**/*.{#{type}}").reject do |p|
@@ -10,9 +11,13 @@ module Lhj
10
11
  end
11
12
  result = {}
12
13
  all_files.each do |f|
13
- wrapper_lines = find_available_wrapper(f)
14
- infos = handle_file(f, wrapper_lines)
15
- result[File.basename(f)] = infos if infos.length.positive?
14
+ file_name = File.basename(f)
15
+ wrapper_map = find_available_wrapper(f)
16
+ # block循环引用提醒
17
+ handle_block_notify(file_name, wrapper_map[:blocks]) if wrapper_map[:blocks].length.positive?
18
+ # 处理高版本api提示
19
+ infos = handle_available_file(f, wrapper_map[:avails])
20
+ result[file_name] = infos if infos.length.positive?
16
21
  end
17
22
  # result
18
23
  # show_result(result)
@@ -30,10 +35,12 @@ module Lhj
30
35
  end
31
36
 
32
37
  def self.find_available_wrapper(file)
33
- lines = []
38
+ available_lines = []
39
+ block_lines = []
34
40
  File.open(file, 'r') do |f|
35
41
  multi_comment = false
36
42
  available_idx = 0
43
+ block_idx = 0
37
44
  f.readlines.each_with_index do |line, idx|
38
45
  multi_comment = true if line =~ %r{/\*} && line !~ %r{\*/} && !multi_comment
39
46
  if line !~ %r{/\*} && line =~ %r{\*/} && multi_comment
@@ -43,17 +50,42 @@ module Lhj
43
50
 
44
51
  next if multi_comment
45
52
  next if line =~ %r{\s*//}
46
- next unless line =~ API_AVAILABLE_KEY_BEGIN_REGEX || available_idx.positive?
47
53
 
48
- available_idx += 1 if line =~ /\{/
49
- available_idx -= 1 if line =~ /\}/
50
- lines << { idx: idx }
54
+ if line =~ API_AVAILABLE_KEY_BEGIN_REGEX || available_idx.positive?
55
+ available_idx += 1 if line =~ /\{/
56
+ available_idx -= 1 if line =~ /\}/
57
+ available_lines << { idx: idx }
58
+ end
59
+ if (line =~ BLOCK_KEY_BEGIN_REGEX && line !~ /^\s*[+-]/ && line !~ /dispatch_get_main_queue/) || block_idx.positive?
60
+ line_position = block_idx.zero? ? :start : :process
61
+ block_idx += 1 if line =~ /\{/
62
+ block_idx -= 1 if line =~ /\}/
63
+ line_position = :end if block_idx.zero?
64
+ block_lines << { idx: idx, line: line, position: line_position }
65
+ end
51
66
  end
52
67
  end
53
- lines
68
+ { avails: available_lines, blocks: block_lines }
69
+ end
70
+
71
+ def self.handle_block_notify(file_name, wrapper_lines)
72
+ arr = wrapper_lines.filter { |l| l[:position] != :start }
73
+ arr.filter! { |l| l[:position] != :end }
74
+ arr.filter! { |l| l[:line] =~ /self/ || l[:line] =~ /\s+_/ }
75
+ arr.filter! { |l| l[:line] !~ /\^/ }
76
+ arr.filter! { |l| l[:line] !~ /weak/ }
77
+ arr.filter! { |l| l[:line] !~ /strong/ }
78
+ return if arr.empty?
79
+
80
+ puts "源文件:#{file_name}"
81
+ arr.each do |l|
82
+ puts "第#{l[:idx] + 1}行:"
83
+ puts l[:line].strip
84
+ end
85
+ puts "\n"
54
86
  end
55
87
 
56
- def self.handle_file(file, wrapper_lines)
88
+ def self.handle_available_file(file, wrapper_lines)
57
89
  result = []
58
90
  File.open(file, 'r') do |f|
59
91
  multi_comment = false
data/lib/lhj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lhj
4
- VERSION = '0.2.75'
4
+ VERSION = '0.2.76'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.75
4
+ version: 0.2.76
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-10 00:00:00.000000000 Z
11
+ date: 2024-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj