1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-03-05 15:16:07 +02:00

Merge pull request #55 from davad/cleanup/fix-naming-convention

Cleanup linting errors
This commit is contained in:
Tim Voronov 2018-10-05 20:48:57 -04:00 committed by GitHub
commit 7fef5f3eb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 431 additions and 339 deletions

View File

@ -18,10 +18,14 @@ addons:
before_install: before_install:
- curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
- go get -u github.com/mgechev/revive
- sudo curl -o /usr/local/lib/antlr-4.7.1-complete.jar https://www.antlr.org/download/antlr-4.7.1-complete.jar - sudo curl -o /usr/local/lib/antlr-4.7.1-complete.jar https://www.antlr.org/download/antlr-4.7.1-complete.jar
- export CLASSPATH=".:/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH" - export CLASSPATH=".:/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH"
- mkdir $HOME/travis-bin - mkdir $HOME/travis-bin
- echo -e '#!/bin/bash\njava -jar /usr/local/lib/antlr-4.7.1-complete.jar "$@"' > $HOME/travis-bin/antlr4 - echo -e '#!/bin/bash\njava -jar /usr/local/lib/antlr-4.7.1-complete.jar "$@"' > $HOME/travis-bin/antlr4
- echo -e '#!/bin/bash\njava org.antlr.v4.gui.TestRig "$@"' > $HOME/travis-bin/grun - echo -e '#!/bin/bash\njava org.antlr.v4.gui.TestRig "$@"' > $HOME/travis-bin/grun
- chmod +x $HOME/travis-bin/* - chmod +x $HOME/travis-bin/*
- export PATH=$PATH:$HOME/travis-bin - export PATH=$PATH:$HOME/travis-bin
script:
- revive -config revive.toml -formatter friendly -exclude ./pkg/parser/fql/... ./...

70
Gopkg.lock generated
View File

@ -1,6 +1,41 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
digest = "1:b464fe4a2262c37c82c16ff76dd77ae8efb85036d2f6b13b428a3e63bce3d562"
name = "github.com/MontFerret/ferret"
packages = [
"cli",
"cli/browser",
"pkg/compiler",
"pkg/parser",
"pkg/parser/fql",
"pkg/runtime",
"pkg/runtime/collections",
"pkg/runtime/core",
"pkg/runtime/expressions",
"pkg/runtime/expressions/clauses",
"pkg/runtime/expressions/literals",
"pkg/runtime/expressions/operators",
"pkg/runtime/logging",
"pkg/runtime/values",
"pkg/stdlib",
"pkg/stdlib/collections",
"pkg/stdlib/html",
"pkg/stdlib/html/driver",
"pkg/stdlib/html/driver/common",
"pkg/stdlib/html/driver/dynamic",
"pkg/stdlib/html/driver/dynamic/eval",
"pkg/stdlib/html/driver/dynamic/events",
"pkg/stdlib/html/driver/static",
"pkg/stdlib/strings",
"pkg/stdlib/types",
"pkg/stdlib/utils",
]
pruneopts = "UT"
revision = "51d794d6c1b3cbc5e4d3a654000a601f974b0288"
[[projects]] [[projects]]
digest = "1:a62f6ed230a8cd138a9efbe718e7d0b0294f139266f5f55cd942769a9aac8de2" digest = "1:a62f6ed230a8cd138a9efbe718e7d0b0294f139266f5f55cd942769a9aac8de2"
name = "github.com/PuerkitoBio/goquery" name = "github.com/PuerkitoBio/goquery"
@ -137,14 +172,6 @@
revision = "a96e63847dc3c67d17befa69c303767e2f84e54f" revision = "a96e63847dc3c67d17befa69c303767e2f84e54f"
version = "v2.1" version = "v2.1"
[[projects]]
branch = "master"
digest = "1:f7aa53146bf79462509d4ce136826ebbd64907e4679e1b04e62758da6b68e589"
name = "github.com/orcaman/concurrent-map"
packages = ["."]
pruneopts = "UT"
revision = "b28018939af9022337862b94a463abb18abb3e0e"
[[projects]] [[projects]]
digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747" digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747"
name = "github.com/pkg/errors" name = "github.com/pkg/errors"
@ -221,6 +248,32 @@
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
input-imports = [ input-imports = [
"github.com/MontFerret/ferret/cli",
"github.com/MontFerret/ferret/cli/browser",
"github.com/MontFerret/ferret/pkg/compiler",
"github.com/MontFerret/ferret/pkg/parser",
"github.com/MontFerret/ferret/pkg/parser/fql",
"github.com/MontFerret/ferret/pkg/runtime",
"github.com/MontFerret/ferret/pkg/runtime/collections",
"github.com/MontFerret/ferret/pkg/runtime/core",
"github.com/MontFerret/ferret/pkg/runtime/expressions",
"github.com/MontFerret/ferret/pkg/runtime/expressions/clauses",
"github.com/MontFerret/ferret/pkg/runtime/expressions/literals",
"github.com/MontFerret/ferret/pkg/runtime/expressions/operators",
"github.com/MontFerret/ferret/pkg/runtime/logging",
"github.com/MontFerret/ferret/pkg/runtime/values",
"github.com/MontFerret/ferret/pkg/stdlib",
"github.com/MontFerret/ferret/pkg/stdlib/collections",
"github.com/MontFerret/ferret/pkg/stdlib/html",
"github.com/MontFerret/ferret/pkg/stdlib/html/driver",
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/common",
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/dynamic",
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/dynamic/eval",
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/dynamic/events",
"github.com/MontFerret/ferret/pkg/stdlib/html/driver/static",
"github.com/MontFerret/ferret/pkg/stdlib/strings",
"github.com/MontFerret/ferret/pkg/stdlib/types",
"github.com/MontFerret/ferret/pkg/stdlib/utils",
"github.com/PuerkitoBio/goquery", "github.com/PuerkitoBio/goquery",
"github.com/antlr/antlr4/runtime/Go/antlr", "github.com/antlr/antlr4/runtime/Go/antlr",
"github.com/chzyer/readline", "github.com/chzyer/readline",
@ -236,7 +289,6 @@
"github.com/mafredri/cdp/rpcc", "github.com/mafredri/cdp/rpcc",
"github.com/mafredri/cdp/session", "github.com/mafredri/cdp/session",
"github.com/natefinch/lumberjack", "github.com/natefinch/lumberjack",
"github.com/orcaman/concurrent-map",
"github.com/pkg/errors", "github.com/pkg/errors",
"github.com/rs/zerolog", "github.com/rs/zerolog",
"github.com/sethgrid/pester", "github.com/sethgrid/pester",

View File

@ -32,12 +32,12 @@ doc:
fmt: fmt:
go fmt ${DIR_CLI}/... ${DIR_PKG}/... go fmt ${DIR_CLI}/... ${DIR_PKG}/...
# https://github.com/golang/lint # https://github.com/mgechev/revive
# go get github.com/golang/lint/golint # go get github.com/mgechev/revive
lint: lint:
golint ${DIR_CLI}/... ${DIR_PKG}/... revive -config ../revive.toml -formatter friendly -exclude ./pkg/parser/fql/... ./...
# http://godoc.org/code.google.com/p/go.tools/cmd/vet # http://godoc.org/code.google.com/p/go.tools/cmd/vet
# go get code.google.com/p/go.tools/cmd/vet # go get code.google.com/p/go.tools/cmd/vet
vet: vet:
go vet ${DIR_CLI}/... ${DIR_PKG}/... go vet ${DIR_CLI}/... ${DIR_PKG}/...

View File

@ -11,7 +11,7 @@ import (
type Topic struct { type Topic struct {
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
Url string `json:"url"` URL string `json:"url"`
} }
func main() { func main() {
@ -23,7 +23,7 @@ func main() {
} }
for _, topic := range topics { for _, topic := range topics {
fmt.Println(fmt.Sprintf("%s: %s %s", topic.Name, topic.Description, topic.Url)) fmt.Println(fmt.Sprintf("%s: %s %s", topic.Name, topic.Description, topic.URL))
} }
} }

View File

@ -9,6 +9,6 @@ type errorListener struct {
*antlr.DefaultErrorListener *antlr.DefaultErrorListener
} }
func (d *errorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) { func (d *errorListener) SyntaxError(_ antlr.Recognizer, _ interface{}, line, column int, msg string, _ antlr.RecognitionException) {
panic(errors.Errorf("%s at %d:%d", msg, line, column)) panic(errors.Errorf("%s at %d:%d", msg, line, column))
} }

View File

@ -536,7 +536,7 @@ func (v *visitor) doVisitObjectLiteral(ctx *fql.ObjectLiteralContext, scope *sco
return literals.NewObjectLiteralWith(props...), nil return literals.NewObjectLiteralWith(props...), nil
} }
func (v *visitor) doVisitPropertyNameContext(ctx *fql.PropertyNameContext, scope *scope) (core.Expression, error) { func (v *visitor) doVisitPropertyNameContext(ctx *fql.PropertyNameContext, _ *scope) (core.Expression, error) {
return literals.NewStringLiteral(ctx.Identifier().GetText()), nil return literals.NewStringLiteral(ctx.Identifier().GetText()), nil
} }
@ -611,7 +611,7 @@ func (v *visitor) doVisitBooleanLiteral(ctx *fql.BooleanLiteralContext) (core.Ex
return literals.NewBooleanLiteral(strings.ToUpper(ctx.GetText()) == "TRUE"), nil return literals.NewBooleanLiteral(strings.ToUpper(ctx.GetText()) == "TRUE"), nil
} }
func (v *visitor) doVisitNoneLiteral(ctx *fql.NoneLiteralContext) (core.Expression, error) { func (v *visitor) doVisitNoneLiteral(_ *fql.NoneLiteralContext) (core.Expression, error) {
return literals.None, nil return literals.None, nil
} }
@ -723,7 +723,7 @@ func (v *visitor) doVisitFunctionCallExpression(context *fql.FunctionCallExpress
) )
} }
func (v *visitor) doVisitParamContext(context *fql.ParamContext, scope *scope) (collections.IterableExpression, error) { func (v *visitor) doVisitParamContext(context *fql.ParamContext, _ *scope) (collections.IterableExpression, error) {
name := context.Identifier().GetText() name := context.Identifier().GetText()
return expressions.NewParameterExpression( return expressions.NewParameterExpression(
@ -1012,7 +1012,7 @@ func (v *visitor) doVisitForTernaryExpression(ctx *fql.ForTernaryExpressionConte
) )
} }
func (v *visitor) createTernaryOperator(src core.SourceMap, exps []core.Expression, scope *scope) (*expressions.ConditionExpression, error) { func (v *visitor) createTernaryOperator(src core.SourceMap, exps []core.Expression, _ *scope) (*expressions.ConditionExpression, error) {
var test core.Expression var test core.Expression
var consequent core.Expression var consequent core.Expression
var alternate core.Expression var alternate core.Expression

View File

@ -43,8 +43,8 @@ type (
pos int pos int
} }
HtmlNodeIterator struct { HTMLNodeIterator struct {
values values.HtmlNode values values.HTMLNode
pos int pos int
} }
) )
@ -55,15 +55,15 @@ func ToIterator(value core.Value) (Iterator, error) {
return NewArrayIterator(value.(*values.Array)), nil return NewArrayIterator(value.(*values.Array)), nil
case core.ObjectType: case core.ObjectType:
return NewObjectIterator(value.(*values.Object)), nil return NewObjectIterator(value.(*values.Object)), nil
case core.HtmlElementType, core.HtmlDocumentType: case core.HTMLElementType, core.HTMLDocumentType:
return NewHtmlNodeIterator(value.(values.HtmlNode)), nil return NewHTMLNodeIterator(value.(values.HTMLNode)), nil
default: default:
return nil, core.TypeError( return nil, core.TypeError(
value.Type(), value.Type(),
core.ArrayType, core.ArrayType,
core.ObjectType, core.ObjectType,
core.HtmlDocumentType, core.HTMLDocumentType,
core.HtmlElementType, core.HTMLElementType,
) )
} }
} }
@ -128,7 +128,7 @@ func (iterator *SliceIterator) Next() (core.Value, core.Value, error) {
if len(iterator.values) > iterator.pos { if len(iterator.values) > iterator.pos {
idx := iterator.pos idx := iterator.pos
val := iterator.values[idx] val := iterator.values[idx]
iterator.pos += 1 iterator.pos++
return val, values.NewInt(idx), nil return val, values.NewInt(idx), nil
} }
@ -148,7 +148,7 @@ func (iterator *MapIterator) HasNext() bool {
i := 0 i := 0
for k := range iterator.values { for k := range iterator.values {
keys[i] = k keys[i] = k
i += 1 i++
} }
iterator.keys = keys iterator.keys = keys
@ -161,7 +161,7 @@ func (iterator *MapIterator) Next() (core.Value, core.Value, error) {
if len(iterator.keys) > iterator.pos { if len(iterator.keys) > iterator.pos {
key := iterator.keys[iterator.pos] key := iterator.keys[iterator.pos]
val := iterator.values[key] val := iterator.values[key]
iterator.pos += 1 iterator.pos++
return val, values.NewString(key), nil return val, values.NewString(key), nil
} }
@ -181,7 +181,7 @@ func (iterator *ArrayIterator) Next() (core.Value, core.Value, error) {
if int(iterator.values.Length()) > iterator.pos { if int(iterator.values.Length()) > iterator.pos {
idx := iterator.pos idx := iterator.pos
val := iterator.values.Get(values.NewInt(idx)) val := iterator.values.Get(values.NewInt(idx))
iterator.pos += 1 iterator.pos++
return val, values.NewInt(idx), nil return val, values.NewInt(idx), nil
} }
@ -206,7 +206,7 @@ func (iterator *ObjectIterator) Next() (core.Value, core.Value, error) {
if len(iterator.keys) > iterator.pos { if len(iterator.keys) > iterator.pos {
key := iterator.keys[iterator.pos] key := iterator.keys[iterator.pos]
val, _ := iterator.values.Get(values.NewString(key)) val, _ := iterator.values.Get(values.NewString(key))
iterator.pos += 1 iterator.pos++
return val, values.NewString(key), nil return val, values.NewString(key), nil
} }
@ -214,20 +214,20 @@ func (iterator *ObjectIterator) Next() (core.Value, core.Value, error) {
return values.None, values.None, ErrExhausted return values.None, values.None, ErrExhausted
} }
func NewHtmlNodeIterator(input values.HtmlNode) *HtmlNodeIterator { func NewHTMLNodeIterator(input values.HTMLNode) *HTMLNodeIterator {
return &HtmlNodeIterator{input, 0} return &HTMLNodeIterator{input, 0}
} }
func (iterator *HtmlNodeIterator) HasNext() bool { func (iterator *HTMLNodeIterator) HasNext() bool {
return iterator.values.Length() > values.NewInt(iterator.pos) return iterator.values.Length() > values.NewInt(iterator.pos)
} }
func (iterator *HtmlNodeIterator) Next() (core.Value, core.Value, error) { func (iterator *HTMLNodeIterator) Next() (core.Value, core.Value, error) {
if iterator.values.Length() > values.NewInt(iterator.pos) { if iterator.values.Length() > values.NewInt(iterator.pos) {
idx := iterator.pos idx := iterator.pos
val := iterator.values.GetChildNode(values.NewInt(idx)) val := iterator.values.GetChildNode(values.NewInt(idx))
iterator.pos += 1 iterator.pos++
return val, values.NewInt(idx), nil return val, values.NewInt(idx), nil
} }

View File

@ -32,7 +32,7 @@ func (i *LimitIterator) HasNext() bool {
func (i *LimitIterator) Next() (core.Value, core.Value, error) { func (i *LimitIterator) Next() (core.Value, core.Value, error) {
if i.counter() <= i.count { if i.counter() <= i.count {
i.currCount += 1 i.currCount++
return i.src.Next() return i.src.Next()
} }
@ -54,7 +54,7 @@ func (i *LimitIterator) verifyOffset() {
} }
for (i.offset > i.currCount) && i.src.HasNext() { for (i.offset > i.currCount) && i.src.HasNext() {
i.currCount += 1 i.currCount++
i.src.Next() i.src.Next()
} }
} }

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
) )
//revive:disable-next-line redefines-builtin-id
type Type int64 type Type int64
const ( const (
@ -15,8 +16,8 @@ const (
DateTimeType Type = 5 DateTimeType Type = 5
ArrayType Type = 6 ArrayType Type = 6
ObjectType Type = 7 ObjectType Type = 7
HtmlElementType Type = 8 HTMLElementType Type = 8
HtmlDocumentType Type = 9 HTMLDocumentType Type = 9
BinaryType Type = 10 BinaryType Type = 10
) )
@ -29,8 +30,8 @@ var typestr = map[Type]string{
DateTimeType: "datetime", DateTimeType: "datetime",
ArrayType: "array", ArrayType: "array",
ObjectType: "object", ObjectType: "object",
HtmlElementType: "HTMLElement", HTMLElementType: "HTMLElement",
HtmlDocumentType: "HTMLDocument", HTMLDocumentType: "HTMLDocument",
BinaryType: "BinaryType", BinaryType: "BinaryType",
} }

View File

@ -12,7 +12,7 @@ func NewBooleanLiteral(val bool) BooleanLiteral {
return BooleanLiteral(val) return BooleanLiteral(val)
} }
func (l BooleanLiteral) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) { func (l BooleanLiteral) Exec(_ context.Context, _ *core.Scope) (core.Value, error) {
if l == true { if l == true {
return values.True, nil return values.True, nil
} }

View File

@ -12,6 +12,6 @@ func NewFloatLiteral(value float64) FloatLiteral {
return FloatLiteral(value) return FloatLiteral(value)
} }
func (l FloatLiteral) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) { func (l FloatLiteral) Exec(_ context.Context, _ *core.Scope) (core.Value, error) {
return values.NewFloat(float64(l)), nil return values.NewFloat(float64(l)), nil
} }

View File

@ -12,6 +12,6 @@ func NewIntLiteral(value int) IntLiteral {
return IntLiteral(value) return IntLiteral(value)
} }
func (l IntLiteral) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) { func (l IntLiteral) Exec(_ context.Context, _ *core.Scope) (core.Value, error) {
return values.NewInt(int(l)), nil return values.NewInt(int(l)), nil
} }

View File

@ -10,6 +10,6 @@ type noneLiteral struct{}
var None = &noneLiteral{} var None = &noneLiteral{}
func (l noneLiteral) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) { func (l noneLiteral) Exec(_ context.Context, _ *core.Scope) (core.Value, error) {
return values.None, nil return values.None, nil
} }

View File

@ -12,6 +12,6 @@ func NewStringLiteral(str string) StringLiteral {
return StringLiteral(str) return StringLiteral(str)
} }
func (l StringLiteral) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) { func (l StringLiteral) Exec(_ context.Context, _ *core.Scope) (core.Value, error) {
return values.NewString(string(l)), nil return values.NewString(string(l)), nil
} }

View File

@ -14,7 +14,7 @@ type (
} }
) )
var ( const (
AndType LogicalOperatorType = 0 AndType LogicalOperatorType = 0
OrType LogicalOperatorType = 1 OrType LogicalOperatorType = 1
NotType LogicalOperatorType = 2 NotType LogicalOperatorType = 2

View File

@ -14,7 +14,7 @@ type baseOperator struct {
right core.Expression right core.Expression
} }
func (operator *baseOperator) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) { func (operator *baseOperator) Exec(_ context.Context, _ *core.Scope) (core.Value, error) {
return values.None, core.ErrInvalidOperation return values.None, core.ErrInvalidOperation
} }

View File

@ -36,7 +36,7 @@ func (e *ParameterExpression) Iterate(ctx context.Context, scope *core.Scope) (c
return iter, nil return iter, nil
} }
func (e *ParameterExpression) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) { func (e *ParameterExpression) Exec(ctx context.Context, _ *core.Scope) (core.Value, error) {
param, err := core.ParamFrom(ctx, e.name) param, err := core.ParamFrom(ctx, e.name)
if err != nil { if err != nil {

View File

@ -58,7 +58,7 @@ func (e *VariableExpression) Iterate(ctx context.Context, scope *core.Scope) (co
return iter, nil return iter, nil
} }
func (e *VariableExpression) Exec(ctx context.Context, scope *core.Scope) (core.Value, error) { func (e *VariableExpression) Exec(_ context.Context, scope *core.Scope) (core.Value, error) {
return scope.GetVariable(e.name) return scope.GetVariable(e.name)
} }

View File

@ -43,8 +43,8 @@ func GetIn(from core.Value, byPath []core.Value) (core.Value, error) {
result = arr.Get(segment.(Int)) result = arr.Get(segment.(Int))
break break
case core.HtmlElementType, core.HtmlDocumentType: case core.HTMLElementType, core.HTMLDocumentType:
el := result.(HtmlNode) el := result.(HTMLNode)
if segmentType == core.IntType { if segmentType == core.IntType {
result = el.GetChildNode(segment.(Int)) result = el.GetChildNode(segment.(Int))
@ -59,7 +59,7 @@ func GetIn(from core.Value, byPath []core.Value) (core.Value, error) {
case "innerText": case "innerText":
result = el.InnerText() result = el.InnerText()
case "innerHtml": case "innerHtml":
result = el.InnerHtml() result = el.InnerHTML()
case "value": case "value":
result = el.Value() result = el.Value()
case "attributes": case "attributes":
@ -69,11 +69,11 @@ func GetIn(from core.Value, byPath []core.Value) (core.Value, error) {
case "length": case "length":
result = el.Length() result = el.Length()
case "url": case "url":
if result.Type() == core.HtmlDocumentType { if result.Type() == core.HTMLDocumentType {
doc, ok := result.(HtmlDocument) doc, ok := result.(HTMLDocument)
if ok { if ok {
result = doc.Url() result = doc.URL()
} }
} }
default: default:
@ -92,8 +92,8 @@ func GetIn(from core.Value, byPath []core.Value) (core.Value, error) {
from.Type(), from.Type(),
core.ArrayType, core.ArrayType,
core.ObjectType, core.ObjectType,
core.HtmlDocumentType, core.HTMLDocumentType,
core.HtmlElementType, core.HTMLElementType,
) )
} }
} }
@ -226,7 +226,7 @@ func Parse(input interface{}) core.Value {
size := v.Len() size := v.Len()
arr := NewArray(size) arr := NewArray(size)
for i := 0; i < size; i += 1 { for i := 0; i < size; i++ {
value := v.Index(i) value := v.Index(i)
arr.Push(Parse(value.Interface())) arr.Push(Parse(value.Interface()))
} }
@ -252,7 +252,7 @@ func Parse(input interface{}) core.Value {
obj := NewObject() obj := NewObject()
size := t.NumField() size := t.NumField()
for i := 0; i < size; i += 1 { for i := 0; i < size; i++ {
field := t.Field(i) field := t.Field(i)
value := v.Field(i) value := v.Field(i)

View File

@ -3,7 +3,7 @@ package values
import "github.com/MontFerret/ferret/pkg/runtime/core" import "github.com/MontFerret/ferret/pkg/runtime/core"
type ( type (
HtmlNode interface { HTMLNode interface {
core.Value core.Value
NodeType() Int NodeType() Int
@ -14,7 +14,7 @@ type (
InnerText() String InnerText() String
InnerHtml() String InnerHTML() String
Value() core.Value Value() core.Value
@ -31,9 +31,9 @@ type (
QuerySelectorAll(selector String) core.Value QuerySelectorAll(selector String) core.Value
} }
HtmlDocument interface { HTMLDocument interface {
HtmlNode HTMLNode
Url() core.Value URL() core.Value
} }
) )

View File

@ -20,8 +20,8 @@ func Length(_ context.Context, inputs ...core.Value) (core.Value, error) {
core.StringType, core.StringType,
core.ArrayType, core.ArrayType,
core.ObjectType, core.ObjectType,
core.HtmlElementType, core.HTMLElementType,
core.HtmlDocumentType, core.HTMLDocumentType,
core.BinaryType, core.BinaryType,
) )

View File

@ -23,13 +23,13 @@ func Click(_ context.Context, args ...core.Value) (core.Value, error) {
if len(args) == 1 { if len(args) == 1 {
arg1 := args[0] arg1 := args[0]
err := core.ValidateType(arg1, core.HtmlElementType) err := core.ValidateType(arg1, core.HTMLElementType)
if err != nil { if err != nil {
return values.False, err return values.False, err
} }
el, ok := arg1.(*dynamic.HtmlElement) el, ok := arg1.(*dynamic.HTMLElement)
if !ok { if !ok {
return values.False, core.Error(core.ErrInvalidType, "expected dynamic element") return values.False, core.Error(core.ErrInvalidType, "expected dynamic element")
@ -42,13 +42,13 @@ func Click(_ context.Context, args ...core.Value) (core.Value, error) {
arg1 := args[0] arg1 := args[0]
selector := args[1].String() selector := args[1].String()
err = core.ValidateType(arg1, core.HtmlDocumentType) err = core.ValidateType(arg1, core.HTMLDocumentType)
if err != nil { if err != nil {
return values.None, err return values.None, err
} }
doc, ok := arg1.(*dynamic.HtmlDocument) doc, ok := arg1.(*dynamic.HTMLDocument)
if !ok { if !ok {
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document") return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
@ -73,13 +73,13 @@ func ClickAll(_ context.Context, args ...core.Value) (core.Value, error) {
arg1 := args[0] arg1 := args[0]
selector := args[1].String() selector := args[1].String()
err = core.ValidateType(arg1, core.HtmlDocumentType) err = core.ValidateType(arg1, core.HTMLDocumentType)
if err != nil { if err != nil {
return values.None, err return values.None, err
} }
doc, ok := arg1.(*dynamic.HtmlDocument) doc, ok := arg1.(*dynamic.HTMLDocument)
if !ok { if !ok {
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document") return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
@ -102,7 +102,7 @@ func Navigate(_ context.Context, args ...core.Value) (core.Value, error) {
return values.None, err return values.None, err
} }
err = core.ValidateType(args[0], core.HtmlDocumentType) err = core.ValidateType(args[0], core.HTMLDocumentType)
if err != nil { if err != nil {
return values.None, err return values.None, err
@ -114,7 +114,7 @@ func Navigate(_ context.Context, args ...core.Value) (core.Value, error) {
return values.None, err return values.None, err
} }
doc, ok := args[0].(*dynamic.HtmlDocument) doc, ok := args[0].(*dynamic.HTMLDocument)
if !ok { if !ok {
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document") return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
@ -141,13 +141,13 @@ func Input(_ context.Context, args ...core.Value) (core.Value, error) {
if len(args) == 2 { if len(args) == 2 {
arg1 := args[0] arg1 := args[0]
err := core.ValidateType(arg1, core.HtmlElementType) err := core.ValidateType(arg1, core.HTMLElementType)
if err != nil { if err != nil {
return values.False, err return values.False, err
} }
el, ok := arg1.(*dynamic.HtmlElement) el, ok := arg1.(*dynamic.HTMLElement)
if !ok { if !ok {
return values.False, core.Error(core.ErrInvalidType, "expected dynamic element") return values.False, core.Error(core.ErrInvalidType, "expected dynamic element")
@ -164,7 +164,7 @@ func Input(_ context.Context, args ...core.Value) (core.Value, error) {
arg1 := args[0] arg1 := args[0]
err = core.ValidateType(arg1, core.HtmlDocumentType) err = core.ValidateType(arg1, core.HTMLDocumentType)
if err != nil { if err != nil {
return values.False, err return values.False, err
@ -178,7 +178,7 @@ func Input(_ context.Context, args ...core.Value) (core.Value, error) {
return values.False, err return values.False, err
} }
doc, ok := arg1.(*dynamic.HtmlDocument) doc, ok := arg1.(*dynamic.HTMLDocument)
if !ok { if !ok {
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document") return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")

View File

@ -13,7 +13,7 @@ import (
* @param selector (String) - Selector * @param selector (String) - Selector
* @returns str (String) - String value of inner html. * @returns str (String) - String value of inner html.
*/ */
func InnerHtml(_ context.Context, args ...core.Value) (core.Value, error) { func InnerHTML(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2) err := core.ValidateArgs(args, 2, 2)
if err != nil { if err != nil {
@ -23,19 +23,19 @@ func InnerHtml(_ context.Context, args ...core.Value) (core.Value, error) {
arg1 := args[0] arg1 := args[0]
selector := args[1].String() selector := args[1].String()
err = core.ValidateType(arg1, core.HtmlDocumentType) err = core.ValidateType(arg1, core.HTMLDocumentType)
if err != nil { if err != nil {
return values.None, err return values.None, err
} }
doc, ok := arg1.(*dynamic.HtmlDocument) doc, ok := arg1.(*dynamic.HTMLDocument)
if !ok { if !ok {
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
} }
return doc.InnerHtmlBySelector(values.NewString(selector)) return doc.InnerHTMLBySelector(values.NewString(selector))
} }
/* /*
@ -44,7 +44,7 @@ func InnerHtml(_ context.Context, args ...core.Value) (core.Value, error) {
* @param selector (String) - Selector * @param selector (String) - Selector
* @returns array (Array) - Array of string values. * @returns array (Array) - Array of string values.
*/ */
func InnerHtmlAll(_ context.Context, args ...core.Value) (core.Value, error) { func InnerHTMLAll(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2) err := core.ValidateArgs(args, 2, 2)
if err != nil { if err != nil {
@ -54,19 +54,19 @@ func InnerHtmlAll(_ context.Context, args ...core.Value) (core.Value, error) {
arg1 := args[0] arg1 := args[0]
selector := args[1].String() selector := args[1].String()
err = core.ValidateType(arg1, core.HtmlDocumentType) err = core.ValidateType(arg1, core.HTMLDocumentType)
if err != nil { if err != nil {
return values.None, err return values.None, err
} }
doc, ok := arg1.(*dynamic.HtmlDocument) doc, ok := arg1.(*dynamic.HTMLDocument)
if !ok { if !ok {
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
} }
return doc.InnerHtmlBySelectorAll(values.NewString(selector)) return doc.InnerHTMLBySelectorAll(values.NewString(selector))
} }
/* /*
@ -85,19 +85,19 @@ func InnerText(_ context.Context, args ...core.Value) (core.Value, error) {
arg1 := args[0] arg1 := args[0]
selector := args[1].String() selector := args[1].String()
err = core.ValidateType(arg1, core.HtmlDocumentType) err = core.ValidateType(arg1, core.HTMLDocumentType)
if err != nil { if err != nil {
return values.None, err return values.None, err
} }
doc, ok := arg1.(*dynamic.HtmlDocument) doc, ok := arg1.(*dynamic.HTMLDocument)
if !ok { if !ok {
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
} }
return doc.InnerHtmlBySelector(values.NewString(selector)) return doc.InnerHTMLBySelector(values.NewString(selector))
} }
/* /*
@ -116,17 +116,17 @@ func InnerTextAll(_ context.Context, args ...core.Value) (core.Value, error) {
arg1 := args[0] arg1 := args[0]
selector := args[1].String() selector := args[1].String()
err = core.ValidateType(arg1, core.HtmlDocumentType) err = core.ValidateType(arg1, core.HTMLDocumentType)
if err != nil { if err != nil {
return values.None, err return values.None, err
} }
doc, ok := arg1.(*dynamic.HtmlDocument) doc, ok := arg1.(*dynamic.HTMLDocument)
if !ok { if !ok {
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
} }
return doc.InnerHtmlBySelectorAll(values.NewString(selector)) return doc.InnerHTMLBySelectorAll(values.NewString(selector))
} }

View File

@ -2,7 +2,7 @@ package common
import "golang.org/x/net/html" import "golang.org/x/net/html"
func ToHtmlType(nt html.NodeType) int { func ToHTMLType(nt html.NodeType) int {
switch nt { switch nt {
case html.DocumentNode: case html.DocumentNode:
return 9 return 9

View File

@ -17,7 +17,7 @@ const (
) )
type Driver interface { type Driver interface {
GetDocument(ctx context.Context, url string) (values.HtmlNode, error) GetDocument(ctx context.Context, url string) (values.HTMLNode, error)
Close() error Close() error
} }

View File

@ -21,23 +21,24 @@ import (
"time" "time"
) )
const BlankPageUrl = "about:blank"
type HtmlDocument struct { const BlankPageURL = "about:blank"
type HTMLDocument struct {
sync.Mutex sync.Mutex
logger *zerolog.Logger logger *zerolog.Logger
conn *rpcc.Conn conn *rpcc.Conn
client *cdp.Client client *cdp.Client
events *events.EventBroker events *events.EventBroker
url values.String url values.String
element *HtmlElement element *HTMLElement
} }
func LoadHtmlDocument( func LoadHTMLDocument(
ctx context.Context, ctx context.Context,
conn *rpcc.Conn, conn *rpcc.Conn,
url string, url string,
) (*HtmlDocument, error) { ) (*HTMLDocument, error) {
if conn == nil { if conn == nil {
return nil, core.Error(core.ErrMissedArgument, "connection") return nil, core.Error(core.ErrMissedArgument, "connection")
} }
@ -80,7 +81,7 @@ func LoadHtmlDocument(
return nil, err return nil, err
} }
if url != BlankPageUrl { if url != BlankPageURL {
err = waitForLoadEvent(ctx, client) err = waitForLoadEvent(ctx, client)
if err != nil { if err != nil {
@ -88,7 +89,7 @@ func LoadHtmlDocument(
} }
} }
root, innerHtml, err := getRootElement(client) root, innerHTML, err := getRootElement(client)
if err != nil { if err != nil {
return nil, err return nil, err
@ -100,13 +101,13 @@ func LoadHtmlDocument(
return nil, err return nil, err
} }
return NewHtmlDocument( return NewHTMLDocument(
logging.FromContext(ctx), logging.FromContext(ctx),
conn, conn,
client, client,
broker, broker,
root, root,
innerHtml, innerHTML,
), nil ), nil
} }
@ -121,29 +122,29 @@ func getRootElement(client *cdp.Client) (dom.Node, values.String, error) {
return dom.Node{}, values.EmptyString, err return dom.Node{}, values.EmptyString, err
} }
innerHtml, err := client.DOM.GetOuterHTML(ctx, dom.NewGetOuterHTMLArgs().SetNodeID(d.Root.NodeID)) innerHTML, err := client.DOM.GetOuterHTML(ctx, dom.NewGetOuterHTMLArgs().SetNodeID(d.Root.NodeID))
if err != nil { if err != nil {
return dom.Node{}, values.EmptyString, err return dom.Node{}, values.EmptyString, err
} }
return d.Root, values.NewString(innerHtml.OuterHTML), nil return d.Root, values.NewString(innerHTML.OuterHTML), nil
} }
func NewHtmlDocument( func NewHTMLDocument(
logger *zerolog.Logger, logger *zerolog.Logger,
conn *rpcc.Conn, conn *rpcc.Conn,
client *cdp.Client, client *cdp.Client,
broker *events.EventBroker, broker *events.EventBroker,
root dom.Node, root dom.Node,
innerHtml values.String, innerHTML values.String,
) *HtmlDocument { ) *HTMLDocument {
doc := new(HtmlDocument) doc := new(HTMLDocument)
doc.logger = logger doc.logger = logger
doc.conn = conn doc.conn = conn
doc.client = client doc.client = client
doc.events = broker doc.events = broker
doc.element = NewHtmlElement(doc.logger, client, broker, root.NodeID, root, innerHtml) doc.element = NewHTMLElement(doc.logger, client, broker, root.NodeID, root, innerHTML)
doc.url = "" doc.url = ""
if root.BaseURL != nil { if root.BaseURL != nil {
@ -154,7 +155,7 @@ func NewHtmlDocument(
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
updated, innerHtml, err := getRootElement(client) updated, innerHTML, err := getRootElement(client)
if err != nil { if err != nil {
doc.logger.Error(). doc.logger.Error().
@ -169,7 +170,7 @@ func NewHtmlDocument(
doc.element.Close() doc.element.Close()
// create a new root element wrapper // create a new root element wrapper
doc.element = NewHtmlElement(doc.logger, client, broker, updated.NodeID, updated, innerHtml) doc.element = NewHTMLElement(doc.logger, client, broker, updated.NodeID, updated, innerHTML)
doc.url = "" doc.url = ""
if updated.BaseURL != nil { if updated.BaseURL != nil {
@ -180,32 +181,32 @@ func NewHtmlDocument(
return doc return doc
} }
func (doc *HtmlDocument) MarshalJSON() ([]byte, error) { func (doc *HTMLDocument) MarshalJSON() ([]byte, error) {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.MarshalJSON() return doc.element.MarshalJSON()
} }
func (doc *HtmlDocument) Type() core.Type { func (doc *HTMLDocument) Type() core.Type {
return core.HtmlDocumentType return core.HTMLDocumentType
} }
func (doc *HtmlDocument) String() string { func (doc *HTMLDocument) String() string {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.url.String() return doc.url.String()
} }
func (doc *HtmlDocument) Unwrap() interface{} { func (doc *HTMLDocument) Unwrap() interface{} {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element return doc.element
} }
func (doc *HtmlDocument) Hash() uint64 { func (doc *HTMLDocument) Hash() uint64 {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
@ -218,21 +219,21 @@ func (doc *HtmlDocument) Hash() uint64 {
return h.Sum64() return h.Sum64()
} }
func (doc *HtmlDocument) Clone() core.Value { func (doc *HTMLDocument) Clone() core.Value {
return values.None return values.None
} }
func (doc *HtmlDocument) Compare(other core.Value) int { func (doc *HTMLDocument) Compare(other core.Value) int {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
switch other.Type() { switch other.Type() {
case core.HtmlDocumentType: case core.HTMLDocumentType:
other := other.(*HtmlDocument) other := other.(*HTMLDocument)
return doc.url.Compare(other.url) return doc.url.Compare(other.url)
default: default:
if other.Type() > core.HtmlDocumentType { if other.Type() > core.HTMLDocumentType {
return -1 return -1
} }
@ -240,7 +241,7 @@ func (doc *HtmlDocument) Compare(other core.Value) int {
} }
} }
func (doc *HtmlDocument) Close() error { func (doc *HTMLDocument) Close() error {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
@ -289,95 +290,95 @@ func (doc *HtmlDocument) Close() error {
return doc.conn.Close() return doc.conn.Close()
} }
func (doc *HtmlDocument) NodeType() values.Int { func (doc *HTMLDocument) NodeType() values.Int {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.NodeType() return doc.element.NodeType()
} }
func (doc *HtmlDocument) NodeName() values.String { func (doc *HTMLDocument) NodeName() values.String {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.NodeName() return doc.element.NodeName()
} }
func (doc *HtmlDocument) Length() values.Int { func (doc *HTMLDocument) Length() values.Int {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.Length() return doc.element.Length()
} }
func (doc *HtmlDocument) InnerText() values.String { func (doc *HTMLDocument) InnerText() values.String {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.InnerText() return doc.element.InnerText()
} }
func (doc *HtmlDocument) InnerHtml() values.String { func (doc *HTMLDocument) InnerHTML() values.String {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.InnerHtml() return doc.element.InnerHTML()
} }
func (doc *HtmlDocument) Value() core.Value { func (doc *HTMLDocument) Value() core.Value {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.Value() return doc.element.Value()
} }
func (doc *HtmlDocument) GetAttributes() core.Value { func (doc *HTMLDocument) GetAttributes() core.Value {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.GetAttributes() return doc.element.GetAttributes()
} }
func (doc *HtmlDocument) GetAttribute(name values.String) core.Value { func (doc *HTMLDocument) GetAttribute(name values.String) core.Value {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.GetAttribute(name) return doc.element.GetAttribute(name)
} }
func (doc *HtmlDocument) GetChildNodes() core.Value { func (doc *HTMLDocument) GetChildNodes() core.Value {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.GetChildNodes() return doc.element.GetChildNodes()
} }
func (doc *HtmlDocument) GetChildNode(idx values.Int) core.Value { func (doc *HTMLDocument) GetChildNode(idx values.Int) core.Value {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.GetChildNode(idx) return doc.element.GetChildNode(idx)
} }
func (doc *HtmlDocument) QuerySelector(selector values.String) core.Value { func (doc *HTMLDocument) QuerySelector(selector values.String) core.Value {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.QuerySelector(selector) return doc.element.QuerySelector(selector)
} }
func (doc *HtmlDocument) QuerySelectorAll(selector values.String) core.Value { func (doc *HTMLDocument) QuerySelectorAll(selector values.String) core.Value {
doc.Lock() doc.Lock()
defer doc.Unlock() defer doc.Unlock()
return doc.element.QuerySelectorAll(selector) return doc.element.QuerySelectorAll(selector)
} }
func (doc *HtmlDocument) Url() core.Value { func (doc *HTMLDocument) URL() core.Value {
return doc.url return doc.url
} }
func (doc *HtmlDocument) InnerHtmlBySelector(selector values.String) (values.String, error) { func (doc *HTMLDocument) InnerHTMLBySelector(selector values.String) (values.String, error) {
res, err := eval.Eval( res, err := eval.Eval(
doc.client, doc.client,
fmt.Sprintf(` fmt.Sprintf(`
@ -387,7 +388,7 @@ func (doc *HtmlDocument) InnerHtmlBySelector(selector values.String) (values.Str
return ""; return "";
} }
return el.innerHtml; return el.innerHTML;
`, eval.ParamString(selector.String())), `, eval.ParamString(selector.String())),
true, true,
false, false,
@ -404,7 +405,7 @@ func (doc *HtmlDocument) InnerHtmlBySelector(selector values.String) (values.Str
return values.EmptyString, nil return values.EmptyString, nil
} }
func (doc *HtmlDocument) InnerHtmlBySelectorAll(selector values.String) (*values.Array, error) { func (doc *HTMLDocument) InnerHTMLBySelectorAll(selector values.String) (*values.Array, error) {
res, err := eval.Eval( res, err := eval.Eval(
doc.client, doc.client,
fmt.Sprintf(` fmt.Sprintf(`
@ -416,7 +417,7 @@ func (doc *HtmlDocument) InnerHtmlBySelectorAll(selector values.String) (*values
} }
elements.forEach((i) => { elements.forEach((i) => {
result.push(i.innerHtml); result.push(i.innerHTML);
}); });
return result; return result;
@ -436,7 +437,7 @@ func (doc *HtmlDocument) InnerHtmlBySelectorAll(selector values.String) (*values
return values.NewArray(0), nil return values.NewArray(0), nil
} }
func (doc *HtmlDocument) InnerTextBySelector(selector values.String) (values.String, error) { func (doc *HTMLDocument) InnerTextBySelector(selector values.String) (values.String, error) {
res, err := eval.Eval( res, err := eval.Eval(
doc.client, doc.client,
fmt.Sprintf(` fmt.Sprintf(`
@ -463,7 +464,7 @@ func (doc *HtmlDocument) InnerTextBySelector(selector values.String) (values.Str
return values.EmptyString, nil return values.EmptyString, nil
} }
func (doc *HtmlDocument) InnerTextBySelectorAll(selector values.String) (*values.Array, error) { func (doc *HTMLDocument) InnerTextBySelectorAll(selector values.String) (*values.Array, error) {
res, err := eval.Eval( res, err := eval.Eval(
doc.client, doc.client,
fmt.Sprintf(` fmt.Sprintf(`
@ -495,7 +496,7 @@ func (doc *HtmlDocument) InnerTextBySelectorAll(selector values.String) (*values
return values.NewArray(0), nil return values.NewArray(0), nil
} }
func (doc *HtmlDocument) ClickBySelector(selector values.String) (values.Boolean, error) { func (doc *HTMLDocument) ClickBySelector(selector values.String) (values.Boolean, error) {
res, err := eval.Eval( res, err := eval.Eval(
doc.client, doc.client,
fmt.Sprintf(` fmt.Sprintf(`
@ -525,7 +526,7 @@ func (doc *HtmlDocument) ClickBySelector(selector values.String) (values.Boolean
return values.False, nil return values.False, nil
} }
func (doc *HtmlDocument) ClickBySelectorAll(selector values.String) (values.Boolean, error) { func (doc *HTMLDocument) ClickBySelectorAll(selector values.String) (values.Boolean, error) {
res, err := eval.Eval( res, err := eval.Eval(
doc.client, doc.client,
fmt.Sprintf(` fmt.Sprintf(`
@ -557,7 +558,7 @@ func (doc *HtmlDocument) ClickBySelectorAll(selector values.String) (values.Bool
return values.False, nil return values.False, nil
} }
func (doc *HtmlDocument) InputBySelector(selector values.String, value core.Value) (values.Boolean, error) { func (doc *HTMLDocument) InputBySelector(selector values.String, value core.Value) (values.Boolean, error) {
res, err := eval.Eval( res, err := eval.Eval(
doc.client, doc.client,
fmt.Sprintf( fmt.Sprintf(
@ -593,7 +594,7 @@ func (doc *HtmlDocument) InputBySelector(selector values.String, value core.Valu
return values.False, nil return values.False, nil
} }
func (doc *HtmlDocument) WaitForSelector(selector values.String, timeout values.Int) error { func (doc *HTMLDocument) WaitForSelector(selector values.String, timeout values.Int) error {
task := events.NewWaitTask( task := events.NewWaitTask(
doc.client, doc.client,
fmt.Sprintf(` fmt.Sprintf(`
@ -614,7 +615,7 @@ func (doc *HtmlDocument) WaitForSelector(selector values.String, timeout values.
return err return err
} }
func (doc *HtmlDocument) WaitForNavigation(timeout values.Int) error { func (doc *HTMLDocument) WaitForNavigation(timeout values.Int) error {
timer := time.NewTimer(time.Millisecond * time.Duration(timeout)) timer := time.NewTimer(time.Millisecond * time.Duration(timeout))
onEvent := make(chan bool) onEvent := make(chan bool)
listener := func(_ interface{}) { listener := func(_ interface{}) {
@ -638,9 +639,9 @@ func (doc *HtmlDocument) WaitForNavigation(timeout values.Int) error {
} }
} }
func (doc *HtmlDocument) Navigate(url values.String) error { func (doc *HTMLDocument) Navigate(url values.String) error {
if url == "" { if url == "" {
url = BlankPageUrl url = BlankPageURL
} }
ctx := context.Background() ctx := context.Background()

View File

@ -28,7 +28,7 @@ func NewDriver(address string) *Driver {
return drv return drv
} }
func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode, error) { func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HTMLNode, error) {
err := drv.init(ctx) err := drv.init(ctx)
if err != nil { if err != nil {
@ -39,7 +39,7 @@ func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode
defer cancel() defer cancel()
if url == "" { if url == "" {
url = BlankPageUrl url = BlankPageURL
} }
// Create a new target belonging to the browser context, similar // Create a new target belonging to the browser context, similar
@ -58,7 +58,7 @@ func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode
return nil, err return nil, err
} }
return LoadHtmlDocument(ctx, conn, url) return LoadHTMLDocument(ctx, conn, url)
} }
func (drv *Driver) Close() error { func (drv *Driver) Close() error {

View File

@ -21,7 +21,7 @@ import (
const DefaultTimeout = time.Second * 30 const DefaultTimeout = time.Second * 30
type HtmlElement struct { type HTMLElement struct {
sync.Mutex sync.Mutex
logger *zerolog.Logger logger *zerolog.Logger
client *cdp.Client client *cdp.Client
@ -30,7 +30,7 @@ type HtmlElement struct {
id dom.NodeID id dom.NodeID
nodeType values.Int nodeType values.Int
nodeName values.String nodeName values.String
innerHtml values.String innerHTML values.String
innerText *common.LazyValue innerText *common.LazyValue
value core.Value value core.Value
rawAttrs []string rawAttrs []string
@ -44,7 +44,7 @@ func LoadElement(
client *cdp.Client, client *cdp.Client,
broker *events.EventBroker, broker *events.EventBroker,
id dom.NodeID, id dom.NodeID,
) (*HtmlElement, error) { ) (*HTMLElement, error) {
if client == nil { if client == nil {
return nil, core.Error(core.ErrMissedArgument, "client") return nil, core.Error(core.ErrMissedArgument, "client")
} }
@ -65,31 +65,31 @@ func LoadElement(
return nil, core.Error(err, strconv.Itoa(int(id))) return nil, core.Error(err, strconv.Itoa(int(id)))
} }
innerHtml, err := loadInnerHtml(client, id) innerHTML, err := loadInnerHTML(client, id)
if err != nil { if err != nil {
return nil, core.Error(err, strconv.Itoa(int(id))) return nil, core.Error(err, strconv.Itoa(int(id)))
} }
return NewHtmlElement( return NewHTMLElement(
logger, logger,
client, client,
broker, broker,
id, id,
node.Node, node.Node,
innerHtml, innerHTML,
), nil ), nil
} }
func NewHtmlElement( func NewHTMLElement(
logger *zerolog.Logger, logger *zerolog.Logger,
client *cdp.Client, client *cdp.Client,
broker *events.EventBroker, broker *events.EventBroker,
id dom.NodeID, id dom.NodeID,
node dom.Node, node dom.Node,
innerHtml values.String, innerHTML values.String,
) *HtmlElement { ) *HTMLElement {
el := new(HtmlElement) el := new(HTMLElement)
el.logger = logger el.logger = logger
el.client = client el.client = client
el.broker = broker el.broker = broker
@ -97,7 +97,7 @@ func NewHtmlElement(
el.id = id el.id = id
el.nodeType = values.NewInt(node.NodeType) el.nodeType = values.NewInt(node.NodeType)
el.nodeName = values.NewString(node.NodeName) el.nodeName = values.NewString(node.NodeName)
el.innerHtml = innerHtml el.innerHTML = innerHTML
el.innerText = common.NewLazyValue(el.loadInnerText) el.innerText = common.NewLazyValue(el.loadInnerText)
el.rawAttrs = node.Attributes[:] el.rawAttrs = node.Attributes[:]
el.attributes = common.NewLazyValue(el.loadAttrs) el.attributes = common.NewLazyValue(el.loadAttrs)
@ -120,7 +120,7 @@ func NewHtmlElement(
return el return el
} }
func (el *HtmlElement) Close() error { func (el *HTMLElement) Close() error {
el.Lock() el.Lock()
defer el.Unlock() defer el.Unlock()
@ -140,11 +140,11 @@ func (el *HtmlElement) Close() error {
return nil return nil
} }
func (el *HtmlElement) Type() core.Type { func (el *HTMLElement) Type() core.Type {
return core.HtmlElementType return core.HTMLElementType
} }
func (el *HtmlElement) MarshalJSON() ([]byte, error) { func (el *HTMLElement) MarshalJSON() ([]byte, error) {
val, err := el.innerText.Value() val, err := el.innerText.Value()
if err != nil { if err != nil {
@ -154,29 +154,29 @@ func (el *HtmlElement) MarshalJSON() ([]byte, error) {
return json.Marshal(val.String()) return json.Marshal(val.String())
} }
func (el *HtmlElement) String() string { func (el *HTMLElement) String() string {
return el.InnerHtml().String() return el.InnerHTML().String()
} }
func (el *HtmlElement) Compare(other core.Value) int { func (el *HTMLElement) Compare(other core.Value) int {
switch other.Type() { switch other.Type() {
case core.HtmlDocumentType: case core.HTMLDocumentType:
other := other.(*HtmlElement) other := other.(*HTMLElement)
id := int(el.id) id := int(el.id)
otherId := int(other.id) otherID := int(other.id)
if id == otherId { if id == otherID {
return 0 return 0
} }
if id > otherId { if id > otherID {
return 1 return 1
} }
return -1 return -1
default: default:
if other.Type() > core.HtmlElementType { if other.Type() > core.HTMLElementType {
return -1 return -1
} }
@ -184,11 +184,12 @@ func (el *HtmlElement) Compare(other core.Value) int {
} }
} }
func (el *HtmlElement) Unwrap() interface{} { func (el *HTMLElement) Unwrap() interface{} {
return el return el
} }
func (el *HtmlElement) Hash() uint64 {
func (el *HTMLElement) Hash() uint64 {
el.Lock() el.Lock()
defer el.Unlock() defer el.Unlock()
@ -196,12 +197,12 @@ func (el *HtmlElement) Hash() uint64 {
h.Write([]byte(el.Type().String())) h.Write([]byte(el.Type().String()))
h.Write([]byte(":")) h.Write([]byte(":"))
h.Write([]byte(el.innerHtml)) h.Write([]byte(el.innerHTML))
return h.Sum64() return h.Sum64()
} }
func (el *HtmlElement) Value() core.Value { func (el *HTMLElement) Value() core.Value {
if !el.IsConnected() { if !el.IsConnected() {
return el.value return el.value
} }
@ -225,23 +226,23 @@ func (el *HtmlElement) Value() core.Value {
return val return val
} }
func (el *HtmlElement) Clone() core.Value { func (el *HTMLElement) Clone() core.Value {
return values.None return values.None
} }
func (el *HtmlElement) Length() values.Int { func (el *HTMLElement) Length() values.Int {
return values.NewInt(len(el.children)) return values.NewInt(len(el.children))
} }
func (el *HtmlElement) NodeType() values.Int { func (el *HTMLElement) NodeType() values.Int {
return el.nodeType return el.nodeType
} }
func (el *HtmlElement) NodeName() values.String { func (el *HTMLElement) NodeName() values.String {
return el.nodeName return el.nodeName
} }
func (el *HtmlElement) GetAttributes() core.Value { func (el *HTMLElement) GetAttributes() core.Value {
val, err := el.attributes.Value() val, err := el.attributes.Value()
if err != nil { if err != nil {
@ -252,7 +253,7 @@ func (el *HtmlElement) GetAttributes() core.Value {
return val.Clone() return val.Clone()
} }
func (el *HtmlElement) GetAttribute(name values.String) core.Value { func (el *HTMLElement) GetAttribute(name values.String) core.Value {
attrs, err := el.attributes.Value() attrs, err := el.attributes.Value()
if err != nil { if err != nil {
@ -268,7 +269,7 @@ func (el *HtmlElement) GetAttribute(name values.String) core.Value {
return val return val
} }
func (el *HtmlElement) GetChildNodes() core.Value { func (el *HTMLElement) GetChildNodes() core.Value {
val, err := el.loadedChildren.Value() val, err := el.loadedChildren.Value()
if err != nil { if err != nil {
@ -278,7 +279,7 @@ func (el *HtmlElement) GetChildNodes() core.Value {
return val return val
} }
func (el *HtmlElement) GetChildNode(idx values.Int) core.Value { func (el *HTMLElement) GetChildNode(idx values.Int) core.Value {
val, err := el.loadedChildren.Value() val, err := el.loadedChildren.Value()
if err != nil { if err != nil {
@ -288,7 +289,7 @@ func (el *HtmlElement) GetChildNode(idx values.Int) core.Value {
return val.(*values.Array).Get(idx) return val.(*values.Array).Get(idx)
} }
func (el *HtmlElement) QuerySelector(selector values.String) core.Value { func (el *HTMLElement) QuerySelector(selector values.String) core.Value {
if !el.IsConnected() { if !el.IsConnected() {
return values.None return values.None
} }
@ -323,7 +324,7 @@ func (el *HtmlElement) QuerySelector(selector values.String) core.Value {
return res return res
} }
func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value { func (el *HTMLElement) QuerySelectorAll(selector values.String) core.Value {
if !el.IsConnected() { if !el.IsConnected() {
return values.NewArray(0) return values.NewArray(0)
} }
@ -364,7 +365,7 @@ func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value {
return arr return arr
} }
func (el *HtmlElement) InnerText() values.String { func (el *HTMLElement) InnerText() values.String {
val, err := el.innerText.Value() val, err := el.innerText.Value()
if err != nil { if err != nil {
@ -374,14 +375,14 @@ func (el *HtmlElement) InnerText() values.String {
return val.(values.String) return val.(values.String)
} }
func (el *HtmlElement) InnerHtml() values.String { func (el *HTMLElement) InnerHTML() values.String {
el.Lock() el.Lock()
defer el.Unlock() defer el.Unlock()
return el.innerHtml return el.innerHTML
} }
func (el *HtmlElement) Click() (values.Boolean, error) { func (el *HTMLElement) Click() (values.Boolean, error) {
ctx, cancel := contextWithTimeout() ctx, cancel := contextWithTimeout()
defer cancel() defer cancel()
@ -389,22 +390,22 @@ func (el *HtmlElement) Click() (values.Boolean, error) {
return events.DispatchEvent(ctx, el.client, el.id, "click") return events.DispatchEvent(ctx, el.client, el.id, "click")
} }
func (el *HtmlElement) Input(value core.Value) error { func (el *HTMLElement) Input(value core.Value) error {
ctx, cancel := contextWithTimeout() ctx, cancel := contextWithTimeout()
defer cancel() defer cancel()
return el.client.DOM.SetAttributeValue(ctx, dom.NewSetAttributeValueArgs(el.id, "value", value.String())) return el.client.DOM.SetAttributeValue(ctx, dom.NewSetAttributeValueArgs(el.id, "value", value.String()))
} }
func (el *HtmlElement) IsConnected() values.Boolean { func (el *HTMLElement) IsConnected() values.Boolean {
el.Lock() el.Lock()
defer el.Unlock() defer el.Unlock()
return el.connected return el.connected
} }
func (el *HtmlElement) loadInnerText() (core.Value, error) { func (el *HTMLElement) loadInnerText() (core.Value, error) {
h := el.InnerHtml() h := el.InnerHTML()
if h == values.EmptyString { if h == values.EmptyString {
return h, nil return h, nil
@ -427,11 +428,11 @@ func (el *HtmlElement) loadInnerText() (core.Value, error) {
return values.NewString(parsed.Text()), nil return values.NewString(parsed.Text()), nil
} }
func (el *HtmlElement) loadAttrs() (core.Value, error) { func (el *HTMLElement) loadAttrs() (core.Value, error) {
return parseAttrs(el.rawAttrs), nil return parseAttrs(el.rawAttrs), nil
} }
func (el *HtmlElement) loadChildren() (core.Value, error) { func (el *HTMLElement) loadChildren() (core.Value, error) {
if !el.IsConnected() { if !el.IsConnected() {
return values.NewArray(0), nil return values.NewArray(0), nil
} }
@ -451,11 +452,11 @@ func (el *HtmlElement) loadChildren() (core.Value, error) {
return loaded, nil return loaded, nil
} }
func (el *HtmlElement) handlePageReload(message interface{}) { func (el *HTMLElement) handlePageReload(_ interface{}) {
el.Close() el.Close()
} }
func (el *HtmlElement) handleAttrModified(message interface{}) { func (el *HTMLElement) handleAttrModified(message interface{}) {
reply, ok := message.(*dom.AttributeModifiedReply) reply, ok := message.(*dom.AttributeModifiedReply)
// well.... // well....
@ -493,7 +494,7 @@ func (el *HtmlElement) handleAttrModified(message interface{}) {
attrs.Set(values.NewString(reply.Name), values.NewString(reply.Value)) attrs.Set(values.NewString(reply.Name), values.NewString(reply.Value))
} }
func (el *HtmlElement) handleAttrRemoved(message interface{}) { func (el *HTMLElement) handleAttrRemoved(message interface{}) {
reply, ok := message.(*dom.AttributeRemovedReply) reply, ok := message.(*dom.AttributeRemovedReply)
// well.... // well....
@ -532,7 +533,7 @@ func (el *HtmlElement) handleAttrRemoved(message interface{}) {
attrs.Remove(values.NewString(reply.Name)) attrs.Remove(values.NewString(reply.Name))
} }
func (el *HtmlElement) handleChildrenCountChanged(message interface{}) { func (el *HTMLElement) handleChildrenCountChanged(message interface{}) {
reply, ok := message.(*dom.ChildNodeCountUpdatedReply) reply, ok := message.(*dom.ChildNodeCountUpdatedReply)
if !ok { if !ok {
@ -561,7 +562,7 @@ func (el *HtmlElement) handleChildrenCountChanged(message interface{}) {
el.children = createChildrenArray(node.Node.Children) el.children = createChildrenArray(node.Node.Children)
} }
func (el *HtmlElement) handleChildInserted(message interface{}) { func (el *HTMLElement) handleChildInserted(message interface{}) {
reply, ok := message.(*dom.ChildNodeInsertedReply) reply, ok := message.(*dom.ChildNodeInsertedReply)
if !ok { if !ok {
@ -572,26 +573,26 @@ func (el *HtmlElement) handleChildInserted(message interface{}) {
return return
} }
targetIdx := -1 targetIDx := -1
prevId := reply.PreviousNodeID prevID := reply.PreviousNodeID
nextId := reply.Node.NodeID nextID := reply.Node.NodeID
el.Lock() el.Lock()
defer el.Unlock() defer el.Unlock()
for idx, id := range el.children { for idx, id := range el.children {
if id == prevId { if id == prevID {
targetIdx = idx targetIDx = idx
break break
} }
} }
if targetIdx == -1 { if targetIDx == -1 {
return return
} }
arr := el.children arr := el.children
el.children = append(arr[:targetIdx], append([]dom.NodeID{nextId}, arr[targetIdx:]...)...) el.children = append(arr[:targetIDx], append([]dom.NodeID{nextID}, arr[targetIDx:]...)...)
if !el.loadedChildren.Ready() { if !el.loadedChildren.Ready() {
return return
@ -604,7 +605,7 @@ func (el *HtmlElement) handleChildInserted(message interface{}) {
} }
loadedArr := loaded.(*values.Array) loadedArr := loaded.(*values.Array)
loadedEl, err := LoadElement(el.logger, el.client, el.broker, nextId) loadedEl, err := LoadElement(el.logger, el.client, el.broker, nextID)
if err != nil { if err != nil {
el.logger.Error(). el.logger.Error().
@ -616,9 +617,9 @@ func (el *HtmlElement) handleChildInserted(message interface{}) {
return return
} }
loadedArr.Insert(values.NewInt(targetIdx), loadedEl) loadedArr.Insert(values.NewInt(targetIDx), loadedEl)
newInnerHtml, err := loadInnerHtml(el.client, el.id) newInnerHTML, err := loadInnerHTML(el.client, el.id)
if err != nil { if err != nil {
el.logger.Error(). el.logger.Error().
@ -630,10 +631,10 @@ func (el *HtmlElement) handleChildInserted(message interface{}) {
return return
} }
el.innerHtml = newInnerHtml el.innerHTML = newInnerHTML
} }
func (el *HtmlElement) handleChildDeleted(message interface{}) { func (el *HTMLElement) handleChildDeleted(message interface{}) {
reply, ok := message.(*dom.ChildNodeRemovedReply) reply, ok := message.(*dom.ChildNodeRemovedReply)
if !ok { if !ok {
@ -644,25 +645,25 @@ func (el *HtmlElement) handleChildDeleted(message interface{}) {
return return
} }
targetIdx := -1 targetIDx := -1
targetId := reply.NodeID targetID := reply.NodeID
el.Lock() el.Lock()
defer el.Unlock() defer el.Unlock()
for idx, id := range el.children { for idx, id := range el.children {
if id == targetId { if id == targetID {
targetIdx = idx targetIDx = idx
break break
} }
} }
if targetIdx == -1 { if targetIDx == -1 {
return return
} }
arr := el.children arr := el.children
el.children = append(arr[:targetIdx], arr[targetIdx+1:]...) el.children = append(arr[:targetIDx], arr[targetIDx+1:]...)
if !el.loadedChildren.Ready() { if !el.loadedChildren.Ready() {
return return
@ -675,9 +676,9 @@ func (el *HtmlElement) handleChildDeleted(message interface{}) {
} }
loadedArr := loaded.(*values.Array) loadedArr := loaded.(*values.Array)
loadedArr.RemoveAt(values.NewInt(targetIdx)) loadedArr.RemoveAt(values.NewInt(targetIDx))
newInnerHtml, err := loadInnerHtml(el.client, el.id) newInnerHTML, err := loadInnerHTML(el.client, el.id)
if err != nil { if err != nil {
el.logger.Error(). el.logger.Error().
@ -689,5 +690,5 @@ func (el *HtmlElement) handleChildDeleted(message interface{}) {
return return
} }
el.innerHtml = newInnerHtml el.innerHTML = newInnerHTML
} }

View File

@ -87,7 +87,7 @@ func (broker *EventBroker) RemoveEventListener(event string, listener EventListe
return return
} }
var modifiedListeners []EventListener = nil var modifiedListeners []EventListener
if len(listeners) > 1 { if len(listeners) > 1 {
modifiedListeners = append(listeners[:idx], listeners[idx+1:]...) modifiedListeners = append(listeners[:idx], listeners[idx+1:]...)
@ -114,7 +114,7 @@ func (broker *EventBroker) Start() error {
for { for {
for name, event := range broker.events { for name, event := range broker.events {
counter += 1 counter++
select { select {
case <-ctx.Done(): case <-ctx.Done():

View File

@ -47,10 +47,10 @@ func DispatchEvent(
return values.False, nil return values.False, nil
} }
evtId := evt.Result.ObjectID evtID := evt.Result.ObjectID
// release the event object // release the event object
defer client.Runtime.ReleaseObject(ctx, runtime.NewReleaseObjectArgs(*evtId)) defer client.Runtime.ReleaseObject(ctx, runtime.NewReleaseObjectArgs(*evtID))
res, err := client.Runtime.CallFunctionOn( res, err := client.Runtime.CallFunctionOn(
ctx, ctx,

View File

@ -51,7 +51,7 @@ func parseAttrs(attrs []string) *values.Object {
return res return res
} }
func loadInnerHtml(client *cdp.Client, id dom.NodeID) (values.String, error) { func loadInnerHTML(client *cdp.Client, id dom.NodeID) (values.String, error) {
res, err := client.DOM.GetOuterHTML(context.Background(), dom.NewGetOuterHTMLArgs().SetNodeID(id)) res, err := client.DOM.GetOuterHTML(context.Background(), dom.NewGetOuterHTMLArgs().SetNodeID(id))
if err != nil { if err != nil {

View File

@ -6,15 +6,15 @@ import (
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
) )
type HtmlDocument struct { type HTMLDocument struct {
*HtmlElement *HTMLElement
url values.String url values.String
} }
func NewHtmlDocument( func NewHTMLDocument(
url string, url string,
node *goquery.Document, node *goquery.Document,
) (*HtmlDocument, error) { ) (*HTMLDocument, error) {
if url == "" { if url == "" {
return nil, core.Error(core.ErrMissedArgument, "document url") return nil, core.Error(core.ErrMissedArgument, "document url")
} }
@ -23,27 +23,27 @@ func NewHtmlDocument(
return nil, core.Error(core.ErrMissedArgument, "document root selection") return nil, core.Error(core.ErrMissedArgument, "document root selection")
} }
el, err := NewHtmlElement(node.Selection) el, err := NewHTMLElement(node.Selection)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &HtmlDocument{el, values.NewString(url)}, nil return &HTMLDocument{el, values.NewString(url)}, nil
} }
func (el *HtmlDocument) Type() core.Type { func (el *HTMLDocument) Type() core.Type {
return core.HtmlDocumentType return core.HTMLDocumentType
} }
func (el *HtmlDocument) Compare(other core.Value) int { func (el *HTMLDocument) Compare(other core.Value) int {
switch other.Type() { switch other.Type() {
case core.HtmlDocumentType: case core.HTMLDocumentType:
otherDoc := other.(values.HtmlDocument) otherDoc := other.(values.HTMLDocument)
return el.url.Compare(otherDoc.Url()) return el.url.Compare(otherDoc.URL())
default: default:
if other.Type() > core.HtmlDocumentType { if other.Type() > core.HTMLDocumentType {
return -1 return -1
} }
@ -51,6 +51,6 @@ func (el *HtmlDocument) Compare(other core.Value) int {
} }
} }
func (el *HtmlDocument) Url() core.Value { func (el *HTMLDocument) URL() core.Value {
return el.url return el.url
} }

View File

@ -228,7 +228,7 @@ func TestDocument(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
el, err := static.NewHtmlElement(doc.Selection) el, err := static.NewHTMLElement(doc.Selection)
So(err, ShouldBeNil) So(err, ShouldBeNil)

View File

@ -9,39 +9,39 @@ import (
"hash/fnv" "hash/fnv"
) )
type HtmlElement struct { type HTMLElement struct {
selection *goquery.Selection selection *goquery.Selection
attrs *values.Object attrs *values.Object
children *values.Array children *values.Array
} }
func NewHtmlElement(node *goquery.Selection) (*HtmlElement, error) { func NewHTMLElement(node *goquery.Selection) (*HTMLElement, error) {
if node == nil { if node == nil {
return nil, core.Error(core.ErrMissedArgument, "element selection") return nil, core.Error(core.ErrMissedArgument, "element selection")
} }
return &HtmlElement{node, nil, nil}, nil return &HTMLElement{node, nil, nil}, nil
} }
func (el *HtmlElement) MarshalJSON() ([]byte, error) { func (el *HTMLElement) MarshalJSON() ([]byte, error) {
return json.Marshal(el.InnerText().String()) return json.Marshal(el.InnerText().String())
} }
func (el *HtmlElement) Type() core.Type { func (el *HTMLElement) Type() core.Type {
return core.HtmlElementType return core.HTMLElementType
} }
func (el *HtmlElement) String() string { func (el *HTMLElement) String() string {
return el.InnerHtml().String() return el.InnerHTML().String()
} }
func (el *HtmlElement) Compare(other core.Value) int { func (el *HTMLElement) Compare(other core.Value) int {
switch other.Type() { switch other.Type() {
case core.HtmlElementType: case core.HTMLElementType:
// TODO: complete the comparison // TODO: complete the comparison
return -1 return -1
default: default:
if other.Type() > core.HtmlElementType { if other.Type() > core.HTMLElementType {
return -1 return -1
} }
@ -49,11 +49,12 @@ func (el *HtmlElement) Compare(other core.Value) int {
} }
} }
func (el *HtmlElement) Unwrap() interface{} { func (el *HTMLElement) Unwrap() interface{} {
return el.selection return el.selection
} }
func (el *HtmlElement) Hash() uint64 {
func (el *HTMLElement) Hash() uint64 {
str, err := el.selection.Html() str, err := el.selection.Html()
if err != nil { if err != nil {
@ -69,27 +70,27 @@ func (el *HtmlElement) Hash() uint64 {
return h.Sum64() return h.Sum64()
} }
func (el *HtmlElement) Clone() core.Value { func (el *HTMLElement) Clone() core.Value {
c, _ := NewHtmlElement(el.selection.Clone()) c, _ := NewHTMLElement(el.selection.Clone())
return c return c
} }
func (el *HtmlElement) NodeType() values.Int { func (el *HTMLElement) NodeType() values.Int {
nodes := el.selection.Nodes nodes := el.selection.Nodes
if len(nodes) == 0 { if len(nodes) == 0 {
return 0 return 0
} }
return values.NewInt(common.ToHtmlType(nodes[0].Type)) return values.NewInt(common.ToHTMLType(nodes[0].Type))
} }
func (el *HtmlElement) NodeName() values.String { func (el *HTMLElement) NodeName() values.String {
return values.NewString(goquery.NodeName(el.selection)) return values.NewString(goquery.NodeName(el.selection))
} }
func (el *HtmlElement) Length() values.Int { func (el *HTMLElement) Length() values.Int {
if el.children == nil { if el.children == nil {
el.children = el.parseChildren() el.children = el.parseChildren()
} }
@ -97,7 +98,7 @@ func (el *HtmlElement) Length() values.Int {
return el.children.Length() return el.children.Length()
} }
func (el *HtmlElement) Value() core.Value { func (el *HTMLElement) Value() core.Value {
val, ok := el.selection.Attr("value") val, ok := el.selection.Attr("value")
if ok { if ok {
@ -107,11 +108,11 @@ func (el *HtmlElement) Value() core.Value {
return values.EmptyString return values.EmptyString
} }
func (el *HtmlElement) InnerText() values.String { func (el *HTMLElement) InnerText() values.String {
return values.NewString(el.selection.Text()) return values.NewString(el.selection.Text())
} }
func (el *HtmlElement) InnerHtml() values.String { func (el *HTMLElement) InnerHTML() values.String {
h, err := el.selection.Html() h, err := el.selection.Html()
if err != nil { if err != nil {
@ -121,7 +122,7 @@ func (el *HtmlElement) InnerHtml() values.String {
return values.NewString(h) return values.NewString(h)
} }
func (el *HtmlElement) GetAttributes() core.Value { func (el *HTMLElement) GetAttributes() core.Value {
if el.attrs == nil { if el.attrs == nil {
el.attrs = el.parseAttrs() el.attrs = el.parseAttrs()
} }
@ -129,7 +130,7 @@ func (el *HtmlElement) GetAttributes() core.Value {
return el.attrs return el.attrs
} }
func (el *HtmlElement) GetAttribute(name values.String) core.Value { func (el *HTMLElement) GetAttribute(name values.String) core.Value {
v, ok := el.selection.Attr(name.String()) v, ok := el.selection.Attr(name.String())
if ok { if ok {
@ -139,7 +140,7 @@ func (el *HtmlElement) GetAttribute(name values.String) core.Value {
return values.None return values.None
} }
func (el *HtmlElement) GetChildNodes() core.Value { func (el *HTMLElement) GetChildNodes() core.Value {
if el.children == nil { if el.children == nil {
el.children = el.parseChildren() el.children = el.parseChildren()
} }
@ -147,7 +148,7 @@ func (el *HtmlElement) GetChildNodes() core.Value {
return el.children return el.children
} }
func (el *HtmlElement) GetChildNode(idx values.Int) core.Value { func (el *HTMLElement) GetChildNode(idx values.Int) core.Value {
if el.children == nil { if el.children == nil {
el.children = el.parseChildren() el.children = el.parseChildren()
} }
@ -155,14 +156,14 @@ func (el *HtmlElement) GetChildNode(idx values.Int) core.Value {
return el.children.Get(idx) return el.children.Get(idx)
} }
func (el *HtmlElement) QuerySelector(selector values.String) core.Value { func (el *HTMLElement) QuerySelector(selector values.String) core.Value {
selection := el.selection.Find(selector.String()) selection := el.selection.Find(selector.String())
if selection == nil { if selection == nil {
return values.None return values.None
} }
res, err := NewHtmlElement(selection) res, err := NewHTMLElement(selection)
if err != nil { if err != nil {
return values.None return values.None
@ -171,7 +172,7 @@ func (el *HtmlElement) QuerySelector(selector values.String) core.Value {
return res return res
} }
func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value { func (el *HTMLElement) QuerySelectorAll(selector values.String) core.Value {
selection := el.selection.Find(selector.String()) selection := el.selection.Find(selector.String())
if selection == nil { if selection == nil {
@ -181,7 +182,7 @@ func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value {
arr := values.NewArray(selection.Length()) arr := values.NewArray(selection.Length())
selection.Each(func(i int, selection *goquery.Selection) { selection.Each(func(i int, selection *goquery.Selection) {
el, err := NewHtmlElement(selection) el, err := NewHTMLElement(selection)
if err == nil { if err == nil {
arr.Push(el) arr.Push(el)
@ -191,7 +192,7 @@ func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value {
return arr return arr
} }
func (el *HtmlElement) parseAttrs() *values.Object { func (el *HTMLElement) parseAttrs() *values.Object {
obj := values.NewObject() obj := values.NewObject()
for _, name := range common.Attributes { for _, name := range common.Attributes {
@ -205,7 +206,7 @@ func (el *HtmlElement) parseAttrs() *values.Object {
return obj return obj
} }
func (el *HtmlElement) parseChildren() *values.Array { func (el *HTMLElement) parseChildren() *values.Array {
children := el.selection.Children() children := el.selection.Children()
arr := values.NewArray(10) arr := values.NewArray(10)
@ -213,14 +214,14 @@ func (el *HtmlElement) parseChildren() *values.Array {
children.Each(func(i int, selection *goquery.Selection) { children.Each(func(i int, selection *goquery.Selection) {
//name := goquery.NodeName(selection) //name := goquery.NodeName(selection)
//if name != "#text" && name != "#comment" { //if name != "#text" && name != "#comment" {
// child, err := NewHtmlElement(selection) // child, err := NewHTMLElement(selection)
// //
// if err == nil { // if err == nil {
// arr.Push(child) // arr.Push(child)
// } // }
//} //}
child, err := NewHtmlElement(selection) child, err := NewHTMLElement(selection)
if err == nil { if err == nil {
arr.Push(child) arr.Push(child)

View File

@ -250,7 +250,7 @@ func TestElement(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
el, err := static.NewHtmlElement(doc.Find("body")) el, err := static.NewHTMLElement(doc.Find("body"))
So(err, ShouldBeNil) So(err, ShouldBeNil)
@ -266,7 +266,7 @@ func TestElement(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
el, err := static.NewHtmlElement(doc.Find("body")) el, err := static.NewHTMLElement(doc.Find("body"))
So(err, ShouldBeNil) So(err, ShouldBeNil)
@ -290,7 +290,7 @@ func TestElement(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
el, err := static.NewHtmlElement(doc.Find("body")) el, err := static.NewHTMLElement(doc.Find("body"))
So(err, ShouldBeNil) So(err, ShouldBeNil)
@ -315,7 +315,7 @@ func TestElement(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
el, err := static.NewHtmlElement(doc.Find("#q")) el, err := static.NewHTMLElement(doc.Find("#q"))
So(err, ShouldBeNil) So(err, ShouldBeNil)
@ -342,7 +342,7 @@ func TestElement(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
el, err := static.NewHtmlElement(doc.Find("h2")) el, err := static.NewHTMLElement(doc.Find("h2"))
So(err, ShouldBeNil) So(err, ShouldBeNil)
@ -369,11 +369,11 @@ func TestElement(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
el, err := static.NewHtmlElement(doc.Find("#content")) el, err := static.NewHTMLElement(doc.Find("#content"))
So(err, ShouldBeNil) So(err, ShouldBeNil)
v := el.InnerHtml() v := el.InnerHTML()
So(v, ShouldEqual, "<h2>Ferret</h2>") So(v, ShouldEqual, "<h2>Ferret</h2>")
}) })
@ -385,7 +385,7 @@ func TestElement(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
el, err := static.NewHtmlElement(doc.Find("body .card-img-top:nth-child(1)")) el, err := static.NewHTMLElement(doc.Find("body .card-img-top:nth-child(1)"))
So(err, ShouldBeNil) So(err, ShouldBeNil)

View File

@ -28,7 +28,7 @@ func NewDriver(setters ...Option) *Driver {
return &Driver{client} return &Driver{client}
} }
func (d *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode, error) { func (d *Driver) GetDocument(_ context.Context, url string) (values.HTMLNode, error) {
req, err := httpx.NewRequest(httpx.MethodGet, url, nil) req, err := httpx.NewRequest(httpx.MethodGet, url, nil)
if err != nil { if err != nil {
@ -55,10 +55,10 @@ func (d *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode,
return nil, errors.Wrapf(err, "failed to parse a document %s", url) return nil, errors.Wrapf(err, "failed to parse a document %s", url)
} }
return NewHtmlDocument(url, doc) return NewHTMLDocument(url, doc)
} }
func (d *Driver) ParseDocument(ctx context.Context, str string) (values.HtmlNode, error) { func (d *Driver) ParseDocument(_ context.Context, str string) (values.HTMLNode, error) {
buf := bytes.NewBuffer([]byte(str)) buf := bytes.NewBuffer([]byte(str))
doc, err := goquery.NewDocumentFromReader(buf) doc, err := goquery.NewDocumentFromReader(buf)
@ -67,7 +67,7 @@ func (d *Driver) ParseDocument(ctx context.Context, str string) (values.HtmlNode
return nil, errors.Wrap(err, "failed to parse a document") return nil, errors.Wrap(err, "failed to parse a document")
} }
return NewHtmlDocument("#string", doc) return NewHTMLDocument("#string", doc)
} }
func (d *Driver) Close() error { func (d *Driver) Close() error {

View File

@ -26,7 +26,7 @@ func Elements(_ context.Context, inputs ...core.Value) (core.Value, error) {
return el.QuerySelectorAll(selector), nil return el.QuerySelectorAll(selector), nil
} }
func elementArgs(inputs []core.Value) (values.HtmlNode, values.String, error) { func elementArgs(inputs []core.Value) (values.HTMLNode, values.String, error) {
if len(inputs) == 0 { if len(inputs) == 0 {
return nil, values.EmptyString, core.Error(core.ErrMissedArgument, "element and arg2") return nil, values.EmptyString, core.Error(core.ErrMissedArgument, "element and arg2")
} }
@ -38,14 +38,14 @@ func elementArgs(inputs []core.Value) (values.HtmlNode, values.String, error) {
arg1 := inputs[0] arg1 := inputs[0]
arg2 := inputs[1] arg2 := inputs[1]
if arg1.Type() != core.HtmlDocumentType && if arg1.Type() != core.HTMLDocumentType &&
arg1.Type() != core.HtmlElementType { arg1.Type() != core.HTMLElementType {
return nil, values.EmptyString, core.TypeError(arg1.Type(), core.HtmlDocumentType, core.HtmlElementType) return nil, values.EmptyString, core.TypeError(arg1.Type(), core.HTMLDocumentType, core.HTMLElementType)
} }
if arg2.Type() != core.StringType { if arg2.Type() != core.StringType {
return nil, values.EmptyString, core.TypeError(arg2.Type(), core.StringType) return nil, values.EmptyString, core.TypeError(arg2.Type(), core.StringType)
} }
return arg1.(values.HtmlNode), arg2.(values.String), nil return arg1.(values.HTMLNode), arg2.(values.String), nil
} }

View File

@ -24,13 +24,13 @@ func WaitElement(_ context.Context, args ...core.Value) (core.Value, error) {
} }
} }
err = core.ValidateType(arg, core.HtmlDocumentType) err = core.ValidateType(arg, core.HTMLDocumentType)
if err != nil { if err != nil {
return values.None, err return values.None, err
} }
doc, ok := arg.(*dynamic.HtmlDocument) doc, ok := arg.(*dynamic.HTMLDocument)
if !ok { if !ok {
return values.False, core.Error(core.ErrInvalidType, "expected dynamic document") return values.False, core.Error(core.ErrInvalidType, "expected dynamic document")
@ -46,13 +46,13 @@ func WaitNavigation(_ context.Context, args ...core.Value) (core.Value, error) {
return values.None, err return values.None, err
} }
err = core.ValidateType(args[0], core.HtmlDocumentType) err = core.ValidateType(args[0], core.HTMLDocumentType)
if err != nil { if err != nil {
return values.None, err return values.None, err
} }
doc, ok := args[0].(*dynamic.HtmlDocument) doc, ok := args[0].(*dynamic.HTMLDocument)
if !ok { if !ok {
return values.None, core.Error(core.ErrInvalidType, "expected dynamic document") return values.None, core.Error(core.ErrInvalidType, "expected dynamic document")

View File

@ -14,8 +14,8 @@ func NewLib() map[string]core.Function {
"CLICK_ALL": ClickAll, "CLICK_ALL": ClickAll,
"NAVIGATE": Navigate, "NAVIGATE": Navigate,
"INPUT": Input, "INPUT": Input,
"INNER_HTML": InnerHtml, "INNER_HTML": InnerHTML,
"INNER_HTML_ALL": InnerHtmlAll, "INNER_HTML_ALL": InnerHTMLAll,
"INNER_TEXT": InnerText, "INNER_TEXT": InnerText,
"INNER_TEXT_ALL": InnerTextAll, "INNER_TEXT_ALL": InnerTextAll,
} }

View File

@ -12,7 +12,7 @@ import (
* @params text (String) - The string to parse as JSON. * @params text (String) - The string to parse as JSON.
* @returns FQL value (Value) * @returns FQL value (Value)
*/ */
func JsonParse(_ context.Context, args ...core.Value) (core.Value, error) { func JSONParse(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1) err := core.ValidateArgs(args, 1, 1)
if err != nil { if err != nil {
@ -35,7 +35,7 @@ func JsonParse(_ context.Context, args ...core.Value) (core.Value, error) {
* @params value (Value) - The input value to serialize. * @params value (Value) - The input value to serialize.
* @returns json (String) * @returns json (String)
*/ */
func JsonStringify(_ context.Context, args ...core.Value) (core.Value, error) { func JSONStringify(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1) err := core.ValidateArgs(args, 1, 1)
if err != nil { if err != nil {

View File

@ -9,11 +9,11 @@ import (
"testing" "testing"
) )
func TestJsonParse(t *testing.T) { func TestJSONParse(t *testing.T) {
Convey("When args are not passed", t, func() { Convey("When args are not passed", t, func() {
Convey("It should return an error", func() { Convey("It should return an error", func() {
var err error var err error
_, err = strings.JsonParse(context.Background()) _, err = strings.JSONParse(context.Background())
So(err, ShouldBeError) So(err, ShouldBeError)
}) })
@ -26,7 +26,7 @@ func TestJsonParse(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
out, err := strings.JsonParse( out, err := strings.JSONParse(
context.Background(), context.Background(),
values.NewString(string(b)), values.NewString(string(b)),
) )
@ -42,7 +42,7 @@ func TestJsonParse(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
out, err := strings.JsonParse( out, err := strings.JSONParse(
context.Background(), context.Background(),
values.NewString(string(b)), values.NewString(string(b)),
) )
@ -58,7 +58,7 @@ func TestJsonParse(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
out, err := strings.JsonParse( out, err := strings.JSONParse(
context.Background(), context.Background(),
values.NewString(string(b)), values.NewString(string(b)),
) )
@ -74,7 +74,7 @@ func TestJsonParse(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
out, err := strings.JsonParse( out, err := strings.JSONParse(
context.Background(), context.Background(),
values.NewString(string(b)), values.NewString(string(b)),
) )
@ -90,7 +90,7 @@ func TestJsonParse(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
out, err := strings.JsonParse( out, err := strings.JSONParse(
context.Background(), context.Background(),
values.NewString(string(b)), values.NewString(string(b)),
) )
@ -110,7 +110,7 @@ func TestJsonParse(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
out, err := strings.JsonParse( out, err := strings.JSONParse(
context.Background(), context.Background(),
values.NewString(string(b)), values.NewString(string(b)),
) )
@ -128,7 +128,7 @@ func TestJsonParse(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
out, err := strings.JsonParse( out, err := strings.JSONParse(
context.Background(), context.Background(),
values.NewString(string(b)), values.NewString(string(b)),
) )
@ -139,18 +139,18 @@ func TestJsonParse(t *testing.T) {
}) })
} }
func TestJsonStringify(t *testing.T) { func TestJSONStringify(t *testing.T) {
Convey("When args are not passed", t, func() { Convey("When args are not passed", t, func() {
Convey("It should return an error", func() { Convey("It should return an error", func() {
var err error var err error
_, err = strings.JsonStringify(context.Background()) _, err = strings.JSONStringify(context.Background())
So(err, ShouldBeError) So(err, ShouldBeError)
}) })
}) })
Convey("It should serialize none", t, func() { Convey("It should serialize none", t, func() {
out, err := strings.JsonStringify( out, err := strings.JSONStringify(
context.Background(), context.Background(),
values.None, values.None,
) )
@ -160,7 +160,7 @@ func TestJsonStringify(t *testing.T) {
}) })
Convey("It should serialize boolean", t, func() { Convey("It should serialize boolean", t, func() {
out, err := strings.JsonStringify( out, err := strings.JSONStringify(
context.Background(), context.Background(),
values.False, values.False,
) )
@ -170,7 +170,7 @@ func TestJsonStringify(t *testing.T) {
}) })
Convey("It should serialize string", t, func() { Convey("It should serialize string", t, func() {
out, err := strings.JsonStringify( out, err := strings.JSONStringify(
context.Background(), context.Background(),
values.NewString("foobar"), values.NewString("foobar"),
) )
@ -180,7 +180,7 @@ func TestJsonStringify(t *testing.T) {
}) })
Convey("It should serialize int", t, func() { Convey("It should serialize int", t, func() {
out, err := strings.JsonStringify( out, err := strings.JSONStringify(
context.Background(), context.Background(),
values.NewInt(1), values.NewInt(1),
) )
@ -190,7 +190,7 @@ func TestJsonStringify(t *testing.T) {
}) })
Convey("It should serialize float", t, func() { Convey("It should serialize float", t, func() {
out, err := strings.JsonStringify( out, err := strings.JSONStringify(
context.Background(), context.Background(),
values.NewFloat(1.1), values.NewFloat(1.1),
) )
@ -200,7 +200,7 @@ func TestJsonStringify(t *testing.T) {
}) })
Convey("It should serialize array", t, func() { Convey("It should serialize array", t, func() {
out, err := strings.JsonStringify( out, err := strings.JSONStringify(
context.Background(), context.Background(),
values.NewArrayWith( values.NewArrayWith(
values.NewString("foo"), values.NewString("foo"),
@ -216,7 +216,7 @@ func TestJsonStringify(t *testing.T) {
obj := values.NewObject() obj := values.NewObject()
obj.Set(values.NewString("foo"), values.NewString("bar")) obj.Set(values.NewString("foo"), values.NewString("bar"))
out, err := strings.JsonStringify( out, err := strings.JSONStringify(
context.Background(), context.Background(),
obj, obj,
) )
@ -230,7 +230,7 @@ func TestJsonStringify(t *testing.T) {
So(err, ShouldBeNil) So(err, ShouldBeNil)
out, err := strings.JsonStringify( out, err := strings.JSONStringify(
context.Background(), context.Background(),
obj, obj,
) )

View File

@ -10,8 +10,8 @@ func NewLib() map[string]core.Function {
"ENCODE_URI_COMPONENT": EncodeURIComponent, "ENCODE_URI_COMPONENT": EncodeURIComponent,
"FIND_FIRST": FindFirst, "FIND_FIRST": FindFirst,
"FIND_LAST": FindLast, "FIND_LAST": FindLast,
"JSON_PARSE": JsonParse, "JSON_PARSE": JSONParse,
"JSON_STRINGIFY": JsonStringify, "JSON_STRINGIFY": JSONStringify,
"LEFT": Left, "LEFT": Left,
"LIKE": Like, "LIKE": Like,
"LOWER": Lower, "LOWER": Lower,

View File

@ -60,8 +60,8 @@ func ToArray(_ context.Context, inputs ...core.Value) (core.Value, error) {
core.FloatType, core.FloatType,
core.StringType, core.StringType,
core.DateTimeType, core.DateTimeType,
core.HtmlElementType, core.HTMLElementType,
core.HtmlDocumentType: core.HTMLDocumentType:
return values.NewArrayWith(value), nil return values.NewArrayWith(value), nil
case core.ArrayType: case core.ArrayType:
return value, nil return value, nil

View File

@ -74,20 +74,20 @@ func IsObject(_ context.Context, inputs ...core.Value) (core.Value, error) {
return isTypeof(inputs[0], core.ObjectType), nil return isTypeof(inputs[0], core.ObjectType), nil
} }
func IsHtmlElement(_ context.Context, inputs ...core.Value) (core.Value, error) { func IsHTMLElement(_ context.Context, inputs ...core.Value) (core.Value, error) {
if len(inputs) == 0 { if len(inputs) == 0 {
return values.None, core.ErrMissedArgument return values.None, core.ErrMissedArgument
} }
return isTypeof(inputs[0], core.HtmlElementType), nil return isTypeof(inputs[0], core.HTMLElementType), nil
} }
func IsHtmlDocument(_ context.Context, inputs ...core.Value) (core.Value, error) { func IsHTMLDocument(_ context.Context, inputs ...core.Value) (core.Value, error) {
if len(inputs) == 0 { if len(inputs) == 0 {
return values.None, core.ErrMissedArgument return values.None, core.ErrMissedArgument
} }
return isTypeof(inputs[0], core.HtmlDocumentType), nil return isTypeof(inputs[0], core.HTMLDocumentType), nil
} }
func IsBinary(_ context.Context, inputs ...core.Value) (core.Value, error) { func IsBinary(_ context.Context, inputs ...core.Value) (core.Value, error) {

View File

@ -18,8 +18,8 @@ func NewLib() map[string]core.Function {
"IS_DATETIME": IsDateTime, "IS_DATETIME": IsDateTime,
"IS_ARRAY": IsArray, "IS_ARRAY": IsArray,
"IS_OBJECT": IsObject, "IS_OBJECT": IsObject,
"IS_HTML_ELEMENT": IsHtmlElement, "IS_HTML_ELEMENT": IsHTMLElement,
"IS_HTML_DOCUMENT": IsHtmlDocument, "IS_HTML_DOCUMENT": IsHTMLDocument,
"IS_BINARY": IsBinary, "IS_BINARY": IsBinary,
"TYPENAME": TypeName, "TYPENAME": TypeName,
} }

32
revive.toml Normal file
View File

@ -0,0 +1,32 @@
ignoreGeneratedHeader = true
severity = "error"
confidence = 0.8
errorCode = 1
warningCode = 0
[rule.package-comments]
severity = "warning"
[rule.exported]
severity = "warning"
[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.if-return]
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.indent-error-flow]
[rule.errorf]
[rule.empty-block]
[rule.superfluous-else]
[rule.unused-parameter]
[rule.unreachable-code]
[rule.redefines-builtin-id]