Skip to content

[Feature] Create a .clang-format configuration file for the code Auto-formatter #54

Description

@RomanAlexandroff

Description

Arduino IDE 2.3.10's Auto Format feature (Ctrl/Cmd+T) uses ClangFormat under the hood. Currently the project relies on the IDE's default formatting style, which does not match the formatting rules required by The Norm Version 3 (42 School coding standard).

We need a project-local .clang-format file so that Auto Format produces Norm-compliant output for everyone working on this project, without each contributor having to change their own global IDE settings.


Goal

Create a .clang-format file, placed at the root of the sketch/project, that:

  • Applies to .ino files
  • Applies to .cpp files
  • Applies to .h files
  • Mirrors the formatting rules described in The Norm Version 3 as closely as ClangFormat's option set allows (indentation, brace placement, spacing, line length, etc.)
  • Is committed to the repository root so the Arduino IDE picks it up automatically (a sketch-root .clang-format takes precedence over any global configuration)

Notes / Constraints

  • A custom .clang-format file completely overrides Arduino's default configuration rather than merging with it. Any option not explicitly set will fall back to ClangFormat's own default, not Arduino's default — so double check every relevant option is set explicitly rather than assuming it inherits sane Arduino defaults.
  • Since The Norm has some rules ClangFormat cannot express 1:1 (e.g. certain 42-specific naming or structural rules), those gaps should be listed explicitly in the PR description so reviewers know what still needs manual checking.
  • You absolutely may use AI for completing this task, but test that the result works as intended before submitting a Pull Request.

Reference: Arduino's own default .clang-format

Use this as the starting point rather than an empty file, then adjust options to match The Norm v3:

https://raw.githubusercontent.com/arduino/tooling-project-assets/main/other/clang-format-configuration/.clang-format


Reference: Arduino default config file location on disk

For comparison / testing against what the IDE uses out of the box (embedded/global default), the relevant Arduino config and data folders are:

OS Config folder (.arduinoIDE) Data folder (Arduino15)
macOS ~/.arduinoIDE ~/Library/Arduino15
Windows C:\Users\<username>\.arduinoIDE C:\Users\<username>\AppData\Local\Arduino15
Ubuntu / Linux ~/.arduinoIDE ~/.arduino15

A global .clang-format placed in either the config or data folder above is used whenever no sketch-local .clang-format is present. For this project we want the file at the sketch root, since that takes precedence over any global configuration.


Reference: Arduino tutorial

Official step-by-step guide — "Customizing the Auto Formatter Feature":

https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-customize-auto-formatter


Acceptance Criteria

  • .clang-format file exists at the project/sketch root
  • Running Auto Format (Ctrl/Cmd+T) on a .ino, .cpp, and .h file each produces output matching The Norm v3
  • File is documented (short comment header or README note) explaining it's derived from Arduino's default and tailored to The Norm v3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions