Method has too many lines. [15/5] (https://github.com/bbatsov/ruby-style-guide#short-methods) Open
def show
render template: 'pages/404', status: 404 and return if @organisation.nil?
organisations = Organisation.where(id: @organisation.id)
if current_user
@pending_org_admin = current_user.pending_org_admin? @organisation
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [15/5] (https://github.com/bbatsov/ruby-style-guide#short-methods) Open
def self.build params
params.require(:organisation).permit(
:superadmin_email_to_add,
:description,
:address,
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for show is too high. [24.49/15] (http://c2.com/cgi/wiki?AbcMetric) Open
def show
render template: 'pages/404', status: 404 and return if @organisation.nil?
organisations = Organisation.where(id: @organisation.id)
if current_user
@pending_org_admin = current_user.pending_org_admin? @organisation
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method has too many lines. [11/5] (https://github.com/bbatsov/ruby-style-guide#short-methods) Open
def create
# model filters for logged in users, but we check here if that user is an superadmin
# TODO refactor that to model responsibility?
org_params = OrganisationParams.build params
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [8/5] (https://github.com/bbatsov/ruby-style-guide#short-methods) Open
def update
params[:organisation][:superadmin_email_to_add] = params[:organisation_superadmin_email_to_add] if params[:organisation]
update_params = OrganisationParams.build params
return false unless user_can_edit? @organisation
if @organisation.update_attributes_with_superadmin(update_params)
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [8/5] (https://github.com/bbatsov/ruby-style-guide#short-methods) Open
def search
@parsed_params = SearchParamsParser.new(params)
@cat_name_ids = Category.name_and_id_for_what_who_and_how
@organisations = Queries::Organisations.search_by_keyword_and_category(
@parsed_params
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [8/5] (https://github.com/bbatsov/ruby-style-guide#short-methods) Open
def destroy
unless current_user.try(:superadmin?)
flash[:notice] = PERMISSION_DENIED
redirect_to organisation_path(params[:id]) and return false
end
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for destroy is too high. [16.4/15] (http://c2.com/cgi/wiki?AbcMetric) Open
def destroy
unless current_user.try(:superadmin?)
flash[:notice] = PERMISSION_DENIED
redirect_to organisation_path(params[:id]) and return false
end
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
TODO found Open
# TODO refactor that to model responsibility?
- Exclude checks
Line is too long. [124/90] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
params[:organisation][:superadmin_email_to_add] = params[:organisation_superadmin_email_to_add] if params[:organisation]
- Exclude checks
Use &&
instead of and
. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or) Open
redirect_to organisation_path(params[:id]) and return false
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Use the new Ruby 1.9 hash syntax. (https://github.com/bbatsov/ruby-style-guide#hash-literals) Open
render :template =>'organisations/index'
- Read upRead up
- Exclude checks
This cop 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
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}
Use &&
instead of and
. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or) Open
redirect_to organisation_path(params[:id]) and return false
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Prefer before_action
over before_filter
. Open
before_filter :authenticate_user!, :except => [:search, :index, :show]
- Read upRead up
- Exclude checks
This cop enforces the consistent use of action filter methods.
The cop is configurable and can enforce the use of the older somethingfilter methods or the newer somethingaction methods.
If the TargetRailsVersion is set to less than 4.0, the cop will enforce the use of filter methods.
Example: EnforcedStyle: action (default)
# bad
after_filter :do_stuff
append_around_filter :do_stuff
skip_after_filter :do_stuff
# good
after_action :do_stuff
append_around_action :do_stuff
skip_after_action :do_stuff
Example: EnforcedStyle: filter
# bad
after_action :do_stuff
append_around_action :do_stuff
skip_after_action :do_stuff
# good
after_filter :do_stuff
append_around_filter :do_stuff
skip_after_filter :do_stuff
Use &&
instead of and
. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or) Open
render template: 'pages/404', status: 404 and return if @organisation.nil?
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Use &&
instead of and
. (https://github.com/bbatsov/ruby-style-guide#no-and-or-or) Open
redirect_to organisations_path and return false
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end
Prefer single-quoted strings when you don't need string interpolation or special symbols. (https://github.com/bbatsov/ruby-style-guide#consistent-string-literals) Open
render action: "edit"
- Read upRead up
- Exclude checks
Checks if uses of quotes match the configured preference.
Example: EnforcedStyle: single_quotes (default)
# bad
"No special symbols"
"No string interpolation"
"Just text"
# good
'No special symbols'
'No string interpolation'
'Just text'
"Wait! What's #{this}!"
Example: EnforcedStyle: double_quotes
# bad
'Just some text'
'No special chars or interpolation'
# good
"Just some text"
"No special chars or interpolation"
"Every string in #{project} uses double_quotes"
Use the new Ruby 1.9 hash syntax. (https://github.com/bbatsov/ruby-style-guide#hash-literals) Open
before_filter :authenticate_user!, :except => [:search, :index, :show]
- Read upRead up
- Exclude checks
This cop 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
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}