Commit c0ade4a0fdde8e13c2daaf5afbf96ab0a2628ead
1 parent
0d71a3c6
chore(usr): 配置 checkstyle.xml 并修复 5 处 lint 违规
- 添加 backend/checkstyle.xml(Spring Boot 友好规则集,替换过严的 sun_checks.xml) - pom.xml 配置 maven-checkstyle-plugin 使用自定义规则 - 修复: Application.java 未使用 import - 修复: AuthController / UserController 通配符 import 改为精确 import - 修复: GlobalExceptionHandler 两处未使用 import
Showing
6 changed files
with
71 additions
and
5 deletions
backend/checkstyle.xml
0 → 100644
| 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 | + 项目 checkstyle 规则(Spring Boot + Lombok 友好,不使用 sun_checks.xml 的过严规则) | ||
| 7 | + 规则原则:检查明显的代码问题,不干预 Lombok 注解生成类、不要求 final 参数、不限制行长。 | ||
| 8 | +--> | ||
| 9 | +<module name="Checker"> | ||
| 10 | + <property name="charset" value="UTF-8"/> | ||
| 11 | + <property name="severity" value="error"/> | ||
| 12 | + <property name="fileExtensions" value="java"/> | ||
| 13 | + | ||
| 14 | + <module name="TreeWalker"> | ||
| 15 | + <!-- 未使用的 import --> | ||
| 16 | + <module name="UnusedImports"/> | ||
| 17 | + <!-- 重复 import --> | ||
| 18 | + <module name="RedundantImport"/> | ||
| 19 | + <!-- 通配符 import(java.util.* 等)--> | ||
| 20 | + <module name="AvoidStarImport"/> | ||
| 21 | + | ||
| 22 | + <!-- 左大括号位置 --> | ||
| 23 | + <module name="LeftCurly"/> | ||
| 24 | + <!-- 空代码块(空 catch 需有注释)--> | ||
| 25 | + <module name="EmptyBlock"> | ||
| 26 | + <property name="option" value="text"/> | ||
| 27 | + </module> | ||
| 28 | + | ||
| 29 | + <!-- switch 缺少 default --> | ||
| 30 | + <module name="MissingSwitchDefault"/> | ||
| 31 | + | ||
| 32 | + <!-- == 比较 String 字面量 --> | ||
| 33 | + <module name="StringLiteralEquality"/> | ||
| 34 | + | ||
| 35 | + <!-- 多余的分号 --> | ||
| 36 | + <module name="EmptyStatement"/> | ||
| 37 | + | ||
| 38 | + <!-- 修饰符顺序 (public static final ...) --> | ||
| 39 | + <module name="ModifierOrder"/> | ||
| 40 | + | ||
| 41 | + <!-- 不允许 System.out.println(生产代码用 logger)--> | ||
| 42 | + <module name="Regexp"> | ||
| 43 | + <property name="format" value="System\.(out|err)\.print"/> | ||
| 44 | + <property name="illegalPattern" value="true"/> | ||
| 45 | + <property name="message" value="请使用 logger 而非 System.out/err.print"/> | ||
| 46 | + </module> | ||
| 47 | + </module> | ||
| 48 | +</module> |
backend/pom.xml
| @@ -122,6 +122,16 @@ | @@ -122,6 +122,16 @@ | ||
| 122 | <plugins> | 122 | <plugins> |
| 123 | <plugin> | 123 | <plugin> |
| 124 | <groupId>org.apache.maven.plugins</groupId> | 124 | <groupId>org.apache.maven.plugins</groupId> |
| 125 | + <artifactId>maven-checkstyle-plugin</artifactId> | ||
| 126 | + <configuration> | ||
| 127 | + <configLocation>checkstyle.xml</configLocation> | ||
| 128 | + <consoleOutput>true</consoleOutput> | ||
| 129 | + <failsOnError>true</failsOnError> | ||
| 130 | + <includeTestSourceDirectory>false</includeTestSourceDirectory> | ||
| 131 | + </configuration> | ||
| 132 | + </plugin> | ||
| 133 | + <plugin> | ||
| 134 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 125 | <artifactId>maven-surefire-plugin</artifactId> | 135 | <artifactId>maven-surefire-plugin</artifactId> |
| 126 | <configuration> | 136 | <configuration> |
| 127 | <argLine> | 137 | <argLine> |
backend/src/main/java/com/example/erp/Application.java
| @@ -2,7 +2,6 @@ package com.example.erp; | @@ -2,7 +2,6 @@ package com.example.erp; | ||
| 2 | 2 | ||
| 3 | import org.springframework.boot.SpringApplication; | 3 | import org.springframework.boot.SpringApplication; |
| 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 5 | -import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
| 6 | 5 | ||
| 7 | @SpringBootApplication | 6 | @SpringBootApplication |
| 8 | public class Application { | 7 | public class Application { |
backend/src/main/java/com/example/erp/common/exception/GlobalExceptionHandler.java
| @@ -2,11 +2,9 @@ package com.example.erp.common.exception; | @@ -2,11 +2,9 @@ package com.example.erp.common.exception; | ||
| 2 | 2 | ||
| 3 | import com.example.erp.common.response.Result; | 3 | import com.example.erp.common.response.Result; |
| 4 | import lombok.extern.slf4j.Slf4j; | 4 | import lombok.extern.slf4j.Slf4j; |
| 5 | -import org.springframework.http.HttpStatus; | ||
| 6 | import org.springframework.validation.FieldError; | 5 | import org.springframework.validation.FieldError; |
| 7 | import org.springframework.web.bind.MethodArgumentNotValidException; | 6 | import org.springframework.web.bind.MethodArgumentNotValidException; |
| 8 | import org.springframework.web.bind.annotation.ExceptionHandler; | 7 | import org.springframework.web.bind.annotation.ExceptionHandler; |
| 9 | -import org.springframework.web.bind.annotation.ResponseStatus; | ||
| 10 | import org.springframework.web.bind.annotation.RestControllerAdvice; | 8 | import org.springframework.web.bind.annotation.RestControllerAdvice; |
| 11 | 9 | ||
| 12 | @Slf4j | 10 | @Slf4j |
backend/src/main/java/com/example/erp/module/usr/controller/AuthController.java
| @@ -8,7 +8,11 @@ import com.example.erp.module.usr.vo.BrandVO; | @@ -8,7 +8,11 @@ import com.example.erp.module.usr.vo.BrandVO; | ||
| 8 | import com.example.erp.module.usr.vo.LoginVO; | 8 | import com.example.erp.module.usr.vo.LoginVO; |
| 9 | import jakarta.validation.Valid; | 9 | import jakarta.validation.Valid; |
| 10 | import lombok.RequiredArgsConstructor; | 10 | import lombok.RequiredArgsConstructor; |
| 11 | -import org.springframework.web.bind.annotation.*; | 11 | +import org.springframework.web.bind.annotation.GetMapping; |
| 12 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 13 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 14 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 15 | +import org.springframework.web.bind.annotation.RestController; | ||
| 12 | 16 | ||
| 13 | import java.util.List; | 17 | import java.util.List; |
| 14 | import java.util.Map; | 18 | import java.util.Map; |
backend/src/main/java/com/example/erp/module/usr/controller/UserController.java
| @@ -15,7 +15,14 @@ import com.example.erp.module.usr.vo.UserUpdateRespVO; | @@ -15,7 +15,14 @@ import com.example.erp.module.usr.vo.UserUpdateRespVO; | ||
| 15 | import jakarta.validation.Valid; | 15 | import jakarta.validation.Valid; |
| 16 | import lombok.RequiredArgsConstructor; | 16 | import lombok.RequiredArgsConstructor; |
| 17 | import org.springframework.security.core.annotation.AuthenticationPrincipal; | 17 | import org.springframework.security.core.annotation.AuthenticationPrincipal; |
| 18 | -import org.springframework.web.bind.annotation.*; | 18 | +import org.springframework.web.bind.annotation.GetMapping; |
| 19 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 20 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 21 | +import org.springframework.web.bind.annotation.PutMapping; | ||
| 22 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 23 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 24 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 25 | +import org.springframework.web.bind.annotation.RestController; | ||
| 19 | 26 | ||
| 20 | import java.util.List; | 27 | import java.util.List; |
| 21 | 28 |