@synergyerp/backend-standards 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci-template.yml +20 -3
- package/.husky/pre-commit +3 -0
- package/.husky/pre-push +3 -0
- package/eslint.config.js +24 -7
- package/package.json +1 -1
- package/scripts/detect-no-verify.sh +62 -0
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
# This is a TEMPLATE for consumer repos.
|
|
2
|
+
# Copy this to .github/workflows/ci.yml in your project.
|
|
3
|
+
#
|
|
4
|
+
# Consumer repos should USE this as a reference, not directly call it.
|
|
5
|
+
# The actual CI is triggered by the consumer repo's own .github/workflows/ci.yml
|
|
6
|
+
# which installs @synergyerp/backend-standards and runs the same commands.
|
|
7
|
+
#
|
|
8
|
+
# ANTI-BYPASS DESIGN: Local git hooks (Husky) can be skipped with --no-verify.
|
|
9
|
+
# This CI pipeline is the SERVER-SIDE enforcement layer that cannot be bypassed.
|
|
10
|
+
# Every PR is re-validated here regardless of what happened locally.
|
|
11
|
+
|
|
1
12
|
name: CI Pipeline (Template)
|
|
2
13
|
|
|
3
14
|
on:
|
|
@@ -32,11 +43,17 @@ jobs:
|
|
|
32
43
|
key: pnpm-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}
|
|
33
44
|
path: ~/.pnpm-store
|
|
34
45
|
- run: pnpm install --frozen-lockfile
|
|
35
|
-
|
|
36
|
-
-
|
|
37
|
-
|
|
46
|
+
|
|
47
|
+
# SERVER-SIDE ANTI-BYPASS: Validates ALL commit messages in this PR,
|
|
48
|
+
# catching any commits that were made with --no-verify locally.
|
|
49
|
+
# This step runs unconditionally and will fail if any commit in the PR
|
|
50
|
+
# does not meet the conventional commit standard.
|
|
51
|
+
- name: Validate Commit Messages (--no-verify anti-bypass)
|
|
38
52
|
if: github.event_name == 'pull_request'
|
|
39
53
|
run: pnpm exec commitlint --from origin/${{ github.base_ref }} --to HEAD
|
|
54
|
+
|
|
55
|
+
- run: pnpm lint
|
|
56
|
+
- run: pnpm check-modularization
|
|
40
57
|
- run: pnpm check-types
|
|
41
58
|
- run: pnpm format:check
|
|
42
59
|
- run: pnpm test:ci
|
package/.husky/pre-commit
CHANGED
package/.husky/pre-push
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env sh
|
|
2
2
|
. "$(dirname -- "$0")/_/husky.sh"
|
|
3
3
|
|
|
4
|
+
# Detect --no-verify bypass patterns
|
|
5
|
+
sh "$(dirname -- "$0")/../scripts/detect-no-verify.sh"
|
|
6
|
+
|
|
4
7
|
echo "🚀 Running pre-push quality checks..."
|
|
5
8
|
pnpm lint && pnpm check-modularization && pnpm check-types && pnpm test:ci
|
package/eslint.config.js
CHANGED
|
@@ -89,24 +89,37 @@ export default tseslint.config(
|
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
91
|
selector: "VariableDeclarator[id.name='temp']",
|
|
92
|
-
message:
|
|
93
|
-
"Variable name 'temp' is banned. Use a descriptive name like 'formattedDate'.",
|
|
92
|
+
message: "Variable name 'temp' is banned. Use a descriptive name like 'formattedDate'.",
|
|
94
93
|
},
|
|
95
94
|
{
|
|
96
95
|
selector: "VariableDeclarator[id.name='arr']",
|
|
97
|
-
message:
|
|
98
|
-
"Variable name 'arr' is banned. Use a descriptive name like 'permissions'.",
|
|
96
|
+
message: "Variable name 'arr' is banned. Use a descriptive name like 'permissions'.",
|
|
99
97
|
},
|
|
100
98
|
{
|
|
101
99
|
selector: "VariableDeclarator[id.name='obj']",
|
|
102
|
-
message:
|
|
103
|
-
"Variable name 'obj' is banned. Use a descriptive name like 'config'.",
|
|
100
|
+
message: "Variable name 'obj' is banned. Use a descriptive name like 'config'.",
|
|
104
101
|
},
|
|
105
102
|
{
|
|
106
103
|
selector: "VariableDeclarator[id.name='result']",
|
|
107
104
|
message:
|
|
108
105
|
"Variable name 'result' is banned. Use a descriptive name like 'validationResult'.",
|
|
109
106
|
},
|
|
107
|
+
// ===== PREVENT _-PREFIXED SINGLE-LETTER NAMES (bypassing id-length) =====
|
|
108
|
+
{
|
|
109
|
+
selector:
|
|
110
|
+
'VariableDeclarator[id.name=/^_[a-z]$/], FunctionDeclaration[id.name=/^_[a-z]$/], FunctionExpression[id.name=/^_[a-z]$/]',
|
|
111
|
+
message:
|
|
112
|
+
"Do not use '_'-prefixed single-letter names (e.g. '_d', '_e', '_q'). Use meaningful names like 'date', 'employee', 'query'.",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
selector: 'ArrowFunctionExpression > Identifier[name=/^_[a-z]$/]:first-child',
|
|
116
|
+
message: "Do not use '_'-prefixed single-letter parameter names. Use meaningful names.",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
selector:
|
|
120
|
+
'FunctionDeclaration > Identifier[name=/^_[a-z]$/]:first-child, FunctionExpression > Identifier[name=/^_[a-z]$/]:first-child',
|
|
121
|
+
message: "Do not use '_'-prefixed single-letter parameter names. Use meaningful names.",
|
|
122
|
+
},
|
|
110
123
|
],
|
|
111
124
|
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
|
|
112
125
|
|
|
@@ -140,7 +153,11 @@ export default tseslint.config(
|
|
|
140
153
|
'@typescript-eslint/no-unsafe-member-access': 'error',
|
|
141
154
|
'@typescript-eslint/no-unused-vars': [
|
|
142
155
|
'error',
|
|
143
|
-
{
|
|
156
|
+
{
|
|
157
|
+
argsIgnorePattern: '^_',
|
|
158
|
+
destructuredArrayIgnorePattern: '^_',
|
|
159
|
+
ignoreRestSiblings: true,
|
|
160
|
+
},
|
|
144
161
|
],
|
|
145
162
|
|
|
146
163
|
// PRETTIER
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synergyerp/backend-standards",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "SynergyERP backend standards — ESLint, Prettier, commitlint, Husky, TypeScript configs, modularization enforcement, and PR templates.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env sh
|
|
2
|
+
# ============================================================
|
|
3
|
+
# detect-no-verify.sh
|
|
4
|
+
#
|
|
5
|
+
# PURPOSE: Warn developers when --no-verify aliases / config
|
|
6
|
+
# are detected. This script is run in pre-commit and pre-push
|
|
7
|
+
# hooks. It does NOT block git itself (which cannot be done at
|
|
8
|
+
# the OS level), but it:
|
|
9
|
+
# 1. Detects known --no-verify aliases in global/local git config
|
|
10
|
+
# 2. Logs a dated violation entry to .git/no-verify-violations.log
|
|
11
|
+
# 3. Exits non-zero so the hook chain fails loudly
|
|
12
|
+
#
|
|
13
|
+
# The CI pipeline independently re-validates all commit messages
|
|
14
|
+
# via commitlint (see .github/workflows/ci-template.yml), which
|
|
15
|
+
# is the actual server-side enforcement that --no-verify cannot
|
|
16
|
+
# bypass.
|
|
17
|
+
# ============================================================
|
|
18
|
+
|
|
19
|
+
set -e
|
|
20
|
+
|
|
21
|
+
VIOLATIONS=0
|
|
22
|
+
|
|
23
|
+
echo ""
|
|
24
|
+
echo "🛡️ Checking for --no-verify bypass patterns..."
|
|
25
|
+
|
|
26
|
+
# 1. Scan all git aliases in local + global config
|
|
27
|
+
ALL_ALIASES=$(git config --list 2>/dev/null | grep '^alias\.' || true)
|
|
28
|
+
|
|
29
|
+
if echo "$ALL_ALIASES" | grep -qi 'no-verify\|no.verify'; then
|
|
30
|
+
echo ""
|
|
31
|
+
echo "❌ ERROR: A git alias containing --no-verify was found in your git config!"
|
|
32
|
+
echo ""
|
|
33
|
+
echo "$ALL_ALIASES" | grep -i 'no-verify\|no.verify'
|
|
34
|
+
echo ""
|
|
35
|
+
echo " Please remove this alias. The standards require all commits to pass hooks."
|
|
36
|
+
echo " Run: git config --global --unset alias.<name>"
|
|
37
|
+
VIOLATIONS=$((VIOLATIONS + 1))
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
# 2. Check for HUSKY=0 environment variable (bypasses husky hooks entirely)
|
|
41
|
+
if [ "${HUSKY}" = "0" ]; then
|
|
42
|
+
echo ""
|
|
43
|
+
echo "❌ ERROR: HUSKY=0 is set — this bypasses ALL Husky hooks!"
|
|
44
|
+
echo " Unset HUSKY or remove it from your shell profile."
|
|
45
|
+
VIOLATIONS=$((VIOLATIONS + 1))
|
|
46
|
+
fi
|
|
47
|
+
|
|
48
|
+
# 3. Log violations to .git/no-verify-violations.log for auditability
|
|
49
|
+
if [ $VIOLATIONS -gt 0 ]; then
|
|
50
|
+
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
|
51
|
+
LOG_FILE="$(git rev-parse --git-dir)/no-verify-violations.log"
|
|
52
|
+
echo "$TIMESTAMP user=$(git config user.email 2>/dev/null || echo unknown) violations=$VIOLATIONS" >> "$LOG_FILE"
|
|
53
|
+
echo ""
|
|
54
|
+
echo " ☝️ A record of this violation has been written to .git/no-verify-violations.log"
|
|
55
|
+
echo " ☝️ Note: even if you bypass this hook, the CI pipeline will re-run commitlint"
|
|
56
|
+
echo " on every PR and will reject commits that skipped required validation."
|
|
57
|
+
echo ""
|
|
58
|
+
exit 1
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
echo "✅ No --no-verify bypass patterns detected."
|
|
62
|
+
echo ""
|