7 | To support publishers in meeting their duties under the EU User Consent Policy, Google offers a Consent SDK.
8 | Hence, importing classes from com.google.android.ads.consent.* or com.google.android.ump.*
9 | since Android API 21 is considered as a good practice.
10 |
Displaying dark colors is particularly beneficial for mobile devices with (AM)OLED screens.
3 | Consequently, custom resources like bright colors values and bitmap images with too high luminance should be avoided.
A negative effect on the device s battery is when an app is paired with a companion device (over Bluetooth, BLE, or Wi-Fi)
3 | and that it has been excluded from battery optimizations (run in the background) using the declaration
4 | Manifest.permission.REQUEST_COMPANION_RUN_IN_BACKGROUND.
To avoid draining the battery, an Android device that is left idle quickly falls asleep.
3 | Hence, keeping the screen on should be avoided, unless it is absolutely necessary. If so, developers typically
4 | use the FLAG_KEEP_SCREEN_ON in their activity. Another way to implement this is in their application's
5 | layout XML file, by using the android:keepScreenOn attribute.
10 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/main/resources/templates/codenarc-rule-index.md.template:
--------------------------------------------------------------------------------
1 | ---
2 | layout: default
3 | title: CodeNarc - Rule Index
4 | ---
5 |
6 | # Rule Index
7 |
8 | **CodeNarc** includes ${numberOfRules} rules.
9 | <% ruleSets.each { name, rules ->\
10 | def ruleSetLink = "./codenarc-rules-${name}.html"
11 | def capitalizedName = name.capitalize() %>
12 | ## [$capitalizedName]($ruleSetLink)
13 | <% rules.each { rule -> def extraInfo = ruleExtraInformation[rule.name] ? " (${ruleExtraInformation[rule.name]})" : '' %>\
14 | * [${rule.name}](./codenarc-rules-${name}.html#${rule.name.toLowerCase()}-rule) ${extraInfo}
15 | <% } } %>
16 |
--------------------------------------------------------------------------------
/android-plugin/src/main/resources/io/ecocode/rules/java/README.md:
--------------------------------------------------------------------------------
1 | # These files are GENERATED
2 |
3 | The files from this folder are **generated** directly from our rules descriptions project.
4 |
5 | Consequently, do not attempt to manually modify files here, nor submit Pull Request (PR) modifying description
6 | or rule metatada. Any PR will be systematically rejected.
7 |
8 | If you want to:
9 |
10 | * update descriptions;
11 | * extends their content;
12 | * fix misleading content;
13 | * adjust rule metadata;
14 | * etc.
15 |
16 | Then, please reach us though our mail , prior to submitting any code change.
17 |
18 | Thanks,
19 | *The ecoCode Team*
20 |
--------------------------------------------------------------------------------
/android-plugin/src/main/resources/io/ecocode/rules/xml/README.md:
--------------------------------------------------------------------------------
1 | # These files are GENERATED
2 |
3 | The files from this folder are **generated** directly from our rules descriptions project.
4 |
5 | Consequently, do not attempt to manually modify files here, nor submit Pull Request (PR) modifying description
6 | or rule metatada. Any PR will be systematically rejected.
7 |
8 | If you want to:
9 |
10 | * update descriptions;
11 | * extends their content;
12 | * fix misleading content;
13 | * adjust rule metadata;
14 | * etc.
15 |
16 | Then, please reach us though our mail , prior to submitting any code change.
17 |
18 | Thanks,
19 | *The ecoCode Team*
20 |
--------------------------------------------------------------------------------
/CITATION.cff:
--------------------------------------------------------------------------------
1 | cff-version: 1.2.0
2 | message: "If you use this software, please cite it as below."
3 | preferred-citation:
4 | type: conference-paper
5 | conference:
6 | name: "Automated Software Engineering"
7 | collection-title: "Proceedings of the 37th IEEE/ACM International Conference on Automated Software Engineering"
8 | publisher: ACM
9 | authors:
10 | - family-names: "Le Goaër"
11 | given-names: "Olivier"
12 | orcid: "https://orcid.org/0000-0001-5405-1688"
13 | - family-names: "Hertout"
14 | given-names: "Julien"
15 | title: "ecoCode: A SonarQube Plugin to Remove Energy Smells from Android Projects"
16 | doi: 10.1145/3551349.3559518
17 | year: 2022
18 |
--------------------------------------------------------------------------------
/android-plugin/src/main/resources/io/ecocode/rules/java/EC506.html:
--------------------------------------------------------------------------------
1 |
2 |
To avoid draining the battery, an Android device that is left idle quickly falls asleep.
3 | Hence, keeping the screen on should be avoided, unless it is absolutely necessary. If so, developers typically
4 | use the FLAG_KEEP_SCREEN_ON in their activity. Another way to implement this is in their application's
5 | layout XML file, by using the android:keepScreenOn attribute.
10 |
--------------------------------------------------------------------------------
/android-plugin/src/test/resources/org/sonar/plugins/groovy/codenarc/parsing/line-number-not-specified.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/test/resources/rulesets/NestedRuleSet1.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/sonar-project.properties:
--------------------------------------------------------------------------------
1 | # must be unique in a given SonarQube instance
2 | sonar.projectKey=sonar-custom-plugin-example
3 |
4 | # --- optional properties ---
5 |
6 | # defaults to project key
7 | #sonar.projectName=My project
8 | # defaults to 'not provided'
9 | #sonar.projectVersion=1.0
10 |
11 | # Path is relative to the sonar-project.properties file. Defaults to .
12 | #sonar.sources=.
13 |
14 | # Encoding of the source code. Default is default system encoding
15 | #sonar.sourceEncoding=UTF-8
16 |
17 | sonar.eslint.reportPaths=/opt/project/eslint-report.json
18 | sonar.css.stylelint.reportPaths=/opt/project/stylelint-report.json
19 | sonar.java.binaries=/opt/project/java-plugin/target/classes
20 | sonar.scm.disabled=true
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/test/resources/rulesets/RuleSet2.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/android-plugin/src/main/resources/io/ecocode/rules/java/EC532.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Importing the com.google.android.gms.analytics.Tracker or com.google.firebase.analytics.FirebaseAnalytics classes means that the app sends hits to Google Analytics. It is not necessarily sensitive information, but it is a first step towards Google Ads and hence this practice should be discouraged at early stage.
4 |
An app holding the permission REQUEST_IGNORE_BATTERY_OPTIMIZATIONS asks the user to allow it to ignore
3 | battery optimizations (that is, put them on the whitelist of apps).
4 |
Most applications should not use this; there are many facilities provided by the platform for applications to
5 | operate correctly in the various power saving modes.
Introduced in Android 9, the adaptive brightness feature raises or lower the brightness of the screen depending on
3 | the light in the current environment.
4 | For some reasons, developers may disable this feature programmatically, setting the field
5 | WindowManager.LayoutParams#screenBrightness with the constant BRIGHTNESS_OVERRIDE_FULL.
6 | This feature was introduced to improve battery life, be careful when deactivating it.
Turning on the torch mode programmatically with CameraManager#setTorchMode(..., true) must absolutely be
3 | avoided because the flashlight is one of the most energy-intensive component.
In contrast to classic Bluetooth, Bluetooth Low Energy (BLE)
3 | is designed to provide significantly lower power consumption.
4 | Its purpose is to save energy on both paired devices but very few
5 | developers are aware of this alternative API.
6 | From the Android client side, it means append android.bluetooth.le.*
7 | imports to android.bluetooth.* imports in order to benefits from
8 | low-energy features.
Creation of a Media Recorder object with new MediaRecorder() is used to record
3 | audio and video. Class own a release() method.
4 |
In addition to unnecessary resources (such as memory and instances of codecs) being held,
5 | failure to call this method immediately if a media object is no longer needed may also lead to
6 | continuous battery consumption for mobile devices.
To avoid draining the battery, an Android device that is left idle quickly falls asleep.
3 | Hence, keeping the screen on should be avoided, unless it is absolutely necessary.
4 | If so, developers typically use a Power Manager system service feature called wake locks
5 | by invoking PowerManager.WakeLock#newWakeLock(int levelAndFlags, String tag),
6 | along with the specific permission WAKE_LOCK in their manifest.
Taking into account when the device is entering or exiting the power save mode is higly desirable for the battery
3 | life.
4 | It implies the existence of a broadcast receiver registered on the action
5 | ACTION_POWER_SAVE_MODE_CHANGED,
6 | or programmaticaly with a call to PowerManager#isPowerSaveMode().
Creation of a Media Player object with new MediaPlayer() can
3 | be used to control playback of audio/video files and streams. Class own arelease() method.
4 |
In addition to unnecessary resources (such as memory and instances of codecs) being held,
5 | failure to call this method immediately if a media object is no longer needed may also lead to
6 | continuous battery consumption for mobile devices.
In Android 11 (API level 30) or higher, a call to
3 | Surface#setFrameRate(float frameRate, int compatibility) results in a change to the display refresh
4 | rate. However, a regular app displays 60 frames per second (60Hz). In order to optimize content refreshes and hence
5 | saving energy, this frequency should not be raised to 90Hz or 120Hz, despite this is now supported by many devices.
6 |
To avoid draining the battery, an Android device that is left idle quickly falls asleep.
3 | Hence, keeping the CPU on should be avoided, unless it is absolutely necessary.
4 | If so, developers typically use a Power Manager system service feature called wake locks
5 | by invoking PowerManager.WakeLock#newWakeLock(int levelAndFlags, String tag),
6 | along with the specific permission WAKE_LOCK in their manifest.
3 | For some use cases, it might be necessary to get a unique device identifier by a call to TelephonyManager#getDeviceId()
4 | (returns IMEI on GSM, MEID for CDMA).
5 | However, this raises privacy concerns and it is not recommended.
6 | Alternatively, you may use android.provider.Settings.Secure.ANDROID_ID.
7 |
Opening and closing internet connection continuously is extremely battery-inefficient since HTTP exchange is the most
3 | consuming operation of the network. This bug typically occurs when one obtain a new HttpURLConnection
4 | by calling URL#openConnection() within a loop control structure (while, for, do-while, for-each).
5 | Also, this bad practice must be early prevented because it is the root of another evil that consists in polling
6 | data at regular intervals, instead of using push notifications to save a lot of battery power.
7 |
Noncompliant Code Example
8 |
9 | for (int val : myArray) {
10 | URL.openConnection();
11 | }
12 |
Taking into account when the device is entering or exiting the power save mode is higly desirable for the battery
3 | life.
4 | It implies the existence of a broadcast receiver registered on the action
5 | ACTION_POWER_SAVE_MODE_CHANGED,
6 | or programmaticaly with a call to PowerManager#isPowerSaveMode().
7 |
Compliant Code Example
8 |
9 | new IntentFilter(Intent.ACTION_POWER_SAVE_MODE_CHANGED)
10 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/test/resources/source/SourceFile1.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package source
17 |
18 | /**
19 | * Source file for testing
20 | *
21 | * @author Chris Mair
22 | */
23 | class SourceFile1 {
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/main/resources/rulesets/serialization.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 | Serialization rule set.
8 | These rules check for Java serialization-specific violations.
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/test/resources/sourcewithdirs/SourceFile1.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sourcewithdirs
17 |
18 | /**
19 | * Source file for testing
20 | *
21 | * @author Chris Mair
22 | */
23 | class SourceFile1 {
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/test/resources/sourcewithdirs/subdir1/Subdir1File1.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sourcewithdirs.subdir1
17 |
18 | /**
19 | * Source file for testing
20 | *
21 | * @author Chris Mair
22 | */
23 | class Subdir1File1 {
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/test/resources/sourcewithdirs/subdir1/Subdir1File2.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sourcewithdirs.subdir1
17 |
18 | /**
19 | * Source file for testing
20 | *
21 | * @author Chris Mair
22 | */
23 | class Subdir1File2 {
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/test/resources/sourcewithdirs/subdir2/Subdir2File1.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sourcewithdirs.subdir2
17 |
18 | /**
19 | * Source file for testing
20 | *
21 | * @author Chris Mair
22 | */
23 | class Subdir2File1 {
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/test/resources/sourcewitherrors/SourceFile1.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sourcewitherrors
17 |
18 | /**
19 | * Source file for testing
20 | *
21 | * @author Chris Mair
22 | */
23 | class SourceFile1 {
24 |
25 | String name
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/test/resources/sourcewithdirs/subdir2/subdir2a/Subdir2aFile1.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sourcewithdirs.subdir2.subdir2a
17 |
18 | /**
19 | * Source file for testing
20 | *
21 | * @author Chris Mair
22 | */
23 | class Subdir2aFile1 {
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/android-plugin/src/main/resources/io/ecocode/rules/java/EC517.html:
--------------------------------------------------------------------------------
1 |
2 |
The fused location provider is one of the location APIs in Google Play
3 | services which combines signals from GPS, Wi-Fi, and cell networks, as well
4 | as accelerometer, gyroscope, magnetometer and other sensors. It is officially
5 | recommended to maximize battery life.
6 | Thus, developer has to set up Google Play Service in her gradle file with a dependency to
7 | com.google.android.gms:play-services-location:x.y.z, and then to
8 | import from com.google.android.gms.location instead of the
9 | android.location package of the SDK.
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/test/resources/sourcewitherrors/SourceFileWithCompileError.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2008 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package sourcewitherrors
17 |
18 | /**
19 | * Source file for testing
20 | *
21 | * @author Chris Mair
22 | */
23 | class SourceFileWithCompileError {
24 |
25 | !$%^
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/android-plugin/src/main/resources/io/ecocode/rules/java/EC510.html:
--------------------------------------------------------------------------------
1 |
2 |
For developers wishing to display OpenGL rendering, when choosing the rendering mode
3 | with GLSurfaceView#setRenderMode(int renderMode),
4 | using RENDERMODE_WHEN_DIRTY instead of RENDERMODE_CONTINUOUSLY
5 | (by default) can improve battery life and overall system performance by allowing the GPU and CPU
6 | to idle when the view does not need to be updated.
Shaking of an Android device is possible in all circumstances with a call to getSystemService(Context.VIBRATOR_SERVICE) (API 26) or
3 | getSystemService(Context.VIBRATOR.MANAGER.SERVICE) (API 31).
4 | Behind this effect stands a specific miniature hardware component, motor or actuator, that consumes power.
5 | As a consequence, its usage must be discouraged, especially since its added value is not clear.
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/docker/build.gradle.template:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'com.github.johnrengelman.shadow' version '6.1.0'
4 | }
5 |
6 | repositories {
7 | mavenCentral()
8 | }
9 |
10 | dependencies {
11 | compile 'org.codehaus.groovy:groovy:${groovy.version}'
12 | compile 'org.codehaus.groovy:groovy-xml:${groovy.version}'
13 | compile 'org.codehaus.groovy:groovy-json:${groovy.version}'
14 | compile 'org.codehaus.groovy:groovy-ant:${groovy.version}'
15 | compile 'org.codehaus.groovy:groovy-templates:${groovy.version}'
16 |
17 | compile('org.codenarc:CodeNarc:${codenarc.version}') {
18 | exclude group: 'org.codehaus.groovy'
19 | }
20 |
21 | compile 'ch.qos.logback:logback-classic:1.2.3'
22 | }
23 |
24 | shadowJar {
25 | archiveBaseName.set('codenarc-all')
26 | archiveClassifier.set('')
27 | archiveVersion.set('')
28 | manifest {
29 | attributes 'Main-Class': 'org.codenarc.CodeNarc'
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/ruleset/RuleSetConfigurer.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2021 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.codenarc.ruleset
17 |
18 | /**
19 | * Represents a configurer for a ruleset
20 | *
21 | * @author Chris Mair
22 | */
23 | interface RuleSetConfigurer {
24 |
25 | void configure(RuleSet ruleSet, String name)
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/android-plugin/src/main/resources/io/ecocode/rules/java/EC512.html:
--------------------------------------------------------------------------------
1 |
2 |
Most Android-powered devices have built-in sensors that measure motion, orientation, and various environmental conditions.
3 | In addition to these are the image sensor (a.k.a. Camera) and the geo-positioning sensor (a.k.a. GPS).
4 |
The common point of all these sensors is that they are expensive while in use. Their common bug is to let the sensor
5 | unnecessarily process data when the app enters an idle state, typically when paused or stopped.
6 | Consequently, calls must be carefully pairwised: Camera.open()/Camera.release().
7 | Failing to do so can drain the battery in just a few hours.
8 |
Noncompliant Code Example
9 |
10 | Camera camera = Camera.open();
11 |
12 |
Compliant Code Example
13 |
14 | Camera camera = Camera.open();
15 | camera.release();
16 |
17 |
18 |
--------------------------------------------------------------------------------
/android-plugin/src/test/java/io/ecocode/EcoCodeRulesPluginTest.java:
--------------------------------------------------------------------------------
1 | package io.ecocode;
2 |
3 | import org.junit.Test;
4 | import org.sonar.api.Plugin;
5 | import org.sonar.api.SonarEdition;
6 | import org.sonar.api.SonarQubeSide;
7 | import org.sonar.api.SonarRuntime;
8 | import org.sonar.api.internal.SonarRuntimeImpl;
9 | import org.sonar.api.utils.Version;
10 |
11 | import static org.assertj.core.api.Assertions.assertThat;
12 |
13 | public class EcoCodeRulesPluginTest {
14 |
15 | public static final Version VERSION_10_3 = Version.create(10, 3);
16 |
17 | @Test
18 | public void testExtensions() {
19 | EcoCodeRulesPlugin plugin = new EcoCodeRulesPlugin();
20 | SonarRuntime runtime =
21 | SonarRuntimeImpl.forSonarQube(VERSION_10_3, SonarQubeSide.SCANNER, SonarEdition.COMMUNITY);
22 | Plugin.Context context = new Plugin.Context(runtime);
23 | plugin.define(context);
24 | assertThat(context.getExtensions()).hasSize(14);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/ruleregistry/RuleRegistryHolder.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.codenarc.ruleregistry
17 |
18 | /**
19 | * Holds a reference to the RuleRegistry static singleton
20 | *
21 | * @author Chris Mair
22 | */
23 | class RuleRegistryHolder {
24 |
25 | static RuleRegistry ruleRegistry
26 | }
27 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/ruleregistry/RuleRegistry.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.codenarc.ruleregistry
17 |
18 | /**
19 | * Represents a registry of rule classes, accessible by rule name
20 | *
21 | * @author Chris Mair
22 | */
23 | interface RuleRegistry {
24 |
25 | Class getRuleClass(String ruleName)
26 | }
27 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 |
31 | **Smartphone (please complete the following information):**
32 | - Device: [e.g. iPhone6]
33 | - OS: [e.g. iOS8.1]
34 | - Browser [e.g. stock browser, safari]
35 | - Version [e.g. 22]
36 |
37 | **Additional context**
38 | Add any other context about the problem here.
39 |
--------------------------------------------------------------------------------
/android-plugin/src/main/resources/io/ecocode/rules/java/EC519.html:
--------------------------------------------------------------------------------
1 |
2 |
It's always good that an app has different behavior when device is connected/disconnected
3 | to a power station, or has different battery levels.
4 | One can monitor the changes in charging state with a broadcast receiver registered
5 | on the actions ACTION_POWER_CONNECTED and ACTION_POWER_DISCONNECTED,
6 | or monitor significant changes in battery level with a broadcast receiver registered
7 | on the actions BATTERY_LOW and BATTERY_OKAY.
8 |
Compliant Code Example
9 |
10 | new IntentFilter(Intent.ACTION_POWER_CONNECTED)
11 |
12 | OR
13 |
14 | new IntentFilter(Intent.ACTION_POWER_DISCONNECTED)
15 |
16 | OR
17 |
18 | new IntentFilter(Intent.ACTION_POWER_BATTERY_OKAY)
19 |
20 | OR
21 |
22 | new IntentFilter(Intent.ACTION_POWER_BATTERY_LOW)
23 |
With Bluetooth Low Energy technology (see BLE API smell), a Bluetooth Smart Ready
3 | device (the master) will establish a link with a Bluetooth Smart device (the slave).
4 | Most often, the slave is a GATT server and the master is a GATT client. GATT capable
5 | devices can be discovered using BLE scan process.
6 |
Invoking BluetoothGatt#requestConnectionPriority(int connectionPriority)
7 | with the value CONNECTION_PRIORITY_LOW_POWER, is recommended to reduce
8 | power consumption.
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/report/BaselineViolation.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.codenarc.report
17 |
18 | import groovy.transform.Immutable
19 |
20 | /**
21 | * Represents a single violation within a baseline report
22 | */
23 | @Immutable
24 | class BaselineViolation {
25 |
26 | String ruleName
27 | String message
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/main/resources/rulesets/unused.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 | Unused rule set.
8 | These rules check for unused definitions within the source code.
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/main/resources/rulesets/size.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 | Size and complexity rule set.
8 | These rules check against thresholds for code size and complexity.
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/android-plugin/src/main/resources/io/ecocode/rules/java/EC525.html:
--------------------------------------------------------------------------------
1 |
2 |
With Bluetooth Low Energy technology, a Bluetooth Smart Ready device (the master)
3 | will establish a link with a Bluetooth Smart device (the slave). Most often,
4 | the slave is a GATT server and the master is a GATT client. GATT capable
5 | devices can be discovered using BLE scan process.
6 |
The default and preferred advertising mode is ADVERTISE_MODE_LOW_POWER
7 | when calling AdvertiseSettings.Builder#setAdvertiseMode(int advertiseMode).
8 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/main/resources/rulesets/imports.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 | Imports rule set.
8 | These rules implement standards and best practices related to import statements.
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/codenarc-converter/CodeNarc/src/main/groovy/org/codenarc/ant/ReportOption.groovy:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010 the original author or authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.codenarc.ant
17 |
18 | /**
19 | * JavaBean class holding the properties for a