Skip to content

Commit 66ab4ff

Browse files
authored
refactor: Add linters, move to yarn, fix code. (#190)
* refactor: Add linters, move to yarn, fix code. * fix: Allow param reassignments on props.
1 parent 47d4555 commit 66ab4ff

File tree

11 files changed

+2672
-3668
lines changed

11 files changed

+2672
-3668
lines changed

.eslintrc.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
module.exports = {
22
env: {
33
browser: true,
4-
es6: true,
5-
jquery: true,
4+
es2021: true,
65
},
76
extends: [
87
'airbnb-base',
98
],
10-
globals: {
11-
Atomics: 'readonly',
12-
SharedArrayBuffer: 'readonly',
13-
},
149
parserOptions: {
15-
ecmaVersion: 2018,
10+
ecmaVersion: 12,
11+
sourceType: 'module',
1612
},
1713
rules: {
18-
"no-param-reassign": [2, { "props": false }]
14+
'no-param-reassign': [2, { props: false }],
1915
},
2016
};

lms/extractors/base.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
from dataclasses import dataclass
22
import re
3-
from re import IGNORECASE
43
import string
5-
from typing import (
6-
Any, ClassVar, Iterator, List,
7-
Pattern, Sequence, Tuple, Union, cast,
8-
)
4+
from typing import Any, Iterator, List, Sequence, Tuple, Union, cast
95

106
from werkzeug.datastructures import FileStorage
117

@@ -23,7 +19,7 @@ class File:
2319

2420

2521
class Extractor:
26-
UPLOAD_TITLE: ClassVar[Pattern] = re.compile(r'Upload\s+(\d+)', IGNORECASE)
22+
UPLOAD_TITLE = re.compile(r'Upload\s+(\d+)', re.IGNORECASE)
2723

2824
def __init__(self, to_extract: FileStorage):
2925
self.to_extract = to_extract

lms/lmsweb/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ class AdminCommentTextView(AdminModelView):
557557
webapp,
558558
name='LMS',
559559
template_mode='bootstrap3',
560-
index_view=MyAdminIndexView(),
560+
index_view=MyAdminIndexView(), # NOQA
561561
)
562562

563563
for m in ALL_MODELS:

lms/static/comments.js

+13-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const DEFAULT_COMMENTED_LINE_COLOR = '#fab3b0';
22
const FLAKE_COMMENTED_LINE_COLOR = '#fac4c3';
33
const HOVER_LINE_STYLE = '1px solid #0d0d0f';
44

