Git Product home page Git Product logo

java-checkstyle's Introduction

java-checkstyle

Klaviyo's Java Checkstyle config based on Google's

Installation

Gradle

Integrating Klaviyo's Checkstyle config into a gradle project is a little more involved, but can be accomplished with a custom task and defining that custom task as a dependency of the checkstyle task.

# gradle.properties
checkstyleXmlUrl=https://raw.githubusercontent.com/klaviyo/java-checkstyle/master/checkstyle.xml
checkstyleConfigDir=config/checkstyle
checkstyleLocalPath=config/checkstyle/checkstyle.xml
# NOTE: in theory the above 2 values for checkstyle dir/path are configurable,
#       however they are here to document the default values because I was not
#       able to get the checkstyle gradle plugin to accept any other values.
// build.gradle
task lint(type: GradleBuild) {
    tasks = ['getCheckstyle', 'checkstyleMain']
}

// NOTE: this line is required to make checkstyle not go crazy linting generated source files
checkstyleMain.source = "src/main/java"

task getCheckstyle {
    doLast {
        // check if the config dir was created yet
        def checkstyleConfigDir = new File(checkstyleConfigDir)
        if (!checkstyleConfigDir.exists() && !checkstyleConfigDir.mkdirs()) {
            throw new StopActionException("failed to create directory ${checkstyleConfigDir}")
        }
        if (!checkstyleConfigDir.with { isDirectory() && canRead() && canExecute() }) {
            throw new StopActionException("failed to access directory ${checkstyleConfigDir}")
        }

        // save the remote file down if it doesn't exist
        def checkstyleConfig = new File(checkstyleLocalPath)
        if (!checkstyleConfig.exists()) {
            println "Downloading ${checkstyleXmlUrl}"
            checkstyleConfig << new URL(checkstyleXmlUrl).getText()
        }
    }
}
tasks.checkstyleMain.dependsOn('getCheckstyle')
tasks.checkstyleTest.dependsOn('getCheckstyle')

Maven

To integrate Klaviyo's Checkstyle configuration into a maven build, add the following to your project's pom.xml

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <configLocation>
            https://raw.githubusercontent.com/klaviyo/java-checkstyle/master/checkstyle.xml
          </configLocation>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>8.11</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>

IntellijIDEA

  • Install the checkstyle plugin from the plugin browser or from github
  • Once installed, open settings and navigate to Other Settings > Checkstyle
  • Check Treat Checkstyle errors as warnings so you can distinguish between actual java syntax errors and simple linting errors
  • Hit the plus button on the right side of the settings window to add a new configuration file and select file from HTTP. Make sure you use the raw content link, not the prettified HTML view link.

java-checkstyle's People

Contributors

gregflynn avatar paulangton avatar willcummings avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.