Skip to content

Commit

Permalink
Improve linter documentation (#1650)
Browse files Browse the repository at this point in the history
This PR doesn't change any code. It adds a new docstring to improve the
experience of a contributor adding a new lint.

It also fixes an error in the crate-level documentation.
  • Loading branch information
orpuente-MS authored Jun 19, 2024
1 parent ae1ff32 commit a064c88
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/qsc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//! ```
//! declare_ast_lints!{
//! ...
//! (DoubleParens, LintLevel::Warn, "unnecesary double parentheses"),
//! (DoubleParens, LintLevel::Warn, "unnecessary parentheses", "remove the extra parentheses for clarity"),
//! }
//! ```
//!
Expand All @@ -52,7 +52,7 @@
//! if let ExprKind::Paren(ref inner_expr) = *expr.kind {
//! if matches!(*inner_expr.kind, ExprKind::Paren(_)) {
//! // we push the lint to the buffer
//! push_lint!(Self, expr.span, buffer);
//! buffer.push(lint!(self, child.span))
//! }
//! }
//! }
Expand Down
17 changes: 17 additions & 0 deletions compiler/qsc_linter/src/lints/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ use crate::linter::ast::declare_ast_lints;
use qsc_ast::ast::{BinOp, ExprKind, Lit, StmtKind};
use qsc_data_structures::span::Span;

// Read Me:
// To add a new lint add a new tuple to this structure. The tuple has four elements:
// `(lint_name, default_lint_level, message, help)`
//
// where:
// lint_name: Name of the lint.
// default_lint_level: Default level for the lint, can be overriden by the user in qsharp.json.
// message: Message shown in the editor when hovering over the squiggle generated by the lint.
// help: A user friendly message explaining how to fix the lint.
//
// Then, add an `impl lint_name` block adding the lint logic.
//
// After adding a lint you need to go language_service/code_action.rs and add a Quickfix
// for the newly added lint (or opt out of the Quickfix) in the match statement in that file.
//
// For more details on how to add a lint, please refer to the crate-level documentation
// in qsc_linter/lib.rs.
declare_ast_lints! {
(DivisionByZero, LintLevel::Error, "attempt to divide by zero", "division by zero will fail at runtime"),
(NeedlessParens, LintLevel::Allow, "unnecessary parentheses", "remove the extra parentheses for clarity"),
Expand Down
17 changes: 17 additions & 0 deletions compiler/qsc_linter/src/lints/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ use crate::linter::hir::declare_hir_lints;

use super::lint;

// Read Me:
// To add a new lint add a new tuple to this structure. The tuple has four elements:
// `(lint_name, default_lint_level, message, help)`
//
// where:
// lint_name: Name of the lint.
// default_lint_level: Default level for the lint, can be overriden by the user in qsharp.json.
// message: Message shown in the editor when hovering over the squiggle generated by the lint.
// help: A user friendly message explaining how to fix the lint.
//
// Then, add an `impl lint_name` block adding the lint logic.
//
// After adding a lint you need to go language_service/code_action.rs and add a Quickfix
// for the newly added lint (or opt out of the Quickfix) in the match statement in that file.
//
// For more details on how to add a lint, please refer to the crate-level documentation
// in qsc_linter/lib.rs.
declare_hir_lints! {
(NeedlessOperation, LintLevel::Allow, "operation does not contain any quantum operations", "this callable can be declared as a function instead")
}
Expand Down

0 comments on commit a064c88

Please sign in to comment.