Skip to content

Shear

Shear is a structural formatter.

Core trick

Applies deterministic AST rewrites that remove redundant else, elif, and nested-if structure in Python and JavaScript without changing behavior.

Tags

Description

Shear is a structural formatter. It simplifies code by removing unnecessary nesting, redundant branches, and duplicated logic without changing behavior. It currently supports Python and JavaScript, with a broader goal of automating structural cleanup across languages. It works alongside tools like Ruff and can simplify code their autofixes leave unchanged.
nijaru/shear★ 00 forksRustCreated Sep 8, 2026 · last push Sep 9, 2026

README excerpt

# Shear

[![Check](https://github.com/nijaru/shear/actions/workflows/check.yml/badge.svg)](https://github.com/nijaru/shear/actions/workflows/check.yml)

A deterministic, offline structural formatter for Python and JavaScript.

Shear removes mechanically unnecessary control structure — redundant `else` branches, nested conditions, duplicated branch tails — while preserving behavior. It runs locally with no model or API key, like any other formatter. Use it after editing code, then run your native formatter, linter, and tests.

## Rules

| Rule | Rewrites | Python | JavaScript |
|---|---|---|---|
| `redundant-else` | `else` after a branch that always returns, raises, breaks, or continues | Yes | Yes |
| `redundant-elif` | `elif` after an exiting branch | Yes | — |
| `merge-nested-if` | an `if` that is the only statement of another `if` | Yes | Yes |
| `guard-clause` | an exiting `else` into an early guard clause | Yes | Yes |
| `shared-branch-tail` | identical trailing statements from both branches, moved after the conditional | Yes | — |

Rules compose to a fixed point, so a `redundant-else` can expose a `merge-nested-if` on the next pass. Each rule owns its own safety conditions; uncertain cases are skipped rather than guessed. Per-rule contracts are in [docs/RULES.md](docs/RULES.md).

## Install

Requires a recent stable Rust toolchain (edition 2024; development is checked with Rust 1.98).

```sh
cargo install --path .
```

Or build in place:

```sh
cargo build --release
./t

Team