Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/py_modules/code_projects/check_code_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def set_versions():
gnat_version = run("gnat", "--version").partition('\n')[0]
gnat_prove_version = run("gnatprove", "--version").partition('\n')[0]
gprbuild_version = run("gprbuild", "--version").partition('\n')[0]
except:
except Exception:
gcc_version = "<unknown>" if gcc_version is None else gcc_version
gnat_version = "<unknown>" if gnat_version is None else gnat_version
gnat_prove_version = "<unknown>" if gnat_prove_version is None else gnat_prove_version
Expand Down Expand Up @@ -153,7 +153,7 @@ def cleanup_project(language, project_filename, main_file):

try:
ref_block_check = checks.BlockCheck.from_json_file()
except:
except Exception:
pass

if ref_block_check is not None and not force_checks:
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/ts/areas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ export class LabArea extends Area {

this.button.addEventListener('click', () => {
this.button.classList.toggle('active');
if (this.container.style.display == '' ||
this.container.style.display == 'block') {
if (this.container.style.display === '' ||
this.container.style.display === 'block') {
this.container.style.display = 'none';
} else {
this.container.style.display = 'block';
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/ts/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ export function getLanguages(files: ResourceList): string {
* @returns {UnparsedSwitches} switches.
*/
export function getUnparsedSwitches(rawSwitches: string): UnparsedSwitches {
const parsed = JSON.parse(rawSwitches);
let parsed;
try {
parsed = JSON.parse(rawSwitches);
} catch {
throw new Error(`Failed to parse switches JSON: ${rawSwitches}`);
}
const switches: UnparsedSwitches = {Builder: [], Compiler: []};
for (const k in switches) {
if (k in parsed) {
Expand Down Expand Up @@ -131,7 +136,7 @@ export function parseSwitches(switches: UnparsedSwitches): ParsedSwitches {
* @returns {Array<string>} the filenames of each potential 'main' file.
*/
export function findMains(files: ResourceList): Array<string> {
if (files.length == 1) return [files[0].basename];
if (files.length === 1) return [files[0].basename];
const mains: Array<string> = [];
const fileNames = new Set(files.map((f) => f.basename));
for (const f of files) {
Expand All @@ -158,7 +163,7 @@ export function findMains(files: ResourceList): Array<string> {
* file extension removed.
*/
export function getMain(files: ResourceList, main: string): string {
if (main == '') {
if (main === '') {
const potentialMains = findMains(files);
if (potentialMains.length == 1) {
main = potentialMains[0];
Expand All @@ -168,7 +173,7 @@ export function getMain(files: ResourceList, main: string): string {
}
}
main = main.split('.')[0];
if (main == '') return '';
if (main === '') return '';
return `for Main use ("${main}");`;
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/ts/sandbox-redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export function sandboxRedirect(): void {
const cookieValue = cookies.get(cookieName) as string;
const cookieReferenceValue = "true";

if (cookieValue != cookieReferenceValue) {
if (cookieValue !== cookieReferenceValue) {
const passw = prompt("Enter site password:")

if (passw != "Ada") {
if (passw !== "Ada") {
const msg = 'You have reached learn-sandbox, the learn testing site. ' +
'This is reserved for testers only. You will be directed to the main ' +
'learn.adacore.com site after pressing OK.';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class ServerWorker {

/**
* Delay function
* @param {number} ms - Number of milliseconds to delay-+
* @param {number} ms - Number of milliseconds to delay
* @returns {Promise<unknown>} - A promise to await
*/
public static delay(ms: number): Promise<unknown> {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const RELOAD_CONFIRM_MSG =

export const DOWNLOAD_TOOLTIP = 'Download source files';
export const DOWNLOAD_MAINTENANCE =
'The download functionilty is currently undergoing maintenance';
'The download functionality is currently undergoing maintenance';
// const SETTINGS_TOOLTIP = 'Modify settings for this editor';

export const SETTINGS_TABBED_EDITOR_LABEL =
Expand Down
58 changes: 38 additions & 20 deletions frontend/src/ts/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Widget {
// Parse files
const files = getElemsByClass(this.container, 'file');
// Check to make sure we have files in the widget
if (files.length == 0) {
if (files.length === 0) {
throw Error('Malformed widget: No files present.');
}
for (const file of files) {
Expand Down Expand Up @@ -148,7 +148,7 @@ class Widget {

// Get tabbed view status from cookie
const cookieTabbedView = cookies.get('tabbed_view') as string;
const tabbedView = (cookieTabbedView != 'false');
const tabbedView = (cookieTabbedView !== 'false');

// attach handlers to the settings bar items
const tabSetting =
Expand Down Expand Up @@ -184,7 +184,7 @@ class Widget {
const themeSetting =
this.getElem('settings-bar', 'theme-setting') as HTMLInputElement;
// Set checkbox according to value from cookie
themeSetting.checked = (cookieTheme == 'dark');
themeSetting.checked = (cookieTheme === 'dark');
this.setTheme(cookieTheme);

themeSetting.addEventListener('change', () => {
Expand Down Expand Up @@ -220,7 +220,13 @@ class Widget {
dlButton.addEventListener('click', async () => {
this.outputArea.reset();
const files = this.collectResources();
const switches = JSON.parse(this.container.dataset.switches as string);
let switches;
try {
switches = JSON.parse(this.container.dataset.switches as string);
} catch {
this.outputArea.addError(Strings.INTERNAL_ERROR_MESSAGE);
return;
}
const activeSwitches: UnparsedSwitches = {
Builder: switches['Builder'],
Compiler: this.getActiveCompilerSwitches()};
Expand Down Expand Up @@ -380,18 +386,22 @@ class Widget {
'compiler-switch-help-info')[0];
d.addEventListener('click', () => {
if (! d.classList.contains('disabled')) {
d.innerHTML = '';
d.textContent = '';
d.classList.add('disabled');
}
});

b.addEventListener('click', () => {
d.innerHTML = '<b>' + switchName + '</b>: ' +
b.title + '<br/>' +
'<div class="compiler-switch-help-info-click-remove">(' +
Strings.COMPILER_SWITCH_REMOVE_HELP_MESSAGE +
')</div>';

d.textContent = '';
const bold = document.createElement('b');
bold.textContent = switchName;
d.appendChild(bold);
d.appendChild(document.createTextNode(': ' + b.title));
d.appendChild(document.createElement('br'));
const helpDiv = document.createElement('div');
helpDiv.classList.add('compiler-switch-help-info-click-remove');
helpDiv.textContent = '(' + Strings.COMPILER_SWITCH_REMOVE_HELP_MESSAGE + ')';
d.appendChild(helpDiv);
d.classList.remove('disabled');
});
}
Expand All @@ -403,7 +413,7 @@ class Widget {
*/
private setTheme(themeStr : string) : void {
let theme = EditorTheme.Light;
if (themeStr == 'dark') {
if (themeStr === 'dark') {
theme = EditorTheme.Dark;
}

Expand Down Expand Up @@ -474,7 +484,14 @@ class Widget {

const files = this.collectResources();

const switches = JSON.parse(this.container.dataset.switches as string);
let switches;
try {
switches = JSON.parse(this.container.dataset.switches as string);
} catch {
this.outputArea.addError(Strings.INTERNAL_ERROR_MESSAGE);
this.outputArea.showSpinner(false);
return;
}
switches['Compiler'] = this.getActiveCompilerSwitches();

const serverData: RunProgram.TSData = {
Expand Down Expand Up @@ -555,7 +572,7 @@ class Widget {

// Lines that contain a sloc are clickable:
const cb = (): void => {
if (window.getSelection()?.toString() == '') {
if (window.getSelection()?.toString() === '') {
view.header.scrollIntoView(true);
view.header.click();
// Jump to corresponding line
Expand All @@ -567,7 +584,7 @@ class Widget {

// If the message if of type info, addInfo
// Otherwise, addMsg
if (msgType == 'info') {
if (msgType === 'info') {
homeArea.addInfo(outMsg, cb);
} else {
homeArea.addMsg(outMsg, cb);
Expand All @@ -594,7 +611,7 @@ class Widget {
}

if (data.completed) {
if (data.status != 0) {
if (data.status !== 0) {
this.outputArea.addError(Strings.EXIT_STATUS_LABEL +
': ' + data.status);
}
Expand Down Expand Up @@ -716,13 +733,14 @@ export function widgetFactory(widgets: Array<HTMLDivElement>): void {
console.error('Error:', error);

// clear the offending element to remove any processing that was done
element.innerHTML = '';
element.textContent = '';

// add an error message to the page in its place
const errorDiv = document.createElement('div');
errorDiv.innerHTML = '<p>An error has occured processing this widget.' +
Strings.INTERNAL_ERROR_MESSAGE + '</p>';

const errorP = document.createElement('p');
errorP.textContent = 'An error has occured processing this widget.' +
Strings.INTERNAL_ERROR_MESSAGE;
errorDiv.appendChild(errorP);
element.appendChild(errorDiv);
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/ts/dom-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('getElemsByTag', () => {
c.classList.add('diff-class');
parent.appendChild(c);

it('should return an array with the elems that have the class', () => {
it('should return an array with the elems that have the tag', () => {
const elems = getElemsByTag(parent, 'button');
expect(elems).to.have.length(2);
});
Expand Down
Loading