Skip to content

Commit 69b135c

Browse files
committed
chore(formatting)
1 parent 46da56e commit 69b135c

File tree

6 files changed

+121
-33
lines changed

6 files changed

+121
-33
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v4
16-
16+
1717
- name: Set up Python
1818
uses: actions/setup-python@v5
1919
with:
2020
python-version: "3.11"
2121
cache: "pip"
22-
22+
2323
- name: Install dependencies
2424
run: |
2525
python -m pip install --upgrade pip
2626
pip install ruff black mypy
2727
pip install -e ".[dev]"
28-
28+
2929
- name: Run Ruff
3030
run: ruff check src/ tests/
31-
31+
3232
- name: Run Black
3333
run: black --check src/ tests/
34-
34+
3535
- name: Run MyPy
3636
run: mypy src/
3737

@@ -41,25 +41,25 @@ jobs:
4141
strategy:
4242
matrix:
4343
python-version: ["3.11", "3.12"]
44-
44+
4545
steps:
4646
- uses: actions/checkout@v4
47-
47+
4848
- name: Set up Python ${{ matrix.python-version }}
4949
uses: actions/setup-python@v5
5050
with:
5151
python-version: ${{ matrix.python-version }}
5252
cache: "pip"
53-
53+
5454
- name: Install dependencies
5555
run: |
5656
python -m pip install --upgrade pip
5757
pip install -e ".[dev]"
58-
58+
5959
- name: Run tests with coverage
6060
run: |
6161
pytest --cov=sitescanner --cov-report=xml --cov-report=term
62-
62+
6363
- name: Upload coverage to Codecov
6464
uses: codecov/codecov-action@v4
6565
with:
@@ -71,23 +71,23 @@ jobs:
7171
runs-on: ubuntu-latest
7272
steps:
7373
- uses: actions/checkout@v4
74-
74+
7575
- name: Set up Python
7676
uses: actions/setup-python@v5
7777
with:
7878
python-version: "3.11"
7979
cache: "pip"
80-
80+
8181
- name: Install dependencies
8282
run: |
8383
python -m pip install --upgrade pip
8484
pip install bandit safety
8585
pip install -e .
86-
86+
8787
- name: Run Bandit
8888
run: bandit -r src/ -f json -o bandit-report.json
8989
continue-on-error: true
90-
90+
9191
- name: Run Safety
9292
run: safety check --json
9393
continue-on-error: true

