checkstyle / checkstyle

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. By default it supports the Google Java Style Guide and Sun Code Conventions, but is highly configurable. It can be invoked with an ANT task and a command line program.
https://checkstyle.org
GNU Lesser General Public License v2.1
8.34k stars 3.67k forks source link

Create and Document Check Update Procedure for New Language Features #14889

Closed nrmancuso closed 5 months ago

nrmancuso commented 5 months ago

When we add support for new language features, we always play a guessing game of what checks should be updated. While some heuristics will always be required, we can also have a procedure to follow to at least give is some direction and confidence that we have done our due diligence to fully support new language features. Adding the ability to parse new language features is really only the beginning of what we need to do.

As we have seen in the past, it is good to follow the bug report template to aid in demonstration of need for check updates.

We can call this document "New Language Feature Check Integration Process".

We need to create a document with the following outline:

Some sources of inspiration that I have used in the past for check discovery:

  1. Consider similar tokens, i.e. for RECORD_DEF, it was reasonable to look at all checks that had CLASS_DEF in their acceptable tokens.

  2. Similar constructs. An example of this would be constructors and methods.

  3. JEPS themselves; they often have some recommendations about how to use new language features. Often times, JEPs may solve a particular problem in the language, and we can create checks to suggest to use these new features instead of the "old syntax". An example would be instanceof, where we avoid the cast by pattern matching.

  4. Whitespace checks touch on most tokens

  5. Examples in large codebases. To help facilitate this, we need to find some projects that use newer language features. Let's look through the new projects files in contribution that @Kevin222004 added last year. Example: https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/github-action-projects1.properties

  6. Review other static analysis tools (PMD, IDEA Inspections, spotbugs, etc.)

This document will live in the docs directory.

nrmancuso commented 5 months ago

@rnveach @mahfouz72 please share any additional check discovery methods that you can think of.

mahfouz72 commented 5 months ago

These are all great methods, and I believe they should be sufficient to show us where updates should be made.

please share any additional check discovery methods that you can think of.

I think finding real usage examples in large codebases will be helpful. This may guide us in identifying potential violations and areas that require to be covered by checks

rnveach commented 5 months ago

One of the first steps is to find the JEPS and JLS for the new token.

Ensure document has number/letter points to be referenced later. Some linking to them would also be good.

Some checks will always be impacted. IllegalToken.

Similar constructs

Methods and constructors as an example.

Discovery of similar checks

Left and right curly.

Review of associated JEPs

Reviewing to find pertinent information to the current JEP

mahfouz72 commented 5 months ago

another good method is to review similar static code analysis tools and IDE inspection rules for new features it may help us to identify potential check updates.

nrmancuso commented 5 months ago

@rnveach please add "approved" label if you are good