Skip to content

Commit

Permalink
chore: enforce no unused parameters and locals with TypeScript (#3051)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tbouffard authored Mar 7, 2024
1 parent 4c08adc commit 6886a6b
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 35 deletions.
2 changes: 0 additions & 2 deletions dev/ts/component/DropFileUserInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,7 +28,6 @@ export class DropFileUserInterface {
) {
this.document = window.document;
this.head = document.head;
this.body = document.body;
this.initializeDragAndDrop();
}

Expand Down
22 changes: 11 additions & 11 deletions dev/ts/component/SvgExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/component/mxgraph/shape/render/icon-painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/config/jest.image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class RetriesCounter {

const retriesCounter = new RetriesCounter();

async function saveAndRegisterImages(matcherContext: MatcherContext, received: Buffer, options: MatchImageSnapshotOptions): Promise<void> {
async function saveAndRegisterImages(matcherContext: MatcherContext, options: MatchImageSnapshotOptions): Promise<void> {
const snapshotIdentifier = options.customSnapshotIdentifier as string;
// Manage expected and received images
const baseImagePathWithName = `${options.customDiffDir}/${snapshotIdentifier}`;
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/unit/component/mxgraph/renderer/StyleComputer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')}` : '';
Expand Down Expand Up @@ -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`);
});
Expand Down Expand Up @@ -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}`);
});
Expand All @@ -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}`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down
4 changes: 2 additions & 2 deletions test/unit/component/parser/json/BpmnJsonParser.marker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/helpers/TestUtils.BpmnJsonParser.event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
});

Expand Down
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
"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",
"sourceMap": false,
"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,
Expand Down

0 comments on commit 6886a6b

Please sign in to comment.