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/mixin/string_literals_help.rb
Ruby
mit
12,856
master
824
# frozen_string_literal: true module RuboCop module Cop # Common functionality for cops checking single/double quotes. module StringLiteralsHelp private def wrong_quotes?(src_or_node) src = src_or_node.is_a?(RuboCop::AST::Node) ? src_or_node.source : src_or_node return false if s...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/def_node.rb
Ruby
mit
12,856
master
638
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking def nodes. module DefNode extend NodePattern::Macros include VisibilityHelp private def non_public?(node) non_public_modifier?(node.parent) || preceding_non_public_modifier?(node) ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/interpolation.rb
Ruby
mit
12,856
master
653
# frozen_string_literal: true module RuboCop module Cop # Common functionality for working with string interpolations. # # @abstract Subclasses are expected to implement {#on_interpolation}. module Interpolation def on_dstr(node) on_node_with_interpolations(node) end alias ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/array_min_size.rb
Ruby
mit
12,856
master
1,692
# frozen_string_literal: true module RuboCop module Cop # Handles the `MinSize` configuration option for array-based cops # `Style/SymbolArray` and `Style/WordArray`, which check for use of the # relevant percent literal syntax such as `%i[...]` and `%w[...]` module ArrayMinSize private ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/allowed_receivers.rb
Ruby
mit
12,856
master
845
# frozen_string_literal: true module RuboCop module Cop # This module encapsulates the ability to allow certain receivers in a cop. module AllowedReceivers def allowed_receiver?(receiver) receiver_name = receiver_name(receiver) allowed_receivers.include?(receiver_name) end ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/allowed_pattern.rb
Ruby
mit
12,856
master
2,070
# frozen_string_literal: true module RuboCop module Cop # This module encapsulates the ability to ignore certain lines when # parsing. module AllowedPattern private def allowed_line?(line) line = if line.respond_to?(:source_line) line.source_line elsif...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/hash_shorthand_syntax.rb
Ruby
mit
12,856
master
8,754
# frozen_string_literal: true module RuboCop module Cop # This module checks for Ruby 3.1's hash value omission syntax. # rubocop:disable Metrics/ModuleLength module HashShorthandSyntax OMIT_HASH_VALUE_MSG = 'Omit the hash value.' EXPLICIT_HASH_VALUE_MSG = 'Include the hash value.' DO_N...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/space_after_punctuation.rb
Ruby
mit
12,856
master
1,507
# frozen_string_literal: true module RuboCop module Cop # Common functionality for cops checking for missing space after # punctuation. module SpaceAfterPunctuation MSG = 'Space missing after %<token>s.' def on_new_investigation each_missing_space(processed_source.tokens) do |token, ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/parentheses.rb
Ruby
mit
12,856
master
383
# frozen_string_literal: true module RuboCop module Cop # Common functionality for handling parentheses. module Parentheses private def parens_required?(node) range = node.source_range source = range.source_buffer.source /[a-z]/.match?(source[range.begin_pos - 1]) || /[a...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/method_complexity.rb
Ruby
mit
12,856
master
2,149
# frozen_string_literal: true module RuboCop module Cop # @api private # # This module handles measurement and reporting of complexity in methods. module MethodComplexity include AllowedMethods include AllowedPattern include Metrics::Utils::RepeatedCsendDiscount extend NodePat...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/integer_node.rb
Ruby
mit
12,856
master
270
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking integer nodes. module IntegerNode private def integer_part(node) node.source.sub(/^[+-]/, '').split(/[eE.]/, 2).first end end end end
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/on_normal_if_unless.rb
Ruby
mit
12,856
master
299
# frozen_string_literal: true module RuboCop module Cop # Common functionality for cops checking if and unless expressions. module OnNormalIfUnless def on_if(node) return if node.modifier_form? || node.ternary? on_normal_if_unless(node) end end end end
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/forbidden_identifiers.rb
Ruby
mit
12,856
master
528
# frozen_string_literal: true module RuboCop module Cop # This module encapsulates the ability to forbid certain identifiers in a cop. module ForbiddenIdentifiers SIGILS = '@$' # if a variable starts with a sigil it will be removed def forbidden_identifier?(name) name = name.to_s.delete(...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/target_ruby_version.rb
Ruby
mit
12,856
master
1,083
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking target ruby version. module TargetRubyVersion def required_minimum_ruby_version @minimum_target_ruby_version end def required_maximum_ruby_version @maximum_target_ruby_version ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/gem_declaration.rb
Ruby
mit
12,856
master
304
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking gem declarations. module GemDeclaration extend NodePattern::Macros # @!method gem_declaration?(node) def_node_matcher :gem_declaration?, '(send nil? :gem str ...)' end end end
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/first_element_line_break.rb
Ruby
mit
12,856
master
1,339
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking for a line break before the first # element in a multi-line collection. module FirstElementLineBreak private def check_method_line_break(node, children, ignore_last: false) return if children....
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/forbidden_pattern.rb
Ruby
mit
12,856
master
399
# frozen_string_literal: true module RuboCop module Cop # This module encapsulates the ability to forbid certain patterns in a cop. module ForbiddenPattern def forbidden_pattern?(name) forbidden_patterns.any? { |pattern| Regexp.new(pattern).match?(name) } end def forbidden_patterns...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/symbol_help.rb
Ruby
mit
12,856
master
309
# frozen_string_literal: true module RuboCop module Cop # Classes that include this module just implement functions for working # with symbol nodes. module SymbolHelp def hash_key?(node) node.parent&.pair_type? && node == node.parent.child_nodes.first end end end end
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/rational_literal.rb
Ruby
mit
12,856
master
380
# frozen_string_literal: true module RuboCop module Cop # Common functionality for handling Rational literals. module RationalLiteral extend NodePattern::Macros private # @!method rational_literal?(node) def_node_matcher :rational_literal?, <<~PATTERN (send (int _)...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/hash_alignment_styles.rb
Ruby
mit
12,856
master
4,818
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking hash alignment. module HashAlignmentStyles # Handles calculation of deltas when the enforced style is 'key'. class KeyAlignment def checkable_layout?(_node) true end def ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/hash_subset.rb
Ruby
mit
12,856
master
6,123
# frozen_string_literal: true module RuboCop module Cop # Common functionality for Style/HashExcept and Style/HashSlice cops. # It registers an offense on methods with blocks that are equivalent # to Hash#except or Hash#slice. # rubocop:disable Metrics/ModuleLength module HashSubset include...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb
Ruby
mit
12,856
master
4,235
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking the closing brace of a literal is # either on the same line as the last contained elements or a new line. module MultilineLiteralBraceLayout include ConfigurableEnforcedStyle private def check_...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/allowed_identifiers.rb
Ruby
mit
12,856
master
500
# frozen_string_literal: true module RuboCop module Cop # This module encapsulates the ability to allow certain identifiers in a cop. module AllowedIdentifiers SIGILS = '@$' # if a variable starts with a sigil it will be removed def allowed_identifier?(name) !allowed_identifiers.empty? &...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/unused_argument.rb
Ruby
mit
12,856
master
739
# frozen_string_literal: true module RuboCop module Cop module Lint # Common functionality for cops handling unused arguments. module UnusedArgument extend NodePattern::Macros def after_leaving_scope(scope, _variable_table) scope.variables.each_value { |variable| check_argu...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/nil_methods.rb
Ruby
mit
12,856
master
529
# frozen_string_literal: true module RuboCop module Cop # This module provides a list of methods that are: # 1. In the NilClass by default # 2. Added to NilClass by explicitly requiring any standard libraries # 3. Cop's configuration parameter AllowedMethods. module NilMethods include Allow...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/heredoc.rb
Ruby
mit
12,856
master
949
# frozen_string_literal: true module RuboCop module Cop # Common functionality for working with heredoc strings. module Heredoc OPENING_DELIMITER = /(<<[~-]?)['"`]?([^'"`]+)['"`]?/.freeze def on_str(node) return unless node.heredoc? on_heredoc(node) end alias on_dstr...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/preferred_delimiters.rb
Ruby
mit
12,856
master
1,392
# frozen_string_literal: true module RuboCop module Cop # Common functionality for handling percent literal delimiters. class PreferredDelimiters attr_reader :type, :config PERCENT_LITERAL_TYPES = %w[% %i %I %q %Q %r %s %w %W %x].freeze def initialize(type, config, preferred_delimiters) ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/dig_help.rb
Ruby
mit
12,856
master
628
# frozen_string_literal: true module RuboCop module Cop # Help methods for working with `Enumerable#dig` in cops. # Used by `Style::DigChain` and `Style::SingleArgumentDig` module DigHelp extend NodePattern::Macros # @!method dig?(node) def_node_matcher :dig?, <<~PATTERN (call ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/string_help.rb
Ruby
mit
12,856
master
1,144
# frozen_string_literal: true module RuboCop module Cop # Classes that include this module just implement functions to determine # what is an offense and how to do autocorrection. They get help with # adding offenses for the faulty string nodes, and with filtering out # nodes. module StringHelp ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/ordered_gem_node.rb
Ruby
mit
12,856
master
1,835
# frozen_string_literal: true module RuboCop module Cop # Common functionality for Bundler/OrderedGems and # Gemspec/OrderedDependencies. module OrderedGemNode private def get_source_range(node, comments_as_separators) unless comments_as_separators first_comment = processed...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/min_branches_count.rb
Ruby
mit
12,856
master
1,047
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking minimum branches count. module MinBranchesCount private def min_branches_count?(node) branches = if node.case_type? node.when_branches elsif node.if_type? ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/preceding_following_alignment.rb
Ruby
mit
12,856
master
8,211
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking whether an AST node/token is aligned # with something on a preceding or following line # rubocop:disable Metrics/ModuleLength module PrecedingFollowingAlignment # Tokens that end with an `=`, as well as ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/enforce_superclass.rb
Ruby
mit
12,856
master
1,553
# frozen_string_literal: true module RuboCop module Cop # Common functionality for enforcing a specific superclass. # # IMPORTANT: RuboCop core depended on this module when it supported Rails department. # Rails department has been extracted to RuboCop Rails gem. # # @deprecated This module i...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/alignment.rb
Ruby
mit
12,856
master
2,739
# frozen_string_literal: true module RuboCop module Cop # This module checks for nodes that should be aligned to the left or right. # This amount is determined by the instance variable @column_delta. module Alignment SPACE = ' ' private attr_reader :column_delta def configured_...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/empty_lines_around_body.rb
Ruby
mit
12,856
master
5,744
# frozen_string_literal: true module RuboCop module Cop module Layout # Common functionality for checking if presence/absence of empty lines # around some kind of body matches the configuration. module EmptyLinesAroundBody extend NodePattern::Macros include ConfigurableEnforcedS...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/auto_corrector.rb
Ruby
mit
12,856
master
214
# frozen_string_literal: true module RuboCop module Cop # extend this module to signal autocorrection support module AutoCorrector def support_autocorrect? true end end end end
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/end_keyword_alignment.rb
Ruby
mit
12,856
master
2,254
# frozen_string_literal: true module RuboCop module Cop # Functions for checking the alignment of the `end` keyword. module EndKeywordAlignment include ConfigurableEnforcedStyle include RangeHelp MSG = '`end` at %<end_line>d, %<end_col>d is not aligned with ' \ '`%<source>s` at...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/check_single_line_suitability.rb
Ruby
mit
12,856
master
1,773
# frozen_string_literal: true module RuboCop module Cop # Checks for code on multiple lines that could be rewritten on a single line # without changing semantics or exceeding the `Max` parameter of `Layout/LineLength`. module CheckSingleLineSuitability def suitable_as_single_line?(node) !to...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/space_before_punctuation.rb
Ruby
mit
12,856
master
1,385
# frozen_string_literal: true module RuboCop module Cop # Common functionality for cops checking for space before # punctuation. module SpaceBeforePunctuation include RangeHelp MSG = 'Space found before %<token>s.' def on_new_investigation each_missing_space(processed_source.s...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/array_syntax.rb
Ruby
mit
12,856
master
400
# frozen_string_literal: true module RuboCop module Cop # Common code for ordinary arrays with [] that can be written with % # syntax. module ArraySyntax private def bracketed_array_of?(element_type, node) return false unless node.square_brackets? && !node.values.empty? node...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/configurable_formatting.rb
Ruby
mit
12,856
master
1,406
# frozen_string_literal: true module RuboCop module Cop # Shared functionality between mixins that enforce naming conventions module ConfigurableFormatting include ConfigurableEnforcedStyle def check_name(node, name, name_range) if valid_name?(node, name) correct_style_detected...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/empty_parameter.rb
Ruby
mit
12,856
master
546
# frozen_string_literal: true module RuboCop module Cop # Common code for empty parameter cops. module EmptyParameter extend NodePattern::Macros private # @!method empty_arguments?(node) def_node_matcher :empty_arguments?, <<~PATTERN (block _ $(args) _) PATTERN ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/negative_conditional.rb
Ruby
mit
12,856
master
894
# frozen_string_literal: true module RuboCop module Cop # Some common code shared between `NegatedIf` and # `NegatedWhile` cops. module NegativeConditional extend NodePattern::Macros MSG = 'Favor `%<inverse>s` over `%<current>s` for negative conditions.' private # @!method sing...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/configurable_naming.rb
Ruby
mit
12,856
master
423
# frozen_string_literal: true module RuboCop module Cop # This module provides functionality for checking if names match the # configured EnforcedStyle. module ConfigurableNaming include ConfigurableFormatting FORMATS = { snake_case: /^@{0,2}[\d[[:lower:]]_]+[!?=]?$/, camelCa...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/line_length_help.rb
Ruby
mit
12,856
master
4,821
# frozen_string_literal: true module RuboCop module Cop # Help methods for determining if a line is too long. module LineLengthHelp include Alignment private def allow_rbs_inline_annotation? config.for_cop('Layout/LineLength')['AllowRBSInlineAnnotation'] end def rbs_i...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/configurable_enforced_style.rb
Ruby
mit
12,856
master
3,082
# frozen_string_literal: true module RuboCop module Cop # Handles `EnforcedStyle` configuration parameters. module ConfigurableEnforcedStyle def opposite_style_detected style_detected(alternative_style) end def correct_style_detected style_detected(style) end d...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/statement_modifier.rb
Ruby
mit
12,856
master
3,546
# frozen_string_literal: true module RuboCop module Cop # Common functionality for modifier cops. module StatementModifier include LineLengthHelp private def single_line_as_modifier?(node) return false if non_eligible_node?(node) || non_eligible_body?(node....
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/check_line_breakable.rb
Ruby
mit
12,856
master
7,739
# frozen_string_literal: true module RuboCop module Cop # This mixin detects collections that are safe to "break" # by inserting new lines. This is useful for breaking # up long lines. # # Let's look at hashes as an example: # # We know hash keys are safe to break across lines. We can add...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/percent_array.rb
Ruby
mit
12,856
master
3,990
# frozen_string_literal: true module RuboCop module Cop # Common functionality for handling percent arrays. module PercentArray private # Ruby does not allow percent arrays in an ambiguous block context. # # @example # # foo %i[bar baz] { qux } def invalid_percent...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/gemspec_help.rb
Ruby
mit
12,856
master
1,420
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking gem declarations. module GemspecHelp extend NodePattern::Macros # @!method gem_specification?(node) def_node_matcher :gem_specification?, <<~PATTERN (block (send (const...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/duplication.rb
Ruby
mit
12,856
master
1,602
# frozen_string_literal: true module RuboCop module Cop # Common functionality for dealing with duplication. module Duplication private # Whether the `collection` contains any duplicates. # # @param [Array] collection an array to check for duplicates # @return [Boolean] whether...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/match_range.rb
Ruby
mit
12,856
master
678
# frozen_string_literal: true module RuboCop module Cop # Common functionality for obtaining source ranges from regexp matches module MatchRange include RangeHelp private # Return a new `Range` covering the first matching group number for each # match of `regex` inside `range` ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/annotation_comment.rb
Ruby
mit
12,856
master
2,009
# frozen_string_literal: true module RuboCop module Cop # Representation of an annotation comment in source code (eg. `# TODO: blah blah blah`). class AnnotationComment attr_reader :comment, :margin, :keyword, :colon, :space, :note # @param [Parser::Source::Comment] comment # @param [Array...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/allowed_methods.rb
Ruby
mit
12,856
master
1,441
# frozen_string_literal: true module RuboCop module Cop # This module encapsulates the ability to allow certain methods when # parsing. Even if the code is in offense, if it contains methods # that are allowed. This module is equivalent to the IgnoredMethods module, # which will be deprecated in Rubo...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/min_body_length.rb
Ruby
mit
12,856
master
508
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking minimum body length. module MinBodyLength private def min_body_length?(node) (node.loc.end.line - node.loc.keyword.line) > min_body_length end def min_body_length length = cop...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/multiline_element_line_breaks.rb
Ruby
mit
12,856
master
907
# frozen_string_literal: true module RuboCop module Cop # Common functionality for checking for a line break before each # element in a multi-line collection. module MultilineElementLineBreaks private def check_line_breaks(_node, children, ignore_last: false) return if all_on_same_li...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/trailing_body.rb
Ruby
mit
12,856
master
543
# frozen_string_literal: true module RuboCop module Cop # Common methods shared by TrailingBody cops module TrailingBody def trailing_body?(node) body = node.to_a.reverse[0] body && node.multiline? && body_on_first_line?(node, body) end def body_on_first_line?(node, body) ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/require_library.rb
Ruby
mit
12,856
master
1,705
# frozen_string_literal: true module RuboCop module Cop # Ensure a require statement is present for a standard library determined # by variable library_name module RequireLibrary extend NodePattern::Macros RESTRICT_ON_SEND = [:require].freeze def ensure_required(corrector, node, libra...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/mixin/hash_transform_method/autocorrection.rb
Ruby
mit
12,856
master
2,106
# frozen_string_literal: true module RuboCop module Cop module HashTransformMethod # Internal helper class to hold autocorrect data Autocorrection = Struct.new(:match, :block_node, :leading, :trailing) do def self.from_each_with_object(node, match) new(match, node, 0, 0) end...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/migration/department_name.rb
Ruby
mit
12,856
master
2,898
# frozen_string_literal: true # Lint/RedundantCopDisableDirective needs to be disabled so as # to be able to provide examples of rubocop:disable comments. # rubocop:disable Lint/RedundantCopDisableDirective module RuboCop module Cop module Migration # Checks that cop names in rubocop:disable comments are g...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/security/json_load.rb
Ruby
mit
12,856
master
2,292
# frozen_string_literal: true module RuboCop module Cop module Security # Checks for the use of JSON class methods which have potential # security issues. # # `JSON.load` and similar methods allow deserialization of arbitrary ruby objects: # # [source,ruby] # ---- ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/security/open.rb
Ruby
mit
12,856
master
2,594
# frozen_string_literal: true module RuboCop module Cop module Security # Checks for the use of `Kernel#open` and `URI.open` with dynamic # data. # # `Kernel#open` and `URI.open` enable not only file access but also process # invocation by prefixing a pipe symbol (e.g., `open("| ls"...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/security/compound_hash.rb
Ruby
mit
12,856
master
3,452
# frozen_string_literal: true module RuboCop module Cop module Security # Checks for implementations of the `hash` method which combine # values using custom logic instead of delegating to `Array#hash`. # # Manually combining hashes is error prone and hard to follow, especially # wh...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/security/io_methods.rb
Ruby
mit
12,856
master
1,719
# frozen_string_literal: true module RuboCop module Cop module Security # Checks for the first argument to `IO.read`, `IO.binread`, `IO.write`, `IO.binwrite`, # `IO.foreach`, and `IO.readlines`. # # If argument starts with a pipe character (`'|'`) and the receiver is the `IO` class, ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/security/eval.rb
Ruby
mit
12,856
master
1,389
# frozen_string_literal: true module RuboCop module Cop module Security # Checks for the use of `Kernel#eval` and `Binding#eval` with # dynamic strings as arguments. Evaluating non-literal strings # can enable code injection attacks and makes it difficult to # reason about what code will ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/security/yaml_load.rb
Ruby
mit
12,856
master
1,633
# frozen_string_literal: true module RuboCop module Cop module Security # Checks for the use of YAML class methods which have # potential security issues leading to remote code execution when # loading from an untrusted source. # # NOTE: Ruby 3.1+ (Psych 4) uses `Psych.load` as `Psy...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/security/marshal_load.rb
Ruby
mit
12,856
master
1,068
# frozen_string_literal: true module RuboCop module Cop module Security # Checks for the use of Marshal class methods which have # potential security issues leading to remote code execution when # loading from an untrusted source. # # @example # # bad # Marshal.load(...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/gemspec/dependency_version.rb
Ruby
mit
12,856
master
4,421
# frozen_string_literal: true module RuboCop module Cop module Gemspec # Enforce that gem dependency version specifications or a commit reference (branch, # ref, or tag) are either required or forbidden. # # @example EnforcedStyle: required (default) # # # bad # Gem:...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/gemspec/duplicated_assignment.rb
Ruby
mit
12,856
master
3,604
# frozen_string_literal: true module RuboCop module Cop module Gemspec # An attribute assignment method calls should be listed only once # in a gemspec. # # Assigning to an attribute with the same name using `spec.foo =` or # `spec.attribute#[]=` will be an unintended usage. On the ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/gemspec/attribute_assignment.rb
Ruby
mit
12,856
master
2,838
# frozen_string_literal: true module RuboCop module Cop module Gemspec # Use consistent style for Gemspec attributes assignment. # # @example # # # bad # # This example uses two styles for assignment of metadata attribute. # Gem::Specification.new do |spec| #...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/gemspec/require_mfa.rb
Ruby
mit
12,856
master
4,851
# frozen_string_literal: true module RuboCop module Cop module Gemspec # Requires a gemspec to have `rubygems_mfa_required` metadata set. # # This setting tells RubyGems that MFA (Multi-Factor Authentication) is # required for accounts to be able perform privileged operations, such as ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/gemspec/ruby_version_globals_usage.rb
Ruby
mit
12,856
master
1,546
# frozen_string_literal: true module RuboCop module Cop module Gemspec # Checks that `RUBY_VERSION` and `Ruby::VERSION` constants are not used in gemspec. # Using `RUBY_VERSION` and `Ruby::VERSION` are dangerous because value of the # constant is determined by `rake release`. # It's possi...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/gemspec/deprecated_attribute_assignment.rb
Ruby
mit
12,856
master
2,580
# frozen_string_literal: true module RuboCop module Cop module Gemspec # Checks that deprecated attributes are not set in a gemspec file. # Removing deprecated attributes allows the user to receive smaller packed gems. # # @example # # # bad # Gem::Specification.new ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/gemspec/add_runtime_dependency.rb
Ruby
mit
12,856
master
954
# frozen_string_literal: true module RuboCop module Cop module Gemspec # Prefer `add_dependency` over `add_runtime_dependency` as the latter is # considered soft-deprecated. # # @example # # # bad # Gem::Specification.new do |spec| # spec.add_runtime_depend...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/gemspec/required_ruby_version.rb
Ruby
mit
12,856
master
4,205
# frozen_string_literal: true module RuboCop module Cop module Gemspec # Checks that `required_ruby_version` in a gemspec file is set to a valid # value (non-blank) and matches `TargetRubyVersion` as set in RuboCop's # configuration for the gem. # # This ensures that RuboCop is usin...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/gemspec/ordered_dependencies.rb
Ruby
mit
12,856
master
3,032
# frozen_string_literal: true module RuboCop module Cop module Gemspec # Dependencies in the gemspec should be alphabetically sorted. # # @example # # bad # spec.add_dependency 'rubocop' # spec.add_dependency 'rspec' # # # good # spec.add_dependency...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/gemspec/development_dependencies.rb
Ruby
mit
12,856
master
3,034
# frozen_string_literal: true module RuboCop module Cop module Gemspec # Enforce that development dependencies for a gem are specified in # `Gemfile`, rather than in the `gemspec` using # `add_development_dependency`. Alternatively, using `EnforcedStyle: # gemspec`, enforce that all depen...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_interpolation.rb
Ruby
mit
12,856
master
4,357
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for strings that are just an interpolated expression. # # @safety # Autocorrection is unsafe because when calling a destructive method to string, # the resulting string may have different behavior or r...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/env_home.rb
Ruby
mit
12,856
master
1,378
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for consistent usage of `ENV['HOME']`. If `nil` is used as # the second argument of `ENV.fetch`, it is treated as a bad case like `ENV[]`. # # @safety # The cop is unsafe because the result when `nil` is...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/module_function.rb
Ruby
mit
12,856
master
4,372
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for use of `extend self` or `module_function` in a module. # # Supported styles are: `module_function` (default), `extend_self` and `forbidden`. # # A couple of things to keep in mind: # # - `f...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/special_global_vars.rb
Ruby
mit
12,856
master
8,236
# frozen_string_literal: true module RuboCop module Cop module Style # Looks for uses of Perl-style global variables. # Perl-style global variables like `$;` or `$/` are cryptic # and hard to understand without consulting documentation. # The `English` library provides descriptive aliases...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/dir.rb
Ruby
mit
12,856
master
1,449
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for places where the `#\_\_dir\_\_` method can replace more # complex constructs to retrieve a canonicalized absolute path to the # current file. # # @example # # bad # path = File.expand_p...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/trailing_method_end_statement.rb
Ruby
mit
12,856
master
1,424
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for trailing code after the method definition. # # @example # # bad # def some_method # do_stuff; end # # def do_this(x) # baz.map { |b| b.this(x) } end # # ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/yoda_condition.rb
Ruby
mit
12,856
master
5,251
# frozen_string_literal: true module RuboCop module Cop module Style # Enforces or forbids Yoda conditions, # i.e. comparison operations where the order of expression is reversed. # eg. `5 == x` # # @safety # This cop is unsafe because comparison operators can be defined ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/safe_navigation_chain_length.rb
Ruby
mit
12,856
master
1,616
# frozen_string_literal: true module RuboCop module Cop module Style # Enforces safe navigation chains length to not exceed the configured maximum. # The longer the chain is, the harder it becomes to track what on it could be # returning `nil`. # # There is a potential interplay wit...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/raise_args.rb
Ruby
mit
12,856
master
5,196
# frozen_string_literal: true module RuboCop module Cop module Style # Checks the args passed to `fail` and `raise`. # # Exploded style (default) enforces passing the exception class and message # arguments separately, rather than constructing an instance of the error. # # Com...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/nested_ternary_operator.rb
Ruby
mit
12,856
master
1,709
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for nested ternary op expressions. # # @example # # bad # a ? (b ? b1 : b2) : a2 # # # good # if a # b ? b1 : b2 # else # a2 # end class ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/file_open.rb
Ruby
mit
12,856
master
2,745
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for `File.open` without a block, which can leak file descriptors. # # When `File.open` is called without a block, the caller is responsible # for closing the file descriptor. If it is not explicitly closed, it ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/hash_like_case.rb
Ruby
mit
12,856
master
1,869
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for places where `case-when` represents a simple 1:1 # mapping and can be replaced with a hash lookup. # # @example MinBranchesCount: 3 (default) # # bad # case country # when 'europe' ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/string_concatenation.rb
Ruby
mit
12,856
master
5,693
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for places where string concatenation # can be replaced with string interpolation. # # The cop can autocorrect simple cases but will skip autocorrecting # more complex cases where the resulting code would ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/encoding.rb
Ruby
mit
12,856
master
1,891
# frozen_string_literal: true module RuboCop module Cop module Style # Checks that source files have no utf-8 encoding comments. # Since Ruby 2.0, UTF-8 is the default source encoding, so # these comments are no longer necessary and just add noise. # # @example # # bad ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/numeric_predicate.rb
Ruby
mit
12,856
master
5,445
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for usage of comparison operators (`==`, # `>`, `<`) to test numbers as zero, positive, or negative. # These can be replaced by their respective predicate methods. # This cop can also be configured to do the rev...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/percent_q_literals.rb
Ruby
mit
12,856
master
2,067
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for usage of the %Q() syntax when %q() would do. # # @example EnforcedStyle: lower_case_q (default) # # The `lower_case_q` style prefers `%q` unless # # interpolation is needed. # # bad #...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_regexp_constructor.rb
Ruby
mit
12,856
master
1,318
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for the instantiation of regexp using redundant `Regexp.new` or `Regexp.compile`. # Autocorrect replaces to regexp literal which is the simplest and fastest. # # @example # # # bad # Regexp...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/super_arguments.rb
Ruby
mit
12,856
master
8,569
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for redundant argument forwarding when calling super with arguments identical to # the method definition. # # Using zero arity `super` within a `define_method` block results in `RuntimeError`: # # [s...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/ambiguous_endless_method_definition.rb
Ruby
mit
12,856
master
2,214
# frozen_string_literal: true module RuboCop module Cop module Style # Looks for endless methods inside operations of lower precedence (`and`, `or`, and # modifier forms of `if`, `unless`, `while`, `until`) that are ambiguous due to # lack of parentheses. This may lead to unexpected behavior as...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/numeric_literal_prefix.rb
Ruby
mit
12,856
master
3,025
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for octal, hex, binary, and decimal literals using # uppercase prefixes and corrects them to lowercase prefix # or no prefix (in case of decimals). # # @example EnforcedOctalStyle: zero_with_o (default) ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/empty_method.rb
Ruby
mit
12,856
master
3,035
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for the formatting of empty method definitions. # By default it enforces empty method definitions to go on a single # line (compact style), but it can be configured to enforce the `end` # to go on its own line (...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/empty_class_definition.rb
Ruby
mit
12,856
master
4,315
# frozen_string_literal: true module RuboCop module Cop module Style # Enforces consistent style for empty class definitions. # # This cop can enforce either a standard class definition or `Class.new` # for classes with no body. # # The supported styles are: # # * ...
github
rubocop/rubocop
https://github.com/rubocop/rubocop
lib/rubocop/cop/style/redundant_begin.rb
Ruby
mit
12,856
master
6,728
# frozen_string_literal: true module RuboCop module Cop module Style # Checks for redundant `begin` blocks. A `begin` block is redundant # when the `rescue`/`ensure` can be handled by the enclosing method # or block definition directly, avoiding unnecessary indentation. # # @example...