Skip to content

Commit 354248b

Browse files
committed
Merge branch 'main' into feature/prefer-collections-with-pagination
# Conflicts: # eslint-plugin/README.md # eslint-plugin/lib/index.js
2 parents f4471c2 + 7863820 commit 354248b

File tree

14 files changed

+444
-10
lines changed

14 files changed

+444
-10
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
sonarcloud:
3333
name: SonarCloud
3434
runs-on: ubuntu-latest
35+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
3536

3637
steps:
3738
- uses: actions/checkout@v3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Editors & OS
22
.DS_Store
33
.idea
4+
.vscode
45
*.iml
56

67
# Yarn

.yarn/versions/0a63a0fb.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
releases:
2+
"@ecocode/eslint-plugin": minor

.yarn/versions/37179847.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
releases:
2+
"@ecocode/eslint-plugin": minor

.yarn/versions/89666e13.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
releases:
2+
"@ecocode/eslint-plugin": minor

eslint-plugin/CHANGELOG.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add rule `@ecocode/avoid-high-accuracy-geolocation`
13+
- Add rule `@ecocode/no-import-all-from-library`
14+
1015
## [0.1.0] - 2023-03-24
1116

1217
### Added
1318

14-
- First alpha version of the ESLint plugin 🚀
15-
- Add rule `@ecocode/no-multiple-access-dom-element`
16-
- Create tooling script to generate SonarQube rules
17-
- Setup mocha and nyc for tests and coverage
18-
- Setup basic coding style tools
19-
- Write complete contributing guide
19+
- First alpha version of the ESLint plugin 🚀
20+
- Add rule `@ecocode/no-multiple-access-dom-element`
21+
- Create tooling script to generate SonarQube rules
22+
- Setup mocha and nyc for tests and coverage
23+
- Setup basic coding style tools
24+
- Write complete contributing guide
2025

2126
[Unreleased]: https://github.com/green-code-initiative/ecoCode-linter/compare/eslint-plugin/0.1.0...HEAD
2227

eslint-plugin/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ to have more information about the integration.
6565
⚠️ Configurations set to warn in.\
6666
✅ Set in the `recommended` configuration.
6767

68-
| Name | Description | ⚠️ |
69-
| :------------------------------------------------------------------------------------- | :-------------------------------------------- | :- |
70-
| [no-multiple-access-dom-element](docs/rules/no-multiple-access-dom-element.md) | Disallow multiple access of same DOM element. ||
71-
| [prefer-collections-with-pagination](docs/rules/prefer-collections-with-pagination.md) | Prefer API collections with pagination ||
68+
| Name | Description | ⚠️ |
69+
| :------------------------------------------------------------------------------------- | :--------------------------------------------------------- | :- |
70+
| [avoid-high-accuracy-geolocation](docs/rules/avoid-high-accuracy-geolocation.md) | Avoid using high accuracy geolocation in web applications. ||
71+
| [no-import-all-from-library](docs/rules/no-import-all-from-library.md) | Should not import all from library ||
72+
| [no-multiple-access-dom-element](docs/rules/no-multiple-access-dom-element.md) | Disallow multiple access of same DOM element. ||
73+
| [prefer-collections-with-pagination](docs/rules/prefer-collections-with-pagination.md) | Prefer API collections with pagination. ||
7274

7375
<!-- end auto-generated rules list -->
7476

50 KB
Loading
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Avoid using high accuracy geolocation in web applications (`@ecocode/avoid-high-accuracy-geolocation`)
2+
3+
⚠️ This rule _warns_ in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
## Rule details
8+
9+
This rule aims at reducing CPU consumption by telling the device to use a less accurate yet more eco friendly geolocation, when geolocation API is used.
10+
11+
## Examples
12+
13+
Examples of **non compliant** code for this rule:
14+
15+
```js
16+
var options = { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 };
17+
function success(pos) {
18+
console.log(pos.coords);
19+
}
20+
21+
function error(err) {
22+
console.warn(err);
23+
}
24+
25+
navigator.geolocation.getCurrentPosition(success, error, options);
26+
```
27+
28+
Examples of **compliant** code for this rule:
29+
30+
```js
31+
// enableHighAccuracy is false by default, so not declaring it is correct
32+
function success(pos) {
33+
console.log(pos);
34+
}
35+
navigator.geolocation.getCurrentPosition(success);
36+
```
37+
38+
```js
39+
var options = { enableHighAccuracy: false, timeout: 5000, maximumAge: 0 };
40+
function success(pos) {
41+
console.log(pos.coords);
42+
}
43+
44+
function error(err) {
45+
console.warn(err);
46+
}
47+
48+
navigator.geolocation.getCurrentPosition(success, error, options);
49+
```
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Should not import all from library (`@ecocode/no-import-all-from-library`)
2+
3+
⚠️ This rule _warns_ in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
7+
## Rule details
8+
9+
This rule aims to reduce weight of programs by using only needed modules. Many libraries export only one module by
10+
default, but some of them are exporting ES modules or submodules. We should use them to select more precisly needed
11+
modules and avoid unnecessarily overloading files weight.
12+
13+
![Example with lodash](https://raw.githubusercontent.com/green-code-initiative/ecoCode-linter/main/eslint-plugin/docs/images/no-import-all-from-library.jpg)
14+
15+
*Example with the well-known [lodash](https://lodash.com/) library, if you only need "isEmpty" method.*
16+
17+
## Options
18+
19+
You can externally add your own libraries to be checked.
20+
To add your own libraries you need to modify your .eslintrc.js by adding the following rule configuration:
21+
22+
```js
23+
module.exports = {
24+
...yourConf,
25+
rules: {
26+
"no-import-all-from-library": [
27+
"warn",
28+
{
29+
notAllowedLibraries: ["some-lib"], // will check for -> import someLib from "some-lib"
30+
importByNamespaceNotAllowedLibraries: ["some-other-lib"], // will check for -> import * as someOtherLib from "some-other-lib"
31+
},
32+
],
33+
},
34+
};
35+
```
36+
37+
## Examples
38+
39+
Examples of **non-compliant** code for this rule:
40+
41+
```js
42+
// Example with lodash
43+
import lodash from "lodash";
44+
import { isEmpty } from "lodash";
45+
import * as lodash from "lodash";
46+
47+
// Example with underscore
48+
import _ from "underscore";
49+
```
50+
51+
Examples of **compliant** code for this rule:
52+
53+
```js
54+
// Example with lodash (uses submodules)
55+
import isEmpty from "lodash/isEmpty";
56+
import intersect from "lodash/intersect";
57+
58+
// Example with underscore (uses esm modules)
59+
import map from "underscore/modules/map.js";
60+
```

0 commit comments

Comments
 (0)