boxt_ruby_style_guide 7.4.0 → 7.7.3

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: 00a10b1e139e15aa28f133847e8a102bba235fd15840b8da636cc2658cbbd821
4
- data.tar.gz: '0683e861cc45e0177b5e9f96c4ac05e47ae77b99314978463fa9178da217277d'
3
+ metadata.gz: bb14b8f791b4feded3f27f40c3bb50de7087c97f6c68177831a0d480e52e3860
4
+ data.tar.gz: db0f26c2a9cd3f5dc8137a74c03819f0744a09c64be7cdad45eb250994dd2ee3
5
5
  SHA512:
6
- metadata.gz: 65c4b44b3a1eb0077bcaf1dc2be3035439fd7b9b0771409f1b02483ac81f5d2b744768f6901206e600f9cbb3fec0743ef585e52f89fabac58250ebcfc44b6891
7
- data.tar.gz: 3d3b1cc9df23483d023e55b1029e47d98cfdc62982c366f8992b5ef6ee95077f216f9368498447d478c9ebe7530cd7e2e1fb94c5147702c706409e369a2f8ed1
6
+ metadata.gz: 07e967593138ce3ac4fe0aea5f6eca2a53c46611e2a3694a3a582abd0d5e52fcbb1a461d8e3917d2fecdae8529f70be656bc849bdaed13391695cfa6f2c027ca
7
+ data.tar.gz: 301463c3158cc8f859b408fbf8a0fc8a4c4cb8bcb102d64d7af2ab0a53d606753c1b61e574b6cea6eaa8d4ce1b44b44358ad8b59a349e21886889737b5725155
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/VERSION CHANGED
@@ -1 +1 @@
1
- 7.4.0
1
+ 7.7.3
@@ -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 = "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
@@ -3,60 +3,53 @@
3
3
  require "boxt_ruby_style_guide"
4
4
  require "rubocop"
5
5
 
6
+ require "boxt_ruby_style_guide/git_diff"
7
+ require "boxt_ruby_style_guide/filepath_matcher"
8
+
6
9
  ##
7
10
  # The base branch to compare HEAD with for changes
8
11
  BASE_BRANCH = "develop"
9
12
 
10
13
  ##
11
- # Directories containing Ruby files to lint
12
- RUBY_DIRS = %w[app lib test spec].freeze
14
+ # Name of the master Rubocop lint task to run
15
+ RUBOCOP_TASK_NAME = :"lint:execute_rubocop"
13
16
 
14
17
  ##
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
18
+ # Pattern for matching autofix options
19
+ AUTO_REGEX = /\A-a\Z/i.freeze
33
20
 
34
21
  namespace :lint do
35
22
  desc "Runs rubocop against all files with committed changes different from base branch"
36
23
  task :rubocop do
37
- exec("rubocop #{diff_file_paths};")
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")
38
35
  end
39
36
 
40
- private
41
-
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-tree -r --name-only --diff-filter=d #{base_branch} HEAD \
57
- | egrep '#{GREP_PATTERN}'
58
- BASH
59
- file_paths = `#{command}`
60
- file_paths.gsub(/\n|\r/, " ")
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
61
45
  end
62
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.4.0
4
+ version: 7.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boxt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-01 00:00:00.000000000 Z
11
+ date: 2020-10-23 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
@@ -31,6 +45,9 @@ dependencies:
31
45
  - - ">"
32
46
  - !ruby/object:Gem::Version
33
47
  version: '5'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '7'
34
51
  type: :development
35
52
  prerelease: false
36
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +55,9 @@ dependencies:
38
55
  - - ">"
39
56
  - !ruby/object:Gem::Version
40
57
  version: '5'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '7'
41
61
  - !ruby/object:Gem::Dependency
42
62
  name: rubocop-faker
43
63
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +114,34 @@ dependencies:
94
114
  - - "~>"
95
115
  - !ruby/object:Gem::Version
96
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'
97
145
  - !ruby/object:Gem::Dependency
98
146
  name: rake
99
147
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +212,8 @@ files:
164
212
  - VERSION
165
213
  - default.yml
166
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
167
217
  - lib/boxt_ruby_style_guide/railtie.rb
168
218
  - lib/boxt_ruby_style_guide/version.rb
169
219
  - lib/tasks/lint.rake