Add and apply ESLint spacing rules

For now we're only adding rules related to spacing and double quotes,
following the same rules we use in Ruby, which are the same rules
CoffeeScript followed when compiling these files.

We're also using the recommended ESLint rules, which will warn us about
many JavaScript common pitfalls, the `strict` rule which enforces using
strict mode, and the `no-console` rule, which will prevent us from
shipping code meant for debugging.

Although it's arguably more common to use the JSON format to define
these rules, I've chosen YAML because it's the format we use in all our
linters.
This commit is contained in:
Javi Martín
2019-07-02 16:42:28 +02:00
parent ec5af1f1bc
commit 5211f47842
64 changed files with 119 additions and 104 deletions

67
.eslintrc.yml Normal file
View File

@@ -0,0 +1,67 @@
env:
browser: true
es6: false
extends: "eslint:recommended"
globals:
$: readonly
App: readonly
annotator: readonly
c3: readonly
CKEDITOR: readonly
L: readonly
Turbolinks: readonly
parserOptions:
ecmaVersion: 5
rules:
array-bracket-spacing: error
block-spacing: error
brace-style: error
comma-spacing: error
computed-property-spacing: error
curly: error
eol-last: error
func-call-spacing: error
indent:
- error
- 2
key-spacing: error
keyword-spacing: error
linebreak-style: error
lines-between-class-members: error
no-console: error
no-multi-spaces: error
no-multiple-empty-lines:
- error
- max: 1
no-spaced-func: error
no-tabs: error
no-trailing-spaces: error
no-whitespace-before-property: error
object-curly-spacing:
- error
- always
- objectsInObjects: false
padded-blocks:
- error
- never
quotes:
- error
- double
- avoidEscape: true
semi-spacing: error
space-before-blocks: error
space-before-function-paren:
- error
- never
space-in-parens: error
space-infix-ops: error
space-unary-ops: error
spaced-comment:
- error
- always
- markers:
- "="
exceptions:
- "-"
strict: error
switch-colon-spacing: error

View File

@@ -5,3 +5,6 @@ scss:
erblint: erblint:
enabled: true enabled: true
config_file: .erb-lint.yml config_file: .erb-lint.yml
eslint:
enabled: true
config_file: .eslintrc.yml

View File

@@ -44,5 +44,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -14,5 +14,4 @@
}, ".js-participation"); }, ".js-participation");
} }
}; };
}).call(this); }).call(this);

View File

@@ -27,5 +27,4 @@
App.Answers.nestedAnswers(); App.Answers.nestedAnswers();
} }
}; };
}).call(this); }).call(this);

View File

@@ -2,5 +2,4 @@
(function() { (function() {
"use strict"; "use strict";
window.App = {}; window.App = {};
}).call(this); }).call(this);

View File

@@ -116,8 +116,9 @@ var initialize_modules = function() {
App.LegislationAdmin.initialize(); App.LegislationAdmin.initialize();
App.LegislationAllegations.initialize(); App.LegislationAllegations.initialize();
App.Legislation.initialize(); App.Legislation.initialize();
if ( $(".legislation-annotatable").length ) if ($(".legislation-annotatable").length) {
App.LegislationAnnotatable.initialize(); App.LegislationAnnotatable.initialize();
}
App.WatchFormChanges.initialize(); App.WatchFormChanges.initialize();
App.TreeNavigator.initialize(); App.TreeNavigator.initialize();
App.Documentable.initialize(); App.Documentable.initialize();
@@ -135,14 +136,16 @@ var initialize_modules = function() {
App.SendAdminNotificationAlert.initialize(); App.SendAdminNotificationAlert.initialize();
App.ModalDownload.initialize(); App.ModalDownload.initialize();
App.Settings.initialize(); App.Settings.initialize();
if ( $("#js-columns-selector").length ) if ($("#js-columns-selector").length) {
App.ColumnsSelector.initialize(); App.ColumnsSelector.initialize();
}
App.BudgetEditAssociations.initialize(); App.BudgetEditAssociations.initialize();
if ( $("#votation_type_enum_type").length ) if ($("#votation_type_enum_type").length) {
App.Votations.initialize(); App.Votations.initialize();
}
}; };
$(function(){ $(function() {
"use strict"; "use strict";
Turbolinks.enableProgressBar(); Turbolinks.enableProgressBar();

View File

@@ -25,5 +25,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -38,5 +38,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -14,5 +14,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -14,5 +14,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -84,5 +84,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -69,5 +69,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -30,5 +30,4 @@
return ""; return "";
} }
}; };
}).call(this); }).call(this);

