Giter Site home page Giter Site logo

yuokada / createyourowncheckstylecheck Goto Github PK

View Code? Open in Web Editor NEW

This project forked from blundell/createyourowncheckstylecheck

0.0 1.0 0.0 42 KB

How to write a custom CheckStyle check and incorporate it into your Maven project

Home Page: http://blog.blundellapps.com/create-your-own-checkstyle-check/

Java 100.00%

createyourowncheckstylecheck's Introduction

CreateYourOwnCheckStyleCheck

Contains two projects

  • TestProject contains the poorly written Java code that will have checkstyle ran on it

  • BlundellCheckstyle contains the custom checkstyle checks that have been written

How it works

  • TestProject uses the maven-checkstyle-plugin
  • the maven-checkstyle-plugin has a dependency on BlundellCheckStyle
  • BlundellCheckstyle is where we create the custom checks
  • the maven-checkstyle-plugin then uses a checkstyle-configuration.xml file to declare what checks we want checkstyle to run
  • within checkstyle-configuration.xml we declare our custom checks from BlundellCheckStyle

How to run checkstyle

  • from a Terminal
  • run mvn install
  • go into the TestProject folder
  • run mvn checkstyle:checkstyle
  • open up target/site/checkstyle.html to see style errors

Current Limitations

  • in checkstyle-configuration.xml we have to use the full package of the check com.blundell.checks.AntiHungarian
  • this can be fixed by declaring a checkstyle-packages.xml this currently doesn't work

checkstyle-packages.xml would looks something like this:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE checkstyle-packages PUBLIC
  "-//Puppy Crawl//DTD Package Names 1.0//EN"
  "http://www.puppycrawl.com/dtds/packages_1_0.dtd">

<checkstyle-packages>
  <package name="com.blundell.checks">
</checkstyle-packages>

and you would add it to the maven-checkstyle-plugin declaration

// There are multiple ways to try this, I haven't found one that works
// so I do not want to document it here

then your checkstyle-configuration.xml would not need the package:

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
    "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
    "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">

<module name="Checker">
  <module name="TreeWalker">
    <!-- Blundell specific checks -->
    <module name="AntiHungarian" />
  </module>
</module>

createyourowncheckstylecheck's People

Contributors

blundell avatar gnorsilva avatar dependabot[bot] avatar johnjohndoe avatar yuokada avatar

Watchers

 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.