code-scanning-rubocop 0.2.0 → 0.3.0

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: 739a88bd1b19ec2ee128962c43c90c7c3680e2e04ad8cfb98feb9773aa7419d8
4
- data.tar.gz: f7f7aaa9fc8607ffe535494dcbfcd9ea1ac17620bba8073a9a67859064c45e28
3
+ metadata.gz: f4e32fd700366fde1538d35a360bb632a31ad42a1199653c3f4ec2a00ae94ae6
4
+ data.tar.gz: 99f87d64f5287e712b0375f4e9d7fa840aeddf8fb619a0600f3aa1b5442f4d66
5
5
  SHA512:
6
- metadata.gz: 8c48865aedc4968ed50c8d6dfb1ae3e42b8b44fde53a82219e0b47bafcc0b51b84cb29642d7e29db5759caec0345a953a7940928bc85396aacbee393deb35ffe
7
- data.tar.gz: 33a344112b71cba3ab3a77411173cff7bc96a88fb4d2df3db9536edbb86aa6ececf57052950cf4098daf6df5e18bf15c41af1d4e8635102ec300948768f6003c
6
+ metadata.gz: ee4a2b0bdac90ecd2720874c9f5e55d2cef7763f3613a0ea4653f2533e7b065ea4763d0d6e347d602434ff377d7cbaa90ea9d429830ea0d964b5e23031fb9c59
7
+ data.tar.gz: e723dea9868724bd0bdcd50a05dce61fe1a9d6fcc9b7912618fd81b2aedf99045164dc25bc2f01b33f0630025ff3325b099cc9ba17ac19ea545bc6586084b3aa
@@ -0,0 +1,34 @@
1
+ name: "Rubocop"
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ rubocop_job:
7
+ runs-on: ubuntu-latest
8
+ name: Code Scanning job run
9
+ strategy:
10
+ fail-fast: false
11
+
12
+ steps:
13
+ - name: Checkout repository
14
+ uses: actions/checkout@v2
15
+
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6
20
+
21
+ - name: Install dependencies
22
+ run: bundle install
23
+
24
+ - name: Rubocop run
25
+ run: |
26
+ bash -c "
27
+ bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
28
+ [[ $? -ne 2 ]]
29
+ "
30
+
31
+ - name: Upload Sarif output
32
+ uses: github/codeql-action/upload-sarif@v1
33
+ with:
34
+ sarif_file: rubocop.sarif
@@ -0,0 +1,23 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6
20
+ - name: Install dependencies
21
+ run: bundle install
22
+ - name: Run tests
23
+ run: bundle exec rake
@@ -0,0 +1,46 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
4
+ # configuration file. It makes it possible to enable/disable
5
+ # certain cops (checks) and to alter their behavior if they accept
6
+ # any parameters. The file can be placed either in your home
7
+ # directory or in some project directory.
8
+ #
9
+ # RuboCop will start looking for the configuration file in the directory
10
+ # where the inspected file is and continue its way up to the root directory.
11
+ #
12
+ # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
13
+
14
+ Layout/LineLength:
15
+ Exclude:
16
+ - 'code-scanning-rubocop.gemspec'
17
+ Layout/SpaceAroundMethodCallOperator:
18
+ Enabled: true
19
+
20
+ Lint/RaiseException:
21
+ Enabled: true
22
+ Lint/StructNewOverride:
23
+ Enabled: true
24
+
25
+ Style/HashSyntax:
26
+ EnforcedStyle: ruby19
27
+ Style/StringLiterals:
28
+ EnforcedStyle: double_quotes
29
+ Style/ExponentialNotation:
30
+ Enabled: true
31
+ Style/HashEachMethods:
32
+ Enabled: true
33
+ Style/HashTransformKeys:
34
+ Enabled: true
35
+ Style/HashTransformValues:
36
+ Enabled: true
37
+ Style/ClassAndModuleChildren:
38
+ Exclude:
39
+ - 'test/**/*'
40
+
41
+ Metrics/MethodLength:
42
+ Enabled: false
43
+ Metrics/BlockLength:
44
+ Enabled: false
45
+ Metrics/AbcSize:
46
+ Enabled: false
@@ -0,0 +1,14 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-05-05 14:10:36 -0400 using RuboCop version 0.82.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ Style/Documentation:
10
+ Exclude:
11
+ - 'spec/**/*'
12
+ - 'test/**/*'
13
+ - 'lib/code_scanning.rb'
14
+ - 'lib/code_scanning/**/*'
data/Dockerfile CHANGED
@@ -1,10 +1,5 @@
1
1
  FROM ruby:2.7.1
