Skip to content

Commit

Permalink
Merge pull request #26 from green-code-initiative/23-add-sonar-rules
Browse files Browse the repository at this point in the history
Add new rules in Sonar plugin
  • Loading branch information
utarwyn authored Oct 29, 2023
2 parents 08ad152 + a6228a9 commit c191c83
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 11 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

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

Expand Down
11 changes: 8 additions & 3 deletions RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@
| EC8 | @ecocode/avoid-high-accuracy-geolocation | Avoid using high accuracy geolocation | |
| EC11 | @ecocode/no-multiple-access-dom-element | Call a DOM element multiple times without caching | |
| EC12 | @ecocode/no-multiple-style-changes | Modify several CSS properties all at once | |
| EC25 | @ecocode/no-empty-image-src-attribute | Do not use an image with empty source attribute | |
| EC26 | @ecocode/prefer-shorthand-css-notations | Prefer shorthand CSS notations | |
| EC29 | @ecocode/avoid-css-animations | Avoid usage of CSS animations | |
| EC30 | @ecocode/provide-print-css | Provide a print stylesheet | |

### Back-end

| # | ESLint key | Rule Name | Observation |
|------|---------------------------------------------|----------------------------------------|-------------------------|
| EC13 | @ecocode/prefer-collections-with-pagination | Prefer API collections with pagination | for NestJS (TypeScript) |
| # | ESLint key | Rule Name | Observation |
|------|---------------------------------------------|---------------------------------------------|-------------------------|
| EC13 | @ecocode/prefer-collections-with-pagination | Prefer API collections with pagination | for NestJS (TypeScript) |
| EC24 | @ecocode/limit-db-query-results | Limit the number of returns for a SQL query | |
2 changes: 1 addition & 1 deletion sonar-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<project.build.sourceEncoding>${encoding}</project.build.sourceEncoding>
<project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding>

<ecocode-rules-specifications.version>0.0.1</ecocode-rules-specifications.version>
<ecocode-rules-specifications.version>0.0.6</ecocode-rules-specifications.version>
<sonarqube.version>9.4.0.54424</sonarqube.version>
<sonar-javascript.version>9.13.0.20537</sonar-javascript.version>
<sonar-packaging.version>1.21.0.505</sonar-packaging.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ private CheckList() {

public static List<Class<? extends JavaScriptCheck>> getAllChecks() {
return Arrays.asList(
AvoidCSSAnimations.class,
AvoidHighAccuracyGeolocation.class,
LimitDbQueryResult.class,
NoEmptyImageSrcAttribute.class,
NoImportAllFromLibrary.class,
NoMultipleAccessDomElement.class,
NoMultipleStyleChanges.class,
PreferCollectionsWithPagination.class
PreferCollectionsWithPagination.class,
PreferShorthandCSSNotations.class,
ProvidePrintCSS.class
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* ecoCode JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.ecocode.javascript.checks;

import org.sonar.check.Rule;
import org.sonar.plugins.javascript.api.EslintBasedCheck;
import org.sonar.plugins.javascript.api.JavaScriptRule;
import org.sonar.plugins.javascript.api.TypeScriptRule;

@JavaScriptRule
@TypeScriptRule
@Rule(key = AvoidCSSAnimations.RULE_KEY)
public class AvoidCSSAnimations implements EslintBasedCheck {

public static final String RULE_KEY = "EC29";

@Override
public String eslintKey() {
return "@ecocode/avoid-css-animations";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* ecoCode JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.ecocode.javascript.checks;

import org.sonar.check.Rule;
import org.sonar.plugins.javascript.api.EslintBasedCheck;
import org.sonar.plugins.javascript.api.JavaScriptRule;
import org.sonar.plugins.javascript.api.TypeScriptRule;

@JavaScriptRule
@TypeScriptRule
@Rule(key = LimitDbQueryResult.RULE_KEY)
public class LimitDbQueryResult implements EslintBasedCheck {

public static final String RULE_KEY = "EC24";

@Override
public String eslintKey() {
return "@ecocode/limit-db-query-results";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* ecoCode JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.ecocode.javascript.checks;

import org.sonar.check.Rule;
import org.sonar.plugins.javascript.api.EslintBasedCheck;
import org.sonar.plugins.javascript.api.JavaScriptRule;
import org.sonar.plugins.javascript.api.TypeScriptRule;

@JavaScriptRule
@TypeScriptRule
@Rule(key = NoEmptyImageSrcAttribute.RULE_KEY)
public class NoEmptyImageSrcAttribute implements EslintBasedCheck {

public static final String RULE_KEY = "EC25";

@Override
public String eslintKey() {
return "@ecocode/no-empty-image-src-attribute";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* ecoCode JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.ecocode.javascript.checks;

import org.sonar.check.Rule;
import org.sonar.plugins.javascript.api.EslintBasedCheck;
import org.sonar.plugins.javascript.api.JavaScriptRule;
import org.sonar.plugins.javascript.api.TypeScriptRule;

@JavaScriptRule
@TypeScriptRule
@Rule(key = PreferShorthandCSSNotations.RULE_KEY)
public class PreferShorthandCSSNotations implements EslintBasedCheck {

public static final String RULE_KEY = "EC26";

@Override
public String eslintKey() {
return "@ecocode/prefer-shorthand-css-notations";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* ecoCode JavaScript plugin - Provides rules to reduce the environmental footprint of your JavaScript programs
* Copyright © 2023 Green Code Initiative (https://www.ecocode.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.ecocode.javascript.checks;

import org.sonar.check.Rule;
import org.sonar.plugins.javascript.api.EslintBasedCheck;
import org.sonar.plugins.javascript.api.JavaScriptRule;
import org.sonar.plugins.javascript.api.TypeScriptRule;

@JavaScriptRule
@TypeScriptRule
@Rule(key = ProvidePrintCSS.RULE_KEY)
public class ProvidePrintCSS implements EslintBasedCheck {

public static final String RULE_KEY = "EC30";

@Override
public String eslintKey() {
return "@ecocode/provide-print-css";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
"EC8",
"EC9",
"EC11",
"EC12"
"EC12",
"EC24",
"EC25",
"EC26",
"EC29",
"EC30"
]
}

0 comments on commit c191c83

Please sign in to comment.