Skip to content

Commit 7dd2593

Browse files
authored
Merge pull request #3 from dhwani-ris/develop
Develop
2 parents f5f4595 + 24b6daf commit 7dd2593

File tree

7 files changed

+48
-194
lines changed

7 files changed

+48
-194
lines changed

.pre-commit-hooks.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
files: \.py$
88
pass_filenames: true
99

10-
- id: frappe-translation-check
11-
name: Frappe Translation Wrappers Check
12-
description: Check if user-facing strings are wrapped in translation functions
13-
entry: frappe-pre-commit-translations
14-
language: python
15-
additional_dependencies: [frappe-pre-commit]
16-
files: \.(py|js)$
17-
pass_filenames: true
18-
1910
- id: frappe-sql-security
2011
name: Frappe SQL Security Check
2112
description: Check for SQL injection vulnerabilities and security issues

DEVELOPER.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pip install build twine
1919
```bash
2020
# Test the console scripts
2121
frappe-pre-commit-coding-standards --help
22-
frappe-pre-commit-translations --help
2322
frappe-pre-commit-sql-security --help
2423
frappe-pre-commit-doctype-naming --help
2524

@@ -186,9 +185,6 @@ Follow [Semantic Versioning](https://semver.org/):
186185
# Test coding standards
187186
python scripts/check_coding_standards.py scripts/check_coding_standards.py
188187

189-
# Test translations
190-
python scripts/check_translations.py scripts/check_translations.py
191-
192188
# Test SQL security
193189
python scripts/check_sql_security.py scripts/check_sql_security.py
194190

README.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
## ✨ Features
1010

1111
- 🛡️ **SQL Injection Prevention** - Detect and prevent SQL injection vulnerabilities
12-
- 🌐 **Translation Validation** - Ensure all user-facing strings are properly wrapped for internationalization
1312
- 📏 **Coding Standards** - Enforce Frappe-specific coding conventions and best practices
1413
- 📝 **DocType Naming** - Validate DocType and field naming conventions
1514
-**Fast Execution** - Lightweight checks with minimal dependencies
@@ -76,7 +75,6 @@ pre-commit run --all-files
7675
| Hook ID | Description | Files | Dependencies |
7776
|---------|-------------|-------|--------------|
7877
| `frappe-coding-standards` | General coding standards and best practices | `*.py` | None |
79-
| `frappe-translation-check` | Translation wrapper validation | `*.py`, `*.js` | None |
8078
| `frappe-sql-security` | SQL injection and security checks | `*.py` | None |
8179
| `frappe-doctype-naming` | DocType and field naming conventions | `*.py`, `*.js`, `*.json` | `pyyaml` |
8280

@@ -204,27 +202,6 @@ frappe.db.sql("SELECT * FROM tabUser WHERE name = %s", user_name)
204202
frappe.db.set_value("User", user, "password", frappe.utils.password.encrypt(plain_password))
205203
```
206204

207-
### 🌐 Translation Checks
208-
209-
**Ensures all user-facing strings are wrapped:**
210-
211-
```python
212-
# ❌ Will be flagged
213-
frappe.msgprint("Document saved successfully")
214-
frappe.throw("Invalid email address")
215-
216-
# ✅ Correct approach
217-
frappe.msgprint(_("Document saved successfully"))
218-
frappe.throw(_("Invalid email address"))
219-
```
220-
221-
```javascript
222-
// ❌ Will be flagged
223-
frappe.msgprint("Document saved successfully");
224-
225-
// ✅ Correct approach
226-
frappe.msgprint(__("Document saved successfully"));
227-
```
228205

229206
### 📏 Coding Standards
230207

examples/.pre-commit-config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ repos:
7777
- repo: https://github.com/dhwani-ris/frappe-pre-commit
7878
rev: v1.0.1
7979
hooks:
80-
- id: frappe-translation-check
81-
exclude: hooks\.py$
8280
- id: frappe-sql-security
8381
- id: frappe-doctype-naming
8482
- id: frappe-coding-standards

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "frappe-pre-commit"
7-
version = "1.0.0"
7+
version = "1.0.1"
88
description = "Pre-commit hooks for Frappe Framework coding standards"
99
readme = "README.md"
1010
license = "MIT"

scripts/check_doctype_naming.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,54 @@ def _is_valid_field_label(label):
145145
if not label:
146146
return False
147147

148-
# Should be Title Case
149-
# Examples: "Customer Name", "Item Code", "Posting Date"
148+
# Should be Title Case, but allow for:
149+
# - Numbers (e.g., "Address 1", "Address 2")
150+
# - Special characters like "&", "%", "(", ")", "-" (e.g., "A & B", "Discount %", "Price (USD)")
151+
# - Common prepositions like "of", "in", "at", "to", "for", "with", "by" (e.g., "Area of Address")
152+
# - Abbreviations and acronyms
153+
150154
words = label.split()
151-
return all(word[0].isupper() if word else False for word in words)
155+
if not words:
156+
return False
157+
158+
# Common prepositions that can be lowercase
159+
prepositions = {'of', 'in', 'at', 'to', 'for', 'with', 'by', 'from', 'on', 'up', 'down', 'out', 'off', 'over', 'under'}
160+
161+
for i, word in enumerate(words):
162+
if not word:
163+
continue
164+
165+
# Skip validation for numbers
166+
if word.isdigit():
167+
continue
168+
169+
# Skip validation for standalone special characters like "&", "%", "-", etc.
170+
if word in ['&', '-', '/', '\\', '%', '+', '=']:
171+
continue
172+
173+
# Handle words with parentheses like "(USD)", "(Active)", etc.
174+
if word.startswith('(') and word.endswith(')'):
175+
# Check if the content inside parentheses is valid (all caps or mixed case)
176+
content = word[1:-1] # Remove parentheses
177+
if content.isupper() or content.isalpha():
178+
continue
179+
180+
# Check for invalid patterns
181+
if '_' in word: # No underscores allowed
182+
return False
183+
184+
if word.isupper() and len(word) > 1: # No all caps words (except single letters)
185+
return False
186+
187+
# Allow lowercase for prepositions (except at the beginning)
188+
if i > 0 and word.lower() in prepositions:
189+
continue
190+
191+
# For all other words, first character should be uppercase
192+
if not word[0].isupper():
193+
return False
194+
195+
return True
152196

153197

154198
def main():

scripts/check_translations.py

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)