code-scanning-rubocop 0.3.0 → 0.6.1

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: f4e32fd700366fde1538d35a360bb632a31ad42a1199653c3f4ec2a00ae94ae6
4
- data.tar.gz: 99f87d64f5287e712b0375f4e9d7fa840aeddf8fb619a0600f3aa1b5442f4d66
3
+ metadata.gz: 627fdcc7b65f53d26dc2b282199ac26fbf02a2b2eab521eca4523f3542e517fa
4
+ data.tar.gz: 54782e0495c961c25d03f72361cfc1f5ed4083a18b7f7384f5492264400f4dd0
5
5
  SHA512:
6
- metadata.gz: ee4a2b0bdac90ecd2720874c9f5e55d2cef7763f3613a0ea4653f2533e7b065ea4763d0d6e347d602434ff377d7cbaa90ea9d429830ea0d964b5e23031fb9c59
7
- data.tar.gz: e723dea9868724bd0bdcd50a05dce61fe1a9d6fcc9b7912618fd81b2aedf99045164dc25bc2f01b33f0630025ff3325b099cc9ba17ac19ea545bc6586084b3aa
6
+ metadata.gz: 96e006d3410433323cd6c5dc6397f8d06d418db855edaa0a688a17358d3ec1ec23a853facd2aa6c9267866b61542804dd925fc38728d412195297b0a7aae049a
7
+ data.tar.gz: 154b7ab2cbafde3032ab35d3b24a376b3abcb1387a0d76cc9459a4d42047a119a52862aa11e2893ebd32b554f35826d17594a4892dc5aff278b38f2d4a5f1011
@@ -1,4 +1,4 @@
1
- name: "Rubocop"
1
+ name: "RuboCop"
2
2
 
3
3
  on: [push]
4
4
 
@@ -21,7 +21,7 @@ jobs:
21
21
  - name: Install dependencies
22
22
  run: bundle install
23
23
 
24
- - name: Rubocop run
24
+ - name: RuboCop run
25
25
  run: |
26
26
  bash -c "
27
27
  bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
data/.rubocop.yml CHANGED
@@ -10,6 +10,8 @@ inherit_from: .rubocop_todo.yml
10
10
  # where the inspected file is and continue its way up to the root directory.
11
11
  #
12
12
  # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
13
+ AllCops:
14
+ NewCops: enable
13
15
 
14
16
  Layout/LineLength:
15
17
  Exclude:
data/Gemfile.lock CHANGED
@@ -1,31 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-scanning-rubocop (0.2.0)
5
- rubocop (~> 0.82.0)
4
+ code-scanning-rubocop (0.5.0)
5
+ rubocop (~> 1.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- ast (2.4.0)
11
- jaro_winkler (1.5.4)
10
+ ast (2.4.2)
12
11
  minitest (5.14.0)
13
- parallel (1.19.1)
14
- parser (2.7.1.2)
15
- ast (~> 2.4.0)
16
- rainbow (3.0.0)
12
+ parallel (1.21.0)
13
+ parser (3.1.0.0)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.1.1)
17
16
  rake (12.3.3)
18
- rexml (3.2.4)
19
- rubocop (0.82.0)
20
- jaro_winkler (~> 1.5.1)
17
+ regexp_parser (2.2.0)
18
+ rexml (3.2.5)
19
+ rubocop (1.24.1)
21
20
  parallel (~> 1.10)
22
- parser (>= 2.7.0.1)
21
+ parser (>= 3.0.0.0)
23
22
  rainbow (>= 2.2.2, < 4.0)
23
+ regexp_parser (>= 1.8, < 3.0)
24
24
  rexml
25
+ rubocop-ast (>= 1.15.1, < 2.0)
25
26
  ruby-progressbar (~> 1.7)
26
- unicode-display_width (>= 1.4.0, < 2.0)
27
- ruby-progressbar (1.10.1)
28
- unicode-display_width (1.7.0)
27
+ unicode-display_width (>= 1.4.0, < 3.0)
28
+ rubocop-ast (1.15.1)
29
+ parser (>= 3.0.1.1)
30
+ ruby-progressbar (1.11.0)
31
+ unicode-display_width (2.1.0)
29
32
 
30
33
  PLATFORMS
31
34
  ruby
@@ -36,4 +39,4 @@ DEPENDENCIES
36
39
  rake (~> 12.0)
37
40
 
38
41
  BUNDLED WITH
39
- 2.1.4
42
+ 2.3.4
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # CodeScanning::Rubocop
2
2
 
