Skip to content

Commit 562c54a

Browse files
committed
Added SonarQube checks and gradle Checkstyle
1 parent 41b1956 commit 562c54a

File tree

4 files changed

+250
-1
lines changed

4 files changed

+250
-1
lines changed

.github/workflows/build.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: SonarQube
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
jobs:
9+
build:
10+
name: Build and analyze
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: 17
20+
distribution: 'zulu' # Alternative distribution options are available
21+
- name: Cache SonarQube packages
22+
uses: actions/cache@v4
23+
with:
24+
path: ~/.sonar/cache
25+
key: ${{ runner.os }}-sonar
26+
restore-keys: ${{ runner.os }}-sonar
27+
- name: Cache Gradle packages
28+
uses: actions/cache@v4
29+
with:
30+
path: ~/.gradle/caches
31+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
32+
restore-keys: ${{ runner.os }}-gradle
33+
- name: Build and analyze
34+
env:
35+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
36+
run: ./gradlew build sonar --info

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
### Hexlet tests and linter status:
2-
[![Actions Status](https://github.com/aseccxz/java-project-61/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/aseccxz/java-project-61/actions)
2+
[![Actions Status](https://github.com/aseccxz/java-project-61/actions/workflows/hexlet-check.yml/badge.svg)](https://github.com/aseccxz/java-project-61/actions)
3+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)
4+
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=bugs)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)
5+
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)
6+
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)
7+
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)
8+
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)
9+
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)
10+
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)
11+
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=aseccxz_java-project-61&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=aseccxz_java-project-61)

app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
application
33
id("com.github.ben-manes.versions") version "0.53.0"
44
id("org.sonarqube") version "6.3.1.5724"
5+
checkstyle
56
}
67

