class RuboCop::DirectiveComment
cops it contains.
special ‘rubocop:disable` and `rubocop:enable` comment and exposes what
This class wraps the `Parser::Source::Comment` object that represents a
def self.before_comment(line)
def self.before_comment(line) line.split(DIRECTIVE_COMMENT_REGEXP).first end
def all_cop_names
def all_cop_names exclude_redundant_directive_cop(cop_registry.names) end
def all_cops?
def all_cops? cops == 'all' end
def cop_names
def cop_names @cop_names ||= all_cops? ? all_cop_names : parsed_cop_names end
def cop_names_for_department(department)
def cop_names_for_department(department) names = cop_registry.names_for_department(department) has_redundant_directive_cop = department == REDUNDANT_DIRECTIVE_COP_DEPARTMENT has_redundant_directive_cop ? exclude_redundant_directive_cop(names) : names end
def department?(name)
def department?(name) cop_registry.department?(name) end
def department_names
Returns array of specified in this directive department names
def department_names splitted_cops_string.select { |cop| department?(cop) } end
def directive_count
def directive_count splitted_cops_string.count end
def disabled?
def disabled? %w[disable todo].include?(mode) end
def disabled_all?
def disabled_all? disabled? && all_cops? end
def enabled?
def enabled? mode == 'enable' end
def enabled_all?
def enabled_all? !disabled? && all_cops? end
def exclude_redundant_directive_cop(cops)
def exclude_redundant_directive_cop(cops) cops - [REDUNDANT_DIRECTIVE_COP] end
def in_directive_department?(cop)
def in_directive_department?(cop) department_names.any? { |department| cop.start_with?(department) } end
def initialize(comment, cop_registry = Cop::Registry.global)
def initialize(comment, cop_registry = Cop::Registry.global) @comment = comment @cop_registry = cop_registry @mode, @cops = match_captures end
def line_number
def line_number comment.source_range.line end
def match?(cop_names)
def match?(cop_names) parsed_cop_names.uniq.sort == cop_names.uniq.sort end
def match_captures
def match_captures @match_captures ||= comment.text.match(DIRECTIVE_COMMENT_REGEXP)&.captures end
def overridden_by_department?(cop)
def overridden_by_department?(cop) in_directive_department?(cop) && splitted_cops_string.include?(cop) end
def parsed_cop_names
def parsed_cop_names splitted_cops_string.map do |name| department?(name) ? cop_names_for_department(name) : name end.flatten end
def range
def range match = comment.text.match(DIRECTIVE_COMMENT_REGEXP) begin_pos = comment.source_range.begin_pos Parser::Source::Range.new( comment.source_range.source_buffer, begin_pos + match.begin(0), begin_pos + match.end(0) ) end
def single_line?
def single_line? !comment.text.start_with?(DIRECTIVE_COMMENT_REGEXP) end
def splitted_cops_string
def splitted_cops_string (cops || '').split(/,\s*/) end