3
- 'code-scanning-rubocop' is a gem to integrate Rubocop and the GitHub's code scanning feature.
4
- The repository is composed by two components. The gem which can be installed in any ruby application and a default GitHub action to ease the usage of it.
3
+ 'code-scanning-rubocop' is a gem to integrate RuboCop and the GitHub's code scanning feature.
4
+ The repository is composed by two components. The gem which can be installed in any ruby application and a default GitHub action to ease the usage of it.
5
5
 
6
6
  The rubygem adds a SARIF exporter to the rubocop runner. GitHub's code scanning feature accepts a SARIF file with the 'results' (alerts) generated by the tool.
7
7
  The action, is what will run rubocop with the exporter. Note: you can only run the gem within your application, and have our own action that calls rubocop. See more in the Installation and Usage sections.
@@ -9,13 +9,13 @@ The action, is what will run rubocop with the exporter. Note: you can only run t
9
9
  This is how it would look in your Security tab:
10
10
  ![preview](preview.png)
11
11
 
12
- ## Action Installation
12
+ ## Action Installation
13
13
 
14
14
  The easiest way to install the integration, is this action template bellow. It will install the gem in your app and run it for you within the GitHub's action enviroment. To install the action create a file `.github/workflows/rubocop-analysis.yml` like the following:
15
15
 
