Skip to content

Commit 493194e

Browse files
committed
Fix Linting
1 parent 62a37aa commit 493194e

File tree

12 files changed

+87
-99
lines changed

12 files changed

+87
-99
lines changed

src/commons/application/actions/SessionActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,4 @@ const SessionActions = createActions('session', {
153153
});
154154

155155
// For compatibility with existing code (actions helper)
156-
export default SessionActions
156+
export default SessionActions;
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { testSaga } from "redux-saga-test-plan"
2-
import WorkspaceActions from "src/commons/workspace/WorkspaceActions"
1+
import { testSaga } from 'redux-saga-test-plan';
2+
import WorkspaceActions from 'src/commons/workspace/WorkspaceActions';
33

4-
import { combineSagaHandlers, createActions } from "../utils"
4+
import { combineSagaHandlers, createActions } from '../utils';
55

66
// Would have used spyOn, but for some reason that doesn't work properly
77
jest.mock('src/commons/sagas/SafeEffects', () => ({
88
...jest.requireActual('src/commons/sagas/SafeEffects'),
99
// Mock wrap saga to just be a passthrough so that the identity
1010
// checking that testSaga uses will pass
1111
wrapSaga: (x: any) => x
12-
}))
12+
}));
1313

1414
test('test combineSagaHandlers', () => {
15-
const mockTakeEveryHandler = jest.fn()
16-
const mockTakeLatestHandler = jest.fn()
17-
const mockTakeLeadingHandler = jest.fn()
15+
const mockTakeEveryHandler = jest.fn();
16+
const mockTakeLatestHandler = jest.fn();
17+
const mockTakeLeadingHandler = jest.fn();
1818

1919
const saga = combineSagaHandlers({
2020
[WorkspaceActions.toggleUsingUpload.type]: mockTakeEveryHandler,
@@ -31,13 +31,13 @@ test('test combineSagaHandlers', () => {
3131
takeEvery: mockTakeEveryHandler,
3232
takeLeading: mockTakeLeadingHandler
3333
}
34-
})
34+
});
3535

3636
testSaga(saga)
3737
.next()
3838
.takeEvery(WorkspaceActions.toggleUsingUpload.type, mockTakeEveryHandler)
3939
.next()
40-
.takeEvery(WorkspaceActions.toggleFolderMode.type, mockTakeEveryHandler)
40+
.takeEvery(WorkspaceActions.toggleFolderMode.type, mockTakeEveryHandler)
4141
.next()
4242
.takeLatest(WorkspaceActions.toggleUsingCse.type, mockTakeLatestHandler)
4343
.next()
@@ -47,23 +47,23 @@ test('test combineSagaHandlers', () => {
4747
.next()
4848
.takeLeading(WorkspaceActions.toggleEditorAutorun.type, mockTakeLeadingHandler)
4949
.next()
50-
.isDone()
51-
})
50+
.isDone();
51+
});
5252

5353
test('createActions', () => {
5454
const actions = createActions('workspace', {
5555
act0: false,
5656
act1: (value: string) => ({ value }),
5757
act2: 525600
58-
})
58+
});
5959

60-
const act0 = actions.act0()
61-
expect(act0.type).toEqual('workspace/act0')
60+
const act0 = actions.act0();
61+
expect(act0.type).toEqual('workspace/act0');
6262

63-
const act1 = actions.act1('test')
64-
expect(act1.type).toEqual('workspace/act1')
65-
expect(act1.payload).toMatchObject({ value: 'test' })
63+
const act1 = actions.act1('test');
64+
expect(act1.type).toEqual('workspace/act1');
65+
expect(act1.payload).toMatchObject({ value: 'test' });
6666

67-
const act2 = actions.act2()
68-
expect(act2.type).toEqual('workspace/act2')
69-
})
67+
const act2 = actions.act2();
68+
expect(act2.type).toEqual('workspace/act2');
69+
});