View File

@@ -4,7 +4,7 @@
// TODO: This module is complex enough to require its own tests. Rewrite it using Ecma6 class syntax and // TODO: This module is complex enough to require its own tests. Rewrite it using Ecma6 class syntax and
// write tests for this feature after consul has been migrated to Rails 5.1 // write tests for this feature after consul has been migrated to Rails 5.1
(function(){ (function() {
"use strict"; "use strict";
var ProposalGraph = function(url) { var ProposalGraph = function(url) {
@@ -33,7 +33,7 @@
.done(this.draw.bind(this)); .done(this.draw.bind(this));
}; };
ProposalGraph.prototype.refreshGoals = function () { ProposalGraph.prototype.refreshGoals = function() {
return $.ajax({ return $.ajax({
url: this.resourcesUrl, url: this.resourcesUrl,
cache: false, cache: false,
@@ -52,11 +52,11 @@
}); });
}; };
ProposalGraph.prototype.refreshData = function () { ProposalGraph.prototype.refreshData = function() {
return $.ajax({ return $.ajax({
url: this.url, url: this.url,
cache: false, cache: false,
success: function (data) { success: function(data) {
this.parseData(data); this.parseData(data);
}.bind(this), }.bind(this),
data: { data: {
@@ -68,8 +68,8 @@
ProposalGraph.prototype.parseData = function(data) { ProposalGraph.prototype.parseData = function(data) {
var key; var key;
this.xColumnValues = [ ]; this.xColumnValues = [];
this.progressColumnValues = [ this.progressLabel ]; this.progressColumnValues = [this.progressLabel];
for (key in data) { for (key in data) {
if (Object.prototype.hasOwnProperty.call(data, key)) { if (Object.prototype.hasOwnProperty.call(data, key)) {
@@ -87,7 +87,7 @@
return $.ajax({ return $.ajax({
url: this.successfulProposalDataUrl, url: this.successfulProposalDataUrl,
cache: false, cache: false,
success: function (data) { success: function(data) {
this.parseSuccessfulProposalData(data); this.parseSuccessfulProposalData(data);
}.bind(this), }.bind(this),
data: { data: {
@@ -99,7 +99,7 @@
ProposalGraph.prototype.parseSuccessfulProposalData = function(data) { ProposalGraph.prototype.parseSuccessfulProposalData = function(data) {
var key; var key;
this.successfulColumnValues = [ this.successLabel ]; this.successfulColumnValues = [this.successLabel];
for (key in data) { for (key in data) {
if (Object.prototype.hasOwnProperty.call(data, key)) { if (Object.prototype.hasOwnProperty.call(data, key)) {
@@ -113,7 +113,7 @@
return $.ajax({ return $.ajax({
url: this.proposalAchievementsUrl, url: this.proposalAchievementsUrl,
cache: false, cache: false,
success: function (data) { success: function(data) {
this.parseAchievements(data); this.parseAchievements(data);
}.bind(this), }.bind(this),
data: { data: {
@@ -138,7 +138,7 @@
} }
}; };
ProposalGraph.prototype.addXColumnValue = function (value) { ProposalGraph.prototype.addXColumnValue = function(value) {
if (this.xColumnValues.indexOf(value) === -1) { if (this.xColumnValues.indexOf(value) === -1) {
this.xColumnValues.push(value); this.xColumnValues.push(value);
} }
@@ -163,14 +163,14 @@
this.successfulColumnValues this.successfulColumnValues
], ],
colors: colors, colors: colors,
color: function (color, d) { color: function(color, d) {
var achievement; var achievement;
if (d.id === this.successfulColumnValues[0] || !Object.prototype.hasOwnProperty.call(d, "x")) { if (d.id === this.successfulColumnValues[0] || !Object.prototype.hasOwnProperty.call(d, "x")) {
return color; return color;
} }
achievement = this.achievements.find(function (element) { achievement = this.achievements.find(function(element) {
return element.value === this.xColumnValues[d.index + 1]; return element.value === this.xColumnValues[d.index + 1];
}.bind(this)); }.bind(this));
@@ -211,8 +211,8 @@
}, },
tooltip: { tooltip: {
format: { format: {
title: function (d) { title: function(d) {
var achievement = this.achievements.find(function (element) { var achievement = this.achievements.find(function(element) {
return element.value === this.xColumnValues[d + 1]; return element.value === this.xColumnValues[d + 1];
}.bind(this)); }.bind(this));
@@ -227,7 +227,7 @@
}); });
}; };
ProposalGraph.prototype.tickYValues = function () { ProposalGraph.prototype.tickYValues = function() {
var i, var i,
tick = [0], tick = [0],
maximumValue = this.maximumValue === 0 ? this.proposalSuccess : Math.round(this.maximumValue * 1.10), maximumValue = this.maximumValue === 0 ? this.proposalSuccess : Math.round(this.maximumValue * 1.10),
@@ -242,7 +242,7 @@
return tick; return tick;
}; };
ProposalGraph.prototype.tickXValues = function () { ProposalGraph.prototype.tickXValues = function() {
var i, var i,
l, l,
tick = [], tick = [],
@@ -251,7 +251,7 @@
if (this.xColumnValues.length > 1) { if (this.xColumnValues.length > 1) {
tick.push(0); tick.push(0);
for(i = step, l = this.xColumnValues.length - 1; i < l; i += step) { for (i = step, l = this.xColumnValues.length - 1; i < l; i += step) {
tick.push(i); tick.push(i);
} }
} }
@@ -259,7 +259,7 @@
return tick; return tick;
}; };
ProposalGraph.prototype.formatXColumnValues = function () { ProposalGraph.prototype.formatXColumnValues = function() {
var i, l; var i, l;
this.xColumnValues = this.xColumnValues.sort(); this.xColumnValues = this.xColumnValues.sort();
@@ -286,8 +286,8 @@
return this.groupBy === undefined || this.groupBy === "" || this.groupBy === null; return this.groupBy === undefined || this.groupBy === "" || this.groupBy === null;
}; };
$(document).ready(function () { $(document).ready(function() {
$("[data-proposal-graph-url]").each(function () { $("[data-proposal-graph-url]").each(function() {
var graph = new ProposalGraph($(this).data("proposal-graph-url")); var graph = new ProposalGraph($(this).data("proposal-graph-url"));
graph.successfulProposalDataUrl = $(this).data("successful-proposal-graph-url"); graph.successfulProposalDataUrl = $(this).data("successful-proposal-graph-url");
graph.proposalAchievementsUrl = $(this).data("proposal-achievements-url"); graph.proposalAchievementsUrl = $(this).data("proposal-achievements-url");

View File

@@ -166,5 +166,4 @@
$("#" + id).remove(); $("#" + id).remove();
} }
}; };
}).call(this); }).call(this);

View File

@@ -9,5 +9,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -18,5 +18,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -5,5 +5,4 @@
$("#" + resource_id + " .js-flag-actions").html(button).foundation(); $("#" + resource_id + " .js-flag-actions").html(button).foundation();
} }
}; };
}).call(this); }).call(this);

View File

@@ -10,5 +10,4 @@
} }
} }
}; };
}).call(this); }).call(this);

View File

@@ -64,5 +64,4 @@
App.Forms.hideOrShowFieldsAfterSelection(); App.Forms.hideOrShowFieldsAfterSelection();
} }
}; };
}).call(this); }).call(this);

View File

@@ -26,5 +26,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -37,5 +37,4 @@
} }
}; };
}; };
}).call(this); }).call(this);

