rubocop_plus 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ module RubocopPlus
2
+ module Commands
3
+ # Helpers for creating output are grouped in this file.
4
+ class Rubo < Cri::CommandRunner
5
+ def write_results_message
6
+ prefix = "#{total_violations_count} issues found, results written to rubocop/"
7
+ prefix = total_violations_count.zero? ? prefix.rubo_green : prefix.rubo_red
8
+ puts "#{prefix} (rubocop_plus v#{installed_version_of_gem} / rubocop v#{rubocop_version_name})"
9
+ end
10
+
11
+ def write_starting_message
12
+ print "Running rubocop ... "
13
+ end
14
+
15
+ # Read the total number of violations from the output. Unfortunately, rubocop doesn't have a direct way to generate
16
+ # this number, but it does produce a file with the output burried inside it. We can search the file and figure out the
17
+ # violations count. The file will have a line that looks like this:
18
+ # 1234 Total
19
+ def determine_total_violations_count
20
+ total_line = ""
21
+ File.readlines(style_counts_text_file_name).each { |line| total_line = line if line.include?("Total") }
22
+ @total_violations = total_line.empty? ? 0 : total_line.split(" ").first.to_i
23
+ end
24
+
25
+ # Return the total violations count from the last rubocop run and remember the result. This result should not do
26
+ # any validation to make sure the file exists, or is correct. That is checked in other parts of the system.
27
+ def total_violations_count
28
+ return @total_violations unless @total_violations.nil?
29
+
30
+ first_line = File.read(total_violations_count_text_file_name)
31
+ @total_violations = first_line.strip.to_i
32
+ end
33
+
34
+ # This method writes a single integer to a file which represents the total number of violations. The value in this file
35
+ # can be used to fail builds on the CI/CD pipeline which have too many violations. Rubocop doesn't appear to have a
36
+ # formatter that will write the total number of violations to a file. Fortunately, we can pull this information out of
37
+ # some other files and write the output ourselves.
38
+ def generate_total_violations_file
39
+ File.open(total_violations_count_text_file_name, 'w') { |f| f.print determine_total_violations_count }
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,57 @@
1
+ module RubocopPlus
2
+ module Commands
3
+ # Helpers for performing validations are grouped in this file.
4
+ class Rubo < Cri::CommandRunner
5
+ def check_if_yml_present!
6
+ raise RubocopPlus::Commands::MissingYml unless rubocop_yml_present?
7
+ end
8
+
9
+ def check_if_yml_has_correct_content!
10
+ raise RubocopPlus::Commands::IncorrectYml unless rubocop_yml_has_correct_content?
11
+ end
12
+
13
+ def check_if_rubocop_command_exists!
14
+ raise RubocopPlus::Commands::NoRubocopCommand unless rubocop_command_exists?
15
+ end
16
+
17
+ def check_if_results_exist!
18
+ error = RubocopPlus::Commands::BadOutput
19
+
20
+ check_if_violations_count_exists?
21
+ raise error, "The '#{output_folder_name}' folder does not exist." unless File.directory?(output_folder_name)
22
+ raise error, "Missing #{style_issues_text_file_name}" unless File.exist?(style_issues_text_file_name)
23
+ raise error, "Missing #{style_issues_html_file_name}" unless File.exist?(style_issues_html_file_name)
24
+ raise error, "Missing #{style_counts_text_file_name}" unless File.exist?(style_counts_text_file_name)
25
+ end
26
+
27
+ def check_if_violations_count_exists?
28
+ error = RubocopPlus::Commands::BadOutput
29
+ raise error, "Missing #{total_violations_count_text_file_name}" unless File.exist?(total_violations_count_text_file_name)
30
+
31
+ violations = File.read(total_violations_count_text_file_name)
32
+ raise error, "#{total_violations_count_text_file_name} is empty" if violations.nil? || violations.strip.empty?
33
+ end
34
+
35
+ # This method is called when the user runs `rubo --total-violations`. That option is used to open the "total violations
36
+ # counts" file and print the number. However, the user can run `rubo`, wait for a bit, delete his rubocop folder
37
+ # and THEN run `rubo --total-violations`. This is a little different from the other checks where we are IMMEDIATELY
38
+ # checking the results of the rubo command. In those checks, we're trying to make sure the rubo command worked correctly
39
+ # and was successfully able to write results. In this check, we're making sure the files are still around before we try
40
+ # and open them.
41
+ def check_if_total_violations_count_still_present_and_valid!
42
+ error = RubocopPlus::Commands::OutputMissing
43
+ prefix = "Cannot proceed."
44
+ raise error, "#{prefix} The '#{output_folder_name}' folder does not exist." unless File.directory?(output_folder_name)
45
+
46
+ file_name = total_violations_count_text_file_name
47
+ raise error, "#{prefix} The #{file_name} file is missing." unless File.exist?(file_name)
48
+
49
+ violations = File.read(file_name)
50
+ raise error, "#{prefix} The #{file_name} file is empty." if violations.nil? || violations.strip.empty?
51
+
52
+ violations = violations.strip
53
+ raise error, "#{prefix} The #{file_name} file contains non-digit characters." unless violations =~ /^\d*$/
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,8 @@
1
+ module Cri
2
+ # A small monkey patch to force the cri gem to stop coloring output.
3
+ module Platform
4
+ def self.color?(_io)
5
+ false
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,91 @@
1
+ # https://gist.github.com/steakknife/88b6c3837a5e90a08296
2
+ # Copyright (c) 2014,2016 Barry Allard <barry.allard@gmail.com>
3
+ # License: MIT
4
+ #
5
+ # inspiration: https://stackoverflow.com/questions/2889720/one-liner-in-ruby-for-displaying-a-prompt-getting-input-and-assigning-to-a-var
6
+ #
7
+ # Which Bourne shell?
8
+ #
9
+ # require 'which'
10
+ #
11
+ # Which 'sh'
12
+ #
13
+ #
14
+ # Or all zsh(es)
15
+ #
16
+ # require 'which'
17
+ #
18
+ # WhichAll 'zsh'
19
+ #
20
+ module Which
21
+ # similar to `which {{cmd}}`, except relative paths *are* always expanded
22
+ # returns: first match absolute path (String) to cmd (no symlinks followed),
23
+ # or nil if no executable found
24
+ def which(cmd)
25
+ which0(cmd) do |abs_exe|
26
+ return abs_exe
27
+ end
28
+ nil
29
+ end
30
+
31
+ # similar to `which -a {{cmd}}`, except relative paths *are* always expanded
32
+ # returns: always an array, or [] if none found
33
+ def which_all(cmd)
34
+ results = []
35
+ which0(cmd) do |abs_exe|
36
+ results << abs_exe
37
+ end
38
+ results
39
+ end
40
+
41
+ def real_executable?(file)
42
+ File.executable?(file) && !File.directory?(file)
43
+ end
44
+
45
+ def executable_file_extensions
46
+ ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
47
+ end
48
+
49
+ def search_paths
50
+ ENV['PATH'].split(File::PATH_SEPARATOR)
51
+ end
52
+
53
+ def find_executable(path, cmd, &_block)
54
+ executable_file_extensions.each do |ext|
55
+ if real_executable?(abs_exe = File.expand_path(cmd + ext, path))
56
+ yield(abs_exe)
57
+ end
58
+ end
59
+ end
60
+
61
+ # internal use only
62
+ # +_found_exe+ is yielded to on *all* successful match(es),
63
+ # with path to absolute file (String)
64
+ def which0(cmd, &found_exe)
65
+ # call expand_path(f, nil) == expand_path(f) for relative/abs path cmd
66
+ find_executable(nil, cmd, &found_exe) if File.basename(cmd) != cmd
67
+
68
+ search_paths.each do |path|
69
+ find_executable(path, cmd, &found_exe)
70
+ end
71
+ end
72
+
73
+ module_function(*public_instance_methods) # `extend self`, sorta
74
+ end
75
+
76
+ # make Which() and WhichAll() work
77
+ module Kernel
78
+ # rubocop:disable Naming/MethodName
79
+ # return abs-path to +cmd+
80
+ def Which(cmd)
81
+ Which.which cmd
82
+ end
83
+ module_function :Which
84
+
85
+ # return all abs-path(s) to +cmd+ or [] if none
86
+ def WhichAll(cmd)
87
+ Which.which_all cmd
88
+ end
89
+ module_function :WhichAll
90
+ # rubocop:enable Naming/MethodName
91
+ end
@@ -0,0 +1,14 @@
1
+ require "rubocop_plus/version"
2
+ require "rubocop_plus/core_ext/string"
3
+ require "rubocop"
4
+ # require "rubocop-performance"
5
+ # require "rubocop-rails"
6
+
7
+ # Setup pry for development when running "rake console". Guard against load
8
+ # errors in production (since pry is not a runtime dependency in the .gemspec)
9
+ # rubocop:disable Lint/HandleExceptions
10
+ begin
11
+ require "pry"
12
+ rescue LoadError
13
+ end
14
+ # rubocop:enable Lint/HandleExceptions
@@ -0,0 +1,23 @@
1
+ # Add some ome simple colorization methods for formatting console output.
2
+ # Prefix methods with rs_ so they don't collide with other gems.
3
+ class String
4
+ class << self
5
+ attr_accessor :allow_color
6
+ end
7
+
8
+ def rubo_colorize(color_code)
9
+ String.allow_color ? "\e[#{color_code}m#{self}\e[0m" : self
10
+ end
11
+
12
+ def rubo_red
13
+ rubo_colorize(31)
14
+ end
15
+
16
+ def rubo_green
17
+ rubo_colorize(32)
18
+ end
19
+
20
+ def rubo_yellow
21
+ rubo_colorize(33)
22
+ end
23
+ end
@@ -0,0 +1,4 @@
1
+ module RubocopPlus
2
+ VERSION = "1.11.0".freeze
3
+ RUBOCOP_VERSION = '0.79.0'.freeze
4
+ end
@@ -0,0 +1,14 @@
1
+ # DO NOT MODIFY THIS FILE unless you want to deviate from the rubocop_plus ruleset.
2
+
3
+ # This file defines the settings used by rubocop when it runs. You would normally add your customizations directly to this
4
+ # file, but this file has been pre configured to read settings out of the rubocop_plus gem instead.
5
+
6
+ # Tell rubocop to load its settings from the rubocop_plus gem.
7
+ inherit_gem:
8
+ rubocop_plus: config/rubocop.yml
9
+
10
+ Rails:
11
+ Enabled: true
12
+
13
+ # Place custom settings below this comment. All customizations will OVERRIDE rubocop_plus rules. rubocop_plus & rubocop
14
+ # do not attempt to merge these settings with their defaults. Long term changes should be ported to the rubocop_plus gem.
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "rubocop_plus/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "rubocop_plus"
7
+ spec.version = RubocopPlus::VERSION
8
+ spec.authors = ["roberts1000"]
9
+ spec.email = ["roberts@corlewsolutions.com"]
10
+
11
+ spec.summary = "Enhancements to the standard rubocop gem."
12
+ spec.description = "Enhancements to the standard rubocop gem."
13
+ spec.homepage = "https://github.com/roberts1000/rubocop_plus"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 2.0"
24
+ spec.add_development_dependency "pry", "~> 0.12.2"
25
+ spec.add_development_dependency "rake", "~> 13.0"
26
+ spec.add_development_dependency "rspec", "~> 3.9.0"
27
+
28
+ spec.add_dependency "cri", "~> 2.0"
29
+ spec.add_dependency "rubocop", RubocopPlus::RUBOCOP_VERSION.to_s
30
+ spec.add_dependency "rubocop-performance", "~> 1.5.2"
31
+ spec.add_dependency "rubocop-rails", "~> 2.4.1"
32
+ spec.add_dependency "rubocop-rspec", "~> 1.37.1"
33
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop_plus
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.11.0
5
+ platform: ruby
6
+ authors:
7
+ - roberts1000
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.12.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.12.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.9.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: cri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.79.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.79.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-performance
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.5.2
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.5.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 2.4.1
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 2.4.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.37.1
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.37.1
139
+ description: Enhancements to the standard rubocop gem.
140
+ email:
141
+ - roberts@corlewsolutions.com
142
+ executables:
143
+ - rubo
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".rubocop.yml"
150
+ - ".travis.yml"
151
+ - CHANGELOG.md
152
+ - Gemfile
153
+ - LICENSE.md
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - bin/setup
158
+ - bin/start_rspec
159
+ - config/group/layout.yml
160
+ - config/group/lint.yml
161
+ - config/group/metrics.yml
162
+ - config/group/naming.yml
163
+ - config/group/rails.yml
164
+ - config/group/rspec.yml
165
+ - config/group/style.yml
166
+ - config/rubocop.yml
167
+ - exe/rubo
168
+ - lib/commands/rubo.rb
169
+ - lib/commands/rubo/errors/bad_output.rb
170
+ - lib/commands/rubo/errors/incorrect_yml.rb
171
+ - lib/commands/rubo/errors/missing_yml.rb
172
+ - lib/commands/rubo/errors/no_rubocop_command.rb
173
+ - lib/commands/rubo/errors/output_missing.rb
174
+ - lib/commands/rubo/helpers/misc.rb
175
+ - lib/commands/rubo/helpers/output.rb
176
+ - lib/commands/rubo/helpers/validations.rb
177
+ - lib/commands/rubo/utils/cri_platform_monkey_patch.rb
178
+ - lib/commands/rubo/utils/which.rb
179
+ - lib/rubocop_plus.rb
180
+ - lib/rubocop_plus/core_ext/string.rb
181
+ - lib/rubocop_plus/version.rb
182
+ - lib/templates/.rubocop.yml
183
+ - rubocop_plus.gemspec
184
+ homepage: https://github.com/roberts1000/rubocop_plus
185
+ licenses:
186
+ - MIT
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubygems_version: 3.1.2
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: Enhancements to the standard rubocop gem.
207
+ test_files: []