Skip to content

Commit abe22d8

Browse files
committed
Enhance Vue support in ESLint rules and documentation, including new template examples and compliance notes
1 parent 272f800 commit abe22d8

14 files changed

Lines changed: 27 additions & 19 deletions

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
### Changed
2222

2323
- [#107](https://github.com/green-code-initiative/creedengo-javascript/pull/107) Move to creedengo-rules-specifications v3
24+
- [#115](https://github.com/green-code-initiative/creedengo-javascript/pull/115) Add Vue SFC template support to JSX‑based rules (avoid-autoplay, no-empty-image-src-attribute, prefer-lighter-formats-for-image-files, avoid-css-animations, prefer-shorthand-css-notations)
25+
- [#115](https://github.com/green-code-initiative/creedengo-javascript/pull/115) Add Vue RuleTester cases and test-project Vue examples for the updated rules
2426

2527
### Fixed
2628

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ return (
2828
);
2929
```
3030

31-
This rule supports [React](https://react.dev/) (JSX) and Vue SFC templates when using `vue-eslint-parser`.
31+
This rule is build for [React](https://react.dev/) and JSX.
3232

33+
```jsx
3334
<template>
3435
<video autoplay></video> <!-- Non-compliant -->
3536
<video preload="none"></video> <!-- Compliant -->
3637
</template>
37-
38-
Vue support requires `vue-eslint-parser` so the rule can access the template AST.
39-
Dynamic bindings like `:preload="x"` are not validated by this rule.
38+
```
4039

4140
## Resources
4241

eslint-plugin/docs/rules/avoid-css-animations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ Limiting the usage of CSS animations helps in creating a more energy-efficient a
2424
<div style={{ border: "1px solid black" }} /> // Compliant
2525
```
2626

27+
```jsx
2728
<template>
2829
<div style="border: 1px solid black; transition: border 2s ease;"></div> <!-- Non-compliant -->
2930
<div style="border: 1px solid black;"></div> <!-- Compliant -->
3031
</template>
32+
```
3133

3234
Vue support only checks static style attributes; :style bindings are not validated.
3335

eslint-plugin/docs/rules/no-empty-image-src-attribute.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,15 @@ return (
4040
);
4141
```
4242

43-
This rule supports React (JSX) and Vue SFC templates when using vue-eslint-parser.
43+
This rule is build for [React](https://react.dev/) and JSX.
4444

45+
```jsx
4546
<template>
4647
<img src="" /> <!-- Non-compliant -->
4748
<img /> <!-- Non-compliant -->
4849
<img src="./logo.svg" /> <!-- Compliant -->
4950
</template>
50-
51-
Vue support requires vue-eslint-parser; dynamic bindings like :src are not validated by this rule.
52-
51+
```
5352

5453
## Resources
5554

eslint-plugin/docs/rules/prefer-lighter-formats-for-image-files.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ is supported, the image.webp image will be downloaded; otherwise, image.jpg imag
7272
</picture>
7373
```
7474

75+
```jsx
7576
<template>
7677
<img src="./assets/cat.jpg" alt="Unoptimized image of a cat" /> <!-- Non-compliant -->
7778
<img src="./assets/cat.webp" alt="Optimized image of a cat" /> <!-- Compliant -->
7879
</template>
79-
80-
Vue support requires vue-eslint-parser; dynamic bindings like :src are not validated by this rule.
80+
```
8181

8282
Also remember to consider browser compatibility.
8383
Older browsers may not recognize .webp/.avif images and fail to display them.

eslint-plugin/docs/rules/prefer-shorthand-css-notations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ For example, if you only want to set the left margin, you must continue to use `
6464
</div>
6565
```
6666

67+
```jsx
6768
<template>
6869
<div style="margin-top: 1em; margin-right: 0; margin-bottom: 2em; margin-left: 0.5em;"></div> <!-- Non-compliant -->
6970
<div style="margin: 1em 0 2em 0.5em;"></div> <!-- Compliant -->
7071
</template>
72+
```
7173

7274
Vue support only checks static style attributes; :style bindings are not validated.
7375

eslint-plugin/lib/rules/avoid-css-animations.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module.exports = {
6868
);
6969

7070
if (styleAttribute?.value.expression?.properties) {
71+
// To prevent (for example) <div style={{ animate: 'width 2s' }}>
7172
const property = styleAttribute.value.expression.properties.find(
7273
(prop) =>
7374
prop.key != null &&

eslint-plugin/lib/rules/no-empty-image-src-attribute.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ module.exports = {
6969
(attr) => attr.name.name === "src",
7070
);
7171
if (srcValue?.value?.value === "") {
72+
//to prevent <img src='' alt='Empty image'/>
7273
context.report({
7374
node: srcValue,
7475
messageId: "SpecifySrcAttribute",
7576
});
7677
} else if (!srcValue) {
78+
//to prevent <img />
7779
context.report({
7880
node,
7981
messageId: "SpecifySrcAttribute",

test-project/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"license": "GPL-3.0",
1010
"author": "Green Code Initiative",
1111
"scripts": {
12-
"lint": "eslint --ext .js,.ts,.vue src",
13-
"lint:report": "eslint --ext .js,.ts,.vue src -f json -o eslint-report.json",
12+
"lint": "eslint src/.",
13+
"lint:report": "eslint src/. -f json -o eslint-report.json",
1414
"sonar": "sonar"
1515
},
1616
"devDependencies": {
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<template>
2-
<video autoplay></video>
3-
<video preload="auto"></video>
2+
<video autoplay></video> <!-- NonCompliant Avoid autoplay and set preload='none' for video and audio elements. -->
3+
<video preload="auto"></video> <!-- NonCompliant Avoid autoplay and set preload='none' for video and audio elements. -->
4+
<video preload="none"></video> <!-- Compliant -->
45
</template>

0 commit comments

Comments
 (0)