lhj-tools 0.2.74 → 0.2.76

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7617205034e037486f6f9cb332e7064f49bd32d509d9f1e957c5df47100dabb
4
- data.tar.gz: 254627f1697ed73f5aeb332d8e9da0f15e2b356698e02d1ce695836d0e7139cf
3
+ metadata.gz: 0ff453988d6ea9c2bb877d84e1ecf252763a5255cd40f037f11fccc343fb29b7
4
+ data.tar.gz: ff065515c59fd2b7fd2bbc1dd9d6797b095b7568f74d16c67466e495b398585e
5
5
  SHA512:
6
- metadata.gz: 8f596ee969cb0231148e553cff8683280ea271dd4bf303ea6347c2963d6ee8f05b8802d05ebca7f174834aec3e09874b58ba16141df418420f1a44304584a1b6
7
- data.tar.gz: 8cdcccbca6add90899a7e0efb3c3b62a5c67bc9f7ba054c5c183b4e6626cb369da5dc6c11026090a46e059f9d6fb4f6b172f1d33fb523d42d6ce63714e5a75f0
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, line: line }
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
@@ -71,15 +103,15 @@ module Lhj
71
103
  # 2. 找到的行是否已available代码块
72
104
  next if wrapper_lines.length.positive? && wrapper_lines.any? { |w| w[:idx] == idx }
73
105
 
74
- result << { idx: idx + 1, line: line }
106
+ result << { idx: idx + 1, line: line.strip }
75
107
  end
76
108
  end
77
109
  result
78
110
  end
79
111
 
80
112
  def self.match_white_list_reg(line)
81
- regs ||= load_white_api_list
82
- regs.any? { |r| line =~ /#{r}/ }
113
+ @regs ||= load_white_api_list
114
+ @regs.any? { |r| /#{r}/ =~ line }
83
115
  end
84
116
 
85
117
  def self.load_white_api_list
@@ -95,6 +127,7 @@ module Lhj
95
127
  def self.notify(result)
96
128
  temp = Lhj::ErbTemplateHelper.load('ios_avaliable_api_notify')
97
129
  temp_result = Lhj::ErbTemplateHelper.render(temp, { result: result, branch: git_branch }, '-')
130
+ puts temp_result
98
131
  Lhj::Dingtalk.post_message_robot(robot_url, 'check code', temp_result)
99
132
  end
100
133
 
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.74'
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.74
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