rubycritic_gitlab_code_quality 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 +7 -0
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +5 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/lib/generator/gitlab.rb +67 -0
- data/lib/rubycritic_gitlab_code_quality/version.rb +5 -0
- data/lib/rubycritic_gitlab_code_quality.rb +8 -0
- data/lib/utilits.rb +57 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f86e0e0e0021871b5d4edfa6f42c2318734f5816953dbddc03fb7f30c7a41363
|
4
|
+
data.tar.gz: b7d4d3918b31c0f7de271280187d54a350009e3f6eed71d101447bdea4b7479d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80797587a95b4bb4e54eb027a6b3c63c07db3245caa684c7e883c028430faec8c006a8537b7f574fa47d233f4ceced0cee095b999bd2e6fef52c2e883569956d
|
7
|
+
data.tar.gz: 3ab009bf63ef7d61e83cb06df9df28a84c2aab9b9c49beec47db65866ccf399c0b6b3c855cc307b6448c060ae86686e98d8bcfbeeed3b703f0e1fbeee147a5d4
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# RubycriticGitlabQualityFormatter
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
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/rubycritic_gitlab_quality_formatter`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
15
|
+
```
|
16
|
+
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
|
+
|
19
|
+
```bash
|
20
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
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.
|
30
|
+
|
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rubycritic_gitlab_quality_formatter.
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubycriticGitlabCodeQuality::Generator
|
4
|
+
class Gitlab
|
5
|
+
def initialize(analysed_modules)
|
6
|
+
@analysed_modules = analysed_modules
|
7
|
+
end
|
8
|
+
|
9
|
+
# Generate the JSON report file for GitLab Code Quality
|
10
|
+
def generate_report
|
11
|
+
json_report = JSON.pretty_generate(build_report)
|
12
|
+
FileUtils.mkdir_p(file_directory) # Ensure output directory exists:contentReference[oaicite:7]{index=7}
|
13
|
+
File.write(file_pathname, json_report)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def file_directory
|
19
|
+
RubyCritic::Config.root
|
20
|
+
end
|
21
|
+
|
22
|
+
def file_pathname
|
23
|
+
File.join(file_directory, 'gl-code-quality-report.json')
|
24
|
+
end
|
25
|
+
|
26
|
+
# Build the JSON array of issues (as a pretty-printed JSON string)
|
27
|
+
def build_report
|
28
|
+
@analysed_modules.each_with_object([]) do |mod, issues|
|
29
|
+
mod.smells.each do |smell|
|
30
|
+
locations = smell.locations
|
31
|
+
issues << issue_hash(smell, locations)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Determine if a smell should be included as a "critical" issue
|
37
|
+
# def critical_issue?(smell)
|
38
|
+
# type = smell.type
|
39
|
+
# # Exclude trivial naming/code style smells
|
40
|
+
# return false if type =~ /Uncommunicative/ # e.g. UncommunicativeVariableName
|
41
|
+
# # (Add other minor smell types to exclude if needed)
|
42
|
+
# # If the smell has a numeric score (e.g. complexity score), we can require it be high:
|
43
|
+
# if smell.respond_to?(:score) && smell.score.is_a?(Numeric)
|
44
|
+
# return false if smell.score < 15 # skip low-impact complexity (<15, not very complex)
|
45
|
+
# end
|
46
|
+
# true # include by default if not filtered out
|
47
|
+
# end
|
48
|
+
|
49
|
+
# Construct the issue hash for a given smell and a specific location
|
50
|
+
def issue_hash(smell, locations)
|
51
|
+
main_location = locations.first
|
52
|
+
{
|
53
|
+
type: 'issue',
|
54
|
+
description: smell.message,
|
55
|
+
check_name: smell.type,
|
56
|
+
fingerprint: Utilits.fingerprint(smell, main_location),
|
57
|
+
severity: Utilits.severity(smell),
|
58
|
+
location: {
|
59
|
+
path: Utilits.relative_path(main_location.pathname.to_s),
|
60
|
+
lines: { begin: main_location.line },
|
61
|
+
other_locations: Utilits.additional_locations_hash(locations)
|
62
|
+
},
|
63
|
+
categories: [Utilits.category(smell)]
|
64
|
+
}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/utilits.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Utilits
|
4
|
+
class << self
|
5
|
+
# Helper to get relative file path (without "./") from a Pathname or string
|
6
|
+
def relative_path(file_path)
|
7
|
+
path = file_path.to_s
|
8
|
+
path.sub(%r{^\.\/}, '')
|
9
|
+
end
|
10
|
+
|
11
|
+
def fingerprint(smell, location)
|
12
|
+
# Use a stable combination of attributes to generate an MD5 hash
|
13
|
+
data = "#{smell.type}|#{smell.context}|#{smell.message}|#{location.pathname}|#{location.line}"
|
14
|
+
Digest::MD5.hexdigest(data)
|
15
|
+
end
|
16
|
+
|
17
|
+
def category(smell)
|
18
|
+
case smell.type.to_s
|
19
|
+
when /Complex|TooManyStatements|LongParameterList/
|
20
|
+
"Complexity"
|
21
|
+
when /Duplicate/
|
22
|
+
"Duplication"
|
23
|
+
when /Irresponsible|FeatureEnvy|UtilityFunction|Clarity|NilCheck|ControlParameter/
|
24
|
+
"Clarity"
|
25
|
+
else
|
26
|
+
"Clarity" # default to Clarity if not matched, since we filtered out pure style issues
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def additional_locations_hash(locations)
|
31
|
+
additional_locations = locations[1..]
|
32
|
+
return nil if additional_locations.empty?
|
33
|
+
|
34
|
+
additional_locations.map do
|
35
|
+
{ path: relative_path(it.pathname.to_s),
|
36
|
+
lines: { begin: it.line } }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Map the smell to a severity level for GitLab (info, minor, major, critical, blocker)
|
41
|
+
def severity(smell)
|
42
|
+
score = smell.score
|
43
|
+
return "info" unless score
|
44
|
+
|
45
|
+
case score
|
46
|
+
when 0..9
|
47
|
+
"info"
|
48
|
+
when 10..29
|
49
|
+
"minor"
|
50
|
+
when 30..80
|
51
|
+
"major"
|
52
|
+
else
|
53
|
+
"critical"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubycritic_gitlab_code_quality
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- n.kats
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-05-21 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: rubycritic
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: 4.9.2
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 4.9.2
|
26
|
+
email:
|
27
|
+
- ''
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- ".rubocop.yml"
|
33
|
+
- CHANGELOG.md
|
34
|
+
- README.md
|
35
|
+
- Rakefile
|
36
|
+
- lib/generator/gitlab.rb
|
37
|
+
- lib/rubycritic_gitlab_code_quality.rb
|
38
|
+
- lib/rubycritic_gitlab_code_quality/version.rb
|
39
|
+
- lib/utilits.rb
|
40
|
+
licenses: []
|
41
|
+
metadata: {}
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 3.1.0
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubygems_version: 3.6.5
|
57
|
+
specification_version: 4
|
58
|
+
summary: gitlab code quality formatter for use with gitlab CI.
|
59
|
+
test_files: []
|