Add noUnusedLocals to tsconfig + fix the new alerts (#6396)

<!-- THIS COMMENT IS INVISIBLE IN THE FINAL PR, BUT FEEL FREE TO REMOVE
IT
Thanks for taking the time to improve CE. We really appreciate it.
Before opening the PR, please make sure that the tests & linter pass
their checks,
  by running `make check`.
In the best case scenario, you are also adding tests to back up your
changes,
  but don't sweat it if you don't. We can discuss them at a later date.
Feel free to append your name to the CONTRIBUTORS.md file
Thanks again, we really appreciate this!
-->
This commit is contained in:
Ofek
2024-05-14 18:46:22 +03:00
committed by GitHub
parent 77791d863b
commit bcb397f56b
15 changed files with 28 additions and 70 deletions

View File

@@ -169,7 +169,7 @@ export class D8Compiler extends BaseCompiler implements SimpleOutputFilenameComp
let files = await fs.readdir(dirPath); let files = await fs.readdir(dirPath);
const dexFile = files.find(f => f.endsWith('.dex')); const dexFile = files.find(f => f.endsWith('.dex'));
const baksmaliOptions = ['-jar', this.compiler.objdumper, 'd', `${dexFile}`, '-o', dirPath]; 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, maxOutput: maxSize,
customCwd: dirPath, customCwd: dirPath,
}); });

View File

@@ -61,7 +61,7 @@ export class SolidityEravmCompiler extends BaseCompiler {
const combinedJson = JSON.parse(result.asm); const combinedJson = JSON.parse(result.asm);
const asm: any[] = []; 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']}); asm.push({text: build['asm']});
} }
return {asm}; return {asm};

View File

@@ -125,8 +125,6 @@ export class LlvmAstParser {
// Refers to the user's source file rather than a system header // Refers to the user's source file rather than a system header
const sourceRegex = /<source>/g; const sourceRegex = /<source>/g;
const slocRegex = /<<invalid sloc>>/;
// <<invalid sloc>, /app/hell.hpp:5:1> // <<invalid sloc>, /app/hell.hpp:5:1>
const userSource = /<<invalid sloc>, \/app\/.*:\d+:\d+>/; const userSource = /<<invalid sloc>, \/app\/.*:\d+:\d+>/;
@@ -178,7 +176,6 @@ export class LlvmAstParser {
} else if (userSource.test(output[i].text)) { } else if (userSource.test(output[i].text)) {
continue; continue;
} else { } else {
// if (!slocRegex.test(output[i].text)) {
mostRecentIsSource = isBlockUserSource(output, i, mostRecentIsSource); mostRecentIsSource = isBlockUserSource(output, i, mostRecentIsSource);
if (mostRecentIsSource) continue; if (mostRecentIsSource) continue;
} }

View File

