agentsclimarketplace

Code quality

Skill JaviCeronn/CleanCode_skill_ML-MLOps/skills/code-quality

Apply Clean Code and code-quality best practices when writing, refactoring, or reviewing Python and ML/MLOps code. Covers the SOLID principles, Clean Code rules (single-purpose functions, descriptive names, few arguments, no flag args, no side effects, polymorphism over conditionals), design patterns (Factory, Strategy, Adapter, Registry, Dependency Injection), ML-specific quality (no data leakage, reproducibility, configuration management, logging), and the tooling to enforce it (ruff, black, mypy, pytest, pre-commit). Use whenever the user asks to improve code quality, refactor, review code, apply SOLID / clean code / design patterns, remove code smells, or write production-grade Python/ML code.From its SKILL.md

Install
npx -y skills add JaviCeronn/CleanCode_skill_ML-MLOps --skill code-quality

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

9.0 KB, as published. Nobody here has run it

Code Quality — Clean Code for Python & ML/MLOps

Objective

Even when our main job is not software development, the result of our work lives largely in code. The goal is to produce code that is not only functional, but also readable, maintainable, and efficient across its whole lifecycle.

A useful (only half-joking) quality metric: WTFs per minute during code review. Fewer is better. This skill is about lowering that number.

This skill makes Claude apply these principles by default when generating, refactoring, or reviewing Python — with an ML/MLOps slant — and provides reference material to go deeper.


When to use this skill

Trigger this skill when the task involves any of:

  • Writing new Python / ML code that should be production-quality.
  • Refactoring or cleaning up existing code, or removing "code smells".
  • Reviewing a diff, PR, function, class, or notebook for quality.
  • Questions about SOLID, Clean Code, design patterns, or quality tooling.
  • Turning exploratory notebook code into a maintainable module/package.

How to apply it

When writing new code

  1. Pick clear, descriptive names; add type hints and a one-line docstring.
  2. Keep each function/class doing one thing at one level of abstraction.
  3. Keep the argument list short (≤ 2–3; group the rest into a config dataclass).
  4. Make functions pure where possible: take inputs, return new outputs, avoid mutating shared state or arguments (especially pandas DataFrames).
  5. Reach for a design pattern only when it removes real duplication or branching — not preemptively (respect YAGNI).

When reviewing code

Walk the checklist below. For each issue, name the principle it violates, show a concrete before → after, and explain why it is better. Prioritise correctness and clarity over stylistic nitpicks. Be pragmatic: a 10-line script does not need an abstract factory.

Altitude / pragmatism

Clean code is a means, not an end. Do not over-engineer:

  • Exploratory notebooks and one-off scripts have a lower bar than shipped library code.
  • Don't introduce an interface/pattern for a single implementation that will never vary.
  • Prefer the simplest design that is correct and readable (KISS). Add structure when a second concrete case actually appears, not in anticipation of one.

The golden rules (quick reference)

