Skip to content

Commit e87727d

Browse files
authored
Add web linters to Makefile and lint-web.yml GitHub Actions (#614)
* Add lint-web to CI/CD and add additional linters to Makefile (jshint jscpd markuplint) - closes #390 Signed-off-by: Mihai Criveti <[email protected]> * Add lint-web to CI/CD and add additional linters to Makefile (jshint jscpd markuplint) - closes #390 Signed-off-by: Mihai Criveti <[email protected]> * Add lint-web to CI/CD and add additional linters to Makefile (jshint jscpd markuplint) - closes #390 Signed-off-by: Mihai Criveti <[email protected]> * Add lint-web to CI/CD and add additional linters to Makefile (jshint jscpd markuplint) - closes #390 Signed-off-by: Mihai Criveti <[email protected]> * Add lint-web to CI/CD and add additional linters to Makefile (jshint jscpd markuplint) - closes #390 Signed-off-by: Mihai Criveti <[email protected]> * Add lint-web to CI/CD and add additional linters to Makefile (jshint jscpd markuplint) - closes #390 Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: Mihai Criveti <[email protected]>
1 parent e7df209 commit e87727d

File tree

3 files changed

+196
-3
lines changed

3 files changed

+196
-3
lines changed

.github/workflows/lint-web.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# ===============================================================
2+
# 🕸️ Web Lint & Static Analysis - Frontend Code Quality Gate
3+
# ===============================================================
4+
# Authors: Mihai Criveti
5+
# - runs each web linter in its own matrix job for visibility
6+
# - mirrors the actual CLI commands used locally (no `make`)
7+
# - ensures fast-failure isolation: one failure doesn't hide others
8+
# - installs tools per-job without package.json
9+
# - logs are grouped and plain-text for readability
10+
# ---------------------------------------------------------------
11+
12+
name: Web Lint & Static Analysis
13+
14+
on:
15+
push:
16+
branches: ["main"]
17+
pull_request:
18+
branches: ["main"]
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
lint-web:
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
include:
29+
# -------------------------------------------------------
30+
# 🧼 HTML/CSS/JS Linters & Validators
31+
# -------------------------------------------------------
32+
- id: htmlhint
33+
cmd: |
34+
npm install --no-save --legacy-peer-deps htmlhint
35+
npx htmlhint "mcpgateway/templates/*.html"
36+
37+
- id: stylelint
38+
cmd: |
39+
npm install --no-save --legacy-peer-deps stylelint stylelint-config-standard @stylistic/stylelint-config stylelint-order
40+
npx stylelint "mcpgateway/static/*.css"
41+
42+
- id: eslint
43+
cmd: |
44+
npm install --no-save --legacy-peer-deps \
45+
eslint \
46+
eslint-config-standard \
47+
eslint-config-prettier \
48+
eslint-plugin-import \
49+
eslint-plugin-n \
50+
eslint-plugin-prettier \
51+
eslint-plugin-promise \
52+
prettier
53+
npx eslint "mcpgateway/static/*.js"
54+
55+
# -------------------------------------------------------
56+
# 🔒 Security Scanners
57+
# -------------------------------------------------------
58+
- id: retire
59+
cmd: |
60+
npm install --no-save --legacy-peer-deps retire
61+
npx retire --path mcpgateway/static
62+
63+
- id: npm-audit
64+
cmd: |
65+
if [ ! -f package.json ]; then
66+
npm init -y >/dev/null
67+
fi
68+
npm audit --audit-level=high || true
69+
70+
# -------------------------------------------------------
71+
# 🔍 Additional Code Quality Tools
72+
# -------------------------------------------------------
73+
- id: jshint
74+
cmd: |
75+
npm install --no-save --legacy-peer-deps jshint
76+
if [ -f .jshintrc ]; then
77+
npx jshint --config .jshintrc "mcpgateway/static/*.js"
78+
else
79+
npx jshint --esversion=11 "mcpgateway/static/*.js"
80+
fi
81+
82+
- id: jscpd
83+
cmd: |
84+
npm install --no-save --legacy-peer-deps jscpd
85+
npx jscpd "mcpgateway/static/" "mcpgateway/templates/"
86+
87+
# - id: markuplint
88+
# cmd: |
89+
# npm install --no-save --legacy-peer-deps markuplint
90+
# npx markuplint mcpgateway/templates/*
91+
92+
name: ${{ matrix.id }}
93+
runs-on: ubuntu-latest
94+
95+
steps:
96+
# -----------------------------------------------------------
97+
# 0️⃣ Checkout
98+
# -----------------------------------------------------------
99+
- name: ⬇️ Checkout source
100+
uses: actions/checkout@v4
101+
with:
102+
fetch-depth: 1
103+
104+
# -----------------------------------------------------------
105+
# 1️⃣ Node.js Setup
106+
# -----------------------------------------------------------
107+
- name: 📦 Set up Node.js
108+
uses: actions/setup-node@v4
109+
with:
110+
node-version: '20'
111+
112+
# -----------------------------------------------------------
113+
# 2️⃣ Run Linter (install and execute in one step)
114+
# -----------------------------------------------------------
115+
- name: 🔍 Run ${{ matrix.id }}
116+
run: ${{ matrix.cmd }}
117+
118+
# -------------------------------------------------------
119+
# 🐍 Python-based JS Security Scanner (separate job)
120+
# -------------------------------------------------------
121+
nodejsscan:
122+
name: nodejsscan
123+
runs-on: ubuntu-latest
124+
125+
steps:
126+
# -----------------------------------------------------------
127+
# 0️⃣ Checkout
128+
# -----------------------------------------------------------
129+
- name: ⬇️ Checkout source
130+
uses: actions/checkout@v4
131+
with:
132+
fetch-depth: 1
133+
134+
# -----------------------------------------------------------
135+
# 1️⃣ Python Setup
136+
# -----------------------------------------------------------
137+
- name: 🐍 Set up Python
138+
uses: actions/setup-python@v5
139+
with:
140+
python-version: "3.12"
141+
cache: pip
142+
143+
# -----------------------------------------------------------
144+
# 2️⃣ Install nodejsscan
145+
# -----------------------------------------------------------
146+
- name: 🔧 Install nodejsscan
147+
run: |
148+
python3 -m pip install --upgrade pip
149+
pip install nodejsscan
150+
151+
# -----------------------------------------------------------
152+
# 3️⃣ Run nodejsscan
153+
# -----------------------------------------------------------
154+
- name: 🔒 Run nodejsscan
155+
run: |
156+
nodejsscan --directory ./mcpgateway/static

.jshintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"esversion": 11,
3+
"browser": true,
4+
"devel": true,
5+
"string": true,
6+
"globals": {
7+
"console": true,
8+
"window": true,
9+
"document": true,
10+
"fetch": true,
11+
"URLSearchParams": true
12+
}
13+
}

