Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(eslint): add unicorn/prevent abbreviations rule #2865

Merged
merged 11 commits into from
Sep 20, 2023
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = {
},
},
],
'unicorn/prevent-abbreviations': 'error',
'import/newline-after-import': ['error', { count: 1 }],
'import/first': 'error',
'import/order': [
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/generate-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- '.github/actions/build-setup/**/*'
- '.github/workflows/generate-documentation.yml'
- 'docs/users/**'
- 'scripts/docs.mjs'
- 'scripts/generate-users-documentation.mjs'
- 'src/**'
- '.nvmrc'
- 'package.json'
Expand All @@ -25,7 +25,7 @@ on:
- '.github/actions/custom-surge-preview/**/*'
- '.github/workflows/generate-documentation.yml'
- 'docs/users/**'
- 'scripts/docs.mjs'
- 'scripts/generate-users-documentation.mjs'
- 'src/**'
- '.nvmrc'
- 'package.json'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<title>bpmn-visualization - Library Integration</title>
<link rel="icon" type="image/svg+xml" href="./static/img/favicon.svg">
<script src="../ts/pages/lib-integration.ts" type="module"></script>
<script src="../ts/pages/library-integration.ts" type="module"></script>
</head>
<body>
<div id="bpmn-container-custom"></div>
Expand Down
10 changes: 5 additions & 5 deletions dev/ts/component/DropFileUserInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export class DropFileUserInterface {
this.addEventsOnDocument(this.outerContainerId, this.containerToFade);
}

private preventDefaults(e: Event): void {
e.preventDefault();
e.stopPropagation();
private preventDefaults(event: Event): void {
event.preventDefault();
event.stopPropagation();
}

private preventDefaultsOnEvents(events: string[], container: Element | Window): void {
Expand Down Expand Up @@ -152,8 +152,8 @@ export class DropFileUserInterface {
const dt = event.dataTransfer;
const files = dt.files;
dropCallback(files[0]);
} catch (e) {
const errorMessage = e instanceof Error ? e.message : String(e);
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logErrorAndOpenAlert(errorMessage);
} finally {
isDocument ? (this as Document).querySelector('#' + outerContainerId).classList.remove('dragging') : (this as HTMLElement).classList.remove('dragging');
Expand Down
46 changes: 23 additions & 23 deletions dev/ts/component/SvgExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ ${svgAsString}
const viewScale = this.graph.view.scale;

// Prepares SVG document that holds the output
const svgDoc = mxUtils.createXmlDocument();
const root = svgDoc.createElementNS(mxConstants.NS_SVG, 'svg');
const svgDocument = mxUtils.createXmlDocument();
const root = svgDocument.createElementNS(mxConstants.NS_SVG, 'svg');

const s = scale / viewScale;
const w = Math.max(1, Math.ceil(bounds.width * s) + 2 * border);
Expand All @@ -75,9 +75,9 @@ ${svgAsString}
root.setAttribute('width', w + 'px');
root.setAttribute('height', h + 'px');
root.setAttribute('viewBox', (crisp ? '-0.5 -0.5' : '0 0') + ' ' + w + ' ' + h);
svgDoc.appendChild(root);
svgDocument.appendChild(root);

const group = svgDoc.createElementNS(mxConstants.NS_SVG, 'g');
const group = svgDocument.createElementNS(mxConstants.NS_SVG, 'g');
root.appendChild(group);

const svgCanvas = this.createSvgCanvas(group);
Expand All @@ -98,7 +98,7 @@ ${svgAsString}
imgExport.includeOverlays = true;

imgExport.drawState(this.graph.getView().getState(this.graph.model.root), svgCanvas);
return svgDoc;
return svgDocument;
}

createSvgCanvas(node: Element): mxSvgCanvas2DType {
Expand All @@ -123,7 +123,7 @@ class CanvasForExport extends mxSvgCanvas2D {
y: number,
w: number,
h: number,
str: string,
content: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
align: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand All @@ -139,51 +139,51 @@ class CanvasForExport extends mxSvgCanvas2D {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
rotation: number,
): string {
return this.computeTruncatedText(str, w);
return this.computeTruncatedText(content, w);
}

override plainText(
x: number,
y: number,
w: number,
h: number,
str: string,
content: string,
align: string,
valign: string,
wrap: string,
overflow: string,
clip: string,
rotation: number,
dir: string,
direction: string,
): void {
str = this.computeTruncatedText(str, w);
super.plainText(x, y, w, h, str, align, valign, wrap, overflow, clip, rotation, dir);
content = this.computeTruncatedText(content, w);
super.plainText(x, y, w, h, content, align, valign, wrap, overflow, clip, rotation, direction);
}

private computeTruncatedText(str: string, w: number): string {
private computeTruncatedText(content: string, w: number): string {
// Assumes a max character width of 0.5em
if (str == null || this.state.fontSize <= 0) {
if (content == null || this.state.fontSize <= 0) {
return '';
}

try {
this.htmlConverter.innerHTML = str;
str = mxUtils.extractTextWithWhitespace(this.htmlConverter.childNodes);
this.htmlConverter.innerHTML = content;
content = mxUtils.extractTextWithWhitespace(this.htmlConverter.childNodes);

// Workaround for substring breaking double byte UTF
const exp = Math.ceil((2 * w) / this.state.fontSize);
const result = [];
let length = 0;
let index = 0;

while ((exp == 0 || length < exp) && index < str.length) {
const char = str.charCodeAt(index);
while ((exp == 0 || length < exp) && index < content.length) {
const char = content.charCodeAt(index);
if (char == 10 || char == 13) {
if (length > 0) {
break;
}
} else {
result.push(str.charAt(index));
result.push(content.charAt(index));
if (char < 255) {
length++;
}
Expand All @@ -192,12 +192,12 @@ class CanvasForExport extends mxSvgCanvas2D {
}

// Uses result and adds ellipsis if more than 1 char remains
if (result.length < str.length && str.length - result.length > 1) {
str = mxUtils.trim(result.join('')) + '...';
if (result.length < content.length && content.length - result.length > 1) {
content = mxUtils.trim(result.join('')) + '...';
}
} catch (e) {
console.warn('Error while computing txt label', e);
} catch (error) {
console.warn('Error while computing txt label', error);
}
return str;
return content;
}
}
4 changes: 2 additions & 2 deletions dev/ts/component/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function downloadAsPng(svg: string): void {
document.body.appendChild(imgPreview);

const canvas = document.createElement('canvas');
const canvasCtx = canvas.getContext('2d');
const canvasContext = canvas.getContext('2d');

imgPreview.onload = function () {
const img = new Image();
Expand All @@ -73,7 +73,7 @@ export function downloadAsPng(svg: string): void {
canvas.height = imgPreview.naturalHeight;
img.crossOrigin = 'Anonymous';
img.onload = function () {
canvasCtx.drawImage(img, 0, 0);
canvasContext.drawImage(img, 0, 0);
URL.revokeObjectURL(svgUrl);
const pngInBase64 = canvas.toDataURL('image/png');
document.body.removeChild(imgPreview);
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions dev/ts/pages/bpmn-rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { documentReady, log, logError, startBpmnVisualization } from '../dev-bundle-index';
import { documentReady, log, logError, startBpmnVisualization } from '../development-bundle-index';

function statusFetchKO(errorMsg: string): void {
logError(errorMsg);
function statusFetchKO(errorMessage: string): void {
logError(errorMessage);
const statusElt = document.getElementById('status-zone');
statusElt.innerText = errorMsg;
statusElt.innerText = errorMessage;
statusElt.className = 'status-ko';
log('Status zone set with error:', errorMsg);
log('Status zone set with error:', errorMessage);
}

documentReady(() => startBpmnVisualization({ globalOptions: { container: 'bpmn-container' }, statusKoNotifier: statusFetchKO }));
22 changes: 11 additions & 11 deletions dev/ts/pages/diagram-navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { configureControlsPanel, configureMousePointer, documentReady, fit, FitType, startBpmnVisualization, zoom, ZoomType } from '../dev-bundle-index';
import { configureControlsPanel, configureMousePointer, documentReady, fit, FitType, startBpmnVisualization, zoom, ZoomType } from '../development-bundle-index';

function configureFitAndZoomButtons(): void {
Object.values(FitType).forEach(fitType => {
Expand All @@ -26,37 +26,37 @@ function configureFitAndZoomButtons(): void {
}

function configureZoomThrottleInput(parameters: URLSearchParams): HTMLInputElement {
const elZoomThrottle = document.getElementById('zoom-throttle') as HTMLInputElement;
const zoomThrottleElement = document.getElementById('zoom-throttle') as HTMLInputElement;
if (parameters.get('zoomThrottle')) {
elZoomThrottle.value = parameters.get('zoomThrottle');
zoomThrottleElement.value = parameters.get('zoomThrottle');
}
return elZoomThrottle;
return zoomThrottleElement;
}

function configureZoomDebounceInput(parameters: URLSearchParams): HTMLInputElement {
const elZoomDebounce = document.getElementById('zoom-debounce') as HTMLInputElement;
const zoomDebounceElement = document.getElementById('zoom-debounce') as HTMLInputElement;
if (parameters.get('zoomDebounce')) {
elZoomDebounce.value = parameters.get('zoomDebounce');
zoomDebounceElement.value = parameters.get('zoomDebounce');
}
return elZoomDebounce;
return zoomDebounceElement;
}

function start(): void {
const parameters = new URLSearchParams(window.location.search);
configureMousePointer(parameters);
configureControlsPanel(parameters);

const elZoomThrottle = configureZoomThrottleInput(parameters);
const elZoomDebounce = configureZoomDebounceInput(parameters);
const zoomThrottleElement = configureZoomThrottleInput(parameters);
const zoomDebounceElement = configureZoomDebounceInput(parameters);

startBpmnVisualization({
globalOptions: {
container: 'bpmn-container',
navigation: {
enabled: true,
zoom: {
throttleDelay: Number(elZoomThrottle.value),
debounceDelay: Number(elZoomDebounce.value),
throttleDelay: Number(zoomThrottleElement.value),
debounceDelay: Number(zoomDebounceElement.value),
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions dev/ts/pages/elements-identification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import type { BpmnElementKind, BpmnSemantic, Overlay, ShapeStyleUpdate, StyleUpdate } from '../dev-bundle-index';
import type { BpmnElementKind, BpmnSemantic, Overlay, ShapeStyleUpdate, StyleUpdate } from '../development-bundle-index';

import {
addCssClasses,
Expand All @@ -37,7 +37,7 @@ import {
ShapeBpmnElementKind,
isChildOfSubProcess,
isFlowKind,
} from '../dev-bundle-index';
} from '../development-bundle-index';

let lastIdentifiedBpmnIds: string[] = [];
let lastIdentifiedParentBpmnIds: string[] = [];
Expand Down
8 changes: 4 additions & 4 deletions dev/ts/pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import type { FitOptions, FitType } from '../dev-bundle-index';
import type { FitOptions, FitType } from '../development-bundle-index';

import {
documentReady,
Expand All @@ -30,7 +30,7 @@ import {
zoom,
ZoomType,
windowAlertStatusKoNotifier,
} from '../dev-bundle-index';
} from '../development-bundle-index';

let fitOnLoad = true;
let fitOptions: FitOptions = {};
Expand Down Expand Up @@ -120,8 +120,8 @@ function configureDisplayedFooterContent(): void {
function preventZoomingPage(): void {
document.addEventListener(
'wheel',
(e: WheelEvent): void => {
if (e.ctrlKey) e.preventDefault(); // prevent whole page zoom
(event: WheelEvent): void => {
if (event.ctrlKey) event.preventDefault(); // prevent whole page zoom
},
{ passive: false, capture: true },
);
Expand Down
File renamed without changes.
14 changes: 11 additions & 3 deletions dev/ts/pages/overlays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import type { Overlay, OverlayPosition } from '../dev-bundle-index';

import { addOverlays, configureControlsPanel, configureMousePointer, documentReady, getModelElementsByIds, removeAllOverlays, startBpmnVisualization } from '../dev-bundle-index';
import type { Overlay, OverlayPosition } from '../development-bundle-index';

import {
addOverlays,
configureControlsPanel,
configureMousePointer,
documentReady,
getModelElementsByIds,
removeAllOverlays,
startBpmnVisualization,
} from '../development-bundle-index';

const bpmnIdInputElt = document.getElementById('bpmn-id-input') as HTMLInputElement;

Expand Down
8 changes: 4 additions & 4 deletions dev/ts/shared/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ function showMousePointer(): void {
true,
);
function updateButtons(buttons: number): void {
for (let i = 0; i < 5; i++) {
box.classList.toggle('button-' + i, (buttons & (1 << i)) > 0);
for (let index = 0; index < 5; index++) {
box.classList.toggle('button-' + index, (buttons & (1 << index)) > 0);
}
}
}
Expand All @@ -97,8 +97,8 @@ export function configureMousePointer(parameters: URLSearchParams): void {
}

export function configureControlsPanel(parameters: URLSearchParams): void {
const elControlsPanel = document.getElementById('controls-panel');
const controlsPanelElement = document.getElementById('controls-panel');
if (parameters.get('showControlsPanel') === 'true') {
elControlsPanel.classList.remove('hidden');
controlsPanelElement.classList.remove('hidden');
}
}
Loading