From 92fa5054d7fc58c527d6076578532d98e193f9a8 Mon Sep 17 00:00:00 2001 From: Marius Dumitru Florea <marius@xwiki.com> Date: Wed, 10 Dec 2014 15:17:06 +0200 Subject: [PATCH] [misc] Fix yuicompressor default config and run JSHint on the tree webjar. * Use the .min suffix in the default yuicompressor configuration because it's a best practice. * Add support for running JSHint on JavaScript code at build time. * Fix JSHint errors in the job and tree webjars * Use strict JavaScript in the job and tree webjars --- xwiki-platform-core/pom.xml | 24 +++++++++++++++---- .../xwiki-platform-job-webjar/pom.xml | 4 ++++ .../src/main/resources/jobRunner.js | 3 ++- .../xwiki-platform-tree-webjar/pom.xml | 7 ++++++ .../src/main/resources/tree.js | 19 ++++++++------- .../xwiki-platform-web/pom.xml | 2 ++ .../xwiki-platform-wysiwyg-war/pom.xml | 2 ++ 7 files changed, 46 insertions(+), 15 deletions(-) diff --git a/xwiki-platform-core/pom.xml b/xwiki-platform-core/pom.xml index 4cf844a1eef..cfa77fb7f72 100644 --- a/xwiki-platform-core/pom.xml +++ b/xwiki-platform-core/pom.xml @@ -339,17 +339,31 @@ <exclude>**/*.min.*</exclude> </excludes> <outputDirectory>${webjar.contentDirectory}</outputDirectory> - <!-- Don't overwrite the original version. --> - <nosuffix>false</nosuffix> - <suffix>.min</suffix> </configuration> </execution> </executions> <configuration> <skip>${xwiki.minification.skip}</skip> + <!-- We prefer to use the JSHint Maven Plugin because it gives us more control over the validation rules. --> <jswarn>false</jswarn> - <!-- Overwrite the resource files with the minimized version. --> - <nosuffix>true</nosuffix> + <!-- The default suffix uses the dash as separator (-min) but we prefer the dot (.min) because it is + currently more widely used in the JavaScript world. --> + <suffix>.min</suffix> + </configuration> + </plugin> + <plugin> + <groupId>com.cj.jshintmojo</groupId> + <artifactId>jshint-maven-plugin</artifactId> + <version>1.3.0</version> + <executions> + <execution> + <goals> + <goal>lint</goal> + </goals> + </execution> + </executions> + <configuration> + <globals>require,define</globals> </configuration> </plugin> <plugin> diff --git a/xwiki-platform-core/xwiki-platform-job/xwiki-platform-job-webjar/pom.xml b/xwiki-platform-core/xwiki-platform-job/xwiki-platform-job-webjar/pom.xml index 3cc20ee6006..0598b0f34d0 100644 --- a/xwiki-platform-core/xwiki-platform-job/xwiki-platform-job-webjar/pom.xml +++ b/xwiki-platform-core/xwiki-platform-job/xwiki-platform-job-webjar/pom.xml @@ -45,6 +45,10 @@ </dependencies> <build> <plugins> + <plugin> + <groupId>com.cj.jshintmojo</groupId> + <artifactId>jshint-maven-plugin</artifactId> + </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <executions> diff --git a/xwiki-platform-core/xwiki-platform-job/xwiki-platform-job-webjar/src/main/resources/jobRunner.js b/xwiki-platform-core/xwiki-platform-job/xwiki-platform-job-webjar/src/main/resources/jobRunner.js index 9fbd1fc148b..fd3d89699de 100644 --- a/xwiki-platform-core/xwiki-platform-job/xwiki-platform-job-webjar/src/main/resources/jobRunner.js +++ b/xwiki-platform-core/xwiki-platform-job/xwiki-platform-job-webjar/src/main/resources/jobRunner.js @@ -1,4 +1,5 @@ define(['jquery'], function($) { + 'use strict'; var createCallback = function(config, promise) { var answerJobQuestion = function(data) { // 'this' is the job status. @@ -62,5 +63,5 @@ define(['jquery'], function($) { }; return this; - } + }; }); diff --git a/xwiki-platform-core/xwiki-platform-tree/xwiki-platform-tree-webjar/pom.xml b/xwiki-platform-core/xwiki-platform-tree/xwiki-platform-tree-webjar/pom.xml index 0d3a940cfda..c0bd6d2dfa2 100644 --- a/xwiki-platform-core/xwiki-platform-tree/xwiki-platform-tree-webjar/pom.xml +++ b/xwiki-platform-core/xwiki-platform-tree/xwiki-platform-tree-webjar/pom.xml @@ -57,6 +57,13 @@ </dependencies> <build> <plugins> + <plugin> + <groupId>com.cj.jshintmojo</groupId> + <artifactId>jshint-maven-plugin</artifactId> + <configuration> + <options>laxbreak,expr</options> + </configuration> + </plugin> <plugin> <groupId>org.lesscss</groupId> <artifactId>lesscss-maven-plugin</artifactId> diff --git a/xwiki-platform-core/xwiki-platform-tree/xwiki-platform-tree-webjar/src/main/resources/tree.js b/xwiki-platform-core/xwiki-platform-tree/xwiki-platform-tree-webjar/src/main/resources/tree.js index 8369448c217..135f7263561 100644 --- a/xwiki-platform-core/xwiki-platform-tree/xwiki-platform-tree-webjar/src/main/resources/tree.js +++ b/xwiki-platform-core/xwiki-platform-tree/xwiki-platform-tree-webjar/src/main/resources/tree.js @@ -1,4 +1,5 @@ define(['jquery', 'JobRunner', 'jsTree'], function($, JobRunner) { + 'use strict'; // Fix the regular expression used by jsTree to escape special characters in CSS selectors. It is mainly used to be // able to find a tree node by its id using Element#querySelector. We overwrite the default value used by jsTree in // order to add the following special characters: ?`. @@ -33,7 +34,7 @@ define(['jquery', 'JobRunner', 'jsTree'], function($, JobRunner) { node.data = {validChildren: validChildren}; } nestedCallback(children); - } + }; } var childrenURL = node.data && node.data.childrenURL; parameters = parameters || {}; @@ -73,9 +74,9 @@ define(['jquery', 'JobRunner', 'jsTree'], function($, JobRunner) { return true; }; - var canCopyNodes = function(nodes) {return canPerformBatchOperation(nodes, 'Copy')}; - var canCutNodes = function(nodes) {return canPerformBatchOperation(nodes, 'Move')}; - var canRemoveNodes = function(nodes) {return canPerformBatchOperation(nodes, 'Delete')}; + var canCopyNodes = function(nodes) {return canPerformBatchOperation(nodes, 'Copy');}; + var canCutNodes = function(nodes) {return canPerformBatchOperation(nodes, 'Move');}; + var canRemoveNodes = function(nodes) {return canPerformBatchOperation(nodes, 'Delete');}; var validateOperation = function (operation, node, parent, position, more) { // The operation can be 'create_node', 'rename_node', 'delete_node', 'move_node' or 'copy_node'. @@ -108,7 +109,7 @@ define(['jquery', 'JobRunner', 'jsTree'], function($, JobRunner) { var position = paginationElement.parent().children().index(paginationElement[0]); tree.delete_node(paginationNode); $.each(children, function(index) { - var selectFirstChild = index == 0 && tree.element.hasClass('jstree-no-links'); + var selectFirstChild = index === 0 && tree.element.hasClass('jstree-no-links'); tree.create_node(parent, this, position + index, selectFirstChild && function(firstChild) { tree.select_node(firstChild); }); @@ -237,8 +238,8 @@ define(['jquery', 'JobRunner', 'jsTree'], function($, JobRunner) { // Make sure the parameters are not modified by the event listeners. data.parameters = $.extend(true, {}, parameters || {}); tree.element.trigger('xtree.contextMenu.' + action, data); - } - } + }; + }; var prepareNodeTemplate = function(parent, template) { var defaultTemplate = { @@ -346,7 +347,7 @@ define(['jquery', 'JobRunner', 'jsTree'], function($, JobRunner) { }, execute: function(action, node, params) { var url = node.data && node.data[action + 'URL']; - var params = params || {}; + params = params || {}; if (!url) { url = this.element.attr('data-url'); params.action = action; @@ -547,7 +548,7 @@ define(['jquery', 'JobRunner', 'jsTree'], function($, JobRunner) { // }).each(function() { - $(this).jstree($.extend(true, getDefaultParams($(this)), params || {})) + $(this).jstree($.extend(true, getDefaultParams($(this)), params || {})); $.extend($.jstree.reference(this), customTreeAPI, {jobRunner: createJobRunner(this)}); }); }; diff --git a/xwiki-platform-core/xwiki-platform-web/pom.xml b/xwiki-platform-core/xwiki-platform-web/pom.xml index e5ad5f68e52..44f139f81ad 100644 --- a/xwiki-platform-core/xwiki-platform-web/pom.xml +++ b/xwiki-platform-core/xwiki-platform-web/pom.xml @@ -52,6 +52,8 @@ <!-- Don't output in the default webapp location, since the war plugin will overwrite the files in there with the original, uncompressed ones. --> <webappDirectory>${project.build.directory}/minimized</webappDirectory> + <!-- We don't need the suffix (.min) because the minified files are put in a separate folder. --> + <nosuffix>true</nosuffix> <excludes> <!-- Exclude already minified files --> <exclude>**/*-min.js</exclude> diff --git a/xwiki-platform-core/xwiki-platform-wysiwyg/xwiki-platform-wysiwyg-war/pom.xml b/xwiki-platform-core/xwiki-platform-wysiwyg/xwiki-platform-wysiwyg-war/pom.xml index dc8d369ea01..bfe7fedd6db 100644 --- a/xwiki-platform-core/xwiki-platform-wysiwyg/xwiki-platform-wysiwyg-war/pom.xml +++ b/xwiki-platform-core/xwiki-platform-wysiwyg/xwiki-platform-wysiwyg-war/pom.xml @@ -141,6 +141,8 @@ <configuration> <sourceDirectory>${xwe.directory}/stylesheets</sourceDirectory> <outputDirectory>${xwe.directory}/stylesheets</outputDirectory> + <!-- Overwrite the CSS files with the minified version. --> + <nosuffix>true</nosuffix> <aggregations> <aggregation> <removeIncluded>true</removeIncluded> -- GitLab