Makefile

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,11 +714,14 @@ tomllint: ## 📑 TOML validation (tomlcheck)
714714
# 🕸️ WEBPAGE LINTERS & STATIC ANALYSIS
715715
# =============================================================================
716716
# help: 🕸️ WEBPAGE LINTERS & STATIC ANALYSIS (HTML/CSS/JS lint + security scans + formatting)
717-
# help: install-web-linters - Install HTMLHint, Stylelint, ESLint, Retire.js & Prettier via npm
717+
# help: install-web-linters - Install HTMLHint, Stylelint, ESLint, Retire.js, Prettier, JSHint, jscpd & markuplint via npm
718718
# help: nodejsscan - Run nodejsscan for JS security vulnerabilities
719719
# help: lint-web - Run HTMLHint, Stylelint, ESLint, Retire.js, nodejsscan and npm audit
720+
# help: jshint - Run JSHint for additional JavaScript analysis
721+
# help: jscpd - Detect copy-pasted code in JS/HTML/CSS files
722+
# help: markuplint - Modern HTML linting with markuplint
720723
# help: format-web - Format HTML, CSS & JS files with Prettier
721-
.PHONY: install-web-linters nodejsscan lint-web format-web
724+
.PHONY: install-web-linters nodejsscan lint-web jshint jscpd markuplint format-web
722725

723726
install-web-linters:
724727
@echo "🔧 Installing HTML/CSS/JS lint, security & formatting tools..."
@@ -731,7 +734,10 @@ install-web-linters:
731734
stylelint stylelint-config-standard @stylistic/stylelint-config stylelint-order \
732735
eslint eslint-config-standard \
733736
retire \
734-
prettier
737+
prettier \
738+
jshint \
739+
jscpd \
740+
markuplint
735741

736742
nodejsscan:
737743
@echo "🔒 Running nodejsscan for JavaScript security vulnerabilities..."
@@ -754,6 +760,24 @@ lint-web: install-web-linters nodejsscan
754760
echo "⚠️ Skipping npm audit: no package.json found"; \
755761
fi
756762

763+
jshint: install-web-linters
764+
@echo "🔍 Running JSHint for JavaScript analysis..."
765+
@if [ -f .jshintrc ]; then \
766+
echo "📋 Using .jshintrc configuration"; \
767+
npx jshint --config .jshintrc mcpgateway/static/*.js || true; \
768+
else \
769+
echo "📋 No .jshintrc found, using defaults with ES11"; \
770+
npx jshint --esversion=11 mcpgateway/static/*.js || true; \
771+
fi
772+
773+
jscpd: install-web-linters
774+
@echo "🔍 Detecting copy-pasted code with jscpd..."
775+
@npx jscpd "mcpgateway/static/" "mcpgateway/templates/" || true
776+
777+
markuplint: install-web-linters
778+
@echo "🔍 Running markuplint for modern HTML validation..."
779+
@npx markuplint mcpgateway/templates/* || true
780+
757781
format-web: install-web-linters
758782
@echo "🎨 Formatting HTML, CSS & JS with Prettier..."
759783
@npx prettier --write "mcpgateway/templates/**/*.html" \

0 commit comments

Comments
 (0)