Skip to content

Commit

Permalink
1245 eslint linting (#1486)
Browse files Browse the repository at this point in the history
* Adds `yarn lint` to `make lint`
* Closes #1245
  • Loading branch information
ColdHeat authored Jun 12, 2020
1 parent a30437c commit c3897f9
Show file tree
Hide file tree
Showing 61 changed files with 321 additions and 357 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ module.exports = {
"sourceType": "module"
},
"rules": {
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
}
};
165 changes: 73 additions & 92 deletions CTFd/themes/admin/assets/js/challenges/challenge.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import $ from "jquery";
import { ezToast } from "core/ezq";
import { ezToast, ezQuery } from "core/ezq";
import { htmlEntities } from "core/utils";
import CTFd from "core/CTFd";
import nunjucks from "nunjucks";

Expand Down Expand Up @@ -90,105 +91,85 @@ function renderSubmissionResponse(response, cb) {
}

$(() => {
$(".preview-challenge").click(function(event) {
$(".preview-challenge").click(function(_event) {
window.challenge = new Object();
$.get(CTFd.config.urlRoot + "/api/v1/challenges/" + CHALLENGE_ID, function(
response
) {
const challenge_data = response.data;
challenge_data["solves"] = null;

$.getScript(
CTFd.config.urlRoot + challenge_data.type_data.scripts.view,
function() {
$.get(
CTFd.config.urlRoot + challenge_data.type_data.templates.view,
function(template_data) {
$("#challenge-window").empty();
const template = nunjucks.compile(template_data);
window.challenge.data = challenge_data;
window.challenge.preRender();

challenge_data["description"] = window.challenge.render(
challenge_data["description"]
);
challenge_data["script_root"] = CTFd.config.urlRoot;

$("#challenge-window").append(template.render(challenge_data));

$(".challenge-solves").click(function(event) {
getsolves($("#challenge-id").val());
});
$(".nav-tabs a").click(function(event) {
event.preventDefault();
$(this).tab("show");
});

// Handle modal toggling
$("#challenge-window").on("hide.bs.modal", function(event) {
$("#submission-input").removeClass("wrong");
$("#submission-input").removeClass("correct");
$("#incorrect-key").slideUp();
$("#correct-key").slideUp();
$("#already-solved").slideUp();
$("#too-fast").slideUp();
});

$("#submit-key").click(function(event) {
event.preventDefault();
$("#submit-key").addClass("disabled-button");
$("#submit-key").prop("disabled", true);
window.challenge.submit(function(data) {
renderSubmissionResponse(data);
}, true);
// Preview passed as true
});

$("#submission-input").keyup(function(event) {
if (event.keyCode == 13) {
$("#submit-key").click();
}
});

$(".input-field").bind({
focus: function() {
$(this)
.parent()
.addClass("input--filled");
$label = $(this).siblings(".input-label");
},
blur: function() {
if ($(this).val() === "") {
$(this)
.parent()
.removeClass("input--filled");
$label = $(this).siblings(".input-label");
$label.removeClass("input--hide");
$.get(
CTFd.config.urlRoot + "/api/v1/challenges/" + window.CHALLENGE_ID,
function(response) {
const challenge_data = response.data;
challenge_data["solves"] = null;

$.getScript(
CTFd.config.urlRoot + challenge_data.type_data.scripts.view,
function() {
$.get(
CTFd.config.urlRoot + challenge_data.type_data.templates.view,
function(template_data) {
$("#challenge-window").empty();
const template = nunjucks.compile(template_data);
window.challenge.data = challenge_data;
window.challenge.preRender();

challenge_data["description"] = window.challenge.render(
challenge_data["description"]
);
challenge_data["script_root"] = CTFd.config.urlRoot;

$("#challenge-window").append(template.render(challenge_data));

$(".nav-tabs a").click(function(event) {
event.preventDefault();
$(this).tab("show");
});

// Handle modal toggling
$("#challenge-window").on("hide.bs.modal", function(_event) {
$("#submission-input").removeClass("wrong");
$("#submission-input").removeClass("correct");
$("#incorrect-key").slideUp();
$("#correct-key").slideUp();
$("#already-solved").slideUp();
$("#too-fast").slideUp();
});

$("#submit-key").click(function(event) {
event.preventDefault();
$("#submit-key").addClass("disabled-button");
$("#submit-key").prop("disabled", true);
window.challenge.submit(function(data) {
renderSubmissionResponse(data);
}, true);
// Preview passed as true
});

$("#submission-input").keyup(function(event) {
if (event.keyCode == 13) {
$("#submit-key").click();
}
}
});

window.challenge.postRender();
window.location.replace(
window.location.href.split("#")[0] + "#preview"
);

$("#challenge-window").modal();
}
);
}
);
});
});

window.challenge.postRender();
window.location.replace(
window.location.href.split("#")[0] + "#preview"
);

$("#challenge-window").modal();
}
);
}
);
}
);
});

$(".delete-challenge").click(function(event) {
$(".delete-challenge").click(function(_event) {
ezQuery({
title: "Delete Challenge",
body: "Are you sure you want to delete {0}".format(
"<strong>" + htmlentities(CHALLENGE_NAME) + "</strong>"
"<strong>" + htmlEntities(window.CHALLENGE_NAME) + "</strong>"
),
success: function() {
CTFd.fetch("/api/v1/challenges/" + CHALLENGE_ID, {
CTFd.fetch("/api/v1/challenges/" + window.CHALLENGE_ID, {
method: "DELETE"
}).then(function(response) {
if (response.success) {
Expand All @@ -203,7 +184,7 @@ $(() => {
event.preventDefault();
const params = $(event.target).serializeJSON(true);

CTFd.fetch("/api/v1/challenges/" + CHALLENGE_ID, {
CTFd.fetch("/api/v1/challenges/" + window.CHALLENGE_ID, {
method: "PATCH",
credentials: "same-origin",
headers: {
Expand Down
6 changes: 3 additions & 3 deletions CTFd/themes/admin/assets/js/challenges/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ export function addFile(event) {
event.preventDefault();
let form = event.target;
let data = {
challenge: CHALLENGE_ID,
challenge: window.CHALLENGE_ID,
type: "challenge"
};
helpers.files.upload(form, data, function(response) {
helpers.files.upload(form, data, function(_response) {
setTimeout(function() {
window.location.reload();
}, 700);
});
}

export function deleteFile(event) {
export function deleteFile(_event) {
const file_id = $(this).attr("file-id");
const row = $(this)
.parent()
Expand Down
6 changes: 3 additions & 3 deletions CTFd/themes/admin/assets/js/challenges/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function deleteFlag(event) {
});
}

export function addFlagModal(event) {
export function addFlagModal(_event) {
$.get(CTFd.config.urlRoot + "/api/v1/flags/types", function(response) {
const data = response.data;
const flag_type_select = $("#flags-create-select");
Expand All @@ -52,7 +52,7 @@ export function addFlagModal(event) {
$("#flag-edit-modal form").submit(function(event) {
event.preventDefault();
const params = $(this).serializeJSON(true);
params["challenge"] = CHALLENGE_ID;
params["challenge"] = window.CHALLENGE_ID;
CTFd.fetch("/api/v1/flags", {
method: "POST",
credentials: "same-origin",
Expand All @@ -65,7 +65,7 @@ export function addFlagModal(event) {
.then(function(response) {
return response.json();
})
.then(function(response) {
.then(function(_response) {
window.location.reload();
});
});
Expand Down
35 changes: 2 additions & 33 deletions CTFd/themes/admin/assets/js/challenges/hints.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
import $ from "jquery";
import CTFd from "core/CTFd";
import { ezQuery, ezAlert } from "core/ezq";

function hint(id) {
return CTFd.fetch("/api/v1/hints/" + id + "?preview=true", {
method: "GET",
credentials: "same-origin",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
});
}

function loadhint(hintid) {
const md = CTFd.lib.markdown();

hint(hintid).then(function(response) {
if (response.data.content) {
ezAlert({
title: "Hint",
body: md.render(response.data.content),
button: "Got it!"
});
} else {
ezAlert({
title: "Error",
body: "Error loading hint!",
button: "OK"
});
}
});
}
import { ezQuery } from "core/ezq";

export function showHintModal(event) {
event.preventDefault();
Expand Down Expand Up @@ -116,7 +85,7 @@ export function deleteHint(event) {
export function editHint(event) {
event.preventDefault();
const params = $(this).serializeJSON(true);
params["challenge"] = CHALLENGE_ID;
params["challenge"] = window.CHALLENGE_ID;

let method = "POST";
let url = "/api/v1/hints";
Expand Down
3 changes: 2 additions & 1 deletion CTFd/themes/admin/assets/js/challenges/new.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CTFd from "core/CTFd";
import nunjucks from "nunjucks";
import $ from "jquery";

window.challenge = new Object();
Expand Down Expand Up @@ -63,7 +64,7 @@ $.get(CTFd.config.urlRoot + "/api/v1/challenges/types", function(response) {
}
});

function createChallenge(event) {
function createChallenge(_event) {
const challenge = $(this)
.find("option:selected")
.data("meta");
Expand Down
14 changes: 7 additions & 7 deletions CTFd/themes/admin/assets/js/challenges/requirements.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ export function addRequirement(event) {
return;
}

CHALLENGE_REQUIREMENTS.prerequisites.push(
window.CHALLENGE_REQUIREMENTS.prerequisites.push(
parseInt(requirements["prerequisite"])
);

const params = {
requirements: CHALLENGE_REQUIREMENTS
requirements: window.CHALLENGE_REQUIREMENTS
};

CTFd.fetch("/api/v1/challenges/" + CHALLENGE_ID, {
CTFd.fetch("/api/v1/challenges/" + window.CHALLENGE_ID, {
method: "PATCH",
credentials: "same-origin",
headers: {
Expand All @@ -38,18 +38,18 @@ export function addRequirement(event) {
});
}

export function deleteRequirement(event) {
export function deleteRequirement(_event) {
const challenge_id = $(this).attr("challenge-id");
const row = $(this)
.parent()
.parent();

CHALLENGE_REQUIREMENTS.prerequisites.pop(challenge_id);
window.CHALLENGE_REQUIREMENTS.prerequisites.pop(challenge_id);

const params = {
requirements: CHALLENGE_REQUIREMENTS
requirements: window.CHALLENGE_REQUIREMENTS
};
CTFd.fetch("/api/v1/challenges/" + CHALLENGE_ID, {
CTFd.fetch("/api/v1/challenges/" + window.CHALLENGE_ID, {
method: "PATCH",
credentials: "same-origin",
headers: {
Expand Down
4 changes: 2 additions & 2 deletions CTFd/themes/admin/assets/js/challenges/tags.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import $ from "jquery";
import CTFd from "core/CTFd";

export function deleteTag(event) {
export function deleteTag(_event) {
const $elem = $(this);
const tag_id = $elem.attr("tag-id");

Expand All @@ -22,7 +22,7 @@ export function addTag(event) {
const tag = $elem.val();
const params = {
value: tag,
challenge: CHALLENGE_ID
challenge: window.CHALLENGE_ID
};

CTFd.api.post_tag_list({}, params).then(response => {
Expand Down
Loading

0 comments on commit c3897f9

Please sign in to comment.