Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update the ID and the URL to your PR and the text


### Changed

- Correction of various typos in rules documentations
Expand Down
3 changes: 2 additions & 1 deletion RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 |
Expand Down
13 changes: 13 additions & 0 deletions src/main/rules/GCI66/javascript/GCI3.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
== Why is this an issue?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file should not be commited


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';
----
16 changes: 16 additions & 0 deletions src/main/rules/GCI777/GCI777.json
Original file line number Diff line number Diff line change
@@ -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"
}
21 changes: 21 additions & 0 deletions src/main/rules/GCI777/javascript/GCI777.asciidoc
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this rule depends on specifics libraries, the rule should list the dependencies that are concerned or add an external link to them

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);
----