checkstyle-suppression-generator 0.0.1

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: 42e391eb667e9f0df93569f81c1b6b6f2cfb6b870ed541d794b95ec15f71feaa
4
+ data.tar.gz: 366c228d8a8d5a27cec451fe35e6a9d035f4bb03cf53e6f9a3d76cb42370d91e
5
+ SHA512:
6
+ metadata.gz: 59c239fdf6265eee4930e9eccf4d96bafae357a4c461f1a74606338f876c4f4c50570bc5d546b6a0313e77e1d20a04cc7d222e4725edb845bd16c188b3fc9e4e
7
+ data.tar.gz: 588388ee5b9c58b34f2fc48c2695177ffc4bb85fd795122ee12ce8bf7d09b287d96db07383dc36cc8c4a395723de7cb0718877cd627d4603d7e6db39ab7abbd6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Tyler Matthews
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Checkstyle Suppression Generator
2
+ [![Gem Version](https://badge.fury.io/rb/checkstyle-suppression-generator.svg)](https://badge.fury.io/rb/checkstyle-suppression-generator)
3
+ ![CI Status](https://github.com/matthewstyler/ruby-perlin-2D-map-generator/actions/workflows/main.yml/badge.svg)
4
+ ![CodeQL](https://github.com/matthewstyler/checkstyle-suppression-generator/workflows/CodeQL/badge.svg)
5
+ <a href="https://codeclimate.com/github/matthewstyler/checkstyle-suppression-generator/test_coverage"><img src="https://api.codeclimate.com/v1/badges/b63e2b943acbfd970fae/test_coverage" /></a>
6
+ <a href="https://codeclimate.com/github/matthewstyler/checkstyle-suppression-generator/maintainability"><img src="https://api.codeclimate.com/v1/badges/b63e2b943acbfd970fae/maintainability" /></a>
7
+
8
+ A gem that takes as input the output of a maven checkstyle plugin checkstyle:check goal and generates a suppressions.xml file.
9
+
10
+ Example Input:
11
+ ```sh
12
+ [INFO] Scanning for projects...
13
+ [INFO] ------------------------------------------------------------------------
14
+ [INFO] Reactor Build Order:
15
+ [INFO]
16
+ [INFO] my-project [jar]
17
+ [INFO] ------------------< com.my-project:my-project >------------------
18
+ [INFO] Building my-project 0.0.1-SNAPSHOT [1/1]
19
+ [INFO] from my-project/pom.xml
20
+ [INFO] --------------------------------[ jar ]---------------------------------
21
+ [INFO]
22
+ [INFO] --- checkstyle:3.3.0:check (default-cli) @ my-project ---
23
+ [WARNING] src/main/java/com/test/DEF.java:[147,4] (coding) OverloadMethodsDeclarationOrder: All overloaded methods should be placed next to each other. Placing non-overloaded methods in between overloaded methods with the same type is a violation. Previous overloaded method located at line '119'.
24
+ [WARNING] src/main/java/com/test/ABC.java:[26,11] (sizes) ParameterNumber: More than 7 parameters (found 9).
25
+ [WARNING] src/main/java/com/test/ABC.java:[103,4] (coding) ReturnCount: Return count is 6 (max allowed for non-void methods/lambdas is 4).
26
+ [WARNING] src/main/java/com/test/ABC.java:[103,4] (metrics) NPathComplexity: NPath Complexity is 720 (max allowed is 200).
27
+ [INFO] ------------------------------------------------------------------------
28
+ [INFO] Reactor Summary for my-project 0.0.1-SNAPSHOT:
29
+ [INFO]
30
+ [INFO] my-project .................................. FAILURE [ 1.957 s]
31
+ [INFO] ------------------------------------------------------------------------
32
+ [INFO] BUILD FAILURE
33
+ [INFO] ------------------------------------------------------------------------
34
+ [INFO] Total time: 2.841 s
35
+ [INFO] Finished at: 2023-12-20T16:31:35-05:00
36
+ [INFO] ------------------------------------------------------------------------
37
+ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.3.0:check (default-cli) on project my-project: You have 4 Checkstyle violations. -> [Help 1]
38
+ [ERROR]
39
+ [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
40
+ [ERROR] Re-run Maven using the -X switch to enable full debug logging.
41
+ [ERROR]
42
+ [ERROR] For more information about the errors and possible solutions, please read the following articles:
43
+ [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
44
+ [ERROR]
45
+ [ERROR] After correcting the problems, you can resume the build with the command
46
+ [ERROR] mvn <args> -rf :my-project
47
+
48
+ ```
49
+
50
+ Output:
51
+
52
+ ```xml
53
+ <?xml version="1.0"?>
54
+ <!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
55
+ "https://checkstyle.org/dtds/suppressions_1_2.dtd">
56
+
57
+ <suppressions>
58
+
59
+ <suppress checks="OverloadMethodsDeclarationOrder" files="src/main/java/com/test/DEF.java"/>
60
+ <suppress checks="ParameterNumber" files="src/main/java/com/test/ABC.java"/>
61
+ <suppress checks="ReturnCount" files="src/main/java/com/test/ABC.java"/>
62
+ <suppress checks="NPathComplexity" files="src/main/java/com/test/ABC.java"/>
63
+
64
+ </suppressions>
65
+
66
+ ```
67
+
68
+
69
+ ## Command Line Usage
70
+ ```sh
71
+ Usage: checkstyle-suppression-generator command [OPTIONS]
72
+ CHECKSTYLE_OUTPUT_FILE(STRING) [O=O]
73
+
74
+ Generate a Java checkstyle suppressions.xml file from a checkstyle:check output.
75
+
76
+
77
+ Arguments:
78
+ CHECKSTYLE_OUTPUT_FILE(STRING) Output from checkstyle:check goal
79
+
80
+ Keywords:
81
+ O=O Name of the suppressions file to be generated (default
82
+ "suppressions.xml")
83
+
84
+ Options:
85
+ -h, --help Print usage
86
+ ```
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ lib_path = File.expand_path('../lib', __dir__)
5
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
6
+ require 'CLI/command'
7
+
8
+ Signal.trap('INT') do
9
+ warn("\n#{caller.join("\n")}: interrupted")
10
+ exit(1)
11
+ end
12
+
13
+ CLI::Command.new.parse.run
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tty/option'
4
+ require 'suppression_generator'
5
+
6
+ module CLI
7
+ # Command line usage for the suppression generator
8
+ class Command
9
+ include TTY::Option
10
+
11
+ usage do
12
+ program 'checkstyle-suppression-generator'
13
+ desc 'Generate a Java checkstyle suppressions.xml file from a checkstyle:check output.'
14
+ end
15
+
16
+ argument :checkstyle_output_file do
17
+ name 'checkstyle_output_file(String)'
18
+ arity one
19
+ desc 'Output from checkstyle:check goal'
20
+ end
21
+
22
+ keyword :o do
23
+ default 'suppressions.xml'
24
+ arity one
25
+ desc 'Name of the suppressions file to be generated'
26
+ end
27
+
28
+ flag :help do
29
+ short '-h'
30
+ long '--help'
31
+ desc 'Print usage'
32
+ end
33
+
34
+ def run
35
+ if params[:help]
36
+ print help
37
+ elsif params.errors.any?
38
+ puts params.errors.summary
39
+ else
40
+ execute_command
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def execute_command
47
+ SuppressionGenerator.new(params[:checkstyle_output_file], params[:o]).generate
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Reads the checkstyle:check file
4
+ class CheckstyleOutputReader
5
+ def initialize(filename)
6
+ @filename = filename
7
+ end
8
+
9
+ def read
10
+ File.read(@filename)
11
+ rescue Errno::ENOENT
12
+ raise ArgumentError, "File not found: #{@filename}"
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Data bag to capture fields used to generate suppressions from an offending checkstyle output line
4
+ class CheckstyleOutputToken
5
+ attr_reader :severity, :file_name, :offense
6
+
7
+ def initialize(token_data)
8
+ @severity = token_data[1]
9
+ @file_name = token_data[2]
10
+ @offense = token_data[3]
11
+ end
12
+
13
+ def to_suppression
14
+ "\t<suppress checks=\"#{offense}\" files=\"#{file_name}\"/>"
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'checkstyle_output_token'
4
+
5
+ # Tokenizes each line of a given output string
6
+ class CheckstyleOutputTokenizer
7
+ PATTERN = /\[(\w+)\]\s+(\S+\.java)(?:.*\)).(\w+):/.freeze
8
+
9
+ def initialize(checkstyle_output)
10
+ @checkstyle_output = checkstyle_output
11
+ end
12
+
13
+ def tokenize
14
+ @tokenize ||= @checkstyle_output.each_line.map do |line|
15
+ token_data = PATTERN.match(line)
16
+ CheckstyleOutputToken.new(token_data) if token_data
17
+ end.compact
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'checkstyle_output_reader'
4
+ require 'checkstyle_output_tokenizer'
5
+ require 'suppressions_populator'
6
+ require 'suppression_writer'
7
+
8
+ # Facade that manages the application input and output for suppression generation
9
+ class SuppressionGenerator
10
+ def initialize(checkstyle_file_name, suppressions_file_name)
11
+ @checkstyle_file_name = checkstyle_file_name
12
+ @suppressions_file_name = suppressions_file_name
13
+ end
14
+
15
+ def generate
16
+ write_suppressions(SuppressionsPopulator.new(tokenize_checkstyle_output(read_checkstyle_file)).populate)
17
+ end
18
+
19
+ private
20
+
21
+ def write_suppressions(suppression_xml)
22
+ SuppressionWriter.new(@suppressions_file_name, suppression_xml).write
23
+ end
24
+
25
+ def read_checkstyle_file
26
+ CheckstyleOutputReader.new(@checkstyle_file_name).read
27
+ end
28
+
29
+ def tokenize_checkstyle_output(checkstyle_output)
30
+ CheckstyleOutputTokenizer.new(checkstyle_output).tokenize
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Writes the suppression xml to a given file name
4
+ class SuppressionWriter
5
+ def initialize(file_name, suppression_xml)
6
+ @file_name = file_name
7
+ @suppression_xml = suppression_xml
8
+ end
9
+
10
+ def write
11
+ File.write(@file_name, @suppression_xml)
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Populates a string with the suppression xml, given a list of tokens
4
+ class SuppressionsPopulator
5
+ HEADER = <<~HEADER
6
+ <?xml version="1.0"?>
7
+ <!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
8
+ "https://checkstyle.org/dtds/suppressions_1_2.dtd">
9
+
10
+ <suppressions>
11
+ HEADER
12
+
13
+ FOOTER = <<~FOOTER
14
+ </suppressions>
15
+ FOOTER
16
+
17
+ def initialize(tokens)
18
+ @tokens = tokens
19
+ end
20
+
21
+ def populate
22
+ "#{HEADER}\n#{@tokens.map(&:to_suppression).join("\n")}\n\n#{FOOTER}"
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: checkstyle-suppression-generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Matthews (matthewstyler)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-12-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tty-option
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.18'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.18'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.1.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.1.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.10.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.10.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 13.1.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 13.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.58.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.58.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.22.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.22.0
111
+ description: |-
112
+ A gem that takes as input the output of a maven checkstyle plugin checkstyle:check goal and
113
+ generates a suppressions.xml file
114
+ email: matthews.tyl@gmail.com
115
+ executables:
116
+ - checkstyle-suppression-generator
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - LICENSE
121
+ - README.md
122
+ - bin/checkstyle-suppression-generator
123
+ - lib/CLI/command.rb
124
+ - lib/checkstyle_output_reader.rb
125
+ - lib/checkstyle_output_token.rb
126
+ - lib/checkstyle_output_tokenizer.rb
127
+ - lib/suppression_generator.rb
128
+ - lib/suppression_writer.rb
129
+ - lib/suppressions_populator.rb
130
+ homepage: https://github.com/matthewstyler/checkstyle-suppression-generator
131
+ licenses:
132
+ - MIT
133
+ metadata:
134
+ source_code_uri: https://github.com/matthewstyler/checkstyle-suppression-generator
135
+ bug_tracker_uri: https://github.com/matthewstyler/checkstyle-suppression-generator/issues
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 2.7.0
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.1.2
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Generate a Java checkstyle suppressions.xml file from a checkstyle:check
155
+ output.
156
+ test_files: []