1 of 5

Style Checking

CS 240 – Advanced Programming Concepts

2 of 5

Style Checking Overview

  • Tools can be used to compare code against a coding style standard and either report errors or reformat the code
  • Some tools are built into IDEs (like Intellij and VS Code)
  • Some tools are intended to be part of an automated build process
  • Style checker examples:
    • Checkstyle – Java, configurable, generally used as part of an automated build process but IDE plugins exist
    • Prettier – Supports many languages (often used on JavaScript, Typescript, CSS, JSON, etc), opinionated—doesn’t support many configuration options
    • Intellij Built-in Code Formatter – Java, configurable

3 of 5

Reformatting Code in Intellij

Menu: Code -> Reformat Code

  1. Reformats code selection if code is selected in an open editor
  2. Reformats all code in the currently visible open editor if no code is selected
  3. Reformats the selected class or file in the class list pane if no code is open in an editor window
  4. Reformats all code in the selected directory if a folder is selected and there is no code open in an editor window

4 of 5

Configuring the Code Formatter

  • Mac Menu: Intellij IDEA -> Settings
    • Select: Editor -> Code Style -> Java
  • Windows Menu: File -> Settings
    • Select: Editor -> Code Style -> Java

  • Multiple tabs with many options you can set/change to adjust formatting�

5 of 5

Configuring the Code Formatter (cont.)