Skip to content

Commit f33adb1

Browse files
committed
2021-01-10 Version 1.0.0: Repository update
1. Added: - GitHub Actions integration; - Checkstyle support; - CPD support; - README.md.
1 parent 3afeba7 commit f33adb1

File tree

6 files changed

+106
-15
lines changed

6 files changed

+106
-15
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
env:
10+
GRADLE_OPTS: -Dorg.gradle.daemon=false
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up JDK 1.8
18+
uses: actions/setup-java@v1
19+
with:
20+
java-version: 1.8
21+
- name: Build with Gradle
22+
run: ./gradlew build

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# checkstyle-checks-java
2+
3+
[![GitHubActions](https://github.com/fartem/checkstyle-checks-java/workflows/Build/badge.svg)](https://github.com/fartem/checkstyle-checks-hava/actions?query=workflow%3ABuild)
4+
5+
## About
6+
7+
Custom Checkstyle checks for Java projects.
8+
9+
## Checks
10+
11+
| Check | Description | Level |
12+
| --- | --- | --- |
13+
| `UtilityClassPrivateConstructorCheck` | Check primary private constructor in Utility class | `Error` |
14+
15+
## Installation
16+
17+
### Gradle
18+
19+
If you are using [Checkstyle plugin]() for Gradle, add checks project as dependency in the `dependencies` section in the `build.gradle`:
20+
21+
```groovy
22+
checkstyle 'com.github.fartem:checkstyle-checks-java:master'
23+
```
24+
25+
## How to use
26+
27+
Add to `TreeWalker` module:
28+
29+
```xml
30+
<module name="com.smlnskgmail.jaman.checkstyle.checks.UtilityClassPrivateConstructorCheck">
31+
<property name="id" value="UtilityClassPrivateConstructorCheck" />
32+
</module>
33+
```
34+
35+
## How to contribute
36+
37+
Read [Commit Convention](https://github.com/fartem/repository-rules/blob/master/commit-convention/COMMIT_CONVENTION.md). Make sure your build is green before you contribute your pull request. Then:
38+
39+
```shell
40+
./gradlew clean
41+
./gradlew build
42+
```
43+
44+
If you don't see any error messages, submit your pull request.
45+
46+
## Contributors
47+
48+
- [@fartem](https://github.com/fartem) as Artem Fomchenkov

build.gradle

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
11
plugins {
22
id 'java'
3+
id 'checkstyle'
4+
id 'de.aaschmid.cpd' version '3.1'
35
}
46

57
group 'com.smlnskgmail.jaman.checkstyle'
68
version '1.0.0'
79

10+
checkstyle {
11+
toolVersion '8.38'
12+
ignoreFailures false
13+
showViolations true
14+
15+
def checkstyleConfigPath = "$rootDir/checkstyle.xml"
16+
def checkstyleConfig = new File(checkstyleConfigPath)
17+
new URL(
18+
"https://raw.githubusercontent.com/fartem/repository-rules/master/rules/java/checkstyle/checkstyle.xml"
19+
).withInputStream {
20+
i -> checkstyleConfig.withOutputStream {
21+
it << i
22+
}
23+
}
24+
25+
configFile file(checkstyleConfigPath)
26+
}
27+
28+
checkstyleMain {
29+
source = 'src/main/java'
30+
}
31+
32+
cpd {
33+
language = 'java'
34+
}
35+
836
repositories {
937
mavenCentral()
1038
}
1139

1240
dependencies {
1341
implementation 'com.puppycrawl.tools:checkstyle:8.38'
1442
}
15-
16-
test {
17-
useJUnitPlatform()
18-
}

gradlew

100644100755
File mode changed.

settings.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
rootProject.name = 'checkstyle-checks-java'
2-

src/main/java/com/smlnskgmail/jaman/checkstyle/checks/UtilityClassPrivateConstructorCheck.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ public void visitToken(DetailAST ast) {
1919
TokenUtil.forEachChild(
2020
objBlock,
2121
TokenTypes.CTOR_DEF,
22-
detailAST -> {
23-
TokenUtil.forEachChild(
24-
detailAST,
25-
TokenTypes.MODIFIERS,
26-
modifiers -> {
27-
if (!modifiers.branchContains(TokenTypes.LITERAL_PRIVATE)) {
28-
log(ast);
29-
}
22+
detailAST -> TokenUtil.forEachChild(
23+
detailAST,
24+
TokenTypes.MODIFIERS,
25+
modifiers -> {
26+
if (!modifiers.branchContains(TokenTypes.LITERAL_PRIVATE)) {
27+
log(ast);
3028
}
31-
);
32-
}
29+
}
30+
)
3331
);
3432
}
3533
}

0 commit comments

Comments
 (0)