90 lines
2.7 KiB
YAML
90 lines
2.7 KiB
YAML
inherit_from: .rubocop.common.yml
|
|
|
|
inherit_mode:
|
|
merge:
|
|
- Exclude
|
|
|
|
AllCops:
|
|
NewCops: disable
|
|
|
|
<%=
|
|
|
|
# if you want to see what this all evaluates to, you can run
|
|
# `require 'erb'; puts ERB.new(File.read(".rubocop.enforced.yml")).result(binding)` from IRB
|
|
|
|
# keys are cops you want to opt in for (nil being all cops)
|
|
# values are an array of directories to opt in for (nil being all directories)
|
|
OPT_IN = {
|
|
nil => %w[Gemfile.d].freeze,
|
|
'Layout' => %w[bin build config db doc engines gems script].freeze
|
|
}.freeze
|
|
|
|
# this code generates a configuration that disables all cops for all files
|
|
# _unless_ the cop is already configured in .rubocop.common.yml, OR the file
|
|
# is in one of the OPT_IN directories. It does this by generating an Exclude
|
|
# configuration for every cop (except already configured) that lists all
|
|
# directories (except OPT_IN). AllCops does not support an Include, and
|
|
# even if it did, inheritance to individual cops would not work correctly.
|
|
|
|
def generate_excludes(opt_in_array)
|
|
return nil unless opt_in_array
|
|
|
|
excludes = []
|
|
dirs_to_exclude_siblings_of = []
|
|
|
|
opt_in_array.each do |dir|
|
|
components = dir.split("/")
|
|
(0...components.length).each do |i|
|
|
ancestor = components[0..i].join("/")
|
|
exclude = "#{ancestor}/*"
|
|
excludes << exclude unless excludes.include?(exclude) || opt_in_array.include?(ancestor)
|
|
dirs_to_exclude_siblings_of << ancestor unless dirs_to_exclude_siblings_of.include?(ancestor)
|
|
end
|
|
end
|
|
|
|
dirs_to_find_siblings_of = dirs_to_exclude_siblings_of.map do |dir|
|
|
File.dirname(dir)
|
|
end.uniq
|
|
|
|
dirs_to_find_siblings_of.each do |dir|
|
|
dirs = Dir["#{dir}/*"]
|
|
.select { |dir| File.directory?(dir) }
|
|
.map { |dir| dir.sub(%r{^\./}, "") }
|
|
dirs -= dirs_to_exclude_siblings_of
|
|
excludes.concat(dirs.map { |d| "#{d}/**/*" })
|
|
end
|
|
|
|
excludes.sort
|
|
end
|
|
|
|
resolved_excludes = OPT_IN.transform_values do |dirs|
|
|
next nil unless dirs
|
|
|
|
generate_excludes((Array(dirs) + OPT_IN[nil]).uniq)
|
|
end
|
|
|
|
require 'yaml'
|
|
|
|
common_config = YAML.safe_load(File.read(".rubocop.common.yml"))
|
|
common_config["require"].each { |f| require f }
|
|
# already configured cops in common.yml are intended to apply to all files already
|
|
already_configured_cops = common_config.keys.select { |k| k.include?("/") && !common_config[k]['Exclude'] }.to_set
|
|
|
|
config = {}
|
|
RuboCop::Cop::Registry.all.each do |cop|
|
|
next if cop.department == :Metrics
|
|
next if cop.cop_name == 'Lint/Syntax'
|
|
next if already_configured_cops.include?(cop.cop_name)
|
|
|
|
key = [cop.cop_name, cop.department.to_s, nil].find do |key|
|
|
resolved_excludes.key?(key)
|
|
end
|
|
excludes = resolved_excludes[key]
|
|
next if excludes.nil?
|
|
|
|
config[cop.cop_name] = { "Exclude" => excludes }
|
|
end
|
|
|
|
config.to_yaml.sub(/^---\n/, "")
|
|
%>
|