From bcb397f56b5d223fa476b7cba9515418162f54d6 Mon Sep 17 00:00:00 2001 From: Ofek Date: Tue, 14 May 2024 18:46:22 +0300 Subject: [PATCH] Add noUnusedLocals to tsconfig + fix the new alerts (#6396) --- lib/compilers/d8.ts | 2 +- lib/compilers/solidity-eravm.ts | 2 +- lib/llvm-ast.ts | 3 --- lib/parsers/asm-parser-mads.ts | 5 +---- lib/parsers/asm-parser.ts | 2 +- lib/runtime-tools/heaptrack-wrapper.ts | 4 ---- static/compiler-service.ts | 6 ------ static/compiler-shared.ts | 4 ++-- static/panes/compiler.ts | 12 ------------ static/panes/conformance-view.ts | 10 ---------- static/panes/tree.ts | 8 ++------ static/widgets/compiler-overrides.ts | 4 +--- static/widgets/runtime-tools.ts | 4 +--- test/base-compiler-tests.ts | 26 +++++++++++++------------- tsconfig.base.json | 6 +++++- 15 files changed, 28 insertions(+), 70 deletions(-) diff --git a/lib/compilers/d8.ts b/lib/compilers/d8.ts index f0df82f0b..d15881ff2 100644 --- a/lib/compilers/d8.ts +++ b/lib/compilers/d8.ts @@ -169,7 +169,7 @@ export class D8Compiler extends BaseCompiler implements SimpleOutputFilenameComp let files = await fs.readdir(dirPath); const dexFile = files.find(f => f.endsWith('.dex')); const baksmaliOptions = ['-jar', this.compiler.objdumper, 'd', `${dexFile}`, '-o', dirPath]; - const baksmaliResult = await this.exec(javaCompiler.javaRuntime, baksmaliOptions, { + await this.exec(javaCompiler.javaRuntime, baksmaliOptions, { maxOutput: maxSize, customCwd: dirPath, }); diff --git a/lib/compilers/solidity-eravm.ts b/lib/compilers/solidity-eravm.ts index 73c905259..94e3f2c05 100644 --- a/lib/compilers/solidity-eravm.ts +++ b/lib/compilers/solidity-eravm.ts @@ -61,7 +61,7 @@ export class SolidityEravmCompiler extends BaseCompiler { const combinedJson = JSON.parse(result.asm); const asm: any[] = []; - for (const [path, build] of Object.entries(combinedJson.contracts) as [string, JSON][]) { + for (const build of Object.values(combinedJson.contracts) as JSON[]) { asm.push({text: build['asm']}); } return {asm}; diff --git a/lib/llvm-ast.ts b/lib/llvm-ast.ts index d33bc6393..c716839e9 100644 --- a/lib/llvm-ast.ts +++ b/lib/llvm-ast.ts @@ -125,8 +125,6 @@ export class LlvmAstParser { // Refers to the user's source file rather than a system header const sourceRegex = //g; - const slocRegex = /<>/; - // <, /app/hell.hpp:5:1> const userSource = /<, \/app\/.*:\d+:\d+>/; @@ -178,7 +176,6 @@ export class LlvmAstParser { } else if (userSource.test(output[i].text)) { continue; } else { - // if (!slocRegex.test(output[i].text)) { mostRecentIsSource = isBlockUserSource(output, i, mostRecentIsSource); if (mostRecentIsSource) continue; } diff --git a/lib/parsers/asm-parser-mads.ts b/lib/parsers/asm-parser-mads.ts index 3c147fc9b..276a31450 100644 --- a/lib/parsers/asm-parser-mads.ts +++ b/lib/parsers/asm-parser-mads.ts @@ -114,13 +114,10 @@ export class MadsAsmParser extends AsmParser { const startTime = process.hrtime.bigint(); const asm: ParsedAsmResultLine[] = []; const labelDefinitions: Record = {}; - const dontMaskFilenames = filters.dontMaskFilenames; let asmLines = utils.splitLines(asmResult); const startingLineCount = asmLines.length; const source: AsmResultSource | undefined | null = null; - const func: string | null = null; - const mayRemovePreviousLabel = true; // Handle "error" documents. if (asmLines.length === 1 && asmLines[0][0] === '<') { @@ -195,7 +192,7 @@ export class MadsAsmParser extends AsmParser { match = line.match(this.constAssignment); if (match) { - const value = parseInt(match[1], 16); + // const value = parseInt(match[1], 16); const label = match[3]; labelDefinitions[label] = asm.length; diff --git a/lib/parsers/asm-parser.ts b/lib/parsers/asm-parser.ts index b2d99b6b4..bcf2f9fb0 100644 --- a/lib/parsers/asm-parser.ts +++ b/lib/parsers/asm-parser.ts @@ -808,7 +808,7 @@ export class AsmParser extends AsmRegex implements IAsmParser { const relocname = match.groups.relocname; const relocdata = match.groups.relocdata; // value/addend matched but not used yet. - const match_value = relocdata.match(this.relocDataSymNameRe); + // const match_value = relocdata.match(this.relocDataSymNameRe); asm.push({ text: ` ${relocname} ${relocdata}`, address: address, diff --git a/lib/runtime-tools/heaptrack-wrapper.ts b/lib/runtime-tools/heaptrack-wrapper.ts index f055127c2..80e6effb2 100644 --- a/lib/runtime-tools/heaptrack-wrapper.ts +++ b/lib/runtime-tools/heaptrack-wrapper.ts @@ -34,7 +34,6 @@ import { TypicalExecutionFunc, UnprocessedExecResult, } from '../../types/execution/execution.interfaces.js'; -import {unwrap} from '../assert.js'; import {CompilationEnvironment} from '../compilation-env.js'; import {executeDirect} from '../exec.js'; import {logger} from '../logger.js'; @@ -133,7 +132,6 @@ export class HeaptrackWrapper extends BaseRuntimeTool { } private async interpretAndSave(execOptions: ExecutionOptions, result: UnprocessedExecResult) { - const dirPath = unwrap(execOptions.appHome); execOptions.input = fs.readFileSync(this.rawOutput).toString('utf8'); const interpretResults = await this.interpret(execOptions); @@ -162,8 +160,6 @@ export class HeaptrackWrapper extends BaseRuntimeTool { } public async exec(filepath: string, args: string[], execOptions: ExecutionOptions): Promise { - const dirPath = unwrap(execOptions.appHome); - const runOptions = JSON.parse(JSON.stringify(execOptions)); const interpretOptions = JSON.parse(JSON.stringify(execOptions)); interpretOptions.maxOutput = 1024 * 1024 * 1024; diff --git a/static/compiler-service.ts b/static/compiler-service.ts index e6a31e41f..2d12e20fc 100644 --- a/static/compiler-service.ts +++ b/static/compiler-service.ts @@ -310,12 +310,6 @@ export class CompilerService { }); } - private getFilenameFromUrl(url: string): string { - const jsurl = new URL(url); - const urlpath = jsurl.pathname; - return urlpath.substring(urlpath.lastIndexOf('/') + 1); - } - public async expandToFiles(source: string): Promise { const includesOrEmbeds = new IncludeDownloads(); diff --git a/static/compiler-shared.ts b/static/compiler-shared.ts index 6a7bba381..5dc660f03 100644 --- a/static/compiler-shared.ts +++ b/static/compiler-shared.ts @@ -73,11 +73,11 @@ export class CompilerShared implements ICompilerShared { private initButtons(onChange: () => void) { this.overridesButton = this.domRoot.find('.btn.show-overrides'); - this.overridesWidget = new CompilerOverridesWidget(this.domRoot, this.overridesButton, onChange); + this.overridesWidget = new CompilerOverridesWidget(this.overridesButton, onChange); this.runtimeToolsButton = this.domRoot.find('.btn.show-runtime-tools'); if (this.runtimeToolsButton.length > 0) { - this.runtimeToolsWidget = new RuntimeToolsWidget(this.domRoot, this.runtimeToolsButton, onChange); + this.runtimeToolsWidget = new RuntimeToolsWidget(this.runtimeToolsButton, onChange); } } diff --git a/static/panes/compiler.ts b/static/panes/compiler.ts index 7e015b832..ac8df72f7 100644 --- a/static/panes/compiler.ts +++ b/static/panes/compiler.ts @@ -151,7 +151,6 @@ export class Compiler extends MonacoPane; private deferCompiles: boolean; private needsCompile: boolean; @@ -173,7 +172,6 @@ export class Compiler extends MonacoPane | null; private revealJumpStack: (monaco.editor.ICodeEditorViewState | null)[]; - private compilerPickerElement: JQuery; private compilerPicker: CompilerPicker; private compiler: CompilerInfo | null; private recentInstructionSet: InstructionSet | null; @@ -238,7 +236,6 @@ export class Compiler extends MonacoPane; private statusLabel: JQuery; private statusIcon: JQuery; - private monacoPlaceholder: JQuery; private rustHirButton: JQuery; private libsWidget: LibsWidget | null; private isLabelCtxKey: monaco.editor.IContextKey; @@ -363,7 +360,6 @@ export class Compiler extends MonacoPane { if ((event.ctrlKey || event.metaKey) && String.fromCharCode(event.which).toLowerCase() === 's') { event.preventDefault(); @@ -3788,11 +3781,6 @@ export class Compiler extends MonacoPane { - return this.compilerService.getCompilersForLang(this.currentLangId ?? '') ?? {}; - } - updateCompilersSelector(info: {options?: string}) { if (this.compilerPicker instanceof CompilerPicker) this.compilerPicker.update(this.currentLangId ?? '', this.compiler?.id ?? ''); diff --git a/static/panes/conformance-view.ts b/static/panes/conformance-view.ts index a46282cef..33d3f01e9 100644 --- a/static/panes/conformance-view.ts +++ b/static/panes/conformance-view.ts @@ -46,11 +46,6 @@ import {SourceAndFiles} from '../download-service.js'; import {escapeHTML, unique} from '../../shared/common-utils.js'; import {unwrapString} from '../assert.js'; -type ConformanceStatus = { - allowCompile: boolean; - allowAdd: boolean; -}; - type CompilerEntry = { parent: JQuery; picker: CompilerPicker | null; @@ -79,7 +74,6 @@ export class Conformance extends Pane { private compilerPickers: CompilerEntry[] = []; private expandedSourceAndFiles: SourceAndFiles | null; private currentLibs: Lib[]; - private status: ConformanceStatus; private readonly stateByLang: Record; private libsButton: JQuery; private conformanceContentRoot: JQuery; @@ -97,10 +91,6 @@ export class Conformance extends Pane { this.sourceNeedsExpanding = true; this.expandedSourceAndFiles = null; - this.status = { - allowCompile: false, - allowAdd: true, - }; this.stateByLang = {}; this.paneRenaming = new PaneRenaming(this, state); diff --git a/static/panes/tree.ts b/static/panes/tree.ts index 8570164ab..14a88ab3e 100644 --- a/static/panes/tree.ts +++ b/static/panes/tree.ts @@ -57,7 +57,6 @@ export class Tree { private readonly hub: Hub; private eventHub: EventHub; private readonly settings: SiteSettings; - private httpRoot: string; private readonly alertSystem: Alert; private root: JQuery; private rowTemplate: JQuery; @@ -88,9 +87,6 @@ export class Tree { this.hub = hub; this.eventHub = hub.createEventHub(); this.settings = Settings.getStoredSettings(); - - this.httpRoot = window.httpRoot; - this.alertSystem = new Alert(); this.alertSystem.prefixMessage = 'Tree #' + this.id; @@ -728,12 +724,12 @@ export class Tree { this.sendCompileRequests(); }, newSettings.delayAfterChange); } - private getPaneName() { return `Tree #${this.id}`; } - private updateTitle() { + // eslint-disable-next-line no-unused-vars + updateTitle() { const name = this.paneName ? this.paneName : this.getPaneName(); this.container.setTitle(escapeHTML(name)); } diff --git a/static/widgets/compiler-overrides.ts b/static/widgets/compiler-overrides.ts index 3dcbad2db..afae239e5 100644 --- a/static/widgets/compiler-overrides.ts +++ b/static/widgets/compiler-overrides.ts @@ -57,7 +57,6 @@ class ActiveState {} type OverrideState = IncompatibleState | InactiveState | ActiveState; export class CompilerOverridesWidget { - private domRoot: JQuery; private popupDomRoot: JQuery; private envVarsInput: JQuery; private dropdownButton: JQuery; @@ -65,8 +64,7 @@ export class CompilerOverridesWidget { private configured: ConfiguredOverrides = []; private compiler: CompilerInfo | undefined; - constructor(domRoot: JQuery, dropdownButton: JQuery, onChangeCallback: CompilerOverridesChangeCallback) { - this.domRoot = domRoot; + constructor(dropdownButton: JQuery, onChangeCallback: CompilerOverridesChangeCallback) { this.popupDomRoot = $('#overrides-selection'); this.dropdownButton = dropdownButton; this.envVarsInput = this.popupDomRoot.find('.envvars'); diff --git a/static/widgets/runtime-tools.ts b/static/widgets/runtime-tools.ts index a57dc3850..d0886876a 100644 --- a/static/widgets/runtime-tools.ts +++ b/static/widgets/runtime-tools.ts @@ -49,7 +49,6 @@ type FavRuntimeTool = { type FavRuntimeTools = FavRuntimeTool[]; export class RuntimeToolsWidget { - private domRoot: JQuery; private popupDomRoot: JQuery; private envVarsInput: JQuery; private dropdownButton: JQuery; @@ -58,8 +57,7 @@ export class RuntimeToolsWidget { private compiler: CompilerInfo | undefined; private possibleTools: PossibleRuntimeTools; - constructor(domRoot: JQuery, dropdownButton: JQuery, onChangeCallback: RuntimeToolsChangeCallback) { - this.domRoot = domRoot; + constructor(dropdownButton: JQuery, onChangeCallback: RuntimeToolsChangeCallback) { this.popupDomRoot = $('#runtimetools-selection'); this.dropdownButton = dropdownButton; this.envVarsInput = this.popupDomRoot.find('.envvars'); diff --git a/test/base-compiler-tests.ts b/test/base-compiler-tests.ts index 3150dacbe..8cdeab36d 100644 --- a/test/base-compiler-tests.ts +++ b/test/base-compiler-tests.ts @@ -107,7 +107,7 @@ describe('Basic compiler invariants', () => { describe('Compiler execution', () => { let ce: CompilationEnvironment; let compiler: BaseCompiler; - let compilerNoExec: BaseCompiler; + // let compilerNoExec: BaseCompiler; let win32compiler: Win32Compiler; const executingCompilerInfo = makeFakeCompilerInfo({ @@ -163,22 +163,22 @@ describe('Compiler execution', () => { ce = makeCompilationEnvironment({languages}); compiler = new BaseCompiler(executingCompilerInfo, ce); win32compiler = new Win32Compiler(win32CompilerInfo, ce); - compilerNoExec = new BaseCompiler(noExecuteSupportCompilerInfo, ce); + // compilerNoExec = new BaseCompiler(noExecuteSupportCompilerInfo, ce); }); // afterEach(() => restore()); - function stubOutCallToExec(execStub, compiler, content, result, nthCall) { - execStub.onCall(nthCall || 0).callsFake((compiler, args) => { - const minusO = args.indexOf('-o'); - expect(minusO).toBeGreaterThanOrEqual(0); - const output = args[minusO + 1]; - // Maybe we should mock out the FS too; but that requires a lot more work. - fs.writeFileSync(output, content); - result.filenameTransform = (x: string) => x; - return Promise.resolve(result); - }); - } + // function stubOutCallToExec(execStub, compiler, content, result, nthCall) { + // execStub.onCall(nthCall || 0).callsFake((compiler, args) => { + // const minusO = args.indexOf('-o'); + // expect(minusO).toBeGreaterThanOrEqual(0); + // const output = args[minusO + 1]; + // // Maybe we should mock out the FS too; but that requires a lot more work. + // fs.writeFileSync(output, content); + // result.filenameTransform = (x: string) => x; + // return Promise.resolve(result); + // }); + // } it('basecompiler should handle spaces in options correctly', () => { const userOptions = []; diff --git a/tsconfig.base.json b/tsconfig.base.json index 2e425adc0..b8bd70e3c 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -11,6 +11,10 @@ "skipLibCheck": true, "strict": true, "noImplicitAny": false, - "noImplicitOverride": true + "noImplicitOverride": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "noUnusedLocals": true, + "noImplicitThis": true } }