boxt_ruby_style_guide 7.2.1 → 7.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +13 -5
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/boxt_ruby_style_guide.rb +7 -11
- data/lib/boxt_ruby_style_guide/filepath_matcher.rb +44 -0
- data/lib/boxt_ruby_style_guide/git_diff.rb +38 -0
- data/lib/boxt_ruby_style_guide/railtie.rb +1 -1
- data/lib/tasks/lint.rake +55 -0
- metadata +75 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3269906781941588a2da2ed478c324852a270245e9aeb64cddc877835d6ede19
|
4
|
+
data.tar.gz: 9b1255d5557fd33a70e3cb5f6fccf61d5c7ac44f37055bff8e193108927e00d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1ce04bee4be54bdc9b5bdb4fa55695d364e32546f0c7a0fa93fb458c72d38510cc48667f51809387e39ab12e37058592a3ac4ea3d43e7910177e17f2da6179b
|
7
|
+
data.tar.gz: 4516330c35be5df90616fa65cf8370afa368b441fe3d495da0e5b9542bafd12d0218b1a331eeaa3c548cf93d3ea4f1a26098c5ad7da25ff6b8906dd5b4f543b6
|
data/README.md
CHANGED
@@ -41,10 +41,10 @@ Add a `.rubocop.yml` file to the root of your project with the following setting
|
|
41
41
|
inherit_gem:
|
42
42
|
boxt_ruby_style_guide:
|
43
43
|
- default.yml # use default cops
|
44
|
-
- pending.yml # use pending cops
|
44
|
+
- pending.yml # use pending cops
|
45
45
|
- rails.yml # use Rails cops - see Additional Extensions/Cops
|
46
|
-
- rails-pending.yml # use pending rails cops
|
47
|
-
- rspec.yml # use rspec cops
|
46
|
+
- rails-pending.yml # use pending rails cops
|
47
|
+
- rspec.yml # use rspec cops
|
48
48
|
```
|
49
49
|
|
50
50
|
### Additional Extensions/Cops
|
@@ -60,7 +60,7 @@ To enable add the following to your `.rubocop.yml` file.
|
|
60
60
|
```yml
|
61
61
|
inherit_gem:
|
62
62
|
boxt_ruby_style_guide:
|
63
|
-
# .... add cops
|
63
|
+
# .... add cops
|
64
64
|
|
65
65
|
require:
|
66
66
|
- rubocop-faker # if your project is using the Faker gem then add this
|
@@ -75,9 +75,17 @@ Lint tasks to run against files listed as changed by Git.
|
|
75
75
|
To run `rubocop` against any changed files use:
|
76
76
|
|
77
77
|
```sh
|
78
|
-
rake lint:rubocop
|
78
|
+
rake lint:rubocop RUBOCOP_LINT_BASE=your-base-branch
|
79
79
|
```
|
80
80
|
|
81
|
+
To run `rubocop` with autofix, use one of the following:
|
82
|
+
|
83
|
+
```sh
|
84
|
+
rake lint:rubocop_a RUBOCOP_LINT_BASE=your-base-branch
|
85
|
+
rake lint:rubocop_A RUBOCOP_LINT_BASE=your-base-branch
|
86
|
+
```
|
87
|
+
|
88
|
+
|
81
89
|
If there are no changed files the commands will run against all files.
|
82
90
|
|
83
91
|
## Editor Plugins
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
7.
|
1
|
+
7.7.0
|
@@ -4,17 +4,13 @@ require "boxt_ruby_style_guide/railtie" if defined?(Rails)
|
|
4
4
|
require "boxt_ruby_style_guide/version"
|
5
5
|
|
6
6
|
module BoxtRubyStyleGuide
|
7
|
-
|
8
|
-
def install_tasks
|
9
|
-
Dir[File.join(gem_spec.gem_dir, "tasks/*.rake")].each do |file|
|
10
|
-
load(file)
|
11
|
-
end
|
12
|
-
end
|
7
|
+
module_function
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
##
|
10
|
+
# Provide a root path helper for the gem root dir
|
11
|
+
#
|
12
|
+
# Returns Pathname
|
13
|
+
def root
|
14
|
+
Pathname.new(File.dirname(__dir__))
|
19
15
|
end
|
20
16
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BoxtRubyStyleGuide
|
4
|
+
##
|
5
|
+
# Sanitizes a list of filepaths based on Rubocops exclusions
|
6
|
+
class FilepathMatcher
|
7
|
+
require "yaml"
|
8
|
+
|
9
|
+
##
|
10
|
+
# Compare a given filepath with a grep-style filename pattern
|
11
|
+
FILEPATH_PATTERN_MATCH = proc do |filepath, pattern|
|
12
|
+
File.fnmatch(pattern, filepath)
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Array of file patterns to make sure we only check files that are Ruby files
|
17
|
+
INCLUDE_PATTERNS = %w[
|
18
|
+
Gemfile
|
19
|
+
Rakefile
|
20
|
+
*.gemspec
|
21
|
+
**/*.rb
|
22
|
+
**/*.rake
|
23
|
+
].freeze
|
24
|
+
|
25
|
+
##
|
26
|
+
# Array of the excluded files from Rubocop default.yml config
|
27
|
+
EXCLUDE_PATTERNS = YAML.load_file(
|
28
|
+
BoxtRubyStyleGuide.root.join("default.yml")
|
29
|
+
).dig("AllCops", "Exclude")
|
30
|
+
|
31
|
+
attr_reader :filepaths
|
32
|
+
|
33
|
+
def initialize(*filepaths)
|
34
|
+
@filepaths = filepaths
|
35
|
+
end
|
36
|
+
|
37
|
+
def all_matches
|
38
|
+
filepaths.select do |filepath|
|
39
|
+
filepath_proc = FILEPATH_PATTERN_MATCH.curry.call(filepath)
|
40
|
+
INCLUDE_PATTERNS.any?(filepath_proc) && EXCLUDE_PATTERNS.none?(filepath_proc)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module BoxtRubyStyleGuide
|
4
|
+
# Returns a list of files that have changed, as detected by `git-diff`
|
5
|
+
#
|
6
|
+
# TODO: Write tests for this to ensure we're pulling the desired diff files
|
7
|
+
# see: https://github.com/ruby-git/ruby-git
|
8
|
+
class GitDiff
|
9
|
+
require "git"
|
10
|
+
|
11
|
+
##
|
12
|
+
# List of Git statuses we should test
|
13
|
+
# See: https://git-scm.com/docs/git-status#_short_format
|
14
|
+
TEST_STATUSES = %w[M A U].freeze
|
15
|
+
|
16
|
+
attr_reader :base
|
17
|
+
|
18
|
+
def initialize(base = "master")
|
19
|
+
@base = base
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# A list of the local file paths of Ruby files with committed changes.
|
24
|
+
#
|
25
|
+
# Returns Array
|
26
|
+
def all
|
27
|
+
@all ||= begin
|
28
|
+
git.diff(base).name_status.select { |_, stat| TEST_STATUSES.include?(stat) }.keys
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def git
|
35
|
+
@git ||= Git.open(".")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -5,7 +5,7 @@ require "rails"
|
|
5
5
|
module BoxtRubyStyleGuide
|
6
6
|
class Railtie < Rails::Railtie
|
7
7
|
rake_tasks do
|
8
|
-
files =
|
8
|
+
files = BoxtRubyStyleGuide.root.join("lib", "tasks", "*.rake")
|
9
9
|
Dir[files].each { |file| load(file) }
|
10
10
|
end
|
11
11
|
end
|
data/lib/tasks/lint.rake
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "boxt_ruby_style_guide"
|
4
|
+
require "rubocop"
|
5
|
+
|
6
|
+
require "boxt_ruby_style_guide/git_diff"
|
7
|
+
require "boxt_ruby_style_guide/filepath_matcher"
|
8
|
+
|
9
|
+
##
|
10
|
+
# The base branch to compare HEAD with for changes
|
11
|
+
BASE_BRANCH = "develop"
|
12
|
+
|
13
|
+
##
|
14
|
+
# Name of the master Rubocop lint task to run
|
15
|
+
RUBOCOP_TASK_NAME = :"lint:execute_rubocop"
|
16
|
+
|
17
|
+
##
|
18
|
+
# Pattern for matching autofix options
|
19
|
+
AUTO_REGEX = /\A-a\Z/i.freeze
|
20
|
+
|
21
|
+
namespace :lint do
|
22
|
+
desc "Runs rubocop against all files with committed changes different from base branch"
|
23
|
+
task :rubocop do
|
24
|
+
Rake::Task[RUBOCOP_TASK_NAME].invoke
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "Runs rubocop against all files using -a (soft autofix) option"
|
28
|
+
task :rubocop_a do
|
29
|
+
Rake::Task[RUBOCOP_TASK_NAME].invoke("-a")
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Runs rubocop against all files using -A (hard autofix) option"
|
33
|
+
task :rubocop_A do
|
34
|
+
Rake::Task[RUBOCOP_TASK_NAME].invoke("-A")
|
35
|
+
end
|
36
|
+
|
37
|
+
task :execute_rubocop, [:auto_flag] do |_t, args|
|
38
|
+
if sanitized_file_paths.any?
|
39
|
+
# Sanitize args to make sure only a single "a" or "A" is accepted
|
40
|
+
auto_flag = AUTO_REGEX.match(args[:auto_flag])
|
41
|
+
exec("bundle exec rubocop $RUBOCOP_CHANGED_FILES #{auto_flag}".strip)
|
42
|
+
else
|
43
|
+
puts "No matching Ruby files changed"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
# Returns Array
|
51
|
+
def sanitized_file_paths
|
52
|
+
base = ENV.fetch("RUBOCOP_LINT_BASE", BASE_BRANCH)
|
53
|
+
changed_files = BoxtRubyStyleGuide::GitDiff.new(base).all
|
54
|
+
BoxtRubyStyleGuide::FilepathMatcher.new(*changed_files).all_matches
|
55
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,63 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boxt_ruby_style_guide
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Boxt
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rubocop
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - '='
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
33
|
+
version: 0.92.0
|
20
34
|
type: :runtime
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - '='
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
40
|
+
version: 0.92.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5'
|
48
|
+
- - "<"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '7'
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '5'
|
58
|
+
- - "<"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '7'
|
27
61
|
- !ruby/object:Gem::Dependency
|
28
62
|
name: rubocop-faker
|
29
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +114,34 @@ dependencies:
|
|
80
114
|
- - "~>"
|
81
115
|
- !ruby/object:Gem::Version
|
82
116
|
version: '2.1'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: bundler-audit
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: 0.7.0.1
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: 0.7.0.1
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: byebug
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
83
145
|
- !ruby/object:Gem::Dependency
|
84
146
|
name: rake
|
85
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +190,14 @@ dependencies:
|
|
128
190
|
requirements:
|
129
191
|
- - "~>"
|
130
192
|
- !ruby/object:Gem::Version
|
131
|
-
version: '0.
|
193
|
+
version: '0.19'
|
132
194
|
type: :development
|
133
195
|
prerelease: false
|
134
196
|
version_requirements: !ruby/object:Gem::Requirement
|
135
197
|
requirements:
|
136
198
|
- - "~>"
|
137
199
|
- !ruby/object:Gem::Version
|
138
|
-
version: '0.
|
200
|
+
version: '0.19'
|
139
201
|
description: Ruby styleguide info for the BOXT projects, as well as config settings
|
140
202
|
for Rubocop
|
141
203
|
email:
|
@@ -150,8 +212,11 @@ files:
|
|
150
212
|
- VERSION
|
151
213
|
- default.yml
|
152
214
|
- lib/boxt_ruby_style_guide.rb
|
215
|
+
- lib/boxt_ruby_style_guide/filepath_matcher.rb
|
216
|
+
- lib/boxt_ruby_style_guide/git_diff.rb
|
153
217
|
- lib/boxt_ruby_style_guide/railtie.rb
|
154
218
|
- lib/boxt_ruby_style_guide/version.rb
|
219
|
+
- lib/tasks/lint.rake
|
155
220
|
- pending.yml
|
156
221
|
- rails-pending.yml
|
157
222
|
- rails.yml
|
@@ -160,7 +225,7 @@ homepage: https://github.com/boxt/ruby-style-guide
|
|
160
225
|
licenses:
|
161
226
|
- MIT
|
162
227
|
metadata: {}
|
163
|
-
post_install_message:
|
228
|
+
post_install_message:
|
164
229
|
rdoc_options: []
|
165
230
|
require_paths:
|
166
231
|
- lib
|
@@ -175,8 +240,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
240
|
- !ruby/object:Gem::Version
|
176
241
|
version: '0'
|
177
242
|
requirements: []
|
178
|
-
rubygems_version: 3.1.
|
179
|
-
signing_key:
|
243
|
+
rubygems_version: 3.1.2
|
244
|
+
signing_key:
|
180
245
|
specification_version: 4
|
181
246
|
summary: Ruby styleguide info for the BOXT Ruby projects
|
182
247
|
test_files: []
|