2
2
 
3
- # throw errors if Gemfile has been modified since Gemfile.lock
4
- RUN bundle config --global frozen 1
5
-
6
- RUN gem install code-scanning-rubocop -v0.2.0
7
-
8
3
  ARG GITHUB_WORKSPACE
9
4
 
10
5
  COPY entrypoint.sh /entrypoint.sh
data/Gemfile CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in code-scanning-rubocop.gemspec
4
6
  gemspec
5
7
 
6
- gem "rake", "~> 12.0"
7
8
  gem "minitest", "~> 5.0"
9
+ gem "rake", "~> 12.0"
data/README.md CHANGED
@@ -1,34 +1,82 @@
1
- # Code::Scanning::Rubocop
1
+ # CodeScanning::Rubocop
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/code/scanning/rubocop`. To experiment with that code, run `bin/console` for an interactive prompt.
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.
4
5
 
5
- TODO: Delete this and the text above, and describe your gem
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
+ 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.
6
8
 
7
- ## Installation
9
+ This is how it would look in your Security tab:
10
+ ![preview](preview.png)
8
11
 
9
- Add this line to your application's Gemfile:
12
+ ## Action Installation
10
13
 
11
- ```ruby
12
- gem 'code-scanning-rubocop'
13
- ```
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
+
16
+ ```yaml
17
+ # .github/workflows/rubocop-analysis.yml
18
+ name: "Rubocop"
14
19
 
15
- And then execute:
20
+ on: [push]
16
21
 
17
- $ bundle install
22
+ jobs:
23
+ rubocop:
24
+ runs-on: ubuntu-latest
25
+ strategy:
26
+ fail-fast: false
18
27
 
19
- Or install it yourself as:
28
+ steps:
29
+ - name: Checkout repository
30
+ uses: actions/checkout@v2
20
31
 
21
- $ gem install code-scanning-rubocop
32
+ - name: Set up Ruby
33
+ uses: ruby/setup-ruby@v1
34
+ with:
35
+ ruby-version: 2.6
22
36
 
