Skip to content

Commit

Permalink
chore(eslint): enable 3 rules of the unicorn plugin (#2912)
Browse files Browse the repository at this point in the history
Add `unicorn/prefer-at`, `unicorn/prefer-dom-node-dataset`, `unicorn/text-encoding-identifier-case` rules.
  • Loading branch information
csouchet authored Oct 6, 2023
1 parent e4953fe commit 6cf48c4
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ module.exports = {
'unicorn/prefer-ternary': 'error',
'unicorn/prefer-logical-operator-over-ternary': 'error',
'unicorn/consistent-function-scoping': 'error',
'unicorn/prefer-at': 'error',
'unicorn/prefer-dom-node-append': 'error',
'unicorn/prefer-dom-node-dataset': 'error',
'unicorn/prefer-dom-node-remove': 'error',
'unicorn/no-negated-condition': 'error',
'unicorn/no-array-callback-reference': 'error',
Expand All @@ -72,6 +74,7 @@ module.exports = {
'unicorn/prefer-switch': 'error',
'unicorn/switch-case-braces': 'error',
'unicorn/prefer-spread': 'error',
'unicorn/text-encoding-identifier-case': 'error',
'import/newline-after-import': ['error', { count: 1 }],
'import/first': 'error',
'import/order': [
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils/parseBpmn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if (!['json', 'model'].includes(outputType)) {
console.info('Use BPMN diagram located at "%s"', bpmnFilePath);

const xmlParser = new BpmnXmlParser();
const json = xmlParser.parse(readFileSync(bpmnFilePath, 'utf-8', __dirname));
const json = xmlParser.parse(readFileSync(bpmnFilePath, 'utf8', __dirname));
const prettyString = (object: BpmnJsonModel | BpmnModel): string => JSON.stringify(object, null, 2);

let result = '';
Expand Down
2 changes: 1 addition & 1 deletion src/component/mxgraph/BpmnCellRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class BpmnCellRenderer extends mxgraph.mxCellRenderer {
// START bpmn-visualization CUSTOMIZATION
if (overlayShape instanceof OverlayBadgeShape) {
overlayShape.node.classList.add('overlay-badge');
overlayShape.node.setAttribute('data-bpmn-id', state.cell.id);
overlayShape.node.dataset.bpmnId = state.cell.id;
}
// END bpmn-visualization CUSTOMIZATION

Expand Down
2 changes: 1 addition & 1 deletion src/component/mxgraph/BpmnGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,6 @@ class BpmnGraphView extends mxgraph.mxGraphView {
return super.getFloatingTerminalPoint(edge, start, end, source);
}
const pts = edge.absolutePoints;
return source ? pts[1] : pts[pts.length - 2];
return source ? pts[1] : pts.at(-2);
}
}
2 changes: 1 addition & 1 deletion src/component/mxgraph/config/ShapeConfigurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export default class ShapeConfigurator {
}

this.node.setAttribute('class', allBpmnClassNames.join(' '));
this.node.setAttribute('data-bpmn-id', this.state.cell.id);
this.node.dataset.bpmnId = this.state.cell.id;
}
// END bpmn-visualization CUSTOMIZATION
canvas.minStrokeWidth = this.minSvgStrokeWidth;
Expand Down
2 changes: 1 addition & 1 deletion src/component/mxgraph/overlay/custom-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class MxGraphCustomOverlay extends mxgraph.mxCellOverlay {
}
// last point for end position
else {
return pts[pts.length - 1];
return pts.at(-1);
}
}
}
2 changes: 1 addition & 1 deletion src/component/mxgraph/renderer/CoordinatesTranslator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class CoordinatesTranslator {
const points: mxPointType[] = edge.geometry.points;

const p0 = points[0];
const pe = points[points.length - 1];
const pe = points.at(-1);

if (p0 != null && pe != null) {
const dx = pe.x - p0.x;
Expand Down
2 changes: 1 addition & 1 deletion src/component/registry/bpmn-elements-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class BpmnElementsRegistry implements CssClassesRegistry, ElementsRegistr
}

private getRelatedBpmnSemantic(htmlElement: HTMLElement): BpmnSemantic {
return this.bpmnModelRegistry.getBpmnSemantic(htmlElement.getAttribute('data-bpmn-id'));
return this.bpmnModelRegistry.getBpmnSemantic(htmlElement.dataset.bpmnId);
}

addCssClasses(bpmnElementIds: string | string[], classNames: string | string[]): void {
Expand Down
2 changes: 1 addition & 1 deletion test/shared/file-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
import { readdirSync, readFileSync as fsReadFileSync } from 'node:fs';
import { join } from 'node:path';

export function readFileSync(relativePathToSourceFile: string, encoding: BufferEncoding = 'utf-8', directoryName = __dirname): string {
export function readFileSync(relativePathToSourceFile: string, encoding: BufferEncoding = 'utf8', directoryName = __dirname): string {
return fsReadFileSync(join(directoryName, relativePathToSourceFile), { encoding });
}

Expand Down

0 comments on commit 6cf48c4

Please sign in to comment.