Skip to content

Commit 593f1f1

Browse files
committed
Apply some PR feedbacks
1 parent 7f91907 commit 593f1f1

File tree

5 files changed

+52
-55
lines changed

5 files changed

+52
-55
lines changed

eslint-plugin/README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ Add `@creedengo` to the `plugins` section of your `.eslintrc`, followed by rules
7474
⚠️ Configurations set to warn in.\
7575
✅ Set in the `recommended` configuration.
7676

77-
| Name                               | Description | ⚠️ |
78-
| :------------------------------------------------------------------------------------- | :------------------------------------------------------------------------ | :- |
79-
| [avoid-autoplay](docs/rules/avoid-autoplay.md) | Disallow autoplay and enforce preload='none' for video and audio elements ||
80-
| [avoid-brightness-override](docs/rules/avoid-brightness-override.md) | Should avoid to override brightness ||
81-
| [avoid-css-animations](docs/rules/avoid-css-animations.md) | Avoid usage of CSS animations ||
82-
| [avoid-high-accuracy-geolocation](docs/rules/avoid-high-accuracy-geolocation.md) | Avoid using high accuracy geolocation in web applications ||
83-
| [limit-db-query-results](docs/rules/limit-db-query-results.md) | Should limit the number of returns for a SQL query ||
84-
| [no-empty-image-src-attribute](docs/rules/no-empty-image-src-attribute.md) | Disallow usage of image with empty source attribute ||
85-
| [no-import-all-from-library](docs/rules/no-import-all-from-library.md) | Should not import all from library ||
86-
| [no-multiple-access-dom-element](docs/rules/no-multiple-access-dom-element.md) | Disallow multiple access of same DOM element ||
87-
| [no-multiple-style-changes](docs/rules/no-multiple-style-changes.md) | Disallow multiple style changes at once ||
88-
| [no-torch](docs/rules/no-torch.md) | Should not programmatically enable torch mode ||
89-
| [prefer-collections-with-pagination](docs/rules/prefer-collections-with-pagination.md) | Prefer API collections with pagination ||
90-
| [prefer-shorthand-css-notations](docs/rules/prefer-shorthand-css-notations.md) | Encourage usage of shorthand CSS notations ||
91-
| [provide-print-css](docs/rules/provide-print-css.md) | Enforce providing a print stylesheet ||
77+
| Name | Description | ⚠️ |
78+
| :------------------------------------------------------------------------------------- | :-------------------------------------------------------- | :- |
79+
| [avoid-autoplay](docs/rules/avoid-autoplay.md) | Avoid autoplay for videos and audio content ||
80+
| [avoid-brightness-override](docs/rules/avoid-brightness-override.md) | Should avoid to override brightness ||
81+
| [avoid-css-animations](docs/rules/avoid-css-animations.md) | Avoid usage of CSS animations ||
82+
| [avoid-high-accuracy-geolocation](docs/rules/avoid-high-accuracy-geolocation.md) | Avoid using high accuracy geolocation in web applications ||
83+
| [limit-db-query-results](docs/rules/limit-db-query-results.md) | Should limit the number of returns for a SQL query ||
84+
| [no-empty-image-src-attribute](docs/rules/no-empty-image-src-attribute.md) | Disallow usage of image with empty source attribute ||
85+
| [no-import-all-from-library](docs/rules/no-import-all-from-library.md) | Should not import all from library ||
86+
| [no-multiple-access-dom-element](docs/rules/no-multiple-access-dom-element.md) | Disallow multiple access of same DOM element ||
87+
| [no-multiple-style-changes](docs/rules/no-multiple-style-changes.md) | Disallow multiple style changes at once ||
88+
| [no-torch](docs/rules/no-torch.md) | Should not programmatically enable torch mode ||
89+
| [prefer-collections-with-pagination](docs/rules/prefer-collections-with-pagination.md) | Prefer API collections with pagination ||
90+
| [prefer-shorthand-css-notations](docs/rules/prefer-shorthand-css-notations.md) | Encourage usage of shorthand CSS notations ||
91+
| [provide-print-css](docs/rules/provide-print-css.md) | Enforce providing a print stylesheet ||
9292

9393
<!-- end auto-generated rules list -->
9494

eslint-plugin/docs/rules/avoid-autoplay.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
# Disallow autoplay and enforce preload='none' for video and audio elements (`@creedengo/avoid-autoplay`)
2-
3-
⚠️ This rule _warns_ in the ✅ `recommended` config.
4-
5-
<!-- end auto-generated rule header -->
1+
# Avoid autoplay for videos and audio content (`@creedengo/avoid-autoplay`)
62

73
⚠️ This rule _warns_ in the ✅ `recommended` config.
84

