diff --git a/RULES.md b/RULES.md index 05310c4b0..7a5d5fa45 100644 --- a/RULES.md +++ b/RULES.md @@ -66,7 +66,7 @@ Some are applicable for different technologies. | EC86 | GC.Collect should not be called | In most cases, the cost of calling GC.Collect far outweighs the benefits | | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | βœ… | 🚫 | | EC87 | Use collection indexer | Collection indexers should be used instead of Linq, when available | | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | βœ… | 🚫 | | EC88 | Dispose resource asynchronously | Resources that implement `IAsyncDisposable` should be disposed asynchronously | | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | βœ… | 🚫 | -| EC203 | Detect unoptimized file formats | When it is possible, to use svg format image over other image format | | πŸš€ | πŸš€ | πŸš€ | βœ… | πŸš€ | πŸš€ | 🚫 | +| EC203 | Detect unoptimized file formats | When it is possible, to use svg format image over other image format | | βœ… | πŸš€ | πŸš€ | βœ… | πŸš€ | πŸš€ | 🚫 | | EC404 | Avoid list comprehension in iterations | Use generator comprehension instead of list comprehension in for loop declaration | | 🚫 | 🚫 | 🚫 | βœ… | 🚫 | 🚫 | 🚫 | | | 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) | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | 🚫 | 🚫 | diff --git a/ecocode-rules-specifications/src/main/rules/EC203/java/EC203.asciidoc b/ecocode-rules-specifications/src/main/rules/EC203/java/EC203.asciidoc new file mode 100644 index 000000000..85d38acb6 --- /dev/null +++ b/ecocode-rules-specifications/src/main/rules/EC203/java/EC203.asciidoc @@ -0,0 +1,78 @@ +If possible, the utilisation of svg image format (or `` html tag) is recommended over other image format. + +Because SVGs are generally smaller than other image format, they’re less taxing on your server despite needing to render on load. + +When to use SVG : + +- Your image is used for decorative website graphics, logos, icons, graphs and diagrams, and other simple images. +- You image require animation. +- You image need to be responsive and scale without lack of quality. + +Some advantages of using SVG: + +- SVGs are scalable and will render pixel-perfect at any resolution whereas JPEGs, PNGs and GIFs will not. +- SVGs are vector images and therefore are usually much smaller in file-size than bitmap-based images. +- SVGs can be embedded into the HTML which means they can be cached, edited directly using CSS and indexed for greater accessibility. +- SVGs can be animated directly or by using CSS or JavaScript making it easy for web designers to add interactivity to a site. + +## Noncompliant Code Example + +``` +img_jpg = "image.jpg" +``` + +## Compliant Solution + +``` +img_svg = "image.svg" +``` + +## Noncompliant Code Example + +``` +public void foo() { + // ... + image_format = testImage("image.jpg") + // ... +} +``` + +## Compliant Solution + +``` +public void foo() { + // ... + image_format = testImage("image.svg") + // ... +} +``` + +## Noncompliant Code Example + +``` +public void foo() { + // ... + return '' + // ... +} +``` + +## Compliant Solution + +``` +public void foo() { + // ... + return '' + // ... +} +``` + +Or + +``` + public void foo() { + // ... + return ('') + // ... +} +``` diff --git a/ecocode-rules-specifications/src/main/rules/EC203/python/EC203.asciidoc b/ecocode-rules-specifications/src/main/rules/EC203/python/EC203.asciidoc index 85d38acb6..fd2a42084 100644 --- a/ecocode-rules-specifications/src/main/rules/EC203/python/EC203.asciidoc +++ b/ecocode-rules-specifications/src/main/rules/EC203/python/EC203.asciidoc @@ -30,49 +30,48 @@ img_svg = "image.svg" ## Noncompliant Code Example ``` -public void foo() { - // ... +def foo() : + # ... image_format = testImage("image.jpg") - // ... -} + # ... ``` ## Compliant Solution ``` -public void foo() { - // ... +def foo() : + # ... image_format = testImage("image.svg") - // ... + # ... } ``` ## Noncompliant Code Example ``` -public void foo() { - // ... +def foo() : + # ... return '' - // ... + # ... } ``` ## Compliant Solution ``` -public void foo() { - // ... +def foo() : + # ... return '' - // ... + # ... } ``` Or ``` - public void foo() { - // ... +def foo() : + # ... return ('') - // ... + # ... } ```