rubocop-gitlab_formatter 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dc653c05f38b15dd3819c0b4ad9141d402c7f62809a3c2e8aaa931f75c3caa2a
4
+ data.tar.gz: 950eb51ff5dbcd2dc6bace396a7111d1689353f4d24c49dffe68deaecd6bd4ee
5
+ SHA512:
6
+ metadata.gz: eb09f4a99cc22cb7a188088db6ad0b04161cb7b654a3542660426bb937cdb242e77a5b14b91c97b2951da93f303a227b67fa04e9e581e7aacb8c549d1630188f
7
+ data.tar.gz: 9ffd97a5bbbb30dfc6263b1376347cb9569c3e07655d913ae3bf7e0514faa065b3c1b604c933138fe50aa110788292ee57f76be080c789f71a1e0d2ba6601a13
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Jonathan Georges
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # RuboCop GitLab Formatter
2
+
3
+ A very simple [RuboCop](https://github.com/rubocop/rubocop) formatter that renders a json compliant with the [Gitlab CodeQuality format](https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html#implementing-a-custom-tool).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rubocop-gitlab_formatter', require: false
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```ruby
22
+ $ gem install rubocop-gitlab_formatter
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```sh
28
+ rubocop --require rubocop-gitlab_formatter --format RuboCop::Formatter::GitLabFormatter
29
+ ```
30
+
31
+ Or require it in `.rubocop.yml`:
32
+
33
+ ```yaml
34
+ require:
35
+ - rubocop-gitlab_formatter
36
+ ```
37
+
38
+ The main purpose of the formatter is to be used with the [GitLab code quality](https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html) report.
39
+
40
+ Configure your `.gitlab-ci.yml` like that:
41
+
42
+ ```yaml
43
+ rubocop:
44
+ artifacts:
45
+ reports:
46
+ codequality: codequality_reports.json
47
+ script:
48
+ - rubocop --require rubocop-gitlab_formatter --format RuboCop::Formatter::GitLabFormatter --out codequality_reports.json
49
+ ```
50
+
51
+ And enjoy the Code Quality features :tada:
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jojos003/rubocop-gitlab_formatter.
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+ require 'rubocop/formatter/base_formatter'
5
+
6
+ module RuboCop
7
+ module Formatter
8
+ # A very simple RuboCop formatter for use with GitLab code quality artifact
9
+ # @see https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html#implementing-a-custom-tool
10
+ class GitLabFormatter < BaseFormatter
11
+ include PathUtil
12
+
13
+ SEVERITY_MAPPING = {
14
+ I: 'info',
15
+ R: 'minor',
16
+ C: 'minor',
17
+ W: 'major',
18
+ E: 'critical',
19
+ F: 'blocker'
20
+ }.freeze
21
+
22
+ attr_reader :output_array
23
+
24
+ def initialize(output, options = {})
25
+ super
26
+
27
+ @output_array = []
28
+ end
29
+
30
+ def file_finished(file, offenses)
31
+ offenses.each do |offense|
32
+ output_array << hash_for_offense(file, offense)
33
+ end
34
+ end
35
+
36
+ def finished(_inspected_files)
37
+ output.write output_array.to_json
38
+ end
39
+
40
+ def hash_for_offense(file, offense)
41
+ {
42
+ description: offense.message,
43
+ fingerprint: offense.hash,
44
+ severity: SEVERITY_MAPPING[offense.severity.code.to_sym],
45
+ location: hash_for_location(file, offense.location)
46
+ }
47
+ end
48
+
49
+ def hash_for_location(file, location)
50
+ {
51
+ path: smart_path(file),
52
+ lines: {
53
+ begin: location.line
54
+ }
55
+ }
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubocop'
4
+
5
+ require_relative 'rubocop/formatter/gitlab_formatter'
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubocop-gitlab_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Georges
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rubocop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.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.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.9'
83
+ description: A very simple RuboCop formatter that renders a json compliant with the
84
+ Gitlab CodeQuality format.
85
+ email:
86
+ - jojos003@free.fr
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - LICENSE.txt
92
+ - README.md
93
+ - lib/rubocop-gitlab_formatter.rb
94
+ - lib/rubocop/formatter/gitlab_formatter.rb
95
+ homepage: https://github.com/jojos003/rubocop-gitlab_formatter
96
+ licenses:
97
+ - MIT
98
+ metadata:
99
+ rubygems_mfa_required: 'true'
100
+ homepage_uri: https://github.com/jojos003/rubocop-gitlab_formatter
101
+ source_code_uri: https://github.com/jojos003/rubocop-gitlab_formatter
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.6.0
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubygems_version: 3.3.7
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: A RuboCop formatter for GitLab CodeQuality reports
121
+ test_files: []