module Pluginscan # Extends Check with helpers for making patterns and ignores based on a list of function names class FunctionCheck < Check def initialize(check_hash) check_hash.default = [] check_hash[:patterns] = self.class.patterns(check_hash[:patterns], check_hash[:function_names]) check_hash[:ignores] = self.class.ignores(check_hash[:ignores], check_hash[:function_names]) super(check_hash) end def self.function_list(functions) # ^ Start of line # [^a-z0-9|_] Characters which would imply that the word isn't the whole function name # \s* any amount of whitespace # \\( a literal open bracket - i.e. the start of the function arguments functions.map{ |function| Regexp.new("(^|[^a-z0-9|_])(#{function})\s*\\(") } end def self.function_ignores(functions) # If the author is creating a similarly named function then that should be ignored (?) functions.map { |function| Regexp.new("function\s+[^a-z0-9|_]?#{function}\s*\\(") } end private def self.patterns(patterns, function_names) Array(patterns) + function_list(function_names) end private def self.ignores(ignores, function_names) Array(ignores) + function_ignores(function_names) + CommentChecker::COMMENT_REGEXPS end end end