Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat files and update lint config #297

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
68c6b91
Reformat devserver with Prettier
RichDom2185 Mar 26, 2024
98b3571
Reformat scripts with Prettier
RichDom2185 Mar 26, 2024
246ad13
Reformat tabs with Prettier
RichDom2185 Mar 26, 2024
d57c4c3
Reformat bundles with Prettier
RichDom2185 Mar 26, 2024
ed00f2c
Reformat config files with Prettier
RichDom2185 Mar 26, 2024
b33035b
Merge branch 'master' of https://github.com/source-academy/modules in…
RichDom2185 Apr 8, 2024
e58323d
Report unused disable directives
RichDom2185 Apr 8, 2024
f0adf32
Revert some Prettier devserver changes
RichDom2185 Apr 8, 2024
0a1c106
Revert some changes
RichDom2185 Apr 11, 2024
790b2cb
Revert some changes
RichDom2185 Apr 11, 2024
74a8d9b
Update .gitignore
RichDom2185 Apr 11, 2024
b24ad87
Revert some changes in scripts
RichDom2185 Apr 11, 2024
77eaa1a
Reformat ModalDiv
RichDom2185 Apr 11, 2024
c440062
Revert some changes in tabs
RichDom2185 Apr 11, 2024
3184411
Revert some changes in tabs
RichDom2185 Apr 11, 2024
b19b3f3
Reformat some files manually
RichDom2185 Apr 11, 2024
e049d79
Revert some changes in bundles
RichDom2185 Apr 11, 2024
1af7840
Reformat sound.test.ts
RichDom2185 Apr 11, 2024
a2caec5
Revert some changes in bundles
RichDom2185 Apr 11, 2024
63ed6ac
Downgrade unused disable directives severity
RichDom2185 Apr 11, 2024
393d095
Revert some changes in bundles
RichDom2185 Apr 11, 2024
690e0c4
Revert some changes in bundles
RichDom2185 Apr 13, 2024
2708100
Fix arrow parens lint
RichDom2185 Apr 13, 2024
7be4131
Enforce member delimiter style
RichDom2185 Apr 13, 2024
ff56592
Make arrow-parens global
RichDom2185 Apr 13, 2024
409eb9b
Use React.FC typing
RichDom2185 Apr 13, 2024
089ce65
Reformat MarkSweep
RichDom2185 Apr 13, 2024
f319466
Standardize operator-linebreak to before
RichDom2185 Apr 13, 2024
91aad7a
Reformat devserver
RichDom2185 Apr 13, 2024
a75a77f
Reformat utils
RichDom2185 Apr 13, 2024
0facb84
Reformat MultiUserController
RichDom2185 Apr 13, 2024
15e7926
Reformat CopyGc
RichDom2185 Apr 13, 2024
b71a002
Reformat canvas_holder
RichDom2185 Apr 13, 2024
c29cfcc
Update tab template
RichDom2185 Apr 13, 2024
9085574
Lint scripts
RichDom2185 Apr 13, 2024
f9c1b5c
Merge branch 'master' into reformat-files-1
RichDom2185 Apr 13, 2024
9755239
Bump actions-gh-pages to v4
RichDom2185 Apr 13, 2024
d3918d6
Reformat buildAll test
RichDom2185 Apr 13, 2024
5011783
Reformat Unity Academy tab
RichDom2185 Apr 13, 2024
7c084cb
Add empty line to EOFs
RichDom2185 Apr 13, 2024
f1d8961
Update submodule to use relative path
RichDom2185 Apr 13, 2024
9ebf333
Merge branch 'master' into reformat-files-1
RichDom2185 Apr 25, 2024
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
2 changes: 1 addition & 1 deletion devserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This server relies on [`Vite`](https://vitejs.dev) to create a server that automatically reloads when it detects file system changes. This allows Source Academy developers to make changes to their tabs without having to use the frontend, and have it render code changes live.

The server is designed to be run using `yarn devserver` from the repository's root directory, hence `vite.config.ts` is not located within this folder.
The server is designed to be run using `yarn devserver` from the repository's root directory, hence `vite.config.ts` is not located within this folder.
2 changes: 1 addition & 1 deletion devserver/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
12 changes: 10 additions & 2 deletions devserver/src/components/ControlButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { AnchorButton, Button, Icon, type IconName, Intent } from '@blueprintjs/core';
import {
AnchorButton,
Button,
Icon,
Intent,
type IconName
} from '@blueprintjs/core';
import React from 'react';

type ButtonOptions = {
Expand Down Expand Up @@ -38,7 +44,9 @@ const ControlButton: React.FC<ControlButtonProps> = ({
...defaultOptions,
...options
};
const iconElement = icon && <Icon icon={icon} color={buttonOptions.iconColor} />;
const iconElement = icon && (
<Icon icon={icon} color={buttonOptions.iconColor} />
);
// Refer to #2417 and #2422 for why we conditionally
// set the button component. See also:
// https://blueprintjs.com/docs/#core/components/button
Expand Down
192 changes: 103 additions & 89 deletions devserver/src/components/Playground.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { Classes, Intent, OverlayToaster, type ToastProps } from '@blueprintjs/core';
import {
Classes,
Intent,
OverlayToaster,
type ToastProps
} from '@blueprintjs/core';
import classNames from 'classnames';
import { SourceDocumentation, getNames, runInContext, type Context } from 'js-slang';
import {
SourceDocumentation,
getNames,
runInContext,
type Context
} from 'js-slang';

// Importing this straight from js-slang doesn't work for whatever reason
import createContext from 'js-slang/dist/createContext';
Expand Down Expand Up @@ -42,9 +52,15 @@ const createContextHelper = () => {
const Playground: React.FC<{}> = () => {
const [dynamicTabs, setDynamicTabs] = React.useState<SideContentTab[]>([]);
const [selectedTabId, setSelectedTab] = React.useState(testTabContent.id);
const [codeContext, setCodeContext] = React.useState<Context>(createContextHelper());
const [editorValue, setEditorValue] = React.useState(localStorage.getItem('editorValue') ?? '');
const [replOutput, setReplOutput] = React.useState<InterpreterOutput | null>(null);
const [codeContext, setCodeContext] = React.useState<Context>(
createContextHelper()
);
const [editorValue, setEditorValue] = React.useState(
localStorage.getItem('editorValue') ?? ''
);
const [replOutput, setReplOutput] = React.useState<InterpreterOutput | null>(
null
);
const [alerts, setAlerts] = React.useState<string[]>([]);

const toaster = React.useRef<OverlayToaster>(null);
Expand All @@ -58,87 +74,89 @@ const Playground: React.FC<{}> = () => {
}
};

const getAutoComplete = useCallback((row: number, col: number, callback: any) => {
getNames(editorValue, row, col, codeContext)
.then(([editorNames, displaySuggestions]) => {
if (!displaySuggestions) {
callback();
return;
}

const editorSuggestions = editorNames.map((editorName: any) => ({
...editorName,
caption: editorName.name,
value: editorName.name,
score: editorName.score ? editorName.score + 1000 : 1000,
name: undefined
}));

const builtins: Record<string, any> = SourceDocumentation.builtins[Chapter.SOURCE_4];
const builtinSuggestions = Object.entries(builtins)
.map(([builtin, thing]) => ({
...thing,
caption: builtin,
value: builtin,
score: 100,
name: builtin,
docHTML: thing.description
const getAutoComplete = useCallback(
(row: number, col: number, callback: any) => {
getNames(editorValue, row, col, codeContext).then(
([editorNames, displaySuggestions]) => {
if (!displaySuggestions) {
callback();
return;
}

const editorSuggestions = editorNames.map((editorName: any) => ({
...editorName,
caption: editorName.name,
value: editorName.name,
score: editorName.score ? editorName.score + 1000 : 1000,
name: undefined
}));

callback(null, [
...builtinSuggestions,
...editorSuggestions
]);
});
}, [editorValue, codeContext]);
const builtins: Record<string, any> =
SourceDocumentation.builtins[Chapter.SOURCE_4];
const builtinSuggestions = Object.entries(builtins).map(
([builtin, thing]) => ({
...thing,
caption: builtin,
value: builtin,
score: 100,
name: builtin,
docHTML: thing.description
})
);

callback(null, [...builtinSuggestions, ...editorSuggestions]);
}
);
},
[editorValue, codeContext]
);

const loadTabs = () => getDynamicTabs(codeContext)
.then((tabs) => {
setDynamicTabs(tabs);
const loadTabs = () =>
getDynamicTabs(codeContext)
.then((tabs) => {
setDynamicTabs(tabs);

const newIds = tabs.map(({ id }) => id);
// If the currently selected tab no longer exists,
// switch to the default test tab
if (!newIds.includes(selectedTabId)) {
setSelectedTab(testTabContent.id);
}
setAlerts(newIds);
})
.catch((error) => {
showToast(errorToast);
console.log(error);
});
const newIds = tabs.map(({ id }) => id);
// If the currently selected tab no longer exists,
// switch to the default test tab
if (!newIds.includes(selectedTabId)) {
setSelectedTab(testTabContent.id);
}
setAlerts(newIds);
})
.catch((error) => {
showToast(errorToast);
console.log(error);
});

const evalCode = () => {
codeContext.errors = [];
// eslint-disable-next-line no-multi-assign
codeContext.moduleContexts = mockModuleContext.moduleContexts = {};

runInContext(editorValue, codeContext)
.then((result) => {
if (codeContext.errors.length > 0) {
showToast(errorToast);
} else {
loadTabs()
.then(() => showToast(evalSuccessToast));
}
runInContext(editorValue, codeContext).then((result) => {
if (codeContext.errors.length > 0) {
showToast(errorToast);
} else {
loadTabs().then(() => showToast(evalSuccessToast));
}

// TODO: Add support for console.log?
if (result.status === 'finished') {
setReplOutput({
type: 'result',
// code: editorValue,
consoleLogs: [],
value: stringify(result.value)
});
} else if (result.status === 'error') {
setReplOutput({
type: 'errors',
errors: codeContext.errors,
consoleLogs: []
});
}
});
// TODO: Add support for console.log?
if (result.status === 'finished') {
setReplOutput({
type: 'result',
// code: editorValue,
consoleLogs: [],
value: stringify(result.value)
});
} else if (result.status === 'error') {
setReplOutput({
type: 'errors',
errors: codeContext.errors,
consoleLogs: []
});
}
});
};

const resetEditor = () => {
Expand All @@ -160,13 +178,8 @@ const Playground: React.FC<{}> = () => {
controlBarProps: {
editorButtons: [
<ControlBarRunButton handleEditorEval={evalCode} key="eval" />,
<ControlBarClearButton onClick={resetEditor}
key="clear"
/>,
<ControlBarRefreshButton
onClick={onRefresh}
key="refresh"
/>
<ControlBarClearButton onClick={resetEditor} key="clear" />,
<ControlBarRefreshButton onClick={onRefresh} key="refresh" />
]
},
replProps: {
Expand All @@ -182,18 +195,19 @@ const Playground: React.FC<{}> = () => {
sideContentProps: {
dynamicTabs: [testTabContent, ...dynamicTabs],
selectedTabId,
onChange: useCallback((newId: string) => {
setSelectedTab(newId);
setAlerts(alerts.filter((id) => id !== newId));
}, [alerts]),
onChange: useCallback(
(newId: string) => {
setSelectedTab(newId);
setAlerts(alerts.filter((id) => id !== newId));
},
[alerts]
),
alerts
}
};

return (
<HotKeys
className={classNames('Playground', Classes.DARK)}
>
<HotKeys className={classNames('Playground', Classes.DARK)}>
<OverlayToaster ref={toaster} />
<Workspace {...workspaceProps} />
</HotKeys>
Expand Down
26 changes: 15 additions & 11 deletions devserver/src/components/Workspace.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FocusStyleManager } from '@blueprintjs/core';
import { type Enable, Resizable, type ResizeCallback } from 're-resizable';
import { Resizable, type Enable, type ResizeCallback } from 're-resizable';
import React from 'react';

import ControlBar, { type ControlBarProps } from './controlBar/ControlBar';
Expand All @@ -10,8 +10,8 @@ import { useDimensions } from './utils/Hooks';

type DispatchProps = {
handleEditorEval: () => void;
handleEditorValueChange: (newValue: string) => void
handlePromptAutocomplete: (row: number, col: number, callback: any) => void
handleEditorValueChange: (newValue: string) => void;
handlePromptAutocomplete: (row: number, col: number, callback: any) => void;
};

type StateProps = {
Expand All @@ -21,9 +21,9 @@ type StateProps = {
replProps: ReplProps;
sideContentHeight?: number;
sideContentIsResizeable?: boolean;
editorValue: string
editorValue: string;

sideContentProps: SideContentProps
sideContentProps: SideContentProps;
};

const rightResizeOnly: Enable = { right: true };
Expand All @@ -40,7 +40,9 @@ const Workspace: React.FC<WorkspaceProps> = (props) => {

const [contentContainerWidth] = useDimensions(contentContainerDiv);

const [sideContentHeight, setSideContentHeight] = React.useState<number | undefined>(undefined);
const [sideContentHeight, setSideContentHeight] = React.useState<
number | undefined
>(undefined);

FocusStyleManager.onlyShowFocusOnTabs();

Expand All @@ -58,8 +60,8 @@ const Workspace: React.FC<WorkspaceProps> = (props) => {
const toggleEditorDividerDisplay: ResizeCallback = (_a, _b, ref) => {
const leftThreshold = 5;
const rightThreshold = 95;
const editorWidthPercentage
= ((ref as HTMLDivElement).clientWidth / contentContainerWidth) * 100;
const editorWidthPercentage =
((ref as HTMLDivElement).clientWidth / contentContainerWidth) * 100;
// update resizable size
if (editorWidthPercentage > rightThreshold) {
leftParentResizable.current!.updateSize({
Expand All @@ -79,8 +81,8 @@ const Workspace: React.FC<WorkspaceProps> = (props) => {
* so that it's bottom border snaps flush with editor's bottom border
*/
const toggleDividerDisplay: ResizeCallback = (_a, _b, ref) => {
maxDividerHeight.current
= sideDividerDiv.current!.clientHeight > maxDividerHeight.current!
maxDividerHeight.current =
sideDividerDiv.current!.clientHeight > maxDividerHeight.current!
? sideDividerDiv.current!.clientHeight
: maxDividerHeight.current;
const resizableHeight = (ref as HTMLDivElement).clientHeight;
Expand Down Expand Up @@ -125,7 +127,9 @@ const Workspace: React.FC<WorkspaceProps> = (props) => {
className="resize-side-content"
enable={bottomResizeOnly}
onResize={toggleDividerDisplay}
onResizeStop={(_a, _b, ref) => setSideContentHeight(ref.clientHeight)}
onResizeStop={(_a, _b, ref) =>
setSideContentHeight(ref.clientHeight)
}
>
<SideContent
sideContentHeight={sideContentHeight}
Expand Down
11 changes: 9 additions & 2 deletions devserver/src/components/controlBar/ControlBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ const ControlBar: React.FC<ControlBarProps> = (props) => {
);

const flowControl = props.flowButtons && (
<div className={classNames('ControlBar_flow', Classes.BUTTON_GROUP)}>{props.flowButtons}</div>
<div className={classNames('ControlBar_flow', Classes.BUTTON_GROUP)}>
{props.flowButtons}
</div>
);

const editingWorkspaceControl = (
<div className={classNames('ControlBar_editingWorkspace', Classes.BUTTON_GROUP)}>
<div
className={classNames(
'ControlBar_editingWorkspace',
Classes.BUTTON_GROUP
)}
>
{props.editingWorkspaceButtons}
</div>
);
Expand Down
18 changes: 10 additions & 8 deletions devserver/src/components/controlBar/ControlBarClearButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { IconNames } from '@blueprintjs/icons';
import ControlButton from '../ControlButton';

type Props = {
onClick: () => void
onClick: () => void;
};

export const ControlBarClearButton = (props: Props) => <Tooltip content="Clear the editor and context">
<ControlButton
label="Clear"
icon={IconNames.Trash}
onClick={props.onClick}
/>
</Tooltip>;
export const ControlBarClearButton = (props: Props) => (
<Tooltip content="Clear the editor and context">
<ControlButton
label="Clear"
icon={IconNames.Trash}
onClick={props.onClick}
/>
</Tooltip>
);
Loading
Loading