78
group = "hexlet.code"
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
4+
"https://checkstyle.org/dtds/configuration_1_3.dtd">
5+
6+
<!--
7+
8+
Checkstyle configuration that checks the sun coding conventions from:
9+
10+
- the Java Language Specification at
11+
https://docs.oracle.com/javase/specs/jls/se11/html/index.html
12+
13+
- the Sun Code Conventions at https://www.oracle.com/technetwork/java/codeconvtoc-136057.html
14+
15+
- the Javadoc guidelines at
16+
https://www.oracle.com/technetwork/java/javase/documentation/index-137868.html
17+
18+
- the JDK Api documentation https://docs.oracle.com/en/java/javase/11/
19+
20+
- some best practices
21+
22+
Checkstyle is very configurable. Be sure to read the documentation at
23+
https://checkstyle.org (or in your downloaded distribution).
24+
25+
Most Checks are configurable, be sure to consult the documentation.
26+
27+
To completely disable a check, just comment it out or delete it from the file.
28+
To suppress certain violations please review suppression filters.
29+
30+
Finally, it is worth reading the documentation.
31+
32+
-->
33+
34+
<module name="Checker">
35+
<!--
36+
If you set the basedir property below, then all reported file
37+
names will be relative to the specified directory. See
38+
https://checkstyle.org/5.x/config.html#Checker
39+
40+
<property name="basedir" value="${basedir}"/>
41+
-->
42+
<property name="severity" value="error"/>
43+
44+
<property name="fileExtensions" value="java, properties, xml"/>
45+
46+
<!-- Excludes all 'module-info.java' files -->
47+
<!-- See https://checkstyle.org/config_filefilters.html -->
48+
<module name="BeforeExecutionExclusionFileFilter">
49+
<property name="fileNamePattern" value="module\-info\.java$"/>
50+
</module>
51+
52+
<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
53+
<module name="SuppressionFilter">
54+
<property name="file" value="${org.checkstyle.sun.suppressionfilter.config}"
55+
default="checkstyle-suppressions.xml" />
56+
<property name="optional" value="true"/>
57+
</module>
58+
59+
<!-- Checks that a package-info.java file exists for each package. -->
60+
<!-- See https://checkstyle.org/config_javadoc.html#JavadocPackage -->
61+
<!-- <module name="JavadocPackage"/> -->
62+
63+
<!-- Checks whether files end with a new line. -->
64+
<!-- See https://checkstyle.org/config_misc.html#NewlineAtEndOfFile -->
65+
<module name="NewlineAtEndOfFile"/>
66+
67+
<!-- Checks that property files contain the same keys. -->
68+
<!-- See https://checkstyle.org/config_misc.html#Translation -->
69+
<module name="Translation"/>
70+
71+
<!-- Checks for Size Violations. -->
72+
<!-- See https://checkstyle.org/config_sizes.html -->
73+
<module name="FileLength"/>
74+
<module name="LineLength">
75+
<property name="fileExtensions" value="java"/>
76+
<property name="max" value="120"/>
77+
</module>
78+
79+
<!-- Checks for whitespace -->
80+
<!-- See https://checkstyle.org/config_whitespace.html -->
81+
<module name="FileTabCharacter"/>
82+
83+
<!-- Miscellaneous other checks. -->
84+
<!-- See https://checkstyle.org/config_misc.html -->
85+
<module name="RegexpSingleline">
86+
<property name="format" value="\s+$"/>
87+
<property name="minimum" value="0"/>
88+
<property name="maximum" value="0"/>
89+
<property name="message" value="Line has trailing spaces."/>
90+
</module>
91+
92+
<!-- Checks for Headers -->
93+
<!-- See https://checkstyle.org/config_header.html -->
94+
<!-- <module name="Header"> -->
95+
<!-- <property name="headerFile" value="${checkstyle.header.file}"/> -->
96+
<!-- <property name="fileExtensions" value="java"/> -->
97+
<!-- </module> -->
98+
99+
<module name="TreeWalker">
100+
101+
<!-- Checks for Javadoc comments. -->
102+
<!-- See https://checkstyle.org/config_javadoc.html -->
103+
<module name="InvalidJavadocPosition"/>
104+
<module name="JavadocMethod"/>
105+
<module name="JavadocType"/>
106+
<!-- <module name="JavadocVariable"/> -->
107+
<module name="JavadocStyle"/>
108+
<!-- <module name="MissingJavadocMethod"/> -->
109+
110+
<!-- Checks for Naming Conventions. -->
111+
<!-- See https://checkstyle.org/config_naming.html -->
112+
<module name="ConstantName"/>
113+
<module name="LocalFinalVariableName"/>
114+
<module name="LocalVariableName"/>
115+
<module name="MemberName"/>
116+
<module name="MethodName"/>
117+
<module name="PackageName"/>
118+
<module name="ParameterName"/>
119+
<module name="StaticVariableName"/>
120+
<module name="TypeName"/>
121+
122+
<!-- Checks for imports -->
123+
<!-- See https://checkstyle.org/config_import.html -->
124+
<module name="AvoidStarImport"/>
125+
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
126+
<module name="RedundantImport"/>
127+
<module name="UnusedImports">
128+
<property name="processJavadoc" value="false"/>
129+
</module>
130+
131+
<!-- Checks for Size Violations. -->
132+
<!-- See https://checkstyle.org/config_sizes.html -->
133+
<module name="MethodLength"/>
134+
<module name="ParameterNumber"/>
135+
136+
<!-- Checks for whitespace -->
137+
<!-- See https://checkstyle.org/config_whitespace.html -->
138+
<module name="EmptyForIteratorPad"/>
139+
<module name="GenericWhitespace"/>
140+
<module name="MethodParamPad"/>
141+
<module name="NoWhitespaceAfter"/>
142+
<module name="NoWhitespaceBefore"/>
143+
<module name="OperatorWrap"/>
144+
<module name="ParenPad"/>
145+
<module name="TypecastParenPad"/>
146+
<module name="WhitespaceAfter"/>
147+
<module name="WhitespaceAround"/>
148+
149+
<!-- Modifier Checks -->
150+
<!-- See https://checkstyle.org/config_modifiers.html -->
151+
<module name="ModifierOrder"/>
152+
<module name="RedundantModifier"/>
153+
154+
<!-- Checks for blocks. You know, those {}'s -->
155+
<!-- See https://checkstyle.org/config_blocks.html -->
156+
<module name="AvoidNestedBlocks"/>
157+
<module name="EmptyBlock"/>
158+
<module name="LeftCurly"/>
159+
<module name="NeedBraces"/>
160+
<module name="RightCurly"/>
161+
162+
<!-- Checks for common coding problems -->
163+
<!-- See https://checkstyle.org/config_coding.html -->
164+
<module name="EmptyStatement"/>
165+
<module name="EqualsHashCode"/>
166+
<module name="HiddenField"/>
167+
<module name="IllegalInstantiation"/>
168+
<module name="InnerAssignment"/>
169+
<module name="MagicNumber"/>
170+
<module name="MissingSwitchDefault"/>
171+
<module name="MultipleVariableDeclarations"/>
172+
<module name="SimplifyBooleanExpression"/>
173+
<module name="SimplifyBooleanReturn"/>
174+
175+
<!-- Checks for class design -->
176+
<!-- See https://checkstyle.org/config_design.html -->
177+
<module name="DesignForExtension"/>
178+
<module name="FinalClass"/>
179+
<!-- <module name="HideUtilityClassConstructor"/> -->
180+
<module name="InterfaceIsType"/>
181+
<module name="VisibilityModifier"/>
182+
183+
<!-- Miscellaneous other checks. -->
184+
<!-- See https://checkstyle.org/config_misc.html -->
185+
<module name="ArrayTypeStyle"/>
186+
<!-- <module name="FinalParameters"/> -->
187+
<module name="TodoComment"/>
188+
<module name="UpperEll"/>
189+
190+
<module name="Indentation">
191+
<property name="basicOffset" value="4"/>
192+
</module>
193+
194+
<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->
195+
<module name="SuppressionXpathFilter">
196+
<property name="file" value="${org.checkstyle.sun.suppressionxpathfilter.config}"
197+
default="checkstyle-xpath-suppressions.xml" />
198+
<property name="optional" value="true"/>
199+
</module>
200+
201+
</module>
202+
203+
</module>

0 commit comments

Comments
 (0)