--- title: "Jam 02 - Exercise 1.5 - Code Style Configuration" tags: - 3 🧪 in testing - 4 🥳 done - jam02 - code style - tools --- <!-- markdownlint-disable line-length single-h1 no-inline-html --> <!-- markdownlint-configure-file { "ul-indent": { "indent": 4 }, "link-fragments": {"ignore_case": true} } --> # Exercise 1.5 - Code Style Configuration {%hackmd dJZ5TulxSDKme-3fSY4Lbw %} ## Overview - Exercise 1.5 Professional code isn't just about functionality—it's also about readability and maintainability. In this exercise, you'll configure IntelliJ to enforce consistent code style using checkstyle, a tool that helps maintain Java coding standards. We're introducing checkstyle early in the course because good coding style is a habit best developed from the start. The style rules will evolve as you progress through the jams—we'll start with basic formatting and gradually introduce more sophisticated requirements as you learn new Java concepts. For now, we'll focus on your main source files, but in future jams, we'll expand this to include proper test file organization and documentation as you learn about unit testing in Java. ## Required Steps - Checkstyle Setup 1. **Install the Checkstyle Plugin** - Open IntelliJ IDEA preferences/settings (Ctrl+Alt+S) - Go to Plugins - Search for "CheckStyle-IDEA" - Install the plugin - Restart IntelliJ when prompted 2. **Configure Checkstyle** - Return to IntelliJ preferences/settings - Navigate to Tools → Checkstyle - Under "Configuration File": - Click the [+] button to add a new configuration - Description: "CSCI 205 Style" - Select "Use a checkstyle file accessible via HTTP" - Enter URL: `https://eg.bucknell.edu/~csci205/2025-spring/checkstyle.xml` - Under "Scope" (when adding the configuration): - Select "Project Files" - Click "Next" and then "Finish" - Under "Scan Scope" (in main settings): - Select "Only Java sources (including tests)" - This ensures checkstyle runs on both your source code and future test files - Make sure your new configuration is checked/active - Click "Apply" 3. **Enable Real-Time Scanning** - Still in the Checkstyle settings - Check "Treat Checkstyle errors as warnings" - Click "Apply" ![image](https://hackmd.io/_uploads/BkS7prKdJg.png) - Go to File → Settings → Editor → Inspections - Search for "Checkstyle" - Make sure the checkbox next to "Checkstyle real-time scan" is enabled - Click "Apply" and "OK" ![Settings for editor then inspections](https://hackmd.io/_uploads/BkAt2SFdJl.png) :::info 🔑 **Understanding Style Rules** Our checkstyle configuration enforces: - Proper indentation (4 spaces) - Meaningful variable names - Required Javadoc comments - Consistent brace placement - Maximum line length - And many other professional coding standards You can see style violations in IntelliJ as yellow underlines (warnings). ::: 4. **Verify Configuration** - Open any Java file in your project - Right-click in the editor - Select "Check Current File" - You should see style warnings if any rules are violated :::warning 🚧 **Important Style Notes** - Fix style issues as you code, don't wait until the end - Use IntelliJ's auto-format (⌘⌥L on Mac, Ctrl+Alt+L on Windows) to fix many issues automatically - Some style rules (like meaningful names) require manual fixes - All code submissions must pass checkstyle verification ::: ## Save Your Work - Exercise 1.5 While this is primarily a configuration exercise, there are important files to commit: 1. Commit the IntelliJ configuration files: - The `.idea/checkstyle-idea.xml` file contains your checkstyle settings - Stage and commit this file to preserve your configuration 2. Verify your configuration is properly saved by: - Closing IntelliJ completely - Reopening your project - Verifying checkstyle is still configured and active :::info 🔍 **Why Commit Configuration?** - Committing IDE configuration ensures consistent style checking across all team members - It helps maintain code quality standards throughout the project - New team members can immediately follow the same style guidelines :::