@@ -114,13 +114,10 @@ export class MadsAsmParser extends AsmParser {
const startTime = process.hrtime.bigint(); const startTime = process.hrtime.bigint();
const asm: ParsedAsmResultLine[] = []; const asm: ParsedAsmResultLine[] = [];
const labelDefinitions: Record<string, number> = {}; const labelDefinitions: Record<string, number> = {};
const dontMaskFilenames = filters.dontMaskFilenames;
let asmLines = utils.splitLines(asmResult); let asmLines = utils.splitLines(asmResult);
const startingLineCount = asmLines.length; const startingLineCount = asmLines.length;
const source: AsmResultSource | undefined | null = null; const source: AsmResultSource | undefined | null = null;
const func: string | null = null;
const mayRemovePreviousLabel = true;
// Handle "error" documents. // Handle "error" documents.
if (asmLines.length === 1 && asmLines[0][0] === '<') { if (asmLines.length === 1 && asmLines[0][0] === '<') {
@@ -195,7 +192,7 @@ export class MadsAsmParser extends AsmParser {
match = line.match(this.constAssignment); match = line.match(this.constAssignment);
if (match) { if (match) {
const value = parseInt(match[1], 16); // const value = parseInt(match[1], 16);
const label = match[3]; const label = match[3];
labelDefinitions[label] = asm.length; labelDefinitions[label] = asm.length;

View File

@@ -808,7 +808,7 @@ export class AsmParser extends AsmRegex implements IAsmParser {
const relocname = match.groups.relocname; const relocname = match.groups.relocname;
const relocdata = match.groups.relocdata; const relocdata = match.groups.relocdata;
// value/addend matched but not used yet. // value/addend matched but not used yet.
const match_value = relocdata.match(this.relocDataSymNameRe); // const match_value = relocdata.match(this.relocDataSymNameRe);
asm.push({ asm.push({
text: ` ${relocname} ${relocdata}`, text: ` ${relocname} ${relocdata}`,
address: address, address: address,

View File

@@ -34,7 +34,6 @@ import {
TypicalExecutionFunc, TypicalExecutionFunc,
UnprocessedExecResult, UnprocessedExecResult,
} from '../../types/execution/execution.interfaces.js'; } from '../../types/execution/execution.interfaces.js';
import {unwrap} from '../assert.js';
import {CompilationEnvironment} from '../compilation-env.js'; import {CompilationEnvironment} from '../compilation-env.js';
import {executeDirect} from '../exec.js'; import {executeDirect} from '../exec.js';
import {logger} from '../logger.js'; import {logger} from '../logger.js';
@@ -133,7 +132,6 @@ export class HeaptrackWrapper extends BaseRuntimeTool {
} }
private async interpretAndSave(execOptions: ExecutionOptions, result: UnprocessedExecResult) { private async interpretAndSave(execOptions: ExecutionOptions, result: UnprocessedExecResult) {
const dirPath = unwrap(execOptions.appHome);
execOptions.input = fs.readFileSync(this.rawOutput).toString('utf8'); execOptions.input = fs.readFileSync(this.rawOutput).toString('utf8');
const interpretResults = await this.interpret(execOptions); 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<UnprocessedExecResult> { public async exec(filepath: string, args: string[], execOptions: ExecutionOptions): Promise<UnprocessedExecResult> {
const dirPath = unwrap(execOptions.appHome);
const runOptions = JSON.parse(JSON.stringify(execOptions)); const runOptions = JSON.parse(JSON.stringify(execOptions));
const interpretOptions = JSON.parse(JSON.stringify(execOptions)); const interpretOptions = JSON.parse(JSON.stringify(execOptions));
interpretOptions.maxOutput = 1024 * 1024 * 1024; interpretOptions.maxOutput = 1024 * 1024 * 1024;

View File

@@ -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<SourceAndFiles> { public async expandToFiles(source: string): Promise<SourceAndFiles> {
const includesOrEmbeds = new IncludeDownloads(); const includesOrEmbeds = new IncludeDownloads();

View File

@@ -73,11 +73,11 @@ export class CompilerShared implements ICompilerShared {
private initButtons(onChange: () => void) { private initButtons(onChange: () => void) {
this.overridesButton = this.domRoot.find('.btn.show-overrides'); 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'); this.runtimeToolsButton = this.domRoot.find('.btn.show-runtime-tools');
if (this.runtimeToolsButton.length > 0) { if (this.runtimeToolsButton.length > 0) {
this.runtimeToolsWidget = new RuntimeToolsWidget(this.domRoot, this.runtimeToolsButton, onChange); this.runtimeToolsWidget = new RuntimeToolsWidget(this.runtimeToolsButton, onChange);
} }
} }

View File

@@ -151,7 +151,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
private readonly id: number; private readonly id: number;
private sourceTreeId: number | null; private sourceTreeId: number | null;
private sourceEditorId: number | null; private sourceEditorId: number | null;
private originalCompilerId: string;
private readonly infoByLang: Record<string, {compiler: string; options: string}>; private readonly infoByLang: Record<string, {compiler: string; options: string}>;
private deferCompiles: boolean; private deferCompiles: boolean;
private needsCompile: boolean; private needsCompile: boolean;
@@ -173,7 +172,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
private linkedFadeTimeoutId: NodeJS.Timeout | null; private linkedFadeTimeoutId: NodeJS.Timeout | null;
private toolsMenu: JQuery<HTMLElement> | null; private toolsMenu: JQuery<HTMLElement> | null;
private revealJumpStack: (monaco.editor.ICodeEditorViewState | null)[]; private revealJumpStack: (monaco.editor.ICodeEditorViewState | null)[];
private compilerPickerElement: JQuery<HTMLElement>;
private compilerPicker: CompilerPicker; private compilerPicker: CompilerPicker;
private compiler: CompilerInfo | null; private compiler: CompilerInfo | null;
private recentInstructionSet: InstructionSet | null; private recentInstructionSet: InstructionSet | null;
@@ -238,7 +236,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
private bottomBar: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>; private bottomBar: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private statusLabel: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>; private statusLabel: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private statusIcon: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>; private statusIcon: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private monacoPlaceholder: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private rustHirButton: JQuery<HTMLElement>; private rustHirButton: JQuery<HTMLElement>;
private libsWidget: LibsWidget | null; private libsWidget: LibsWidget | null;
private isLabelCtxKey: monaco.editor.IContextKey<boolean>; private isLabelCtxKey: monaco.editor.IContextKey<boolean>;
@@ -363,7 +360,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.deviceViewOpen = !!state.deviceViewOpen; this.deviceViewOpen = !!state.deviceViewOpen;
this.flagsViewOpen = state.flagsViewOpen || false; this.flagsViewOpen = state.flagsViewOpen || false;
this.wantOptInfo = state.wantOptInfo; this.wantOptInfo = state.wantOptInfo;
this.originalCompilerId = state.compiler;
this.selection = state.selection; this.selection = state.selection;
} }
@@ -2539,7 +2535,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.optionsField.val(this.options); this.optionsField.val(this.options);
this.shortCompilerName = this.domRoot.find('.short-compiler-name'); this.shortCompilerName = this.domRoot.find('.short-compiler-name');
this.compilerPickerElement = this.domRoot.find('.compiler-picker');
this.setCompilerVersionPopover(); this.setCompilerVersionPopover();
this.topBar = this.domRoot.find('.top-bar'); this.topBar = this.domRoot.find('.top-bar');
@@ -2549,8 +2544,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.hideable = this.domRoot.find('.hideable'); this.hideable = this.domRoot.find('.hideable');
this.statusIcon = this.domRoot.find('.status-icon'); this.statusIcon = this.domRoot.find('.status-icon');
this.monacoPlaceholder = this.domRoot.find('.monaco-placeholder');
$(this.domRoot).on('keydown', event => { $(this.domRoot).on('keydown', event => {
if ((event.ctrlKey || event.metaKey) && String.fromCharCode(event.which).toLowerCase() === 's') { if ((event.ctrlKey || event.metaKey) && String.fromCharCode(event.which).toLowerCase() === 's') {
event.preventDefault(); event.preventDefault();
@@ -3788,11 +3781,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
}); });
}); });
} }
private getCurrentLangCompilers(): Record<string, CompilerInfo> {
return this.compilerService.getCompilersForLang(this.currentLangId ?? '') ?? {};
}
updateCompilersSelector(info: {options?: string}) { updateCompilersSelector(info: {options?: string}) {
if (this.compilerPicker instanceof CompilerPicker) if (this.compilerPicker instanceof CompilerPicker)
this.compilerPicker.update(this.currentLangId ?? '', this.compiler?.id ?? ''); this.compilerPicker.update(this.currentLangId ?? '', this.compiler?.id ?? '');

View File

@@ -46,11 +46,6 @@ import {SourceAndFiles} from '../download-service.js';
import {escapeHTML, unique} from '../../shared/common-utils.js'; import {escapeHTML, unique} from '../../shared/common-utils.js';
import {unwrapString} from '../assert.js'; import {unwrapString} from '../assert.js';
type ConformanceStatus = {
allowCompile: boolean;
allowAdd: boolean;
};
type CompilerEntry = { type CompilerEntry = {
parent: JQuery<HTMLElement>; parent: JQuery<HTMLElement>;
picker: CompilerPicker | null; picker: CompilerPicker | null;
@@ -79,7 +74,6 @@ export class Conformance extends Pane<ConformanceViewState> {
private compilerPickers: CompilerEntry[] = []; private compilerPickers: CompilerEntry[] = [];
private expandedSourceAndFiles: SourceAndFiles | null; private expandedSourceAndFiles: SourceAndFiles | null;
private currentLibs: Lib[]; private currentLibs: Lib[];
private status: ConformanceStatus;
private readonly stateByLang: Record<string, ConformanceViewState>; private readonly stateByLang: Record<string, ConformanceViewState>;
private libsButton: JQuery<HTMLElement>; private libsButton: JQuery<HTMLElement>;
private conformanceContentRoot: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>; private conformanceContentRoot: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
@@ -97,10 +91,6 @@ export class Conformance extends Pane<ConformanceViewState> {
this.sourceNeedsExpanding = true; this.sourceNeedsExpanding = true;
this.expandedSourceAndFiles = null; this.expandedSourceAndFiles = null;
this.status = {
allowCompile: false,
allowAdd: true,
};
this.stateByLang = {}; this.stateByLang = {};
this.paneRenaming = new PaneRenaming(this, state); this.paneRenaming = new PaneRenaming(this, state);

View File

@@ -57,7 +57,6 @@ export class Tree {
private readonly hub: Hub; private readonly hub: Hub;
private eventHub: EventHub; private eventHub: EventHub;
private readonly settings: SiteSettings; private readonly settings: SiteSettings;
private httpRoot: string;
private readonly alertSystem: Alert; private readonly alertSystem: Alert;
private root: JQuery; private root: JQuery;
private rowTemplate: JQuery; private rowTemplate: JQuery;
@@ -88,9 +87,6 @@ export class Tree {
this.hub = hub; this.hub = hub;
this.eventHub = hub.createEventHub(); this.eventHub = hub.createEventHub();
this.settings = Settings.getStoredSettings(); this.settings = Settings.getStoredSettings();
this.httpRoot = window.httpRoot;
this.alertSystem = new Alert(); this.alertSystem = new Alert();
this.alertSystem.prefixMessage = 'Tree #' + this.id; this.alertSystem.prefixMessage = 'Tree #' + this.id;
@@ -728,12 +724,12 @@ export class Tree {
this.sendCompileRequests(); this.sendCompileRequests();
}, newSettings.delayAfterChange); }, newSettings.delayAfterChange);
} }
private getPaneName() { private getPaneName() {
return `Tree #${this.id}`; return `Tree #${this.id}`;
} }
private updateTitle() { // eslint-disable-next-line no-unused-vars
updateTitle() {
const name = this.paneName ? this.paneName : this.getPaneName(); const name = this.paneName ? this.paneName : this.getPaneName();
this.container.setTitle(escapeHTML(name)); this.container.setTitle(escapeHTML(name));
} }

View File

@@ -57,7 +57,6 @@ class ActiveState {}
type OverrideState = IncompatibleState | InactiveState | ActiveState; type OverrideState = IncompatibleState | InactiveState | ActiveState;
export class CompilerOverridesWidget { export class CompilerOverridesWidget {
private domRoot: JQuery;
private popupDomRoot: JQuery<HTMLElement>; private popupDomRoot: JQuery<HTMLElement>;
private envVarsInput: JQuery<HTMLElement>; private envVarsInput: JQuery<HTMLElement>;
private dropdownButton: JQuery; private dropdownButton: JQuery;
@@ -65,8 +64,7 @@ export class CompilerOverridesWidget {
private configured: ConfiguredOverrides = []; private configured: ConfiguredOverrides = [];
private compiler: CompilerInfo | undefined; private compiler: CompilerInfo | undefined;
constructor(domRoot: JQuery, dropdownButton: JQuery, onChangeCallback: CompilerOverridesChangeCallback) { constructor(dropdownButton: JQuery, onChangeCallback: CompilerOverridesChangeCallback) {
this.domRoot = domRoot;
this.popupDomRoot = $('#overrides-selection'); this.popupDomRoot = $('#overrides-selection');
this.dropdownButton = dropdownButton; this.dropdownButton = dropdownButton;
this.envVarsInput = this.popupDomRoot.find('.envvars'); this.envVarsInput = this.popupDomRoot.find('.envvars');

View File

@@ -49,7 +49,6 @@ type FavRuntimeTool = {
type FavRuntimeTools = FavRuntimeTool[]; type FavRuntimeTools = FavRuntimeTool[];
export class RuntimeToolsWidget { export class RuntimeToolsWidget {
private domRoot: JQuery;
private popupDomRoot: JQuery<HTMLElement>; private popupDomRoot: JQuery<HTMLElement>;
private envVarsInput: JQuery<HTMLElement>; private envVarsInput: JQuery<HTMLElement>;
private dropdownButton: JQuery; private dropdownButton: JQuery;
@@ -58,8 +57,7 @@ export class RuntimeToolsWidget {
private compiler: CompilerInfo | undefined; private compiler: CompilerInfo | undefined;
private possibleTools: PossibleRuntimeTools; private possibleTools: PossibleRuntimeTools;
constructor(domRoot: JQuery, dropdownButton: JQuery, onChangeCallback: RuntimeToolsChangeCallback) { constructor(dropdownButton: JQuery, onChangeCallback: RuntimeToolsChangeCallback) {
this.domRoot = domRoot;
this.popupDomRoot = $('#runtimetools-selection'); this.popupDomRoot = $('#runtimetools-selection');
this.dropdownButton = dropdownButton; this.dropdownButton = dropdownButton;
this.envVarsInput = this.popupDomRoot.find('.envvars'); this.envVarsInput = this.popupDomRoot.find('.envvars');

View File

@@ -107,7 +107,7 @@ describe('Basic compiler invariants', () => {
describe('Compiler execution', () => { describe('Compiler execution', () => {
let ce: CompilationEnvironment; let ce: CompilationEnvironment;
let compiler: BaseCompiler; let compiler: BaseCompiler;
let compilerNoExec: BaseCompiler; // let compilerNoExec: BaseCompiler;
let win32compiler: Win32Compiler; let win32compiler: Win32Compiler;
const executingCompilerInfo = makeFakeCompilerInfo({ const executingCompilerInfo = makeFakeCompilerInfo({
@@ -163,22 +163,22 @@ describe('Compiler execution', () => {
ce = makeCompilationEnvironment({languages}); ce = makeCompilationEnvironment({languages});
compiler = new BaseCompiler(executingCompilerInfo, ce); compiler = new BaseCompiler(executingCompilerInfo, ce);
win32compiler = new Win32Compiler(win32CompilerInfo, ce); win32compiler = new Win32Compiler(win32CompilerInfo, ce);
compilerNoExec = new BaseCompiler(noExecuteSupportCompilerInfo, ce); // compilerNoExec = new BaseCompiler(noExecuteSupportCompilerInfo, ce);
}); });
// afterEach(() => restore()); // afterEach(() => restore());
function stubOutCallToExec(execStub, compiler, content, result, nthCall) { // function stubOutCallToExec(execStub, compiler, content, result, nthCall) {
execStub.onCall(nthCall || 0).callsFake((compiler, args) => { // execStub.onCall(nthCall || 0).callsFake((compiler, args) => {
const minusO = args.indexOf('-o'); // const minusO = args.indexOf('-o');
expect(minusO).toBeGreaterThanOrEqual(0); // expect(minusO).toBeGreaterThanOrEqual(0);
const output = args[minusO + 1]; // const output = args[minusO + 1];
// Maybe we should mock out the FS too; but that requires a lot more work. // // Maybe we should mock out the FS too; but that requires a lot more work.
fs.writeFileSync(output, content); // fs.writeFileSync(output, content);
result.filenameTransform = (x: string) => x; // result.filenameTransform = (x: string) => x;
return Promise.resolve(result); // return Promise.resolve(result);
}); // });
} // }
it('basecompiler should handle spaces in options correctly', () => { it('basecompiler should handle spaces in options correctly', () => {
const userOptions = []; const userOptions = [];

View File

@@ -11,6 +11,10 @@
"skipLibCheck": true, "skipLibCheck": true,
"strict": true, "strict": true,
"noImplicitAny": false, "noImplicitAny": false,
"noImplicitOverride": true "noImplicitOverride": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noUnusedLocals": true,
"noImplicitThis": true
} }
} }