source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_parentheses.rb
Ruby
mit
12,856
master
12,705
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for redundant parentheses. # # @example # # # bad # (x) if ((y.z).nil?) # # # good # x if y.z.nil? # class RedundantParentheses < Base # rubocop:disable Metrics/...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/array_join.rb
Ruby
mit
12,856
master
1,167
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for uses of `*` as a substitute for `Array#join`. # Using `join` is clearer about intent and more readable than # overloading the `*` operator for string conversion. # # Not all cases can be reliably check...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/require_order.rb
Ruby
mit
12,856
master
3,781
# frozen_string_literal: true module RuboCop module Cop module Style # Sort `require` and `require_relative` in alphabetical order. # # @safety # This cop's autocorrection is unsafe because it will obviously change the execution order. # # @example # # bad # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_argument.rb
Ruby
mit
12,856
master
4,207
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for a redundant argument passed to certain methods. # # NOTE: This cop is limited to methods with single parameter. # # Method names and their redundant arguments can be configured like this: # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/copyright.rb
Ruby
mit
12,856
master
3,830
# frozen_string_literal: true module RuboCop module Cop module Style # Checks that a copyright notice was given in each source file. # # The default regexp for an acceptable copyright notice can be found in # config/default.yml. The default can be changed as follows: # # [sour...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/trailing_body_on_module.rb
Ruby
mit
12,856
master
950
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for trailing code after the module definition. # # @example # # bad # module Foo extend self # end # # # good # module Foo # extend self # end # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/numbered_parameters_limit.rb
Ruby
mit
12,856
master
1,865
# frozen_string_literal: true module RuboCop module Cop module Style # Detects use of an excessive amount of numbered parameters in a # single block. Having too many numbered parameters can make code too # cryptic and hard to read. # # The cop defaults to registering an offense if t...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/tally_method.rb
Ruby
mit
12,856
master
6,647
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for manual counting patterns that can be replaced by `Enumerable#tally`. # # The cop detects the following patterns: # # - `each_with_object(Hash.new(0)) { |item, counts| counts[item] += 1 }` # - `gr...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_fetch_block.rb
Ruby
mit
12,856
master
3,461
# frozen_string_literal: true module RuboCop module Cop module Style # Identifies places where `fetch(key) { value }` can be replaced by `fetch(key, value)`. # # In such cases `fetch(key, value)` method is faster than `fetch(key) { value }`. # # NOTE: The block string `'value'` in `...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/in_pattern_then.rb
Ruby
mit
12,856
master
1,622
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for `in;` uses in `case` expressions. # # @example # # bad # case expression # in pattern_a; foo # in pattern_b; bar # end # # # good # case expression ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/perl_backrefs.rb
Ruby
mit
12,856
master
3,523
# frozen_string_literal: true module RuboCop module Cop module Style # Looks for uses of Perl-style regexp match # backreferences and their English versions like # $1, $2, $&, &+, $MATCH, $PREMATCH, etc. # # @example # # bad # puts $1 # # # good #...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/empty_literal.rb
Ruby
mit
12,856
master
5,025
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for the use of a method, the result of which # would be a literal, like an empty array, hash, or string. # # NOTE: When frozen string literals are enabled, `String.new` # isn't corrected to an empty string...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/yaml_file_read.rb
Ruby
mit
12,856
master
1,887
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for the use of `YAML.load`, `YAML.safe_load`, and `YAML.parse` with # `File.read` argument. # # NOTE: `YAML.safe_load_file` was introduced in Ruby 3.0. # # @example # # # bad # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_struct_keyword_init.rb
Ruby
mit
12,856
master
3,864
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for redundant `keyword_init` option for `Struct.new`. # # Since Ruby 3.2, `keyword_init` in `Struct.new` defaults to `nil` behavior. # Therefore, this cop detects and autocorrects redundant `keyword_init: nil` ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/lambda.rb
Ruby
mit
12,856
master
3,486
# frozen_string_literal: true module RuboCop module Cop module Style # (by default) checks for uses of the lambda literal syntax for # single line lambdas, and the method call syntax for multiline lambdas. # It is configurable to enforce one of the styles for both single line # and multil...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/multiple_comparison.rb
Ruby
mit
12,856
master
4,955
# frozen_string_literal: true module RuboCop module Cop module Style # Checks against comparing a variable with multiple items, where # `Array#include?`, `Set#include?` or a `case` could be used instead # to avoid code repetition. # It accepts comparisons of multiple method calls to avoid...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_array_constructor.rb
Ruby
mit
12,856
master
2,039
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for the instantiation of array using redundant `Array` constructor. # Autocorrect replaces to array literal which is the simplest and fastest. # # @example # # # bad # Array.new([]) #...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/class_check.rb
Ruby
mit
12,856
master
1,424
# frozen_string_literal: true module RuboCop module Cop module Style # Enforces consistent use of `Object#is_a?` or `Object#kind_of?`. # # @example EnforcedStyle: is_a? (default) # # bad # var.kind_of?(Date) # var.kind_of?(Integer) # # # good # var....
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/keyword_arguments_merging.rb
Ruby
mit
12,856
master
1,918
# frozen_string_literal: true module RuboCop module Cop module Style # When passing an existing hash as keyword arguments, provide additional arguments # directly rather than using `merge`. # # Providing arguments directly is more performant than using `merge`, and # also leads to s...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/method_def_parentheses.rb
Ruby
mit
12,856
master
5,735
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for parentheses around the arguments in method # definitions. Both instance and class/singleton methods are checked. # # Regardless of style, parentheses are necessary for: # # 1. Endless methods ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/invertible_unless_condition.rb
Ruby
mit
12,856
master
5,102
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for usages of `unless` which can be replaced by `if` with inverted condition. # Code without `unless` is easier to read, but that is subjective, so this cop # is disabled by default. # # Methods that can b...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/hash_fetch_chain.rb
Ruby
mit
12,856
master
3,379
# frozen_string_literal: true module RuboCop module Cop module Style # Use `Hash#dig` instead of chaining potentially null `fetch` calls. # # When `fetch(identifier, nil)` calls are chained on a hash, the expectation # is that each step in the chain returns either `nil` or another hash, ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/if_unless_modifier_of_if_unless.rb
Ruby
mit
12,856
master
1,229
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for if and unless statements used as modifiers of other if or # unless statements. # # @example # # # bad # tired? ? 'stop' : 'go faster' if running? # # # bad # if ti...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/string_literals.rb
Ruby
mit
12,856
master
3,988
# frozen_string_literal: true module RuboCop module Cop module Style # Checks if uses of quotes match the configured preference. # # @example EnforcedStyle: single_quotes (default) # # bad # "No special symbols" # "No string interpolation" # "Just text" # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/hash_each_methods.rb
Ruby
mit
12,856
master
7,535
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for uses of `each_key` and `each_value` `Hash` methods. # # NOTE: If you have an array of two-element arrays, you can put # parentheses around the block arguments to indicate that you're not # working ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/frozen_string_literal_comment.rb
Ruby
mit
12,856
master
7,026
# frozen_string_literal: true module RuboCop module Cop module Style # Helps you transition from mutable string literals # to frozen string literals. # It will add the `# frozen_string_literal: true` magic comment to the top # of files to enable frozen string literals. Frozen string liter...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/date_time.rb
Ruby
mit
12,856
master
2,747
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for consistent usage of the `DateTime` class over the # `Time` class. This cop is disabled by default since these classes, # although highly overlapping, have particularities that make them not # replaceable in ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/float_division.rb
Ruby
mit
12,856
master
5,065
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for division with integers coerced to floats. # It is recommended to either always use `fdiv` or coerce one side only. # This cop also provides other options for code consistency. # # For `Regexp.last_matc...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/constant_visibility.rb
Ruby
mit
12,856
master
2,859
# frozen_string_literal: true module RuboCop module Cop module Style # Checks that constants defined in classes and modules have # an explicit visibility declaration. By default, Ruby makes all class- # and module constants public, which litters the public API of the # class or module. Ex...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_freeze.rb
Ruby
mit
12,856
master
2,076
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for uses of `Object#freeze` on immutable objects. # # NOTE: `Regexp` and `Range` literals are frozen objects since Ruby 3.0. # # NOTE: From Ruby 3.0, this cop allows explicit freezing of interpolated ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_conditional.rb
Ruby
mit
12,856
master
2,186
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for redundant returning of true/false in conditionals. # # @example # # bad # x == y ? true : false # # # bad # if x == y # true # else # false #...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/parallel_assignment.rb
Ruby
mit
12,856
master
9,837
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for simple usages of parallel assignment. # Parallel assignment is less readable than individual # assignments and makes it harder to follow what each # variable is being set to. # # This will only c...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/comparable_clamp.rb
Ruby
mit
12,856
master
3,762
# frozen_string_literal: true module RuboCop module Cop module Style # Enforces the use of `Comparable#clamp` instead of comparison by minimum and maximum. # # This cop supports autocorrection for `if/elsif/else` bad style only. # Because `ArgumentError` occurs if the minimum and maximum ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/optional_boolean_parameter.rb
Ruby
mit
12,856
master
1,794
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for places where keyword arguments can be used instead of # boolean arguments when defining methods. `respond_to_missing?` method is allowed by default. # These are customizable with `AllowedMethods` option. # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_regexp_character_class.rb
Ruby
mit
12,856
master
3,615
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for unnecessary single-element `Regexp` character classes. # # @example # # # bad # r = /[x]/ # # # good # r = /x/ # # # bad # r = /[\s]/ # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/collection_compact.rb
Ruby
mit
12,856
master
5,368
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for places where custom logic on rejection nils from arrays # and hashes can be replaced with `{Array,Hash}#{compact,compact!}`. # # @safety # It is unsafe by default because false positives may occur in...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/alias.rb
Ruby
mit
12,856
master
5,476
# frozen_string_literal: true module RuboCop module Cop module Style # Enforces the use of either `#alias` or `#alias_method` # depending on configuration. Consistent use of one or the # other prevents confusion about their different semantics # (e.g., `alias` is resolved at parse time, w...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/single_line_methods.rb
Ruby
mit
12,856
master
4,944
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for single-line method definitions that contain a body. # Single-line methods with a body are harder to read and debug # than their multi-line equivalents. It will accept single-line # methods with no body. ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/end_block.rb
Ruby
mit
12,856
master
742
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for `END` blocks. `END` blocks are Perl-style constructs # and `Kernel#at_exit` is the idiomatic Ruby alternative, as it's # explicit and can be used anywhere. # # @example # # bad # END { ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/multiline_in_pattern_then.rb
Ruby
mit
12,856
master
1,483
# frozen_string_literal: true module RuboCop module Cop module Style # Checks uses of the `then` keyword in multi-line `in` statement. # # @example # # bad # case expression # in pattern then # end # # # good # case expression # in p...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/top_level_method_definition.rb
Ruby
mit
12,856
master
2,042
# frozen_string_literal: true module RuboCop module Cop module Style # Newcomers to ruby applications may write top-level methods, # when ideally they should be organized in appropriate classes or modules. # This cop looks for definitions of top-level methods and warns about them. # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/array_first_last.rb
Ruby
mit
12,856
master
2,292
# frozen_string_literal: true module RuboCop module Cop module Style # Identifies usages of `arr[0]` and `arr[-1]` and suggests to change # them to use `arr.first` and `arr.last` instead. # # The cop is disabled by default due to safety concerns. # # @safety # This cop...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/slicing_with_range.rb
Ruby
mit
12,856
master
4,563
# frozen_string_literal: true module RuboCop module Cop module Style # Checks that arrays are not sliced with the redundant `ary[0..-1]`, replacing it with `ary`, # and ensures arrays are sliced with endless ranges instead of `ary[start..-1]` on Ruby 2.6+, # and with beginless ranges instead of...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/each_for_simple_loop.rb
Ruby
mit
12,856
master
2,216
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for loops which iterate a constant number of times, # using a `Range` literal and `#each`. This can be done more readably using # `Integer#times`. # # This check only applies if the block takes no paramete...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/for.rb
Ruby
mit
12,856
master
2,377
# frozen_string_literal: true module RuboCop module Cop module Style # Looks for uses of the `for` keyword or `each` method. The # preferred alternative is set in the EnforcedStyle configuration # parameter. An `each` call with a block on a single line is always # allowed. # #...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/class_and_module_children.rb
Ruby
mit
12,856
master
8,072
# frozen_string_literal: true module RuboCop module Cop module Style # Checks that namespaced classes and modules are defined with a consistent style. # # With `nested` style, classes and modules should be defined separately (one constant # on each line, without `::`). With `compact` styl...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/block_delimiters.rb
Ruby
mit
12,856
master
15,844
# frozen_string_literal: true # rubocop:disable Metrics/ClassLength module RuboCop module Cop module Style # Checks for uses of braces or do/end around single line or # multi-line blocks. # # Methods that can be either procedural or functional and cannot be # categorised from their ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/reduce_to_hash.rb
Ruby
mit
12,856
master
6,260
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for `each_with_object`, `inject`, and `reduce` calls that build # a hash from an enumerable, where `to_h` with a block could be used instead. # # This cop complements `Style/HashTransformKeys` and `Style/HashTra...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/each_with_object.rb
Ruby
mit
12,856
master
4,524
# frozen_string_literal: true module RuboCop module Cop module Style # Looks for inject / reduce calls where the passed in object is # returned at the end and so could be replaced by each_with_object without # the need to return the object at the end. # # However, we can't replace w...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/multiline_if_then.rb
Ruby
mit
12,856
master
1,222
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for uses of the `then` keyword in multi-line `if` statements. # In multi-line `if` statements, `then` is redundant because the newline # already separates the condition from the body. # # @example # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/expand_path_arguments.rb
Ruby
mit
12,856
master
5,918
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for use of the `File.expand_path` arguments. # Likewise, it also checks for the `Pathname.new` argument. # # Contrastive bad case and good case are alternately shown in # the following examples. # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/dig_chain.rb
Ruby
mit
12,856
master
2,664
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for chained `dig` calls that can be collapsed into a single `dig`. # # @safety # This cop is unsafe because it cannot be guaranteed that the receiver # is an `Enumerable` or does not have a nonstandard...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/optional_arguments.rb
Ruby
mit
12,856
master
1,622
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for optional arguments to methods # that do not come at the end of the argument list. # # @safety # This cop is unsafe because changing a method signature will # implicitly change behavior. ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/symbol_array.rb
Ruby
mit
12,856
master
4,053
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for array literals made up of symbols that are not # using the %i() syntax. # # Alternatively, it checks for symbol arrays using the %i() syntax on # projects which do not want to use that syntax, perhaps ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/semicolon.rb
Ruby
mit
12,856
master
6,399
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for multiple expressions placed on the same line. # It also checks for lines terminated with a semicolon. # In idiomatic Ruby, each expression should be on its own line # for readability. # # This co...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/missing_respond_to_missing.rb
Ruby
mit
12,856
master
2,204
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for the presence of `method_missing` without also # defining `respond_to_missing?`. # # Not defining `respond_to_missing?` will cause metaprogramming # methods like `respond_to?` to behave unexpectedly: ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/if_with_boolean_literal_branches.rb
Ruby
mit
12,856
master
5,027
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for redundant `if` with boolean literal branches. # It checks only conditions to return boolean value (`true` or `false`) for safe detection. # The conditions to be checked are comparison methods, predicate methods, a...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/while_until_do.rb
Ruby
mit
12,856
master
1,063
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for uses of `do` in multi-line `while/until` statements. # # @example # # # bad # while x.any? do # do_something(x.pop) # end # # # good # while x.any? ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/map_to_set.rb
Ruby
mit
12,856
master
1,852
# frozen_string_literal: true module RuboCop module Cop module Style # Looks for uses of `map.to_set` or `collect.to_set` that could be # written with just `to_set`. # # @safety # This cop is unsafe, as it can produce false positives if the receiver # is not an `Enumerable...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/struct_inheritance.rb
Ruby
mit
12,856
master
2,476
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for inheritance from `Struct.new`. Inheriting from `Struct.new` # adds a superfluous level in inheritance tree. # # @safety # Autocorrection is unsafe because it will change the inheritance # tre...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/even_odd.rb
Ruby
mit
12,856
master
1,395
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for places where `Integer#even?` or `Integer#odd?` # can be used. # # @example # # # bad # if x % 2 == 0 # end # # # good # if x.even? # end clas...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_filter_chain.rb
Ruby
mit
12,856
master
3,739
# frozen_string_literal: true module RuboCop module Cop module Style # Identifies usages of `any?`, `empty?` or `none?` predicate methods # chained to `select`/`filter`/`find_all` and change them to use predicate method instead. # # @safety # This cop's autocorrection is unsafe be...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/begin_block.rb
Ruby
mit
12,856
master
536
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for `BEGIN` blocks. They are Perl-style constructs that execute # code before the rest of the file is parsed, making the control flow # harder to follow and reason about. # # @example # # bad ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/colon_method_definition.rb
Ruby
mit
12,856
master
792
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for class methods that are defined using the `::` # operator instead of the `.` operator. # # @example # # bad # class Foo # def self::bar # end # end # # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/negated_while.rb
Ruby
mit
12,856
master
881
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for uses of while with a negated condition. # # @example # # bad # while !foo # bar # end # # # good # until foo # bar # end # # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/concat_array_literals.rb
Ruby
mit
12,856
master
2,943
# frozen_string_literal: true module RuboCop module Cop module Style # Enforces the use of `Array#push(item)` instead of `Array#concat([item])` # to avoid redundant array literals. # # @safety # This cop is unsafe, as it can produce false positives if the receiver # is not...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_assignment.rb
Ruby
mit
12,856
master
2,891
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for redundant assignment before returning. # # @example # # bad # def test # x = foo # x # end # # # bad # def test # if x # z = ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/double_cop_disable_directive.rb
Ruby
mit
12,856
master
1,418
# frozen_string_literal: true # rubocop:disable Lint/RedundantCopDisableDirective # rubocop:disable Style/DoubleCopDisableDirective module RuboCop module Cop module Style # Detects double disable comments on one line. This is mostly to catch # automatically generated comments that need to be regener...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/it_block_parameter.rb
Ruby
mit
12,856
master
3,752
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for blocks with one argument where `it` block parameter can be used. # # It provides four `EnforcedStyle` options: # # 1. `allow_single_line` (default) ... Always uses the `it` block parameter in a single ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/def_with_parentheses.rb
Ruby
mit
12,856
master
1,724
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for parentheses in the definition of a method, # that does not take any arguments. Both instance and # class/singleton methods are checked. # # @example # # # bad # def foo() # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/file_read.rb
Ruby
mit
12,856
master
2,879
# frozen_string_literal: true module RuboCop module Cop module Style # Favor `File.(bin)read` convenience methods. # # @example # # bad - text mode # File.open(filename).read # File.open(filename, &:read) # File.open(filename) { |f| f.read } # File.open(f...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/hash_except.rb
Ruby
mit
12,856
master
2,637
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods # that can be replaced with `Hash#except` method. # # This cop should only be enabled on Ruby version 3.0 or higher. # (`Hash#except` w...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/strip.rb
Ruby
mit
12,856
master
1,157
# frozen_string_literal: true module RuboCop module Cop module Style # Identifies places where `lstrip.rstrip` can be replaced by # `strip`. # # @example # # bad # 'abc'.lstrip.rstrip # 'abc'.rstrip.lstrip # # # good # 'abc'.strip class ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/if_inside_else.rb
Ruby
mit
12,856
master
4,790
# frozen_string_literal: true module RuboCop module Cop module Style # If the `else` branch of a conditional consists solely of an `if` node, # it can be combined with the `else` to become an `elsif`. # This helps to keep the nesting level from getting too deep. # # @example #...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/if_with_semicolon.rb
Ruby
mit
12,856
master
4,180
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for uses of semicolon in if statements. # # @example # # # bad # result = if some_condition; something else another_thing end # # # good # result = some_condition ? somethin...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/or_assignment.rb
Ruby
mit
12,856
master
2,534
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for potential usage of the `||=` operator. # # @example # # bad # name = name ? name : 'Bozhidar' # # # bad # name = if name # name # else # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/trivial_accessors.rb
Ruby
mit
12,856
master
6,557
# frozen_string_literal: true module RuboCop module Cop module Style # Looks for trivial reader/writer methods, that could # have been created with the attr_* family of functions automatically. # `to_ary`, `to_a`, `to_c`, `to_enum`, `to_h`, `to_hash`, `to_i`, `to_int`, `to_io`, # `to_open...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/single_line_block_params.rb
Ruby
mit
12,856
master
4,052
# frozen_string_literal: true module RuboCop module Cop module Style # Checks whether the block parameters of a single-line # method accepting a block match the names specified via configuration. # # For instance one can configure `reduce`(`inject`) to use |a, e| as # parameters. ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_current_directory_in_path.rb
Ruby
mit
12,856
master
1,500
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for paths given to `require_relative` that start with # the current directory (`./`), which can be omitted. # # @example # # # bad # require_relative './path/to/feature' # # #...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/array_intersect.rb
Ruby
mit
12,856
master
6,109
# frozen_string_literal: true module RuboCop module Cop module Style # In Ruby 3.1, `Array#intersect?` has been added. # # This cop identifies places where: # # * `(array1 & array2).any?` # * `(array1.intersection(array2)).any?` # * `array1.any? { |elem| array2.member?(e...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/symbol_literal.rb
Ruby
mit
12,856
master
590
# frozen_string_literal: true module RuboCop module Cop module Style # Checks symbol literal syntax. # # @example # # # bad # :"symbol" # # # good # :symbol class SymbolLiteral < Base extend AutoCorrector MSG = 'Do not use strin...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/format_string_token.rb
Ruby
mit
12,856
master
10,235
# frozen_string_literal: true module RuboCop module Cop module Style # Use a consistent style for tokens within a format string. # # By default, all strings are evaluated. In some cases, this may be undesirable, # as they could be used as arguments to a method that does not consider ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/lambda_call.rb
Ruby
mit
12,856
master
2,008
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for use of the lambda.(args) syntax. # # @example EnforcedStyle: call (default) # # bad # lambda.(x, y) # # # good # lambda.call(x, y) # # @example EnforcedStyle: brac...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/non_nil_check.rb
Ruby
mit
12,856
master
4,655
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for non-nil checks, which are usually redundant. # # With `IncludeSemanticChanges` set to `false` by default, this cop # does not report offenses for `!x.nil?` and does no changes that might # change behav...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/min_max_comparison.rb
Ruby
mit
12,856
master
2,760
# frozen_string_literal: true module RuboCop module Cop module Style # Enforces the use of `max` or `min` instead of comparison for greater or less. # # NOTE: It can be used if you want to present limit or threshold in Ruby 2.7+. # That it is slow though. So autocorrection will apply gene...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/symbol_proc.rb
Ruby
mit
12,856
master
9,561
# frozen_string_literal: true module RuboCop module Cop module Style # Use symbols as procs when possible. # # If you prefer a style that allows block for method with arguments, # please set `true` to `AllowMethodsWithArguments`. # `define_method?` methods are allowed by default. ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/unpack_first.rb
Ruby
mit
12,856
master
1,789
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for accessing the first element of `String#unpack` # which can be replaced with the shorter method `unpack1`. # # @example # # # bad # 'foo'.unpack('h*').first # 'foo'.unpack('h*')[...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/hash_transform_keys.rb
Ruby
mit
12,856
master
3,504
# frozen_string_literal: true module RuboCop module Cop module Style # Looks for uses of `+_.each_with_object({}) {...}+`, # `+_.map {...}.to_h+`, and `+Hash[_.map {...}]+` that are actually just # transforming the keys of a hash, and tries to use a simpler & faster # call to `transform_k...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_double_splat_hash_braces.rb
Ruby
mit
12,856
master
3,881
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for redundant uses of double splat hash braces. # # @example # # # bad # do_something(**{foo: bar, baz: qux}) # # # good # do_something(foo: bar, baz: qux) # # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/single_argument_dig.rb
Ruby
mit
12,856
master
2,191
# frozen_string_literal: true module RuboCop module Cop module Style # Sometimes using `dig` method ends up with just a single # argument. In such cases, dig should be replaced with `[]`. # # Since replacing `hash&.dig(:key)` with `hash[:key]` could potentially lead to error, # call...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/numbered_parameters.rb
Ruby
mit
12,856
master
1,207
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for numbered parameters. # # It can either restrict the use of numbered parameters to # single-lined blocks, or disallow completely numbered parameters. # # @example EnforcedStyle: allow_single_line ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/open_struct_use.rb
Ruby
mit
12,856
master
1,903
# frozen_string_literal: true module RuboCop module Cop module Style # Flags uses of `OpenStruct`, as it is now officially discouraged # to be used for performance, version compatibility, and potential security issues. # # @safety # Note that this cop may flag false positives; for...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/empty_else.rb
Ruby
mit
12,856
master
4,617
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for empty else-clauses, possibly including comments and/or an # explicit `nil` depending on the EnforcedStyle. # # @example EnforcedStyle: both (default) # # warn on empty else and else with nil in it ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/hash_syntax.rb
Ruby
mit
12,856
master
9,440
# frozen_string_literal: true module RuboCop module Cop module Style # 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 probl...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/class_methods.rb
Ruby
mit
12,856
master
1,401
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for uses of the class/module name instead of # self, when defining class/module methods. # # @example # # bad # class SomeClass # def SomeClass.class_method # # ... # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/method_called_on_do_end_block.rb
Ruby
mit
12,856
master
1,465
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for methods called on a do...end block. The point of # this check is that it's easy to miss the call tacked on to the block # when reading code. # # @example # # bad # a do # b ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/mutable_constant.rb
Ruby
mit
12,856
master
8,161
# frozen_string_literal: true module RuboCop module Cop module Style # Checks whether some constant value isn't a # mutable literal (e.g. array or hash). # # Strict mode can be used to freeze all constants, rather than # just literals. # Strict mode is considered an experiment...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/hash_slice.rb
Ruby
mit
12,856
master
2,629
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for usages of `Hash#reject`, `Hash#select`, and `Hash#filter` methods # that can be replaced with `Hash#slice` method. # # This cop should only be enabled on Ruby version 2.5 or higher. # (`Hash#slice` was...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/sole_nested_conditional.rb
Ruby
mit
12,856
master
8,308
# frozen_string_literal: true module RuboCop module Cop module Style # If the branch of a conditional consists solely of a conditional node, # its conditions can be combined with the conditions of the outer branch. # This helps to keep the nesting level from getting too deep. # # @e...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/string_chars.rb
Ruby
mit
12,856
master
1,231
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for uses of `String#split` with empty string or regexp literal argument. # # @safety # This cop is unsafe because it cannot be guaranteed that the receiver # is actually a string. If another class has ...