Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves Doc with sonar_rules_reused.md and passing it to tooling (sh scripts) #18

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions tools/rules_config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Purpose

1. **Rules Tagging system**

Add one new tag to a list of rules (using SonarQube API).
Add one new tag to a list of rules from `SONAR_RULES_REUSED.md` (using SonarQube API).
Why ? because maybe some original SonarQube rules are already ready for being part of this plugin

2. **EcoCode Quality Profile**
Expand All @@ -27,7 +27,7 @@ Requirements
- Sonar token (`SONAR_TOKEN` variable) : put here the new added token previously
- Sonar URL (`SONAR_URL` variable) : put here your custom Sonar URL ("http://localhost:9000" by default)
- name of tag to add (`TAG_ECOCONCEPTION` variable) : the name of the new tag to add to a list of rules
- rules keys list (string format separated with one comma) (`RULES_KEYS` variable) : specify here the list of all keys of rules that you want to add th new tag
- file path to `SONAR_RULES_REUSED.md` (`FILEPATH_SONAR_RULES_REUSED` variable) : filepath in the local folder. Contains all rules.
- name of profile to add (`PROFILE_ECOCONCEPTION` variable) : the name of the new profile to add for each language
- language keys list (string format separated with one comma) (`PROFILES_LANGUAGE_KEYS` variable) : specify here the list of all keys language that you want to add the new ecocode quality profile

Expand Down Expand Up @@ -68,7 +68,7 @@ Algorithm

1. **Tags**

- get rules data (rules list from config file)
- get rules data (rules list from parsing `SONAR_RULES_REUSED.md`)
- check if new tag to add (from config file) already exists on systags array or tags array
- add new tag to all existing tags if necessary

Expand All @@ -94,3 +94,12 @@ How does it work ?
- launch `install_tags.sh` to add custom tag to your rules
- launch `check_tags.sh` again to control your rules and tags
- launch `install_profile.sh` to create profiles with the new rules from plugins

Contributing ?
--------------

**You want to add new pre-existing rule from Sonar ?**
- You have to find the sonar key from **"RULES"** view on Sonarqube
- adding a new line to `SONAR_RULES_REUSED.md` with this key
- add references to justify this value
- Create a Pull Request following #CONTRIBUTING.md
5 changes: 5 additions & 0 deletions tools/rules_config/SONAR_RULES_REUSED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| Rules Id | Description | Reference/Validation |
|--|--|--|
| css:S4655 | "!important" should not be used on "keyframes" | -- |
| php:S2014 | "$this" should not be used in a static context | -- |
| Web:ItemTagNotWithinContainerTagCheck | "\<li>" and "\<dt>" item tags should be in "\<ul>", "\<ol>" or "\<dl>" container tags | -- |
5 changes: 2 additions & 3 deletions tools/rules_config/_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ SONAR_URL=http://localhost:9000
TAG_ECOCONCEPTION=test1
# TAG_ECOCONCEPTION=

# list of rule keys that will be updated with new tag
RULES_KEYS=css:S4655,php:S2014,Web:ItemTagNotWithinContainerTagCheck
# RULES_KEYS=
# filepath to markdown doc containing rule keys that will be updated with new tag
FILEPATH_SONAR_RULES_REUSED='./SONAR_RULES_REUSED.md'

# name quality profile
PROFILE_ECOCONCEPTION="EcoCodeProfile"
Expand Down
25 changes: 25 additions & 0 deletions tools/rules_config/_core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,28 @@ debug() {
fi
}

### Read FILEPATH_SONAR_RULES_REUSED file to extract RULES_KEYS
function read_sonar_rules_reused {
debug "Read file ${FILEPATH_SONAR_RULES_REUSED}"
rules_keys=""
{
#Skip header file markdown
read -r
read -r
while IFS='|' read -ra line; do
col=0;
for substr in "${line[@]}"; do
if [ $col -eq 1 ]; then
rules_keys="$rules_keys$(echo $substr | xargs),"
fi
col=$((col+1))
done
done
} < $FILEPATH_SONAR_RULES_REUSED
RULES_KEYS=$(echo $rules_keys | sed 's/.$//')
debug "Extracting rules: $RULES_KEYS \n"
}

### build array with all rules
### $1 : the variable to set into the computed response (using it by reference)
declare -a RULES_ARRAY
Expand Down Expand Up @@ -127,6 +149,9 @@ function validate_parameters() {
# C O R E I N I T I A L I Z A T I O N ( /!\ /!\ /!\ NOT to modify)
###########################################################################################

### export rules keys from markdown documentation
read_sonar_rules_reused

### transform string list of rules keys (separated by a ,) to an array
build_rules_array

Expand Down