Skip to content

Commit 2601ae2

Browse files
committed
Apply remarks from decaffeinate to the new javascript files
This commit applies the suggestions from decaffeinate to the newly generated files so they are easier to read. The code still feels a little weird though. Suivi #3034
1 parent 9678892 commit 2601ae2

File tree

11 files changed

+128
-216
lines changed

11 files changed

+128
-216
lines changed

app/assets/javascripts/application.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
/*
2-
* decaffeinate suggestions:
3-
* DS102: Remove unnecessary code created because of implicit returns
4-
* DS207: Consider shorter variations of null checks
5-
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
6-
*/
71
//= require jquery2
82
//= require jquery_ujs
93
//= require jquery.autocomplete
@@ -15,7 +9,7 @@
159
//= require markitup-markdown
1610
//= require_tree .
1711

18-
const $ = window.jQuery;
12+
$ = window.jQuery;
1913

2014
$("body").on("ajax:success", "form[data-remote]", function(e, data) {
2115
if (data && data.notice) {
@@ -25,7 +19,7 @@ $("body").on("ajax:success", "form[data-remote]", function(e, data) {
2519
$("#nb_votes").text(data.nb_votes);
2620
}
2721
if (!$(this).data("hidden")) {
28-
return $(this)
22+
$(this)
2923
.parent()
3024
.hide();
3125
}
@@ -34,7 +28,7 @@ $("body").on("ajax:success", "form[data-remote]", function(e, data) {
3428
$(".markItUp").markItUp(window.markItUpSettings);
3529

3630
$("a.hit_counter[data-hit]").each(function() {
37-
return (this.href = "/redirect/" + $(this).data("hit"));
31+
this.href = "/redirect/" + $(this).data("hit");
3832
});
3933

4034
// Ready to moule
@@ -49,7 +43,7 @@ $("textarea, #form_answers input").keypress(function(event) {
4943
.find("input[value=Prévisualiser]")
5044
.next("input[type=submit]")
5145
.hide();
52-
return $(this).off(event);
46+
$(this).off(event);
5347
});
5448

5549
// Add/Remove dynamically links in the news form
@@ -94,7 +88,7 @@ $("article.news .edited_by").each(function() {
9488
if (nb > 3) {
9589
const was = field.html();
9690
field.html(`<a>${nb} personnes</a>`);
97-
return field.one("click", () => field.html(was));
91+
field.one("click", () => field.html(was));
9892
}
9993
});
10094

@@ -136,7 +130,7 @@ $("#redaction .link, #redaction .paragraph").lockableEditionInPlace();
136130

137131
// Tags
138132
$.fn.autocompleter = function() {
139-
this.each(function() {
133+
return this.each(function() {
140134
const input = $(this);
141135
return input.autocomplete(input.data("url"), {
142136
multiple: true,
@@ -158,14 +152,14 @@ $(".tag_in_place")
158152
.editionInPlace();
159153
$(".add_tag, .remove_tag")
160154
.click(function() {
161-
return $(this)
155+
$(this)
162156
.blur()
163157
.parents("form")
164158
.data({ hidden: "true" });
165159
})
166160
.parents("form")
167161
.on("ajax:success", function() {
168-
return $(this)
162+
$(this)
169163
.find("input")
170164
.attr({ disabled: "disabled" });
171165
});
@@ -198,7 +192,7 @@ Raccourcis clavier : <ul>
198192
});
199193

200194
$("#account_user_attributes_avatar").change(function() {
201-
if (window.URL != null) {
195+
if (!window.URL) {
202196
return;
203197
}
204198
const url = window.URL.createObjectURL(this.files[0]);
@@ -214,5 +208,4 @@ $("button.more").click(function() {
214208
.next(".more_actions")
215209
.show();
216210
$(this).hide();
217-
return false;
218211
});

app/assets/javascripts/chat.js

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
/*
2-
* decaffeinate suggestions:
3-
* DS101: Remove unnecessary use of Array.from
4-
* DS102: Remove unnecessary code created because of implicit returns
5-
* DS205: Consider reworking code to avoid use of IIFEs
6-
* DS207: Consider shorter variations of null checks
7-
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
8-
*/
91
//= require push
102

11-
const $ = window.jQuery;
3+
$ = window.jQuery;
124

135
class Chat {
146
constructor(board) {
@@ -31,15 +23,13 @@ class Chat {
3123
this.board.find("form").submit(this.postMessage);
3224
this.totoz_type = $.cookie("totoz-type");
3325
this.totoz_url = $.cookie("totoz-url") || "https://totoz.eu/img/";
34-
for (var right of Array.from(this.board.find(".board-right"))) {
26+
for (var right of this.board.find(".board-right")) {
3527
this.norlogize(right);
3628
}
37-
for (var left of Array.from(
38-
this.board
39-
.find(".board-left time")
40-
.get()
41-
.reverse()
42-
)) {
29+
for (var left of this.board
30+
.find(".board-left time")
31+
.get()
32+
.reverse()) {
4333
this.norlogize_left(left);
4434
}
4535
this.board
@@ -73,33 +63,23 @@ class Chat {
7363
.find(".board-left:last .norloge")
7464
.click(this.norloge);
7565
this.inboxContainer.scrollTop(this.inbox.height());
76-
for (right of Array.from(this.inbox.find(".board-right:last"))) {
66+
for (right of this.inbox.find(".board-right:last")) {
7767
this.norlogize(right);
7868
}
79-
return (() => {
80-
const result = [];
81-
for (var left of Array.from(this.inbox.find(".board-left time:last"))) {
82-
result.push(this.norlogize_left(left));
83-
}
84-
return result;
85-
})();
69+
for (var left of this.inbox.find(".board-left time:last")) {
70+
this.norlogize_left(left);
71+
}
8672
} else {
8773
this.inbox
8874
.prepend(msg.message)
8975
.find(".board-left:first .norloge")
9076
.click(this.norloge);
91-
for (right of Array.from(this.inbox.find(".board-right:first"))) {
77+
for (right of this.inbox.find(".board-right:first")) {
9278
this.norlogize(right);
9379
}
94-
return (() => {
95-
const result1 = [];
96-
for (var left of Array.from(
97-
this.inbox.find(".board-left time:first")
98-
)) {
99-
result1.push(this.norlogize_left(left));
100-
}
101-
return result1;
102-
})();
80+
for (var left of this.inbox.find(".board-left time:first")) {
81+
this.norlogize_left(left);
82+
}
10383
}
10484
}
10585

@@ -144,7 +124,7 @@ class Chat {
144124
}
145125
const value = this.input.val();
146126
const range = this.input.caret();
147-
if (range.start == null) {
127+
if (!range.start) {
148128
range.start = 0;
149129
range.end = 0;
150130
}
@@ -173,9 +153,7 @@ class Chat {
173153
const orig = escape(this.data);
174154
let html = "";
175155
while ((matches = r.exec(orig))) {
176-
var [match, datematch, timematch, minutes, index] = Array.from(
177-
matches
178-
);
156+
var [match, datematch, timematch, minutes, index] = matches;
179157
if (index) {
180158
switch (index.substr(0, 1)) {
181159
case ":":
@@ -246,7 +224,7 @@ class Chat {
246224
const orig = escape(this.data);
247225
let html = "";
248226
while ((matches = totoz.exec(orig))) {
249-
var [title, name] = Array.from(matches);
227+
var [title, name] = matches;
250228
var stop = matches.index;
251229
html =
252230
html +
@@ -340,10 +318,8 @@ class Chat {
340318
this.totoz.append(totoz);
341319
}
342320
const position = $(event.target).position();
343-
const [x, y] = Array.from([
344-
position.left,
345-
position.top + event.target.offsetHeight
346-
]);
321+
const x = position.left;
322+
const y = position.top + event.target.offsetHeight;
347323
return totoz.css({
348324
"z-index": "15",
349325
display: "block",

app/assets/javascripts/edition_in_place.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
/*
2-
* decaffeinate suggestions:
3-
* DS101: Remove unnecessary use of Array.from
4-
* DS102: Remove unnecessary code created because of implicit returns
5-
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
6-
*/
7-
const $ = window.jQuery;
1+
$ = window.jQuery;
82

93
class EditionInPlace {
104
constructor(el, edit) {
@@ -41,7 +35,7 @@ class EditionInPlace {
4135
cantEdit() {
4236
this.el.trigger("in_place:cant_edit", this.xhr);
4337
this.button().click(this.loadForm);
44-
return (this.xhr = null);
38+
this.xhr = null;
4539
}
4640

4741
showForm() {
@@ -51,7 +45,7 @@ class EditionInPlace {
5145
form.find(".markItUp").markItUp(window.markItUpSettings);
5246
form.submit(this.submitForm);
5347
this.el.trigger("in_place:form", this.xhr);
54-
return (this.xhr = null);
48+
this.xhr = null;
5549
}
5650

5751
reset(event) {
@@ -79,29 +73,29 @@ class EditionInPlace {
7973
const messages = [];
8074
for (var attribute in response.errors) {
8175
var errors = response.errors[attribute];
82-
for (message of Array.from(errors)) {
76+
for (message of errors) {
8377
messages.push(message);
8478
}
8579
}
8680
if (messages.length === 1) {
8781
error.text("Erreur : " + messages[0]);
8882
} else {
8983
error.text("Erreurs :");
90-
for (message of Array.from(messages)) {
84+
for (message of messages) {
9185
error.append($("<li>").append(message));
9286
}
9387
}
9488
error.show();
9589
} catch (error1) {}
9690
this.el.trigger("in_place:error", this.xhr);
97-
return (this.xhr = null);
91+
this.xhr = null;
9892
}
9993

10094
success() {
10195
this.el = $(this.xhr.responseText).replaceAll(this.el);
10296
this.button().click(this.loadForm);
10397
this.el.trigger("in_place:success", this.xhr);
104-
return (this.xhr = null);
98+
this.xhr = null;
10599
}
106100
}
107101

app/assets/javascripts/lockable_edition_in_place.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
/*
2-
* decaffeinate suggestions:
3-
* DS102: Remove unnecessary code created because of implicit returns
4-
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
5-
*/
6-
const $ = window.jQuery;
1+
$ = window.jQuery;
72

83
$.fn.lockableEditionInPlace = function() {
94
return $(this)
105
.on("in_place:form", function() {
116
const self = $(this);
127
self.data({ cancel: self.find(".cancel").data("url") });
13-
return self.data({
8+
self.data({
149
token: self.find('input[name="authenticity_token"]').serialize()
1510
});
1611
})
1712
.on("in_place:reset", function() {
1813
const self = $(this);
19-
return $.ajax({
14+
$.ajax({
2015
url: self.data("cancel"),
2116
type: "post",
2217
data: self.data("token")

app/assets/javascripts/nested_fields.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
/*
2-
* decaffeinate suggestions:
3-
* DS102: Remove unnecessary code created because of implicit returns
4-
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
5-
*/
6-
const $ = window.jQuery;
1+
$ = window.jQuery;
72

83
class NestedFields {
94
constructor(el, parent, nested, text, tag, attributes) {
@@ -33,15 +28,15 @@ class NestedFields {
3328
})
3429
})
3530
);
36-
return $(`#add_${this.nested}`).click(this.add_item);
31+
$(`#add_${this.nested}`).click(this.add_item);
3732
}
3833

3934
bind_item(item, counter) {
4035
const it = $(item);
4136
it.append(
4237
`<button type="button" class="remove">Supprimer ce ${this.text} </button>`
4338
);
44-
return it.children(".remove").click(() => {
39+
it.children(".remove").click(() => {
4540
if (counter) {
4641
const name = `${this.parent}[${
4742
this.nested

app/assets/javascripts/popup.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
/*
2-
* decaffeinate suggestions:
3-
* DS101: Remove unnecessary use of Array.from
4-
* DS102: Remove unnecessary code created because of implicit returns
5-
* DS205: Consider reworking code to avoid use of IIFEs
6-
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
7-
*/
8-
const $ = window.jQuery;
1+
$ = window.jQuery;
92

103
// Popup management: on click on event element, hide / show popup
114
$(".popup-event").click(function() {
@@ -25,18 +18,13 @@ $(".popup-event").click(function() {
2518
}
2619
// Give new popup display status to all listeners
2720
const listners = popup.data("popup-listner-ids");
28-
return (() => {
29-
const result = [];
30-
for (var listner of Array.from(listners.split(" "))) {
31-
var listnerElement = $(`#${listner}`);
32-
if (showPopup) {
33-
result.push(listnerElement.attr(`data-popup-${popupId}-shown`, ""));
34-
} else {
35-
result.push(
36-
listnerElement.removeAttr(`data-popup-${popupId}-shown`, "")
37-
);
38-
}
21+
22+
for (var listner of listners.split(" ")) {
23+
var listnerElement = $(`#${listner}`);
24+
if (showPopup) {
25+
listnerElement.attr(`data-popup-${popupId}-shown`, "");
26+
} else {
27+
listnerElement.removeAttr(`data-popup-${popupId}-shown`, "");
3928
}
40-
return result;
41-
})();
29+
}
4230
});

0 commit comments

Comments
 (0)