An extension gem for RuboCop is available. The extension allows RuboCop to extract all examples from your documentation pages and identify any failures. With the extension enabled, a rubocop run will include all of the examples in your documentation seamlessly.
It is highly recommended to use the official rubocop-rspec extension in conjunction with RSpec::Documentation.
Add the following to your Gemfile:
gem 'rubocop-rspec-documentation', require: false
Add the following configuration to your .rubocop.yml to enable the extension:
# .rubocop.yml
require:
- rubocop-rspec-documentation
RuboCop will now look for files in rspec-documentation/pages/**/*.md and the provided extension will do the required parsing/extracting/offsetting, allowing RuboCop to work as normal.
The following cops are disabled for your documentation examples as they cannot be sensibly addressed within each example:
Naming/FileNameGemspec/RequiredRubyVersionStyle/FrozenStringLiteralCommentLint/RedundantCopEnableDirectiveThere is currently an issue using auto-correct with RuboCop, causing infinite loops with indentation corrections. Possibly a bug in RuboCop’s extension mechanism - avoid using auto-correct with your Markdown files until this has been resolved.