Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit b8bf961

Browse files
authored
Add prettier as pre-commit hook, clean up CI
1 parent 732e2ad commit b8bf961

38 files changed

+781
-1403
lines changed

.cirrus.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ env:
55

66
SONAR_TOKEN: VAULT[development/kv/data/sonarcloud data.token]
77
ARTIFACTORY_URL: https://repox.jfrog.io/
8-
ARTIFACTORY_DEPLOY_ACCESS_TOKEN : VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer access_token]
9-
ARTIFACTORY_PROMOTE_ACCESS_TOKEN : VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promoter access_token]
8+
ARTIFACTORY_DEPLOY_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-qa-deployer access_token]
9+
ARTIFACTORY_PROMOTE_ACCESS_TOKEN: VAULT[development/artifactory/token/${CIRRUS_REPO_OWNER}-${CIRRUS_REPO_NAME}-promoter access_token]
1010
# Use bash (instead of sh on linux or cmd.exe on windows)
1111
CIRRUS_SHELL: bash
1212

@@ -26,6 +26,29 @@ container_definition: &CONTAINER_DEFINITION
2626

2727
build_task:
2828
<<: *ONLY_SONARSOURCE_QA
29+
eks_container:
30+
<<: *CONTAINER_DEFINITION
31+
docker_arguments:
32+
CIRRUS_AWS_ACCOUNT: ${CIRRUS_AWS_ACCOUNT}
33+
cpu: 3
34+
memory: 8G
35+
env:
36+
SONARSOURCE_QA: true
37+
node_version_script:
38+
- node --version
39+
script:
40+
- if [ -n "${CIRRUS_BASE_BRANCH}" ]; then git fetch origin "${CIRRUS_BASE_BRANCH}"; fi
41+
- jfrog config add repox --url $ARTIFACTORY_URL --access-token $ARTIFACTORY_DEPLOY_ACCESS_TOKEN
42+
- jfrog rt npm-config --repo-resolve npm --repo-deploy sonarsource-npm-public-qa
43+
- jfrog rt npm-ci
44+
- npm run check-format
45+
- npm run build
46+
- ./scripts/test-ci.sh
47+
- ./scripts/analyze_and_publish.sh
48+
49+
qa_task:
50+
depends_on:
51+
- build
2952
eks_container:
3053
matrix:
3154
- docker_arguments:
@@ -41,7 +64,6 @@ build_task:
4164
cpu: 3
4265
memory: 8G
4366
env:
44-
CIRRUS_CLONE_DEPTH: 10
4567
SONARSOURCE_QA: true
4668
node_version_script:
4769
- node --version
@@ -50,13 +72,8 @@ build_task:
5072
- jfrog rt npm-config --repo-resolve npm --repo-deploy sonarsource-npm-public-qa
5173
- git submodule update --init --depth 1 -r
5274
- jfrog rt npm-ci
53-
- npm run typecheck
5475
- npm run build
55-
- ./scripts/test-ci.sh
56-
- npm run check-format
57-
- npm run lint
5876
- npm run ruling
59-
- ./scripts/analyze_and_publish.sh
6077

6178
ws_scan_task:
6279
depends_on:
@@ -75,7 +92,7 @@ ws_scan_task:
7592
folder: ${CIRRUS_WORKING_DIR}/.m2/repository
7693
whitesource_script:
7794
- ./scripts/run_ws_scan.sh
78-
allow_failures: "true"
95+
allow_failures: 'true'
7996
always:
8097
ws_artifacts:
81-
path: "whitesource/**/*"
98+
path: 'whitesource/**/*'

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npm run precommit

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
.idea/
1010
.vscode/
1111
.github/
12+
.husky
1213

1314
coverage/
1415
docs/
@@ -20,13 +21,13 @@ tests/
2021
.gitattributes
2122
.gitmodules
2223
.npmignore
24+
.prettierignore
2325
.travis.yml
2426
.eslintrc.js
2527
.editorconfig
2628
sonar-project.properties
2729
test-report.xml
2830
tsconfig.json
29-
tsconfig-src.json
3031
.cirrus/
3132
.cirrus.yml
3233
.jfrog/

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.github
2+
.jfrog
3+
coverage
4+
lib
5+
javascript-test-sources
6+
docs

