diff --git a/CHANGELOG.md b/CHANGELOG.md index 366aab864..14ece5c76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- [#333](https://github.com/green-code-initiative/creedengo-rules-specifications/pull/333) Add JS variant of rule GCI777 - Idleness: Keep Screen On (addFlags) + ### Changed - Correction of various typos in rules documentations diff --git a/RULES.md b/RULES.md index 5bf439321..194f398e8 100644 --- a/RULES.md +++ b/RULES.md @@ -75,7 +75,8 @@ Some are applicable for different technologies. | GCI404 | Avoid list comprehension in iterations | Use generator comprehension instead of list comprehension in for loop declaration | | 🚫 | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | 🚫 | | GCI522 | Sobriety: Brightness Override | To avoid draining the battery, iOS and Android devices adapt the brightness of the screen depending on the environment light. | | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | | GCI523 | Sobriety: Thrifty Geolocation (minTime) | High-precision geolocation typically requires more power from the device's GPS hardware. | | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | -| GCI530 | Sobriety: Torch Free | Turning on the torch mode programmatically must absolutely be avoided because the flashlight is one of the most energy-intensive component. | | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| GCI530 | Sobriety: Torch Free | Turning on the torch mode programmatically must absolutely be avoided because the flashlight is one of the most energy-intensive component. | | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | 🚫 | 🚫 | +| GCI777 | Avoid using resource hungry libraries | We must avoid using resource hungry libraries to not waste unecessary energy. | | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | 🚫 | 🚫 | | | Use official social media sharing buttons | These JavaScript plugins are very resource-intensive: to work, they require a large number of requests and download heavy files. It is better to prefer direct links. | [cnumr best practices (3rd edition) BP_019](https://github.com/cnumr/best-practices/blob/main/chapters/BP_019_fr.md) | 🚫 | 🚫 | 🚀 | 🚫 | 🚫 | 🚫 | 🚀 | | | Non-grouped similar CSS declarations | When multiple Document Object Model (DOM) elements have common CSS properties, declare them together in the same style sheet. This method reduces the weight of CSS. | [cnumr best practices (3rd edition) BP_025](https://github.com/cnumr/best-practices/blob/main/chapters/BP_025_fr.md) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | 🚫 | 🚫 | | | Non-standard fonts used | Prefer standard fonts, as they are already present on the user's computer, so they do not need to download them. This saves bandwidth, while speeding up the display of the site. | [cnumr best practices (3rd edition) BP_029](https://github.com/cnumr/best-practices/blob/main/chapters/BP_029_fr.md) | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | diff --git a/src/main/rules/GCI66/javascript/GCI3.asciidoc b/src/main/rules/GCI66/javascript/GCI3.asciidoc new file mode 100644 index 000000000..80736c0e0 --- /dev/null +++ b/src/main/rules/GCI66/javascript/GCI3.asciidoc @@ -0,0 +1,13 @@ +== Why is this an issue? + +Using single quotes for string literals that do **not** require interpolation is more efficient. Double quotes (and backticks) can trigger additional parsing logic to check for variable interpolation, even if none is present. + +[source,js,data-diff-id="2",data-diff-type="noncompliant"] +---- +const message = "Hello world"; +---- + +[source,js,data-diff-id="2",data-diff-type="compliant"] +---- +const message = 'Hello world'; +---- \ No newline at end of file diff --git a/src/main/rules/GCI777/GCI777.json b/src/main/rules/GCI777/GCI777.json new file mode 100644 index 000000000..bdae0d3b2 --- /dev/null +++ b/src/main/rules/GCI777/GCI777.json @@ -0,0 +1,16 @@ +{ + "title": "Avoid using resource hungry libs", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "1h" + }, + "tags": [ + "bad-practice", + "eco-design", + "performance", + "creedengo" + ], + "defaultSeverity": "Minor" +} diff --git a/src/main/rules/GCI777/javascript/GCI777.asciidoc b/src/main/rules/GCI777/javascript/GCI777.asciidoc new file mode 100644 index 000000000..d40cd25dc --- /dev/null +++ b/src/main/rules/GCI777/javascript/GCI777.asciidoc @@ -0,0 +1,21 @@ +== Why is this an issue? + +Avoid imports of known resource-hungry or deprecated libraries and suggest lighter alternatives. + +This rule flags any import, require or dynamic import of libraries listed in the project's deprecation dictionary (`moment`, `iconsax`, etc.), because these libraries +1. Inflate your bundle size +2. Slow parsing & compilation +3. Often lack tree-shaking support +4. May be unmaintained + +[source,js,data-diff-id="2",data-diff-type="noncompliant"] +---- +import moment from "moment"; +const age = moment().diff(birthday, "years"); +---- + +[source,js,data-diff-id="2",data-diff-type="compliant"] +---- +import differenceInYears from "date-fns/differenceInYears"; +const age = differenceInYears(new Date(), birthday); +---- \ No newline at end of file