Skip to content

Commit

Permalink
docs: đź“ť Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanderleek committed Dec 10, 2024
1 parent 4ff08db commit f95f54d
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 123 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,4 @@
# Quickstart

Depending on your development workflow, Code Limit can run as:

- [Pre-commit hook](#pre-commit-hook)
- [GitHub Action](#github-action)
- Standalone
- [Homebrew](#homebrew-install)
- [Pipx](#pipx-install)
- [Pypi](#pypi-install)
- [Platform binary](#platform-binaries)

## Pre-commit hook

Code Limit can be installed as a [pre-commit](https://pre-commit.com/) hook so
it alarms you during development when it's time to refactor:

```yaml
- repo: https://github.com/getcodelimit/codelimit
rev: 0.6.2
hooks:
- id: codelimit
```
Code Limit is intended to be used alongside formatting, linters and other hooks
that improve the consistency and quality of your code (such as
[Black](https://github.com/psf/black),
[Ruff](https://github.com/astral-sh/ruff) and
[MyPy](https://github.com/python/mypy).) As an example pre-commit configuration
see the
[`pre-commit-config.yaml`](https://github.com/getcodelimit/codelimit/blob/main/.pre-commit-config.yaml)
from Code Limit itself.

When running as a hook, Code Limit *warns* about functions that *should* be
refactored and *fails* for functions that *need* to be refactord.
# Development workflow

## GitHub Action

Expand All @@ -47,55 +13,46 @@ your GH Action workflow:

```yaml
name: 'main'

on:
push:
branches: main
branches:
- main
pull_request:
branches: main
branches:
- main

jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v2
- name: 'Run Code Limit'
uses: getcodelimit/codelimit-action@main
```

## Standalone

Code Limit can also run as a standalone program.

### Homebrew install

Code Limit is available on
[Homebrew](https://formulae.brew.sh/formula/codelimit):

```shell
brew install codelimit
```

### Pipx install

To install the standalone version of Code Limit in an isolated Python
environment using [pipx](https://pypa.github.io/pipx) run:

```
pipx install codelimit
- name: 'Run Code Limit'
uses: getcodelimit/codelimit-action@v1
```
### PyPi install
## Pre-commit hook
To install the standalone version of Code Limit for your default Python
installation run:
Code Limit can be installed as a [pre-commit](https://pre-commit.com/) hook so
it alarms you during development when it's time to refactor:
```shell
python -m pip install codelimit
```yaml
- repo: https://github.com/getcodelimit/codelimit
rev: 0.6.2
hooks:
- id: codelimit
```
### Platform binaries

Binaries for different platforms (macOS, Linux, Windows) are available on the
[latest release
page](https://github.com/getcodelimit/codelimit/releases/latest).
Code Limit is intended to be used alongside formatting, linters and other hooks
that improve the consistency and quality of your code (such as
[Black](https://github.com/psf/black),
[Ruff](https://github.com/astral-sh/ruff) and
[MyPy](https://github.com/python/mypy).) As an example pre-commit configuration
see the
[`pre-commit-config.yaml`](https://github.com/getcodelimit/codelimit/blob/main/.pre-commit-config.yaml)
from Code Limit itself.

When running as a hook, Code Limit *warns* about functions that *should* be
refactored and *fails* for functions that *need* to be refactord.
43 changes: 40 additions & 3 deletions docs/usage.md → docs/getting-started/standalone-usage.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Standalone Usage

## Installation

### Homebrew

Code Limit is available on
[Homebrew](https://formulae.brew.sh/formula/codelimit):

```shell
brew install codelimit
```

### Pipx

To install the standalone version of Code Limit in an isolated Python
environment using [pipx](https://pypa.github.io/pipx) run:

```
pipx install codelimit
```

### PyPi

To install the standalone version of Code Limit for your default Python
installation run:

```shell
python -m pip install codelimit
```

### Platform binaries

Binaries for different platforms (macOS, Linux, Windows) are available on the
[latest release
page](https://github.com/getcodelimit/codelimit/releases/latest).

## Usage

Run Code Limit without arguments to see the usage page:

```shell
Expand All @@ -23,7 +60,7 @@ $ codelimit
╰──────────────────────────────────────────────────────────────────────────────╯
```

## Scanning a codebase
### Scanning a codebase

To scan a complete codebase run:

Expand All @@ -33,7 +70,7 @@ codelimit scan path/to/codebase

<div id="scan.cast" style="z-index: 1; position: relative;"></div>

## Viewing a report
### Viewing a report

To view the report with hard-to-maintain and unmaintainable functions of a
codebase that was scanned before run:
Expand All @@ -47,7 +84,7 @@ codebase that was scanned before run:
}
</script>

## Checking files
### Checking files

To check a single file or list of files for functions that need refactoring,
run:
Expand Down
94 changes: 51 additions & 43 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
# Introduction
<div align="center">
<img src="assets/logo.png"/>
</div>

<p align="center">
<em>Your Refactoring Alarm</em>
</p>

<div align="center">
<a href="https://github.com/getcodelimit/codelimit/blob/_codelimit_reports/main/codelimit.md" target="_blank">
<img src="https://github.com/getcodelimit/codelimit/blob/_codelimit_reports/main/badge.svg?raw=true" alt="Badge" class="off-glb">
</a>
</div>

No developer writes unmaintainable code on purpose, yet a lot of code is unmaintainable.

How does that happen?

Actually, most code start out easy, but over time it becomes harder to
maintain, until it's unmaintainable.

## How to prevent unmaintainable code?

The best way to prevent unmaintainable code is to refactor it before it becomes
unmaintainable.

Developers can make simple things complex, like unmaintainable code, but they
are much better at making complex things simple. Refactoring makes complex code
simple again.

But when to refactor? How much to refactor? What to refactor? That's where Code Limit comes in.

## Meet Code Limit

Code Limit is a tool for developers with one goal: _it tells the developer when
it’s time to refactor_.

Code Limit measures the lines of code for each function in your codebase and
assigns each function to a category:

| Easy | Verbose | Hard-to-maintain <span style="color: #e5832f;">&#x26A0;</span> | Unmaintainable <span style="color: #ff0000;">&#x2716;</span> |
| :---: | :---: | :---: | :---: |
| 1 - 15 lines of code | 16 - 30 lines of code | 31 - 60 lines of code | 60+ lines of code |
| ![](assets/easy.png){: style="height:136px;width:230px"} | ![](assets/verbose.png){: style="height:189px;width:230px"} | ![](assets/hard-to-maintain.png){: style="height:294px;width:230px"} | ![](assets/unmaintainable.png){: style="height:564px;width:230px"} |

As the table above shows, functions with more than 60 lines of code (comments
and empty lines are not counted) are _unmaintainable_, and _need_ to be
refactored. Functions with more than 30 lines of code run a risk of turning
into unmaintainable functions over time, you should keep an eye on them and
refactor if possible. Functions in the first two categories are fine and don't
need refactoring.

Function length is just one code metric, but it is a very important code
metric. Short functions are easy to understand, easy to test, easy to re-use.
For example, code duplication is another important code metric but duplication
is much easier to prevent and fix if your functions are short.

<figure markdown>
<div align="center">
<img src="assets/unmaintainable-code.jpg" width="500"/>
<figcaption>Unmaintainable code. Looks easy; should be done in half an hour I reckon <a href="https://twitter.com/KenScambler/status/477322711039893504">[source]</a></figcaption>
</div>
</figure>

Function length is a simple code metric, so simple you can count it by hand.
It's also a (fairly) non-controversial metric, most developers agree longer
functions are harder to maintain. Also, there's always a refactoring possible
to make functions smaller.

Because function length is such a simple code metric, many code quality tools
measure it. But these tools measure a lot more metrics, sometimes so much
metrics that developers are overwhemled and loose focus on the metrics that
matter most.

Code Limit measures only function length but it tries to be the best developer
tool for measuring it. By notifying developers when it's time to refactor, Code
Limit prevents unmaintainable code.

Keep your software maintainable and start using Code Limit today!
### Key features and design principles

* **A non-controversial code metric**: Most developers agree longer functions
are harder to maintain
* **Actionable results**: There's always a refactoring possible to make
functions smaller.
* **Runs everywhere**: Fits your development workflow, whether it's in a build
pipeline, a pre-commit hook, or standalone.
* **Covers many languages**: A single tool for all your projects
* **Sane defaults**: Zero configuration, but allows customization.

*[functions]: Also called methods or procedures, depending on your programming language

## Next steps

Go to the [Getting Started](getting-started/development-workflow.md) section to
start using Code Limit, or read more about the [function length
metric](why-function-length.md).
46 changes: 46 additions & 0 deletions docs/why-function-length.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Why Function Length?

Function length is just one code metric, but it is a very important code
metric. Short functions are easy to understand, easy to test, easy to re-use.
For example, code duplication is another important code metric but duplication
is much easier to prevent and fix if your functions are short.

<figure markdown>
<div align="center">
<img src="../assets/unmaintainable-code.jpg" width="500"/>
<figcaption>Unmaintainable code. Looks easy; should be done in half an hour I reckon <a href="https://twitter.com/KenScambler/status/477322711039893504">[source]</a></figcaption>
</div>
</figure>

Function length is a simple code metric, so simple you can count it by hand.
It's also a (fairly) non-controversial metric, most developers agree longer
functions are harder to maintain. Also, there's always a refactoring possible
to make functions smaller.

## Why Code Limit?

Because function length is such a simple code metric, many code quality tools
measure it. But these tools measure a lot more metrics, sometimes so much
metrics that developers are overwhemled and loose focus on the metrics that
matter most.

Code Limit measures only function length but it tries to be the best developer
tool for measuring it. By notifying developers when it's time to refactor, Code
Limit prevents unmaintainable code.

## How Code Limit measures function length

Code Limit measures the lines of code for each function in your codebase and
assigns each function to a category:

| Easy | Verbose | Hard-to-maintain <span style="color: #e5832f;">&#x26A0;</span> | Unmaintainable <span style="color: #ff0000;">&#x2716;</span> |
| :---: | :---: | :---: | :---: |
| 1 - 15 lines of code | 16 - 30 lines of code | 31 - 60 lines of code | 60+ lines of code |
| ![](assets/easy.png){: style="height:136px;width:230px"} | ![](assets/verbose.png){: style="height:189px;width:230px"} | ![](assets/hard-to-maintain.png){: style="height:294px;width:230px"} | ![](assets/unmaintainable.png){: style="height:564px;width:230px"} |

As the table above shows, functions with more than 60 lines of code (comments
and empty lines are not counted) are _unmaintainable_, and _need_ to be
refactored. Functions with more than 30 lines of code run a risk of turning
into unmaintainable functions over time, you should keep an eye on them and
refactor if possible. Functions in the first two categories are fine and don't
need refactoring.
12 changes: 9 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ theme:
logo: assets/logo.png
favicon: assets/favicon.png
features:
- toc.integrate
- navigation.tabs
- navigation.tabs.sticky
- navigation.tracking
- navigation.footer
- content.code.copy
extra_css:
Expand All @@ -31,11 +33,15 @@ plugins:
shadow: false
- search
markdown_extensions:
- abbr
- attr_list
- pymdownx.snippets
nav:
- 'index.md'
- 'quickstart.md'
- 'usage.md'
- 'why-function-length.md'
- Getting Started:
- 'getting-started/development-workflow.md'
- 'getting-started/standalone-usage.md'
- 'configuration.md'
- 'faq.md'
- 'development.md'
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f95f54d

Please sign in to comment.