src/commons/redux/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ export function createActions<BaseName extends string, BaseActions extends Recor
2424
return Object.entries(baseActions).reduce(
2525
(res, [name, func]) => ({
2626
...res,
27-
[name]: typeof func === 'function'
28-
? createAction(`${baseName}/${name}`, (...args: any) => ({ payload: func(...args) }))
29-
: createAction(`${baseName}/${name}`)
27+
[name]:
28+
typeof func === 'function'
29+
? createAction(`${baseName}/${name}`, (...args: any) => ({ payload: func(...args) }))
30+
: createAction(`${baseName}/${name}`)
3031
}),
3132
{} as Readonly<{
3233
[K in keyof BaseActions]: K extends string

src/commons/sagas/PersistenceSaga.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ const PersistenceSaga = combineSagaHandlers({
232232
}
233233
}
234234
},
235-
[actions.persistenceSaveFile.type]: function* ({ payload: { id, name }}) {
235+
[actions.persistenceSaveFile.type]: function* ({ payload: { id, name } }) {
236236
let toastKey: string | undefined;
237237
try {
238238
toastKey = yield call(showMessage, {
@@ -248,7 +248,7 @@ const PersistenceSaga = combineSagaHandlers({
248248
editorTabs,
249249
context: { chapter, variant },
250250
externalLibrary: external
251-
} = yield* selectWorkspace('playground')
251+
} = yield* selectWorkspace('playground');
252252

253253
if (activeEditorTabIndex === null) {
254254
throw new Error('No active editor tab found.');
@@ -273,7 +273,7 @@ const PersistenceSaga = combineSagaHandlers({
273273
}
274274
},
275275
[actions.persistenceInitialise.type]: ensureInitialised as any
276-
})
276+
});
277277

278278
interface IPlaygroundConfig {
279279
chapter: Chapter;
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
import * as Sentry from '@sentry/browser'
2-
import { call } from "redux-saga/effects"
3-
import { expectSaga } from "redux-saga-test-plan"
1+
import * as Sentry from '@sentry/browser';
2+
import { call } from 'redux-saga/effects';
3+
import { expectSaga } from 'redux-saga-test-plan';
44

5-
import { wrapSaga } from "../SafeEffects"
5+
import { wrapSaga } from '../SafeEffects';
66

7-
jest.spyOn(Sentry, 'captureException')
7+
jest.spyOn(Sentry, 'captureException');
88

99
// Silence console error
10-
jest.spyOn(console, 'error').mockImplementation(x => {})
10+
jest.spyOn(console, 'error').mockImplementation(x => {});
1111

1212
describe('Test wrapSaga', () => {
1313
test('wrapSaga is transparent', async () => {
14-
const mockFn = jest.fn()
14+
const mockFn = jest.fn();
1515
const wrappedSaga = wrapSaga(function* () {
16-
yield call(mockFn)
17-
})
16+
yield call(mockFn);
17+
});
1818

19-
await expectSaga(wrappedSaga).silentRun()
19+
await expectSaga(wrappedSaga).silentRun();
2020

21-
expect(mockFn).toHaveBeenCalledTimes(1)
22-
})
21+
expect(mockFn).toHaveBeenCalledTimes(1);
22+
});
2323

2424
test('wrapSaga handles errors appropriately', async () => {
25-
const errorToThrow = new Error()
25+
const errorToThrow = new Error();
2626
const wrappedSaga = wrapSaga(function* () {
27-
throw errorToThrow
28-
})
27+
throw errorToThrow;
28+
});
2929

30-
await expectSaga(wrappedSaga).silentRun()
30+
await expectSaga(wrappedSaga).silentRun();
3131

32-
expect(Sentry.captureException).toHaveBeenCalledWith(errorToThrow)
33-
expect(console.error).toHaveBeenCalledTimes(1)
34-
})
35-
})
32+
expect(Sentry.captureException).toHaveBeenCalledWith(errorToThrow);
33+
expect(console.error).toHaveBeenCalledTimes(1);
34+
});
35+
});

src/commons/utils/TypeHelper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ export function objectEntries<T extends Record<any, any>>(obj: T) {
177177
return Object.entries(obj) as DeconstructRecord<T>;
178178
}
179179

180+
/**
181+
* Utility for extracting the ActionCreator type from all the action
182+
* creators using the specific type string
183+
*/
180184
export type ActionTypeToCreator<T extends SourceActionType['type']> = Extract<
181185
(typeof actions)[keyof typeof actions],
182186
(...args: any[]) => { type: T }

src/commons/workspace/WorkspaceActions.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { Context } from 'js-slang';
22
import { Chapter, Variant } from 'js-slang/dist/types';
33