View File

@@ -114,5 +114,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -15,5 +15,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -171,5 +171,4 @@
$("#new_image_link").removeClass("hide"); $("#new_image_link").removeClass("hide");
} }
}; };
}).call(this); }).call(this);

View File

@@ -11,5 +11,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -16,5 +16,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -22,5 +22,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -33,5 +33,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -229,5 +229,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -7,5 +7,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -29,5 +29,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -128,5 +128,4 @@
return !isNaN(parseFloat(n)) && isFinite(n); return !isNaN(parseFloat(n)) && isFinite(n);
} }
}; };
}).call(this); }).call(this);

View File

@@ -48,5 +48,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -11,5 +11,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -9,5 +9,4 @@
$("#" + id + " .js-moderator-investment-actions:first").hide(); $("#" + id + " .js-moderator-investment-actions:first").hide();
} }
}; };
}).call(this); }).call(this);

View File

@@ -8,5 +8,4 @@
$("#" + id + " .js-moderator-comment-actions").hide(); $("#" + id + " .js-moderator-comment-actions").hide();
} }
}; };
}).call(this); }).call(this);

View File

@@ -9,5 +9,4 @@
$("#" + id + " .js-moderator-debate-actions:first").hide(); $("#" + id + " .js-moderator-debate-actions:first").hide();
} }
}; };
}).call(this); }).call(this);

