Skip to content

Commit d6bacb1

Browse files
Add dead code and duplicate code detection
- Add vulture for dead code detection in pre-commit hooks - Add jscpd for duplicate code detection in pre-commit hooks - Add .jscpd.json configuration for duplicate detection settings - Add .vulture_whitelist.py for framework entry points - Add .github/workflows/code-quality.yml for CI code quality checks Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> Change-Id: Ia6de66341ae300ee8737923b9fcdad3907d92a63 Reviewed-on: https://review.couchbase.org/c/TAF/+/243275 Tested-by: Ashwin <ashwin.govindarajulu@couchbase.com> Reviewed-by: Bharath G P <bharath.gp@couchbase.com>
1 parent 31cc7c9 commit d6bacb1

4 files changed

Lines changed: 131 additions & 0 deletions

File tree

.github/workflows/code-quality.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Code Quality
2+
3+
on:
4+
push:
5+
branches: [master, master_jython, trinity]
6+
pull_request:
7+
branches: [master, master_jython, trinity]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Setup Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.10'
19+
20+
- name: Install linters
21+
run: |
22+
pip install ruff vulture jscpd
23+
24+
- name: Run Ruff linter
25+
run: |
26+
ruff check --output-format=github .
27+
28+
- name: Run Ruff formatter check
29+
run: |
30+
ruff format --check .
31+
32+
dead-code:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Setup Python
38+
uses: actions/setup-python@v5
39+
with:
40+
python-version: '3.10'
41+
42+
- name: Install vulture
43+
run: pip install vulture
44+
45+
- name: Run dead code detection
46+
run: |
47+
vulture --min-confidence 80 \
48+
--exclude "DocLoader/,sirius/,lib/capellaAPI/,build/,dist/" \
49+
. .vulture_whitelist.py || true
50+
# Report but don't fail - dead code detection is informational
51+
52+
duplicate-code:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v4
56+
57+
- name: Setup Node.js (for jscpd)
58+
uses: actions/setup-node@v4
59+
with:
60+
node-version: '20'
61+
62+
- name: Install jscpd
63+
run: npm install -g jscpd
64+
65+
- name: Run duplicate code detection
66+
run: |
67+
jscpd --min-lines 20 --min-tokens 50 \
68+
--ignore "DocLoader/**,sirius/**,lib/capellaAPI/**,build/**,dist/**" \
69+
--reporters console \
70+
. || true
71+
# Report but don't fail - duplicate detection is informational

.jscpd.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"threshold": 0,
3+
"reporters": ["html", "console", "json"],
4+
"ignore": [
5+
"**/node_modules/**",
6+
"**/.git/**",
7+
"**/.idea/**",
8+
"**/build/**",
9+
"**/dist/**",
10+
"**/__pycache__/**",
11+
"**/*.min.js",
12+
"**/*.pyc",
13+
"**/DocLoader/**",
14+
"**/sirius/**",
15+
"**/lib/capellaAPI/**"
16+
],
17+
"min-lines": 20,
18+
"min-tokens": 50,
19+
"format": "python",
20+
"output": "./reports/jscpd"
21+
}

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ repos:
3131
- id: isort
3232
args: ["--profile", "black"]
3333

34+
# Dead code detection
35+
- repo: https://github.com/jendrikseipp/vulture
36+
rev: v2.11
37+
hooks:
38+
- id: vulture
39+
args: [--min-confidence, "80", --exclude, "DocLoader/,sirius/,lib/capellaAPI/,build/,dist/"]
40+
41+
# Duplicate code detection
42+
- repo: https://github.com/juscilan/jscpd-pre-commit
43+
rev: v1.0.0
44+
hooks:
45+
- id: jscpd
46+
args: [--min-lines, "20", --min-tokens, "50", --reporters, "console"]
47+
3448
# AGENTS.md validation
3549
- repo: local
3650
hooks:

.vulture_whitelist.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Vulture whitelist for TAF
2+
# Add false positives here that vulture incorrectly flags as dead code
3+
4+
# Framework entry points (called dynamically)
5+
testrunner.main
6+
setUp
7+
tearDown
8+
setUpClass
9+
tearDownClass
10+
11+
# SDK client methods (called via reflection)
12+
SDKClient.__init__
13+
SDKClient.connect
14+
SDKClient.disconnect
15+
16+
# Test input methods (called via TestInputSingleton)
17+
TestInput.parse_params
18+
19+
# REST API methods (called dynamically)
20+
RestConnection.get_pools_default
21+
RestConnection.get_nodes
22+
RestConnection.create_bucket
23+
24+
# Decorator-registered functions
25+
task.async_task

0 commit comments

Comments
 (0)