YouShAllNotPass는 우아한 코드를위한 정적 분석기입니다.
겉보기에 평범한 코드에서 찾을 수있는 것 :
package com . example ;
import java . util . Collection ;
import java . util . StringTokenizer ;
public class Words {
public static final String DELIM = " ,." ;
private Collection < String > words ;
public Words () {
this . words = null ;
}
public Words ( Collection < String > words ) {
this . words = words ;
}
boolean containsIn ( String text ) {
if ( words == null ) return false ;
StringTokenizer tokenizer = new StringTokenizer ( text , DELIM );
while ( tokenizer . hasMoreTokens ()) {
String nextWord = tokenizer . nextToken ();
if ( words . contains ( nextWord )) return true ;
}
return false ;
}
}YouShAllNotPass 분석의 위반 :
nullfree
com.example.Words(Words.java:12) > null
com.example.Words.containsIn(Words.java:20) > null
staticfree
com.example.A.main(A.java:6) > static
com.example.Words(Words.java:7) > static
allfinal
com.example.A.main(A.java:6) > String[] args
com.example.A(A.java:5) > A
com.example.Words(Words.java:9) > words
com.example.Words.containsIn(Words.java:22) > StringTokenizer tokenizer = new StringTokenizer(text, DELIM)
com.example.Words.containsIn(Words.java:24) > String nextWord = tokenizer.nextToken()
com.example.Words(Words.java:15) > Collection<String> words
com.example.Words.containsIn(Words.java:19) > String text
com.example.Words(Words.java:6) > Words
allpublic
com.example.Words.containsIn(Words.java:19)
nomultiplereturn
com.example.Words.containsIn(Words.java:19)
플러그인을 루트 build.gradle 에 추가하십시오
plugins {
id ' dev.youshallnotpass ' version ' x.y.z '
}
// then configure it, if you need:
youshallnotpass {
offline = true // default false
nullfree {
disabled = true // default false
threshold = 3 // default 0
skipComparisons = true // default false
}
staticfree {
disabled = true // default false
threshold = 2 // default 0
}
allfinal {
disabled = true // default false
threshold = 1 // default 0
skipInterfaceMethodParams = false // default true
skipLambdaParams = true // default false
skipCatchParams = true // default false
}
allpublic {
disabled = true // default false
threshold = 4 // default 0
}
setterfree {
disabled = true // default false
threshold = 5 // default 0
}
nomultiplereturn {
disabled = true // default false
threshold = 6 // default 0
}
inheritancefree {
disabled = true // default false
threshold = 7 // default 0
}
} 여기서 xyz Gradle 플러그인의 실제 버전입니다
호출 :
./gradlew youshallnotpass pom.xml 에 플러그인을 추가하십시오
< plugin >
< groupId >dev.youshallnotpass</ groupId >
< artifactId >youshallnotpass-maven-plugin</ artifactId >
< version >x.y.z</ version >
<!-- then configure it, if you need: -->
< configuration >
< offline >true</ offline > <!-- default false -->
< nullfree >
< disabled >true</ disabled > <!-- default false -->
< threshold >3</ threshold > <!-- default 0 -->
< skipComparisons >true</ skipComparisons > <!-- default false -->
</ nullfree >
< staticfree >
< disabled >true</ disabled > <!-- default false -->
< threshold >2</ threshold > <!-- default 0 -->
</ staticfree >
< allfinal >
< disabled >true</ disabled > <!-- default false -->
< threshold >1</ threshold > <!-- default 0 -->
< skipInterfaceMethodParams >false</ skipInterfaceMethodParams > <!-- default true -->
< skipLambdaParams >true</ skipLambdaParams > <!-- default false -->
< skipCatchParams >true</ skipCatchParams > <!-- default false -->
</ allfinal >
< allpublic >
< disabled >true</ disabled > <!-- default false -->
< threshold >4</ threshold > <!-- default 0 -->
</ allpublic >
< setterfree >
< disabled >true</ disabled > <!-- default false -->
< threshold >5</ threshold > <!-- default 0 -->
</ setterfree >
< nomultiplereturn >
< disabled >true</ disabled > <!-- default false -->
< threshold >6</ threshold > <!-- default 0 -->
</ nomultiplereturn >
< inheritancefree >
< disabled >true</ disabled > <!-- default false -->
< threshold >7</ threshold > <!-- default 0 -->
</ inheritancefree >
</ configuration >
</ plugin >호출 :
mvn youshallnotpass:youshallnotpass 여기서 xyz Maven Central의 실제 버전입니다
✅ nullfree ( null 이 나쁜 이유는 무엇입니까?) 우아한 코드는 null 키워드를 사용해서는 안됩니다.
staticfree ( static 나쁜 이유는 무엇입니까?) 우아한 코드는 static 키워드를 사용해서는 안됩니다.
✅ 모든 클래스, 모든 필드, 모든 인수, 모든 지역 변수는 우아한 코드에서 final 이어야합니다.
InstanceOffree [in progress] 우아한 코드는 instanceof 인스턴스를 사용해서는 안됩니다.
✅ 상속 식 무료 우아한 코드는 클래스 상속을 사용해서는 안됩니다 (한 클래스가 다른 클래스를 다른 클래스를 extends 때) 구성 및 유형 상속 만 허용됩니다.
열거적인 [in progress] 우아한 코드는 enum 를 사용해서는 안됩니다.
스위치 프리 [in progress] 우아한 코드는 switch 블록/표현식을 사용해서는 안됩니다.
✅ Nomultiplereturn Elegant Code는 어떤 방법 으로든 반품 한 명 (또는 아무도 없음) 만 포함해야합니다.
getterfree [in progress] 우아한 코드는 getters를 포함해서는 안됩니다.
setterfree 우아한 코드에는 세터가 포함되어서는 안됩니다
AllPublic Elegant Code는 public 방법 만 사용해야합니다
NopublicMethodnotOverrides [in progress] 우아한 코드의 모든 공개 방법은 인터페이스에서 과대 평가되어야합니다.
플러그인 구성 옵션 :
skipComparisons 부울 표현식에서 null 사용할 수 있습니다. if ( some == null ) {
...
} @SuppressWarnings("nullfree") 에 의해 코드에서 억제 될 수 있습니다.
@SuppressWarnings("staticfree") 에 의해 코드에서 억제 될 수 있습니다.
플러그인 구성 옵션 :
skipInterfaceMethodParams 인터페이스 메소드 매개 변수 final S를 제한하거나 없을 수 있습니다. 기본적으로 그러한 장소에 대한 final 설정이 필요하지 않습니다.skipLambdaParams Lambda 매개 변수의 Skip final 허용합니다. 기본적으로 Lambda 매개 변수는 final 이어야합니다.skipCatchParams catch 매개 변수에서 Skip final 허용합니다. 기본적으로 catch 매개 변수는 final 이어야합니다. @SuppressWarnings("allfinal") 에 의해 코드에서 억제 될 수 있습니다.
@SuppressWarnings("allpublic") 에 의해 코드에서 억제 될 수 있습니다.
@SuppressWarnings("setterfree") 에 의해 코드에서 억제 될 수 있습니다.
@SuppressWarnings("nomultiplereturn") 에 의해 코드에서 억제 될 수 있습니다.
@SuppressWarnings("inheritancefree")
offline = true 설정없이 YouShAllNotPass 플러그인을 사용하는 경우 검사 배지를 ReadME 파일에 첨부 할 수 있습니다.
 모든 검사는 threshold 으로 구성 할 수 있습니다.
gradle 에서
youshallnotpass {
.. .
staticfree {
threshold = 19
}
.. .
} maven 에서
< configuration >
< staticfree >
< threshold >19</ threshold >
</ staticfree >
</ configuration > 모든 검사는 disabled 설정으로 비활성화 할 수 있습니다.
gradle 에서
youshallnotpass {
.. .
staticfree {
disabled = true
}
.. .
} maven 에서
< configuration >
< staticfree >
< disabled >true</ disabled >
</ staticfree >
</ configuration >모든 검사는 기본적으로 활성화됩니다.
글로벌 exclude 설정이 있으며, 이는 패턴 제외를 정의하는 데 사용할 수 있습니다 : in gradle
youshallnotpass {
exclude = [ " glob:**/test/**/*Test.java " ]
} maven 에서
< configuration >
< exclude >glob:**/test/**/*Test.java</ exclude >
</ configuration >검사 로컬 제외 구성 옵션이 있습니다.이 옵션은 글로벌 제외 구성보다 우선 순위가 높습니다.
gradle 에서
nullfree {
exclude = [ " glob:**/*SomeBadFile.java " ]
} maven 에서
< nullfree >
< exclude >glob:**/*SomeBadFile.java</ exclude >
</ nullfree >MIT