Create Pattern Rules


7. Build an error

Building an error is achieved with the function buildError. There is the function signature:

1buildError(startLine, startCol, endLine, endCol, message, severity, category)

The function takes the following parameters:

  1. startLine: the line where the violation starts.
  2. startCol: the column where the violation starts.
  3. endLine: the line where the violation ends.
  4. endCol: the column where the violation ends.
  5. message: the message to show in the IDE/Pull Request.
  6. severity: severity of the error (will impact how the violation is shown in the IDE). Correct values are critical, error, warning and info.
  7. category: the category of the error. Correct values are error_prone, security, safety, best_practices, code_style, design and deployment.

Our violation reports an error with the message do not assert on foo right where the name foo appears. It is an informational message in the category BEST_PRACTICES. We use the code on the right to build the error.

1const error = buildError(
2  exceptionName.start.line,
3  exceptionName.start.col,
4  exceptionName.end.line,
5  exceptionName.end.col,
6  "do not assert on foo",
7  "INFO", 

Let's go!

Start interacting with the tutorial!


Codiga Logo
Codiga Hub
  • Rulesets
  • Playground
  • Snippets
  • Cookbooks
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.