ESLint plugin to disallow unsafe coding practices like direct assignments to innerHTML or calls to insertAdjacentHTML without sanitization. Developed by Mozilla, it supports ESLint 9 and 10 (v4.x), and the Sanitizer API. Key differentiators: focuses on security, requires tagged template literals for escaping, and has two rules (method and property).
npm install eslint-plugin-no-unsanitizedVerified import paths — ran on the pinned version, not inferred.
Shows how to enable both rules using flat config (ESLint >=9).
Migrate to flat config using `import nounsanitized from 'eslint-plugin-no-unsanitized'` and spread `nounsanitized.configs.recommended`.
Upgrade ESLint to version 9 or 10.
Use `import nounsanitized from 'eslint-plugin-no-unsanitized'` and reference rules as 'nounsanitized/...'.
Use `escapeHTML` tagged template syntax: `escapeHTML`userInput` or `Sanitizer.escapeHTML`userInput``.
To allow `setHTMLUnsafe`, set `'nounsanitized/method': ['error', { allowSafe: false }]` or similar custom config.Ensure correct import: `import nounsanitized from 'eslint-plugin-no-unsanitized'` and add to plugins object.
Use prefix 'nounsanitized/' instead: `'nounsanitized/method': 'error'`.
Install with 'npm install --save-dev eslint-plugin-no-unsanitized' and use ESM import syntax.
Migrate to flat config: import plugin and spread its configs.recommended.