Sha256: 543b3dc9df30bd47f6afcefa5845106d666e40c58df7e6a5df01be6ffe76913e

Contents?: true

Size: 1.75 KB

Versions: 35

Compression:

Stored size: 1.75 KB

Contents

require 'digest'
require 'precheck/rule'

module Precheck
  class CurseWordsRule < TextRule
    def self.key
      :curse_words
    end

    def self.env_name
      "RULE_CURSE_WORDS"
    end

    def self.friendly_name
      "No curse words"
    end

    def self.description
      "including words that might be considered objectionable"
    end

    def rule_block
      return lambda { |text|
        return RuleReturn.new(validation_state: Precheck::VALIDATION_STATES[:passed]) if text.to_s.strip.empty?

        all_metadata_words_list = text.to_s.downcase.split
        metadata_word_hashes = all_metadata_words_list.map { |word| Digest::SHA256.hexdigest(word) }
        curse_hashes_set = hashed_curse_word_set

        found_words = []
        metadata_word_hashes.each_with_index do |word, index|
          if curse_hashes_set.include?(word)
            found_words << all_metadata_words_list[index]
          end
        end

        if found_words.length > 0
          friendly_found_words = found_words.join(', ')
          UI.verbose "#{self.class.name.split('::').last ||= self.class.name} found potential curse words 😬"
          UI.verbose "Keep in mind, these words might be ok given the context they are used in"
          UI.verbose "Matched: \"#{friendly_found_words}\""
          return RuleReturn.new(validation_state: VALIDATION_STATES[:failed], failure_data: "found: #{friendly_found_words}")
        else
          return RuleReturn.new(validation_state: VALIDATION_STATES[:passed])
        end
      }
    end

    def hashed_curse_word_set
      curse_hashes = []
      File.open(File.dirname(__FILE__) + '/rules_data/curse_word_hashes/en_us.txt').each do |line|
        curse_hashes << line.to_s.strip
      end
      return curse_hashes.to_set
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
fastlane-2.47.0.beta.20170717010003 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.47.0.beta.20170716010003 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.47.0.beta.20170715010003 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.47.0.beta.20170714010002 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.47.0.beta.20170713010003 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.1 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.47.0.beta.20170712010003 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.47.0.beta.20170711010003 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.0 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.0.beta.20170710010003 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.0.beta.20170709010003 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.0.beta.20170708010003 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.0.beta.20170707010003 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.0.beta.20170706133903 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.0.beta.20170706133802 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.0.beta.20170706133702 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.0.beta.20170706133602 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.0.beta.20170706133502 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.46.0.beta.20170706133402 precheck/lib/precheck/rules/curse_words_rule.rb
fastlane-2.45.0 precheck/lib/precheck/rules/curse_words_rule.rb