Skip to content

Commit 23160b3

Browse files
Steven Pennyalecthomas
Steven Penny
authored andcommitted
lexers/internal: remove danwakefield/fnmatch
This package appears to be old and unmaintained, and it gets pulled into the go.sum of every single package importing Chroma. Also fnmatch doesnt seem to do any error checking on the pattern, while the standard package does. Also, the standard package path/filepath is already imported, so it appears not to cost anything to change it.
1 parent 3683949 commit 23160b3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Diff for: lexers/internal/api.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"sort"
77
"strings"
88

9-
"github.com/danwakefield/fnmatch"
10-
119
"github.com/alecthomas/chroma"
1210
)
1311

@@ -104,11 +102,17 @@ func Match(filename string) chroma.Lexer {
104102
for _, lexer := range Registry.Lexers {
105103
config := lexer.Config()
106104
for _, glob := range config.Filenames {
107-
if fnmatch.Match(glob, filename, 0) {
105+
ok, err := filepath.Match(glob, filename)
106+
if err != nil { // nolint
107+
panic(err)
108+
} else if ok {
108109
matched = append(matched, lexer)
109110
} else {
110111
for _, suf := range &ignoredSuffixes {
111-
if fnmatch.Match(glob+suf, filename, 0) {
112+
ok, err := filepath.Match(glob+suf, filename)
113+
if err != nil {
114+
panic(err)
115+
} else if ok {
112116
matched = append(matched, lexer)
113117
break
114118
}
@@ -125,11 +129,17 @@ func Match(filename string) chroma.Lexer {
125129
for _, lexer := range Registry.Lexers {
126130
config := lexer.Config()
127131
for _, glob := range config.AliasFilenames {
128-
if fnmatch.Match(glob, filename, 0) {
132+
ok, err := filepath.Match(glob, filename)
133+
if err != nil { // nolint
134+
panic(err)
135+
} else if ok {
129136
matched = append(matched, lexer)
130137
} else {
131138
for _, suf := range &ignoredSuffixes {
132-
if fnmatch.Match(glob+suf, filename, 0) {
139+
ok, err := filepath.Match(glob+suf, filename)
140+
if err != nil {
141+
panic(err)
142+
} else if ok {
133143
matched = append(matched, lexer)
134144
break
135145
}

0 commit comments

Comments
 (0)