nucop 0.8.0 → 0.10.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: b06c2da379c5ceea08460f4fef215b819753f14fccadf5af591e683accb6ef66
4
- data.tar.gz: b9d59749fb3b9c0071939ea7d04c499226f7d71bf525817cec8e0ab3e028f226
3
+ metadata.gz: 7ff54f8a1918cd048657e884cafc31ebebfc0b1f5cf4f680ee6744258c3f71d2
4
+ data.tar.gz: 68ce2d04feece7e38b8310d375b4b44bc30b7e04bd2310cf4d9782765a1cf483
5
5
  SHA512:
6
- metadata.gz: 1e612a9b8a530a1b3e37233a3e7f48aeaeb5cae8161a6b56ae8fd2453f28401d8419b65cf1e22599810d863bbbee217d0180ea4dc9dae850d8c4a87faec9e522
7
- data.tar.gz: 1621ea5c7bde20e04de0737ba8f8611e1ff7a38957da5a5b9cd8a6156652845187c20c546b71b8d60981e6a9fb4dbedb14c8ad6dc226b063695c533ebcccf575
6
+ metadata.gz: 7083788bc1f37779cc1eb5dbee8a9f2ff9afaf2d0e48a24bf7a3049b0005640b7194a73d9d3bed4c6968dceacd1febad1ef993989e0458a8d9571b3adc7e6e63
7
+ data.tar.gz: 5d90bbae9eb57877e843566391448e32e7f59a84ec650fb3adc89cc1fac43e742bd61a0ff3d178104a9a0d144c4417522976ade0d03da9d23b96691726acb658
data/lib/nucop/cli.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "thor"
2
2
  require "open3"
3
+ require "net/http"
4
+ require "json"
3
5
 
4
6
  RUBOCOP_DEFAULT_CONFIG_FILE = ".rubocop.yml"
5
7
  CONFIGURATION_FILEPATH = ".nucop.yml"
@@ -17,6 +19,18 @@ module Nucop
17
19
  invoke :diff, nil, options.merge(only: cops_to_enforce.join(","))
18
20
  end
19
21
 
22
+ desc "diff_enforced_github", "run RuboCop on the current diff using only the enforced cops (using GitHub to find the files changed)"
23
+ method_option "github-authorization-token", desc: "a GitHub authorization token for the repository this script is running against"
24
+ method_option "commit-spec", default: "main", desc: "the commit-ish used to determine the diff."
25
+ method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option (deprecated)"
26
+ method_option "autocorrect", type: :boolean, default: false, desc: "runs RuboCop with autocorrect option"
27
+ method_option "autocorrect-all", type: :boolean, default: false, desc: "runs RuboCop with autocorrect-all option"
28
+ method_option "junit_report", type: :string, default: nil, desc: "runs RuboCop with junit formatter option"
29
+ method_option "json", type: :string, default: nil, desc: "Output results as JSON format to the provided file"
30
+ def diff_enforced_github
31
+ invoke :diff_github, nil, options.merge(only: cops_to_enforce.join(","))
32
+ end
33
+
20
34
  desc "diff", "run RuboCop on the current diff"
21
35
  method_option "commit-spec", default: "origin/main", desc: "the commit used to determine the diff."
22
36
  method_option "only", desc: "run only specified cop(s) and/or cops in the specified departments"
@@ -43,7 +57,7 @@ module Nucop
43
57
  end
44
58
  end
45
59
 
46
- if options[:ignore] && File.exist?(options[:diffignore_file]) && !File.zero?(options[:diffignore_file])
60
+ if options[:ignore] && File.exist?(options[:diffignore_file]) && !File.empty?(options[:diffignore_file])
47
61
  files, non_ignored_diff_status = Open3.capture2("grep -v -f #{options[:diffignore_file]}", stdin_data: files)
48
62
 
49
63
  if non_ignored_diff_status != 0
@@ -64,6 +78,77 @@ module Nucop
64
78
  exit 0
65
79
  end
66
80
 
