allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [01/11] allura git commit: [#8039] parse inline JS from html too (jslint did this); .eslintrc file with safe basics; fix some errors
Date Mon, 18 Jan 2016 20:31:37 GMT
Repository: allura
Updated Branches:
  refs/heads/master 26799a11b -> 3c2fee08c


[#8039] parse inline JS from html too (jslint did this); .eslintrc file with safe basics;
fix some errors


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/c8b8ee66
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/c8b8ee66
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/c8b8ee66

Branch: refs/heads/master
Commit: c8b8ee667b681ae81c202b02388d5b292c82e3d9
Parents: 1ba6651
Author: Dave Brondsema <dave@brondsema.net>
Authored: Thu Jan 14 22:05:22 2016 -0500
Committer: Heith Seewald <heiths@gmail.com>
Committed: Mon Jan 18 14:43:55 2016 -0500

----------------------------------------------------------------------
 .eslintrc                                       | 42 ++++++++++++++++++++
 Allura/allura/lib/widgets/discuss.py            |  8 ++--
 .../templates/app_admin_webhooks_list.html      |  4 +-
 .../allura/templates/jinja_master/master.html   |  6 +--
 .../allura/templates/jinja_master/top_nav.html  |  3 +-
 Allura/docs/getting_started/installation.rst    |  2 +-
 AlluraTest/alluratest/validation.py             | 25 ++++++++----
 Dockerfile                                      |  2 +-
 ForgeWiki/forgewiki/nf/wiki/js/browse.js        |  2 -
 ForgeWiki/forgewiki/templates/wiki/master.html  |  5 ++-
 ForgeWiki/forgewiki/wiki_main.py                |  8 ++--
 11 files changed, 76 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/c8b8ee66/.eslintrc
----------------------------------------------------------------------
diff --git a/.eslintrc b/.eslintrc
new file mode 100644
index 0000000..493b774
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,42 @@
+{
+  "rules": {
+    "indent": [2, 4],
+    "no-unused-vars": [2, {"vars": "all", "args": "none"}],
+    "no-console": 0,
+    "semi": [2, "always"],
+    "eqeqeq": 2,
+    "block-scoped-var": 2,
+    "consistent-return": 2,
+    // specify curly brace conventions for all control statements
+    "curly": [2, "all"],
+    // require default case in switch statements
+    "default-case": 2,
+    // disallow use of eval()
+    "no-eval": 2,
+    // disallow adding to native types
+    "no-extend-native": 2,
+    // disallow use of eval()-like methods
+    "no-implied-eval": 2,
+    // disallow this keywords outside of classes or class-like objects
+    "no-invalid-this": 2,
+    // disallow creation of functions within loops
+    "no-loop-func": 2,
+    // disallow declaring the same variable more then once
+    "no-redeclare": 2,
+    // disallow use of the with statement
+    "no-with": 2,
+    // require use of the second argument for parseInt()
+    "radix": 2
+  },
+  "globals": {
+
+  },
+  "parser": "esprima-fb",
+  "env": {
+    "browser": true,
+    "jquery": true
+  },
+  "extends": "eslint:recommended",
+  "plugins": [
+  ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/allura/blob/c8b8ee66/Allura/allura/lib/widgets/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/discuss.py b/Allura/allura/lib/widgets/discuss.py
index 1e3d632..e5ab85c 100644
--- a/Allura/allura/lib/widgets/discuss.py
+++ b/Allura/allura/lib/widgets/discuss.py
@@ -325,20 +325,19 @@ class Post(HierWidget):
                     if (mod === 'Delete' && !confirm('Really delete this post?'))
{
                         return;
                     }
-                    var id_post = $(post).attr('id');
                     $.ajax({
                         type: 'POST',
                         url: this.parentNode.action,
                         data: jQuery(this.parentNode).serialize(),
                         success: function() {
-                            if (mod == 'Delete'){
+                            if (mod === 'Delete'){
                                 $(post).remove();
                             }
-                            else if (mod == 'Approve'){
+                            else if (mod === 'Approve'){
                                 $('a.reply_post, a.shortlink, form.moderate_spam, form.moderate_approve',
post).toggle();
                                 $('div.moderate', post).removeClass('moderate');
                             }
-                            else if (mod == 'Spam'){
+                            else if (mod === 'Spam'){
                                 $(post).remove();
                             }
                         }
@@ -484,7 +483,6 @@ class Thread(HierWidget):
             }
             if (thread_spam.length) {
                 if (allow_moderate.length) {
-                    var cval = $.cookie('_session_id');
                     thread_spam[0].style.display='block';
                 }
             }

http://git-wip-us.apache.org/repos/asf/allura/blob/c8b8ee66/Allura/allura/templates/app_admin_webhooks_list.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/app_admin_webhooks_list.html b/Allura/allura/templates/app_admin_webhooks_list.html
index f61feec..494d720 100644
--- a/Allura/allura/templates/app_admin_webhooks_list.html
+++ b/Allura/allura/templates/app_admin_webhooks_list.html
@@ -55,9 +55,9 @@ $(function() {
     var csrf = $.cookie('_session_id');
     var data = {'webhook': id, '_session_id': csrf};
     var url = $(this).attr('href');
-    var $tr = $(this).parents('tr')
+    var $tr = $(this).parents('tr');
     $.post(url, data, function(data) {
-      if (data['status'] == 'ok') {
+      if (data['status'] === 'ok') {
         $tr.remove();
       } else {
         console.log(data);

http://git-wip-us.apache.org/repos/asf/allura/blob/c8b8ee66/Allura/allura/templates/jinja_master/master.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/master.html b/Allura/allura/templates/jinja_master/master.html
index 52160a8..dbb6dae 100644
--- a/Allura/allura/templates/jinja_master/master.html
+++ b/Allura/allura/templates/jinja_master/master.html
@@ -52,10 +52,6 @@
     <meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
     <title>{% block title %}Your title goes here{% endblock %}</title>
     {{ theme_macros.extra_header(g.theme_href('')) }}
-    <script type="text/javascript">
-        /*jslint onevar: false, nomen: false, evil: true, css: true, plusplus: false, white:
false, forin: true, on: true, immed: false */
-        /*global confirm, alert, unescape, window, jQuery, $, net, COMSCORE */
-    </script>
     {% for blob in g.resource_manager.emit('head_css') %}
         {{ blob }}
     {% endfor %}
@@ -184,7 +180,7 @@
         }).blur(function () {
             $(this).tooltipster('hide');
         });
-    })
+    });
 </script>
 </body>
 </html>

http://git-wip-us.apache.org/repos/asf/allura/blob/c8b8ee66/Allura/allura/templates/jinja_master/top_nav.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/top_nav.html b/Allura/allura/templates/jinja_master/top_nav.html
index c103280..adb5b85 100644
--- a/Allura/allura/templates/jinja_master/top_nav.html
+++ b/Allura/allura/templates/jinja_master/top_nav.html
@@ -52,6 +52,7 @@
     {% do g.register_forge_js('js/build/transpiled.js') %} {# if we do more es6, we'll need
to register this in other places, or maybe even global #}
     <script>
         'use strict';
+        /*global ReactDOM, React, Main, ToggleAddNewTool */
         var _data = {{ h.escape_json(c.project.nav_data(admin_options=True))|safe }};
         $(document).ready(function () {
             $('#toggle-admin-btn').click(function () {
@@ -77,7 +78,7 @@
                 delay: 200,
                 theme: 'tooltipster-light',
                 position: 'top'
-            })
+            });
         });
     </script>
 {% endif %}

http://git-wip-us.apache.org/repos/asf/allura/blob/c8b8ee66/Allura/docs/getting_started/installation.rst
----------------------------------------------------------------------
diff --git a/Allura/docs/getting_started/installation.rst b/Allura/docs/getting_started/installation.rst
index 0e94f2a..9ac052e 100644
--- a/Allura/docs/getting_started/installation.rst
+++ b/Allura/docs/getting_started/installation.rst
@@ -191,7 +191,7 @@ For non-Ubuntu installations see https://nodejs.org/en/download/package-manager/
     (env-allura)~$ curl --silent --location https://deb.nodesource.com/setup_4.x | sudo bash
-
     (env-allura)~$ sudo apt-get install nodejs
     (env-allura)~$ cd ~/src/allura
-    (env-allura)~$ sudo npm install -g broccoli-cli eslint
+    (env-allura)~$ sudo npm install -g broccoli-cli eslint eslint-plugin-html
     (env-allura)~$ npm install
     (env-allura)~$ npm run build
 

http://git-wip-us.apache.org/repos/asf/allura/blob/c8b8ee66/AlluraTest/alluratest/validation.py
----------------------------------------------------------------------
diff --git a/AlluraTest/alluratest/validation.py b/AlluraTest/alluratest/validation.py
index f1a235b..803f489 100644
--- a/AlluraTest/alluratest/validation.py
+++ b/AlluraTest/alluratest/validation.py
@@ -29,6 +29,7 @@ import subprocess
 import json
 import urllib2
 import re
+import pkg_resources
 
 import webtest
 from webtest import TestApp
@@ -187,17 +188,25 @@ def validate_html5_chunk(html):
     return validate_html5(html)
 
 
-def validate_js(html_or_response):
+def validate_js(html_or_response, within_html=False):
     if hasattr(html_or_response, 'body'):
         if html_or_response.status_int != 200:
             return
-        js = html_or_response.body
+        text = html_or_response.body
     else:
-        js = html_or_response
-    fname = dump_to_file('eslint-', js, suffix='.js')
-    p = subprocess.Popen(['eslint', '--no-ignore', fname],
-                         stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-    stdout, stderr = p.communicate(js)
+        text = html_or_response
+    fname = dump_to_file('eslint-', text, suffix='.html' if within_html else '.js')
+    eslintrc = os.path.join(pkg_resources.get_distribution('allura').location, '../.eslintrc')
+    cmd = ['eslint',
+           '-c', eslintrc,  # since we're in a tmp dir
+           '--no-ignore',  # tmp dirs ignored by default
+           ]
+    if within_html:
+        cmd += ['--rule', 'indent: 0']  # inline HTML always has indentation wrong
+        cmd += ['--plugin', 'html']
+    cmd += [fname]
+    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    stdout, stderr = p.communicate()
     if p.returncode == 0:
         os.unlink(fname)
     else:
@@ -209,7 +218,7 @@ def validate_page(html_or_response):
     if Config.instance().validation_enabled('html5'):
         validate_html(html_or_response)
     if Config.instance().validation_enabled('inlinejs'):
-        validate_js(html_or_response)
+        validate_js(html_or_response, within_html=True)
 
 
 class AntiSpamTestApp(TestApp):

http://git-wip-us.apache.org/repos/asf/allura/blob/c8b8ee66/Dockerfile
----------------------------------------------------------------------
diff --git a/Dockerfile b/Dockerfile
index 546731d..6c6c036 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -36,7 +36,7 @@ RUN curl --silent --location https://deb.nodesource.com/setup_4.x | sudo
bash -
     apt-get install --yes nodejs
 
 # only do the global installation here.  All local packages are installed in init-docker-dev.sh,
since they need the shared mount
-RUN npm install -g broccoli-cli eslint
+RUN npm install -g broccoli-cli eslint eslint-plugin-html
 
 # Snapshot generation for SVN (and maybe other SCMs) might fail without this
 RUN locale-gen en_US.UTF-8

http://git-wip-us.apache.org/repos/asf/allura/blob/c8b8ee66/ForgeWiki/forgewiki/nf/wiki/js/browse.js
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/nf/wiki/js/browse.js b/ForgeWiki/forgewiki/nf/wiki/js/browse.js
index 70a5b76..81c0028 100644
--- a/ForgeWiki/forgewiki/nf/wiki/js/browse.js
+++ b/ForgeWiki/forgewiki/nf/wiki/js/browse.js
@@ -17,8 +17,6 @@
        under the License.
 */
 
-/*jslint onevar: false, nomen: false, evil: true, css: true, plusplus: false, white: false,
forin: true */
-/*global alert, unescape, window, jQuery, $, net, COMSCORE */
 var show_deleted, can_delete;
 
 function toggle_deleted(show) {

http://git-wip-us.apache.org/repos/asf/allura/blob/c8b8ee66/ForgeWiki/forgewiki/templates/wiki/master.html
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/templates/wiki/master.html b/ForgeWiki/forgewiki/templates/wiki/master.html
index 9f0ada1..ad03778 100644
--- a/ForgeWiki/forgewiki/templates/wiki/master.html
+++ b/ForgeWiki/forgewiki/templates/wiki/master.html
@@ -36,11 +36,12 @@
 {% block extra_js %}
     <script type="text/javascript">
         $('.post-link').click(function () {
+            var dialog_text;
             var version = $(this).data("dialog-id");
             if (version) {
-                var dialog_text = $(".confirmation_dialog_" + version);
+                dialog_text = $(".confirmation_dialog_" + version);
             } else {
-                var dialog_text = $(".confirmation_dialog");
+                dialog_text = $(".confirmation_dialog");
             }
 
             var modal = $('#lightbox_confirm');

http://git-wip-us.apache.org/repos/asf/allura/blob/c8b8ee66/ForgeWiki/forgewiki/wiki_main.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 339f3b8..aa18d58 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -273,8 +273,8 @@ The wiki uses [Markdown](%s) syntax.
             var link = this;
             var data = {
                 _session_id: $.cookie('_session_id'),
-                subscribe: '1',
-            }
+                subscribe: '1'
+            };
             $.post(this.href, data, function(){
                 $('#messages').notify('Subscribed to wiki.');
                 $('span', link).text('Unsubscribe');
@@ -286,8 +286,8 @@ The wiki uses [Markdown](%s) syntax.
             var link = this;
             var data = {
                 _session_id: $.cookie('_session_id'),
-                unsubscribe: '1',
-            }
+                unsubscribe: '1'
+            };
             $.post(this.href, data, function(){
                 $('#messages').notify('Unsubscribed.');
                 $('span', link).text('Subscribe to wiki');


Mime
View raw message