-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ec513): integrated rule html and json
- Loading branch information
1 parent
a1ee6e5
commit cde52fa
Showing
6 changed files
with
76 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"EC547", | ||
"EC523", | ||
"EC503", | ||
"EC603" | ||
"EC603", | ||
"EC513" | ||
] | ||
} |
49 changes: 49 additions & 0 deletions
49
swift-lang/src/main/resources/io/ecocode/rules/swift/EC513.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<p>Most Android-powered devices have built-in sensors that measure motion, orientation, and various environmental conditions. | ||
In addition to these are the image sensor (a.k.a Camera) and the geopositioning sensor (a.k.a GPS).</p> | ||
<br>The common point of all these sensors is that they are expensive while in use. Their common bug is to let the sensor | ||
unnecessarily process data when the app enters an idle state, typically when paused or stopped.</br> | ||
Consequently, calls must be carefully pairwised: <code>CLLocationManager.startUpdatingLocation() and CLLocationManager.stopUpdatingLocation()</code>.</br> | ||
Failing to do so can drain the battery in just a few hours.</p> | ||
<h2>Noncompliant Code Example</h2> | ||
<pre> | ||
import CoreLocation | ||
|
||
class LocationTracker: NSObject, CLLocationManagerDelegate { | ||
var locationManager: CLLocationManager? | ||
|
||
override init() { | ||
super.init() | ||
locationManager = CLLocationManager() | ||
locationManager?.delegate = self | ||
locationManager?.requestAlwaysAuthorization() // Request appropriate authorization | ||
locationManager?.startUpdatingLocation() // Start location updates | ||
} | ||
|
||
// LocationManager Delegate Methods | ||
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | ||
// Process new locations | ||
} | ||
} | ||
</pre> | ||
<br> | ||
<h2>Compliant Code Example</h2> | ||
<pre> | ||
class LocationTracker: NSObject, CLLocationManagerDelegate { | ||
var locationManager: CLLocationManager? | ||
|
||
override init() { | ||
super.init() | ||
locationManager = CLLocationManager() | ||
locationManager?.delegate = self | ||
locationManager?.requestAlwaysAuthorization() // Request appropriate authorization | ||
locationManager?.startUpdatingLocation() // Start location updates only when needed | ||
} | ||
|
||
// LocationManager Delegate Methods | ||
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { | ||
// Process new locations | ||
// Possibly stop updates if they are no longer needed | ||
locationManager?.stopUpdatingLocation() | ||
} | ||
} | ||
</pre> |
19 changes: 19 additions & 0 deletions
19
swift-lang/src/main/resources/io/ecocode/rules/swift/EC513.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"key": "EC513", | ||
"title": "Leakage: Location Leak", | ||
"defaultSeverity": "Major", | ||
"description": "Most iOS devices come equipped with a variety of sensors that measure motion, orientation, and various environmental conditions. In addition to these, the devices include advanced sensors such as the image sensor (commonly referred to as the Camera) and the geo-positioning sensor (commonly referred to as GPS).\n\nThe common point of all these sensors is that they are power-intensive while in use. A typical issue arises when these sensors continue to process data unnecessarily after the application enters an idle state, typically when paused or when the user stops interacting with it.\n\nConsequently, calls must be carefully paired: CLLocationManager.startUpdatingLocation() and CLLocationManager.stopUpdatingLocation(). Failing to do so can drain the battery in just a few hours.", | ||
"status": "ready", | ||
"remediation": { | ||
"func": "Constant/Issue", | ||
"constantCost": "20min" | ||
}, | ||
"tags": [ | ||
"sobriety", | ||
"environment", | ||
"ecocode", | ||
"eco-design" | ||
], | ||
"type": "CODE_SMELL" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters