Sha256: 23370745a161b6108eecf9ec69c7da32db3644216a9a01f266374f334d3cc064

Contents?: true

Size: 1.96 KB

Versions: 18

Compression:

Stored size: 1.96 KB

Contents

module Lhj
  class TraditionalCheckHelper
    def self.check(path, ignore_path, type = 'm,h,pch')
      ignore_file = File.join(ignore_path, '.checkignore')
      ignore_list = []
      ignore_list = File.readlines(ignore_file).map { |f| f.gsub(/\n/, '') } if File.exist?(ignore_file)
      check_ignore(path, type: type, ignore: ignore_list)
    end

    def self.check_ignore(path, type: 'm,h,pch', ignore: [])
      result = {}
      all_files = Dir.glob("#{path}/**/*.{#{type}}").reject do |p|
        p =~ /Pods/ || ignore.include?(File.basename(p))
      end
      all_files.each do |f|
        infos = handle_file(f)
        next unless infos.length.positive?

        result[File.basename(f)] = infos
      end
      result.keys.each_slice(10) { |a| notify(result.slice(*a)) }
    end

    def self.show_result(result)
      result.each do |k, v|
        puts k
        v.each do |o|
          puts "第#{o[:idx]}行:"
          puts o[:cn]
          puts o[:hk]
        end
      end
    end

    def self.handle_file(file)
      result = []
      File.open(file, 'r') do |f|
        f.readlines.each_with_index do |line, idx|
          next if line =~ %r{//}
          next if line =~ /#/
          next if line.strip =~ /^\*/
          next if line =~ /log|Log|LOG/
          next unless line =~ /[\u4e00-\u9fa5]/
          next unless Lhj::Trans::Helper.instance.contain_zh_hk(line)

          result << { idx: idx + 1, cn: line.strip, hk: Lhj::Trans::Helper.instance.trans_zh_hk_str(line).strip }
        end
      end
      result
    end

    def self.robot_url
      'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807'
    end

    def self.notify(result)
      temp = Lhj::ErbTemplateHelper.load('traditional_code_notify')
      temp_result = Lhj::ErbTemplateHelper.render(temp, { result: result }, '-')
      puts temp_result
      Lhj::Dingtalk.post_message_robot(robot_url, 'check code', temp_result)
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
lhj-tools-0.2.37 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.36 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.35 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.34 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.33 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.32 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.31 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.30 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.29 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.28 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.27 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.26 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.25 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.24 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.23 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.21 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.20 lib/lhj/helper/traditional_check_helper.rb
lhj-tools-0.2.19 lib/lhj/helper/traditional_check_helper.rb