Skip to content

Commit

Permalink
feat: Add lint rule for bad forward decls
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src committed Nov 3, 2023
1 parent c20ea0a commit 1d4fc50
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/scip/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ func (st *symbolTable) addOccurrence(path string, occ *scip.Occurrence) error {
if occ.Symbol == "" {
return emptyStringError{what: "symbol", context: fmt.Sprintf("occurrence at %s @ %s", path, scipRangeToString(*scip.NewRange(occ.Range)))}
}
if scip.SymbolRole_Definition.Matches(occ) && scip.SymbolRole_ForwardDeclaration.Matches(occ) {
return forwardDeclIsDefinitionError{occ.Symbol, path, *scip.NewRange(occ.Range)}
}
tryInsertOccurrence := func(occMap fileOccurrenceMap) error {
occKey := scipOccurrenceKey(occ)
if fileOccs, ok := occMap[path]; ok {
Expand Down Expand Up @@ -327,6 +330,17 @@ func (e missingSymbolForOccurrenceError) Error() string {
" in external symbols or any document", e.path, scipRangeToString(e.occ), e.symbol)
}

type forwardDeclIsDefinitionError struct {
symbol string
path string
range_ scip.Range
}

func (e forwardDeclIsDefinitionError) Error() string {
return fmt.Sprintf("error: forward declaration for %v at %v @ %v was marked as definition",
e.symbol, e.path, scipRangeToString(e.range_))
}

type duplicateOccurrenceWarning struct {
symbol string
path string
Expand Down

0 comments on commit 1d4fc50

Please sign in to comment.