mozilla / eslint-plugin-no-unsanitized

Custom ESLint rule to disallows unsafe innerHTML, outerHTML, insertAdjacentHTML and alike
Mozilla Public License 2.0
231 stars 38 forks source link

Fix flat recommended #251

Closed alecmev closed 1 month ago

alecmev commented 2 months ago

The usage example in README is incorrect. Could fix README, but this approach is easier to deal with (e.g., when you want to just add files: [...] to it). This is a breaking change, unfortunately.

mozfreddyb commented 1 month ago

Can you help me understand what this is doing?

alecmev commented 1 month ago

Sure! README instructs to use the config like so:

https://github.com/mozilla/eslint-plugin-no-unsanitized/blob/73fd741e82876931fa6eb910eeb3793942019d3a/README.md#L61-L65

But that actually won't work, gotta spread it:

export default config = [...nounsanitized.configs.recommended];

But I propose that instead recommended is turned into an object, rather than an array with a single object in it. That makes it easier to "patch" the config, e.g.:

export default config = [{ ...nounsanitized.configs.recommended, files: ['**/foo/*.js'] }];

With the array you instead need to do this:

export default config = [...nounsanitized.configs.recommended.map((x) => ({ ...x, files: ['**/foo/*.js'] }))];
mozfreddyb commented 1 month ago

OK, thanks for explaning. I'd like @Standard8 to take a second look. Might just be there's a reason why this is written the way it is and I don't want to break anything accidentally. :)

alecmev commented 1 month ago

Thanks! 😉