@synergyerp/backend-standards 1.2.0 → 1.3.1
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 +25 -11
- 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
|
@@ -75,10 +75,7 @@ export default tseslint.config(
|
|
|
75
75
|
},
|
|
76
76
|
rules: {
|
|
77
77
|
// NAMING (BACKEND_STANDARDS.md Section 5.1)
|
|
78
|
-
'id-length': [
|
|
79
|
-
'error',
|
|
80
|
-
{ min: 2, max: 50, exceptions: ['i', 'j', 'k', '_'], properties: 'never' },
|
|
81
|
-
],
|
|
78
|
+
'id-length': ['error', { min: 2, max: 50, properties: 'never' }],
|
|
82
79
|
camelcase: ['error', { properties: 'never', ignoreDestructuring: false }],
|
|
83
80
|
'no-restricted-syntax': [
|
|
84
81
|
'error',
|
|
@@ -89,24 +86,37 @@ export default tseslint.config(
|
|
|
89
86
|
},
|
|
90
87
|
{
|
|
91
88
|
selector: "VariableDeclarator[id.name='temp']",
|
|
92
|
-
message:
|
|
93
|
-
"Variable name 'temp' is banned. Use a descriptive name like 'formattedDate'.",
|
|
89
|
+
message: "Variable name 'temp' is banned. Use a descriptive name like 'formattedDate'.",
|
|
94
90
|
},
|
|
95
91
|
{
|
|
96
92
|
selector: "VariableDeclarator[id.name='arr']",
|
|
97
|
-
message:
|
|
98
|
-
"Variable name 'arr' is banned. Use a descriptive name like 'permissions'.",
|
|
93
|
+
message: "Variable name 'arr' is banned. Use a descriptive name like 'permissions'.",
|
|
99
94
|
},
|
|
100
95
|
{
|
|
101
96
|
selector: "VariableDeclarator[id.name='obj']",
|
|
102
|
-
message:
|
|
103
|
-
"Variable name 'obj' is banned. Use a descriptive name like 'config'.",
|
|
97
|
+
message: "Variable name 'obj' is banned. Use a descriptive name like 'config'.",
|
|
104
98
|
},
|
|
105
99
|
{
|
|
106
100
|
selector: "VariableDeclarator[id.name='result']",
|
|
107
101
|
message:
|
|
108
102
|
"Variable name 'result' is banned. Use a descriptive name like 'validationResult'.",
|
|
109
103
|
},
|
|
104
|
+
// ===== PREVENT _-PREFIXED SINGLE-LETTER NAMES (bypassing id-length) =====
|
|
105
|
+
{
|
|
106
|
+
selector:
|
|
107
|
+
'VariableDeclarator[id.name=/^_[a-z]$/], FunctionDeclaration[id.name=/^_[a-z]$/], FunctionExpression[id.name=/^_[a-z]$/]',
|
|
108
|
+
message:
|
|
109
|
+
"Do not use '_'-prefixed single-letter names (e.g. '_d', '_e', '_q'). Use meaningful names like 'date', 'employee', 'query'.",
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
selector: 'ArrowFunctionExpression > Identifier[name=/^_[a-z]$/]:first-child',
|
|
113
|
+
message: "Do not use '_'-prefixed single-letter parameter names. Use meaningful names.",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
selector:
|
|
117
|
+
'FunctionDeclaration > Identifier[name=/^_[a-z]$/]:first-child, FunctionExpression > Identifier[name=/^_[a-z]$/]:first-child',
|
|
118
|
+
message: "Do not use '_'-prefixed single-letter parameter names. Use meaningful names.",
|
|
119
|
+
},
|
|
110
120
|
],
|
|
111
121
|
'unicorn/filename-case': ['error', { case: 'kebabCase' }],
|
|
112
122
|
|
|
@@ -140,7 +150,11 @@ export default tseslint.config(
|
|
|
140
150
|
'@typescript-eslint/no-unsafe-member-access': 'error',
|
|
141
151
|
'@typescript-eslint/no-unused-vars': [
|
|
142
152
|
'error',
|
|
143
|
-
{
|
|
153
|
+
{
|
|
154
|
+
argsIgnorePattern: '^_',
|
|
155
|
+
destructuredArrayIgnorePattern: '^_',
|
|
156
|
+
ignoreRestSiblings: true,
|
|
157
|
+
},
|
|
144
158
|
],
|
|
145
159
|
|
|
146
160
|
// PRETTIER
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synergyerp/backend-standards",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
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 ""
|