Skip to content

Commit 4ff08db

Browse files
committed
docs: 📝 LLAP
1 parent 21fb0ca commit 4ff08db

25 files changed

+4820
-1
lines changed

.github/workflows/main.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: main
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build:
10+
name: Deploy docs
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: 'Checkout sources'
14+
uses: actions/checkout@v4
15+
16+
- name: 'Deploy docs'
17+
uses: mhausenblas/mkdocs-deploy-gh-pages@master
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
REQUIREMENTS: requirements.txt

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
site/
2+
.DS_Store

LICENSE

Lines changed: 619 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# getcodelimit.github.io
1+
# Code Limit Documentation

docs/assets/easy.png

219 KB
Loading

docs/assets/favicon.png

1.64 KB
Loading

docs/assets/hard-to-maintain.png

557 KB
Loading

docs/assets/logo.png

9.27 KB
Loading

docs/assets/report.cast

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{"version": 2, "width": 80, "height": 25, "timestamp": 1712420376, "env": {"SHELL": "/bin/zsh", "TERM": "xterm-256color"}}
2+
[0.372445, "o", "\u001b]2;rob@mahler:~/projects/opensource/fastapi\u0007\u001b]1;..ource/fastapi\u0007"]
3+
[0.372945, "o", "\u001b]0;~/projects/opensource/fastapi\u0007"]
4+
[0.376495, "o", "\r\n"]
5+
[0.376679, "o", "\u001b[0m\u001b[27m\u001b[24m\u001b[J\u001b[34m~/projects/opensource/fastapi\u001b[39m\r\n\r\u001b[35m❯\u001b[39m \u001b[K"]
6+
[0.376864, "o", "\u001b[?1h\u001b="]
7+
[0.377014, "o", "\u001b[?2004h"]
8+
[0.425151, "o", "\r\r\u001b[A\u001b[0m\u001b[27m\u001b[24m\u001b[J\u001b[34m~/projects/opensource/fastapi\u001b[39m \u001b[38;5;242mmaster\u001b[38;5;218m\u001b[39m\r\n\r\u001b[35m❯\u001b[39m \u001b[K"]
9+
[1.704691, "o", "c"]
10+
[2.220527, "o", "\bco"]
11+
[2.466128, "o", "d"]
12+
[2.511853, "o", "e"]
13+
[2.646861, "o", "l"]
14+
[2.735853, "o", "i"]
15+
[2.955499, "o", "m"]
16+
[3.019103, "o", "i"]
17+
[3.593736, "o", "t"]
18+
[3.654651, "o", " "]
19+
[3.976152, "o", "r"]
20+
[4.02638, "o", "e"]
21+
[4.088613, "o", "p"]
22+
[4.142272, "o", "o"]
23+
[4.540734, "o", "r"]
24+
[5.204344, "o", "t"]
25+
[5.386895, "o", " "]
26+
[6.078544, "o", "."]
27+
[6.734379, "o", "\u001b[?1l\u001b>"]
28+
[6.735087, "o", "\u001b[?2004l\r\r\n"]
29+
[6.737336, "o", "\u001b]2;codelimit report .\u0007\u001b]1;codelimit\u0007"]
30+
[6.737727, "o", "\u001b]0;fastapi: codelimit report .\u0007"]
31+
[6.996205, "o", "\u001b[1mfastapi/applications.py\u001b[0m\u001b[36m:\u001b[0m64\u001b[36m:\u001b[0m5\u001b[36m:\u001b[0m 317 \u001b[31m✖\u001b[0m __init__\r\n"]
32+
[6.996294, "o", "\u001b[1mfastapi/param_functions.py\u001b[0m\u001b[36m:\u001b[0m1263\u001b[36m:\u001b[0m1\u001b[36m:\u001b[0m 229 \u001b[31m✖\u001b[0m Body\r\n"]
33+
[6.996347, "o", "\u001b[1mfastapi/param_functions.py\u001b[0m\u001b[36m:\u001b[0m643\u001b[36m:\u001b[0m1\u001b[36m:\u001b[0m 222 \u001b[31m✖\u001b[0m Header\r\n"]
34+
[6.996423, "o", "\u001b[1mfastapi/param_functions.py\u001b[0m\u001b[36m:\u001b[0m1592\u001b[36m:\u001b[0m1\u001b[36m:\u001b[0m 222 \u001b[31m✖\u001b[0m Form\r\n"]
35+
[6.996499, "o", "\u001b[1mfastapi/param_functions.py\u001b[0m\u001b[36m:\u001b[0m1906\u001b[36m:\u001b[0m1\u001b[36m:\u001b[0m 222 \u001b[31m✖\u001b[0m File\r\n"]
36+
[6.996571, "o", "\u001b[1mfastapi/param_functions.py\u001b[0m\u001b[36m:\u001b[0m11\u001b[36m:\u001b[0m1\u001b[36m:\u001b[0m 216 \u001b[31m✖\u001b[0m Path\r\n"]
37+
[6.996638, "o", "\u001b[1mfastapi/param_functions.py\u001b[0m\u001b[36m:\u001b[0m339\u001b[36m:\u001b[0m1\u001b[36m:\u001b[0m 215 \u001b[31m✖\u001b[0m Query\r\n"]
38+
[6.996719, "o", "\u001b[1mfastapi/param_functions.py\u001b[0m\u001b[36m:\u001b[0m959\u001b[36m:\u001b[0m1\u001b[36m:\u001b[0m 215 \u001b[31m✖\u001b[0m Cookie\r\n"]
39+
[6.996783, "o", "\u001b[1mfastapi/encoders.py\u001b[0m\u001b[36m:\u001b[0m102\u001b[36m:\u001b[0m1\u001b[36m:\u001b[0m 191 \u001b[31m✖\u001b[0m jsonable_encoder\r\n"]
40+
[6.996855, "o", "\u001b[1mfastapi/openapi/utils.py\u001b[0m\u001b[36m:\u001b[0m215\u001b[36m:\u001b[0m1\u001b[36m:\u001b[0m 183 \u001b[31m✖\u001b[0m get_openapi_path\r\n"]
41+
[6.997954, "o", "\u001b[1;36m57\u001b[0m\u001b[1m more rows, use --full option to get all rows\u001b[0m\r\n"]
42+
[7.017025, "o", "\u001b]2;rob@mahler:~/projects/opensource/fastapi\u0007\u001b]1;..ource/fastapi\u0007"]
43+
[7.017091, "o", "\u001b]0;~/projects/opensource/fastapi\u0007"]
44+
[7.018383, "o", "\r\n"]
45+
[7.018456, "o", "\u001b[0m\u001b[27m\u001b[24m\u001b[J\u001b[34m~/projects/opensource/fastapi\u001b[39m \u001b[38;5;242mmaster\u001b[38;5;218m\u001b[39m\r\n\r\u001b[35m❯\u001b[39m "]
46+
[7.018496, "o", "\u001b[K"]
47+
[7.018593, "o", "\u001b[?1h\u001b="]
48+
[7.018651, "o", "\u001b[?2004h"]
49+
[9.288505, "o", "\u001b[?2004l\r\r\n"]

