Giter Club home page Giter Club logo

checkstyle-annotation-filter's Introduction

GitHub Workflow Status GitHub release (latest SemVer) GitHub

Filter Checkstyle violations to remove elements annotated with a given set of annotations.

This was primarily designed so that classes or methods marked as @Deprecated will not throw violations - there's no point refactoring something already marked for removal.

Dependency

The dependency is available from jitpack.io.

<dependency>
    <groupId>com.github.michaelboyles</groupId>
    <artifactId>checkstyle-annotation-filter</artifactId>
    <version>1.0.1</version>
</dependency>

and, for example

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

Usage

The filter consists of two elements

  1. AnnotationCheck: a "check" which records which violations are annotated with the annotations you have specified
  2. AnnotationFilter: a filter which queries the state of the "check" to decide whether or not to include the violation

Your Checkstyle configuration must include both of these, for example:

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
    "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
    "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
    <module name="TreeWalker">
        <module name="TypeName"/>
        <module name="MethodLength"/>
        <module name="MethodName" />
        <module name="FinalLocalVariable" />
        <!-- more checks -->
        
        <module name="com.github.michaelboyles.checkstyle.annotationfilter.AnnotationFilter">
            <property name="class" value="Deprecated"/>
            <property name="class" value="SuppressWarnings"/>
        </module>
    </module>
    <module name="com.github.michaelboyles.checkstyle.annotationfilter.AnnotationCheck" />
</module>

Currently the filter just takes a class name, so there is no way to differentiate between two annotations with the same name in different packages.

The library JAR file must then be included on the classpath when Checkstyle runs. If you were running from the command line, it may look like this:

java -classpath checkstyle-8.14-all.jar:checkstyle-annotation-filter-1.0.jar com.puppycrawl.tools.checkstyle.Main -c checkstyle_rules.xml test.java

License

This code was mostly adapted from SuppressWarningsFilter and SuppressWarningsHolder in Checkstyle, so is available under the same license: LGPLv2.1

checkstyle-annotation-filter's People

Contributors

michaelboyles avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.