-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
80 lines (63 loc) · 2.18 KB
/
Copy pathRakefile
File metadata and controls
80 lines (63 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
RuboCop::RakeTask.new(:rubocop)
task default: %i[spec rubocop]
desc 'Generate a new cop with a template'
task :new_cop, [:cop] do |_task, args|
require 'rubocop'
cop_name = args.fetch(:cop) do
warn 'usage: bundle exec rake new_cop[Department/Name]'
exit!
end
generator = RuboCop::Cop::Generator.new(cop_name)
generator.write_source
generator.write_spec
generator.inject_require(root_file_path: 'lib/rubocop/cop/hash_inspect_cops.rb')
generator.inject_config(config_file_path: 'config/default.yml')
puts generator.todo
end
desc 'Run cop against clean-module baseline (requires network; CI-only)'
task :baseline do
require 'open3'
require 'tmpdir'
repos = %w[
https://github.com/puppetlabs/puppetlabs-stdlib.git
https://github.com/puppetlabs/puppetlabs-concat.git
]
Dir.mktmpdir('rubocop-hash_inspect-baseline') do |tmpdir|
repos.each do |repo|
name = File.basename(repo, '.git')
clone_dir = File.join(tmpdir, name)
puts "Cloning #{repo}..."
system("git clone --depth=1 --quiet #{repo} #{clone_dir}") ||
abort("Failed to clone #{repo}")
config_path = File.join(clone_dir, '.rubocop_baseline.yml')
File.write(config_path, <<~YAML)
plugins:
- rubocop-hash_inspect
AllCops:
DisabledByDefault: true
NewCops: enable
TargetRubyVersion: 3.4
HashInspect/LegacyHashInspectFormat:
Enabled: true
YAML
puts "Running cop on #{name}..."
cmd = 'bundle exec rubocop --only HashInspect/LegacyHashInspectFormat ' \
"--config #{config_path} --format progress #{clone_dir}"
stdout, stderr, status = Open3.capture3(cmd)
unless status.success?
puts stdout
puts stderr
abort "BASELINE FAILURE: #{name} produced offenses. " \
'Review above output for false positives or genuine upstream legacy-format literals.'
end
puts "#{name}: CLEAN (zero offenses)"
end
end
end