From a3a9dd10a780ec290e8a3769c6e7d5a684ba4562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie=20Renard?= <44666826+amelie-renard-sonarsource@users.noreply.github.com> Date: Mon, 3 May 2021 21:31:58 +0200 Subject: [PATCH] RULEAPI-598 Provide a way to name a language subdirectory correctly (when specializing a rule) --- README.adoc | 8 ++++++-- supported_languages.adoc | 1 + validate_asciidoc.sh | 9 +++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 supported_languages.adoc diff --git a/README.adoc b/README.adoc index bcc8b39f59..be4dd1f718 100644 --- a/README.adoc +++ b/README.adoc @@ -17,7 +17,9 @@ WARNING: **Beta status**: This repository is not used yet in production. The cur ** `rules/Sxxxx`: contains every specification for rule `Sxxxx`. *** `rules/Sxxxx/*.adoc`: Asciidoc files which can be reused by multiple language-specific descriptions. *** `rules/Sxxxx/metadata.json`: rule metadata shared between language-specific RSPECs. Each language can override fields in its own `metadata.json` file. -*** `rules/Sxxxx/[LANGUAGE]`: contains the language-specific RSPEC. For every rule, there must be at least one `[LANGUAGE]` subdirectory. `[LANGUAGE]` can be `java`, `cfamily`, `python`... +*** `rules/Sxxxx/[LANGUAGE]`: contains the language-specific RSPEC. For every rule, there must be at least one `[LANGUAGE]` subdirectory. + +`[LANGUAGE]` can be any of the following: +include::supported_languages.adoc[] **** `rules/Sxxxx/[LANGUAGE]/rule.adoc`: asciidoc file used to generate the `Sxxxx` rule description for programming language `[LANGUAGE]`. It can include parts from `*.adoc` files located in the parent directory. **** `rules/Sxxxx/[LANGUAGE]/metadata.json`: metadatas for the specific language. Each key at the top will completely override the key of the `metadata.json` file of the parent directory. @@ -38,7 +40,9 @@ However, one of the reasons we are migrating to a git repository is that we want ==== For a new rule 1. go to the https://github.com/SonarSource/rspec/actions/workflows/create_new_rspec.yml[Create new RSPEC] GitHub action 2. click on the grey _Run wokflow_ button (on the right). -3. in the field _"Comma-separated list of targeted languages"_ write the list of languages you want to specify this rule for. +3. in the field _"Comma-separated list of targeted languages"_ write the list of languages you want to specify this rule for. + +They can be any of the following: +include::supported_languages.adoc[] 4. click on the green _Run workflow_ button. image::img/new-rule-workflow.png[] diff --git a/supported_languages.adoc b/supported_languages.adoc new file mode 100644 index 0000000000..1c57d8dce4 --- /dev/null +++ b/supported_languages.adoc @@ -0,0 +1 @@ +`abap`, `apex`, `cfamily`, `cobol`, `csharp`, `css`, `flex`, `go`, `html`, `java`, `javascript`, `kotlin`, `php`, `pli`, `plsql`, `python`, `rpg`, `ruby`, `rust`, `scala`, `solidity`, `swift`, `tsql`, `vb6`, `vbnet`, or `xml` diff --git a/validate_asciidoc.sh b/validate_asciidoc.sh index 34a8a56430..8878829d5b 100755 --- a/validate_asciidoc.sh +++ b/validate_asciidoc.sh @@ -17,10 +17,15 @@ do fi else #validate asciidoc - for language in $dir/*/ + supportedLanguages=$(sed 's/ or//' supported_languages.adoc | tr -d '`,') + for language in $dir/*/ do language=${language%*/} echo ${language##*/} + if [[ ! "${supportedLanguages[@]}" =~ "${language##*/}" ]]; then + echo "ERROR: ${language##*/} is not a supported language" + exit_code=1 + fi RULE="$language/rule.adoc" if test -f $RULE; then echo "$RULE exists." @@ -42,4 +47,4 @@ do fi done -exit $exit_code \ No newline at end of file +exit $exit_code