{"record":{"id":"ae21ba7a12a11a79","repo":"rubocop/rubocop","slug":"passing-a-project-root-directory-to-inject-defaul","errorCode":null,"errorMessage":"Passing a project root directory to `inject_defaults!` is no longer supported.","messagePattern":"Passing a project root directory to `inject_defaults!` is no longer supported\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/rubocop/config_loader.rb","lineNumber":166,"sourceCode":"\n      def default_configuration\n        @default_configuration ||= begin\n          print 'Default ' if debug?\n          load_file(DEFAULT_FILE)\n        end\n      end\n\n      # This API is primarily intended for testing and documenting plugins.\n      # When testing a plugin using `rubocop/rspec/support`, the plugin is loaded automatically,\n      # so this API is usually not needed. It is intended to be used only when implementing tests\n      # that do not use `rubocop/rspec/support`.\n      def inject_defaults!(config_yml_path)\n        if Pathname(config_yml_path).directory?\n          warn Rainbow(<<~MESSAGE).yellow, uplevel: 1\n            Use config YAML file path instead of project root directory.\n            e.g., `path/to/config/default.yml`\n          MESSAGE\n          raise ArgumentError,\n                'Passing a project root directory to `inject_defaults!` is no longer supported.'\n        end\n\n        path = config_yml_path.to_s\n        hash = ConfigLoader.load_yaml_configuration(path)\n        config = Config.new(hash, path).tap(&:make_excludes_absolute)\n\n        @default_configuration = ConfigLoader.merge_with_default(config, path)\n      end\n\n      # Returns the path RuboCop inferred as the root of the project. No file\n      # searches will go past this directory.\n      # @deprecated Use `RuboCop::ConfigFinder.project_root` instead.\n      def project_root\n        warn Rainbow(<<~WARNING).yellow, uplevel: 1\n          `RuboCop::ConfigLoader.project_root` is deprecated and will be removed in RuboCop 2.0. \\\n          Use `RuboCop::ConfigFinder.project_root` instead.\n        WARNING","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/rubocop/rubocop/blob/ea712edf2b1b14cb9b3f748bb1003a6141c95c5e/lib/rubocop/config_loader.rb#L148-L184","documentation":"`RuboCop::ConfigLoader.inject_defaults!` merges a plugin's `default.yml` into RuboCop's default configuration. Older plugin ecosystems passed the gem's project root directory; the API now requires the exact YAML file path. Passing a directory first prints a deprecation warning, then raises `ArgumentError`. It is a testing/documentation API — with `rubocop/rspec/support` it is usually unneeded.","triggerScenarios":"Calling `RuboCop::ConfigLoader.inject_defaults!(File.expand_path(__dir__))` or `inject_defaults!(gem_root)` (a directory) instead of `inject_defaults!('path/to/config/default.yml')`; old README examples from rubocop-extension gems copied into a new plugin.","commonSituations":"Maintaining a rubocop plugin (e.g. rubocop-foo with its own cops) whose spec support predates the API change; upgrading RuboCop in a gem that still injects defaults via the directory convention.","solutions":["Pass the full path to the YAML file: `RuboCop::ConfigLoader.inject_defaults!(File.join(__dir__, 'config', 'default.yml'))`.","If the call lives in a third-party plugin gem, upgrade it to a release compatible with current RuboCop.","If your specs use `rubocop/rspec/support`, delete the `inject_defaults!` call entirely — the plugin loads automatically.","The deprecation warning printed before the raise shows the exact expected form; mirror it."],"exampleFix":"# before\nRuboCop::ConfigLoader.inject_defaults!(File.expand_path(__dir__))\n\n# after\nRuboCop::ConfigLoader.inject_defaults!(File.join(__dir__, 'config', 'default.yml'))","handlingStrategy":"type-guard","validationCode":"path = File.expand_path('config/default.yml', __dir__)\nraise ArgumentError, 'pass the YAML file, not a directory' if File.directory?(path)\nraise ArgumentError, 'missing default.yml' unless File.file?(path)\nRuboCop::ConfigLoader.inject_defaults!(path)","typeGuard":"def defaults_yaml_path?(path)\n  path = Pathname(path)\n  path.file? && path.extname == '.yml'\nend","tryCatchPattern":"begin\n  RuboCop::ConfigLoader.inject_defaults!(config_path)\nrescue ArgumentError => e\n  raise if e.message !~ /project root directory/\n  # retry with the YAML file inside the passed directory\n  RuboCop::ConfigLoader.inject_defaults!(File.join(config_path, 'config', 'default.yml'))\nend","preventionTips":["Always build the path to `config/default.yml` explicitly; never pass a directory to inject_defaults!.","Prefer `rubocop/rspec/support` in extension specs — it loads plugins automatically and removes the need for inject_defaults!.","Read the deprecation warning output; RuboCop prints the exact expected call form before raising.","When maintaining a plugin, add a spec that exercises the support setup so API changes fail your build first."],"tags":["rubocop","plugin-api","configuration","breaking-change","argumenterror"],"backgroundTag":"breaking-api-change","analyzedSha":"ea712edf2b1b14cb9b3f748bb1003a6141c95c5e","analyzedAt":"2026-08-21T16:16:18.930Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}