|
18 | 18 |
|
19 | 19 | "use strict"; |
20 | 20 |
|
21 | | -/** @type {import('eslint').Rule.RuleModule} */ |
| 21 | +/** @type {import("eslint").Rule.RuleModule} */ |
22 | 22 | module.exports = { |
23 | | - meta: { |
24 | | - type: "suggestion", |
25 | | - docs: { |
26 | | - description: "Disallow autoplay and enforce preload='none' for video and audio elements", |
27 | | - category: "eco-design", |
28 | | - recommended: "warn", |
29 | | - }, |
30 | | - messages: { |
31 | | - NoAutoplay: "Avoid using autoplay attribute for <video> and <audio> elements. Reference to Rule RGESN 4.1 : https://www.arcep.fr/mes-demarches-et-services/entreprises/fiches-pratiques/referentiel-general-ecoconception-services-numeriques.html", |
32 | | - EnforcePreloadNone: "Set preload='none' for <video> and <audio> elements. Reference to Rule RGESN 4.1 : https://www.arcep.fr/mes-demarches-et-services/entreprises/fiches-pratiques/referentiel-general-ecoconception-services-numeriques.html", |
33 | | - NoAutoplay_EnforcePreloadNone: "Avoid using autoplay attribute and set preload='none' for <video> and <audio> elements. Reference to Rule RGESN 4.1 : https://www.arcep.fr/mes-demarches-et-services/entreprises/fiches-pratiques/referentiel-general-ecoconception-services-numeriques.html ", |
34 | | - }, |
35 | | - schema: [], |
| 23 | + meta: { |
| 24 | + type: "suggestion", |
| 25 | + docs: { |
| 26 | + description: |
| 27 | + "Disallow autoplay and enforce preload='none' for video and audio elements", |
| 28 | + category: "eco-design", |
| 29 | + recommended: "warn", |
36 | 30 | }, |
37 | | - create(context) { |
38 | | - return { |
39 | | - JSXOpeningElement(node) { |
40 | | - if (node.name.name === "video" || node.name.name === "audio") { |
41 | | - const autoplayAttr = node.attributes.find( |
42 | | - (attr) => attr.name.name === "autoplay", |
43 | | - ); |
44 | | - const preloadAttr = node.attributes.find( |
45 | | - (attr) => attr.name.name === "preload", |
46 | | - ); |
47 | | - if(autoplayAttr && (!preloadAttr || preloadAttr.value.value !== "none")) { |
48 | | - context.report({ |
49 | | - node: autoplayAttr||preloadAttr, |
50 | | - messageId: "NoAutoplay_EnforcePreloadNone", |
51 | | - }); |
52 | | - } |
53 | | - else { |
54 | | - if (autoplayAttr) { |
55 | | - context.report({ |
56 | | - node: autoplayAttr, |
57 | | - messageId: "NoAutoplay", |
58 | | - |
59 | | - }); |
60 | | - } |
61 | | - |
62 | | - if (!preloadAttr || preloadAttr.value.value !== "none") { |
63 | | - context.report({ |
64 | | - node: preloadAttr || node, |
65 | | - messageId: "EnforcePreloadNone", |
66 | | - }); |
67 | | - } |
68 | | - } |
69 | | - } |
70 | | - }, |
71 | | - }; |
| 31 | + messages: { |
| 32 | + NoAutoplay: |
| 33 | + "Avoid using autoplay attribute for <video> and <audio> elements. Reference to Rule RGESN 4.1 : https://www.arcep.fr/mes-demarches-et-services/entreprises/fiches-pratiques/referentiel-general-ecoconception-services-numeriques.html", |
| 34 | + EnforcePreloadNone: |
| 35 | + "Set preload='none' for <video> and <audio> elements. Reference to Rule RGESN 4.1 : https://www.arcep.fr/mes-demarches-et-services/entreprises/fiches-pratiques/referentiel-general-ecoconception-services-numeriques.html", |
| 36 | + NoAutoplay_EnforcePreloadNone: |
| 37 | + "Avoid using autoplay attribute and set preload='none' for <video> and <audio> elements. Reference to Rule RGESN 4.1 : https://www.arcep.fr/mes-demarches-et-services/entreprises/fiches-pratiques/referentiel-general-ecoconception-services-numeriques.html ", |
72 | 38 | }, |
| 39 | + schema: [], |
| 40 | + }, |
| 41 | + create(context) { |
| 42 | + return { |
| 43 | + JSXOpeningElement(node) { |
| 44 | + if (node.name.name === "video" || node.name.name === "audio") { |
| 45 | + const autoplayAttr = node.attributes.find( |
| 46 | + (attr) => attr.name.name === "autoplay", |
| 47 | + ); |
| 48 | + const preloadAttr = node.attributes.find( |
| 49 | + (attr) => attr.name.name === "preload", |
| 50 | + ); |
| 51 | + if ( |
| 52 | + autoplayAttr && |
| 53 | + (!preloadAttr || preloadAttr.value.value !== "none") |
| 54 | + ) { |
| 55 | + context.report({ |
| 56 | + node: autoplayAttr || preloadAttr, |
| 57 | + messageId: "NoAutoplay_EnforcePreloadNone", |
| 58 | + }); |
| 59 | + } else { |
| 60 | + if (autoplayAttr) { |
| 61 | + context.report({ |
| 62 | + node: autoplayAttr, |
| 63 | + messageId: "NoAutoplay", |
| 64 | + }); |
| 65 | + } |
| 66 | + |
| 67 | + if (!preloadAttr || preloadAttr.value.value !== "none") { |
| 68 | + context.report({ |
| 69 | + node: preloadAttr || node, |
| 70 | + messageId: "EnforcePreloadNone", |
| 71 | + }); |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | + }, |
| 76 | + }; |
| 77 | + }, |
73 | 78 | }; |
0 commit comments