Skip to content

Commit b270445

Browse files
author
Really Him
committed
chore: readme
1 parent daf9c4a commit b270445

File tree

2 files changed

+97
-98
lines changed

2 files changed

+97
-98
lines changed

README.md

Lines changed: 86 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# code-cop
22

3-
A code quality enforcement tool that analyzes code complexity metrics and helps maintain readable, maintainable code.
3+
A code quality enforcement tool that analyzes code complexity across a number of metrics and helps maintain readable, maintainable code.
44

55
## What is code-cop?
66

@@ -12,10 +12,10 @@ Currently, code-cop supports Python code analysis with plans to add JavaScript a
1212

1313
Complex code is harder to understand, test, and maintain. By enforcing limits on complexity metrics, you can:
1414

15-
- Catch overly complex functions before they're merged
16-
- Maintain consistent code quality standards across your team
17-
- Identify refactoring opportunities
18-
- Reduce technical debt over time
15+
- Catch overly complex functions before they're merged
16+
- Maintain consistent code quality standards across your team
17+
- Identify refactoring opportunities
18+
- Reduce technical debt over time
1919

2020
## Installation
2121

@@ -36,8 +36,8 @@ pip install -e ".[dev]"
3636

3737
### Requirements
3838

39-
- Python 3.11 or higher
40-
- Radon (automatically installed as a dependency)
39+
- Python 3.11 or higher
40+
- Radon (automatically installed as a dependency)
4141

4242
## Basic Usage
4343

@@ -77,79 +77,80 @@ code-cop uses YAML configuration files. By default, it looks for `.code_cop.yaml
7777
use_gitignore: true
7878

7979
defaults:
80-
max_cyclomatic_complexity: 10
81-
min_maintainability_index: 50
82-
max_halstead_volume: 1000
83-
max_halstead_difficulty: 10
84-
max_halstead_effort: 10000
85-
max_cognitive_complexity: 15
80+
max_cyclomatic_complexity: 10
81+
min_maintainability_index: 50
82+
max_halstead_volume: 1000
83+
max_halstead_difficulty: 10
84+
max_halstead_effort: 10000
85+
max_cognitive_complexity: 15
8686

8787
languages:
88-
- name: python
89-
extensions:
90-
- .py
91-
metrics:
92-
- type: cyclomatic_complexity
93-
threshold: 10
94-
comparison: "<="
95-
- type: maintainability_index
96-
threshold: 50
97-
comparison: ">="
98-
- type: halstead_volume
99-
threshold: 1000
100-
comparison: "<="
101-
- type: halstead_difficulty
102-
threshold: 10
103-
comparison: "<="
104-
- type: halstead_effort
105-
threshold: 10000
106-
comparison: "<="
107-
- type: cognitive_complexity
108-
threshold: 15
109-
comparison: "<="
110-
enabled: false # Requires complexipy (not yet implemented)
88+
- name: python
89+
extensions:
90+
- .py
91+
metrics:
92+
- type: cyclomatic_complexity
93+
threshold: 10
94+
comparison: "<="
95+
- type: maintainability_index
96+
threshold: 50
97+
comparison: ">="
98+
- type: halstead_volume
99+
threshold: 1000
100+
comparison: "<="
101+
- type: halstead_difficulty
102+
threshold: 10
103+
comparison: "<="
104+
- type: halstead_effort
105+
threshold: 10000
106+
comparison: "<="
107+
- type: cognitive_complexity
108+
threshold: 15
109+
comparison: "<="
110+
enabled: false # Requires complexipy (not yet implemented)
111111

112112
ignore_patterns:
113-
- "**/test_*.py"
114-
- "**/*_test.py"
115-
- "**/tests/**"
116-
- "**/__pycache__/**"
113+
- "**/test_*.py"
114+
- "**/*_test.py"
115+
- "**/tests/**"
116+
- "**/__pycache__/**"
117117
```
118118
119119
### Configuration Structure
120120
121-
- **use_gitignore**: Whether to automatically use patterns from `.gitignore` (default: true)
122-
- **defaults**: Default thresholds used when language-specific configuration is not provided
123-
- **languages**: Language-specific configurations
124-
- **name**: Language identifier (currently only "python" is supported)
125-
- **extensions**: File extensions to associate with this language
126-
- **metrics**: List of metrics to check
127-
- **type**: The metric type (see Metrics section below)
128-
- **threshold**: The threshold value
129-
- **comparison**: How to compare the metric value with the threshold
130-
- **enabled**: Whether to check this metric (default: true)
131-
- **ignore_patterns**: Additional gitignore-style patterns for files to skip (combined with .gitignore if `use_gitignore` is true)
121+
- **use_gitignore**: Whether to automatically use patterns from `.gitignore` (default: true)
122+
- **defaults**: Default thresholds used when language-specific configuration is not provided
123+
- **languages**: Language-specific configurations
124+
- **name**: Language identifier (currently only "python" is supported)
125+
- **extensions**: File extensions to associate with this language
126+
- **metrics**: List of metrics to check
127+
- **type**: The metric type (see Metrics section below)
128+
- **threshold**: The threshold value
129+
- **comparison**: How to compare the metric value with the threshold
130+
- **enabled**: Whether to check this metric (default: true)
131+
- **ignore_patterns**: Additional gitignore-style patterns for files to skip (combined with .gitignore if `use_gitignore` is true)
132132

