Patchwork [4,of,4,v2] check-code: check for consistent usage of the websub filter in hgweb templates

login
register
mail settings
Submitter Steven Brown
Date May 16, 2014, 2:47 p.m.
Message ID <ca8ccf1ffbbd0c9f2d2b.1400251635@steve-debian.home>
Download mbox | patch
Permalink /patch/4786/
State Accepted
Commit c26464ce07817ba6d3338b14dd53d4739709abf1
Headers show

Comments

Steven Brown - May 16, 2014, 2:47 p.m.
# HG changeset patch
# User Steven Brown <StevenGBrown@gmail.com>
# Date 1400249080 -28800
#      Fri May 16 22:04:40 2014 +0800
# Node ID ca8ccf1ffbbd0c9f2d2bedca55670a57cdfb5885
# Parent  047159d0c841fe008d1bf7f5d99837f107e974cc
check-code: check for consistent usage of the websub filter in hgweb templates

The changeset description keyword "desc" should be followed by either the
"firstline" filter or the "websub" filter, unless it is part of the raw style.

The web template checks do not apply to the raw style, because the raw style
follows different conventions than the other templates. If raw style checks
are added later, they would most likely be treated as a separate category.
Pierre-Yves David - May 16, 2014, 6 p.m.
On 05/16/2014 07:47 AM, Steven Brown wrote:
> # HG changeset patch
> # User Steven Brown <StevenGBrown@gmail.com>
> # Date 1400249080 -28800
> #      Fri May 16 22:04:40 2014 +0800
> # Node ID ca8ccf1ffbbd0c9f2d2bedca55670a57cdfb5885
> # Parent  047159d0c841fe008d1bf7f5d99837f107e974cc
> check-code: check for consistent usage of the websub filter in hgweb templates

This series looks nice, but we need the tests to be merged somewhere 
else (Patch 1) and the Backward compatibility clarified in Patch 3. 
Before queuing it.

Patch

diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -367,6 +367,16 @@ 
   []
 ]
 
+webtemplatefilters = []
+
+webtemplatepats = [
+  [],
+  [
+    (r'{desc(\|(?!websub|firstline)[^\|]*)*}',
+     'follow desc keyword with either firstline or websub'),
+  ]
+]
+
 checks = [
     ('python', r'.*\.(py|cgi)$', r'^#!.*python', pyfilters, pypats),
     ('test script', r'(.*/)?test-[^.~]*$', '', testfilters, testpats),
@@ -377,6 +387,8 @@ 
     ('layering violation ui in util', r'mercurial/util\.py', '', pyfilters,
      inutilpats),
     ('txt', r'.*\.txt$', '', txtfilters, txtpats),
+    ('web template', r'mercurial/templates/(?!raw).*\.tmpl', '',
+     webtemplatefilters, webtemplatepats),
 ]
 
 def _preparepats():
diff --git a/tests/test-check-code.t b/tests/test-check-code.t
--- a/tests/test-check-code.t
+++ b/tests/test-check-code.t
@@ -284,3 +284,18 @@ 
    > print _(
    don't use % inside _()
   [1]
+
+web templates
+
+  $ mkdir -p mercurial/templates
+  $ cat > mercurial/templates/example.tmpl <<EOF
+  > {desc}
+  > {desc|firstline}
+  > {desc|websub}
+  > EOF
+
+  $ "$check_code" --warnings mercurial/templates/example.tmpl
+  mercurial/templates/example.tmpl:1:
+   > {desc}
+   warning: follow desc keyword with either firstline or websub
+  [1]