4-
import type { AllColsSortStates, GradingColumnVisibility } from '../../features/grading/GradingTypes';
4+
import type {
5+
AllColsSortStates,
6+
GradingColumnVisibility
7+
} from '../../features/grading/GradingTypes';
58
import type { SALanguage } from '../application/ApplicationTypes';
69
import type { ExternalLibraryName } from '../application/types/ExternalTypes';
710
import type { Library } from '../assessment/AssessmentTypes';
@@ -247,7 +250,8 @@ const newActions = createActions('workspace', {
247250
workspaceLocation
248251
}),
249252
toggleUsingUpload: (usingUpload: boolean, workspaceLocation: WorkspaceLocationsWithTools) => ({
250-
usingUpload, workspaceLocation
253+
usingUpload,
254+
workspaceLocation
251255
}),
252256
updateCurrentStep: (steps: number, workspaceLocation: WorkspaceLocation) => ({
253257
steps,
@@ -266,10 +270,12 @@ const newActions = createActions('workspace', {
266270
workspaceLocation
267271
}),
268272
updateLastDebuggerResult: (lastDebuggerResult: any, workspaceLocation: WorkspaceLocation) => ({
269-
lastDebuggerResult, workspaceLocation
273+
lastDebuggerResult,
274+
workspaceLocation
270275
}),
271276
uploadFiles: (files: UploadResult, workspaceLocation: WorkspaceLocation) => ({
272-
files, workspaceLocation
277+
files,
278+
workspaceLocation
273279
}),
274280
// For grading table
275281
increaseRequestCounter: 0,
@@ -279,4 +285,4 @@ const newActions = createActions('workspace', {
279285
updateGradingColumnVisibility: (filters: GradingColumnVisibility) => ({ filters })
280286
});
281287

282-
export default newActions
288+
export default newActions;

src/commons/workspace/WorkspaceReducer.ts

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const WorkspaceReducer: Reducer<WorkspaceManagerState, SourceActionType>
6666
break;
6767
}
6868

69-
state = oldWorkspaceReducer(state, action);
69+
// state = oldWorkspaceReducer(state, action);
7070
state = newWorkspaceReducer(state, action);
7171
return state;
7272
};
@@ -354,15 +354,15 @@ const newWorkspaceReducer = createReducer(defaultWorkspaceManager, builder => {
354354
state.playground.context.chapter = chapter;
355355
state.playground.context.variant = variant;
356356
})
357-
// .addCase(notifyProgramEvaluated, (state, action) => {
358-
// const workspaceLocation = getWorkspaceLocation(action);
359-
// const debuggerContext = state[workspaceLocation].debuggerContext;
360-
// debuggerContext.result = action.payload.result;
361-
// debuggerContext.lastDebuggerResult = action.payload.lastDebuggerResult;
362-
// debuggerContext.code = action.payload.code;
363-
// debuggerContext.context = action.payload.context;
364-
// debuggerContext.workspaceLocation = action.payload.workspaceLocation;
365-
// })
357+
.addCase(WorkspaceActions.notifyProgramEvaluated, (state, action) => {
358+
const workspaceLocation = getWorkspaceLocation(action);
359+
const debuggerContext = state[workspaceLocation].debuggerContext;
360+
debuggerContext.result = action.payload.result;
361+
debuggerContext.lastDebuggerResult = action.payload.lastDebuggerResult;
362+
debuggerContext.code = action.payload.code;
363+
debuggerContext.context = action.payload.context;
364+
debuggerContext.workspaceLocation = action.payload.workspaceLocation;
365+
})
366366
.addCase(WorkspaceActions.toggleUsingUpload, (state, action) => {
367367
const { workspaceLocation } = action.payload;
368368
if (workspaceLocation === 'playground' || workspaceLocation === 'sicp') {
@@ -380,33 +380,3 @@ const newWorkspaceReducer = createReducer(defaultWorkspaceManager, builder => {
380380
state[workspaceLocation].lastDebuggerResult = action.payload.lastDebuggerResult;
381381
});
382382
});
383-
384-
/** Temporarily kept to prevent conflicts */
385-
const oldWorkspaceReducer: Reducer<WorkspaceManagerState, SourceActionType> = (
386-
state = defaultWorkspaceManager,
387-
action
388-
) => {
389-
const workspaceLocation = getWorkspaceLocation(action);
390-
391-
switch (action.type) {
392-
case WorkspaceActions.notifyProgramEvaluated.type: {
393-
const debuggerContext = {
394-
...state[workspaceLocation].debuggerContext,
395-
result: action.payload.result,
396-
lastDebuggerResult: action.payload.lastDebuggerResult,
397-
code: action.payload.code,
398-
context: action.payload.context,
399-
workspaceLocation: action.payload.workspaceLocation
400-
};
401-
return {
402-
...state,
403-
[workspaceLocation]: {
404-
...state[workspaceLocation],
405-
debuggerContext
406-
}
407-
};
408-
}
409-
default:
410-
return state;
411-
}
412-
};

src/commons/workspace/WorkspaceTypes.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { Context } from 'js-slang';
22

3-
import type { AllColsSortStates, GradingColumnVisibility } from '../../features/grading/GradingTypes';
3+
import type {
4+
AllColsSortStates,
5+
GradingColumnVisibility
6+
} from '../../features/grading/GradingTypes';
47
import type { SourcecastWorkspaceState } from '../../features/sourceRecorder/sourcecast/SourcecastTypes';
58
import type { SourcereelWorkspaceState } from '../../features/sourceRecorder/sourcereel/SourcereelTypes';
69
import type { InterpreterOutput } from '../application/ApplicationTypes';

src/features/github/GitHubActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ const newActions = createActions('github', {
66
githubSaveFileAs: 0
77
});
88

9-
export default newActions
9+
export default newActions;

0 commit comments

Comments
 (0)