Skip to content

Commit c191c83

Browse files
authored
Merge pull request #26 from green-code-initiative/23-add-sonar-rules
Add new rules in Sonar plugin
2 parents 08ad152 + a6228a9 commit c191c83

File tree

10 files changed

+211
-11
lines changed

10 files changed

+211
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- [#14](https://github.com/green-code-initiative/ecoCode-javascript/pull/14) Create SonarQube plugin
13-
- [#21](https://github.com/green-code-initiative/ecoCode-javascript/pull/21) Add rule `@ecocode/avoid-css-animations`
14-
- [#18](https://github.com/green-code-initiative/ecoCode-javascript/pull/18) Add rule `@ecocode/limit-db-query-results`
15-
- [#19](https://github.com/green-code-initiative/ecoCode-javascript/pull/19) Add rule `@ecocode/no-empty-image-src-attribute`
16-
- [#20](https://github.com/green-code-initiative/ecoCode-javascript/pull/20) Add rule `@ecocode/prefer-shorthand-css-notations`
17-
- [#22](https://github.com/green-code-initiative/ecoCode-javascript/pull/22) Add rule `@ecocode/provide-print-css`
13+
- [#21](https://github.com/green-code-initiative/ecoCode-javascript/pull/21) Add rule `@ecocode/avoid-css-animations` (EC29)
14+
- [#18](https://github.com/green-code-initiative/ecoCode-javascript/pull/18) Add rule `@ecocode/limit-db-query-results` (EC24)
15+
- [#19](https://github.com/green-code-initiative/ecoCode-javascript/pull/19) Add rule `@ecocode/no-empty-image-src-attribute` (EC25)
16+
- [#20](https://github.com/green-code-initiative/ecoCode-javascript/pull/20) Add rule `@ecocode/prefer-shorthand-css-notations` (EC26)
17+
- [#22](https://github.com/green-code-initiative/ecoCode-javascript/pull/22) Add rule `@ecocode/provide-print-css` (EC30)
1818
- [#25](https://github.com/green-code-initiative/ecoCode-javascript/pull/25) Add license headers
1919
- [ecoCode#207](https://github.com/green-code-initiative/ecoCode/issues/207) Add release tag analyzis on SonarCloud
2020

RULES.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,14 @@
1313
| EC8 | @ecocode/avoid-high-accuracy-geolocation | Avoid using high accuracy geolocation | |
1414
| EC11 | @ecocode/no-multiple-access-dom-element | Call a DOM element multiple times without caching | |
1515
| EC12 | @ecocode/no-multiple-style-changes | Modify several CSS properties all at once | |
16+
| EC25 | @ecocode/no-empty-image-src-attribute | Do not use an image with empty source attribute | |
17+
| EC26 | @ecocode/prefer-shorthand-css-notations | Prefer shorthand CSS notations | |
18+
| EC29 | @ecocode/avoid-css-animations | Avoid usage of CSS animations | |
19+
| EC30 | @ecocode/provide-print-css | Provide a print stylesheet | |
1620

1721
### Back-end
1822

19-
| # | ESLint key | Rule Name | Observation |
20-
|------|---------------------------------------------|----------------------------------------|-------------------------|
21-
| EC13 | @ecocode/prefer-collections-with-pagination | Prefer API collections with pagination | for NestJS (TypeScript) |
23+
| # | ESLint key | Rule Name | Observation |
24+
|------|---------------------------------------------|---------------------------------------------|-------------------------|
25+
| EC13 | @ecocode/prefer-collections-with-pagination | Prefer API collections with pagination | for NestJS (TypeScript) |
26+
| EC24 | @ecocode/limit-db-query-results | Limit the number of returns for a SQL query | |

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-
<ecocode-rules-specifications.version>0.0.1</ecocode-rules-specifications.version>
52+
<ecocode-rules-specifications.version>0.0.6</ecocode-rules-specifications.version>
5353
<sonarqube.version>9.4.0.54424</sonarqube.version>
5454
<sonar-javascript.version>9.13.0.20537</sonar-javascript.version>
5555
<sonar-packaging.version>1.21.0.505</sonar-packaging.version>

sonar-plugin/src/main/java/io/ecocode/javascript/CheckList.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ private CheckList() {
3434

3535
public static List<Class<? extends JavaScriptCheck>> getAllChecks() {
3636
return Arrays.asList(
37+
AvoidCSSAnimations.class,
3738
AvoidHighAccuracyGeolocation.class,
39+
LimitDbQueryResult.class,
40+
NoEmptyImageSrcAttribute.class,
3841
NoImportAllFromLibrary.class,
3942
NoMultipleAccessDomElement.class,
4043
NoMultipleStyleChanges.class,
41-
PreferCollectionsWithPagination.class
44+
PreferCollectionsWithPagination.class,
45+
PreferShorthandCSSNotations.class,
46+
ProvidePrintCSS.class
4247
);
4348
}
4449

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
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)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package io.ecocode.javascript.checks;
19+
20+
import org.sonar.check.Rule;
21+
import org.sonar.plugins.javascript.api.EslintBasedCheck;
22+
import org.sonar.plugins.javascript.api.JavaScriptRule;
23+
import org.sonar.plugins.javascript.api.TypeScriptRule;
24+
25+
@JavaScriptRule
26+
@TypeScriptRule
27+
@Rule(key = AvoidCSSAnimations.RULE_KEY)
28+
public class AvoidCSSAnimations implements EslintBasedCheck {
29+
30+
public static final String RULE_KEY = "EC29";
31+
32+
@Override
33+
public String eslintKey() {
34+
return "@ecocode/avoid-css-animations";
35+
}
36+
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
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)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package io.ecocode.javascript.checks;
19+
20+
import org.sonar.check.Rule;
21+
import org.sonar.plugins.javascript.api.EslintBasedCheck;
22+
import org.sonar.plugins.javascript.api.JavaScriptRule;
23+
import org.sonar.plugins.javascript.api.TypeScriptRule;
24+
25+
@JavaScriptRule
26+
@TypeScriptRule
27+
@Rule(key = LimitDbQueryResult.RULE_KEY)
28+
public class LimitDbQueryResult implements EslintBasedCheck {
29+
30+
public static final String RULE_KEY = "EC24";
31+
32+
@Override
33+
public String eslintKey() {
34+
return "@ecocode/limit-db-query-results";
35+
}
36+
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
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)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package io.ecocode.javascript.checks;
19+
20+
import org.sonar.check.Rule;
21+
import org.sonar.plugins.javascript.api.EslintBasedCheck;
22+
import org.sonar.plugins.javascript.api.JavaScriptRule;
23+
import org.sonar.plugins.javascript.api.TypeScriptRule;
24+
25+
@JavaScriptRule
26+
@TypeScriptRule
27+
@Rule(key = NoEmptyImageSrcAttribute.RULE_KEY)
28+
public class NoEmptyImageSrcAttribute implements EslintBasedCheck {
29+
30+
public static final String RULE_KEY = "EC25";
31+
32+
@Override
33+
public String eslintKey() {
34+
return "@ecocode/no-empty-image-src-attribute";
35+
}
36+
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
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)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package io.ecocode.javascript.checks;
19+
20+
import org.sonar.check.Rule;
21+
import org.sonar.plugins.javascript.api.EslintBasedCheck;
22+
import org.sonar.plugins.javascript.api.JavaScriptRule;
23+
import org.sonar.plugins.javascript.api.TypeScriptRule;
24+
25+
@JavaScriptRule
26+
@TypeScriptRule
27+
@Rule(key = PreferShorthandCSSNotations.RULE_KEY)
28+
public class PreferShorthandCSSNotations implements EslintBasedCheck {
29+
30+
public static final String RULE_KEY = "EC26";
31+
32+
@Override
33+
public String eslintKey() {
34+
return "@ecocode/prefer-shorthand-css-notations";
35+
}
36+
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
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)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package io.ecocode.javascript.checks;
19+
20+
import org.sonar.check.Rule;
21+
import org.sonar.plugins.javascript.api.EslintBasedCheck;
22+
import org.sonar.plugins.javascript.api.JavaScriptRule;
23+
import org.sonar.plugins.javascript.api.TypeScriptRule;
24+
25+
@JavaScriptRule
26+
@TypeScriptRule
27+
@Rule(key = ProvidePrintCSS.RULE_KEY)
28+
public class ProvidePrintCSS implements EslintBasedCheck {
29+
30+
public static final String RULE_KEY = "EC30";
31+
32+
@Override
33+
public String eslintKey() {
34+
return "@ecocode/provide-print-css";
35+
}
36+
37+
}

sonar-plugin/src/main/resources/io/ecocode/profiles/ecocode_javascript_profile.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"EC8",
55
"EC9",
66
"EC11",
7-
"EC12"
7+
"EC12",
8+
"EC24",
9+
"EC25",
10+
"EC26",
11+
"EC29",
12+
"EC30"
813
]
914
}

0 commit comments

Comments
 (0)