Class: RuboCop::Cop::AI::AdverbSpam

Inherits:
Base
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector, T::Sig
Defined in:
lib/rubocop/cop/ai/adverb_spam.rb

Overview

This cop checks for comments that contain an excessive sequence of adverbs or seemingly random words, which are often generated by malfunctioning AI tools or LLM doc generators.

Examples:

# bad
# @param c_m [String] securely accurately dynamically visually intuitively conditionally ...

# good
# @param c_m [String] the properly formatted parameter

Constant Summary collapse

MSG =

Detailed explanation of what the cop expects to find and correct when triggered.

T.let('Avoid AI-generated spam inside comments (excessive adverbs/meaningless words).', String)
SPAM_PATTERN =

Pattern to match sequences of 2 or more words ending in ‘ly’ including optional spaces and punctuation in between (but NOT newlines).

T.let(/(?:[ \t]*\b[a-zA-Z]+ly\b[ \t,.]*){2,}/i, Regexp)

Instance Method Summary collapse

Instance Method Details

#on_new_investigationObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rubocop/cop/ai/adverb_spam.rb', line 38

def on_new_investigation
  processed_source.comments.each do |comment|
    text = comment.text
    next unless text.match?(SPAM_PATTERN)

    add_offense(comment) do |corrector|
      new_text = text.gsub(SPAM_PATTERN, '').rstrip

      corrector.replace(comment, new_text)
    end
  end
end