Skip to content

Commit 407cebd

Browse files
leeyi45sayomaki
andauthored
Remove Non-Det (#3104)
* Remove non det * Update tests after removing non-det from variants * Migrate eslint config to ES module --------- Co-authored-by: sayomaki <[email protected]>
1 parent 56b1ab0 commit 407cebd

File tree

12 files changed

+46
-99
lines changed

12 files changed

+46
-99
lines changed

eslint.config.js renamed to eslint.config.mjs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
// @ts-check
22

3-
// Todo: Use ES module
4-
const eslint = require('@eslint/js');
5-
const tseslint = require('typescript-eslint');
6-
const reactRefresh = require('eslint-plugin-react-refresh');
3+
// import eslint from '@eslint/js';
4+
import { config, configs } from 'typescript-eslint';
5+
import reactPlugin from 'eslint-plugin-react';
6+
import reactHooksPlugin from 'eslint-plugin-react-hooks';
7+
import simpleImportSort from 'eslint-plugin-simple-import-sort'
8+
// import reactRefresh from 'eslint-plugin-react-refresh';
79

8-
const FlatCompat = require('@eslint/eslintrc').FlatCompat;
9-
const compat = new FlatCompat({
10-
baseDirectory: `${__dirname}`
11-
});
12-
13-
module.exports = tseslint.config(
14-
{ ignores: ['eslint.config.js'] },
10+
export default config(
11+
{ ignores: ['eslint.config.mjs'] },
1512
// eslint.configs.recommended,
16-
...tseslint.configs.recommended,
13+
...configs.recommended,
1714
// TODO: Enable when ready
1815
// {
1916
// plugins: {
@@ -23,14 +20,15 @@ module.exports = tseslint.config(
2320
// 'react-refresh/only-export-components': 'warn'
2421
// }
2522
// },
26-
...compat.config({
27-
extends: [
28-
'plugin:react-hooks/recommended'
29-
// "plugin:react/recommended",
30-
// "plugin:react/jsx-runtime"
31-
],
32-
plugins: ['simple-import-sort'],
23+
{
24+
files: ['**/*.ts*'],
25+
plugins: {
26+
'react-hooks': reactHooksPlugin,
27+
'react': reactPlugin,
28+
'simple-import-sort': simpleImportSort
29+
},
3330
rules: {
31+
...reactHooksPlugin.configs['recommended-latest'].rules,
3432
'no-restricted-imports': [
3533
'error',
3634
{
@@ -73,5 +71,5 @@ module.exports = tseslint.config(
7371
],
7472
'simple-import-sort/imports': 'error'
7573
}
76-
})
74+
}
7775
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
"cross-env": "^7.0.3",
142142
"eslint": "^9.9.0",
143143
"eslint-plugin-react": "^7.35.0",
144-
"eslint-plugin-react-hooks": "5.1.0-canary-cb151849e1-20240424",
144+
"eslint-plugin-react-hooks": "^5.2.0",
145145
"eslint-plugin-react-refresh": "^0.4.9",
146146
"eslint-plugin-simple-import-sort": "^12.1.1",
147147
"https-browserify": "^1.0.0",

src/commons/__tests__/Markdown.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ test('Markdown page renders correct Source information', () => {
3737
const source3Default = <Markdown {...mockProps(Chapter.SOURCE_3, Variant.DEFAULT)} />;
3838
expect(source3Default.props.content).toContain('Source \xa73');
3939

40-
const source3NonDet = <Markdown {...mockProps(Chapter.SOURCE_3, Variant.NON_DET)} />;
41-
expect(source3NonDet.props.content).toContain('Source \xa73 Non-Det');
42-
4340
const source3Concurrent = <Markdown {...mockProps(Chapter.SOURCE_3, Variant.CONCURRENT)} />;
4441
expect(source3Concurrent.props.content).toContain('Source \xa73 Concurrent');
4542

src/commons/application/ApplicationTypes.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ type LanguageFeatures = Partial<{
158158
const variantDisplay: Map<Variant, string> = new Map([
159159
[Variant.TYPED, 'Typed'],
160160
[Variant.WASM, 'WebAssembly'],
161-
[Variant.NON_DET, 'Non-Det'],
162161
[Variant.CONCURRENT, 'Concurrent'],
163162
[Variant.LAZY, 'Lazy'],
164163
[Variant.GPU, 'GPU'],
@@ -270,7 +269,6 @@ const sourceSubLanguages: Array<Pick<SALanguage, 'chapter' | 'variant'>> = [
270269
{ chapter: Chapter.SOURCE_3, variant: Variant.DEFAULT },
271270
{ chapter: Chapter.SOURCE_3, variant: Variant.TYPED },
272271
{ chapter: Chapter.SOURCE_3, variant: Variant.CONCURRENT },
273-
{ chapter: Chapter.SOURCE_3, variant: Variant.NON_DET },
274272
{ chapter: Chapter.SOURCE_3, variant: Variant.NATIVE },
275273

276274
{ chapter: Chapter.SOURCE_4, variant: Variant.DEFAULT },
@@ -293,8 +291,7 @@ export const sourceLanguages: SALanguage[] = sourceSubLanguages.map(sublang => {
293291
(variant === Variant.DEFAULT || variant === Variant.NATIVE || variant === Variant.TYPED);
294292

295293
// Enable CSE Machine for Source Chapter 3 and above
296-
supportedFeatures.cseMachine =
297-
chapter >= Chapter.SOURCE_3 && variant !== Variant.CONCURRENT && variant !== Variant.NON_DET;
294+
supportedFeatures.cseMachine = chapter >= Chapter.SOURCE_3 && variant !== Variant.CONCURRENT;
298295

299296
// Local imports/exports require Source 2+ as Source 1 does not have lists.
300297
supportedFeatures.multiFile = chapter >= Chapter.SOURCE_2;
@@ -426,7 +423,6 @@ export const createDefaultWorkspace = (workspaceLocation: WorkspaceLocation): Wo
426423
enableDebugging: true,
427424
debuggerContext: {} as DebuggerContext,
428425
lastDebuggerResult: undefined,
429-
lastNonDetResult: null,
430426
files: {}
431427
});
432428

src/commons/application/__tests__/ApplicationTypes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ describe('available Source language configurations', () => {
6262
variant: Variant.CONCURRENT,
6363
supports: { dataVisualizer: true }
6464
},
65-
{ chapter: Chapter.SOURCE_3, variant: Variant.NON_DET, supports: { dataVisualizer: true } },
6665
{
6766
chapter: Chapter.SOURCE_3,
6867
variant: Variant.NATIVE,

src/commons/application/__tests__/__snapshots__/ApplicationTypes.ts.snap

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,6 @@ Array [
227227
},
228228
"variant": "concurrent",
229229
},
230-
Object {
231-
"chapter": 3,
232-
"displayName": "Source §3 Non-Det",
233-
"mainLanguage": "JavaScript",
234-
"supports": Object {
235-
"cseMachine": false,
236-
"dataVisualizer": true,
237-
"multiFile": true,
238-
"repl": true,
239-
"substVisualizer": false,
240-
},
241-
"variant": "non-det",
242-
},
243230
Object {
244231
"chapter": 3,
245232
"displayName": "Source §3 Native",

src/commons/sagas/WorkspaceSaga/helpers/evalCode.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { compileAndRun as compileAndRunCCode } from '@sourceacademy/c-slang/ctow
22
import { tokenizer } from 'acorn';
33
import { IConduit } from 'conductor/dist/conduit';
44
import { Context, interrupt, Result, resume, runFilesInContext } from 'js-slang';
5-
import { ACORN_PARSE_OPTIONS, TRY_AGAIN } from 'js-slang/dist/constants';
5+
import { ACORN_PARSE_OPTIONS } from 'js-slang/dist/constants';
66
import { InterruptedError } from 'js-slang/dist/errors/errors';
77
import { manualToggleDebugger } from 'js-slang/dist/stdlib/inspector';
88
import { Chapter, ErrorSeverity, ErrorType, SourceError, Variant } from 'js-slang/dist/types';
@@ -128,22 +128,9 @@ export function* evalCodeSaga(
128128
);
129129

130130
const entrypointCode = files[entrypointFilePath];
131-
const lastNonDetResult = yield select(
132-
(state: OverallState) => state.workspaces[workspaceLocation].lastNonDetResult
133-
);
134131

135132
function call_variant(variant: Variant) {
136-
if (variant === Variant.NON_DET) {
137-
return entrypointCode.trim() === TRY_AGAIN
138-
? call(resume, lastNonDetResult)
139-
: call(runFilesInContext, files, entrypointFilePath, context, {
140-
executionMethod: 'interpreter',
141-
originalMaxExecTime: execTime,
142-
stepLimit: stepLimit,
143-
useSubst: substActiveAndCorrectChapter,
144-
envSteps: currentStep
145-
});
146-
} else if (variant === Variant.LAZY) {
133+
if (variant === Variant.LAZY) {
147134
return call(runFilesInContext, files, entrypointFilePath, context, {
148135
scheduler: 'preemptive',
149136
originalMaxExecTime: execTime,
@@ -269,7 +256,6 @@ export function* evalCodeSaga(
269256
});
270257
}
271258

272-
const isNonDet: boolean = context.variant === Variant.NON_DET;
273259
const isLazy: boolean = context.variant === Variant.LAZY;
274260
const isWasm: boolean = context.variant === Variant.WASM;
275261
const isC: boolean = context.chapter === Chapter.FULL_C;
@@ -286,11 +272,19 @@ export function* evalCodeSaga(
286272
? DisplayBufferService.attachConsole(workspaceLocation)
287273
: () => {};
288274

289-
const { result, interrupted, paused } = yield race({
275+
const {
276+
result,
277+
interrupted,
278+
paused
279+
}: {
280+
result: Result;
281+
interrupted: any;
282+
paused: any;
283+
} = yield race({
290284
result:
291285
actionType === InterpreterActions.debuggerResume.type
292286
? call(resume, lastDebuggerResult)
293-
: isNonDet || isLazy || isWasm
287+
: isLazy || isWasm
294288
? call_variant(context.variant)
295289
: isC
296290
? call(cCompileAndRun, entrypointCode, context)
@@ -357,7 +351,6 @@ export function* evalCodeSaga(
357351
if (
358352
result.status !== 'suspended' &&
359353
result.status !== 'finished' &&
360-
result.status !== 'suspended-non-det' &&
361354
result.status !== 'suspended-cse-eval'
362355
) {
363356
yield* dumpDisplayBuffer(workspaceLocation, isStoriesBlock, storyEnv);
@@ -401,11 +394,6 @@ export function* evalCodeSaga(
401394
yield put(actions.endDebuggerPause(workspaceLocation));
402395
yield put(actions.evalInterpreterSuccess('Breakpoint hit!', workspaceLocation));
403396
return;
404-
} else if (isNonDet) {
405-
if (result.value === 'cut') {
406-
result.value = undefined;
407-
}
408-
yield put(actions.updateLastNonDetResult(result, workspaceLocation));
409397
}
410398

411399
yield* dumpDisplayBuffer(workspaceLocation, isStoriesBlock, storyEnv);

src/commons/utils/Hooks.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { useMediaQuery } from '@mantine/hooks';
22
import React, { RefObject } from 'react';
3-
import {
4-
TypedUseSelectorHook,
5-
// eslint-disable-next-line no-restricted-imports
6-
useSelector
7-
} from 'react-redux';
3+
// eslint-disable-next-line no-restricted-imports
4+
import { TypedUseSelectorHook, useSelector } from 'react-redux';
85

96
import { OverallState } from '../application/ApplicationTypes';
107
import { Tokens } from '../application/types/SessionTypes';

src/commons/workspace/WorkspaceActions.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createAction } from '@reduxjs/toolkit';
2-
import { Context, Result } from 'js-slang';
2+
import type { Context } from 'js-slang';
33
import { Chapter, Variant } from 'js-slang/dist/types';
44

55
import { AllColsSortStates, GradingColumnVisibility } from '../../features/grading/GradingTypes';
@@ -14,7 +14,6 @@ import {
1414
SubmissionsTableFilters,
1515
TOGGLE_USING_UPLOAD,
1616
UPDATE_LAST_DEBUGGER_RESULT,
17-
UPDATE_LAST_NON_DET_RESULT,
1817
UPLOAD_FILES,
1918
WorkspaceLocation,
2019
WorkspaceLocationsWithTools,
@@ -281,13 +280,6 @@ export const updateLastDebuggerResult = createAction(
281280
})
282281
);
283282

284-
export const updateLastNonDetResult = createAction(
285-
UPDATE_LAST_NON_DET_RESULT,
286-
(lastNonDetResult: Result, workspaceLocation: WorkspaceLocation) => ({
287-
payload: { lastNonDetResult, workspaceLocation }
288-
})
289-
);
290-
291283
export const toggleUsingUpload = createAction(
292284
TOGGLE_USING_UPLOAD,
293285
(usingUpload: boolean, workspaceLocation: WorkspaceLocationsWithTools) => ({
@@ -306,7 +298,6 @@ export const uploadFiles = createAction(
306298
export default {
307299
...newActions,
308300
updateLastDebuggerResult,
309-
updateLastNonDetResult,
310301
toggleUsingUpload,
311302
uploadFiles
312303
};

src/commons/workspace/WorkspaceReducer.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,6 @@ const newWorkspaceReducer = createReducer(defaultWorkspaceManager, builder => {
380380
.addCase(WorkspaceActions.updateLastDebuggerResult, (state, action) => {
381381
const workspaceLocation = getWorkspaceLocation(action);
382382
state[workspaceLocation].lastDebuggerResult = action.payload.lastDebuggerResult;
383-
})
384-
.addCase(WorkspaceActions.updateLastNonDetResult, (state, action) => {
385-
const workspaceLocation = getWorkspaceLocation(action);
386-
state[workspaceLocation].lastNonDetResult = action.payload.lastNonDetResult;
387383
});
388384
});
389385

src/commons/workspace/WorkspaceTypes.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Context, Result } from 'js-slang';
1+
import type { Context } from 'js-slang';
22

33
import { AllColsSortStates, GradingColumnVisibility } from '../../features/grading/GradingTypes';
44
import { SourcecastWorkspaceState } from '../../features/sourceRecorder/sourcecast/SourcecastTypes';
@@ -11,7 +11,6 @@ import { UploadResult } from '../sideContent/content/SideContentUpload';
1111

1212
export const EVAL_SILENT = 'EVAL_SILENT';
1313
export const UPDATE_LAST_DEBUGGER_RESULT = 'UPDATE_LAST_DEBUGGER_RESULT';
14-
export const UPDATE_LAST_NON_DET_RESULT = 'UPDATE_LAST_NON_DET_RESULT';
1514
export const TOGGLE_USING_UPLOAD = 'TOGGLE_USING_UPLOAD';
1615
export const UPLOAD_FILES = 'UPLOAD_FILES';
1716

@@ -106,7 +105,6 @@ export type WorkspaceState = {
106105
readonly globals: Array<[string, any]>;
107106
readonly debuggerContext: DebuggerContext;
108107
readonly lastDebuggerResult: any;
109-
readonly lastNonDetResult: Result | null;
110108
readonly files: UploadResult;
111109
};
112110

yarn.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8721,15 +8721,6 @@ __metadata:
87218721
languageName: node
87228722
linkType: hard
87238723

8724-
"eslint-plugin-react-hooks@npm:5.1.0-canary-cb151849e1-20240424":
8725-
version: 5.1.0-canary-cb151849e1-20240424
8726-
resolution: "eslint-plugin-react-hooks@npm:5.1.0-canary-cb151849e1-20240424"
8727-
peerDependencies:
8728-
eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0
8729-
checksum: 10c0/dc5d002443861ec93872c4e43b5815e9a1c15cdd4b86f96783291c4c642ed92048334cd3c434d74642cafcf397762450239f4f74e44dce6198256ad421bc4ebd
8730-
languageName: node
8731-
linkType: hard
8732-
87338724
"eslint-plugin-react-hooks@npm:^4.3.0":
87348725
version: 4.6.0
87358726
resolution: "eslint-plugin-react-hooks@npm:4.6.0"
@@ -8739,6 +8730,15 @@ __metadata:
87398730
languageName: node
87408731
linkType: hard
87418732

8733+
"eslint-plugin-react-hooks@npm:^5.2.0":
8734+
version: 5.2.0
8735+
resolution: "eslint-plugin-react-hooks@npm:5.2.0"
8736+
peerDependencies:
8737+
eslint: ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0-0 || ^9.0.0
8738+
checksum: 10c0/1c8d50fa5984c6dea32470651807d2922cc3934cf3425e78f84a24c2dfd972e7f019bee84aefb27e0cf2c13fea0ac1d4473267727408feeb1c56333ca1489385
8739+
languageName: node
8740+
linkType: hard
8741+
87428742
"eslint-plugin-react-refresh@npm:^0.4.9":
87438743
version: 0.4.9
87448744
resolution: "eslint-plugin-react-refresh@npm:0.4.9"
@@ -9655,7 +9655,7 @@ __metadata:
96559655
dompurify: "npm:^3.2.4"
96569656
eslint: "npm:^9.9.0"
96579657
eslint-plugin-react: "npm:^7.35.0"
9658-
eslint-plugin-react-hooks: "npm:5.1.0-canary-cb151849e1-20240424"
9658+
eslint-plugin-react-hooks: "npm:^5.2.0"
96599659
eslint-plugin-react-refresh: "npm:^0.4.9"
96609660
eslint-plugin-simple-import-sort: "npm:^12.1.1"
96619661
flexboxgrid: "npm:^6.3.1"

0 commit comments

Comments
 (0)