Skip to content

Commit

Permalink
Merge pull request #82 from conneroisu/devit
Browse files Browse the repository at this point in the history
devit
  • Loading branch information
conneroisu authored Jul 31, 2024
2 parents 7072e6d + e8f10e3 commit 66f9df4
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 16 deletions.
9 changes: 6 additions & 3 deletions tools/seltabls/cmd/cmds/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ var (
)

// NewStaticCmd createa a new command for the static command.
func NewStaticCmd(ctx context.Context) *cobra.Command {
func NewStaticCmd(_ context.Context) *cobra.Command {
return &cobra.Command{
Use: "static",
Short: "Statically define html given a url.",
Long: `
Statically define html given a url.
`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
cmd.PersistentFlags().StringVarP(
&uuri,
"url",
Expand Down Expand Up @@ -178,7 +178,10 @@ func getURLFileName(fileURL string) (string, error) {

// Check for a successful response status
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("received non-200 response code: %d", resp.StatusCode)
return "", fmt.Errorf(
"received non-200 response code: %d",
resp.StatusCode,
)
}

body, err := io.ReadAll(resp.Body)
Expand Down
2 changes: 1 addition & 1 deletion tools/seltabls/cmd/cmds/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func NewVersionCmd() *cobra.Command {
Use: "version",
Short: "Print the version number of the seltabls command",
Long: `All software has versions. This is seltabls's`,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
cmd.Println("seltabls version 0.1.0.5.0.0-beta1.final")
},
}
Expand Down
6 changes: 3 additions & 3 deletions tools/seltabls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func main() {
// @ignore: script, style, link, img, footer, header
// @occurrences: 2
type TableStruct struct {
A string `hSel:"html>body>div>table>tbody>tr.row_even" dSel:"html>body>div.footer>div>span>a[href]" ctl:"$text"`
A string `hSel:"html>body>div>table>tbody>tr.row_even" dSel:"html>body>div.footer>div>span>a[href]" ctl:"$text"`
B string `hSel:"" dSel:"html>body>div>table>tbody>tr.row_odd" ctl:"$text"`
C string `hSel:"html>head>link[href]" dSel:"html>body>div" ctl:"$text"`
D string `hSel:"" dSel:"html>body>div.footer>div>span>a[href]" ctl:"$text"`
C string `hSel:"html>head>link[href]" dSel:"html>body>div" ctl:"$text"`
D string `hSel:"" dSel:"html>body>div.footer>div>span>a[href]" ctl:"$text"`
E string `hSel:"" dSel:"htmle>body>div.footer>div>span>a[href]" ctl:"$text"`
}
24 changes: 20 additions & 4 deletions tools/seltabls/pkg/analysis/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,22 @@ func GetSelectorHover(
position,
fset,
)
log.Debugf("calling IsPositionInNode: %v time: %s\n", inPosition, time.Since(start))
log.Debugf(
"calling IsPositionInNode: %v time: %s\n",
inPosition,
time.Since(start),
)
// Check if the position is within a struct tag
inTag := parsers.IsPositionInTag(
structNodes[i],
position,
fset,
)
log.Debugf("calling IsPositionInTag: %v time: %s\n", inTag, time.Since(start))
log.Debugf(
"calling IsPositionInTag: %v time: %s\n",
inTag,
time.Since(start),
)
if !inPosition && !inTag {
return
}
Expand All @@ -138,7 +146,12 @@ func GetSelectorHover(
fset,
text,
)
log.Debugf("calling PositionInStructTagValue: %v value: %v time: %s\n", inValue, val, time.Since(start))
log.Debugf(
"calling PositionInStructTagValue: %v value: %v time: %s\n",
inValue,
val,
time.Since(start),
)
var HTMLs []string
found := doc.Find(val)
HTMLs = make([]string, found.Length())
Expand All @@ -147,7 +160,10 @@ func GetSelectorHover(
eg.Go(func() error {
HTML, err := s.Parent().Html()
if err != nil {
return fmt.Errorf("failed to get html: %w", err)
return fmt.Errorf(
"failed to get html: %w",
err,
)
}
HTMLs[i] = fmt.Sprintf(
"%d:\n%s",
Expand Down
8 changes: 6 additions & 2 deletions tools/seltabls/pkg/parsers/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func ValidatePackageName(name string) error {
// Check the rest of the characters
for _, ch := range name[1:] {
if !unicode.IsLetter(ch) && !unicode.IsDigit(ch) && ch != '_' {
return fmt.Errorf("package name must only contain letters, digits, and underscores")
return fmt.Errorf(
"package name must only contain letters, digits, and underscores",
)
}
}

Expand Down Expand Up @@ -57,7 +59,9 @@ func ValidateFileName(name string) error {
// Check the rest of the characters
for _, ch := range name[1:] {
if !unicode.IsLetter(ch) && !unicode.IsDigit(ch) && ch != '_' {
return fmt.Errorf("file name must only contain letters, digits, and underscores")
return fmt.Errorf(
"file name must only contain letters, digits, and underscores",
)
}
}
return nil
Expand Down
4 changes: 3 additions & 1 deletion tools/seltabls/pkg/parsers/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ func PositionInStructTagValue(
split := strings.Split(*text, "\n")
line := split[pos.Line]
if strings.Contains(line, "@url:") {
if urlMatches := urlPattern.FindStringSubmatch(line); len(urlMatches) > 1 {
if urlMatches := urlPattern.FindStringSubmatch(line); len(
urlMatches,
) > 1 {
return urlMatches[1], false
}
}
Expand Down
9 changes: 7 additions & 2 deletions tools/seltabls/pkg/parsers/selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func getSelectorsFromSelection(s *goquery.Selection) string {
// Get the selector for the current node
currentSelector := singleSelector(s)
// Combine the parent and current selectors
if parentSelector != empty && currentSelector != "" && parentSelector != currentSelector {
if parentSelector != empty && currentSelector != "" &&
parentSelector != currentSelector {
return parentSelector + childsep + currentSelector
} else if parentSelector != empty && currentSelector == "" {
return parentSelector
Expand Down Expand Up @@ -199,7 +200,11 @@ func singleSelector(selection *goquery.Selection) string {
}
attr, exists = selection.Attr("src")
if exists {
selector = fmt.Sprintf("%s[src='%s']", goquery.NodeName(selection), attr)
selector = fmt.Sprintf(
"%s[src='%s']",
goquery.NodeName(selection),
attr,
)
}
_, exists = selection.Attr("href")
if exists {
Expand Down

0 comments on commit 66f9df4

Please sign in to comment.