View File

@@ -8,5 +8,4 @@
$("#" + id + " .js-moderator-proposal-notifications-actions:first").hide(); $("#" + id + " .js-moderator-proposal-notifications-actions:first").hide();
} }
}; };
}).call(this); }).call(this);

View File

@@ -9,5 +9,4 @@
$("#" + id + " .js-moderator-proposals-actions:first").hide(); $("#" + id + " .js-moderator-proposals-actions:first").hide();
} }
}; };
}).call(this); }).call(this);

View File

@@ -43,5 +43,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -17,5 +17,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -45,5 +45,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -10,5 +10,4 @@
App.Questions.nestedQuestions(); App.Questions.nestedQuestions();
} }
}; };
}).call(this); }).call(this);

View File

@@ -29,5 +29,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -7,5 +7,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -7,5 +7,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -14,5 +14,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -7,5 +7,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -34,5 +34,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -9,7 +9,7 @@ var initialize_stats_modules = function() {
App.Stats.initialize(); App.Stats.initialize();
}; };
$(function(){ $(function() {
"use strict"; "use strict";
$(document).ready(initialize_stats_modules); $(document).ready(initialize_stats_modules);

View File

@@ -33,5 +33,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -34,5 +34,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -30,5 +30,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -44,5 +44,4 @@
App.TagAutocomplete.init_autocomplete(); App.TagAutocomplete.init_autocomplete();
} }
}; };
}).call(this); }).call(this);

View File

@@ -22,5 +22,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -39,5 +39,4 @@
} }
} }
}; };
}).call(this); }).call(this);

View File

@@ -5,5 +5,4 @@
$(".initialjs-avatar").initial(); $(".initialjs-avatar").initial();
} }
}; };
}).call(this); }).call(this);

View File

@@ -33,5 +33,4 @@
App.ValuationBudgetInvestmentForm.showFeasibilityFieldsOnChange(); App.ValuationBudgetInvestmentForm.showFeasibilityFieldsOnChange();
} }
}; };
}).call(this); }).call(this);

View File

@@ -53,5 +53,4 @@
}); });
} }
}; };
}).call(this); }).call(this);

View File

@@ -20,5 +20,4 @@
App.Votes.hoverize("div.comment-footer"); App.Votes.hoverize("div.comment-footer");
} }
}; };
}).call(this); }).call(this);

View File

@@ -29,5 +29,4 @@
}); });
} }
}; };
}).call(this); }).call(this);