{"record":{"id":"a8616756350d1a72","repo":"rubocop/rubocop","slug":"unrecognized-cop-or-department-name-s","errorCode":null,"errorMessage":"Unrecognized cop or department: %<name>s.","messagePattern":"Unrecognized cop or department: %<name>s\\.","errorType":"exception","errorClass":"RuboCop::IncorrectCopNameError","httpStatus":null,"severity":"error","filePath":"lib/rubocop/options.rb","lineNumber":359,"sourceCode":"  class OptionsValidator\n    class << self\n      SYNTAX_DEPARTMENTS = %w[Syntax Lint/Syntax].freeze\n      private_constant :SYNTAX_DEPARTMENTS\n\n      # Cop name validation must be done later than option parsing, so it's not\n      # called from within Options.\n      def validate_cop_list(names)\n        return unless names\n\n        cop_names = Cop::Registry.global.names\n        departments = Cop::Registry.global.departments.map(&:to_s)\n\n        names.each do |name|\n          next if cop_names.include?(name)\n          next if departments.include?(name)\n          next if SYNTAX_DEPARTMENTS.include?(name)\n\n          raise IncorrectCopNameError, format_message_from(name, cop_names)\n        end\n      end\n\n      private\n\n      def format_message_from(name, cop_names)\n        message = 'Unrecognized cop or department: %<name>s.'\n        message_with_candidate = \"%<message>s\\nDid you mean? %<candidate>s\"\n        corrections = NameSimilarity.find_similar_names(name, cop_names)\n\n        if corrections.empty?\n          format(message, name: name)\n        else\n          format(message_with_candidate, message: format(message, name: name),\n                                         candidate: corrections.join(', '))\n        end\n      end\n    end","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/rubocop/rubocop/blob/ea712edf2b1b14cb9b3f748bb1003a6141c95c5e/lib/rubocop/options.rb#L341-L377","documentation":"RuboCop validates every name passed via --only or --except against Cop::Registry.global (cop names, department names, plus the special Syntax departments \"Syntax\" and \"Lint/Syntax\"). If a name matches none of these, it raises IncorrectCopNameError, and the message appends a \"Did you mean?\" suggestion computed by NameSimilarity.find_similar_names over all registered cop names.","triggerScenarios":"Running `rubocop --only Style/StringLterals` (typo), `--except Layout/LinetLength`, referencing a cop that was renamed or removed in a newer RuboCop, or naming a custom cop whose file was never required/registered before option validation runs.","commonSituations":"Typos in CI pipelines or in the `.rubocop` arguments file; upgrading RuboCop where cops were renamed or moved departments; using third-party cops without the corresponding `require:`/plugin entry in .rubocop.yml so they are not in the registry; stale cop lists kept in scripts.","solutions":["Read the \"Did you mean?\" line printed with the error and re-run with the suggested exact cop name.","Verify the exact spelling with `rubocop --show-cops` (or `rubocop --list-cops`) and copy the name from there.","If this appeared after a RuboCop upgrade, check the changelog for renamed/removed cops and update the list.","For custom/third-party cops, make sure the gem is required (plugins: or require: in .rubocop.yml) so the cop is registered before validation."],"exampleFix":"# before\nrubocop --only Style/StringLterals\n# after\nrubocop --only Style/StringLiterals","handlingStrategy":"validation","validationCode":"require 'rubocop'\n\nvalid = RuboCop::Cop::Registry.global.names\nvalid_depts = RuboCop::Cop::Registry.global.departments.map(&:to_s) + %w[Syntax Lint/Syntax]\n\ncop_list = %w[Style/StringLiterals Layout/LineLength]\nbad = cop_list.reject { |n| valid.include?(n) || valid_depts.include?(n) }\n# shell out only when the list is clean:\nabort \"Unknown cops: #{bad.join(', ')}\" unless bad.empty?","typeGuard":null,"tryCatchPattern":"begin\n  exit(RuboCop::CLI.new.run(ARGV))\nrescue RuboCop::IncorrectCopNameError => e\n  warn \"Fix cop names: #{e.message}\"\n  exit 2\nend","preventionTips":["Generate --only/--except lists from `rubocop --show-cops` output instead of typing names by hand.","Pin the rubocop version in Gemfile so cop names cannot change under you mid-project.","In CI, fail fast on IncorrectCopNameError instead of letting the lint step silently pass with exit 2 handling."],"tags":["rubocop","cli","option-validation","cop-registry","typo","did-you-mean"],"backgroundTag":"invalid-cli-argument","analyzedSha":"ea712edf2b1b14cb9b3f748bb1003a6141c95c5e","analyzedAt":"2026-08-21T16:16:18.930Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}