Showing 107 of 107 total issues
Prefer Rails.root.join('path/to')
. Open
CSV.foreach("#{Rails.root}/config/flickr_profiles.csv") do |row|
- Read upRead up
- Exclude checks
This cop is used to identify usages of file path joining process
to use Rails.root.join
clause. It is used to add uniformity when
joining paths.
Example: EnforcedStyle: arguments (default)
# bad
Rails.root.join('app/models/goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"
# good
Rails.root.join('app', 'models', 'goober')
Example: EnforcedStyle: slashes
# bad
Rails.root.join('app', 'models', 'goober')
File.join(Rails.root, 'app/models/goober')
"#{Rails.root}/app/models/goober"
# good
Rails.root.join('app/models/goober')
Context description should match /^when\b/, /^with\b/, or /^without\b/. Open
context 'for RSS with content module' do
- Exclude checks
Prefer response.parsed_body
to JSON.parse(response.body)
. Open
expect(JSON.parse(response.body).last).to match(hash_including('id' => 'http://some.mrss.url/feed1.xml'))
- Exclude checks
Add an empty line after subject
. Open
subject(:perform) { described_class.new.perform(id) }
- Exclude checks
Prefer have_received
for setting message expectations. Setup AlbumDetectionPhotoIterator
as a spy using allow
or instance_spy
. Open
expect(AlbumDetectionPhotoIterator).to receive(:new).
- Exclude checks
Prefer have_received
for setting message expectations. Setup Elasticsearch::Persistence.client.indices
as a spy using allow
or instance_spy
. Open
expect(Elasticsearch::Persistence.client.indices).to receive(:get_alias).with(name: described_class.alias_name).and_raise(Elasticsearch::Transport::Transport::Errors::NotFound)
- Exclude checks
Prefer using be_alias_exists
matcher over alias_exists?
. Open
expect(described_class.alias_exists?).to be_truthy
- Exclude checks
Prefer have_received
for setting message expectations. Setup Rails.logger
as a spy using allow
or instance_spy
. Open
expect(Rails.logger).to receive(:warn)
- Exclude checks
Use and_return
for static values. Open
expect(AlbumDetector).to(receive(:detect_albums!).exactly(5).times { [] })
- Exclude checks
Prefer using verifying doubles over normal doubles. Open
let(:flickr_group_client) { double('Flickr client for group call') }
- Exclude checks
Prefer allow
over expect
when configuring a response. Open
expect(Elasticsearch::Persistence).to receive(:client).and_return(nil)
- Exclude checks
Prefer using verifying doubles over normal doubles. Open
let(:feed) { double(Feedjira::Parser::Oasis::Mrss, entries: photos) }
- Exclude checks
Prefer using verifying doubles over normal doubles. Open
and_yield(double(MrssProfile, name: '3', id: 'http://some/mrss.url/feed.xml1')).
- Exclude checks
Empty file detected. Open
- Read upRead up
- Exclude checks
Enforces that Ruby source files are not empty.
Example:
# bad
# Empty file
# good
# File containing non commented source lines
Example: AllowComments: true (default)
# good
# File consisting only of comments
Example: AllowComments: false
# bad
# File consisting only of comments
Use to_formatted_s
instead. Open
[base_name, Time.current.to_s(:number)].join('-')
- Exclude checks
Omit the hash value. Open
MrssPhoto.gateway.update(mrss_entry.entry_id, script: script)
- Read upRead up
- Exclude checks
Checks hash literal syntax.
It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).
A separate offense is registered for each problematic pair.
The supported styles are:
- ruby19 - forces use of the 1.9 syntax (e.g.
{a: 1}
) when hashes have all symbols for keys - hash_rockets - forces use of hash rockets for all hashes
- nomixedkeys - simply checks for hashes with mixed syntaxes
- ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes
This cop has EnforcedShorthandSyntax
option.
It can enforce either the use of the explicit hash value syntax or
the use of Ruby 3.1's hash value shorthand syntax.
The supported styles are:
- always - forces use of the 3.1 syntax (e.g. {foo:})
- never - forces use of explicit hash literal value
- either - accepts both shorthand and explicit use of hash literal value
- consistent - forces use of the 3.1 syntax only if all values can be omitted in the hash
Example: EnforcedStyle: ruby19 (default)
# bad
{:a => 2}
{b: 1, :c => 2}
# good
{a: 2, b: 1}
{:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
{d: 1, 'e' => 2} # technically not forbidden
Example: EnforcedStyle: hash_rockets
# bad
{a: 1, b: 2}
{c: 1, 'd' => 5}
# good
{:a => 1, :b => 2}
Example: EnforcedStyle: nomixedkeys
# bad
{:a => 1, b: 2}
{c: 1, 'd' => 2}
# good
{:a => 1, :b => 2}
{c: 1, d: 2}
Example: EnforcedStyle: ruby19nomixed_keys
# bad
{:a => 1, :b => 2}
{c: 2, 'd' => 3} # should just use hash rockets
# good
{a: 1, b: 2}
{:c => 3, 'd' => 4}
Example: EnforcedShorthandSyntax: always (default)
# bad
{foo: foo, bar: bar}
# good
{foo:, bar:}
Example: EnforcedShorthandSyntax: never
# bad
{foo:, bar:}
# good
{foo: foo, bar: bar}
Example: EnforcedShorthandSyntax: either
# good
{foo: foo, bar: bar}
# good
{foo:, bar:}
Example: EnforcedShorthandSyntax: consistent
# bad - `foo` and `bar` values can be omitted
{foo: foo, bar: bar}
# bad - `bar` value can be omitted
{foo:, bar: bar}
# bad - mixed syntaxes
{foo:, bar: baz}
# good
{foo:, bar:}
# good - can't omit `baz`
{foo: foo, bar: baz}
The second argument to describe should be the method being tested. '#instance' or '.class'. Open
describe AlbumDetectionPhotoIterator, 'run' do
- Exclude checks
Spec path should end with album_detection_photo_iterator*run*_spec.rb
. Open
describe AlbumDetectionPhotoIterator, 'run' do
- Exclude checks
Omit the hash value. Open
get '/api/v1/image', params: params
- Read upRead up
- Exclude checks
Checks hash literal syntax.
It can enforce either the use of the class hash rocket syntax or the use of the newer Ruby 1.9 syntax (when applicable).
A separate offense is registered for each problematic pair.
The supported styles are:
- ruby19 - forces use of the 1.9 syntax (e.g.
{a: 1}
) when hashes have all symbols for keys - hash_rockets - forces use of hash rockets for all hashes
- nomixedkeys - simply checks for hashes with mixed syntaxes
- ruby19nomixed_keys - forces use of ruby 1.9 syntax and forbids mixed syntax hashes
This cop has EnforcedShorthandSyntax
option.
It can enforce either the use of the explicit hash value syntax or
the use of Ruby 3.1's hash value shorthand syntax.
The supported styles are:
- always - forces use of the 3.1 syntax (e.g. {foo:})
- never - forces use of explicit hash literal value
- either - accepts both shorthand and explicit use of hash literal value
- consistent - forces use of the 3.1 syntax only if all values can be omitted in the hash
Example: EnforcedStyle: ruby19 (default)
# bad
{:a => 2}
{b: 1, :c => 2}
# good
{a: 2, b: 1}
{:c => 2, 'd' => 2} # acceptable since 'd' isn't a symbol
{d: 1, 'e' => 2} # technically not forbidden
Example: EnforcedStyle: hash_rockets
# bad
{a: 1, b: 2}
{c: 1, 'd' => 5}
# good
{:a => 1, :b => 2}
Example: EnforcedStyle: nomixedkeys
# bad
{:a => 1, b: 2}
{c: 1, 'd' => 2}
# good
{:a => 1, :b => 2}
{c: 1, d: 2}
Example: EnforcedStyle: ruby19nomixed_keys
# bad
{:a => 1, :b => 2}
{c: 2, 'd' => 3} # should just use hash rockets
# good
{a: 1, b: 2}
{:c => 3, 'd' => 4}
Example: EnforcedShorthandSyntax: always (default)
# bad
{foo: foo, bar: bar}
# good
{foo:, bar:}
Example: EnforcedShorthandSyntax: never
# bad
{foo:, bar:}
# good
{foo: foo, bar: bar}
Example: EnforcedShorthandSyntax: either
# good
{foo: foo, bar: bar}
# good
{foo:, bar:}
Example: EnforcedShorthandSyntax: consistent
# bad - `foo` and `bar` values can be omitted
{foo: foo, bar: bar}
# bad - `bar` value can be omitted
{foo:, bar: bar}
# bad - mixed syntaxes
{foo:, bar: baz}
# good
{foo:, bar:}
# good - can't omit `baz`
{foo: foo, bar: baz}
Prefer allow
over expect
when configuring a response. Open
expect(ImageSearch).to receive(:new).with('some query', size: 11, from: 10, flickr_groups: %w[fg1 fg2], flickr_users: %w[fu1 fu2], mrss_names: %w[4 9]).and_return(image_search)
- Exclude checks