profile
viewpoint

Ask questionsCommentConfig needs ♥️

This class parses the special rubocop:disable comments in a source and provides a way to check if each cop is enabled at arbitrary line. lib/rubocop/comment_config.rb

Problem

  1. First of all it looks like a huge class. Over 200 lines.

  2. Class has many public methods, but tested only cop_enabled_at_line?.

  3. There are many cases with direct using private constant:

lib/rubocop/directive_comment.rb:
  16:       match = comment.text.match(CommentConfig::COMMENT_DIRECTIVE_REGEXP)

lib/rubocop/cop/lint/redundant_cop_disable_directive.rb:
  177:           match = comment.text.match(CommentConfig::COMMENT_DIRECTIVE_REGEXP)

lib/rubocop/cop/mixin/documentation_comment.rb:
  48:         CommentConfig::COMMENT_DIRECTIVE_REGEXP.match?(comment.text)

lib/rubocop/cop/mixin/line_length_help.rb:
  19:         comment.text.match?(CommentConfig::COMMENT_DIRECTIVE_REGEXP)
  82:         before_comment, = line.split(CommentConfig::COMMENT_DIRECTIVE_REGEXP)

lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb:
  73:           match = CommentConfig::COMMENT_DIRECTIVE_REGEXP.match(comment.text)

lib/rubocop/ext/processed_source.rb:
  8:         @comment_config ||= CommentConfig.new(self)

Soluttion

Refactor class. We have DirectiveComment that can get part of functionality. Add additional specs.

One more thing

Later we can add disable-next-line feature. See: https://github.com/rubocop/rubocop/issues/9505

rubocop/rubocop

Answer questions AndreiEres

@dvandersluis Could we close the issue?

useful!
source:https://uonfu.com/
Github User Rank List