PRE_COMMIT_SETUP.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Pre-commit Setup
2+
3+
Pre-commit hooks have been configured to automatically check code quality before each commit.
4+
5+
## Installed Hooks
6+
7+
The following checks run automatically on every commit:
8+
9+
1. **Ruff** - Fast Python linter (checks and fixes issues)
10+
2. **Black** - Python code formatter
11+
3. **Mypy** - Static type checker
12+
4. **Pre-commit hooks** - Trailing whitespace, YAML checks, etc.
13+
14+
## Usage
15+
16+
### Automatic (on git commit)
17+
Hooks run automatically when you commit:
18+
```bash
19+
git add <files>
20+
git commit -m "Your message"
21+
# Pre-commit hooks will run automatically
22+
```
23+
24+
### Manual run on all files
25+
```bash
26+
pre-commit run --all-files
27+
```
28+
29+
### Manual run on staged files
30+
```bash
31+
pre-commit run
32+
```
33+
34+
### Run specific hook
35+
```bash
36+
pre-commit run ruff --all-files
37+
pre-commit run black --all-files
38+
pre-commit run mypy --all-files
39+
```
40+
41+
### Skip hooks (not recommended)
42+
```bash
43+
git commit --no-verify -m "Skip hooks"
44+
```
45+
46+
## Individual Tool Usage
47+
48+
### Ruff
49+
```bash
50+
# Check for issues
51+
ruff check src/ tests/
52+
53+
# Fix auto-fixable issues
54+
ruff check --fix src/ tests/
55+
56+
# Format code
57+
ruff format src/ tests/
58+
```
59+
60+
### Black
61+
```bash
62+
# Check formatting
63+
black --check src/ tests/
64+
65+
# Format code
66+
black src/ tests/
67+
```
68+
69+
### Mypy
70+
```bash
71+
# Type check
72+
mypy src/
73+
74+
# With ignore missing imports
75+
mypy src/ --ignore-missing-imports
76+
```
77+
78+
## Configuration Files
79+
80+
- `.pre-commit-config.yaml` - Pre-commit hook configuration
81+
- `pyproject.toml` - Contains Ruff, Black, and Mypy configurations
82+
83+
## What Gets Checked
84+
85+
✅ Code formatting (Black)
86+
✅ Import sorting (Ruff)
87+
✅ Linting (Ruff) - unused imports, code quality, etc.
88+
✅ Type hints (Mypy)
89+
✅ Trailing whitespace
90+
✅ End of file fixes
91+
✅ YAML/TOML syntax
92+
93+
## Installation on New Clones
94+
95+
If you clone this repo elsewhere:
96+
```bash
97+
source .venv/bin/activate
98+
pre-commit install
99+
```

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,10 @@ async def main():
109109
max_depth=3,
110110
enabled_scanners=["sql_injection", "xss"],
111111
)
112-
112+
113113
async with Scanner(config) as scanner:
114114
result = await scanner.scan()
115-
115+
116116
print(f"Found {len(result.vulnerabilities)} vulnerabilities")
117117
for vuln in result.vulnerabilities:
118118
print(f"- {vuln.vuln_type}: {vuln.severity}")
@@ -173,7 +173,7 @@ sitescanner5000/
173173
run: |
174174
pip install sitescanner5000
175175
sitescanner scan ${{ secrets.TARGET_URL }} --output scan-results.json --format json
176-
176+
177177
- name: Check for Critical Vulnerabilities
178178
run: |
179179
# Exit code 2 = critical vulnerabilities found

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Empty test file to satisfy initial test structure."""
22

3+
34
def test_placeholder():
45
"""Placeholder test to ensure pytest runs successfully."""
56
assert True

tests/test_sql_injection.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ async def test_sql_scanner_detects_vulnerability(mock_session, vulnerable_sql_re
4747
mock_session.get.return_value = mock_context
4848

4949
# Scan pages
50-
vulnerabilities = await scanner.scan_pages(
51-
["https://example.com/page?id=1"],
52-
mock_session
53-
)
50+
vulnerabilities = await scanner.scan_pages(["https://example.com/page?id=1"], mock_session)
5451

5552
# Should detect SQL injection
5653
assert len(vulnerabilities) > 0
@@ -67,10 +64,7 @@ async def test_sql_scanner_no_parameters(mock_session):
6764
mock_response.text = AsyncMock(return_value="<html>Safe page</html>")
6865
mock_session.get = AsyncMock(return_value=mock_response)
6966

70-
vulnerabilities = await scanner.scan_pages(
71-
["https://example.com/page"],
72-
mock_session
73-
)
67+
vulnerabilities = await scanner.scan_pages(["https://example.com/page"], mock_session)
7468

7569
# Should return empty list (no parameters to test)
7670
assert len(vulnerabilities) == 0

tests/test_xss.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ async def test_xss_scanner_detects_vulnerability(mock_session, xss_reflected_res
4949
mock_session.get.return_value = mock_context
5050

5151
# Scan pages
52-
vulnerabilities = await scanner.scan_pages(
53-
["https://example.com/search?q=test"],
54-
mock_session
55-
)
52+
vulnerabilities = await scanner.scan_pages(["https://example.com/search?q=test"], mock_session)
5653

5754
# Should detect XSS
5855
assert len(vulnerabilities) > 0
@@ -75,10 +72,7 @@ async def test_xss_scanner_safe_page(mock_session):
7572
mock_context.__aexit__.return_value = None
7673
mock_session.get.return_value = mock_context
7774

78-
vulnerabilities = await scanner.scan_pages(
79-
["https://example.com/search?q=test"],
80-
mock_session
81-
)
75+
vulnerabilities = await scanner.scan_pages(["https://example.com/search?q=test"], mock_session)
8276

8377
# Should not detect XSS (content is properly encoded)
8478
assert len(vulnerabilities) == 0

0 commit comments

Comments
 (0)