Skip to content

Commit 1422198

Browse files
committed
chore(lint): forbid reading the display size from the mermaid source
`no-restricted-globals` rejects `screen` under `packages/mermaid/src`, so rendered geometry cannot start depending on the size of the viewer's monitor again.
1 parent 79657e7 commit 1422198

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

eslint.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,26 @@ export default tseslint.config(
232232
'tsdoc/syntax': 'error',
233233
},
234234
},
235+
{
236+
files: ['packages/mermaid/src/**/*.{ts,js}'],
237+
rules: {
238+
'no-restricted-globals': [
239+
'error',
240+
{
241+
globals: [
242+
{
243+
name: 'screen',
244+
message:
245+
'Rendered geometry must not depend on the display size, or the same diagram lays out differently on different machines.',
246+
},
247+
],
248+
// Also rejects `window.screen`, `globalThis.screen` and `self.screen`, which
249+
// the bare-name form lets through.
250+
checkGlobalObject: true,
251+
},
252+
],
253+
},
254+
},
235255
{
236256
files: ['**/*.spec.{ts,js}', 'cypress/**', 'demos/**', '**/docs/**'],
237257
rules: {

packages/mermaid/src/diagrams/c4/c4Renderer.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ describe('C4 grid placement', () => {
8282
afterEach(() => {
8383
// One test below reports a different display size. Drop that override so the rest
8484
// see the environment's own value and the results do not depend on test order.
85+
// eslint-disable-next-line no-restricted-globals -- proving the layout ignores the display needs to set one
8586
delete (globalThis.screen as unknown as { availWidth?: number }).availWidth;
8687
});
8788

@@ -102,6 +103,7 @@ describe('C4 grid placement', () => {
102103
it('places elements identically whatever the display reports', async () => {
103104
const code = `C4Context\n${systems(5)}`;
104105
const asSeenOn = async (availWidth: number, id: string) => {
106+
// eslint-disable-next-line no-restricted-globals -- the point of this test is that the value is ignored
105107
Object.defineProperty(globalThis.screen, 'availWidth', {
106108
value: availWidth,
107109
configurable: true,

0 commit comments

Comments
 (0)