Skip to content

Commit 47ae827

Browse files
committed
Update comments
1 parent aada8b1 commit 47ae827

File tree

23 files changed

+52
-19
lines changed

23 files changed

+52
-19
lines changed

cmd/minify/main.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/tdewolff/minify/v2/xml"
3131
)
3232

33+
// Version is the current minify version.
3334
var Version = "built from source"
3435

3536
var filetypeMime = map[string]string{
@@ -56,12 +57,14 @@ var (
5657
bundle bool
5758
)
5859

60+
// Task is a minify task.
5961
type Task struct {
6062
srcs []string
6163
dst string
6264
sync bool
6365
}
6466

67+
// NewTask returns a new Task.
6568
func NewTask(root, input, output string, sync bool) (Task, error) {
6669
t := Task{[]string{input}, output, sync}
6770
if 0 < len(output) && output[len(output)-1] == '/' {
@@ -74,6 +77,7 @@ func NewTask(root, input, output string, sync bool) (Task, error) {
7477
return t, nil
7578
}
7679

80+
// Loggers.
7781
var (
7882
Error *log.Logger
7983
Warning *log.Logger
@@ -634,7 +638,7 @@ func minify(mimetype string, t Task) bool {
634638
}
635639
}
636640

637-
fr, err := NewConcatFileReader(t.srcs, openInputFile)
641+
fr, err := newConcatFileReader(t.srcs, openInputFile)
638642
if err != nil {
639643
Error.Println(err)
640644
return false
@@ -662,12 +666,12 @@ func minify(mimetype string, t Task) bool {
662666
return true
663667
}
664668

665-
r := NewCountingReader(fr)
669+
r := newCountingReader(fr)
666670
var w *countingWriter
667671
if fw == os.Stdout {
668-
w = NewCountingWriter(fw)
672+
w = newCountingWriter(fw)
669673
} else {
670-
w = NewCountingWriter(bufio.NewWriter(fw))
674+
w = newCountingWriter(bufio.NewWriter(fw))
671675
}
672676

673677
success := true

cmd/minify/util.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type countingReader struct {
99
N int
1010
}
1111

12-
func NewCountingReader(r io.Reader) *countingReader {
12+
func newCountingReader(r io.Reader) *countingReader {
1313
return &countingReader{r, 0}
1414
}
1515

@@ -24,7 +24,7 @@ type countingWriter struct {
2424
N int
2525
}
2626

27-
func NewCountingWriter(w io.Writer) *countingWriter {
27+
func newCountingWriter(w io.Writer) *countingWriter {
2828
return &countingWriter{w, 0}
2929
}
3030

@@ -56,7 +56,7 @@ type concatFileReader struct {
5656
// NewConcatFileReader reads from a list of filenames, and lazily loads files as it needs it.
5757
// It is a reader that reads a concatenation of those files separated by the separator.
5858
// You must call Close to close the last file in the list.
59-
func NewConcatFileReader(filenames []string, opener func(string) (io.ReadCloser, error)) (*concatFileReader, error) {
59+
func newConcatFileReader(filenames []string, opener func(string) (io.ReadCloser, error)) (*concatFileReader, error) {
6060
var cur io.ReadCloser
6161
if len(filenames) > 0 {
6262
var filename string

cmd/minify/watch.go

+5
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import (
88
"github.com/fsnotify/fsnotify"
99
)
1010

11+
// Watcher is a wrapper for watching file changes in directories.
1112
type Watcher struct {
1213
watcher *fsnotify.Watcher
1314
paths map[string]bool
1415
recursive bool
1516
}
1617

18+
// NewWatcher returns a new Watcher.
1719
func NewWatcher(recursive bool) (*Watcher, error) {
1820
watcher, err := fsnotify.NewWatcher()
1921
if err != nil {
@@ -22,10 +24,12 @@ func NewWatcher(recursive bool) (*Watcher, error) {
2224
return &Watcher{watcher, make(map[string]bool), recursive}, nil
2325
}
2426

27+
// Close closes the watcher.
2528
func (w *Watcher) Close() error {
2629
return w.watcher.Close()
2730
}
2831

32+
// AddPath adds a new path to watch.
2933
func (w *Watcher) AddPath(root string) error {
3034
info, err := os.Stat(root)
3135
if err != nil {
@@ -70,6 +74,7 @@ func (w *Watcher) AddPath(root string) error {
7074
}
7175
}
7276

77+
// Run watches for file changes.
7378
func (w *Watcher) Run() chan string {
7479
files := make(chan string, 10)
7580
go func() {

common.go

+3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ func DataURI(m *M, dataURI []byte) []byte {
8484
return append(append(append(dataBytes, mediatype...), ','), data...)
8585
}
8686

87+
// MaxInt is the maximum value of int.
8788
const MaxInt = int(^uint(0) >> 1)
89+
90+
// MinInt is the minimum value of int.
8891
const MinInt = -MaxInt - 1
8992

9093
// Decimal minifies a given byte slice containing a decimal and removes superfluous characters. It differs from Number in that it does not parse exponents.

css/css.go

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func Minify(m *minify.M, w io.Writer, r io.Reader, params map[string]string) err
6565
return (&Minifier{}).Minify(m, w, r, params)
6666
}
6767

68+
// Token is a parsed token with extra information for functions.
6869
type Token struct {
6970
css.TokenType
7071
Data []byte
@@ -79,6 +80,7 @@ func (t Token) String() string {
7980
return fmt.Sprint(t.Args)
8081
}
8182

83+
// Equal returns true if both tokens are equal.
8284
func (a Token) Equal(b Token) bool {
8385
if a.TokenType == b.TokenType && bytes.Equal(a.Data, b.Data) && len(a.Args) == len(b.Args) {
8486
for i := 0; i < len(a.Args); i++ {
@@ -91,11 +93,13 @@ func (a Token) Equal(b Token) bool {
9193
return false
9294
}
9395

96+
// IsZero return true if a dimension, percentage, or number token is zero.
9497
func (t Token) IsZero() bool {
9598
// as each number is already minified, starting with a zero means it is zero
9699
return (t.TokenType == css.DimensionToken || t.TokenType == css.PercentageToken || t.TokenType == css.NumberToken) && t.Data[0] == '0'
97100
}
98101

102+
// IsLength returns true if the token is a length.
99103
func (t Token) IsLength() bool {
100104
if t.TokenType == css.DimensionToken {
101105
return true
@@ -110,6 +114,7 @@ func (t Token) IsLength() bool {
110114
return false
111115
}
112116

117+
// IsLengthPercentage returns true if the token is a length or percentage token.
113118
func (t Token) IsLengthPercentage() bool {
114119
return t.TokenType == css.PercentageToken || t.IsLength()
115120
}

css/table.go

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ var ShortenColorName = map[Hash][]byte{
162162
White: []byte("#fff"),
163163
}
164164

165+
// PropertyOverrides is a map of which properties are overridden by the given property.
165166
var PropertyOverrides = map[Hash][]Hash{
166167
Background: []Hash{Background, Background_Image, Background_Position, Background_Size, Background_Repeat, Background_Origin, Background_Clip, Background_Attachment, Background_Color},
167168
Font: []Hash{Font, Font_Style, Font_Variant, Font_Weight, Font_Stretch, Font_Size, Font_Family, Line_Height},

html/table.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ var jsMimetypes = map[string]bool{
244244
"application/javascript": true,
245245
}
246246

247-
// Entities are all named character entities.
247+
// EntitiesMap are all named character entities.
248248
var EntitiesMap = map[string][]byte{
249249
"AElig": []byte("&#198;"),
250250
"AMP": []byte("&"),
@@ -1340,6 +1340,7 @@ var EntitiesMap = map[string][]byte{
13401340
"zigrarr": []byte("&#8669;"),
13411341
}
13421342

1343+
// TextRevEntitiesMap is a map of escapes.
13431344
var TextRevEntitiesMap = map[byte][]byte{
13441345
'<': []byte("&lt;"),
13451346
}

js/util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ var (
8787
groupedNotOneBytes = []byte("(!1)")
8888
)
8989

90-
// precendence maps for the precendence inside the operation
90+
// precedence maps for the precedence inside the operation
9191
var unaryPrecMap = map[js.TokenType]js.OpPrec{
9292
js.PostIncrToken: js.OpLHS,
9393
js.PostDecrToken: js.OpLHS,
@@ -187,7 +187,7 @@ var binaryRightPrecMap = map[js.TokenType]js.OpPrec{
187187
js.CommaToken: js.OpAssign,
188188
}
189189

190-
// precendence maps of the operation itself
190+
// precedence maps of the operation itself
191191
var unaryOpPrecMap = map[js.TokenType]js.OpPrec{
192192
js.PostIncrToken: js.OpUpdate,
193193
js.PostDecrToken: js.OpUpdate,

minify.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,10 @@ func (m *M) MinifyMimetype(mimetype []byte, w io.Writer, r io.Reader, params map
211211

212212
if minifier, ok := m.literal[string(mimetype)]; ok { // string conversion is optimized away
213213
return minifier.Minify(m, w, r, params)
214-
} else {
215-
for _, minifier := range m.pattern {
216-
if minifier.pattern.Match(mimetype) {
217-
return minifier.Minify(m, w, r, params)
218-
}
214+
}
215+
for _, minifier := range m.pattern {
216+
if minifier.pattern.Match(mimetype) {
217+
return minifier.Minify(m, w, r, params)
219218
}
220219
}
221220
return ErrNotExist

svg/pathdata.go

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/tdewolff/parse/v2/strconv"
1010
)
1111

12+
// PathData represents a path data string.
1213
type PathData struct {
1314
o *Minifier
1415

@@ -25,13 +26,15 @@ type PathData struct {
2526
coordBuffer []byte
2627
}
2728

29+
// PathDataState is the state of the current path.
2830
type PathDataState struct {
2931
cmd byte
3032
prevDigit bool
3133
prevDigitIsInt bool
3234
prevFlag bool
3335
}
3436

37+
// NewPathData returns a new PathData.
3538
func NewPathData(o *Minifier) *PathData {
3639
return &PathData{
3740
o: o,

tests/css-token/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/tdewolff/parse/v2/css"
66
)
77

8+
// Fuzz is a fuzz test.
89
func Fuzz(data []byte) int {
910
_ = css.IsIdent(data)
1011
return 1

tests/css/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/tdewolff/minify/v2/css"
1010
)
1111

12+
// Fuzz is a fuzz test.
1213
func Fuzz(data []byte) int {
1314
r := bytes.NewBuffer(data)
1415
_ = css.Minify(minify.New(), ioutil.Discard, r, nil)

tests/data-uri/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"github.com/tdewolff/parse/v2"
77
)
88

9+
// Fuzz is a fuzz test.
910
func Fuzz(data []byte) int {
1011
data = parse.Copy(data) // ignore const-input error for OSS-Fuzz
11-
data = minify.DataURI(minify.New(), data)
12+
_ = minify.DataURI(minify.New(), data)
1213
return 1
1314
}

tests/decimal/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/tdewolff/parse/v2"
77
)
88

9+
// Fuzz is a fuzz test.
910
func Fuzz(data []byte) int {
1011
prec := 0
1112
if len(data) > 0 {

tests/html/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/tdewolff/minify/v2/html"
1010
)
1111

12+
// Fuzz is a fuzz test.
1213
func Fuzz(data []byte) int {
1314
r := bytes.NewBuffer(data)
1415
_ = html.Minify(minify.New(), ioutil.Discard, r, nil)

tests/js/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/tdewolff/minify/v2/js"
1010
)
1111

12+
// Fuzz is a fuzz test.
1213
func Fuzz(data []byte) int {
1314
r := bytes.NewBuffer(data)
1415
_ = js.Minify(minify.New(), ioutil.Discard, r, nil)

tests/json/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/tdewolff/minify/v2/json"
1010
)
1111

12+
// Fuzz is a fuzz test.
1213
func Fuzz(data []byte) int {
1314
r := bytes.NewBuffer(data)
1415
_ = json.Minify(minify.New(), ioutil.Discard, r, nil)

tests/mediatype/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"github.com/tdewolff/parse/v2"
77
)
88

9+
// Fuzz is a fuzz test.
910
func Fuzz(data []byte) int {
1011
data = parse.Copy(data) // ignore const-input error for OSS-Fuzz
11-
data = minify.Mediatype(data)
12+
_ = minify.Mediatype(data)
1213
return 1
1314
}

tests/number/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/tdewolff/parse/v2"
77
)
88

9+
// Fuzz is a fuzz test.
910
func Fuzz(data []byte) int {
1011
prec := 0
1112
if len(data) > 0 {

tests/svg-pathdata/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"github.com/tdewolff/parse/v2"
77
)
88

9+
// Fuzz is a fuzz test.
910
func Fuzz(data []byte) int {
1011
pathDataBuffer := svg.NewPathData(&svg.Minifier{Decimals: -1})
1112
data = parse.Copy(data) // ignore const-input error for OSS-Fuzz
12-
data = pathDataBuffer.ShortenPathData(data)
13+
_ = pathDataBuffer.ShortenPathData(data)
1314
return 1
1415
}

tests/svg/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/tdewolff/minify/v2/svg"
1010
)
1111

12+
// Fuzz is a fuzz test.
1213
func Fuzz(data []byte) int {
1314
r := bytes.NewBuffer(data)
1415
_ = svg.Minify(minify.New(), ioutil.Discard, r, nil)

tests/xml/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/tdewolff/minify/v2/xml"
1010
)
1111

12+
// Fuzz is a fuzz test.
1213
func Fuzz(data []byte) int {
1314
r := bytes.NewBuffer(data)
1415
_ = xml.Minify(minify.New(), ioutil.Discard, r, nil)

xml/table.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package xml
22

3-
// Entities are all named character entities.
3+
// EntitiesMap are all named character entities.
44
var EntitiesMap = map[string][]byte{
55
"apos": []byte("'"),
66
"gt": []byte(">"),

0 commit comments

Comments
 (0)