16
16
  ```yaml
17
17
  # .github/workflows/rubocop-analysis.yml
18
- name: "Rubocop"
18
+ name: "RuboCop"
19
19
 
20
20
  on: [push]
21
21
 
@@ -41,7 +41,7 @@ jobs:
41
41
  - name: Install dependencies
42
42
  run: bundle install
43
43
 
44
- - name: Rubocop run
44
+ - name: RuboCop run
45
45
  run: |
46
46
  bash -c "
47
47
  bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.add_dependency "rubocop", "~> 0.82.0"
33
+ spec.add_dependency "rubocop", "~> 1.0"
34
34
  end
@@ -8,19 +8,19 @@ module CodeScanning
8
8
  @cop_name = cop_name
9
9
  @severity = severity.to_s
10
10
  @cop = RuboCop::Cop::Cop.registry.find_by_cop_name(cop_name)
11
- @help = StringIO.new
12
11
  end
13
12
 
14
13
  def id
15
14
  @cop_name
16
15
  end
17
16
 
18
- def append_help(line)
19
- @help.print(line)
20
- end
21
-
22
- def help_empty?
23
- @help.size.zero?
17
+ def help(format)
18
+ case format
19
+ when :text
20
+ "More info: #{help_uri}"
21
+ when :markdown
22
+ "[More info](#{help_uri})"
23
+ end
24
24
  end
25
25
 
26
26
  def ==(other)
@@ -41,12 +41,36 @@ module CodeScanning
41
41
  "none"
42
42
  end
43
43
 
44
- # The URL for the docs are in this format:
45
- # https://docs.rubocop.org/en/stable/cops_layout/#layoutblockendnewline
46
- def query_uri
47
- kind = badge.department.to_s.downcase
48
- full_name = "#{kind}#{badge.cop_name.downcase}"
49
- "https://docs.rubocop.org/en/stable/cops_#{kind}/##{full_name}"
44
+ def help_uri
45
+ return @cop.documentation_url if @cop.documentation_url
46
+ return nil unless department_uri
47
+
48
+ anchor = "#{badge.department}#{badge.cop_name}".downcase.tr("/", "")
49
+ "#{department_uri}##{anchor}"
50
+ end
51
+
52
+ def department_uri
53
+ case badge.department
54
+ when :Performance
55
+ "https://docs.rubocop.org/rubocop-performance/index.html"
56
+ when :Packaging
57
+ "https://docs.rubocop.org/rubocop-packaging/cops_packaging.html"
58
+ when :Rails
59
+ "https://docs.rubocop.org/rubocop-rails/cops_rails.html"
60
+ when :Minitest
61
+ "https://docs.rubocop.org/rubocop-minitest/cops_minitest.html"
62
+ when :RSpec
63
+ "https://docs.rubocop.org/rubocop-rspec/cops_rspec.html"
64
+ when :"RSpec/Rails"
65
+ "https://docs.rubocop.org/rubocop-rspec/cops_rspec_rails.html"
66
+ when :"RSpec/Capybara"
67
+ "https://docs.rubocop.org/rubocop-rspec/cops_rspec_capybara.html"
68
+ when :"RSpec/FactoryBot"
69
+ "https://docs.rubocop.org/rubocop-rspec/cops_rspec_factorybot.html"
70
+ else
71
+ STDERR.puts "WARNING: Unknown docs URI for department #{badge.department}"
72
+ nil
73
+ end
50
74
  end
51
75
 
52
76
  def to_json(opts = {})
@@ -66,7 +90,7 @@ module CodeScanning
66
90
 
67
91
  h = {
68
92
  "id" => @cop_name,
69
- "name" => @cop_name,
93
+ "name" => @cop_name.tr("/", "").gsub("RSpec", "Rspec"),
70
94
  "defaultConfiguration" => {
71
95
  "level" => sarif_severity
72
96
  },
@@ -80,19 +104,23 @@ module CodeScanning
80
104
  properties["description"] = desc
81
105
  end
82
106
 
83
- unless help_empty?
84
- help = @help.string
85
- h["help"] = {
86
- "text" => help,
87
- "markdown" => help
88
- }
89
- properties["queryURI"] = query_uri if badge.qualified?
90
- end
91
-
92
107
  if badge.qualified?
93
108
  kind = badge.department.to_s
94
109
  properties["tags"] = [kind.downcase]
95
110
  end
111
+
112
+ if help_uri
113
+ properties["queryURI"] = help_uri
114
+
115
+ h.merge!(
116
+ "helpUri" => help_uri,
117
+ "help" => {
118
+ "text" => help(:text),
119
+ "markdown" => help(:markdown)
120
+ }
121
+ )
122
+ end
123
+
96
124
  h
97
125
  end
98
126
  end
@@ -7,19 +7,22 @@ module CodeScanning
7
7
  class SarifFormatter < RuboCop::Formatter::BaseFormatter
8
8
  def initialize(output, options = {})
9
9
  super
10
- # rubocop:disable Layout/LineLength
11
10
  @sarif = {
12
11
  "$schema" => "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
13
12
  "version" => "2.1.0"
14
13
  }
15
- # rubocop:enable Layout/LineLength
16
14
  @rules_map = {}
17
15
  @rules = []
18
16
  @results = []
19
17
  @sarif["runs"] = [
20
18
  {
21
19
  "tool" => {
22
- "driver" => { "name" => "Rubocop", "rules" => @rules }
20
+ "driver" => {
21
+ "name" => "RuboCop",
22
+ "version" => RuboCop::Version.version,
23
+ "informationUri" => "https://rubocop.org",
24
+ "rules" => @rules
25
+ }
23
26
  },
24
27
  "results" => @results
25
28
  }
@@ -54,19 +57,15 @@ module CodeScanning
54
57
  "artifactLocation" => {
55
58
  "uri" => relative_path,
56
59
  "uriBaseId" => "%SRCROOT%",
57
- "index" => 0
58
60
  },
59
61
  "region" => {
60
62
  "startLine" => o.line,
61
63
  "startColumn" => o.real_column,
62
- "endColumn" => o.last_column
64
+ "endColumn" => o.last_column.zero? ? o.real_column : o.last_column
63
65
  }
64
66
  }
65
67
  }
66
- ],
67
- "partialFingerprints" => {
68
- # This will be computed by the upload action for now
69
- }
68
+ ]
70
69
  }
71
70
  end
72
71
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module CodeScanning
4
4
  module Rubocop
5
- VERSION = "0.3.0"
5
+ VERSION = "0.6.1"
6
6
  end
7
7
  end
data/lib/code_scanning.rb CHANGED
@@ -6,3 +6,4 @@ module CodeScanning
6
6
  end
7
7
 
8
8
  require_relative "code_scanning/rubocop/sarif_formatter"
9
+ require_relative "code_scanning/rubocop/version"
@@ -1,5 +1,5 @@
1
1
  name: 'Rubocop code-scanning'
2
- description: 'Rubocop and code-scanning integration'
2
+ description: 'RuboCop and code-scanning integration'
3
3
  runs:
4
4
  using: 'docker'
5
5
  image: '../Dockerfile'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-scanning-rubocop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur Neves
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-22 00:00:00.000000000 Z
11
+ date: 2022-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.82.0
19
+ version: '1.0'
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.82.0
26
+ version: '1.0'
27
27
  description: This gem adds a SARIF formatter to rubocop, so we can export alerts to
28
28
  code-scanning inside GitHub.
29
29
  email:
@@ -76,8 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubyforge_project:
80
- rubygems_version: 2.7.6
79
+ rubygems_version: 3.3.3
81
80
  signing_key:
82
81
  specification_version: 4
83
82
  summary: Extra formater to make rubocop compatible with GitHub's code-scanning feature.