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/directive_comment.rb | Ruby | mit | 12,856 | master | 6,591 | # frozen_string_literal: true
module RuboCop
# This class wraps the `Parser::Source::Comment` object that represents a
# special `rubocop:disable` and `rubocop:enable` comment and exposes what
# cops it contains.
class DirectiveComment
# @api private
LINT_DEPARTMENT = 'Lint'
# @api private
LINT... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/config_regeneration.rb | Ruby | mit | 12,856 | master | 958 | # frozen_string_literal: true
module RuboCop
# This class handles collecting the options for regenerating a TODO file.
# @api private
class ConfigRegeneration
AUTO_GENERATED_FILE = RuboCop::CLI::Command::AutoGenerateConfig::AUTO_GENERATED_FILE
COMMAND_REGEX = /(?<=`rubocop )(.*?)(?=`)/.freeze
DEFAULT... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/util.rb | Ruby | mit | 12,856 | master | 381 | # frozen_string_literal: true
module RuboCop
# This module contains a collection of useful utility methods.
module Util
def self.silence_warnings
# Replaces Kernel::silence_warnings since it hides any warnings,
# including the RuboCop ones
old_verbose = $VERBOSE
$VERBOSE = nil
yie... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/name_similarity.rb | Ruby | mit | 12,856 | master | 895 | # frozen_string_literal: true
module RuboCop
# Common functionality for finding names that are similar to a given name.
# @api private
module NameSimilarity
module_function
def find_similar_name(target_name, names)
similar_names = find_similar_names(target_name, names)
similar_names.first
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/arguments_env.rb | Ruby | mit | 12,856 | master | 392 | # frozen_string_literal: true
module RuboCop
# This is a class that reads optional command line arguments to rubocop from environment variable.
# @api private
class ArgumentsEnv
def self.read_as_arguments
if (arguments = ENV.fetch('RUBOCOP_OPTS', '')).empty?
[]
else
require 'shell... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/path_util.rb | Ruby | mit | 12,856 | master | 3,988 | # frozen_string_literal: true
module RuboCop
# Common methods and behaviors for dealing with paths.
module PathUtil
class << self
attr_accessor :relative_paths_cache
end
self.relative_paths_cache = Hash.new { |hash, key| hash[key] = {} }
module_function
# Returns the current working dir... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/lockfile.rb | Ruby | mit | 12,856 | master | 2,908 | # frozen_string_literal: true
begin
# We might not be running with `bundle exec`, so we need to pull in Bundler ourselves,
# in order to use `Bundler::LockfileParser`.
require 'bundler'
rescue LoadError
nil
end
module RuboCop
# Encapsulation of a lockfile for use when checking for gems.
# Does not actuall... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/pending_cops_reporter.rb | Ruby | mit | 12,856 | master | 1,936 | # frozen_string_literal: true
module RuboCop
# Reports information about pending cops that are not explicitly configured.
#
# This class is responsible for displaying warnings when new cops have been added to RuboCop
# but have not yet been enabled or disabled in the user's configuration.
# It provides a cen... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/version.rb | Ruby | mit | 12,856 | master | 5,774 | # frozen_string_literal: true
module RuboCop
# This module holds the RuboCop version information.
module Version
STRING = '1.86.1'
MSG = '%<version>s (using %<parser_version>s, ' \
'rubocop-ast %<rubocop_ast_version>s, ' \
'analyzing as Ruby %<target_ruby_version>s, ' \
'runn... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/config_validator.rb | Ruby | mit | 12,856 | master | 10,437 | # frozen_string_literal: true
module RuboCop
# Handles validation of configuration, for example cop names, parameter
# names, and Ruby versions.
# rubocop:disable Metrics/ClassLength
class ConfigValidator
extend SimpleForwardable
# @api private
COMMON_PARAMS = %w[Exclude Include Severity inherit_m... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/arguments_file.rb | Ruby | mit | 12,856 | master | 396 | # frozen_string_literal: true
module RuboCop
# This is a class that reads optional command line arguments to rubocop from .rubocop file.
# @api private
class ArgumentsFile
def self.read_as_arguments
if File.exist?('.rubocop') && !File.directory?('.rubocop')
require 'shellwords'
File.re... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/plugin.rb | Ruby | mit | 12,856 | master | 1,505 | # frozen_string_literal: true
require_relative 'plugin/configuration_integrator'
require_relative 'plugin/loader'
module RuboCop
# Provides a plugin for RuboCop extensions that conform to lint_roller.
# https://github.com/standardrb/lint_roller
# @api private
module Plugin
BUILTIN_INTERNAL_PLUGINS = {
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/yaml_duplication_checker.rb | Ruby | mit | 12,856 | master | 949 | # frozen_string_literal: true
module RuboCop
# Find duplicated keys from YAML.
# @api private
module YAMLDuplicationChecker
def self.check(yaml_string, filename, &on_duplicated)
handler = DuplicationCheckHandler.new(&on_duplicated)
parser = Psych::Parser.new(handler)
parser.parse(yaml_strin... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/string_interpreter.rb | Ruby | mit | 12,856 | master | 1,951 | # frozen_string_literal: true
module RuboCop
# Take a string with embedded escapes, and convert the escapes as the Ruby
# interpreter would when reading a double-quoted string literal.
# For example, "\\n" will be converted to "\n".
class StringInterpreter
STRING_ESCAPES = {
'\a' => "\a", '\b' => "\b... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/options.rb | Ruby | mit | 12,856 | master | 29,787 | # frozen_string_literal: true
require 'optparse'
require_relative 'arguments_env'
require_relative 'arguments_file'
module RuboCop
class IncorrectCopNameError < StandardError; end
class OptionArgumentError < StandardError; end
# This class handles command line options.
# @api private
class Options
E_S... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cached_data.rb | Ruby | mit | 12,856 | master | 2,283 | # frozen_string_literal: true
require 'json'
module RuboCop
# Converts RuboCop objects to and from the serialization format JSON.
# @api private
class CachedData
def initialize(filename)
@filename = filename
end
def from_json(text)
deserialize_offenses(JSON.parse(text))
end
def... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/warning.rb | Ruby | mit | 12,856 | master | 412 | # frozen_string_literal: true
module RuboCop
# A Warning exception is different from an Offense with severity 'warning'
# When a Warning is raised, this means that RuboCop was unable to perform a
# requested operation (such as inspecting or correcting a source file) due to
# user error
# For example, a confi... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/config_finder.rb | Ruby | mit | 12,856 | master | 2,201 | # frozen_string_literal: true
require_relative 'file_finder'
module RuboCop
# This class has methods related to finding configuration path.
# @api private
class ConfigFinder
DOTFILE = '.rubocop.yml'
XDG_CONFIG = 'config.yml'
RUBOCOP_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/config_loader_resolver.rb | Ruby | mit | 12,856 | master | 12,413 | # frozen_string_literal: true
require 'pathname'
require 'yaml'
require_relative 'plugin'
module RuboCop
# A help class for ConfigLoader that handles configuration resolution.
# @api private
class ConfigLoaderResolver # rubocop:disable Metrics/ClassLength
def resolve_plugins(rubocop_config, plugins)
p... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/runner.rb | Ruby | mit | 12,856 | master | 18,438 | # frozen_string_literal: true
require 'parallel'
module RuboCop
# This class handles the processing of files, which includes dealing with
# formatters and letting cops inspect the files.
class Runner # rubocop:disable Metrics/ClassLength
# An exception indicating that the inspection loop got stuck correctin... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/target_finder.rb | Ruby | mit | 12,856 | master | 8,039 | # frozen_string_literal: true
module RuboCop
# This class finds target files to inspect by scanning the directory tree and picking ruby files.
# @api private
class TargetFinder
HIDDEN_PATH_SUBSTRING = "#{File::SEPARATOR}."
def initialize(config_store, options = {})
@config_store = config_store
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/rake_task.rb | Ruby | mit | 12,856 | master | 3,445 | # frozen_string_literal: true
require 'rake'
require 'rake/tasklib'
module RuboCop
# Provides a custom rake task.
#
# require 'rubocop/rake_task'
# RuboCop::RakeTask.new
#
# Use global Rake namespace here to avoid namespace issues with custom
# rubocop-rake tasks
class RakeTask < ::Rake::TaskLib
a... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cache_config.rb | Ruby | mit | 12,856 | master | 2,334 | # frozen_string_literal: true
module RuboCop
# This class represents the cache config of the caching RuboCop runs.
# @api private
class CacheConfig
def self.root_dir
root = ENV.fetch('RUBOCOP_CACHE_ROOT', nil)
root ||= yield
root ||= if ENV.key?('XDG_CACHE_HOME')
# Include ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/server.rb | Ruby | mit | 12,856 | master | 1,306 | # frozen_string_literal: true
require_relative 'platform'
#
# This code is based on https://github.com/fohte/rubocop-daemon.
#
# Copyright (c) 2018 Hayato Kawai
#
# The MIT License (MIT)
#
# https://github.com/fohte/rubocop-daemon/blob/master/LICENSE.txt
#
module RuboCop
# The bootstrap module for server.
# @api ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/lsp.rb | Ruby | mit | 12,856 | master | 596 | # frozen_string_literal: true
module RuboCop
# The RuboCop's built-in LSP module.
module LSP
module_function
# Returns true when LSP is enabled, false when disabled.
#
# @return [Boolean]
def enabled?
@enabled ||= false
end
# Enable LSP.
#
# @return [void]
def enable... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/result_cache.rb | Ruby | mit | 12,856 | master | 9,151 | # frozen_string_literal: true
require 'digest/sha1'
require 'find'
require 'zlib'
require_relative 'cache_config'
module RuboCop
# Provides functionality for caching RuboCop runs.
# @api private
class ResultCache
NON_CHANGING = %i[color format formatters out debug display_time fail_level
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/lsp/stdin_runner.rb | Ruby | mit | 12,856 | master | 1,783 | # frozen_string_literal: true
#
# This code is based on https://github.com/standardrb/standard.
#
# Copyright (c) 2023 Test Double, Inc.
#
# The MIT License (MIT)
#
# https://github.com/standardrb/standard/blob/main/LICENSE.txt
#
module RuboCop
module Lsp
# Originally lifted from:
# https://github.com/Shopif... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/lsp/severity.rb | Ruby | mit | 12,856 | master | 969 | # frozen_string_literal: true
module RuboCop
module LSP
# Severity for Language Server Protocol of RuboCop.
# @api private
class Severity
SEVERITIES = {
fatal: LanguageServer::Protocol::Constant::DiagnosticSeverity::ERROR,
error: LanguageServer::Protocol::Constant::DiagnosticSeverit... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/lsp/server.rb | Ruby | mit | 12,856 | master | 1,845 | # frozen_string_literal: true
require 'language_server-protocol'
require_relative 'logger'
require_relative 'routes'
require_relative 'runtime'
#
# This code is based on https://github.com/standardrb/standard.
#
# Copyright (c) 2023 Test Double, Inc.
#
# The MIT License (MIT)
#
# https://github.com/standardrb/standar... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/lsp/diagnostic.rb | Ruby | mit | 12,856 | master | 5,649 | # frozen_string_literal: true
require 'language_server-protocol'
require_relative 'disable_comment_edits'
require_relative 'severity'
#
# This code is based on https://github.com/standardrb/standard.
#
# Copyright (c) 2023 Test Double, Inc.
#
# The MIT License (MIT)
#
# https://github.com/standardrb/standard/blob/mai... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/lsp/logger.rb | Ruby | mit | 12,856 | master | 459 | # frozen_string_literal: true
#
# This code is based on https://github.com/standardrb/standard.
#
# Copyright (c) 2023 Test Double, Inc.
#
# The MIT License (MIT)
#
# https://github.com/standardrb/standard/blob/main/LICENSE.txt
#
module RuboCop
module LSP
# Log for Language Server Protocol of RuboCop.
# @api... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/lsp/runtime.rb | Ruby | mit | 12,856 | master | 2,382 | # frozen_string_literal: true
require_relative 'diagnostic'
require_relative 'stdin_runner'
#
# This code is based on https://github.com/standardrb/standard.
#
# Copyright (c) 2023 Test Double, Inc.
#
# The MIT License (MIT)
#
# https://github.com/standardrb/standard/blob/main/LICENSE.txt
#
module RuboCop
module LS... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/lsp/disable_comment_edits.rb | Ruby | mit | 12,856 | master | 4,347 | # frozen_string_literal: true
module RuboCop
module LSP
# Builds LSP text edits for rubocop:disable comments.
# @api private
class DisableCommentEdits
def initialize(offense:, document_encoding:, processed_source:)
@offense = offense
@document_encoding = document_encoding
@p... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/lsp/routes.rb | Ruby | mit | 12,856 | master | 7,853 | # frozen_string_literal: true
require_relative 'severity'
#
# This code is based on https://github.com/standardrb/standard.
#
# Copyright (c) 2023 Test Double, Inc.
#
# The MIT License (MIT)
#
# https://github.com/standardrb/standard/blob/main/LICENSE.txt
#
module RuboCop
module LSP
# Routes for Language Server... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/core_ext/string.rb | Ruby | mit | 12,856 | master | 526 | # frozen_string_literal: true
# Extensions to the core String class
class String
unless method_defined?(:blank?) && ' '.blank?
# Checks whether a string is blank. A string is considered blank if it
# is either empty or contains only whitespace characters.
#
# @return [Boolean] true is the string is b... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/mcp/server.rb | Ruby | mit | 12,856 | master | 7,046 | # frozen_string_literal: true
begin
require 'mcp'
required_mcp_version = '0.6.0'
if Gem::Version.new(required_mcp_version) > Gem::Version.new(MCP::VERSION)
# While `mcp` is not a runtime dependency, users may have an outdated version installed.
warn <<~MESSAGE
Error: `mcp` gem version #{MCP::VERS... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/commissioner.rb | Ruby | mit | 12,856 | master | 6,226 | # frozen_string_literal: true
module RuboCop
module Cop
# Commissioner class is responsible for processing the AST and delegating
# work to the specified cops.
class Commissioner
include RuboCop::AST::Traversal
RESTRICTED_CALLBACKS = %i[on_send on_csend after_send after_csend].freeze
p... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/autocorrect_logic.rb | Ruby | mit | 12,856 | master | 5,303 | # frozen_string_literal: true
module RuboCop
module Cop
# This module encapsulates the logic for autocorrect behavior for a cop.
module AutocorrectLogic
def autocorrect?
autocorrect_requested? && correctable? && autocorrect_enabled?
end
def autocorrect_with_disable_uncorrectable?
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/documentation.rb | Ruby | mit | 12,856 | master | 1,675 | # frozen_string_literal: true
module RuboCop
module Cop
# Helpers for builtin documentation
module Documentation
module_function
# @api private
def department_to_basename(department)
"cops_#{department.to_s.downcase.tr('/', '_')}"
end
# @api private
def url_for(c... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/base.rb | Ruby | mit | 12,856 | master | 17,700 | # frozen_string_literal: true
module RuboCop
module Cop
# A scaffold for concrete cops.
#
# The Cop::Base class is meant to be extended.
#
# Cops track offenses and can autocorrect them on the fly.
#
# A commissioner object is responsible for traversing the AST and invoking
# the spec... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/generator.rb | Ruby | mit | 12,856 | master | 7,007 | # frozen_string_literal: true
module RuboCop
module Cop
# Source and spec generator for new cops
#
# This generator will take a cop name and generate a source file
# and spec file when given a valid qualified cop name.
# @api private
class Generator
SOURCE_TEMPLATE = <<~RUBY
# f... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/message_annotator.rb | Ruby | mit | 12,856 | master | 4,191 | # frozen_string_literal: true
module RuboCop
module Cop
# Message Annotator class annotates a basic offense message
# based on params passed into initializer.
#
# @see #initialize
#
# @example
# RuboCop::Cop::MessageAnnotator.new(
# config, cop_name, cop_config, @options
# ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/cop.rb | Ruby | mit | 12,856 | master | 5,513 | # frozen_string_literal: true
require 'uri'
require_relative 'legacy/corrections_proxy'
module RuboCop
module Cop
# @deprecated Use Cop::Base instead
# Legacy scaffold for Cops.
# See https://docs.rubocop.org/rubocop/v1_upgrade_notes.html
class Cop < Base
attr_reader :offenses
exclude_f... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/internal_affairs.rb | Ruby | mit | 12,856 | master | 2,377 | # frozen_string_literal: true
require_relative 'internal_affairs/cop_description'
require_relative 'internal_affairs/cop_enabled'
require_relative 'internal_affairs/create_empty_file'
require_relative 'internal_affairs/empty_line_between_expect_offense_and_correction'
require_relative 'internal_affairs/example_descrip... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/severity.rb | Ruby | mit | 12,856 | master | 1,410 | # frozen_string_literal: true
module RuboCop
module Cop
# Severity class is simple value object about severity
class Severity
include Comparable
NAMES = %i[info refactor convention warning error fatal].freeze
# @api private
CODE_TABLE = { I: :info, R: :refactor, C: :convention,
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/variable_force.rb | Ruby | mit | 12,856 | master | 13,562 | # frozen_string_literal: true
module RuboCop
module Cop
# This force provides a way to track local variables and scopes of Ruby.
# Cops interact with this force need to override some of the hook methods.
#
# def before_entering_scope(scope, variable_table)
# end
#
# def after_... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/team.rb | Ruby | mit | 12,856 | master | 10,805 | # frozen_string_literal: true
module RuboCop
module Cop
# A group of cops, ready to be called on duty to inspect files.
# Team is responsible for selecting only relevant cops to be sent on duty,
# as well as insuring that the needed forces are sent along with them.
#
# For performance reasons, Te... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/force.rb | Ruby | mit | 12,856 | master | 1,048 | # frozen_string_literal: true
module RuboCop
module Cop
# A scaffold for concrete forces.
class Force
# @api private
class HookError < StandardError
attr_reader :joining_cop
def initialize(joining_cop)
super
@joining_cop = joining_cop
end
end
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/offense.rb | Ruby | mit | 12,856 | master | 6,435 | # frozen_string_literal: true
module RuboCop
module Cop
# An offense represents a style violation detected by RuboCop.
class Offense
include Comparable
# @api private
COMPARISON_ATTRIBUTES = %i[line column cop_name message severity].freeze
# @api public
#
# @!attribute [... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/registry.rb | Ruby | mit | 12,856 | master | 9,329 | # frozen_string_literal: true
module RuboCop
module Cop
# Error raised when an unqualified cop name is used that could
# refer to two or more cops under different departments
class AmbiguousCopName < RuboCop::Error
MSG = 'Ambiguous cop name `%<name>s` used in %<origin>s needs ' \
'depar... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/corrector.rb | Ruby | mit | 12,856 | master | 4,882 | # frozen_string_literal: true
module RuboCop
module Cop
# This class takes a source buffer and rewrite its source
# based on the different correction rules supplied.
#
# Important!
# The nodes modified by the corrections should be part of the
# AST of the source_buffer.
class Corrector < ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/ignored_node.rb | Ruby | mit | 12,856 | master | 943 | # frozen_string_literal: true
module RuboCop
module Cop
# Handles adding and checking ignored nodes.
module IgnoredNode
def ignore_node(node)
ignored_nodes << node
end
def part_of_ignored_node?(node)
ignored_nodes.map(&:loc).any? do |ignored_loc|
next false if ign... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/util.rb | Ruby | mit | 12,856 | master | 6,754 | # frozen_string_literal: true
module RuboCop
module Cop
# This module contains a collection of useful utility methods.
# rubocop:disable Metrics/ModuleLength
module Util
include PathUtil
# Match literal regex characters, not including anchors, character
# classes, alternatives, groups,... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/exclude_limit.rb | Ruby | mit | 12,856 | master | 1,705 | # frozen_string_literal: true
module RuboCop
# Allows specified configuration options to have an exclude limit
# ie. a maximum value tracked that it can be used by `--auto-gen-config`.
module ExcludeLimit
class << self
attr_accessor :tmp_dir
# Reads the aggregated exclude limit values for a cop ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/badge.rb | Ruby | mit | 12,856 | master | 2,050 | # frozen_string_literal: true
module RuboCop
module Cop
# Identifier of all cops containing a department and cop name.
#
# All cops are identified by their badge. For example, the badge for
# `RuboCop::Cop::Layout::IndentationStyle` is `Layout/IndentationStyle`.
# Badges can be parsed as either `... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/generator/require_file_injector.rb | Ruby | mit | 12,856 | master | 2,365 | # frozen_string_literal: true
module RuboCop
module Cop
class Generator
# A class that injects a require directive into the root RuboCop file.
# It looks for other directives that require files in the same (cop)
# namespace and injects the provided one in alpha
class RequireFileInjector
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/generator/configuration_injector.rb | Ruby | mit | 12,856 | master | 1,840 | # frozen_string_literal: true
module RuboCop
module Cop
class Generator
# A class that injects a require directive into the root RuboCop file.
# It looks for other directives that require files in the same (cop)
# namespace and injects the provided one in alpha
class ConfigurationInjector... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/predicate_method.rb | Ruby | mit | 12,856 | master | 10,251 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Checks that predicate methods end with `?` and non-predicate methods do not.
#
# The names of predicate methods (methods that return a boolean value) should end
# in a question mark. Methods that don't return a boolea... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/accessor_method_name.rb | Ruby | mit | 12,856 | master | 2,099 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Avoid prefixing accessor method names with `get_` or `set_`.
# Applies to both instance and class methods.
#
# NOTE: Method names starting with `get_` or `set_` only register an offense
# when the methods match ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/method_parameter_name.rb | Ruby | mit | 12,856 | master | 1,701 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Checks method parameter names for how descriptive they
# are. It is highly configurable.
#
# The `MinNameLength` config option takes an integer. It represents
# the minimum amount of characters the name must be.... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/heredoc_delimiter_case.rb | Ruby | mit | 12,856 | master | 1,625 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Checks that your heredocs are using the configured case.
# By default it is configured to enforce uppercase heredocs.
#
# @example EnforcedStyle: uppercase (default)
# # bad
# <<-sql
# SELECT... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/block_forwarding.rb | Ruby | mit | 12,856 | master | 4,915 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# In Ruby 3.1, anonymous block forwarding has been added.
#
# This cop identifies places where `do_something(&block)` can be replaced
# by `do_something(&)`.
#
# It also supports the opposite style by altern... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/memoized_instance_variable_name.rb | Ruby | mit | 12,856 | master | 9,188 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Checks for memoized methods whose instance variable name
# does not match the method name. Applies to both regular methods
# (defined with `def`) and dynamic methods (defined with
# `define_method` or `define_singleto... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/class_and_module_camel_case.rb | Ruby | mit | 12,856 | master | 1,250 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Checks for class and module names with
# an underscore in them.
#
# `AllowedNames` config takes an array of permitted names.
# Its default value is `['module_parent']`.
# These names can be full class/modu... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/inclusive_language.rb | Ruby | mit | 12,856 | master | 10,257 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Recommends the use of inclusive language instead of problematic terms.
# The cop can check the following locations for offenses:
#
# - identifiers
# - constants
# - variables
# - strings
# - sy... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/constant_name.rb | Ruby | mit | 12,856 | master | 2,561 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Checks whether constant names are written using
# SCREAMING_SNAKE_CASE.
#
# To avoid false positives, it ignores cases in which we cannot know
# for certain the type of value that would be assigned to a constant... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/file_name.rb | Ruby | mit | 12,856 | master | 7,967 | # frozen_string_literal: true
require 'pathname'
module RuboCop
module Cop
module Naming
# Makes sure that Ruby source files have snake_case
# names. Ruby scripts (i.e. source files with a shebang in the
# first line) are ignored.
#
# The cop also ignores `.gemspec` files, because ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/block_parameter_name.rb | Ruby | mit | 12,856 | master | 1,642 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Checks block parameter names for how descriptive they
# are. It is highly configurable.
#
# The `MinNameLength` config option takes an integer. It represents
# the minimum amount of characters the name must be. ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/rescued_exceptions_variable_name.rb | Ruby | mit | 12,856 | master | 5,472 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Makes sure that rescued exceptions variables are named as
# expected.
#
# The `PreferredName` config option takes a `String`. It represents
# the required name of the variable. Its default is `e`.
#
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/variable_name.rb | Ruby | mit | 12,856 | master | 3,341 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Checks that the configured style (snake_case or camelCase) is used for all variable names.
# This includes local variables, instance variables, class variables, method arguments
# (positional, keyword, rest or block), and b... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/variable_number.rb | Ruby | mit | 12,856 | master | 3,921 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Makes sure that all numbered variables use the
# configured style, snake_case, normalcase, or non_integer,
# for their numbering.
#
# Additionally, `CheckMethodNames` and `CheckSymbols` configuration options
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/heredoc_delimiter_naming.rb | Ruby | mit | 12,856 | master | 1,298 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Checks that your heredocs are using meaningful delimiters.
# By default it disallows `END` and `EO*`, and can be configured through
# forbidden listing additional delimiters.
#
# @example
#
# # goo... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/method_name.rb | Ruby | mit | 12,856 | master | 7,278 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Makes sure that all methods use the configured style,
# snake_case or camelCase, for their names.
#
# Method names matching patterns are always allowed.
#
# The cop can be configured with `AllowedPatterns`... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/predicate_prefix.rb | Ruby | mit | 12,856 | master | 6,213 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Checks that predicate method names end with a question mark and
# do not start with a forbidden prefix.
#
# A method is determined to be a predicate method if its name starts with
# one of the prefixes listed in... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/binary_operator_parameter_name.rb | Ruby | mit | 12,856 | master | 1,468 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Makes sure that certain binary operator methods have their
# sole parameter named `other`.
#
# @example
#
# # bad
# def +(amount); end
#
# # good
# def +(other); end
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/naming/ascii_identifiers.rb | Ruby | mit | 12,856 | master | 2,375 | # frozen_string_literal: true
module RuboCop
module Cop
module Naming
# Checks for non-ascii characters in identifier and constant names.
# Identifiers are always checked and whether constants are checked
# can be controlled using AsciiConstants config.
#
# @example
# # bad
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/legacy/corrector.rb | Ruby | mit | 12,856 | master | 1,123 | # frozen_string_literal: true
module RuboCop
module Cop
module Legacy
# Legacy Corrector for v0 API support.
# See https://docs.rubocop.org/rubocop/v1_upgrade_notes.html
class Corrector < RuboCop::Cop::Corrector
# Support legacy second argument
def initialize(source, corr = [])
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/legacy/corrections_proxy.rb | Ruby | mit | 12,856 | master | 985 | # frozen_string_literal: true
module RuboCop
module Cop
module Legacy
# Legacy support for Corrector#corrections
# See https://docs.rubocop.org/rubocop/v1_upgrade_notes.html
class CorrectionsProxy
def initialize(corrector)
@corrector = corrector
end
def <<(cal... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/method_length.rb | Ruby | mit | 12,856 | master | 2,104 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
# Checks if the length of a method exceeds some maximum value.
# Comment lines can optionally be allowed.
# The maximum allowed length is configurable.
#
# You can set constructs you want to fold with `CountAsOne... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/block_nesting.rb | Ruby | mit | 12,856 | master | 2,714 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
# Checks for excessive nesting of conditional and looping constructs.
# Deeply nested code is harder to read, understand, and maintain.
# Extracting nested logic into methods improves clarity.
#
# You can configu... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/collection_literal_length.rb | Ruby | mit | 12,856 | master | 2,436 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
# Checks for literals with extremely many entries. This is indicative of
# configuration or data that may be better extracted somewhere else, like
# a database, fetched from an API, or read from a non-code file (CSV,
#... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/parameter_lists.rb | Ruby | mit | 12,856 | master | 4,413 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
# Checks for methods with too many parameters.
#
# The maximum number of parameters is configurable.
# Keyword arguments can optionally be excluded from the total count,
# as they add less complexity than positio... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/cyclomatic_complexity.rb | Ruby | mit | 12,856 | master | 2,160 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
# Checks that the cyclomatic complexity of methods is not higher
# than the configured maximum. The cyclomatic complexity is the number of
# linearly independent paths through a method. The algorithm counts
# decision ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/module_length.rb | Ruby | mit | 12,856 | master | 1,640 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
# Checks if the length of a module exceeds some maximum value.
# Comment lines can optionally be ignored.
# The maximum allowed length is configurable.
#
# You can set constructs you want to fold with `CountAsOne... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/abc_size.rb | Ruby | mit | 12,856 | master | 1,914 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
# 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
# and https://en.... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/block_length.rb | Ruby | mit | 12,856 | master | 2,475 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
# Checks if the length of a block exceeds some maximum value.
# Comment lines can optionally be ignored.
# The maximum allowed length is configurable.
# The cop can be configured to ignore blocks passed to certain meth... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/perceived_complexity.rb | Ruby | mit | 12,856 | master | 2,258 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
# Tries to produce a complexity score that's a measure of the
# complexity the reader experiences when looking at a method. For that
# reason it considers `when` nodes as something that doesn't add as much
# complexity... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/class_length.rb | Ruby | mit | 12,856 | master | 2,010 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
# Checks if the length of a class exceeds some maximum value.
# Comment lines can optionally be ignored.
# The maximum allowed length is configurable.
#
# You can set constructs you want to fold with `CountAsOne`... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/utils/abc_size_calculator.rb | Ruby | mit | 12,856 | master | 4,387 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
module Utils
# > ABC is .. a software size metric .. computed by counting the number
# > of assignments, branches and conditions for a section of code.
# > http://c2.com/cgi/wiki?AbcMetric
#
# We ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/utils/repeated_attribute_discount.rb | Ruby | mit | 12,856 | master | 4,881 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
module Utils
# @api private
#
# Identifies repetitions `{c}send` calls with no arguments:
#
# foo.bar
# foo.bar # => repeated
# foo.bar.baz.qux # => inner send repeated
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/utils/repeated_csend_discount.rb | Ruby | mit | 12,856 | master | 1,036 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
module Utils
# @api private
#
# Identifies repetitions `&.` on the same variable:
#
# my_var&.foo
# my_var&.bar # => repeated
# my_var = baz # => reset
# my_var&.qux # ... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/utils/iterating_block.rb | Ruby | mit | 12,856 | master | 2,247 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
module Utils
# Used to identify iterating blocks like `.map{}` and `.map(&:...)`
module IteratingBlock
enumerable = %i[
all? any? chain chunk chunk_while collect collect_concat count cycle
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/metrics/utils/code_length_calculator.rb | Ruby | mit | 12,856 | master | 6,585 | # frozen_string_literal: true
module RuboCop
module Cop
module Metrics
module Utils
# Helps to calculate code length for the provided node.
class CodeLengthCalculator
extend NodePattern::Macros
include Util
FOLDABLE_TYPES = %i[array hash heredoc method_call].f... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/correctors/each_to_for_corrector.rb | Ruby | mit | 12,856 | master | 1,288 | # frozen_string_literal: true
module RuboCop
module Cop
# This class autocorrects `#each` enumeration to `for` iteration.
class EachToForCorrector
extend NodePattern::Macros
CORRECTION_WITH_ARGUMENTS = 'for %<variables>s in %<collection>s do'
CORRECTION_WITHOUT_ARGUMENTS = 'for _ in %<enum... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/correctors/require_library_corrector.rb | Ruby | mit | 12,856 | master | 628 | # frozen_string_literal: true
module RuboCop
module Cop
# This class ensures a require statement is present for a standard library
# determined by the variable library_name
class RequireLibraryCorrector
extend RangeHelp
class << self
def correct(corrector, node, library_name)
... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/correctors/condition_corrector.rb | Ruby | mit | 12,856 | master | 635 | # frozen_string_literal: true
module RuboCop
module Cop
# This class does condition autocorrection
class ConditionCorrector
class << self
def correct_negative_condition(corrector, node)
condition = negated_condition(node)
corrector.replace(node.loc.keyword, node.inverse_key... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/correctors/unused_arg_corrector.rb | Ruby | mit | 12,856 | master | 1,142 | # frozen_string_literal: true
module RuboCop
module Cop
# This autocorrects unused arguments.
class UnusedArgCorrector
extend RangeHelp
class << self
attr_reader :processed_source
def correct(corrector, processed_source, node)
return if %i[kwarg kwoptarg].include?(node... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/correctors/for_to_each_corrector.rb | Ruby | mit | 12,856 | master | 1,650 | # frozen_string_literal: true
module RuboCop
module Cop
# This class autocorrects `for` iteration to `#each` enumeration.
class ForToEachCorrector
extend NodePattern::Macros
CORRECTION = '%<collection>s%<dot>seach do |%<argument>s|'
def initialize(for_node)
@for_node = for_... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/correctors/line_break_corrector.rb | Ruby | mit | 12,856 | master | 2,106 | # frozen_string_literal: true
module RuboCop
module Cop
# This class handles autocorrection for code that needs to be moved
# to new lines.
class LineBreakCorrector
extend Alignment
extend TrailingBody
extend Util
class << self
attr_reader :processed_source
def c... |
github | rubocop/rubocop | https://github.com/rubocop/rubocop | lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb | Ruby | mit | 12,856 | master | 3,588 | # frozen_string_literal: true
module RuboCop
module Cop
# Autocorrection logic for the closing brace of a literal either
# on the same line as the last contained elements, or a new line.
class MultilineLiteralBraceCorrector
include MultilineLiteralBraceLayout
include RangeHelp
def self... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.