81
+ desc "diff_github", "run RuboCop on the current diff (using GitHub to find the files changes)"
82
+ method_option "github-authorization-token", desc: "a GitHub authorization token for the repository this script is running against"
83
+ method_option "commit-spec", default: "main", desc: "the commit-ish used to determine the diff."
84
+ method_option "only", desc: "run only specified cop(s) and/or cops in the specified departments"
85
+ method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option (deprecated)"
86
+ method_option "autocorrect", type: :boolean, default: false, desc: "runs RuboCop with autocorrect option"
87
+ method_option "autocorrect-all", type: :boolean, default: false, desc: "runs RuboCop with autocorrect-all option"
88
+ method_option "ignore", type: :boolean, default: true, desc: "ignores files specified in #{options[:diffignore_file]}"
89
+ method_option "added-only", type: :boolean, default: false, desc: "runs RuboCop only on files that have been added (not on files that have been modified)"
90
+ method_option "exit", type: :boolean, default: true, desc: "disable to prevent task from exiting. Used by other Thor tasks when invoking this task, to prevent parent task from exiting"
91
+ def diff_github
92
+ puts "Running on files changed relative to '#{options[:"commit-spec"]}' (specify using the 'commit-spec' option)"
93
+ diff_head = capture_std_out("git rev-parse HEAD").chomp
94
+ diff_base = options[:"commit-spec"]
95
+ repository = capture_std_out("git remote get-url origin | sed 's/git@github.com://; s/.git//'").chomp
96
+
97
+ uri = URI("https://api.github.com/repos/#{repository}/compare/#{diff_base}...#{diff_head}")
98
+ request = Net::HTTP::Get.new(uri)
99
+ request["Accept"] = "application/vnd.github+json"
100
+ request["Authorization"] = "Bearer #{options[:"github-authorization-token"]}"
101
+ request["X-GitHub-Api-Version"] = "2022-11-28"
102
+
103
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }
104
+
105
+ if response.code != "200"
106
+ puts "Error fetching data from Github: #{response.code} -- #{response.body}"
107
+ return true unless options[:exit]
108
+
109
+ exit 0
110
+ end
111
+
112
+ commit_data = JSON.parse(response.body)
113
+
114
+ diff_filter = options[:"added-only"] ? proc { |status| status == "added" } : proc { |status| status != "removed" }
115
+ files = commit_data["files"]
116
+ .filter { |file_data| diff_filter.call(file_data["status"]) }
117
+ .pluck("filename")
118
+ .filter { |file_name| file_name.include?(".rb") }
119
+
120
+ if files.empty?
121
+ if options[:exit]
122
+ puts "There are no rb files present in diff. Exiting."
123
+ exit 0
124
+ else
125
+ puts "There are no rb files present in diff."
126
+ return true
127
+ end
128
+ end
129
+
130
+ if options[:ignore] && File.exist?(options[:diffignore_file]) && !File.empty?(options[:diffignore_file])
131
+ files, non_ignored_diff_status = Open3.capture2("grep -v -f #{options[:diffignore_file]}", stdin_data: files.join("\n"))
132
+
133
+ if non_ignored_diff_status != 0
134
+ if options[:exit]
135
+ puts "There are no non-ignored rb files present in diff. Exiting."
136
+ exit 0
137
+ else
138
+ puts "There are no non-ignored rb files present in diff."
139
+ return true
140
+ end
141
+ end
142
+ end
143
+
144
+ no_violations_detected = invoke :rubocop, [multi_line_to_single_line(files)], options
145
+
146
+ exit 1 unless no_violations_detected
147
+ return true unless options[:exit]
148
+
149
+ exit 0
150
+ end
151
+
67
152
  desc "rubocop", "run RuboCop on files provided"
68
153
  method_option "only", desc: "run only specified cop(s) and/or cops in the specified departments"
69
154
  method_option "auto-correct", type: :boolean, default: false, desc: "runs RuboCop with auto-correct option (deprecated)"
data/lib/nucop/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nucop
2
- VERSION = "0.8.0"
2
+ VERSION = "0.10.0"
3
3
  end
data/lib/nucop.rb CHANGED
@@ -3,9 +3,9 @@ require "nucop/version"
3
3
  require "rubocop"
4
4
  require "git_diff_parser"
5
5
 
6
- Dir[File.join(__dir__, "nucop/helpers/**/*.rb")].sort.each { |f| require f }
7
- Dir[File.join(__dir__, "nucop/formatters/**/*.rb")].sort.each { |f| require f }
8
- Dir[File.join(__dir__, "nucop/cops/**/*.rb")].sort.each { |f| require f }
6
+ Dir[File.join(__dir__, "nucop/helpers/**/*.rb")].each { |f| require f }
7
+ Dir[File.join(__dir__, "nucop/formatters/**/*.rb")].each { |f| require f }
8
+ Dir[File.join(__dir__, "nucop/cops/**/*.rb")].each { |f| require f }
9
9
 
10
10
  module Nucop
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nucop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Schweier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-16 00:00:00.000000000 Z
11
+ date: 2023-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git_diff_parser
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.46'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-factory_bot
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.22'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.22'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rubocop-graphql
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -211,6 +225,7 @@ metadata:
211
225
  changelog_uri: https://github.com/nulogy/nucop/blob/master/CHANGELOG.md
212
226
  source_code_uri: https://github.com/nulogy/nucop
213
227
  bug_tracker_uri: https://github.com/nulogy/nucop/issues
228
+ rubygems_mfa_required: 'true'
214
229
  post_install_message:
215
230
  rdoc_options: []
216
231
  require_paths:
@@ -226,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
241
  - !ruby/object:Gem::Version
227
242
  version: '0'
228
243
  requirements: []
229
- rubygems_version: 3.4.8
244
+ rubygems_version: 3.4.12
230
245
  signing_key:
231
246
  specification_version: 4
232
247
  summary: Nulogy's implementation of RuboCop, including custom cops and additional