5-
65
function markLine(target, color) {
76
if (target.dataset && target.dataset.marked === 'true') { return; }
87
if (target.dataset && target.dataset.vimbackground === 'true') { return; }
@@ -12,11 +11,13 @@ function markLine(target, color) {
1211
function hoverLine(targets, hover) {
1312
const [lineTarget, addCommentTarget] = targets;
1413
if (lineTarget.dataset && lineTarget.dataset.vimbackground === 'true') { return; }
15-
let parsedColor = (
16-
(hover === true) ? HOVER_LINE_STYLE :
17-
(hover === false ? 'none' : hover)
18-
)
19-
let commentOpacity = (hover === true) ? '1' : '0';
14+
const commentOpacity = (hover === true) ? '1' : '0';
15+
let parsedColor = hover;
16+
if (hover === true) {
17+
parsedColor = HOVER_LINE_STYLE;
18+
} else if (hover === false) {
19+
parsedColor = 'none';
20+
}
2021
lineTarget.style.border = parsedColor;
2122
addCommentTarget.style.opacity = commentOpacity;
2223
}
@@ -27,8 +28,7 @@ function isUserGrader() {
2728
}
2829

2930
function formatCommentData(commentData) {
30-
let changedCommentText = commentData.text;
31-
changedCommentText = `<span class="comment-author">${commentData.author_name}:</span> ${commentData.text}`
31+
let changedCommentText = `<span class="comment-author">${commentData.author_name}:</span> ${commentData.text}`;
3232
if (isUserGrader()) {
3333
const deleteButton = `<i class="fa fa-trash grader-delete" aria-hidden="true" data-commentid="${commentData.id}" onclick="deleteComment(${window.fileId}, ${commentData.id});"></i>`;
3434
changedCommentText = `${deleteButton} ${changedCommentText}`;
@@ -56,7 +56,7 @@ function addCommentToLine(line, commentData) {
5656
$(commentElement).popover();
5757
}
5858
if (commentData.is_auto) {
59-
markLine(commentElement[0], FLAKE_COMMENTED_LINE_COLOR);
59+
markLine(commentElement[0], FLAKE_COMMENTED_LINE_COLOR);
6060
} else {
6161
markLine(commentElement[0], DEFAULT_COMMENTED_LINE_COLOR);
6262
commentElement[0].dataset.marked = true;
@@ -73,7 +73,6 @@ function treatComments(comments) {
7373
});
7474
}
7575

76-
7776
function pullComments(fileId, callback) {
7877
const url = `/comments?act=fetch&fileId=${fileId}`;
7978
const xhr = new XMLHttpRequest();
@@ -88,15 +87,15 @@ function pullComments(fileId, callback) {
8887
xhr.send('');
8988
}
9089

91-
9290
function updateOpenedSpans(currentSpans, line) {
9391
/* Because we have each line wrapped in it's own span, we must close
9492
* all the opened spans in this specific line and re-open them in the next
9593
* line. This function help us to manage the state of open span tags.
9694
*/
9795
let isCatching = false;
9896
let phrase = '';
99-
for (const c of line) {
97+
for (let i = 0; i < line.length; i += 1) {
98+
const c = line.length[i];
10099
if (c === '>') {
101100
isCatching = false;
102101
phrase = `<${phrase}>`;
@@ -114,9 +113,8 @@ function updateOpenedSpans(currentSpans, line) {
114113
}
115114
}
116115

117-
118116
function addLineSpansToPre(items) {
119-
let openSpans = [];
117+
const openSpans = [];
120118
Array.from(items).forEach((item) => {
121119
const code = item.innerHTML.trim().split('\n');
122120
item.innerHTML = code.map(
@@ -126,13 +124,12 @@ function addLineSpansToPre(items) {
126124
lineContent += '</span>'.repeat(openSpans.length);
127125
const wrappedLine = `<span data-line="${i + 1}" class="line">${lineContent}</span>`;
128126
return wrappedLine;
129-
}
127+
},
130128
).join('\n');
131129
});
132130
window.dispatchEvent(new Event('lines-numbered'));
133131
}
134132

135-
136133
window.markLink = markLine;
137134
window.hoverLine = hoverLine;
138135
window.addCommentToLine = addCommentToLine;

lms/static/grader.js

+4-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function trackFinished(exerciseId, solutionId, element) {
2222
});
2323
}
2424

25-
2625
function sendComment(kind, fileId, line, commentData) {
2726
const xhr = new XMLHttpRequest();
2827
xhr.open('POST', '/comments');
@@ -56,15 +55,14 @@ function visuallyRemoveComment(commentId) {
5655
const hr = commentElement.nextElementSibling || commentElement.previousElementSibling;
5756
if (hr === null) {
5857
lineElement.dataset.marked = false;
59-
window.markLine(lineElement, "none");
58+
window.markLine(lineElement, 'none');
6059
$(lineElement).popover('dispose');
6160
} else {
6261
hr.parentNode.removeChild(hr);
6362
commentElement.parentNode.removeChild(commentElement);
6463
}
6564
}
6665

67-
6866
function deleteComment(fileId, commentId) {
6967
const xhr = new XMLHttpRequest();
7068
const url = `/comments?act=delete&fileId=${fileId}&commentId=${commentId}`;
@@ -88,12 +86,10 @@ function sendNewComment(...commentData) {
8886
return sendComment('text', ...commentData);
8987
}
9088

91-
9289
function sendExistsComment(...commentData) {
9390
return sendComment('id', ...commentData);
9491
}
9592

96-
9793
function trackDragAreas(lineItems, addCommentItems) {
9894
function findElementsToMark(e) {
9995
const span = (e.target.nodeType === 3) ? e.target.parentNode : e.target;
@@ -141,7 +137,6 @@ function trackDragAreas(lineItems, addCommentItems) {
141137
});
142138
}
143139

144-
145140
function trackDraggables(elements) {
146141
Array.from(elements).forEach((item) => {
147142
item.addEventListener('dragstart', (e) => {
@@ -150,28 +145,25 @@ function trackDraggables(elements) {
150145
});
151146
}
152147

153-
154148
function focusTextArea(lineNumber) {
155149
const target = document.querySelector(`textarea[data-line='${lineNumber}']`);
156-
target.focus({preventScroll: true});
150+
target.focus({ preventScroll: true });
157151
}
158152

159-
160153
function trackTextArea(lineNumber) {
161154
const target = `textarea[data-line='${lineNumber}']`;
162155
const popoverElement = `.grader-add[data-line='${lineNumber}']`;
163156
$(target).keydown((ev) => {
164-
if ((ev.which == 10 || ev.which == 13) && ev.ctrlKey) { // CTRL + ENTER
157+
if ((ev.which === 10 || ev.which === 13) && ev.ctrlKey) { // CTRL + ENTER
165158
sendNewComment(window.fileId, lineNumber, ev.target.value);
166159
$(popoverElement).popover('hide');
167-
} else if (ev.key == 'Escape') {
160+
} else if (ev.key === 'Escape') {
168161
ev.preventDefault();
169162
$(popoverElement).popover('hide');
170163
}
171164
});
172165
}
173166

174-
175167
function registerNewCommentPopover(element) {
176168
const lineNumber = element.dataset.line;
177169
const addCommentString = 'הערה חדשה לשורה';
@@ -187,7 +179,6 @@ function registerNewCommentPopover(element) {
187179
});
188180
}
189181

190-
191182
function addNewCommentButtons(elements) {
192183
Array.from(elements).forEach((item) => {
193184
const newNode = document.createElement('span');
@@ -200,7 +191,6 @@ function addNewCommentButtons(elements) {
200191
$('[data-toggle=popover]').popover();
201192
}
202193

203-
204194
window.deleteComment = deleteComment;
205195
window.sendExistsComment = sendExistsComment;
206196
window.addEventListener('lines-numbered', () => {

0 commit comments

Comments
 (0)