Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Add Nx target to lint code with Checkstyle #112

Closed
tschaffter opened this issue Jun 27, 2022 · 2 comments
Closed

[Feature] Add Nx target to lint code with Checkstyle #112

tschaffter opened this issue Jun 27, 2022 · 2 comments
Labels
🆕 enhancement New feature or request

Comments

@tschaffter
Copy link

tschaffter commented Jun 27, 2022

Is your feature request related to a problem? Please describe

This feature is not related to a problem.

Describe the idea you'd like

Checkstyle is a widely adopted solution to lint Java code. It is part of the Maven CLI and can be executed with mvn checkstyle:check or ./mvnw checkstyle:check. I'm currently integrating Checkstyle to my Nx workspace with the method described below. It would be great if this Nx plugin implemented a target, e.g. named @nxrocks/nx-spring-boot:lint, to lint a project. The goal would be to enable the user to lint project with this Nx plugin without having to manually setup Checkstyle as described below.

Describe alternatives you've considered

Here is how I currently integrate Checkstyle with my Nx workspace.

  1. Add a Checksum configuration file in the root directly of the Nx workspace. I picked the default configuration file google_checks.xml used by Google. When not specifying any configuration file to Checksum, it uses its internal Sun configuration. Both Google and Sun configuration files can be found here.
  2. Add the following target to a project:
    "lint": {
      "executor": "@nrwl/workspace:run-commands",
      "options": {
        "command": "./mvnw checkstyle:check",
        "cwd": "apps/challenge-core-service"
      }
    },
  1. Add the following section to pom.xml to enable the update of Checkstyle at runtime. The current version is 10.3. Without this section, an older version of Checkstyle will run with the mvnw script provided by this GitHub repo.
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-checkstyle-plugin</artifactId>
          <version>3.1.2</version>
          <dependencies>
            <dependency>
              <groupId>com.puppycrawl.tools</groupId>
              <artifactId>checkstyle</artifactId>
              <version>10.3</version>
            </dependency>
          </dependencies>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
  1. Specify the location of the configuration file in pom.xml.
	<properties>
          <checkstyle.config.location>${basedir}/../../checkstyle.xml</checkstyle.config.location>
	</properties>

Additional context

  • The plugin should enable the user to place the Checkstyle configuration file outside of the project that uses it, e.g. in the root directory of the Nx workspace for the sake of keeping the code DRY. Hence, the plugin should allow the user to specify the location of the Checkstyle configuration file.
  • Do not make the assumption that all projects are included directly in the folders apps/ and libs/, e.g. when reading the Checkstyle configuration file. For example, in my workspace I have a project in libs/shared/data-access-x that is shared between multiple projects. I have seen this project structure in workspaces created by others too.

Thanks!

@tschaffter tschaffter added the 🆕 enhancement New feature or request label Jun 27, 2022
@tinesoft
Copy link
Owner

Hi @tschaffter (a.k.a serial issue/feature creator 😅)

In the previous major release of the plugin (v4.0.0) I've added support for formatting/linting via Spotless, which in my opinion is way superior to Checkstyle in terms of features/customizations capabilities( all JVM languages, Maven/Gradle plugins, integration with other tools, etc)

The related formatting executors are:

*nx check-format bootapp
*nx apply-format bootapp or nx do-format bootapp

Do you think that can work for you?

@tschaffter
Copy link
Author

Hi @tinesoft,

I appreciate how your plugin helped me to start developing Spring Boot apps inside with Nx. :-)

I will play with Spotless and let you know. Right now I'm battling an issue related to importing a lib in an app (see upcoming comment to #71).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants