clerk/internal/linter/rules.go (view raw)
| 1 | package linter |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | |
| 6 | "olexsmir.xyz/clerk/internal/analyzer" |
| 7 | ) |
| 8 | |
| 9 | type RuleID string |
| 10 | |
| 11 | // Rule is the best interface that every rule must implement. |
| 12 | type Rule interface { |
| 13 | ID() RuleID |
| 14 | CheckJournal(an *analyzer.Analysis) []Find |
| 15 | } |
| 16 | |
| 17 | type RuleConfig struct { |
| 18 | // Disabled turns the rule off entirely. |
| 19 | Disabled bool |
| 20 | |
| 21 | // Severity overrides the rule's default severity level. |
| 22 | Severity Severity // [SeverityNone] if [Disabled] is true |
| 23 | |
| 24 | // Options holds JSON-encoded options, already validated against the rule. |
| 25 | Options json.RawMessage // TODO: check if there's better options than json |
| 26 | } |
| 27 | |
| 28 | type RuleOptioner interface { |
| 29 | UnmarshalOptions(data json.RawMessage) error |
| 30 | Clone() Rule |
| 31 | } |
| 32 | |
| 33 | type builtinRule struct { |
| 34 | Rule Rule |
| 35 | Severity Severity |
| 36 | } |
| 37 | |
| 38 | // Rules maps every rule ID to its implementation and default severity. |
| 39 | var Rules = map[RuleID]builtinRule{ |
| 40 | AccountDepthLimitID: {&AccountDepthLimit{MaxDepth: 4}, SeverityWarning}, |
| 41 | DuplicatedAccountID: {&DuplicatedAccount{}, SeverityWarning}, |
| 42 | DuplicatedCommodityID: {&DuplicatedCommodity{}, SeverityWarning}, |
| 43 | DuplicatedTagID: {&DuplicatedTag{}, SeverityWarning}, |
| 44 | DuplicatedTransactionID: {&DuplicatedTransaction{}, SeverityWarning}, |
| 45 | EmptyPostingsID: {&EmptyPostings{}, SeverityError}, |
| 46 | InvalidDateTagID: {&InvalidDateTag{}, SeverityError}, |
| 47 | InvalidIncludeID: {&InvalidInclude{}, SeverityError}, |
| 48 | InvalidTypeTagID: {&InvalidTypeTag{}, SeverityError}, |
| 49 | MissingCommodityID: {&MissingCommodity{}, SeverityWarning}, |
| 50 | MissingPayeeID: {&MissingPayee{}, SeverityWarning}, |
| 51 | MissingStatusID: {&MissingStatus{}, SeverityWarning}, |
| 52 | MultipleOmittedAmountsID: {&MultipleOmittedAmounts{}, SeverityError}, |
| 53 | OmittedPrecisionID: {&OmittedPrecision{}, SeverityWarning}, |
| 54 | OrderDateID: {&OrderDate{}, SeverityWarning}, |
| 55 | ParseErrorID: {&ParseError{}, SeverityError}, |
| 56 | UnbalancedTransactionID: {&UnbalancedTransaction{}, SeverityError}, |
| 57 | UndeclaredAccountID: {&UndeclaredAccount{}, SeverityWarning}, |
| 58 | UndeclaredCommodityID: {&UndeclaredCommodity{}, SeverityWarning}, |
| 59 | UndeclaredPayeeID: {&UndeclaredPayee{}, severityNone}, |
| 60 | UndeclaredTagID: {&UndeclaredTag{}, severityNone}, |
| 61 | UnusedAccountID: {&UnusedAccount{}, SeverityWarning}, |
| 62 | UnusedTagID: {&UnusedTag{}, SeverityWarning}, |
| 63 | } |