Skip to content

Commit ac4c704

Browse files
mondejaÁlvaro Mondéjar
authored andcommitted
fix: throw TypeError on fixtures mutation (#147)
1 parent 894b50d commit ac4c704

File tree

5 files changed

+770
-853
lines changed

5 files changed

+770
-853
lines changed

README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ Fixtures are used to inject data for each linted file. It should be a function
318318
that takes the same parameters as a custom rule, but it returns an object with
319319
the data to inject. The data can be accessed in the custom rules.
320320

321-
Fixture values are mutable as the fixtures object is passed as reference to
322-
not create unnecessary copies of the data, so rules should not mutate them.
321+
Fixture values are inmutable, a `TypeError` will be thrown if you try to modify
322+
them in a custom rule.
323323

324324
#### Example
325325

@@ -343,15 +343,6 @@ const config = {
343343
/** @type {Info} */ {fixtures: {iconPath, segments, bbox}},
344344
) => {
345345
reporter.name = 'my-custom-rule';
346-
347-
reporter.warn(`Segments: ${segments}`);
348-
349-
// WARNING: don't do this
350-
// fixtures.myFixture = 'new value';
351-
//
352-
// Instead, create a deep clone
353-
// const myFixture = globalThis.structuredClone(fixtures.myFixture);
354-
// myFixture.newProperty = 'new value';
355346
}
356347
]
357348
},

0 commit comments

Comments
 (0)