UFO ET IT

Checkstyle에서 파일에 대한 모든 검사를 억제하는 방법은 무엇입니까?

ufoet 2021. 1. 13. 07:26
반응형

Checkstyle에서 파일에 대한 모든 검사를 억제하는 방법은 무엇입니까?


저는 써드 파티 클래스에 대한 재정의를하고 있고 모든 검사를 억제하고 싶습니다 (패치가 받아 들여질 때까지만 유지하고 있기 때문입니다).

파일에 대한 모든 검사를 억제하는 방법이 있습니까?

"*"를 사용해 보았지만 실패했습니다.


명령 줄을 사용하는지 IDE에서 사용하는지는 모르지만 기본적으로 suppresions 파일이 필요합니다. Checkstyle 구성 파일을 수동으로 편집하는 경우 새 모듈을 추가하십시오.

<module name="SuppressionFilter">
    <property name="file" value="mysuppressions.xml" />
</module>

당신이 mysuppression.xml뭔가를 할 수 있습니다 :

<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
    "-//Puppy Crawl//DTD Suppressions 1.1//EN"
    "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">

<suppressions>
    <suppress files="TheClassToIgnore\.java" checks="[a-zA-Z0-9]*"/>
</suppressions>

" files"속성 의 값 은 기본적으로 소스 파일의 정규식이고 " checks"속성 의 값은 건너 뛸 검사에 대한 정규식입니다 ( " [a-zA-Z0-9]*"는 기본적으로 모든 것을 건너 뛰는 것을 의미합니다). 이게 당신이 찾고있는 패턴이에요?


내 checks.xml에 SuppressionCommentFilter 태그를 추가하여 파일의 검사를 억제 할 수있었습니다.

먼저 FileContentHolder 태그를 TreeWalker 태그의 자식으로 추가했습니다 ( com.puppycrawl.tools:checkstyle 버전 8.1 이후 에는 이 단계가 필요 하지 않음).

<module name="TreeWalker">
    ...
    <module name="FileContentsHolder"/>
    ...
</module>

그런 다음 checks.xml에 SuppressionCommentFilter를 추가했습니다 (com.puppycrawl.tools:checkstyle의 버전 8.1부터- "TreeWalker"노드 아래).

<module name="SuppressionCommentFilter"/>

검사를 억제하려는 각 파일에서 파일의 첫 번째 줄에 다음 주석을 삽입했습니다.

// CHECKSTYLE:OFF

aberrant80의 답변은 많은 도움이되었습니다. 그의 힌트의 도움으로-정규식 패턴 일치를 사용하여 이것을 checkstyle-suppressions.xml 파일에 추가하여 전체 패키지에 대한 체크 스타일을 억제 할 수있었습니다. 예를 들어. jaxb 패키지의 모든 자동 생성 자바 파일에 대한 체크 스타일 검사를 건너 뛰려면

    <suppressions>
        <suppress checks="[a-zA-Z0-9]*" files="[\\/]jaxb[\\/]" />
    </suppressions>

Checkstyle 용 Checkclipse Eclipse 플러그인을 사용하는 경우 프로젝트 속성 아래의 Checkclipse> 파일 필터 탭으로 이동하여 파일 패턴 (디렉토리 포함)을 포함하거나 제외 할 수 있습니다. 예를 들어, 내 프로젝트에는 최상위 수준의 src테스트 디렉토리 가 포함되어 있습니다 . src 디렉터리의 파일에만 Checkstyle을 적용하고 싶기 때문에 ( test 생략 ) 다음과 같은 포함 패턴을 추가했습니다.

src/.+java$

보시다시피 패턴 사양에 정규식 스타일 구문을 사용합니다.


@ aberrant80의 대답은 내 프로젝트에서 작동하지 않았지만 매우 고무적입니다. maven이 사용되는 경우 link 에 따라 Foo.java에서 checkstyle이 찾는 경고를 억제하려면 다음을 수행 하십시오 .

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    ...
        <configuration>
            ...
            <configLocation>checkstyle.xml</configLocation>
            <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
            ...
        </configuration>                
    ...
</plugin>

And in checkstyle-suppressions.xml

<!DOCTYPE suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN" "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
    <suppress files="Foo.java" checks="[a-zA-Z0-9]*" />
</suppressions>

So far the highest version is 1.1 (1.2 does not exist).


There is an option to ignore write protected files. Or files in a package.


If you wish to not have a group of files within a project inspected, you can filter these files out so they are not inspected by creating a file filter

The file filter uses regex to determine what files to exclude. The regex operates on the complete file name - because of this, you could also exclude whole folders. In this case you could exclude the whole package if you wished.

If you google around a bit - you could probably find some Checkstyle Configuration Propertie files that have examples of what you're looking for. I would suggest after you do so - save it as a bit of a template so you can refer to it in future situations

ReferenceURL : https://stackoverflow.com/questions/1012407/how-to-suppress-all-checks-for-a-file-in-checkstyle

반응형