Skip to content

Commit

Permalink
Add noUnusedLocals to tsconfig + fix the new alerts (compiler-explore…
Browse files Browse the repository at this point in the history
…r#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!
-->
  • Loading branch information
OfekShilon committed May 14, 2024
1 parent 92b6056 commit 38a253a
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 70 deletions.
2 changes: 1 addition & 1 deletion lib/compilers/d8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion lib/compilers/solidity-eravm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
3 changes: 0 additions & 3 deletions lib/llvm-ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ export class LlvmAstParser {
// Refers to the user's source file rather than a system header
const sourceRegex = /<source>/g;

const slocRegex = /<<invalid sloc>>/;

// <<invalid sloc>, /app/hell.hpp:5:1>
const userSource = /<<invalid sloc>, \/app\/.*:\d+:\d+>/;

Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 1 addition & 4 deletions lib/parsers/asm-parser-mads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,10 @@ export class MadsAsmParser extends AsmParser {
const startTime = process.hrtime.bigint();
const asm: ParsedAsmResultLine[] = [];
const labelDefinitions: Record<string, number> = {};
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] === '<') {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/parsers/asm-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions lib/runtime-tools/heaptrack-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -162,8 +160,6 @@ export class HeaptrackWrapper extends BaseRuntimeTool {
}

public async exec(filepath: string, args: string[], execOptions: ExecutionOptions): Promise<UnprocessedExecResult> {
const dirPath = unwrap(execOptions.appHome);

const runOptions = JSON.parse(JSON.stringify(execOptions));
const interpretOptions = JSON.parse(JSON.stringify(execOptions));
interpretOptions.maxOutput = 1024 * 1024 * 1024;
Expand Down
6 changes: 0 additions & 6 deletions static/compiler-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
const includesOrEmbeds = new IncludeDownloads();

Expand Down
4 changes: 2 additions & 2 deletions static/compiler-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
12 changes: 0 additions & 12 deletions static/panes/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
private readonly id: number;
private sourceTreeId: number | null;
private sourceEditorId: number | null;
private originalCompilerId: string;
private readonly infoByLang: Record<string, {compiler: string; options: string}>;
private deferCompiles: boolean;
private needsCompile: boolean;
Expand All @@ -173,7 +172,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
private linkedFadeTimeoutId: NodeJS.Timeout | null;
private toolsMenu: JQuery<HTMLElement> | null;
private revealJumpStack: (monaco.editor.ICodeEditorViewState | null)[];
private compilerPickerElement: JQuery<HTMLElement>;
private compilerPicker: CompilerPicker;
private compiler: CompilerInfo | null;
private recentInstructionSet: InstructionSet | null;
Expand Down Expand Up @@ -238,7 +236,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
private bottomBar: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private statusLabel: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private statusIcon: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private monacoPlaceholder: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
private rustHirButton: JQuery<HTMLElement>;
private libsWidget: LibsWidget | null;
private isLabelCtxKey: monaco.editor.IContextKey<boolean>;
Expand Down Expand Up @@ -363,7 +360,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.deviceViewOpen = !!state.deviceViewOpen;
this.flagsViewOpen = state.flagsViewOpen || false;
this.wantOptInfo = state.wantOptInfo;
this.originalCompilerId = state.compiler;
this.selection = state.selection;
}

Expand Down Expand Up @@ -2539,7 +2535,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.optionsField.val(this.options);

this.shortCompilerName = this.domRoot.find('.short-compiler-name');
this.compilerPickerElement = this.domRoot.find('.compiler-picker');
this.setCompilerVersionPopover();

this.topBar = this.domRoot.find('.top-bar');
Expand All @@ -2549,8 +2544,6 @@ export class Compiler extends MonacoPane<monaco.editor.IStandaloneCodeEditor, Co
this.hideable = this.domRoot.find('.hideable');
this.statusIcon = this.domRoot.find('.status-icon');

this.monacoPlaceholder = this.domRoot.find('.monaco-placeholder');

$(this.domRoot).on('keydown', event => {
if ((event.ctrlKey || event.metaKey) && String.fromCharCode(event.which).toLowerCase() === 's') {
event.preventDefault();
Expand Down Expand Up @@ -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}) {
if (this.compilerPicker instanceof CompilerPicker)
this.compilerPicker.update(this.currentLangId ?? '', this.compiler?.id ?? '');
Expand Down
10 changes: 0 additions & 10 deletions static/panes/conformance-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLElement>;
picker: CompilerPicker | null;
Expand Down Expand Up @@ -79,7 +74,6 @@ export class Conformance extends Pane<ConformanceViewState> {
private compilerPickers: CompilerEntry[] = [];
private expandedSourceAndFiles: SourceAndFiles | null;
private currentLibs: Lib[];
private status: ConformanceStatus;
private readonly stateByLang: Record<string, ConformanceViewState>;
private libsButton: JQuery<HTMLElement>;
private conformanceContentRoot: JQuery<HTMLElementTagNameMap[keyof HTMLElementTagNameMap]>;
Expand All @@ -97,10 +91,6 @@ export class Conformance extends Pane<ConformanceViewState> {
this.sourceNeedsExpanding = true;
this.expandedSourceAndFiles = null;

this.status = {
allowCompile: false,
allowAdd: true,
};
this.stateByLang = {};

this.paneRenaming = new PaneRenaming(this, state);
Expand Down
8 changes: 2 additions & 6 deletions static/panes/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 1 addition & 3 deletions static/widgets/compiler-overrides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ class ActiveState {}
type OverrideState = IncompatibleState | InactiveState | ActiveState;

export class CompilerOverridesWidget {
private domRoot: JQuery;
private popupDomRoot: JQuery<HTMLElement>;
private envVarsInput: JQuery<HTMLElement>;
private dropdownButton: JQuery;
private onChangeCallback: CompilerOverridesChangeCallback;
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');
Expand Down
4 changes: 1 addition & 3 deletions static/widgets/runtime-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type FavRuntimeTool = {
type FavRuntimeTools = FavRuntimeTool[];

export class RuntimeToolsWidget {
private domRoot: JQuery;
private popupDomRoot: JQuery<HTMLElement>;
private envVarsInput: JQuery<HTMLElement>;
private dropdownButton: JQuery;
Expand All @@ -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');
Expand Down
26 changes: 13 additions & 13 deletions test/base-compiler-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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 = [];
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"skipLibCheck": true,
"strict": true,
"noImplicitAny": false,
"noImplicitOverride": true
"noImplicitOverride": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noUnusedLocals": true,
"noImplicitThis": true
}
}

0 comments on commit 38a253a

Please sign in to comment.