133133
### Comparison Operators
134134

135-
- `<=` - Metric value must be less than or equal to threshold
136-
- `<` - Metric value must be less than threshold
137-
- `>=` - Metric value must be greater than or equal to threshold
138-
- `>` - Metric value must be greater than threshold
139-
- `==` - Metric value must equal threshold
140-
- `!=` - Metric value must not equal threshold
135+
- `<=` - Metric value must be less than or equal to threshold
136+
- `<` - Metric value must be less than threshold
137+
- `>=` - Metric value must be greater than or equal to threshold
138+
- `>` - Metric value must be greater than threshold
139+
- `==` - Metric value must equal threshold
140+
- `!=` - Metric value must not equal threshold
141141

142142
## Metrics Explained
143143

144144
### Cyclomatic Complexity
145145

146146
Measures the number of linearly independent paths through a function. Higher values indicate more complex control flow.
147147

148-
- **Good**: 1-10 (simple, easy to test)
149-
- **Moderate**: 11-20 (more complex, harder to test)
150-
- **High**: 21+ (very complex, consider refactoring)
148+
- **Good**: 1-10 (simple, easy to test)
149+
- **Moderate**: 11-20 (more complex, harder to test)
150+
- **High**: 21+ (very complex, consider refactoring)
151151

152152
Example of high complexity:
153+
153154
```python
154155
def process_data(data, mode, validate, transform):
155156
if validate:
@@ -175,33 +176,33 @@ def process_data(data, mode, validate, transform):
175176

176177
A composite metric (0-100) that considers cyclomatic complexity, lines of code, and Halstead volume. Higher values indicate more maintainable code.
177178

178-
- **Good**: 50-100 (maintainable)
179-
- **Moderate**: 20-49 (moderately maintainable)
180-
- **Low**: 0-19 (difficult to maintain)
179+
- **Good**: 50-100 (maintainable)
180+
- **Moderate**: 20-49 (moderately maintainable)
181+
- **Low**: 0-19 (difficult to maintain)
181182

182183
### Halstead Metrics
183184

184185
Based on the number of operators and operands in code:
185186

186-
- **Volume**: Program size based on the number of operations
187-
- **Difficulty**: How hard the code is to understand
188-
- **Effort**: Mental effort required to understand the code
189-
- **Time**: Estimated time to implement (in seconds)
190-
- **Bugs**: Estimated number of bugs (Volume / 3000)
187+
- **Volume**: Program size based on the number of operations
188+
- **Difficulty**: How hard the code is to understand
189+
- **Effort**: Mental effort required to understand the code
190+
- **Time**: Estimated time to implement (in seconds)
191+
- **Bugs**: Estimated number of bugs (Volume / 3000)
191192

192193
### Lines of Code Metrics
193194

194-
- **LOC**: Total lines of code
195-
- **SLOC**: Source lines of code (excluding comments and blanks)
196-
- **LLOC**: Logical lines of code
197-
- **Comment Lines**: Number of comment lines
198-
- **Blank Lines**: Number of blank lines
195+
- **LOC**: Total lines of code
196+
- **SLOC**: Source lines of code (excluding comments and blanks)
197+
- **LLOC**: Logical lines of code
198+
- **Comment Lines**: Number of comment lines
199+
- **Blank Lines**: Number of blank lines
199200

200201
## Exit Codes
201202

202-
- **0**: All metrics pass their thresholds
203-
- **1**: Error (invalid configuration, missing files, etc.)
204-
- **2**: One or more metrics violate their thresholds
203+
- **0**: All metrics pass their thresholds
204+
- **1**: Error (invalid configuration, missing files, etc.)
205+
- **2**: One or more metrics violate their thresholds
205206

206207
This makes code-cop suitable for CI/CD pipelines:
207208

@@ -302,13 +303,13 @@ code_cop/
302303

303304
## Future Enhancements
304305

305-
- JavaScript/TypeScript support via ts-complex
306-
- Cognitive complexity for Python via complexipy
307-
- Pre-commit hook integration
308-
- Git hook support
309-
- HTML report generation
310-
- Baseline file support (ignore existing violations)
311-
- Trend analysis over time
306+
- JavaScript/TypeScript support via ts-complex
307+
- Cognitive complexity for Python via complexipy
308+
- Pre-commit hook integration
309+
- Git hook support
310+
- HTML report generation
311+
- Baseline file support (ignore existing violations)
312+
- Trend analysis over time
312313

313314
## Contributing
314315

@@ -326,5 +327,5 @@ Contributions are welcome! Please:
326327

327328
## Acknowledgments
328329

329-
- [Radon](https://github.com/rubik/radon) for Python code metrics
330-
- Inspired by various code quality tools like ESLint, Pylint, and SonarQube
330+
- [Radon](https://github.com/rubik/radon) for Python code metrics
331+
- Inspired by various code quality tools like ESLint, Pylint, and SonarQube

pyproject.toml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ version = "0.1.0"
88
description = "A code quality enforcement tool that analyzes code complexity metrics"
99
readme = "README.md"
1010
requires-python = ">=3.11"
11-
license = {text = "MIT"}
12-
authors = [
13-
{name = "code-cop contributors"},
11+
license = { text = "MIT" }
12+
authors = [{ name = "Really Him", email = "hesreallyhim@proton.me" }]
13+
keywords = [
14+
"code-quality",
15+
"complexity",
16+
"metrics",
17+
"linting",
18+
"static-analysis",
1419
]
15-
keywords = ["code-quality", "complexity", "metrics", "linting", "static-analysis"]
1620
classifiers = [
1721
"Development Status :: 3 - Alpha",
1822
"Intended Audience :: Developers",
@@ -100,21 +104,15 @@ show_error_codes = true
100104
show_error_context = true
101105

102106
[[tool.mypy.overrides]]
103-
module = [
104-
"radon.*",
105-
"complexipy.*",
106-
]
107+
module = ["radon.*", "complexipy.*"]
107108
ignore_missing_imports = true
108109

109110
[tool.pytest.ini_options]
110111
testpaths = ["tests"]
111112
python_files = ["test_*.py", "*_test.py"]
112113
python_classes = ["Test*"]
113114
python_functions = ["test_*"]
114-
addopts = [
115-
"-ra",
116-
"--strict-markers",
117-
]
115+
addopts = ["-ra", "--strict-markers"]
118116

119117
[tool.coverage.run]
120118
branch = true
@@ -134,4 +132,4 @@ exclude_lines = [
134132
"if __name__ == .__main__.:",
135133
"class .*\\bProtocol\\):",
136134
"@(abc\\.)?abstractmethod",
137-
]
135+
]

0 commit comments

Comments
 (0)