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:
- startLine: the line where the violation starts.
- startCol: the column where the violation starts.
- endLine: the line where the violation ends.
- endCol: the column where the violation ends.
- message: the message to show in the IDE/Pull Request.
- severity: severity of the error (will impact how the violation is shown in the IDE). Correct values are critical, error, warning and info.
- category: the category of the error. Correct values are error_prone, security, safety, best_practices, code_style, design and deployment.
The function buildError is a built-in function in Rosie.
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",
8 "BEST_PRACTICES"
9);
Let's go!
Start interacting with the tutorial!
my-new-rule.js