From 6886a6b18aca50467a3465ea7e85fd29b9232e7f Mon Sep 17 00:00:00 2001 From: Thomas Bouffard <27200110+tbouffard@users.noreply.github.com> Date: Thu, 7 Mar 2024 14:21:18 +0100 Subject: [PATCH] chore: enforce no unused parameters and locals with TypeScript (#3051) Fix new TS compiler errors: remove or prefix (when must be kept to override methods) parameters, remove unused class properties. Unit tests: mark unused parameters in test function. They must be kept as the parameter is used to generate the test title or because it is required by the function signature. Group "noXXX" TypeScript compiler options. --- dev/ts/component/DropFileUserInterface.ts | 2 -- dev/ts/component/SvgExporter.ts | 22 +++++++++---------- .../mxgraph/shape/render/icon-painter.ts | 8 +++---- test/config/jest.image.ts | 4 ++-- .../mxgraph/renderer/StyleComputer.test.ts | 8 +++---- .../json/BpmnJsonParser.association.test.ts | 2 +- .../json/BpmnJsonParser.callActivity.test.ts | 2 +- ...Parser.event.with.event.definition.test.ts | 2 +- .../json/BpmnJsonParser.flowNode.test.ts | 2 +- .../parser/json/BpmnJsonParser.marker.test.ts | 4 ++-- ...BpmnJsonParser.sequenceFlow.normal.test.ts | 2 +- .../json/BpmnJsonParser.sub.process.test.ts | 2 +- .../BpmnJsonParser.text.annotation.test.ts | 2 +- .../helpers/TestUtils.BpmnJsonParser.event.ts | 2 +- tsconfig.json | 6 +++-- 15 files changed, 35 insertions(+), 35 deletions(-) diff --git a/dev/ts/component/DropFileUserInterface.ts b/dev/ts/component/DropFileUserInterface.ts index c76a7236a3..f5e39d7658 100644 --- a/dev/ts/component/DropFileUserInterface.ts +++ b/dev/ts/component/DropFileUserInterface.ts @@ -19,7 +19,6 @@ import { logErrorAndOpenAlert } from '../shared/internal-helpers'; export class DropFileUserInterface { private document: Document; private head: Element; - private body: Element; constructor( private window: Window, @@ -29,7 +28,6 @@ export class DropFileUserInterface { ) { this.document = window.document; this.head = document.head; - this.body = document.body; this.initializeDragAndDrop(); } diff --git a/dev/ts/component/SvgExporter.ts b/dev/ts/component/SvgExporter.ts index fb38e99c5c..826ba4224f 100644 --- a/dev/ts/component/SvgExporter.ts +++ b/dev/ts/component/SvgExporter.ts @@ -118,26 +118,26 @@ class CanvasForExport extends mxSvgCanvas2D { } override getAlternateText( - fo: Element, - x: number, - y: number, + _fo: Element, + _x: number, + _y: number, w: number, - h: number, + _h: number, content: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - align: string, + _align: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - valign: string, + _valign: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - wrap: string, + _wrap: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - format: string, + _format: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - overflow: string, + _overflow: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - clip: string, + _clip: string, // eslint-disable-next-line @typescript-eslint/no-unused-vars - rotation: number, + _rotation: number, ): string { return this.computeTruncatedText(content, w); } diff --git a/src/component/mxgraph/shape/render/icon-painter.ts b/src/component/mxgraph/shape/render/icon-painter.ts index 12ed9714e5..713c2c43d7 100644 --- a/src/component/mxgraph/shape/render/icon-painter.ts +++ b/src/component/mxgraph/shape/render/icon-painter.ts @@ -406,12 +406,12 @@ export class IconPainter { */ paintAsteriskIcon(paintParameter: PaintParameter): void { const canvas = this.newBpmnCanvas(paintParameter, { height: 1, width: 1 }); - drawVerticalLine(paintParameter, canvas); + drawVerticalLine(canvas); canvas.fillAndStroke(); - drawVerticalLine(paintParameter, canvas); + drawVerticalLine(canvas); canvas.rotateOnIconCenter(60); canvas.fillAndStroke(); - drawVerticalLine(paintParameter, canvas); + drawVerticalLine(canvas); canvas.rotateOnIconCenter(240); canvas.fillAndStroke(); } @@ -833,7 +833,7 @@ export class IconPainter { } } -function drawVerticalLine(paintParameter: PaintParameter, canvas: BpmnCanvas): void { +function drawVerticalLine(canvas: BpmnCanvas): void { canvas.begin(); canvas.moveTo(0.38, 0); canvas.lineTo(0.62, 0); diff --git a/test/config/jest.image.ts b/test/config/jest.image.ts index 17b39ac920..a6f0ffce60 100644 --- a/test/config/jest.image.ts +++ b/test/config/jest.image.ts @@ -59,7 +59,7 @@ class RetriesCounter { const retriesCounter = new RetriesCounter(); -async function saveAndRegisterImages(matcherContext: MatcherContext, received: Buffer, options: MatchImageSnapshotOptions): Promise { +async function saveAndRegisterImages(matcherContext: MatcherContext, options: MatchImageSnapshotOptions): Promise { const snapshotIdentifier = options.customSnapshotIdentifier as string; // Manage expected and received images const baseImagePathWithName = `${options.customDiffDir}/${snapshotIdentifier}`; @@ -130,7 +130,7 @@ async function toMatchImageSnapshotCustom(this: MatcherContext, received: Buffer } else { jestLog('Result: failure'); if (retriesCounter.hasReachMaxRetries(testId)) { - await saveAndRegisterImages(this, received, options); + await saveAndRegisterImages(this, options); } // Add configured failure threshold in the error message diff --git a/test/unit/component/mxgraph/renderer/StyleComputer.test.ts b/test/unit/component/mxgraph/renderer/StyleComputer.test.ts index ad53b79623..51fe9004e6 100644 --- a/test/unit/component/mxgraph/renderer/StyleComputer.test.ts +++ b/test/unit/component/mxgraph/renderer/StyleComputer.test.ts @@ -290,7 +290,7 @@ describe('Style Computer', () => { describe.each([ ['expanded', []], ['collapsed', [ShapeBpmnMarkerKind.EXPAND]], - ])(`%s`, (expandKind: string, markers: ShapeBpmnMarkerKind[]) => { + ])(`%s`, (_expandKind: string, markers: ShapeBpmnMarkerKind[]) => { describe.each(Object.values(ShapeBpmnSubProcessKind))(`%s`, (subProcessKind: ShapeBpmnSubProcessKind) => { markers = getExpectedMarkers(markers, subProcessKind); const additionalMarkerStyle = markers.length > 0 ? `;bpmn.markers=${markers.join(',')}` : ''; @@ -361,7 +361,7 @@ describe('Style Computer', () => { it.each([ ['non-instantiating', false], ['instantiating', true], - ])('%s receive task', (instantiatingKind: string, instantiate: boolean) => { + ])('%s receive task', (_instantiatingKind: string, instantiate: boolean) => { const shape = newShape(newShapeBpmnActivity(ShapeBpmnElementKind.TASK_RECEIVE, undefined, instantiate), newLabel({ name: 'Arial' })); expect(computeStyle(shape)).toBe(`receiveTask;bpmn.isInstantiating=${instantiate};fontFamily=Arial`); }); @@ -394,7 +394,7 @@ describe('Style Computer', () => { ['vertical', false, '1'], ['horizontal', true, '0'], ['no isHorizontal value for a', undefined, '1'], - ])('%s pool references a Process', (title: string, isHorizontal: boolean, expected: string) => { + ])('%s pool references a Process', (_title: string, isHorizontal: boolean, expected: string) => { const shape = newShape(newShapeBpmnElement(ShapeBpmnElementKind.POOL), undefined, isHorizontal); expect(computeStyle(shape)).toBe(`pool;horizontal=${expected}`); }); @@ -405,7 +405,7 @@ describe('Style Computer', () => { ['vertical', false, '1'], ['horizontal', true, '0'], ['no isHorizontal value for a', undefined, '1'], - ])('%s lane', (title: string, isHorizontal: boolean, expected: string) => { + ])('%s lane', (_title: string, isHorizontal: boolean, expected: string) => { const shape = newShape(newShapeBpmnElement(ShapeBpmnElementKind.LANE), undefined, isHorizontal); expect(computeStyle(shape)).toBe(`lane;horizontal=${expected}`); }); diff --git a/test/unit/component/parser/json/BpmnJsonParser.association.test.ts b/test/unit/component/parser/json/BpmnJsonParser.association.test.ts index fbc84ccc57..b4d5c359fb 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.association.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.association.test.ts @@ -37,7 +37,7 @@ describe('parse bpmn as json for association', () => { ['array', [processJsonAsObjectWithAssociationJsonAsObject]], ])( `should convert as Edge, when an association is an attribute (as object) of 'process' (as %s)`, - (title: string, processParameter: BuildProcessParameter | BuildProcessParameter[]) => { + (_title: string, processParameter: BuildProcessParameter | BuildProcessParameter[]) => { const json = buildDefinitions({ process: processParameter }); const model = parseJsonAndExpectOnlyEdges(json, 1); diff --git a/test/unit/component/parser/json/BpmnJsonParser.callActivity.test.ts b/test/unit/component/parser/json/BpmnJsonParser.callActivity.test.ts index 13bcb3c84d..ca0a00015f 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.callActivity.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.callActivity.test.ts @@ -44,7 +44,7 @@ describe('parse bpmn as json for callActivity', () => { ['array', [callActivityJson]], ])( `should convert as Shape, when a process contains a ${expandedKind} call activity calling another existing process`, - (title, callActivity: BuildCallActivityParameter | BuildCallActivityParameter[]) => { + (_title, callActivity: BuildCallActivityParameter | BuildCallActivityParameter[]) => { const json: BpmnJsonModel = buildDefinitions({ process: [ { diff --git a/test/unit/component/parser/json/BpmnJsonParser.event.with.event.definition.test.ts b/test/unit/component/parser/json/BpmnJsonParser.event.with.event.definition.test.ts index dfd1c728b5..dbad00dc36 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.event.with.event.definition.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.event.with.event.definition.test.ts @@ -83,7 +83,7 @@ describe.each([ShapeBpmnElementKind.EVENT_START, ShapeBpmnElementKind.EVENT_END, it.each(eventDefinitionParameters)( `should convert as Shape, when '${eventDefinitionKind}EventDefinition' is %s, ${titleForEventDefinitionIsAttributeOf}`, - (title: string, eventDefinition: string | TEventDefinition) => { + (_title: string, eventDefinition: string | TEventDefinition) => { testMustConvertShapes( { bpmnKind: expectedShapeBpmnElementKind as BuildNotBoundaryEventKind, diff --git a/test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts b/test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts index 1097dbd125..d881787752 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.flowNode.test.ts @@ -50,7 +50,7 @@ describe.each([ it.each([ ['object', processWithFlowNodeAsObject], ['array', [processWithFlowNodeAsObject]], - ])(`should convert as Shape, when a ${bpmnKind} is an attribute (as object) of 'process' (as %s)`, (title: string, processJson: TProcess | TProcess[]) => { + ])(`should convert as Shape, when a ${bpmnKind} is an attribute (as object) of 'process' (as %s)`, (_title: string, processJson: TProcess | TProcess[]) => { const json: BpmnJsonModel = { definitions: { targetNamespace: '', diff --git a/test/unit/component/parser/json/BpmnJsonParser.marker.test.ts b/test/unit/component/parser/json/BpmnJsonParser.marker.test.ts index e176aa7963..052c85efb4 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.marker.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.marker.test.ts @@ -48,7 +48,7 @@ describe.each([ ])( `should convert as Shape with ${expectedMarkerKind} marker, when '${bpmnLoopCharacteristicsKind}' is an attribute (as %s) of '${bpmnSemanticType}' and BPMNShape is expanded`, ( - title: string, + _title: string, loopCharacteristics: | string | TStandardLoopCharacteristics @@ -138,7 +138,7 @@ describe.each([ ['array with object', [{ isSequential }]], ])( `should convert as Shape with ${expectedMarkerKind} marker, when 'isSequential' is an attribute (as ${isSequential}) of 'multiInstanceLoopCharacteristics' (as %s) of '${bpmnSemanticType}' and BPMNShape is expanded`, - (title: string, loopCharacteristics: TMultiInstanceLoopCharacteristics | TMultiInstanceLoopCharacteristics[]) => { + (_title: string, loopCharacteristics: TMultiInstanceLoopCharacteristics | TMultiInstanceLoopCharacteristics[]) => { const json: BpmnJsonModel = { definitions: { targetNamespace: '', diff --git a/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.normal.test.ts b/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.normal.test.ts index 52c5db6189..24a3f27ddd 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.normal.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.sequenceFlow.normal.test.ts @@ -35,7 +35,7 @@ describe('parse bpmn as json for sequence flow', () => { it.each([ ['object', processWithSequenceFlowAsObject], ['array', [processWithSequenceFlowAsObject]], - ])(`should convert as Edge, when a sequence flow is an attribute (as object) of 'process' (as %s)`, (title: string, processJson: TProcess | TProcess[]) => { + ])(`should convert as Edge, when a sequence flow is an attribute (as object) of 'process' (as %s)`, (_title: string, processJson: TProcess | TProcess[]) => { const json: BpmnJsonModel = { definitions: { targetNamespace: '', diff --git a/test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts b/test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts index ee5807b81a..ddec8d5ead 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.sub.process.test.ts @@ -91,7 +91,7 @@ describe('parse bpmn as json for sub-process', () => { ['array', [processWithSubProcessAsObject]], ])( `should convert as Shape, when a ${expandedKind} ${expectedShapeBpmnSubProcessKind} sub-process is an attribute (as object) of 'process' (as %s)`, - (title: string, processParameter: BuildProcessParameter | BuildProcessParameter[]) => { + (_title: string, processParameter: BuildProcessParameter | BuildProcessParameter[]) => { const json = buildDefinitions({ process: processParameter }); const model = parseJsonAndExpectOnlySubProcess(json, expectedShapeBpmnSubProcessKind, 1); diff --git a/test/unit/component/parser/json/BpmnJsonParser.text.annotation.test.ts b/test/unit/component/parser/json/BpmnJsonParser.text.annotation.test.ts index 93e8e4bab4..2db0f1e97f 100644 --- a/test/unit/component/parser/json/BpmnJsonParser.text.annotation.test.ts +++ b/test/unit/component/parser/json/BpmnJsonParser.text.annotation.test.ts @@ -36,7 +36,7 @@ describe('parse bpmn as json for text annotation', () => { ['array', [processWithArtifactAsObject]], ])( `should convert as Shape, when a text annotation is an attribute (as object) of 'process' (as %s)`, - (title: string, processParameter: BuildProcessParameter | BuildProcessParameter[]) => { + (_title: string, processParameter: BuildProcessParameter | BuildProcessParameter[]) => { const json = buildDefinitions({ process: processParameter }); const model = parseJsonAndExpectOnlyFlowNodes(json, 1); diff --git a/test/unit/helpers/TestUtils.BpmnJsonParser.event.ts b/test/unit/helpers/TestUtils.BpmnJsonParser.event.ts index 3f15e0d2e6..c639264992 100644 --- a/test/unit/helpers/TestUtils.BpmnJsonParser.event.ts +++ b/test/unit/helpers/TestUtils.BpmnJsonParser.event.ts @@ -78,7 +78,7 @@ export function executeEventCommonTests(buildEventParameter: BuildEventParameter it.each([ ["'name'", 'event name'], ["no 'name'", undefined], - ])(`should convert as Shape, when '${buildEventParameter.bpmnKind}' has %s, ${titleSuffix}`, (title: string, eventName: string) => { + ])(`should convert as Shape, when '${buildEventParameter.bpmnKind}' has %s, ${titleSuffix}`, (_title: string, eventName: string) => { testMustConvertShapes({ ...buildEventParameter, name: eventName }, { ...omitExpectedShape, bpmnElementName: eventName }); }); diff --git a/tsconfig.json b/tsconfig.json index 93f5daf185..01afd3b4fb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,11 +4,14 @@ "outDir": "./build/lib", "module": "ES2015", "target": "ES2015", - "noImplicitAny": true, "strictBindCallApply": true, "alwaysStrict": true, "strictFunctionTypes": true, + "noImplicitAny": true, + "noImplicitOverride": true, "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, "skipLibCheck": false, "experimentalDecorators": true, "moduleResolution": "node", @@ -16,7 +19,6 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "stripInternal": true, - "noImplicitOverride": true, // Vitejs requirements https://vitejs.dev/guide/features.html#typescript-compiler-options "isolatedModules": true, // https://esbuild.github.io/content-types/#isolated-modules "useDefineForClassFields": true,