Skip to content

Code Style

Language-agnostic and language-specific formatting rules for consistent, readable code. Each subdirectory covers a distinct language or concern.

Scope: fix everything in files you touch

Leave every file better than you found it. When you modify a file for any reason — even a one-line change — you are responsible for fixing all true-positive lint issues in that file. It does not matter whether you introduced the issue. If you touched the file, you fix it. No exceptions. Do not wait for the user to ask.

Process

When applying code style to a file, follow this process exactly:

  1. Run the linter on the file.
  2. Pick one problem. Don't plan ahead or think about other problems. You can be systematic about which kinds of problems to focus on first, but don't think beyond the very next problem to fix.
  3. Attempt to fix it.
  4. Run the linter again to verify your fix. If the problem is gone, go back to step 2. If it's still there, keep attempting to fix it until the linter confirms it's resolved before moving on.
  5. Repeat until all fixable problems are resolved.

Do not skip the linter or assume the code is correct without running it. Do not batch fixes — fix one problem at a time and verify each fix before moving on.

sh
node skills/code-style/lint/lint.js <file>

The linter routes by file extension to the appropriate language linter. Universal rules (tabs, line length) run on all matched files. Language-specific rules (ternary formatting, no-var, single quotes, etc.) run via tree-sitter AST analysis.

Topics

  • Code Style: Language-agnostic formatting rules — indentation, line length, braces, trailing commas, and comments. Use when writing or modifying any code file.
  • Bash Style: Bash script formatting including clean multiline strings with strip_indent. Use when writing or modifying bash scripts.
  • CSS Style: CSS formatting rules including one property per line. Use when writing or modifying CSS.
  • HTML Style: HTML formatting rules including boolean attributes. Use when writing or modifying HTML.
  • JavaScript Style: JavaScript formatting rules — double quotes, trailing commas, and consistent syntax. Use when writing or modifying JavaScript.
  • Markdown Style: Markdown formatting rules — backticks for code, reference-style links, and line length. Use when writing or modifying markdown.
  • Adding a New Rule: How to add a new lint rule — capture examples, write fixtures, implement the rule, register it. Use when the user identifies a new style rule to enforce.

See also

  • Writing Style: Prose formatting rules for comments, documentation, and technical writing.