Skip to content

Commit

Permalink
[Improve] Add code quality rules (#252)
Browse files Browse the repository at this point in the history
* [Improve] Add code quality rules

* [Improve] Add code quality rules
  • Loading branch information
wuchunfu authored Sep 20, 2023
1 parent 63598c9 commit 8c969ab
Showing 1 changed file with 129 additions and 3 deletions.
132 changes: 129 additions & 3 deletions community/submit_guide/code-style-and-quality-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ sidebar_position: 3
private static final long serialVersionUID = 1L;
```

2. Redundant strings should be extracted as constants
If a constant has been hardcoded twice or more times, please directly extract it as a constant and change the corresponding reference.
In generally, constants in `log` can be ignored to extract.
2. Redundant strings should be extracted as constants
>If a constant has been hardcoded twice or more times, please directly extract it as a constant and change the corresponding reference.
In generally, constants in `log` can be ignored to extract.

- Negative demo:

Expand Down Expand Up @@ -400,6 +400,132 @@ to reduce code line depth and improve readability like follows:

1. Use a unified `Utils.requireXXX` to complete the validation of the prerequisite, and if possible, replace the `AlertXXException.throwIfXXX` by new pre-conditions checking.

### 3.11 StringUtils

1. Use `StringUtils.isBlank` instead of `StringUtils.isEmpty`

- Negative demo:

```java
if (StringUtils.isEmpty(name)) {
return;
}
```

- Positive demo:

```java
if (StringUtils.isBlank(name)) {
return;
}
```

2. Use `StringUtils.isNotBlank` instead of `StringUtils.isNotEmpty`

- Negative demo:

```java
if (StringUtils.isNotEmpty(name)) {
return;
}
```

- Positive demo:

```java
if (StringUtils.isNotBlank(name)) {
return;
}
```

3. Use `StringUtils.isAllBlank` instead of `StringUtils.isAllEmpty`

- Negative demo:

```java
if (StringUtils.isAllEmpty(name, age)) {
return;
}
```

- Positive demo:

```java
if (StringUtils.isAllBlank(name, age)) {
return;
}
```

### 3.12 `Enum` Class

1. Enumeration value comparison

- Negative demo:

```java
if (status.equals(JobStatus.RUNNING)) {
return;
}
```

- Positive demo:

```java
if (status == JobStatus.RUNNING) {
return;
}
```

2. Enumeration classes do not need to implement Serializable

- Negative demo:

```java
public enum JobStatus implements Serializable {
...
}
```

- Positive demo:

```java
public enum JobStatus {
...
}
```

3. Use `Enum.name()` instead of `Enum.toString()`

- Negative demo:

```java
System.out.println(JobStatus.RUNNING.toString());
```

- Positive demo:

```java
System.out.println(JobStatus.RUNNING.name());
```

4. Enumeration class names uniformly use the Enum suffix

- Negative demo:

```java
public enum JobStatus {
...
}
```

- Positive demo:

```java
public enum JobStatusEnum {
...
}
```

## 4 Exception Processing

This `streampark-console-service` module is the core module for processing user requests.
Expand Down

0 comments on commit 8c969ab

Please sign in to comment.