boxt_ruby_style_guide 7.3.0 → 7.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db37fda2704f058428f66ef3227058dc67c4abd08df1829c5674ff827079bbf6
4
- data.tar.gz: 90302060b3ae806b43f4cce6165744e6b5af59566176dffbc878875a876038c9
3
+ metadata.gz: 28eca289d2e48ea7d90efe79f6815253121c1876e5066033cfe11ad802f8c901
4
+ data.tar.gz: 1608aaac5753d5f00865542d18f1f0daf9b0bf7852aff5139ab65079feca23f8
5
5
  SHA512:
6
- metadata.gz: 5e2bcb595827b288a7d6f9d068ff46036f25fc93bd3e39f3f481d8e5eb6ddbe94f23f65dd8554383cfc009dc4ff9ecf19d00a6564aa45181af77971660826bf3
7
- data.tar.gz: 147a875753ac204afb7b063f00e10047ec7ef1c8a39c28827ded7d2515b0f6076c418a1e11fb9b3c2ab2a93b2220200bc573fa04f96c9523bf545a90b1f4e223
6
+ metadata.gz: 431b69e3a82bf76119f8e7b7936042dc3ef64ee6dcdce6d6c6e9244140cab9b4e7fa8e5cfffbd31245e9026af5fe4a127e8166c9261a0a0d6fd80710423bcf88
7
+ data.tar.gz: 6440d530e3bde18b2645cac87e48c3a987bfdc0992f11b905db068ea51ba3ba955733ba207c3719793e8e71ec6c8eee52a1b93d2e5e6d373ed476ede390a2973
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
@@ -4,7 +4,7 @@ require "bundler/gem_tasks"
4
4
  require "rake/testtask"
5
5
  require "rspec/core/rake_task"
6
6
 
7
- import "./tasks/lint.rake"
7
+ import "lib/tasks/lint.rake"
8
8
 
9
9
  RSpec::Core::RakeTask.new(:spec) do |t|
10
10
  t.pattern = Dir.glob("spec/**/*_spec.rb")
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.3.0
1
+ 7.7.2
@@ -1,10 +1,10 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - "**/*/schema.rb"
4
- - Gemfile.lock
5
- - node_modules/**/*
6
- - tmp/**/*
7
- - vendor/**/*
4
+ - "Gemfile.lock"
5
+ - "node_modules/**/*"
6
+ - "tmp/**/*"
7
+ - "vendor/**/*"
8
8
  TargetRubyVersion: 2.7.1
9
9
  Layout/LineLength:
10
10
  Exclude:
@@ -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
- class << self
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
- private
15
-
16
- def gem_spec
17
- Gem::Specification.find_by_name("boxt_ruby_style_guide")
18
- end
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, 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 = "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 = File.join(File.dirname(__FILE__), "../../tasks/*.rake")
8
+ files = BoxtRubyStyleGuide.root.join("lib", "tasks", "*.rake")
9
9
  Dir[files].each { |file| load(file) }
10
10
  end
11
11
  end
@@ -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 #{sanitized_file_paths.join(" ")} #{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,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxt_ruby_style_guide
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.3.0
4
+ version: 7.7.2
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-09-28 00:00:00.000000000 Z
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
@@ -24,6 +38,26 @@ dependencies:
24
38
  - - '='
25
39
  - !ruby/object:Gem::Version
26
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.18'
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.18'
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.4
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: []