boxt_ruby_style_guide 7.6.0 → 7.9.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 -12
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/default.yml +5 -5
- data/lib/boxt_ruby_style_guide/filepath_matcher.rb +44 -0
- data/lib/boxt_ruby_style_guide/git_diff.rb +38 -0
- data/lib/tasks/lint.rake +18 -52
- metadata +85 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df02aaff031561dd78d64ead4f814ff7b3dca32ed71c6e5ca80d0921a7a57ba6
|
4
|
+
data.tar.gz: c9e037578d06d41dafeaf714db0f1c2db9de4a63ab718a2188a943090301885c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70be516ec5d55e77c4b0afde9fccff43f5ec2cc3f32dd57e14fca433c1e4cac544f655361994bc4e891db2d7090122e1c2c1165684776ac26f4a62c4b91344c5
|
7
|
+
data.tar.gz: b727e3d6d32dc4d329f559c0bf7a482408c1f166e9f3868bd511c5734f4c740539710cdd55a99bad327a3d18cc291f1a057509283483b562b9df7227f1c481a9
|
data/README.md
CHANGED
@@ -24,13 +24,6 @@ And then execute:
|
|
24
24
|
bundle
|
25
25
|
```
|
26
26
|
|
27
|
-
To make the lint rake tasks available to non Rails apps and gems, add the following to the project's `Rakefile`:
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
require "boxt_ruby_style_guide"
|
31
|
-
BoxtRubyStyleGuide.install_tasks
|
32
|
-
```
|
33
|
-
|
34
27
|
Rails apps should have access to the lint tasks by default.
|
35
28
|
|
36
29
|
## Usage
|
@@ -41,10 +34,10 @@ Add a `.rubocop.yml` file to the root of your project with the following setting
|
|
41
34
|
inherit_gem:
|
42
35
|
boxt_ruby_style_guide:
|
43
36
|
- default.yml # use default cops
|
44
|
-
- pending.yml # use pending cops
|
37
|
+
- pending.yml # use pending cops
|
45
38
|
- rails.yml # use Rails cops - see Additional Extensions/Cops
|
46
|
-
- rails-pending.yml # use pending rails cops
|
47
|
-
- rspec.yml # use rspec cops
|
39
|
+
- rails-pending.yml # use pending rails cops
|
40
|
+
- rspec.yml # use rspec cops
|
48
41
|
```
|
49
42
|
|
50
43
|
### Additional Extensions/Cops
|
@@ -60,7 +53,7 @@ To enable add the following to your `.rubocop.yml` file.
|
|
60
53
|
```yml
|
61
54
|
inherit_gem:
|
62
55
|
boxt_ruby_style_guide:
|
63
|
-
# .... add cops
|
56
|
+
# .... add cops
|
64
57
|
|
65
58
|
require:
|
66
59
|
- rubocop-faker # if your project is using the Faker gem then add this
|
@@ -75,9 +68,17 @@ Lint tasks to run against files listed as changed by Git.
|
|
75
68
|
To run `rubocop` against any changed files use:
|
76
69
|
|
77
70
|
```sh
|
78
|
-
rake lint:rubocop
|
71
|
+
RUBOCOP_LINT_BASE=your-base-branch rake lint:rubocop
|
79
72
|
```
|
80
73
|
|
74
|
+
To run `rubocop` with autofix, use one of the following:
|
75
|
+
|
76
|
+
```sh
|
77
|
+
RUBOCOP_LINT_BASE=your-base-branch rake lint:rubocop -a
|
78
|
+
RUBOCOP_LINT_BASE=your-base-branch rake lint:rubocop -A
|
79
|
+
```
|
80
|
+
|
81
|
+
|
81
82
|
If there are no changed files the commands will run against all files.
|
82
83
|
|
83
84
|
## Editor Plugins
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
7.
|
1
|
+
7.9.0
|
data/default.yml
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
3
|
- "**/*/schema.rb"
|
4
|
-
- Gemfile.lock
|
5
|
-
- node_modules/**/*
|
6
|
-
- tmp/**/*
|
7
|
-
- vendor/**/*
|
8
|
-
TargetRubyVersion: 2.7.
|
4
|
+
- "Gemfile.lock"
|
5
|
+
- "node_modules/**/*"
|
6
|
+
- "tmp/**/*"
|
7
|
+
- "vendor/**/*"
|
8
|
+
TargetRubyVersion: 2.7.2
|
9
9
|
Layout/LineLength:
|
10
10
|
Exclude:
|
11
11
|
- config/routes.rb
|
@@ -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, File::FNM_PATHNAME)
|
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:)
|
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
|
data/lib/tasks/lint.rake
CHANGED
@@ -1,64 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "boxt_ruby_style_guide"
|
4
|
+
require "boxt_ruby_style_guide/filepath_matcher"
|
5
|
+
require "boxt_ruby_style_guide/git_diff"
|
4
6
|
require "rubocop"
|
5
7
|
|
6
|
-
##
|
7
|
-
# The base branch to compare HEAD with for changes
|
8
|
-
BASE_BRANCH = "develop"
|
9
|
-
|
10
|
-
##
|
11
|
-
# Directories containing Ruby files to lint
|
12
|
-
RUBY_DIRS = %w[app lib test spec].freeze
|
13
|
-
|
14
|
-
##
|
15
|
-
# Grep file pattern to make sure we only check files that are Ruby files
|
16
|
-
# This pattern matches the following:
|
17
|
-
#
|
18
|
-
# - Gemfile
|
19
|
-
# - Rakefile
|
20
|
-
# - *.gemspec
|
21
|
-
# - app/**/*.{rb,rake}
|
22
|
-
# - lib/**/*.{rb,rake}
|
23
|
-
# - test/**/*.{rb,rake}
|
24
|
-
# - spec/**/*.{rb,rake}
|
25
|
-
#
|
26
|
-
GREP_PATTERN = <<~STRING.delete("\n").delete("\s")
|
27
|
-
(
|
28
|
-
(#{RUBY_DIRS.join('|')})\\/.+\\.(rb|rake)
|
29
|
-
|^
|
30
|
-
(Gemfile|Rakefile|.+\\.gemspec)
|
31
|
-
\Z)
|
32
|
-
STRING
|
33
|
-
|
34
8
|
namespace :lint do
|
35
9
|
desc "Runs rubocop against all files with committed changes different from base branch"
|
36
10
|
task :rubocop do
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
11
|
+
file_paths = sanitized_file_paths
|
12
|
+
puts "File paths: #{file_paths.join(', ')}"
|
13
|
+
|
14
|
+
if file_paths.any?
|
15
|
+
auto_flag_opt = ARGV.select { |a| ["-a", "-A"].include?(a) }.first
|
16
|
+
exec("bundle exec rubocop #{file_paths.join(' ')} #{auto_flag_opt}".strip)
|
17
|
+
else
|
18
|
+
puts "No Ruby files changed"
|
19
|
+
end
|
45
20
|
end
|
21
|
+
end
|
46
22
|
|
47
|
-
|
23
|
+
private
|
48
24
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
# --diff-filter Filter out results that have been deleted on HEAD
|
55
|
-
#
|
56
|
-
# Pipe the output from this command through grep to match only Ruby files in the
|
57
|
-
# desired directories
|
58
|
-
#
|
59
|
-
# Returns String
|
60
|
-
def diff_file_paths
|
61
|
-
base_branch = ENV.fetch("RUBOCOP_LINT_BASE", BASE_BRANCH)
|
62
|
-
"git diff -r --name-only --diff-filter=d #{base_branch} | egrep '#{GREP_PATTERN}'"
|
63
|
-
end
|
25
|
+
# Returns an array of files
|
26
|
+
def sanitized_file_paths
|
27
|
+
base = ENV.fetch("RUBOCOP_LINT_BASE", "main")
|
28
|
+
changed_files = BoxtRubyStyleGuide::GitDiff.new(base: base).all
|
29
|
+
BoxtRubyStyleGuide::FilepathMatcher.new(*changed_files).all_matches
|
64
30
|
end
|
metadata
CHANGED
@@ -1,49 +1,43 @@
|
|
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.9.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:
|
11
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: git
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '1.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '1.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rubocop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '5'
|
34
|
-
- - "<"
|
31
|
+
- - '='
|
35
32
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
37
|
-
type: :
|
33
|
+
version: 1.9.1
|
34
|
+
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
version: '5'
|
44
|
-
- - "<"
|
38
|
+
- - '='
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
40
|
+
version: 1.9.1
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rubocop-faker
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,28 +58,42 @@ dependencies:
|
|
64
58
|
requirements:
|
65
59
|
- - '='
|
66
60
|
- !ruby/object:Gem::Version
|
67
|
-
version: 2.
|
61
|
+
version: 2.9.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.9.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.5.1
|
68
76
|
type: :runtime
|
69
77
|
prerelease: false
|
70
78
|
version_requirements: !ruby/object:Gem::Requirement
|
71
79
|
requirements:
|
72
80
|
- - '='
|
73
81
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
82
|
+
version: 0.5.1
|
75
83
|
- !ruby/object:Gem::Dependency
|
76
84
|
name: rubocop-rspec
|
77
85
|
requirement: !ruby/object:Gem::Requirement
|
78
86
|
requirements:
|
79
87
|
- - '='
|
80
88
|
- !ruby/object:Gem::Version
|
81
|
-
version: 1.
|
89
|
+
version: 2.1.0
|
82
90
|
type: :runtime
|
83
91
|
prerelease: false
|
84
92
|
version_requirements: !ruby/object:Gem::Requirement
|
85
93
|
requirements:
|
86
94
|
- - '='
|
87
95
|
- !ruby/object:Gem::Version
|
88
|
-
version: 1.
|
96
|
+
version: 2.1.0
|
89
97
|
- !ruby/object:Gem::Dependency
|
90
98
|
name: bundler
|
91
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,6 +108,54 @@ dependencies:
|
|
100
108
|
- - "~>"
|
101
109
|
- !ruby/object:Gem::Version
|
102
110
|
version: '2.1'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: bundler-audit
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.7.0.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.7.0.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: byebug
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rails
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '5'
|
146
|
+
- - "<"
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '7'
|
149
|
+
type: :development
|
150
|
+
prerelease: false
|
151
|
+
version_requirements: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">"
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '5'
|
156
|
+
- - "<"
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '7'
|
103
159
|
- !ruby/object:Gem::Dependency
|
104
160
|
name: rake
|
105
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,6 +226,8 @@ files:
|
|
170
226
|
- VERSION
|
171
227
|
- default.yml
|
172
228
|
- lib/boxt_ruby_style_guide.rb
|
229
|
+
- lib/boxt_ruby_style_guide/filepath_matcher.rb
|
230
|
+
- lib/boxt_ruby_style_guide/git_diff.rb
|
173
231
|
- lib/boxt_ruby_style_guide/railtie.rb
|
174
232
|
- lib/boxt_ruby_style_guide/version.rb
|
175
233
|
- lib/tasks/lint.rake
|
@@ -181,7 +239,7 @@ homepage: https://github.com/boxt/ruby-style-guide
|
|
181
239
|
licenses:
|
182
240
|
- MIT
|
183
241
|
metadata: {}
|
184
|
-
post_install_message:
|
242
|
+
post_install_message:
|
185
243
|
rdoc_options: []
|
186
244
|
require_paths:
|
187
245
|
- lib
|
@@ -196,8 +254,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
254
|
- !ruby/object:Gem::Version
|
197
255
|
version: '0'
|
198
256
|
requirements: []
|
199
|
-
rubygems_version: 3.1.
|
200
|
-
signing_key:
|
257
|
+
rubygems_version: 3.1.4
|
258
|
+
signing_key:
|
201
259
|
specification_version: 4
|
202
260
|
summary: Ruby styleguide info for the BOXT Ruby projects
|
203
261
|
test_files: []
|