feat: add JS-015 architecture rule to enforce confirm_modal over native confirm()
Some checks failed
Some checks failed
Prevents reintroduction of native browser confirm() dialogs by flagging them as architecture errors during pre-commit validation. Points developers to use confirm_modal/confirm_modal_dynamic Jinja2 macros. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -238,6 +238,50 @@ javascript_rules:
|
||||
exceptions:
|
||||
- "utils.js"
|
||||
|
||||
- id: "JS-015"
|
||||
name: "Use confirm_modal macros, not native confirm()"
|
||||
severity: "error"
|
||||
description: |
|
||||
All confirmation dialogs must use the project's confirm_modal or
|
||||
confirm_modal_dynamic Jinja2 macros from shared/macros/modals.html.
|
||||
Never use the native browser confirm() dialog.
|
||||
|
||||
The modal macros provide:
|
||||
- Consistent styled dialogs matching the admin/store theme
|
||||
- Dark mode support
|
||||
- Variant colors (danger=red, warning=yellow, info=blue)
|
||||
- Icon support
|
||||
- Double-confirm pattern for destructive operations
|
||||
|
||||
WRONG (native browser dialog):
|
||||
if (!confirm('Are you sure you want to delete this?')) return;
|
||||
if (!confirm(I18n.t('confirmations.delete'))) return;
|
||||
|
||||
RIGHT (state variable + modal macro):
|
||||
// In JS: add state variable and remove confirm() guard
|
||||
showDeleteModal: false,
|
||||
async deleteItem() {
|
||||
// No confirm() guard — modal already confirmed
|
||||
await apiClient.delete('/admin/items/' + this.item.id);
|
||||
}
|
||||
|
||||
// In template: button sets state, macro shows modal
|
||||
<button @click="showDeleteModal = true">Delete</button>
|
||||
{{ confirm_modal('deleteModal', 'Delete Item', 'Are you sure?',
|
||||
'deleteItem()', 'showDeleteModal', 'Delete', 'Cancel', 'danger') }}
|
||||
|
||||
For dynamic messages (containing JS expressions):
|
||||
{{ confirm_modal_dynamic('deleteModal', 'Delete Item',
|
||||
"'Delete ' + item.name + '?'",
|
||||
'deleteItem()', 'showDeleteModal', 'Delete', 'Cancel', 'danger') }}
|
||||
pattern:
|
||||
file_pattern: "static/**/js/**/*.js"
|
||||
anti_patterns:
|
||||
- "confirm\\("
|
||||
exceptions:
|
||||
- "utils.js"
|
||||
- "vendor/"
|
||||
|
||||
- id: "JS-010"
|
||||
name: "Use PlatformSettings for pagination rows per page"
|
||||
severity: "error"
|
||||
|
||||
Reference in New Issue
Block a user