23
- ## Usage
37
+ # This step is not necessary if you add the gem to your Gemfile
38
+ - name: Install Code Scanning integration
39
+ run: bundle add code-scanning-rubocop --skip-install
40
+
41
+ - name: Install dependencies
42
+ run: bundle install
43
+
44
+ - name: Rubocop run
45
+ run: |
46
+ bash -c "
47
+ bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
48
+ [[ $? -ne 2 ]]
49
+ "
50
+
51
+ - name: Upload Sarif output
52
+ uses: github/codeql-action/upload-sarif@v1
53
+ with:
54
+ sarif_file: rubocop.sarif
55
+ ```
24
56
 
25
- TODO: Write usage instructions here
57
+ ## Gem installation & usage in a custom action
58
+ Note: this is not necessary if you use the action above.
26
59
 
27
- ## Development
60
+ To install the gem add this line to your application's Gemfile:
28
61
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
62
+ ```ruby
63
+ gem 'code-scanning-rubocop'
64
+ ```
65
+
66
+ Then, in your custom GitHub's action, you need to run rubocop and make sure you give it the SarifFormatter:
67
+ ```bash
68
+ bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
69
+ ```
70
+
71
+ As a last step, make sure you upload the `rubocop.sarif` file to the code-scan integration. That will create the Code Scanning alerts.
72
+ Thus, add this step to your custom rubocop workflow:
73
+ ```yaml
74
+ - name: Upload Sarif output
75
+ uses: github/codeql-action/upload-sarif@v1
76
+ with:
77
+ sarif_file: rubocop.sarif
78
+ ```
30
79
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
80
 
33
81
  ## Contributing
34
82
 
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
3
5
 
@@ -7,4 +9,27 @@ Rake::TestTask.new(:test) do |t|
7
9
  t.test_files = FileList["test/**/*_test.rb"]
8
10
  end
9
11
 
10
- task :default => :test
12
+ task :generate_rules do
13
+ require_relative "lib/code_scanning/rules_generator"
14
+
15
+ begin
16
+ output_file = "#{Time.now.strftime('%Y%m%d')}.sarif"
17
+ puts "Cloning rubocop repository to read manuals"
18
+ puts
19
+
20
+ sh "git clone git@github.com:rubocop-hq/rubocop.git _tmp"
21
+
22
+ gen = QHelpGenerator.new
23
+ Dir["_tmp/manual/cops_*.md"].each do |f|
24
+ gen.parse_file(f)
25
+ end
26
+ puts
27
+ puts "Writing rules help sarif to '#{output_file}' file"
28
+ puts
29
+ File.write(output_file, gen.sarif_json)
30
+ ensure
31
+ sh "rm -rf _tmp"
32
+ end
33
+ end
34
+
35
+ task default: :test
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
- require "code/scanning/rubocop"
5
+ require "code_scanning"
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -1,7 +1,9 @@
1
- lib = File.expand_path("../lib", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
 
4
- require_relative 'lib/code_scanning/rubocop/version'
6
+ require_relative "lib/code_scanning/rubocop/version"
5
7
 
6
8
  Gem::Specification.new do |spec|
7
9
  spec.name = "code-scanning-rubocop"
@@ -9,25 +11,24 @@ Gem::Specification.new do |spec|
9
11
  spec.authors = ["Arthur Neves"]
10
12
  spec.email = ["arthurnn@gmail.com"]
11
13
 
12
- spec.summary = %q{Extra formater to make rubocop compatible with GitHub's code-scanning feature.}
13
- spec.description = %q{This gem adds a SARIF formatter to rubocop, so we can export alerts to code-scanning inside GitHub.}
14
+ spec.summary = "Extra formater to make rubocop compatible with GitHub's code-scanning feature."
15
+ spec.description = "This gem adds a SARIF formatter to rubocop, so we can export alerts to code-scanning inside GitHub."
14
16
  spec.homepage = "https://github.com/arthurnn/code-scanning-rubocop"
15
17
  spec.license = "MIT"
16
18
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
17
19
 
18
-
19
20
  spec.metadata["homepage_uri"] = spec.homepage
20
21
  spec.metadata["source_code_uri"] = "https://github.com/arthurnn/code-scanning-rubocop"
21
- #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
23
 
23
24
  # Specify which files should be added to the gem when it is released.
24
25
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
27
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
28
  end
28
29
  spec.bindir = "exe"
29
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
31
  spec.require_paths = ["lib"]
31
32
 
32
- spec.add_dependency 'rubocop', '~> 0.82.0'
33
+ spec.add_dependency "rubocop", "~> 0.82.0"
33
34
  end
@@ -7,10 +7,9 @@ cd $GITHUB_WORKSPACE
7
7
  # Install correct bundler version
8
8
  gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)"
9
9
 
10
- bundle install
11
-
12
- bundle inject code-scanning-rubocop "$(gem list | grep code-scanning-rubocop | tr -cd '0-9.')"
10
+ bundle add code-scanning-rubocop --version 0.2.0 --skip-install
13
11
 
12
+ bundle install
14
13
  bundle exec rubocop --require code_scanning --format CodeScanning::SarifFormatter -o rubocop.sarif
15
14
 
16
15
  if [ ! -f rubocop.sarif ]; then
@@ -1,4 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+
1
5
  module CodeScanning
2
6
  end
3
7
 
4
- require 'code_scanning/rubocop/sarif_formatter'
8
+ require_relative "code_scanning/rubocop/sarif_formatter"
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+
5
+ module CodeScanning
6
+ class Rule
7
+ def initialize(cop_name, severity = nil)
8
+ @cop_name = cop_name
9
+ @severity = severity.to_s
10
+ @cop = RuboCop::Cop::Cop.registry.find_by_cop_name(cop_name)
11
+ @help = StringIO.new
12
+ end
13
+
14
+ def id
15
+ @cop_name
16
+ end
17
+
18
+ def append_help(line)
19
+ @help.print(line)
20
+ end
21
+
22
+ def help_empty?
23
+ @help.size.zero?
24
+ end
25
+
26
+ def ==(other)
27
+ badge.match?(other.badge)
28
+ end
29
+ alias eql? ==
30
+
31
+ def badge
32
+ @cop.badge
33
+ end
34
+
35
+ def sarif_severity
36
+ cop_severity = @cop.new.send(:find_severity, nil, @severity)
37
+ return cop_severity if %w[warning error].include?(cop_severity)
38
+ return "note" if %w[refactor convention].include?(cop_severity)
39
+ return "error" if cop_severity == "fatal"
40
+
41
+ "none"
42
+ end
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}"
50
+ end
51
+
52
+ def to_json(opts = {})
53
+ to_h.to_json(opts)
54
+ end
55
+
56
+ def cop_config
57
+ @config ||= RuboCop::ConfigStore.new.for(Pathname.new(Dir.pwd))
58
+ @cop_config ||= @config.for_cop(@cop.department.to_s)
59
+ .merge(@config.for_cop(@cop))
60
+ end
61
+
62
+ def to_h
63
+ properties = {
64
+ "precision" => "very-high"
65
+ }
66
+
67
+ h = {
68
+ "id" => @cop_name,
69
+ "name" => @cop_name,
70
+ "defaultConfiguration" => {
71
+ "level" => sarif_severity
72
+ },
73
+ "properties" => properties
74
+ }
75
+
76
+ desc = cop_config["Description"]
77
+ unless desc.nil?
78
+ h["shortDescription"] = { "text" => desc }
79
+ h["fullDescription"] = { "text" => desc }
80
+ properties["description"] = desc
81
+ end
82
+
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
+ if badge.qualified?
93
+ kind = badge.department.to_s
94
+ properties["tags"] = [kind.downcase]
95
+ end
96
+ h
97
+ end
98
+ end
99
+ end
@@ -1,91 +1,70 @@
1
1
  # frozen_string_literal: true
2
- require 'rubocop/formatter/base_formatter'
3
- require 'json'
4
- require 'pathname'
5
2
 
6
- module CodeScanning
3
+ require "json"
4
+ require_relative "rule"
7
5
 
6
+ module CodeScanning
8
7
  class SarifFormatter < RuboCop::Formatter::BaseFormatter
9
8
  def initialize(output, options = {})
10
9
  super
11
- @sarif = {}
12
- end
13
-
14
- def started(_target_files)
15
- @sarif['$schema'] = 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json'
16
- @sarif['version'] = '2.1.0'
10
+ # rubocop:disable Layout/LineLength
11
+ @sarif = {
12
+ "$schema" => "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
13
+ "version" => "2.1.0"
14
+ }
15
+ # rubocop:enable Layout/LineLength
17
16
  @rules_map = {}
18
- @results = []
19
17
  @rules = []
20
- @sarif['runs'] = [
21
- { 'tool' => {
22
- 'driver' => { 'name' => 'Rubocop', 'rules' => @rules }
18
+ @results = []
19
+ @sarif["runs"] = [
20
+ {
21
+ "tool" => {
22
+ "driver" => { "name" => "Rubocop", "rules" => @rules }
23
23
  },
24
- 'results' => @results }
24
+ "results" => @results
25
+ }
25
26
  ]
26
27
  end
27
28
 
28
- Rule = Struct.new(:name, :index)
29
-
30
- def set_rule(cop_name, severity)
31
- if r = @rules_map[cop_name]
32
- return r
29
+ def get_rule(cop_name, severity)
30
+ r = @rules_map[cop_name]
31
+ if r.nil?
32
+ rule = Rule.new(cop_name, severity&.name)
33
+ r = @rules_map[cop_name] = [rule, @rules.size]
34
+ @rules << rule
33
35
  end
34
36
 
35
- desc = RuboCop::ConfigLoader.default_configuration[cop_name]['Description']
36
- h = {
37
- 'id' => cop_name, 'name' => cop_name,
38
- 'shortDescription' => {
39
- 'text' => desc
40
- },
41
- 'fullDescription' => {
42
- 'text' => desc
43
- },
44
- 'defaultConfiguration' => {
45
- 'level' => sarif_severity(severity)
46
- },
47
- 'properties' => {}
48
- }
49
- @rules << h
50
- @rules_map[cop_name] = Rule.new(cop_name, @rules.size - 1)
51
- end
52
-
53
- def sarif_severity(cop_severity)
54
- return cop_severity if %w[warning error].include?(cop_severity)
55
- return 'note' if %w[refactor convention].include?(cop_severity)
56
- return 'error' if cop_severity == 'fatal'
57
- 'none'
37
+ r
58
38
  end
59
39
 
60
40
  def file_finished(file, offenses)
61
41
  relative_path = RuboCop::PathUtil.relative_path(file)
62
42
 
63
43
  offenses.each do |o|
64
- rule = set_rule(o.cop_name, o.severity.name.to_s)
65
-
44
+ rule, rule_index = get_rule(o.cop_name, o.severity)
66
45
  @results << {
67
- "ruleId" => rule.name,
68
- 'ruleIndex' => rule.index,
69
- 'message' => {
70
- 'text' => o.message
46
+ "ruleId" => rule.id,
47
+ "ruleIndex" => rule_index,
48
+ "message" => {
49
+ "text" => o.message
71
50
  },
72
- 'locations' => [
51
+ "locations" => [
73
52
  {
74
- 'physicalLocation' => {
75
- 'artifactLocation' => {
76
- 'uri' => relative_path,
77
- 'uriBaseId' => '%SRCROOT%',
78
- 'index' => 0
53
+ "physicalLocation" => {
54
+ "artifactLocation" => {
55
+ "uri" => relative_path,
56
+ "uriBaseId" => "%SRCROOT%",
57
+ "index" => 0
79
58
  },
80
- 'region' => {
81
- 'startLine' => o.first_line,
82
- 'startColumn' => o.column,
83
- 'endColumn' => o.last_column
59
+ "region" => {
60
+ "startLine" => o.line,
61
+ "startColumn" => o.real_column,
62
+ "endColumn" => o.last_column
84
63
  }
85
64
  }
86
65
  }
87
66
  ],
88
- 'partialFingerprints' => {
67
+ "partialFingerprints" => {
89
68
  # This will be computed by the upload action for now
90
69
  }
91
70
  }
@@ -93,8 +72,11 @@ module CodeScanning
93
72
  end
94
73
 
95
74
  def finished(_inspected_files)
96
- json = JSON.pretty_generate(@sarif)
97
- output.print(json)
75
+ output.print(sarif_json)
76
+ end
77
+
78
+ def sarif_json
79
+ JSON.pretty_generate(@sarif)
98
80
  end
99
81
  end
100
82
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CodeScanning
2
4
  module Rubocop
3
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
4
6
  end
5
7
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../code_scanning"
4
+
5
+ class QHelpGenerator
6
+ def initialize
7
+ @formatter = CodeScanning::SarifFormatter.new(nil)
8
+ end
9
+
10
+ def parse_file(path_to_file)
11
+ file = File.open(path_to_file)
12
+ current_rule = nil
13
+ file.each_with_index do |line, index|
14
+ # title: skip
15
+ next if index.zero?
16
+
17
+ if line[0..2] == "## "
18
+ current_cop = line[3..-2]
19
+ current_rule, _index = @formatter.get_rule(current_cop, nil)
20
+ next
21
+ end
22
+
23
+ next if current_rule.nil?
24
+ if line == "\n" && current_rule.help_empty?
25
+ # Don't start the help text with new lines
26
+ next
27
+ end
28
+
29
+ current_rule.append_help(line)
30
+ end
31
+ end
32
+
33
+ def sarif_json
34
+ @formatter.sarif_json
35
+ end
36
+ end
Binary file
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.2.0
4
+ version: 0.3.0
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-05 00:00:00.000000000 Z
11
+ date: 2020-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -32,7 +32,11 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
+ - ".github/workflows/rubocop-analysis.yml"
36
+ - ".github/workflows/ruby.yml"
35
37
  - ".gitignore"
38
+ - ".rubocop.yml"
39
+ - ".rubocop_todo.yml"
36
40
  - CODE_OF_CONDUCT.md
37
41
  - Dockerfile
38
42
  - Gemfile
@@ -45,8 +49,11 @@ files:
45
49
  - code-scanning-rubocop.gemspec
46
50
  - entrypoint.sh
47
51
  - lib/code_scanning.rb
52
+ - lib/code_scanning/rubocop/rule.rb
48
53
  - lib/code_scanning/rubocop/sarif_formatter.rb
49
54
  - lib/code_scanning/rubocop/version.rb
55
+ - lib/code_scanning/rules_generator.rb
56
+ - preview.png
50
57
  - rubocop-action/action.yml
51
58
  homepage: https://github.com/arthurnn/code-scanning-rubocop
52
59
  licenses: