Skip to content

Commit

Permalink
Merge branch 'lint' of https://github.com/ryancox/cascadia
Browse files Browse the repository at this point in the history
  • Loading branch information
andybalholm committed Dec 24, 2016
2 parents 7fb769b + 2fe1a00 commit 349dd02
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions fuzz/fuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fuzz

import "github.com/andybalholm/cascadia"

// Fuzz is the entrypoint used by the go-fuzz framework
func Fuzz(data []byte) int {
sel, err := cascadia.Compile(string(data))
if err != nil {
Expand Down
40 changes: 20 additions & 20 deletions parser.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// The cascadia package is an implementation of CSS selectors.
// Package cascadia is an implementation of CSS selectors.
package cascadia

import (
Expand Down Expand Up @@ -414,9 +414,9 @@ func (p *parser) parseAttributeSelector() (Selector, error) {
return nil, fmt.Errorf("attribute operator %q is not supported", op)
}

var expectedParenthesis = errors.New("expected '(' but didn't find it")
var expectedClosingParenthesis = errors.New("expected ')' but didn't find it")
var unmatchedParenthesis = errors.New("unmatched '('")
var errExpectedParenthesis = errors.New("expected '(' but didn't find it")
var errExpectedClosingParenthesis = errors.New("expected ')' but didn't find it")
var errUnmatchedParenthesis = errors.New("unmatched '('")

// parsePseudoclassSelector parses a pseudoclass selector like :not(p).
func (p *parser) parsePseudoclassSelector() (Selector, error) {
Expand All @@ -437,14 +437,14 @@ func (p *parser) parsePseudoclassSelector() (Selector, error) {
switch name {
case "not", "has", "haschild":
if !p.consumeParenthesis() {
return nil, expectedParenthesis
return nil, errExpectedParenthesis
}
sel, err := p.parseSelectorGroup()
if err != nil {
return nil, err
sel, parseErr := p.parseSelectorGroup()
if parseErr != nil {
return nil, parseErr
}
if !p.consumeClosingParenthesis() {
return nil, expectedClosingParenthesis
return nil, errExpectedClosingParenthesis
}

switch name {
Expand All @@ -458,10 +458,10 @@ func (p *parser) parsePseudoclassSelector() (Selector, error) {

case "contains", "containsown":
if !p.consumeParenthesis() {
return nil, expectedParenthesis
return nil, errExpectedParenthesis
}
if p.i == len(p.s) {
return nil, unmatchedParenthesis
return nil, errUnmatchedParenthesis
}
var val string
switch p.s[p.i] {
Expand All @@ -479,7 +479,7 @@ func (p *parser) parsePseudoclassSelector() (Selector, error) {
return nil, errors.New("unexpected EOF in pseudo selector")
}
if !p.consumeClosingParenthesis() {
return nil, expectedClosingParenthesis
return nil, errExpectedClosingParenthesis
}

switch name {
Expand All @@ -491,7 +491,7 @@ func (p *parser) parsePseudoclassSelector() (Selector, error) {

case "matches", "matchesown":
if !p.consumeParenthesis() {
return nil, expectedParenthesis
return nil, errExpectedParenthesis
}
rx, err := p.parseRegex()
if err != nil {
Expand All @@ -501,7 +501,7 @@ func (p *parser) parsePseudoclassSelector() (Selector, error) {
return nil, errors.New("unexpected EOF in pseudo selector")
}
if !p.consumeClosingParenthesis() {
return nil, expectedClosingParenthesis
return nil, errExpectedClosingParenthesis
}

switch name {
Expand All @@ -513,14 +513,14 @@ func (p *parser) parsePseudoclassSelector() (Selector, error) {

case "nth-child", "nth-last-child", "nth-of-type", "nth-last-of-type":
if !p.consumeParenthesis() {
return nil, expectedParenthesis
return nil, errExpectedParenthesis
}
a, b, err := p.parseNth()
if err != nil {
return nil, err
}
if !p.consumeClosingParenthesis() {
return nil, expectedClosingParenthesis
return nil, errExpectedClosingParenthesis
}
if a == 0 {
switch name {
Expand Down Expand Up @@ -570,7 +570,7 @@ func (p *parser) parseInteger() (int, error) {
i++
}
if i == start {
return 0, errors.New("expected integer, but didn't find it.")
return 0, errors.New("expected integer, but didn't find it")
}
p.i = i

Expand Down Expand Up @@ -602,9 +602,9 @@ func (p *parser) parseNth() (a, b int, err error) {
p.i++
goto readN
case 'o', 'O', 'e', 'E':
id, err := p.parseName()
if err != nil {
return 0, 0, err
id, nameErr := p.parseName()
if nameErr != nil {
return 0, 0, nameErr
}
id = toLowerASCII(id)
if id == "odd" {
Expand Down

0 comments on commit 349dd02

Please sign in to comment.