SOLID (OOP design — full detail in references/solid.md)

  • Single Responsibility — one reason to change per class/module.
  • Open/Closed — open to extension, closed to modification (add subclasses/strategies, don't edit a growing if/elif chain).
  • Liskov Substitution — a subtype must be usable anywhere its base type is, without surprises.
  • Interface Segregation — many small, focused interfaces beat one fat interface.
  • Dependency Inversion — depend on abstractions; inject dependencies from outside.

Clean Code (full detail in references/clean-code.md)

  • A function does one thing, at one level of abstraction.
  • Descriptive names + type hints + a short docstring. model.predict(X) beats m.run(d).
  • ≤ 2–3 arguments; group related ones into a @dataclass config object.
  • No boolean flag arguments — split into two well-named functions.
  • No hidden side effects — return new values; copy DataFrames instead of mutating in place; avoid global.
  • Avoid negative conditionals (is_string over is_not_numeric).
  • Replace branching with polymorphism when behaviour varies by a "type" string.
  • DRY — extract duplication; KISS/YAGNI — don't add what you don't need yet.
  • Guard clauses / early returns to keep nesting shallow.
  • No magic numbers — name constants. No dead code / commented-out blocks.
  • Comments explain why, not what; the code itself explains what.
  • Fail fast with specific exceptions; don't silently return None on error.

Design Patterns (full detail in references/design-patterns.md)

  • Factory (+ Registry) — create objects from config without scattering if/elif.
  • Strategy — swap interchangeable algorithms (scalers, metrics, optimisers) at runtime.
  • Adapter — wrap third-party models (sklearn, PyTorch, TF) behind one interface.
  • Dependency Injection — pass collaborators in rather than constructing them inside.

ML/MLOps quality (full detail in references/ml-code-quality.md)

  • Separate concerns: load → preprocess → train → evaluate → serve.
  • No data leakage: fit transforms on train only; use an sklearn Pipeline.
  • Reproducibility: seed everything; version data, code, and models; pin dependencies.
  • Configuration over hardcoding: no hardcoded paths/hyperparameters; use config files.
  • Log, don't print; track experiments (MLflow / W&B).

Tooling (full detail in references/tooling.md)

  • Format with black / ruff format; lint with ruff; type-check with mypy; test with pytest; automate with pre-commit. Configure it all in pyproject.toml.

Code review checklist

Use this as a structured pass over any code:

Naming & readability

  • Names reveal intent (load_dataset, not run/do/data2)?
  • Type hints on public functions and methods?
  • Docstring stating purpose (and non-obvious args/returns)?
  • Magic numbers/strings replaced by named constants/enums?
  • No commented-out code or dead branches?

Functions & classes

  • Each function does one thing at one level of abstraction?
  • ≤ 2–3 arguments (otherwise a config object)?
  • No boolean flag parameters selecting behaviour?
  • Reasonable length and nesting depth (guard clauses used)?
  • No unexpected side effects (no in-place mutation of inputs, no global)?

SOLID & structure

  • Single responsibility per class/module?
  • New variants added by extension, not by editing if/elif chains?
  • Subtypes honour their base type's contract (LSP)?
  • Depends on abstractions, with dependencies injected (DIP)?
  • No duplication that should be extracted (DRY)? No needless abstraction (YAGNI)?

Error handling & correctness

  • Fails fast with specific exceptions; no silent None/bare except?
  • No mutable default arguments (def f(x=[]))?
  • Resources closed via context managers (with)?

ML-specific

  • Transforms fit on train only — no data leakage into validation/test?
  • Randomness seeded; results reproducible?
  • Paths/hyperparameters in config, not hardcoded?
  • Logging instead of print; experiments tracked?

Tooling

  • Passes ruff/black/mypy? Covered by tests?

Reference files

Load the relevant file when you need depth or worked before/after examples:

FileContents
references/solid.mdAll five SOLID principles with Python before/after, including the LSP and ISP examples the source slides omit.
references/clean-code.mdThe full Clean Code rule set with examples and ML-flavoured cases.
references/design-patterns.mdFactory, Strategy, Adapter, Registry, Dependency Injection, Template Method — and when not to use a pattern.
references/ml-code-quality.mdData leakage, reproducibility, configuration management, logging, validation, notebooks vs. production.
references/tooling.mdruff, black, mypy, pytest, pre-commit, plus a ready-to-paste pyproject.toml and .pre-commit-config.yaml.

Sources & further reading

  • Robert C. Martin — Clean Code: A Handbook of Agile Software Craftsmanship.
  • Robert C. Martin — Agile Software Development: Principles, Patterns, and Practices (SOLID).
  • Gamma, Helm, Johnson, Vlissides — Design Patterns (GoF).
  • refactoring.guru — design patterns and refactoring catalogue.
  • PEP 8 — Style Guide for Python Code.
  • PEP 20 — The Zen of Python.
  • scikit-learn — Pipeline / ColumnTransformer for leak-free preprocessing.

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.