From 6b99022a028ee5ae1accf890ec6bc26e5af770ab Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Thu, 5 Oct 2017 16:42:08 +0200 Subject: [PATCH] linter: Add rule against using inline event handlers. --- docs/code-style.md | 5 ----- tools/linter_lib/custom_check.py | 7 +++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/code-style.md b/docs/code-style.md index 679a6b07f0..89ee642211 100644 --- a/docs/code-style.md +++ b/docs/code-style.md @@ -308,11 +308,6 @@ Don't use the tag name in a selector unless you have to. In other words, use `.foo` instead of `span.foo`. We shouldn't have to care if the tag type changes in the future. -Don't use inline event handlers (`onclick=`, etc. attributes). Instead, -attach a jQuery event handler -(`$('#foo').on('click', function () {...})`) when the DOM is ready -(inside a `$(function () {...})` block). - ### Python - Scripts should start with `#!/usr/bin/env python3` and not diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index 528cdec4c2..2e88285b0e 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -430,6 +430,13 @@ def build_custom_checkers(by_lang): {'pattern': '\Walt=["\']{{ ?["\']', 'description': "alt argument should be enclosed by _().", }, + {'pattern': r'\bon\w+ ?=', + 'description': "Don't use inline event handlers (onclick=, etc. attributes) in HTML. Instead," + "attach a jQuery event handler ($('#foo').on('click', function () {...})) when " + "the DOM is ready (inside a $(function () {...}) block).", + 'exclude': set(['templates/zerver/dev_login.html']), + 'good_lines': ["($('#foo').on('click', function () {}"], + 'bad_lines': ["", ""]}, ] # type: RuleList handlebars_rules = html_rules + [ {'pattern': "[<]script",