Clojure coding standards

From hugoduncan/psi · View interactive version

Clojure coding standards is an AI agent skill from the GitHub repository hugoduncan/psi. Comprehensive Clojure coding standards including function formatting, testing patterns, REPL workflows, dependency management, and code organization. Use whenever writing Clojure or babashka code, or tests, reviewing Clojure or babashka projects, or setting up Clojure or babashka development workflo

How to use this skill

Skill file

Clojure Coding Standards

Comprehensive Clojure coding standards for maintainable, readable code.

Core Formatting Rules

Function Structure

(defn process-data
  "Processes the input data according to business rules.
   Returns processed map with validation results."
  [data options]
  (-> data
      validate-input
      (transform-with options)
      add-metadata))

Architecture

λx.prefer(compose(transducers))∧when(working_with(sequences),thread(sequence_functions))

Dependencies

Find available versions:

clojure -T:deps find-versions :lib io.github.user/repo

For git-based dependencies:

clojure -T:deps git-resolve-tags :lib io.github.user/repo

Testing Standards

Test Organization

Test Structure Template

(deftest add-research-messages-test
  ;; Tests the add-research-messages function for proper message handling
  ;; and metadata updates according to the research workflow contract
  (testing "add-research-messages"
    (testing "appends new research messages"
      (is (= expected-messages
             (get-in result [:messages]))))
    (testing "updates the :updated-at field"
      (is (inst? (get result :updated-at))))))

Testing Best Practices

Prefer testing-without-mocks.

REPL Workflow

Discovery & Connection

# Discover running nREPL servers
clj-nrepl-eval --discover-ports

# Start nREPL server
clojure -M:nrepl:dev

# Evaluate code
clj-nrepl-eval -p <PORT> "(+ 1 2 3)"

REPL Management

;; Sync dependencies after deps.edn changes
(do (require 'clojure.repl.deps)
    (clojure.repl.deps/sync-deps))

;; Remove var binding completely
(ns-unmap *ns* 'my-var)

;; Reload namespace
(require 'my.ns :reload)

Linting

clj-kondo --lint src

Code Formatting

Parenthesis Repair

NEVER manually fix parenthesis errors.

Use the tool:

clj-paren-repair path/to/file1.clj path/to/file2.clj

The tool automatically:

Comments & Documentation

Comment Hierarchy

Required Comments

Never Comment

Docstring Format

(defn complex-calculation
  "Calculates the adjusted risk score based on market volatility.

   Returns a map with :score and :confidence-level keys.
   Throws ExceptionInfo if market-data is invalid."
  [market-data user-preferences]
  ;; Implementation here
  )

Error Reporting

For command-line error reports on stderr:

clojure -M:stderr-report

Project Organization

File Structure

Namespace Guidelines

Quick Reference Commands

# Lint codebase
clj-kondo --lint src

# Fix formatting issues
clj-paren-repair src/**/*.clj

# Start development REPL
clojure -M:nrepl:dev

# Run fast tests
clojure -M:test

# Run all tests (including slow ones)
clojure -M:test:integration

Integration with Editors

Preferred Tools

REPL Integration

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.