@@ -43,5 +39,6 @@ This rule is build for [React](https://react.dev/) and JSX.
4339
- [Mozilla Web Technology for Developers](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#attr-preload) -
4440
Preload in HTML
4541
- [W3C](https://w3c.github.io/sustyweb/star.html#UX16-1) - Autoplay attribute
42+
- [RGESN](https://www.arcep.fr/mes-demarches-et-services/entreprises/fiches-pratiques/referentiel-general-ecoconception-services-numeriques.html) - Reference Rule 4.1
4643

4744

eslint-plugin/lib/rules/avoid-autoplay.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* ecoCode JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs
3-
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
2+
* creedengo JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs
3+
* Copyright © 2023 Green Code Initiative (https://green-code-initiative.org)
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -23,18 +23,15 @@ module.exports = {
2323
meta: {
2424
type: "suggestion",
2525
docs: {
26-
description:
27-
"Disallow autoplay and enforce preload='none' for video and audio elements",
26+
description: "Avoid autoplay for videos and audio content",
2827
category: "eco-design",
2928
recommended: "warn",
3029
},
3130
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 ",
31+
NoAutoplay: "Avoid autoplay for video and audio elements.",
32+
EnforcePreloadNone: "Set preload='none' for video and audio elements.",
33+
NoAutoplayAndEnforcePreloadNone:
34+
"Avoid autoplay and set preload='none' for video and audio elements.",
3835
},
3936
schema: [],
4037
},
@@ -43,18 +40,18 @@ module.exports = {
4340
JSXOpeningElement(node) {
4441
if (node.name.name === "video" || node.name.name === "audio") {
4542
const autoplayAttr = node.attributes.find(
46-
(attr) => attr.name.name === "autoplay",
43+
(attr) => attr.name?.name.toLowerCase() === "autoplay",
4744
);
4845
const preloadAttr = node.attributes.find(
49-
(attr) => attr.name.name === "preload",
46+
(attr) => attr.name?.name.toLowerCase() === "preload",
5047
);
5148
if (
5249
autoplayAttr &&
5350
(!preloadAttr || preloadAttr.value.value !== "none")
5451
) {
5552
context.report({
5653
node: autoplayAttr || preloadAttr,
57-
messageId: "NoAutoplay_EnforcePreloadNone",
54+
messageId: "NoAutoplayAndEnforcePreloadNone",
5855
});
5956
} else {
6057
if (autoplayAttr) {

eslint-plugin/tests/lib/rules/avoid-autoplay.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* ecoCode JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs
3-
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
2+
* creedengo JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs
3+
* Copyright © 2023 Green Code Initiative (https://green-code-initiative.org)
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -38,47 +38,50 @@ const ruleTester = new RuleTester({
3838
},
3939
},
4040
});
41-
const expectedError1 = {
41+
42+
const noAutoplayError = {
4243
messageId: "NoAutoplay",
4344
type: "JSXAttribute",
4445
};
45-
const expectedError2 = {
46+
const enforcePreloadNoneError = {
4647
messageId: "EnforcePreloadNone",
4748
type: "JSXAttribute",
4849
};
49-
const expectedError3 = {
50-
messageId: "NoAutoplay_EnforcePreloadNone",
50+
const BothError = {
51+
messageId: "NoAutoplayAndEnforcePreloadNone",
5152
type: "JSXAttribute",
5253
};
5354

5455
ruleTester.run("autoplay-audio-video-attribute-not-present", rule, {
5556
valid: [
56-
`
57-
<audio preload="none"></audio>
58-
`,
57+
'<audio preload="none"></audio>',
5958
'<video preload="none"></video>',
59+
'<video preload="none" {...props}></video>',
6060
],
61-
6261
invalid: [
6362
{
64-
code: `
65-
<audio autoplay></audio>
66-
`,
67-
errors: [expectedError3],
63+
code: "<audio autoplay></audio>",
64+
errors: [BothError],
65+
},
66+
{
67+
code: "<audio autoPlay></audio>",
68+
errors: [BothError],
69+
},
70+
{
71+
code: "<audio autoPlay={true}></audio>",
72+
errors: [BothError],
6873
},
6974
{
70-
code: `
71-
<video autoplay preload="auto"></video>
72-
`,
73-
errors: [expectedError3],
75+
code: '<video autoplay preload="auto"></video>',
76+
errors: [BothError],
7477
},
7578
{
7679
code: '<video autoplay preload="none"></video>',
77-
errors: [expectedError1],
80+
errors: [noAutoplayError],
7881
},
7982
{
80-
code: '<audio preload="auto"></audio>',
81-
errors: [expectedError2],
83+
code: '<audio preload="auto"></audio>',
84+
errors: [enforcePreloadNoneError],
8285
},
8386
],
8487
});

sonar-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
5050
<project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>
5151

52-
<version.creedengo-rules-specifications>2.2.0</version.creedengo-rules-specifications>
52+
<version.creedengo-rules-specifications>2.2.1</version.creedengo-rules-specifications>
5353
<version.sonarqube>9.14.0.375</version.sonarqube>
5454
<version.sonar-javascript>9.13.0.20537</version.sonar-javascript>
5555
<version.sonar-packaging>1.23.0.740</version.sonar-packaging>

0 commit comments

Comments
 (0)