issue

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

This file provides constants and structures for determining comment syntax in source code files. The constants define file extensions while the CommentNotation struct specifies syntax details for various programming languages. The NewCommentNotation function retrieves the appropriate CommentNotation based on a file extension.

The CommentNotations map contains predefined syntax for common languages such as C, Python, and Markdown, with a default syntax for unrecognized file types. When walking a project directory, the program reads each file extension and uses the CommentNotations map to determine the comment syntax for parsing.

The issue package is responsible for handling pending and processed issues. Issues are objects that describe a task, concern, or area of code that requires attention.

Issues are discovered by parsing each line in a source file. When a file is first opened, we determine the syntax used to denote single and multi line comments by checking the extension of the file. I.E main.c, main.go, main.cpp and so on. This will allow the program to understand what comment symbols to search for.

As we scan each line, we check if the line contains the prefix notation for a single or multi line comment. If it contains a single line comment prefix, we parse and get all text after the prefix and annotation. If an issue annotation was located, it qualifies as an issue and we will be appended as a new issue object onto an issues slice.

In the case locating of a multi line comment prefix, we will continue to scan subsequent lines until reaching the multi line comment suffix. At that point, we will do the same check for the single line comment and check that an issue annotation was located and push onto the issues slice if it contained the annotation.

There are two types of issues, pending and processed. Pending issues are those that have not yet been uploaded to a source code management platform. Processed issues are issues that have been uploaded to a source code management platform and will have a unique id number associated with the issue annotation.

See the issue_test.go file for examples.

Index

Constants

View Source
const (
	PENDING_ISSUE   = "pending"
	PROCESSED_ISSUE = "processed"
)

Variables

View Source
var CommentNotations = map[string]CommentNotation{

	"default": {
		SingleLinePrefix: `#`,
	},
	// contains filtered or unexported fields
}

Functions

func PrintTagResults

func PrintTagResults(issues []Issue, keyStyle, valStyle lipgloss.Style)

Types

type CommentNotation

type CommentNotation struct {
	Annotation          string
	AnnotationIndicator bool
	SingleLinePrefix    string
	SingleLinePrefixRe  *regexp.Regexp
	SingleLineSuffix    string
	SingleLineSuffixRe  *regexp.Regexp
	MultiLinePrefix     string
	MultiLinePrefixRe   *regexp.Regexp
	MultiLineSuffix     string
	MultiLineSuffixRe   *regexp.Regexp
	NewLinePrefix       string
	Scanner             *bufio.Scanner
	Stack               NotationStack
}

func NewCommentNotation

func NewCommentNotation(ext string, annotation string, scanner *bufio.Scanner) CommentNotation

func (*CommentNotation) BuildMulti

func (c *CommentNotation) BuildMulti(fields []string, is *Issue, start int, n *uint64) error

func (*CommentNotation) BuildSingle

func (c *CommentNotation) BuildSingle(fields []string, is *Issue, start int, n *uint64) error

func (*CommentNotation) ExtractFromMulti

func (c *CommentNotation) ExtractFromMulti(fields []string, start int) (string, error)

func (*CommentNotation) ExtractFromSingle

func (c *CommentNotation) ExtractFromSingle(fields []string, start int) (string, error)

func (*CommentNotation) FindPrefixIndex

func (c *CommentNotation) FindPrefixIndex(fields []string) int

func (*CommentNotation) ParseLine

func (c *CommentNotation) ParseLine(n *uint64) (Issue, error)

type Issue

type Issue struct {
	ID                   string
	Title                string
	Description          string
	FilePath             string
	StartLineNumber      uint64
	EndLineNumber        uint64
	AnnotationLineNumber uint64
}

type IssueManager

type IssueManager interface {
	GetIssues() []Issue
	Scan(r io.Reader, path string) error
	Walk(root string, ignore []regexp.Regexp) (int, error)
}

func NewIssueManager

func NewIssueManager(issueType string, annotation string) (IssueManager, error)

NewIssueManager will return either a PendingIssue struct or ProcessedIssue struct that satisfies the methods defined in the IssueManager interface. The methods in said interface are used to report new issues an SCM or locate issues that have been reported to an SCM. Each struct will implement methods for walking the project directory and parsing source code files. The main difference is that pending issues can be uploaded to an SCM and processed issues can be resolved and the matching comment in the source code can be removed through it's methods.

type NotationStack

type NotationStack struct {
	Items []string
	Top   int
}

func InitNotationStack

func InitNotationStack() *NotationStack

func (*NotationStack) IsEmpty

func (s *NotationStack) IsEmpty() bool

func (*NotationStack) Peek

func (s *NotationStack) Peek() (string, error)

func (*NotationStack) Pop

func (s *NotationStack) Pop() (string, error)

func (*NotationStack) Push

func (s *NotationStack) Push(notation string)

type PendingIssue

type PendingIssue struct {
	Annotation string
	Issues     []Issue
}

func (*PendingIssue) GetIssues

func (pi *PendingIssue) GetIssues() []Issue

func (*PendingIssue) Scan

func (pi *PendingIssue) Scan(r io.Reader, path string) error

func (*PendingIssue) Walk

func (pi *PendingIssue) Walk(root string, gitIgnore []regexp.Regexp) (int, error)

type ProcessedIssue

type ProcessedIssue struct {
	Annotation string
	Issues     []Issue
}

func (*ProcessedIssue) GetIssues

func (pi *ProcessedIssue) GetIssues() []Issue

func (*ProcessedIssue) Scan

func (pi *ProcessedIssue) Scan(r io.Reader) error

func (*ProcessedIssue) Walk

func (pi *ProcessedIssue) Walk(root string, ignore []regexp.Regexp) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL