Skip to content

Commit

Permalink
bug-fix: enable SuppressWarnings to suppress issues on enhancement pr…
Browse files Browse the repository at this point in the history
…operties (#83)
  • Loading branch information
komasztania authored Jul 10, 2023
1 parent 9eca929 commit 949b2e6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/antlr/GosuParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ classMembers

enhancementMembers
: ((function
| propertySignature functionBody) semicolon?)*
| property) semicolon?)*
;

interfaceMembers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ private Stream<Arguments> getComplexCases() {
.ifs(7)
.switchBlocks(4)
.lambdas(1)
.returns(3)
.methodCalls(24)
.returns(4)
.methodCalls(25)
.atIdentifiers(1)
.uses(2)
.functions(4)
.properties(1)
.build().asArgument()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import de.friday.sonarqube.gosu.plugin.rules.bugs.SameConditionsInIfRule;
import de.friday.sonarqube.gosu.plugin.rules.metrics.CognitiveComplexityRule;
import de.friday.sonarqube.gosu.plugin.rules.metrics.LinesOfCodeRule;
import de.friday.sonarqube.gosu.plugin.rules.smells.MagicNumbersRule;
import de.friday.sonarqube.gosu.plugin.rules.smells.TODOsRule;
import de.friday.sonarqube.gosu.plugin.rules.vulnerabilities.PublicStaticFieldRule;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -108,6 +109,13 @@ void shouldSuppressWarningsOnEnhancements() {
.then().issuesFound().areEmpty();
}

@Test
void shouldSuppressWarningsOnEnhancementsMethods() {
given("SuppressWarningsListener/enhancementSuppressWarnings-methods.gsx")
.whenCheckedAgainst(MagicNumbersRule.class)
.then().issuesFound().areEmpty();
}

@Test
void shouldSuppressWarningsOnCheckWithoutTextRange() {
given("SuppressWarningsListener/lines501.gs")
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/parser/complexCases/SomeEnhancement.gsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,8 @@ enhancement SomeEnhancement : entity.TripExpenseDelegate {
return usedToBeDenied
}

static property get CurrentEffectiveTimedDate(): Date {
return Date.CurrentDate.asEffectiveTimedDate()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package friday.enhancement

uses java.math.BigDecimal

enhancement SampleEnhancement: BigDecimal {

@SuppressWarnings("gosu:MagicNumbersRule")
property get DummyRandomNumber(): BigDecimal {
return BigDecimal.ONE.multiply(345bd)
}

@SuppressWarnings("gosu:MagicNumbersRule")
property set SecondRandomNumber(value: int) {
if (value < 0 or value > 100) {
throw new IllegalArgumentException("Number must be between 0 and 100, as it's a percentage.")
}
var reductionAsDecimal = BigDecimal.valueOf(value).divide(100bd)
}

@SuppressWarnings("gosu:MagicNumbersRule")
function createDummyNumber() {
var no = BigDecimal.ZERO.subtract(-9.5bd)
}

}

0 comments on commit 949b2e6

Please sign in to comment.