Package org.sonar.squidbridge.api

Examples of org.sonar.squidbridge.api.SourceFile


  @Test
  public void test() {
    RedeclaredFunctionCheck check = new RedeclaredFunctionCheck();

    SourceFile file = JavaScriptAstScanner.scanSingleFile(new File("src/test/resources/checks/redeclaredFunction.js"), check);
    CheckMessagesVerifier.verify(file.getCheckMessages())
        .next().atLine(11).withMessage("Rename function \"fun\" as this name is already used.")
        .next().atLine(24).withMessage("Rename function \"inner\" as this name is already used.")
        .noMore();
  }
View Full Code Here


  @Test
  public void test() {
    VariableDeclarationAfterUsageCheck check = new VariableDeclarationAfterUsageCheck();

    SourceFile file = JavaScriptAstScanner.scanSingleFile(new File("src/test/resources/checks/variableDeclarationAfterUsageCheck.js"), check);
    CheckMessagesVerifier.verify(file.getCheckMessages())
        .next().atLine(5).withMessage("Variable 'x' referenced before declaration.")
        .next().atLine(9)
        .next().atLine(14)
        .next().atLine(18)
        .next().atLine(21)
View Full Code Here

public class ForHidingWhileCheckTest {

  private ForHidingWhileCheck check = new ForHidingWhileCheck();
  @Test
  public void test() {
    SourceFile file = JavaScriptAstScanner.scanSingleFile(new File("src/test/resources/checks/forHidingWhile.js"), check);
    CheckMessagesVerifier.verify(file.getCheckMessages())
      .next().atLine(1)
      .next().atLine(4)
      .noMore();
  }
View Full Code Here

  @Test
  public void test() {
    NamedFunctionExpressionCheck check = new NamedFunctionExpressionCheck();

    SourceFile file = JavaScriptAstScanner.scanSingleFile(new File("src/test/resources/checks/namedFunctionExpression.js"), check);
    CheckMessagesVerifier.verify(file.getCheckMessages())
        .next().atLine(1).withMessage("Make this function anonymous by removing its name: 'function() {...}'.")
        .next().atLine(2)
        .next().atLine(3)
        .noMore();
  }
View Full Code Here

  @Test
  public void test() {
    LabelPlacementCheck check = new LabelPlacementCheck();

    SourceFile file = JavaScriptAstScanner.scanSingleFile(new File("src/test/resources/checks/labelPlacement.js"), check);
    CheckMessagesVerifier.verify(file.getCheckMessages())
        .next().atLine(3).withMessage("Remove this \"label\" label.")
        .noMore();
  }
View Full Code Here

  private TooManyLinesInFunctionCheck check = new TooManyLinesInFunctionCheck();

  @Test
  public void testDefault() {
    SourceFile file = JavaScriptAstScanner.scanSingleFile(new File("src/test/resources/checks/tooManyLinesInFunction.js"), check);
    CheckMessagesVerifier.verify(file.getCheckMessages())
      .noMore();
  }
View Full Code Here

  }

  @Test
  public void testCustom() {
    check.max = 3;
    SourceFile file = JavaScriptAstScanner.scanSingleFile(new File("src/test/resources/checks/tooManyLinesInFunction.js"), check);
    CheckMessagesVerifier.verify(file.getCheckMessages())
      .next().atLine(1).withMessage("This function has 6 lines, which is greater than the " + check.max + " lines authorized. Split it into smaller functions.")
      .next().atLine(2).withMessage("This function has 4 lines, which is greater than the " + check.max + " lines authorized. Split it into smaller functions.")
      .next().atLine(8)
      .next().atLine(13)
      .next().atLine(20)
View Full Code Here

  @Test
  public void test() {
    EvalCheck check = new EvalCheck();

    SourceFile file = JavaScriptAstScanner.scanSingleFile(new File("src/test/resources/checks/eval.js"), check);
    CheckMessagesVerifier.verify(file.getCheckMessages())
        .next().atLine(2).withMessage("Remove this use of the \"eval\" function.")
        .next().atLine(5)
        .noMore();
  }
View Full Code Here

  @Test
  public void test() {
    UnusedVariableCheck check = new UnusedVariableCheck();

    SourceFile file = JavaScriptAstScanner.scanSingleFile(new File("src/test/resources/checks/unusedVariable.js"), check);
    CheckMessagesVerifier.verify(file.getCheckMessages())
        .next().atLine(4).withMessage("Remove the declaration of the unused 'a' variable.")
        .next().atLine(17)
        .next().atLine(24)
        .next().atLine(25)
        .next().atLine(31)
View Full Code Here

    assertThat(project.getInt(EcmaScriptMetric.FILES)).isEqualTo(2);
  }

  @Test
  public void comments() {
    SourceFile file = JavaScriptAstScanner.scanSingleFile(new File("src/test/resources/metrics/comments.js"));
    assertThat(file.getInt(EcmaScriptMetric.COMMENT_LINES)).isEqualTo(3);
    assertThat(file.getNoSonarTagLines()).contains(10);
    assertThat(file.getNoSonarTagLines().size()).isEqualTo(1);
  }
View Full Code Here

TOP

Related Classes of org.sonar.squidbridge.api.SourceFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.