Coding Standards
Automate and integrate Coding Standards for uniform and maintainable codebases
Coding Standards is an AI skill that defines, documents, and enforces consistent code style and quality rules across development teams. It covers naming conventions, formatting rules, architectural guidelines, linter configuration, and automated enforcement that enable teams to maintain readable and maintainable codebases.
What Is This?
Overview
Coding Standards provides structured approaches to establishing and enforcing code quality conventions. It handles defining naming conventions for variables, functions, classes, and files, specifying formatting rules for indentation, line length, and bracket placement, establishing architectural guidelines for module organization and dependency direction, configuring linters and formatters to enforce rules automatically, documenting standards in accessible references for team onboarding, and integrating enforcement checks into CI pipelines for pre-merge validation.
Who Should Use This
This skill serves tech leads establishing conventions for new projects, teams adopting consistent standards across multiple repositories, senior developers writing style guides for team reference, and organizations standardizing practices across engineering departments.
Why Use It?
Problems It Solves
Without standards, code style varies between developers, making reviews focus on formatting rather than logic. Inconsistent naming conventions force developers to guess conventions when reading unfamiliar modules. Undocumented patterns lead to repeated debates about the same style choices. Manual style enforcement in reviews is inconsistent and wastes reviewer time.
Core Highlights
Automated enforcement through linters catches violations before code reaches review. Documented conventions eliminate recurring debates about style preferences. CI integration ensures all merged code complies with established standards. Onboarding references help new team members adopt conventions quickly.
How to Use It?
Basic Usage
from dataclasses import dataclass, field
@dataclass
class NamingRule:
element: str
pattern: str
example: str
@dataclass
class CodingStandard:
language: str
naming_rules: list = field(default_factory=list)
formatting: dict = field(default_factory=dict)
guidelines: list = field(default_factory=list)
python_standard = CodingStandard(
language="Python",
naming_rules=[
NamingRule("variables", "snake_case", "user_count"),
NamingRule("functions", "snake_case", "get_user_by_id"),
NamingRule("classes", "PascalCase", "UserService"),
NamingRule("constants", "UPPER_SNAKE", "MAX_RETRIES"),
NamingRule("modules", "snake_case", "user_service.py")
],
formatting={
"indent": 4,
"max_line_length": 88,
"quotes": "double",
"trailing_comma": True
},
guidelines=[
"Prefer composition over inheritance",
"Keep functions under 30 lines",
"Use type hints for public interfaces"
]
)
for rule in python_standard.naming_rules:
print(f"{rule.element}: {rule.pattern} (e.g. {rule.example})")Real-World Examples
import re
import json
class StandardsChecker:
PATTERNS = {
"snake_case": re.compile(r'^[a-z][a-z0-9_]*$'),
"PascalCase": re.compile(r'^[A-Z][a-zA-Z0-9]*$'),
"UPPER_SNAKE": re.compile(r'^[A-Z][A-Z0-9_]*$')
}
def __init__(self, standard):
self.standard = standard
self.violations = []
def check_naming(self, name, element_type):
rule = next(
(r for r in self.standard.naming_rules
if r.element == element_type), None
)
if not rule:
return True
pattern = self.PATTERNS.get(rule.pattern)
if pattern and not pattern.match(name):
self.violations.append({
"name": name,
"expected": rule.pattern,
"element": element_type
})
return False
return True
def check_line_length(self, lines):
max_len = self.standard.formatting.get(
"max_line_length", 88
)
for i, line in enumerate(lines, 1):
if len(line) > max_len:
self.violations.append({
"line": i,
"length": len(line),
"max": max_len
})
def report(self):
if not self.violations:
return "All checks passed"
lines = [f"Found {len(self.violations)} violations:"]
for v in self.violations:
lines.append(f" {json.dumps(v)}")
return "\n".join(lines)
checker = StandardsChecker(python_standard)
checker.check_naming("getUserById", "functions")
checker.check_naming("UserService", "classes")
checker.check_line_length(["x" * 100, "short line"])
print(checker.report())Advanced Tips
Start with an auto-formatter to handle style automatically, then layer linter rules for conventions that formatters cannot enforce. Use baseline files to suppress existing violations when adopting standards on legacy projects, enforcing rules only on new code. Publish standards as a shared linter configuration package for consistent enforcement across repositories.
When to Use It?
Use Cases
Use Coding Standards when establishing conventions for new projects or teams, when onboarding developers who need a reference for project patterns, when configuring automated enforcement through linters and CI pipelines, or when auditing existing codebases for consistency.
Related Topics
ESLint and Prettier configuration, Python Black and Ruff formatters, EditorConfig setup, pre-commit hook automation, and style guide documentation practices complement coding standards.
Important Notes
Requirements
Team agreement on core conventions. Linter and formatter tools for the target language. CI pipeline access for automated enforcement.
Usage Recommendations
Do: automate formatting and style checks to remove manual enforcement burden from reviewers. Document the rationale behind each convention so developers understand the reasoning. Start with widely accepted community standards and customize only where necessary.
Don't: enforce standards so strictly that developer productivity suffers from trivial violations. Adopt every possible rule at once, which overwhelms teams with compliance effort. Change conventions frequently, as constant updates create churn and confusion.
Limitations
Linters enforce syntax-level rules but cannot evaluate design quality or architectural decisions. Automated formatting may conflict with intentional alignment in specific code sections. Standards must balance consistency with practical flexibility for edge cases.
More Skills You Might Like
Explore similar skills to enhance your workflow
Root Cause Tracing
Systematically trace bugs backward through call stack to find original trigger
Spec Driven Workflow
Use when the user asks to write specs before code, define acceptance criteria, plan features before implementation, generate tests from specifications
Azure Deployment Preflight
azure-deployment-preflight skill for programming & development
Configuring TLS 1.3 for Secure Communications
TLS 1.3 (RFC 8446) is the latest version of the Transport Layer Security protocol, providing significant improvements
Remember Interactive Programming
remember-interactive-programming skill for programming & development
Expo UI Jetpack Compose
Build native Android UI components with Jetpack Compose in Expo projects