From 05cb29a55498c054692d066a032712fa20b189d0 Mon Sep 17 00:00:00 2001 From: Himesh Jain Date: Mon, 5 Sep 2022 10:01:56 +0530 Subject: [PATCH] `no-unknown-property`: add `download` property support for `a` and `area` fixes jsx-eslint/eslint-plugin-react#3393 --- CHANGELOG.md | 1 + lib/rules/no-unknown-property.js | 2 ++ tests/lib/rules/no-unknown-property.js | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95cfb36652..62419c27a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). This change log adheres to standards from [Keep a CHANGELOG](https://keepachangelog.com). ## Unreleased +* [`no-unknown-property`]: add `download` property support for `a` and `area` ### Fixed * [`no-unknown-property`]: avoid warning on `fbt` nodes entirely ([#3391][] @ljharb) diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js index 6a8c18db41..70cdcf26de 100644 --- a/lib/rules/no-unknown-property.js +++ b/lib/rules/no-unknown-property.js @@ -30,6 +30,8 @@ const ATTRIBUTE_TAGS_MAP = { checked: ['input'], // image is required for SVG support, all other tags are HTML. crossOrigin: ['script', 'img', 'video', 'audio', 'link', 'image'], + // https://html.spec.whatwg.org/multipage/links.html#downloading-resources + download: ['a', 'area'], fill: [ // https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill // Fill color 'altGlyph', diff --git a/tests/lib/rules/no-unknown-property.js b/tests/lib/rules/no-unknown-property.js index bb4105eb0c..9512887edd 100644 --- a/tests/lib/rules/no-unknown-property.js +++ b/tests/lib/rules/no-unknown-property.js @@ -44,7 +44,8 @@ ruleTester.run('no-unknown-property', rule, { // Some HTML/DOM elements with common attributes should work { code: '
;' }, { code: '
;' }, - { code: 'Read more' }, + { code: 'Read more' }, + { code: '' }, { code: 'A cat sleeping on a keyboard' }, { code: '' }, { code: '' }, @@ -466,5 +467,18 @@ ruleTester.run('no-unknown-property', rule, { }, ], }, + { + code: '
', + errors: [ + { + messageId: 'invalidPropOnTag', + data: { + name: 'download', + tagName: 'div', + allowedTags: 'a, area', + }, + }, + ], + }, ]), });