src/linter/LintRule.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include <string_view> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include <linter/LintFinding.h> | ||
| 9 | |||
| 10 | namespace spice::compiler { | ||
| 11 | |||
| 12 | // Forward declarations | ||
| 13 | class FctDefNode; | ||
| 14 | class ProcDefNode; | ||
| 15 | class StructDefNode; | ||
| 16 | class InterfaceDefNode; | ||
| 17 | class GlobalVarDefNode; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Base class for a single lint rule. | ||
| 21 | * | ||
| 22 | * A rule overrides only the check hooks for the node kinds it cares about; LintPass drives the | ||
| 23 | * AST traversal once and calls into every registered rule from the matching visit method, so | ||
| 24 | * adding a new rule never requires touching the traversal itself. See linter/rules/ for concrete | ||
| 25 | * rules and linter/LintPass.h for how rules get registered and dispatched. | ||
| 26 | */ | ||
| 27 | class LintRule { | ||
| 28 | public: | ||
| 29 | 9 | virtual ~LintRule() = default; | |
| 30 | |||
| 31 | // Rule identity | ||
| 32 | [[nodiscard]] constexpr virtual std::string_view id() const = 0; | ||
| 33 | |||
| 34 | // Check hooks. Default to no-op; override only the ones relevant for this rule. | ||
| 35 | ✗ | virtual void checkFctDef(FctDefNode *node, std::vector<LintFinding> &findings) {} | |
| 36 | ✗ | virtual void checkProcDef(ProcDefNode *node, std::vector<LintFinding> &findings) {} | |
| 37 | 4 | virtual void checkStructDef(StructDefNode *node, std::vector<LintFinding> &findings) {} | |
| 38 | ✗ | virtual void checkInterfaceDef(InterfaceDefNode *node, std::vector<LintFinding> &findings) {} | |
| 39 | 4 | virtual void checkGlobalVarDef(GlobalVarDefNode *node, std::vector<LintFinding> &findings) {} | |
| 40 | }; | ||
| 41 | |||
| 42 | } // namespace spice::compiler | ||
| 43 |