Skip to content
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
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand Down
15 changes: 9 additions & 6 deletions FAQ.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#FAQ


* ### How do I build the plugin from source

This project is built with Maven
Use : `mvn clean package`

* ### Can I use this plugin on SonarCloud ?

SonarCloud is a little different to SonarQube in that it doesn’t currently provide the ability to add third-party plugins like `Sonar rust`.
SonarCloud is a little different to SonarQube in that it doesn’t currently provide the ability to add third-party
plugins like `Community rust`.

* ### Can I use this plugin on SonarLint ?

Expand All @@ -20,7 +20,8 @@ You don't. The (free) Community edition v7.9+ is compatible (and so are Commerci

* ### Can I scan my Rust source code from a CI/CD pipeline ? Can I get Pull Requests decoration ?

There is nothing specific for this plugin. Any CI pipeline which allows a SonarQube analysis can trigger an analysis on a Rust project
There is nothing specific for this plugin. Any CI pipeline which allows a SonarQube analysis can trigger an analysis on
a Rust project
The only requirement is that the `Community Rust` plugin is installed on your SonarQube instance

* ### Does this Community Rust plugin provide a built-in Quality Profile ?
Expand All @@ -33,14 +34,16 @@ Yes, the issues on other languages will be detected by their respective language

* ### How do I reach out for issues, feature requests or questions not listed here ?