README.md

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,43 @@ SonarJS rules for ESLint to help developers produce [Clean Code](https://www.son
88

99
Rules in this category aim to find places in code that have a high chance of being bugs, i.e. don't work as intended.
1010

11-
* All branches in a conditional structure should not have exactly the same implementation ([`no-all-duplicated-branches`])
12-
* Collection elements should not be replaced unconditionally ([`no-element-overwrite`])
13-
* Empty collections should not be accessed or iterated ([`no-empty-collection`])
14-
* Function calls should not pass extra arguments ([`no-extra-arguments`])
15-
* Related "if/else if" statements should not have the same condition ([`no-identical-conditions`])
16-
* Identical expressions should not be used on both sides of a binary operator ([`no-identical-expressions`])
17-
* Return values from functions without side effects should not be ignored ([`no-ignored-return`]) (*uses-types*)
18-
* Loops with at most one iteration should be refactored ([`no-one-iteration-loop`])
19-
* The output of functions that don't return anything should not be used ([`no-use-of-empty-return-value`])
20-
* Non-existent operators '=+', '=-' and '=!' should not be used ([`non-existent-operator`]) (:wrench: *fixable*)
11+
- All branches in a conditional structure should not have exactly the same implementation ([`no-all-duplicated-branches`])
12+
- Collection elements should not be replaced unconditionally ([`no-element-overwrite`])
13+
- Empty collections should not be accessed or iterated ([`no-empty-collection`])
14+
- Function calls should not pass extra arguments ([`no-extra-arguments`])
15+
- Related "if/else if" statements should not have the same condition ([`no-identical-conditions`])
16+
- Identical expressions should not be used on both sides of a binary operator ([`no-identical-expressions`])
17+
- Return values from functions without side effects should not be ignored ([`no-ignored-return`]) (_uses-types_)
18+
- Loops with at most one iteration should be refactored ([`no-one-iteration-loop`])
19+
- The output of functions that don't return anything should not be used ([`no-use-of-empty-return-value`])
20+
- Non-existent operators '=+', '=-' and '=!' should not be used ([`non-existent-operator`]) (:wrench: _fixable_)
2121

2222
### Code Smell Detection :pig:
2323

2424
Code Smells, or maintainability issues, are raised for places of code which might be costly to change in the future. These rules also help to keep the high code quality and readability. And finally, some rules report issues on different suspicious code patterns.
2525

26-
* Cognitive Complexity of functions should not be too high ([`cognitive-complexity`])
27-
* "if ... else if" constructs should end with "else" clauses ([`elseif-without-else`]) (*disabled*)
28-
* "switch" statements should not have too many "case" clauses ([`max-switch-cases`])
29-
* Collapsible "if" statements should be merged ([`no-collapsible-if`])
30-
* Collection sizes and array length comparisons should make sense ([`no-collection-size-mischeck`]) (:wrench: *fixable*, *uses-types*)
31-
* String literals should not be duplicated ([`no-duplicate-string`])
32-
* Two branches in a conditional structure should not have exactly the same implementation ([`no-duplicated-branches`])
33-
* Boolean expressions should not be gratuitous ([`no-gratuitous-expressions`])
34-
* Functions should not have identical implementations ([`no-identical-functions`])
35-
* Boolean checks should not be inverted ([`no-inverted-boolean-check`]) (:wrench: *fixable*, *disabled*)
36-
* "switch" statements should not be nested ([`no-nested-switch`])
37-
* Template literals should not be nested ([`no-nested-template-literals`])
38-
* Boolean literals should not be redundant ([`no-redundant-boolean`])
39-
* Jump statements should not be redundant ([`no-redundant-jump`]) (:wrench: *fixable*)
40-
* Conditionals should start on new lines ([`no-same-line-conditional`]) (:wrench: *fixable*)
41-
* "switch" statements should have at least 3 "case" clauses ([`no-small-switch`])
42-
* Collection and array contents should be used ([`no-unused-collection`])
43-
* "catch" clauses should do more than rethrow ([`no-useless-catch`])
44-
* Local variables should not be declared and then immediately returned or thrown ([`prefer-immediate-return`]) (:wrench: *fixable*)
45-
* Object literal syntax should be used ([`prefer-object-literal`])
46-
* Return of boolean expressions should not be wrapped into an "if-then-else" statement ([`prefer-single-boolean-return`]) (:wrench: *fixable*)
47-
* A "while" loop should be used instead of a "for" loop ([`prefer-while`]) (:wrench: *fixable*)
26+
- Cognitive Complexity of functions should not be too high ([`cognitive-complexity`])
27+
- "if ... else if" constructs should end with "else" clauses ([`elseif-without-else`]) (_disabled_)
28+
- "switch" statements should not have too many "case" clauses ([`max-switch-cases`])
29+
- Collapsible "if" statements should be merged ([`no-collapsible-if`])
30+
- Collection sizes and array length comparisons should make sense ([`no-collection-size-mischeck`]) (:wrench: _fixable_, _uses-types_)
31+
- String literals should not be duplicated ([`no-duplicate-string`])
32+
- Two branches in a conditional structure should not have exactly the same implementation ([`no-duplicated-branches`])
33+
- Boolean expressions should not be gratuitous ([`no-gratuitous-expressions`])
34+
- Functions should not have identical implementations ([`no-identical-functions`])
35+
- Boolean checks should not be inverted ([`no-inverted-boolean-check`]) (:wrench: _fixable_, _disabled_)
36+
- "switch" statements should not be nested ([`no-nested-switch`])
37+
- Template literals should not be nested ([`no-nested-template-literals`])
38+
- Boolean literals should not be redundant ([`no-redundant-boolean`])
39+
- Jump statements should not be redundant ([`no-redundant-jump`]) (:wrench: _fixable_)
40+
- Conditionals should start on new lines ([`no-same-line-conditional`]) (:wrench: _fixable_)
41+
- "switch" statements should have at least 3 "case" clauses ([`no-small-switch`])
42+
- Collection and array contents should be used ([`no-unused-collection`])
43+
- "catch" clauses should do more than rethrow ([`no-useless-catch`])
44+
- Local variables should not be declared and then immediately returned or thrown ([`prefer-immediate-return`]) (:wrench: _fixable_)
45+
- Object literal syntax should be used ([`prefer-object-literal`])
46+
- Return of boolean expressions should not be wrapped into an "if-then-else" statement ([`prefer-single-boolean-return`]) (:wrench: _fixable_)
47+
- A "while" loop should be used instead of a "for" loop ([`prefer-while`]) (:wrench: _fixable_)
4848

4949
[`cognitive-complexity`]: ./docs/rules/cognitive-complexity.md
5050
[`elseif-without-else`]: ./docs/rules/elseif-without-else.md
@@ -81,36 +81,36 @@ Code Smells, or maintainability issues, are raised for places of code which migh
8181

8282
## Prerequisites
8383

84-
* Node.js (>=14.x).
85-
* ESLint 5.x, 6.x, 7.x or 8.x (peer dependency for the plugin).
84+
- Node.js (>=14.x).
85+
- ESLint 5.x, 6.x, 7.x or 8.x (peer dependency for the plugin).
8686

8787
## Usage
8888

89-
* If you don't have ESLint yet configured for your project, follow [these instructions](https://github.com/eslint/eslint#installation-and-usage).
90-
* Install `eslint-plugin-sonarjs` using `npm` (or `yarn`) for your project or globally:
89+
- If you don't have ESLint yet configured for your project, follow [these instructions](https://github.com/eslint/eslint#installation-and-usage).
90+
- Install `eslint-plugin-sonarjs` using `npm` (or `yarn`) for your project or globally:
9191

9292
```sh
9393
npm install eslint-plugin-sonarjs --save-dev # install for your project
9494
npm install eslint-plugin-sonarjs -g # or install globally
9595
```
9696

97-
* Add `eslint-plugin-sonarjs` to the `plugins` option of your `.eslintrc`:
97+
- Add `eslint-plugin-sonarjs` to the `plugins` option of your `.eslintrc`:
9898

9999
```json
100100
{
101101
"plugins": ["sonarjs"]
102102
}
103103
```
104104

105-
* Add `plugin:sonarjs/recommended` to the `extends` option to enable all recommended rules:
105+
- Add `plugin:sonarjs/recommended` to the `extends` option to enable all recommended rules:
106106

107107
```json
108108
{
109109
"extends": ["plugin:sonarjs/recommended"]
110110
}
111111
```
112112

113-
* or enable only some rules manually:
113+
- or enable only some rules manually:
114114

115115
```javascript
116116
{
@@ -121,15 +121,16 @@ npm install eslint-plugin-sonarjs -g # or install globally
121121
}
122122
}
123123
```
124-
* To enable all rules of this plugin, use `@typescript-eslint/parser` as a parser for ESLint ([like we do](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/6e06d59a233e07b28fbbd6398e08b9b0c63b18f9/.eslintrc.js#L4)) and set the [parserOptions.project](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#parseroptionsproject) option. Thanks to it, type information is available, which is beneficial or even essential for some rules.
124+
125+
- To enable all rules of this plugin, use `@typescript-eslint/parser` as a parser for ESLint ([like we do](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/6e06d59a233e07b28fbbd6398e08b9b0c63b18f9/.eslintrc.js#L4)) and set the [parserOptions.project](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#parseroptionsproject) option. Thanks to it, type information is available, which is beneficial or even essential for some rules.
125126

126127
## Available Configurations
127128

128-
This plugin provides only a `recommended` configuration. Almost all rules are activated in this profile with a few exceptions (check the `disabled` tag in the rules list). The `recommended` configuration activates rules with `error` severity.
129+
This plugin provides only a `recommended` configuration. Almost all rules are activated in this profile with a few exceptions (check the `disabled` tag in the rules list). The `recommended` configuration activates rules with `error` severity.
129130

130131
## ESLint and Sonar
131132

132-
This plugin exposes to ESLint users a subset of JS/TS rules from Sonar-* products (aka [SonarJS](https://github.com/SonarSource/SonarJS)). We extracted the rules that are not available in ESLint core or other ESLint plugins to be beneficial for the ESLint community.
133+
This plugin exposes to ESLint users a subset of JS/TS rules from Sonar-\* products (aka [SonarJS](https://github.com/SonarSource/SonarJS)). We extracted the rules that are not available in ESLint core or other ESLint plugins to be beneficial for the ESLint community.
133134

134135
If you are a [SonarQube](https://www.sonarqube.org) or [SonarCloud](https://sonarcloud.io) user, to lint your code locally, we suggest using [SonarLint](https://www.sonarlint.org) IDE extension (available for VSCode, JetBrains IDEs and Eclipse). You can connect SonarLint to your SonarQube/SonarCloud project to synchronize rules configuration, issue statuses, etc.
135136

docs/CONTRIBUTING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ Report bugs and suggest improvements. If something doesn't work well for you or
88

99
## Create New Rule
1010

11-
* Create a new file for the rule implementation in `src/rules`. File name should be lowercased, words must be separated by dashes (`-`).
12-
* Create a test file `<rule name>.test.ts` in `test/rules`.
13-
* Add the rule to `src/index.ts`.
14-
* In folder `docs/rules` create a rule documentation file `<rule name>.md`
15-
* In `README.md` add a reference to this documentation file.
16-
* Run [Ruling](#ruling) test.
11+
- Create a new file for the rule implementation in `src/rules`. File name should be lowercased, words must be separated by dashes (`-`).
12+
- Create a test file `<rule name>.test.ts` in `test/rules`.
13+
- Add the rule to `src/index.ts`.
14+
- In folder `docs/rules` create a rule documentation file `<rule name>.md`
15+
- In `README.md` add a reference to this documentation file.
16+
- Run [Ruling](#ruling) test.
1717

1818
## Testing
1919

docs/RELEASING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## Releasing npm package
22

3-
* [Create a Jira release ticket](https://jira.sonarsource.com/projects/REL) like [this one](https://sonarsource.atlassian.net/browse/REL-2313)
4-
* [Publish a new GitHub release](https://github.com/SonarSource/eslint-plugin-sonarjs/releases/new)
5-
* [Bump the package version for the next development iteration](https://github.com/SonarSource/eslint-plugin-sonarjs/pull/418/files)
3+
- [Create a Jira release ticket](https://jira.sonarsource.com/projects/REL) like [this one](https://sonarsource.atlassian.net/browse/REL-2313)
4+
- [Publish a new GitHub release](https://github.com/SonarSource/eslint-plugin-sonarjs/releases/new)
5+
- [Bump the package version for the next development iteration](https://github.com/SonarSource/eslint-plugin-sonarjs/pull/418/files)

docs/rules/cognitive-complexity.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Cognitive Complexity is a measure of how hard the control flow of a function is
44

55
## See
66

7-
* [Cognitive Complexity](http://redirect.sonarsource.com/doc/cognitive-complexity.html)
7+
- [Cognitive Complexity](http://redirect.sonarsource.com/doc/cognitive-complexity.html)
88

99
## Configuration
1010

docs/rules/elseif-without-else.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if (x == 0) {
1515
doSomethingElse();
1616
}
1717
```
18+
1819
## Compliant Solution
1920

2021
```javascript
@@ -23,7 +24,7 @@ if (x == 0) {
2324
} else if (x == 1) {
2425
doSomethingElse();
2526
} else {
26-
throw "Unexpected value for x";
27+
throw 'Unexpected value for x';
2728
}
2829
```
2930

docs/rules/no-collection-size-mischeck.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
# no-collection-size-mischeck
22

3-
:wrench: *fixable*
3+
:wrench: _fixable_
44

55
The size of a collection and the length of an array are always greater than or equal to zero. So testing that a size or length is greater than or equal to zero doesn't make sense, since the result is always `true`. Similarly testing that it is less than zero will always return `false`. Perhaps the intent was to check the non-emptiness of the collection or array instead.
66

77
## Noncompliant Code Example
88

99
```javascript
10-
if (someSet.size >= 0) {...} // Noncompliant
10+
if (someSet.size >= 0) { // Noncompliant
11+
//...
12+
}
1113

12-
if (someMap.size < 0) {...} // Noncompliant
14+
if (someMap.size < 0) { // Noncompliant
15+
//...
16+
}
1317

14-
const result = someArray.length >= 0; // Noncompliant
18+
const result = someArray.length >= 0; // Noncompliant
1519
```
1620

1721
## Compliant Solution
1822

1923
```javascript
20-
if (someSet.size > 0) {...}
24+
if (someSet.size > 0) {
25+
//...
26+
}
2127

22-
if (someMap.size == 0) {...}
28+
if (someMap.size == 0) {
29+
//...
30+
}
2331

2432
const result = someArray.length > 0;
2533
```

0 commit comments

Comments
 (0)