docs/assets/scan.cast

Lines changed: 67 additions & 0 deletions
Large diffs are not rendered by default.

docs/assets/unmaintainable-code.jpg

45.7 KB
Loading

docs/assets/unmaintainable.png

971 KB
Loading

docs/assets/verbose.png

295 KB
Loading

docs/configuration.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Configuration
2+
3+
## Excluding functions
4+
5+
Functions can be excluded from analysis by putting a `# nocl` comment on the
6+
line above the start of the function, or at any line of the function header.
7+
8+
For example, to ignore a function with a `# nocl` comment above the start of
9+
the function:
10+
11+
```python
12+
# nocl
13+
def some_function():
14+
...
15+
```
16+
17+
Or you can ignore a function by putting a `# nocl` comment on any line of the
18+
header:
19+
20+
```python
21+
def some_function(): # nocl
22+
...
23+
```
24+
25+
```python
26+
def some_functions(
27+
some_numbers: list[int]
28+
) -> int: # nocl
29+
...
30+
```
31+
32+
## Excluding files
33+
34+
Files can be excluded from analysis by using the `--exclude` option.
35+
This option can be used multiple times and takes a [glob pattern](https://en.wikipedia.org/wiki/Glob_(programming)) as a
36+
value, for example:
37+
38+
```shell
39+
codelimit --exclude "*.generated.py" --exclude "docs/*" ...
40+
```
41+
42+
The `--exclude` option extends the default exclusion list.
43+
The default exclusion list is:
44+
45+
```python
46+
[
47+
".bzr",
48+
".direnv",
49+
".eggs",
50+
".git",
51+
".git-rewrite",
52+
".hg",
53+
".ipynb_checkpoints",
54+
".mypy_cache",
55+
".nox",
56+
".pants.d",
57+
".pytest_cache",
58+
".pytype",
59+
".ruff_cache",
60+
".svn",
61+
".tox",
62+
".venv",
63+
".vscode",
64+
"__pypackages__",
65+
"_build",
66+
"buck-out",
67+
"build",
68+
"dist",
69+
"node_modules",
70+
"venv",
71+
"test",
72+
"tests",
73+
]
74+
```

docs/development.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Development
2+
3+
After installing dependencies with `poetry install`, Code Limit can be run from
4+
the repository root like this:
5+
6+
```shell
7+
poetry run codelimit
8+
```
9+
10+
For example, to check a codebase at `~/projects/fastapi` run:
11+
12+
```shell
13+
poetry run codelimit scan ~/projects/fastapi
14+
```
15+
16+
## Local installation using pipx
17+
18+
To install the development repository locally run:
19+
20+
```shell
21+
pipx install .
22+
```
23+
24+
To install the `main` branch locally run:
25+
26+
```shell
27+
pipx install git+https://github.com/getcodelimit/codelimit.git
28+
```
29+
30+
Or to install another branch locally run:
31+
32+
```shell
33+
pip install git+https://github.com/getcodelimit/codelimit.git@issue-123
34+
```
35+
36+
## Building the binary distribution
37+
38+
Generate a self-contained binary:
39+
40+
```shell
41+
poetry run poe bundle
42+
```
43+
44+
## Static documentation
45+
46+
Generating the static documentation:
47+
48+
```shell
49+
poetry run mkdocs build
50+
```
51+
52+
See the output:
53+
54+
```shell
55+
poetry run mkdocs serve
56+
```
57+
58+
Terminal sessions in the documentation are recorded with the [Asciinema
59+
CLI](https://docs.asciinema.org/getting-started/) and stored in the `assets`
60+
folder:
61+
62+
```shell
63+
asciinema rec scan.cast
64+
```

docs/faq.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# F.A.Q.
2+
3+
### Q. What programming languages does Code Limit support?
4+
5+
Currently Code Limit supports these programming languages:
6+
7+
- C
8+
- C++
9+
- Java
10+
- JavaScript
11+
- Python
12+
- TypeScript
13+
14+
### Q. How does Code Limit compare to ...
15+
16+
**Black**
17+
18+
[Black](https://github.com/psf/black) is a code formatter and can run alongside Code Limit.
19+
20+
**Flake8**
21+
22+
[Flake8](https://github.com/PyCQA/flake8) is a linter and can run alongside
23+
Code Limit. Flake8 can be extended with third-party plugins.
24+
25+
**Lizard**
26+
27+
[Lizard](https://github.com/terryyin/lizard) is a code quality tool that
28+
measures cyclomatic complexity and code duplication.The tool is more used for
29+
reporting than monitoring during development.
30+
31+
**Radon**
32+
33+
[Radon](https://github.com/rubik/radon) is a code quality tool that computes
34+
various metrics. Radon calculates cyclomatic complexity for functions but not
35+
lines of code. The tool is more used for reporting than monitoring during
36+
development.
37+
38+
**Ruff**
39+
40+
[Ruff](https://github.com/astral-sh/ruff) is a linter and can run alongside
41+
Code Limit. Ruff has no linting rule for function length.

docs/index.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Introduction
2+
3+
Code Limit is a tool for developers with one goal: _it tells the developer when
4+
it’s time to refactor_.
5+
6+
Code Limit measures the lines of code for each function in your codebase and
7+
assigns each function to a category:
8+
9+
| Easy | Verbose | Hard-to-maintain <span style="color: #e5832f;">&#x26A0;</span> | Unmaintainable <span style="color: #ff0000;">&#x2716;</span> |
10+
| :---: | :---: | :---: | :---: |
11+
| 1 - 15 lines of code | 16 - 30 lines of code | 31 - 60 lines of code | 60+ lines of code |
12+
| ![](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"} |
13+
14+
As the table above shows, functions with more than 60 lines of code (comments
15+
and empty lines are not counted) are _unmaintainable_, and _need_ to be
16+
refactored. Functions with more than 30 lines of code run a risk of turning
17+
into unmaintainable functions over time, you should keep an eye on them and
18+
refactor if possible. Functions in the first two categories are fine and don't
19+
need refactoring.
20+
21+
Function length is just one code metric, but it is a very important code
22+
metric. Short functions are easy to understand, easy to test, easy to re-use.
23+
For example, code duplication is another important code metric but duplication
24+
is much easier to prevent and fix if your functions are short.
25+
26+
<figure markdown>
27+
<div align="center">
28+
<img src="assets/unmaintainable-code.jpg" width="500"/>
29+
<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>
30+
</div>
31+
</figure>
32+
33+
Function length is a simple code metric, so simple you can count it by hand.
34+
It's also a (fairly) non-controversial metric, most developers agree longer
35+
functions are harder to maintain. Also, there's always a refactoring possible
36+
to make functions smaller.
37+
38+
Because function length is such a simple code metric, many code quality tools
39+
measure it. But these tools measure a lot more metrics, sometimes so much
40+
metrics that developers are overwhemled and loose focus on the metrics that
41+
matter most.
42+
43+
Code Limit measures only function length but it tries to be the best developer
44+
tool for measuring it. By notifying developers when it's time to refactor, Code
45+
Limit prevents unmaintainable code.
46+
47+
Keep your software maintainable and start using Code Limit today!

docs/javascripts/asciinema-player.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)