- Issues / Feature requests specific to this plugin can be tracked after you [create a Github issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-issues/creating-an-issue)
- Issues that are related to SonarQube behaviour should be reported in their [Community forum](https://community.sonarsource.com/)
- Issues / Feature requests specific to this plugin can be tracked after
you [create a Github issue](https://docs.github.com/en/issues/tracking-your-work-with-issues/creating-issues/creating-an-issue)
- Issues that are related to SonarQube behaviour should be reported in
their [Community forum](https://community.sonarsource.com/)
- Private material (like source files failing to be parsed) can be sent at community-rust@pm.me


* ### How can I contribute to improving/fixing this plugin ?

We would love to have more contributors.
We would love to have more contributors.
Please read this nice [article](https://gist.github.com/MarcDiethelm/7303312) to get ideas how you can help


Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
| | |
| --- | --- |
| [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=elegoff_sonar-rust&metric=alert_status)](https://sonarcloud.io/dashboard?id=elegoff_sonar-rust) | ![Coverage](https://sonarcloud.io/api/project_badges/measure?project=elegoff_sonar-rust&metric=coverage) |
| [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)|[Download latest release](https://github.com/elegoff/sonar-rust/releases) |
| | |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
| [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=elegoff_sonar-rust&metric=alert_status)](https://sonarcloud.io/dashboard?id=elegoff_sonar-rust) | ![Coverage](https://sonarcloud.io/api/project_badges/measure?project=elegoff_sonar-rust&metric=coverage) |
| [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) | [Download latest release](https://github.com/elegoff/sonar-rust/releases) |

## SonarQube plugin for Rust (Community)

The plugin enables analysis of Rust language within [SonarQube](https://www.sonarqube.org), which is an open platform to
manage code quality.
manage code quality.

### Compatibility with SonarQube versions :

|SonarQube | Rust plugin |
|----------|--------------|
| > 9.9 LTS| not tested |
| 9.9 LTS | 0.2.1 |
| 8.9 - 9.9| 0.1.0 |
| <8.9 | not supported|
| SonarQube | Rust plugin |
|-----------|---------------|
| > 9.9 LTS | not tested |
| 9.9 LTS | 0.2.1 |
| 8.9 - 9.9 | 0.1.0 |
| <8.9 | not supported |

It leverages [Clippy lints](https://rust-lang.github.io/rust-clippy/master/) to raise issues against coding
rules, [LCOV](https://wiki.documentfoundation.org/Development/Lcov)
Expand Down
12 changes: 6 additions & 6 deletions community-rust-checks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<artifactId>community-rust-frontend</artifactId>
<version>${project.version}</version>
</dependency>
<!-- provided by SonarQube -->
<dependency>
<!-- provided by SonarQube -->
<dependency>
<groupId>org.sonarsource.api.plugin</groupId>
<artifactId>sonar-plugin-api</artifactId>
<scope>provided</scope>
Expand All @@ -37,10 +37,10 @@
<artifactId>sonar-analyzer-test-commons</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@

import com.sonar.sslr.api.AstNode;
import com.sonar.sslr.api.AstNodeType;
import java.util.Collections;
import java.util.Set;
import org.sonar.check.Rule;
import org.sonar.check.RuleProperty;
import org.sonar.rust.RustGrammar;

import java.util.Collections;
import java.util.Set;

@Rule(key = "FunctionParametersCount")
public class FunctionParametersCountCheck extends RustCheck {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
*/
package org.elegoff.rust.checks;

import org.junit.Test;
import org.junit.jupiter.api.Test;


import static org.assertj.core.api.Assertions.assertThat;

public class CheckListTest {
class CheckListTest {

@Test
public void testSize() {
void testSize() {
assertThat(CheckList.getRustChecks()).hasSize(3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
*/
package org.elegoff.rust.checks;

import org.junit.Test;

import java.io.File;
import org.junit.jupiter.api.Test;

public class EmptyEnumCheckTest {
class EmptyEnumCheckTest {

@Test
public void test() {
RustCheckVerifier.verify(new File("src/test/resources/checks/empty_enum.rs"), new EmptyEnumCheck());
}
@Test
void test() {
RustCheckVerifier.verify(new File("src/test/resources/checks/empty_enum.rs"), new EmptyEnumCheck());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@
*/
package org.elegoff.rust.checks;

import org.junit.Test;

import java.io.File;
import org.junit.jupiter.api.Test;

public class FunctionParametersCountCheckTest {
@Test
public void test() {
RustCheckVerifier.verify(new File("src/test/resources/checks/function_params_count.rs"), new FunctionParametersCountCheck());
}
class FunctionParametersCountCheckTest {
@Test
void test() {
RustCheckVerifier.verify(new File("src/test/resources/checks/function_params_count.rs"), new FunctionParametersCountCheck());
}

@Test
public void custom() {
FunctionParametersCountCheck check = new FunctionParametersCountCheck();
check.maximumParameterCount = 10;
@Test
void custom() {
FunctionParametersCountCheck check = new FunctionParametersCountCheck();
check.maximumParameterCount = 10;

RustCheckVerifier.verifyNoIssueIgnoringExpected(new File("src/test/resources/checks/function_params_count.rs"), check);
}
RustCheckVerifier.verifyNoIssueIgnoringExpected(new File("src/test/resources/checks/function_params_count.rs"), check);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
*/
package org.elegoff.rust.checks;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.File;

public class LineLengthCheckTest {
@Test
public void test() {
RustCheckVerifier.verify(new File("src/test/resources/checks/line_length.rs"), new LineLengthCheck());
}
class LineLengthCheckTest {
@Test
void test() {
RustCheckVerifier.verify(new File("src/test/resources/checks/line_length.rs"), new LineLengthCheck());
}

@Test
public void custom() {
LineLengthCheck check = new LineLengthCheck();
check.maximumLineLength = 119;
RustCheckVerifier.verify(new File("src/test/resources/checks/line_length_119.rs"), check);
}
@Test
void custom() {
LineLengthCheck check = new LineLengthCheck();
check.maximumLineLength = 119;
RustCheckVerifier.verify(new File("src/test/resources/checks/line_length_119.rs"), check);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@
import org.sonarsource.analyzer.commons.checks.verifier.SingleFileVerifier;

public class RustCheckVerifier {
public static void verify(File file, RustCheck check) {
static void verify(File file, RustCheck check) {
createVerifier(file, check, true, Integer.MAX_VALUE).assertOneOrMoreIssues();
}

public static void verifyWithMarginRight(File file, RustCheck check, int marginRight) {
static void verifyWithMarginRight(File file, RustCheck check, int marginRight) {
createVerifier(file, check, true, marginRight).assertOneOrMoreIssues();
}

public static void verifyNoIssue(File file, RustCheck check) {
static void verifyNoIssue(File file, RustCheck check) {
createVerifier(file, check, true, Integer.MAX_VALUE).assertNoIssues();
}

public static void verifyNoIssueIgnoringExpected(File file, RustCheck check) {
static void verifyNoIssueIgnoringExpected(File file, RustCheck check) {
createVerifier(file, check, false, Integer.MAX_VALUE).assertNoIssues();
}

Expand Down
12 changes: 8 additions & 4 deletions community-rust-frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
<groupId>org.sonarsource.sslr</groupId>
<artifactId>sslr-core</artifactId>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>


<!-- provided by SonarQube -->
<dependency>
<!-- provided by SonarQube -->
<dependency>
<groupId>org.sonarsource.api.plugin</groupId>
<artifactId>sonar-plugin-api</artifactId>
<scope>provided</scope>
Expand All @@ -41,7 +45,7 @@
</dependency>
<dependency>
<!-- packaged with the plugin -->
<groupId>commons-lang</groupId>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1912,8 +1912,8 @@ public static void lexicalpath(LexerlessGrammarBuilder b) {
b.sequence(SPC, RustPunctuator.PATHSEP, SPC, GENERIC_ARGS),
b.sequence(SPC, RustPunctuator.PATHSEP, SPC, TYPE_PATH_FN))));
b.rule(TYPE_PATH_FN).is(
"(",SPC,
b.optional(TYPE_PATH_FN_INPUTS),SPC,
"(", SPC,
b.optional(TYPE_PATH_FN_INPUTS), SPC,
")",
b.optional(b.sequence(SPC, RustPunctuator.RARROW, SPC, TYPE)));
b.rule(TYPE_PATH_FN_INPUTS).is(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public enum RustKeyword implements GrammarRuleKey {

/**
* keywords as String.
*
* @return an array containing all keywords as typed in Java
*/
public static String[] keywordValues() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@
import com.sonar.sslr.api.AstNode;
import com.sonar.sslr.api.Token;
import com.sonar.sslr.impl.ast.AstXmlPrinter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.sslr.parser.LexerlessGrammar;
import org.sonar.sslr.parser.ParserAdapter;
import org.sonar.sslr.tests.Assertions;

import java.nio.charset.StandardCharsets;
import java.util.List;


import static org.assertj.core.api.Assertions.assertThat;

public class RustLexerTest {
class RustLexerTest {
@Test
public void testSize() {
void testSize() {
assertThat(lex("")).hasSize(1);
assertThat(lex(" ")).hasSize(1);
assertThat(lex("foo")).hasSize(2);
Expand All @@ -53,7 +54,7 @@ private List<Token> lex(String source) {
}

@Test
public void testTokens() {
void testTokens() {
Assertions.assertThat(RustLexer.create().build().rule(RustLexer.TOKENS))
.matches("")
.matches("fn")
Expand All @@ -66,7 +67,7 @@ public void testTokens() {
}

@Test
public void testParsing() {
void testParsing() {
String sexpr = "fn update_rates(\n" +
" rates: BoundedVec<(T::Symbol, u64), T::MaxRelaySymbols>,\n" +
" resolve_time: u64,\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.sonar.rust.RustFile;
import org.sonar.rust.RustGrammar;
import org.sonar.rust.RustVisitorContext;
import org.sonar.sslr.parser.LexerlessGrammar;
import org.sonar.sslr.parser.ParserAdapter;

import static org.assertj.core.api.Assertions.assertThat;

public class LinesOfCodeVisitorTest {
import static org.assertj.core.api.Assertions.assertThat;

class LinesOfCodeVisitorTest {

@Test
public void testVisit() {
void testVisit() {

ParserAdapter<LexerlessGrammar> parser = new ParserAdapter<>(StandardCharsets.UTF_8, RustGrammar.create().build());
AstNode rootNode = parser.parse("");
Expand Down Expand Up @@ -65,7 +65,6 @@ public URI uri() {

assertThat(lines).isEmpty();


}

}
Loading