mirror of
https://github.com/rwinkhart/go-highlite.git
synced 2026-09-06 00:47:15 -04:00
Fixes based on various linter suggestions
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
- repo: https://github.com/jessp01/pre-commit-golang
|
||||||
|
rev: v0.5.3
|
||||||
|
hooks:
|
||||||
|
- id: go-fmt
|
||||||
|
- id: go-imports
|
||||||
|
- id: go-vet
|
||||||
|
- id: go-lint
|
||||||
|
- id: go-critic
|
||||||
|
- id: go-ineffassign
|
||||||
|
#- id: go-cyclo
|
||||||
+5
-7
@@ -9,7 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/jessp01/gohighlight"
|
highlight "github.com/jessp01/gohighlight"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -20,15 +20,15 @@ func main() {
|
|||||||
|
|
||||||
gopath := os.Getenv("GOPATH")
|
gopath := os.Getenv("GOPATH")
|
||||||
|
|
||||||
var syn_dir string
|
var synDir string
|
||||||
if gopath == "" {
|
if gopath == "" {
|
||||||
syn_dir = os.Getenv("HOME") + "/.config/zaje/syntax_files"
|
synDir = os.Getenv("HOME") + "/.config/zaje/syntax_files"
|
||||||
} else {
|
} else {
|
||||||
syn_dir = gopath + "/src/github.com/jessp01/gohighlight/syntax_files"
|
synDir = gopath + "/src/github.com/jessp01/gohighlight/syntax_files"
|
||||||
}
|
}
|
||||||
|
|
||||||
var defs []*highlight.Def
|
var defs []*highlight.Def
|
||||||
err, warnings := highlight.ParseSyntaxFiles(syn_dir, &defs)
|
warnings, err := highlight.ParseSyntaxFiles(synDir, &defs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -67,8 +67,6 @@ func main() {
|
|||||||
color.Set(color.FgHiBlue)
|
color.Set(color.FgHiBlue)
|
||||||
|
|
||||||
case highlight.Groups["preproc"]:
|
case highlight.Groups["preproc"]:
|
||||||
//fallthrough
|
|
||||||
//case highlight.Groups["high.red"]:
|
|
||||||
color.Set(color.FgHiRed)
|
color.Set(color.FgHiRed)
|
||||||
|
|
||||||
case highlight.Groups["special"]:
|
case highlight.Groups["special"]:
|
||||||
|
|||||||
+6
-7
@@ -7,14 +7,14 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getDefs(t *testing.T, filename string, data []byte, highlight_lexer string) *Def {
|
func getDefs(t *testing.T, filename string, data []byte, highlightLexer string) *Def {
|
||||||
var def *Def
|
var def *Def
|
||||||
syn_dir := "./syntax_files"
|
synDir := "./syntax_files"
|
||||||
|
|
||||||
var defs []*Def
|
var defs []*Def
|
||||||
lerr, warnings := ParseSyntaxFiles(syn_dir, &defs)
|
warnings, lerr := ParseSyntaxFiles(synDir, &defs)
|
||||||
if lerr != nil {
|
if lerr != nil {
|
||||||
t.Errorf("Couldn't get defs from '%s', error: %v\n", syn_dir, lerr)
|
t.Errorf("Couldn't get defs from '%s', error: %v\n", synDir, lerr)
|
||||||
}
|
}
|
||||||
if len(warnings) > 0 {
|
if len(warnings) > 0 {
|
||||||
t.Errorf("Parsing ended with warnings: '%s'\n", strings.Join(warnings, ";"))
|
t.Errorf("Parsing ended with warnings: '%s'\n", strings.Join(warnings, ";"))
|
||||||
@@ -28,8 +28,8 @@ func getDefs(t *testing.T, filename string, data []byte, highlight_lexer string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if a specific lexer was requested by setting the ENV var, try to load it
|
// if a specific lexer was requested by setting the ENV var, try to load it
|
||||||
if highlight_lexer != "" {
|
if highlightLexer != "" {
|
||||||
syntaxFile, lerr := ioutil.ReadFile(syn_dir + "/" + highlight_lexer + ".yaml")
|
syntaxFile, lerr := ioutil.ReadFile(synDir + "/" + highlightLexer + ".yaml")
|
||||||
if lerr == nil {
|
if lerr == nil {
|
||||||
// Parse it into a `*highlight.Def`
|
// Parse it into a `*highlight.Def`
|
||||||
def, _ = ParseDef(syntaxFile)
|
def, _ = ParseDef(syntaxFile)
|
||||||
@@ -40,6 +40,5 @@ func getDefs(t *testing.T, filename string, data []byte, highlight_lexer string)
|
|||||||
t.Errorf("Found no defs for '%s'\n", filename)
|
t.Errorf("Found no defs for '%s'\n", filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println(def)
|
|
||||||
return def
|
return def
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-10
@@ -62,30 +62,29 @@ func NewHighlighter(def *Def) *Highlighter {
|
|||||||
// color's group (represented as one byte)
|
// color's group (represented as one byte)
|
||||||
type LineMatch map[int]Group
|
type LineMatch map[int]Group
|
||||||
|
|
||||||
func ParseSyntaxFiles(dir string, defs *[]*Def) (error, []string) {
|
// ParseSyntaxFiles builds def array from YAML files in dir
|
||||||
|
func ParseSyntaxFiles(dir string, defs *[]*Def) ([]string, error) {
|
||||||
pattern := "*.yaml"
|
pattern := "*.yaml"
|
||||||
files, err := filepath.Glob(dir + "/" + pattern)
|
files, err := filepath.Glob(dir + "/" + pattern)
|
||||||
var warnings []string
|
var warnings []string
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err, nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file_path := range files {
|
for _, filePath := range files {
|
||||||
file, err := ioutil.ReadFile(file_path)
|
file, err := ioutil.ReadFile(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
warnings = append(warnings, file_path+": "+err.Error())
|
warnings = append(warnings, filePath+": "+err.Error())
|
||||||
} else {
|
} else if len(file) > 0 {
|
||||||
if len(file) > 0 {
|
|
||||||
d, err := ParseDef(file)
|
d, err := ParseDef(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
warnings = append(warnings, file_path+": "+err.Error())
|
warnings = append(warnings, filePath+": "+err.Error())
|
||||||
} else {
|
} else {
|
||||||
*defs = append(*defs, d)
|
*defs = append(*defs, d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return warnings, err
|
||||||
return err, warnings
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int {
|
func findIndex(regex *regexp.Regexp, skip *regexp.Regexp, str []rune, canMatchStart, canMatchEnd bool) []int {
|
||||||
|
|||||||
+3
-3
@@ -10,10 +10,10 @@ import (
|
|||||||
|
|
||||||
func TestInputs(t *testing.T) {
|
func TestInputs(t *testing.T) {
|
||||||
|
|
||||||
test_inputs_dir := "./test_inputs/*"
|
testInputsDir := "./test_inputs/*"
|
||||||
files, err := filepath.Glob(test_inputs_dir)
|
files, err := filepath.Glob(testInputsDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Couldn't open '%s', error: %v\n", test_inputs_dir, err)
|
t.Errorf("Couldn't open '%s', error: %v\n", testInputsDir, err)
|
||||||
}
|
}
|
||||||
for _, filename := range files {
|
for _, filename := range files {
|
||||||
ext := strings.Split(filename, ".")
|
ext := strings.Split(filename, ".")
|
||||||
|
|||||||
@@ -87,11 +87,11 @@ func ParseDef(input []byte) (s *Def, err error) {
|
|||||||
s = new(Def)
|
s = new(Def)
|
||||||
|
|
||||||
for k, v := range rules {
|
for k, v := range rules {
|
||||||
if k == "filetype" {
|
switch k {
|
||||||
|
case "filetype":
|
||||||
filetype := v.(string)
|
filetype := v.(string)
|
||||||
|
|
||||||
s.FileType = filetype
|
s.FileType = filetype
|
||||||
} else if k == "detect" {
|
case "detect":
|
||||||
ftdetect := v.(map[interface{}]interface{})
|
ftdetect := v.(map[interface{}]interface{})
|
||||||
if len(ftdetect) >= 1 {
|
if len(ftdetect) >= 1 {
|
||||||
syntax, err := regexp.Compile(ftdetect["filename"].(string))
|
syntax, err := regexp.Compile(ftdetect["filename"].(string))
|
||||||
@@ -109,7 +109,7 @@ func ParseDef(input []byte) (s *Def, err error) {
|
|||||||
|
|
||||||
s.ftdetect = append(s.ftdetect, header)
|
s.ftdetect = append(s.ftdetect, header)
|
||||||
}
|
}
|
||||||
} else if k == "rules" {
|
case "rules":
|
||||||
inputRules := v.([]interface{})
|
inputRules := v.([]interface{})
|
||||||
|
|
||||||
rules, err := parseRules(inputRules, nil)
|
rules, err := parseRules(inputRules, nil)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jessp01/gohighlight"
|
highlight "github.com/jessp01/gohighlight"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
//nolint
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
printf("%s\n", "Hello world!");
|
printf("%s\n", "Hello world!");
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
Filesystem Size Used Avail Use% Mounted on
|
||||||
|
udev 7.7G 0 7.7G 0% /dev
|
||||||
|
tmpfs 1.6G 3.1M 1.6G 1% /run
|
||||||
|
/dev/nvme0n1p2 23G 21G 673M 97% /
|
||||||
|
tmpfs 7.7G 55M 7.7G 1% /dev/shm
|
||||||
|
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
|
||||||
|
/dev/nvme0n1p5 1.8G 271M 1.5G 16% /tmp
|
||||||
|
/dev/nvme0n1p3 9.1G 7.9G 737M 92% /var
|
||||||
|
/dev/nvme0n1p6 434G 230G 181G 56% /home
|
||||||
|
/dev/nvme0n1p1 511M 3.5M 508M 1% /boot/efi
|
||||||
|
tmpfs 1.6G 25M 1.6G 2% /run/user/1000
|
||||||
|
tmpfs 1.6G 92K 1.6G 1% /run/user/0
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ex, err := os.Executable()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
exPath := filepath.Dir(ex)
|
||||||
|
fmt.Println(exPath)
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
Active Internet connections (only servers)
|
||||||
|
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
|
||||||
|
tcp 0 0 0.0.0.0:35211 0.0.0.0:* LISTEN -
|
||||||
|
tcp 0 0 0.0.0.0:51435 0.0.0.0:* LISTEN 1798003/rpc.mountd
|
||||||
|
tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
|
||||||
|
tcp 0 0 0.0.0.0:51311 0.0.0.0:* LISTEN 1797998/rpc.statd
|
||||||
|
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 1803502/connmand
|
||||||
|
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2384685/cupsd
|
||||||
|
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1798145/mariadbd
|
||||||
|
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1798150/sshd: /usr/
|
||||||
|
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 1798810/master
|
||||||
|
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
|
||||||
|
tcp 0 0 127.0.0.1:35765 0.0.0.0:* LISTEN 878/containerd
|
||||||
|
tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN 2082789/node
|
||||||
|
tcp 0 0 0.0.0.0:46613 0.0.0.0:* LISTEN 1798003/rpc.mountd
|
||||||
|
tcp 0 0 0.0.0.0:54439 0.0.0.0:* LISTEN 1798003/rpc.mountd
|
||||||
|
tcp6 0 0 :::2049 :::* LISTEN -
|
||||||
|
tcp6 0 0 :::36647 :::* LISTEN 1798003/rpc.mountd
|
||||||
|
tcp6 0 0 ::1:631 :::* LISTEN 2384685/cupsd
|
||||||
|
tcp6 0 0 ::1:53 :::* LISTEN 1803502/connmand
|
||||||
|
tcp6 0 0 :::443 :::* LISTEN 1803521/apache2
|
||||||
|
tcp6 0 0 :::33167 :::* LISTEN -
|
||||||
|
tcp6 0 0 :::22 :::* LISTEN 1798150/sshd: /usr/
|
||||||
|
tcp6 0 0 :::25 :::* LISTEN 1798810/master
|
||||||
|
tcp6 0 0 :::111 :::* LISTEN 1/systemd
|
||||||
|
tcp6 0 0 :::80 :::* LISTEN 1803521/apache2
|
||||||
|
tcp6 0 0 :::49243 :::* LISTEN 1798003/rpc.mountd
|
||||||
|
tcp6 0 0 :::55779 :::* LISTEN 1798003/rpc.mountd
|
||||||
|
tcp6 0 0 :::57253 :::* LISTEN 1797998/rpc.statd
|
||||||
|
tcp6 0 0 :::7373 :::* LISTEN 1803521/apache2
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
PING debian.org (149.20.4.15) 56(84) bytes of data.
|
||||||
|
64 bytes from mirror-isc3.debian.org (149.20.4.15): icmp_seq=1 ttl=50 time=155 ms
|
||||||
|
64 bytes from mirror-isc3.debian.org (149.20.4.15): icmp_seq=2 ttl=50 time=152 ms
|
||||||
|
64 bytes from mirror-isc3.debian.org (149.20.4.15): icmp_seq=3 ttl=50 time=160 ms
|
||||||
|
64 bytes from mirror-isc3.debian.org (149.20.4.15): icmp_seq=4 ttl=50 time=173 ms
|
||||||
|
|
||||||
|
--- debian.org ping statistics ---
|
||||||
|
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
|
||||||
|
rtt min/avg/max/mdev = 151.851/160.021/172.823/7.983 ms
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
traceroute to debian.org (149.20.4.15), 30 hops max, 60 byte packets
|
||||||
|
1 192.168.25.122 (192.168.25.122) 2.635 ms 3.320 ms 3.403 ms
|
||||||
|
2 * * *
|
||||||
|
3 * * *
|
||||||
|
4 * * *
|
||||||
|
5 * * *
|
||||||
|
6 172.19.136.161 (172.19.136.161) 294.118 ms 379.170 ms 379.095 ms
|
||||||
|
7 * * *
|
||||||
|
8 172.19.17.154 (172.19.17.154) 25.121 ms 16.297 ms *
|
||||||
|
9 195.66.227.6 (195.66.227.6) 26.169 ms 26.129 ms 22.198 ms
|
||||||
|
10 * * *
|
||||||
|
11 * * *
|
||||||
|
12 * * *
|
||||||
|
13 * * *
|
||||||
|
14 he.pao1.isc.org (72.52.94.70) 154.700 ms 153.893 ms 163.018 ms
|
||||||
|
15 mirror-isc3.debian.org (149.20.4.15) 162.062 ms 143.122 ms 165.659 ms
|
||||||
Reference in New Issue
Block a user