boxt_ruby_style_guide 7.5.0 → 7.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c98e2c24a98ee1a1b71ff68d8ac9e1a71fc828e7dd426fdca7cdb7d1d46bd95
4
- data.tar.gz: d391b2f458db7d6c95e85674ccbacbd44c1b75e4b2cae553d42885e44797e1d2
3
+ metadata.gz: 7e8f3ee70573d3493385981a232a6b08389bdf815827b097aa7a24478f7e5a80
4
+ data.tar.gz: 7a7fede5a038a4e0b764b3ad629d83bafeeed03d9b980c4b851baefbf777c45a
5
5
  SHA512:
6
- metadata.gz: c682a374a5084e2abc80665481fcd9df82f99b301064916153d5d6dd8ed587d226f83698627ab804a98e449fffe0d78fa16e8e7ccfcd0f8c60a13add8196b545
7
- data.tar.gz: '09e6a7393ba970d72171d6e85660a4482594f54de05d9f63ae4248aca894992110073f20bfb9fe9b9feab3c8d2d31399e687fa935b57a6a073e1c4807da9d31a'
6
+ metadata.gz: ffe098e6a1fa3323b8897fbf5cdbff05b0e4e37d66988fdecb15a0f866b7e110c430f6ce427bc15c7ce82fa9a4165029ee514788046c451ea271b6fa65a78bdd
7
+ data.tar.gz: 3a090c5cd4ce2bd4055866e9587842a759800b580c4cc196bc936c5005da60052789e117153bb3bb38175d6197176c6a5fba54ab193c5daea931f16dde00ae63
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/VERSION CHANGED
@@ -1 +1 @@
1
- 7.5.0
1
+ 7.8.0
@@ -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.1
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
@@ -1,61 +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")
27
- (
28
- (#{RUBY_DIRS.join('|')})\\/.+\\.(rb|rake)
29
- |^
30
- (Gemfile|Rakefile|.+\\.gemspec)
31
- )
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
- exec("rubocop #{diff_file_paths};")
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
38
20
  end
21
+ end
39
22
 
40
- private
23
+ private
41
24
 
42
- # A list of the local file paths of Ruby files with committed changes.
43
- #
44
- # Run a git diff-tree command with the following otions:
45
- # -r recursive
46
- # --name-only Only return the name of the files
47
- # --diff-filter Filter out results that have been deleted on HEAD
48
- #
49
- # Pipe the output from this command through grep to match only Ruby files in the
50
- # desired directories
51
- #
52
- # Returns String
53
- def diff_file_paths
54
- base_branch = ENV.fetch("RUBOCOP_LINT_BASE", BASE_BRANCH)
55
- command = <<~BASH
56
- git diff --name-only #{base_branch} HEAD | egrep '#{GREP_PATTERN}'
57
- BASH
58
- file_paths = `#{command}`
59
- file_paths.gsub(/\n|\r/, " ")
60
- 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
61
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.5.0
4
+ version: 7.8.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-10-03 00:00:00.000000000 Z
11
+ date: 2020-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rubocop
14
+ name: git
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.92.0
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: 0.92.0
26
+ version: '1.4'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rails
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: '7'
37
- type: :development
33
+ version: 1.4.2
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: '7'
40
+ version: 1.4.2
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rubocop-faker
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -78,14 +72,14 @@ dependencies:
78
72
  requirements:
79
73
  - - '='
80
74
  - !ruby/object:Gem::Version
81
- version: 1.43.2
75
+ version: 2.0.0
82
76
  type: :runtime
83
77
  prerelease: false
84
78
  version_requirements: !ruby/object:Gem::Requirement
85
79
  requirements:
86
80
  - - '='
87
81
  - !ruby/object:Gem::Version
88
- version: 1.43.2
82
+ version: 2.0.0
89
83
  - !ruby/object:Gem::Dependency
90
84
  name: bundler
91
85
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +94,54 @@ dependencies:
100
94
  - - "~>"
101
95
  - !ruby/object:Gem::Version
102
96
  version: '2.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bundler-audit
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.7.0.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.7.0.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rails
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">"
130
+ - !ruby/object:Gem::Version
131
+ version: '5'
132
+ - - "<"
133
+ - !ruby/object:Gem::Version
134
+ version: '7'
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">"
140
+ - !ruby/object:Gem::Version
141
+ version: '5'
142
+ - - "<"
143
+ - !ruby/object:Gem::Version
144
+ version: '7'
103
145
  - !ruby/object:Gem::Dependency
104
146
  name: rake
105
147
  requirement: !ruby/object:Gem::Requirement
@@ -170,6 +212,8 @@ files:
170
212
  - VERSION
171
213
  - default.yml
172
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
173
217
  - lib/boxt_ruby_style_guide/railtie.rb
174
218
  - lib/boxt_ruby_style_guide/version.rb
175
219
  - lib/tasks/lint.rake
@@ -181,7 +225,7 @@ homepage: https://github.com/boxt/ruby-style-guide
181
225
  licenses:
182
226
  - MIT
183
227
  metadata: {}
184
- post_install_message:
228
+ post_install_message:
185
229
  rdoc_options: []
186
230
  require_paths:
187
231
  - lib
@@ -196,8 +240,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
240
  - !ruby/object:Gem::Version
197
241
  version: '0'
198
242
  requirements: []
199
- rubygems_version: 3.1.2
200
- signing_key:
243
+ rubygems_version: 3.1.4
244
+ signing_key:
201
245
  specification_version: 4
202
246
  summary: Ruby styleguide info for the BOXT Ruby projects
203
247
  test_files: []