ezCater custom cops and shared RuboCop configuration.
RuboCop is a static code analyzer that can enforce style conventions as well as identify common problems.
Installation
Add this line to your application's Gemfile:
group :development do
gem "ezcater_rubocop", require: false
endOr to your gem's gemspec file:
spec.add_development_dependency "ezcater_rubocop"And then execute:
$ bundle install
Or install it yourself as:
$ gem install ezcater_rubocop
Configuration
To use one of the shared RuboCop configurations from this gem, you must define a .rubocop.yml file in your project:
inherit_gem:
ezcater_rubocop: conf/rubocop_rails.ymlFurther customization of RuboCop for your local project may be added to this file.
Available Configurations
- rubocop: Assumes RSpec is used and requires rubocop-rspec. This configuration should be used for gems.
- rubocop_gem: For use in Ruby gem projects, this inherits from the rubocop configuration.
- rubocop_rails: For Rails projects, this inherits from the rubocop configuration.
Documentation
Visit https://gemdocs.org/gems/ezcater_rubocop to view the documentation for our custom cops in the latest release.
Usage
Run rubocop for an entire project:
$ bundle exec rubocop
See the rubocop command-line for additional options including auto-generating
configuration for existing offenses and auto-correction.
Circle Script
This gem contains a script, circle_rubocop.rb, that can be used to run RuboCop in CI.
The behavior of the script is that all files are checked on main or if the rubocop configuration has changed. On non-main branches, only the files added or changed on the branch are checked.
For non-main branches, [rubocop skip] can be included in the commit message to skip
running rubocop.
Versioning
This gem is using Semantic Versioning. All version bumps should increment using MAJOR.MINOR.PATCH based on changes.
When adding a new cop, please enable the cop and release a new major version. This allows us to
constantly roll out improvements without clients having their suite break unknowingly. When a
breaking change is released, users can opt to use --regenerate-todo to update their TODO file. Do
not add cops with enabled: false unless you want that cop to always be disabled.
Custom Cops
-
FeatureFlagActive - Enforce the proper arguments are given to
EzcaterFeatureFlag.active? - FeatureFlagNameValid - Enforce correct flag name format is being used.
- GraphQL/NotAuthorizedScalarField - Enforces the use of authorization (pundit or, optionally, the guard pattern) for scalar fields. See examples within class comment for additional configuration.
-
RailsConfiguration - Enforce use of
Rails.configurationinstead ofRails.application.config. -
RequireGqlErrorHelpers - Use the helpers provided by
GQLErrorsinstead of raisingGraphQL::ExecutionErrordirectly. - RspecDotNotSelfDot - Enforce "." instead of "self." and "::" for example group description.
-
RspecMatchOrderedArray - Enforce use of
match_ordered_arraymatcher instead ofeqmatcher. This matcher comes from the ezcater_matchers gem. -
RspecNoResolveClassField - Do not use deprecated GraphQL testing interface
resolve_class_field. -
RspecRequireBrowserMock - Enforce use of
mock_ezcater_app,mock_chrome_browser&mock_custom_browserhelpers instead of mockingBrowserorEzBrowserdirectly. -
RspecRequireFeatureFlagMock - Enforce use of
mock_feature_flaghelper instead of mockingFeatureFlag.is_active?directly. -
RspecRequireHttpStatusMatcher - Use the HTTP status code matcher, like
expect(response).to have_http_status :bad_request, rather thanexpect(response.code).to eq 400 -
StyleDig - Recommend
digfor deeply nested access. -
Migration/BigintForeignKey - Use
#bigintinstead of#integerfor all foreign keys.
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install.
Releasing a New Version
Releases are automated via release-please. When commits following the Conventional Commits format are merged to main, release-please opens (or updates) a release PR that bumps version.rb and updates CHANGELOG.md automatically. Merging that PR triggers the publish-to-rubygems job, which tags the release and pushes the .gem file to rubygems.org.
You do not need to manually edit version.rb or CHANGELOG.md. Use the correct commit prefix to drive the version bump:
-
fix:→ patch bump -
feat:→ minor bump -
feat!:orBREAKING CHANGE:in the body → major bump
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ezcater/ezcater_rubocop.
Adding New Cops
New cops can be generated via the new_cop rake task which generates
the cop, the spec, updates imports, and adds configuration. Example:
rake 'new_cop[Ezcater/foo_bar]'Follow the instructions after the task executes and update code as necessary for consistency.
In addition, you need to:
- Add the cop to the "Custom Cops" section of this README
- Use a conventional commit prefix (
feat:for a non-breaking new cop,feat!:for a breaking one) so release-please bumps the version and updates the CHANGELOG automatically.
Version Bumps & Changelog Entries
Version bumps and CHANGELOG entries are managed automatically by release-please based on Conventional Commits. Use the correct prefix on your PR title (squash-and-merge is required):
| Commit prefix | Version bump | Example |
|---|---|---|
fix: |
Patch | fix: correct typo in cop message |
feat: |
Minor | feat: add StyleDig cop |
feat!: or BREAKING CHANGE: in body |
Major | feat!: enable StyleDig by default |
chore:, docs:, ci:
|
None | chore: update CI config |
chore: commits do not trigger a release. This keeps the CHANGELOG focused on changes that affect users of the gem.
License
The gem is available as open source under the terms of the MIT License.