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:
- 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
- export CLASSPATH=".:/usr/local/lib/antlr-4.7.1-complete.jar:$CLASSPATH"
- 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 org.antlr.v4.gui.TestRig "$@"' > $HOME/travis-bin/grun
- 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'.
[[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]]
digest = "1:a62f6ed230a8cd138a9efbe718e7d0b0294f139266f5f55cd942769a9aac8de2"
name = "github.com/PuerkitoBio/goquery"
@ -137,14 +172,6 @@
revision = "a96e63847dc3c67d17befa69c303767e2f84e54f"
version = "v2.1"
[[projects]]
branch = "master"
digest = "1:f7aa53146bf79462509d4ce136826ebbd64907e4679e1b04e62758da6b68e589"
name = "github.com/orcaman/concurrent-map"
packages = ["."]
pruneopts = "UT"
revision = "b28018939af9022337862b94a463abb18abb3e0e"
[[projects]]
digest = "1:40e195917a951a8bf867cd05de2a46aaf1806c50cf92eebf4c16f78cd196f747"
name = "github.com/pkg/errors"
@ -221,6 +248,32 @@
analyzer-name = "dep"
analyzer-version = 1
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/antlr/antlr4/runtime/Go/antlr",
"github.com/chzyer/readline",
@ -236,7 +289,6 @@
"github.com/mafredri/cdp/rpcc",
"github.com/mafredri/cdp/session",
"github.com/natefinch/lumberjack",
"github.com/orcaman/concurrent-map",
"github.com/pkg/errors",
"github.com/rs/zerolog",
"github.com/sethgrid/pester",

View File

@ -32,12 +32,12 @@ doc:
fmt:
go fmt ${DIR_CLI}/... ${DIR_PKG}/...
# https://github.com/golang/lint
# go get github.com/golang/lint/golint
# https://github.com/mgechev/revive
# go get github.com/mgechev/revive
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
# go get code.google.com/p/go.tools/cmd/vet
vet:
go vet ${DIR_CLI}/... ${DIR_PKG}/...
go vet ${DIR_CLI}/... ${DIR_PKG}/...

View File

@ -11,7 +11,7 @@ import (
type Topic struct {
Name string `json:"name"`
Description string `json:"description"`
Url string `json:"url"`
URL string `json:"url"`
}
func main() {
@ -23,7 +23,7 @@ func main() {
}
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
}
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))
}

View File

@ -536,7 +536,7 @@ func (v *visitor) doVisitObjectLiteral(ctx *fql.ObjectLiteralContext, scope *sco
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
}
@ -611,7 +611,7 @@ func (v *visitor) doVisitBooleanLiteral(ctx *fql.BooleanLiteralContext) (core.Ex
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
}
@ -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()
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 consequent core.Expression
var alternate core.Expression

View File

@ -43,8 +43,8 @@ type (
pos int
}
HtmlNodeIterator struct {
values values.HtmlNode
HTMLNodeIterator struct {
values values.HTMLNode
pos int
}
)
@ -55,15 +55,15 @@ func ToIterator(value core.Value) (Iterator, error) {
return NewArrayIterator(value.(*values.Array)), nil
case core.ObjectType:
return NewObjectIterator(value.(*values.Object)), nil
case core.HtmlElementType, core.HtmlDocumentType:
return NewHtmlNodeIterator(value.(values.HtmlNode)), nil
case core.HTMLElementType, core.HTMLDocumentType:
return NewHTMLNodeIterator(value.(values.HTMLNode)), nil
default:
return nil, core.TypeError(
value.Type(),
core.ArrayType,
core.ObjectType,
core.HtmlDocumentType,
core.HtmlElementType,
core.HTMLDocumentType,
core.HTMLElementType,
)
}
}
@ -128,7 +128,7 @@ func (iterator *SliceIterator) Next() (core.Value, core.Value, error) {
if len(iterator.values) > iterator.pos {
idx := iterator.pos
val := iterator.values[idx]
iterator.pos += 1
iterator.pos++
return val, values.NewInt(idx), nil
}
@ -148,7 +148,7 @@ func (iterator *MapIterator) HasNext() bool {
i := 0
for k := range iterator.values {
keys[i] = k
i += 1
i++
}
iterator.keys = keys
@ -161,7 +161,7 @@ func (iterator *MapIterator) Next() (core.Value, core.Value, error) {
if len(iterator.keys) > iterator.pos {
key := iterator.keys[iterator.pos]
val := iterator.values[key]
iterator.pos += 1
iterator.pos++
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 {
idx := iterator.pos
val := iterator.values.Get(values.NewInt(idx))
iterator.pos += 1
iterator.pos++
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 {
key := iterator.keys[iterator.pos]
val, _ := iterator.values.Get(values.NewString(key))
iterator.pos += 1
iterator.pos++
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
}
func NewHtmlNodeIterator(input values.HtmlNode) *HtmlNodeIterator {
return &HtmlNodeIterator{input, 0}
func NewHTMLNodeIterator(input values.HTMLNode) *HTMLNodeIterator {
return &HTMLNodeIterator{input, 0}
}
func (iterator *HtmlNodeIterator) HasNext() bool {
func (iterator *HTMLNodeIterator) HasNext() bool {
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) {
idx := iterator.pos
val := iterator.values.GetChildNode(values.NewInt(idx))
iterator.pos += 1
iterator.pos++
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) {
if i.counter() <= i.count {
i.currCount += 1
i.currCount++
return i.src.Next()
}
@ -54,7 +54,7 @@ func (i *LimitIterator) verifyOffset() {
}
for (i.offset > i.currCount) && i.src.HasNext() {
i.currCount += 1
i.currCount++
i.src.Next()
}
}

View File

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

View File

@ -12,7 +12,7 @@ func NewBooleanLiteral(val bool) BooleanLiteral {
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 {
return values.True, nil
}

View File

@ -12,6 +12,6 @@ func NewFloatLiteral(value float64) FloatLiteral {
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
}

View File

@ -12,6 +12,6 @@ func NewIntLiteral(value int) IntLiteral {
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
}

View File

@ -10,6 +10,6 @@ type noneLiteral struct{}
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
}

View File

@ -12,6 +12,6 @@ func NewStringLiteral(str string) StringLiteral {
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
}

View File

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

View File

@ -14,7 +14,7 @@ type baseOperator struct {
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
}

View File

@ -36,7 +36,7 @@ func (e *ParameterExpression) Iterate(ctx context.Context, scope *core.Scope) (c
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)
if err != nil {

View File

@ -58,7 +58,7 @@ func (e *VariableExpression) Iterate(ctx context.Context, scope *core.Scope) (co
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)
}

View File

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

View File

@ -3,7 +3,7 @@ package values
import "github.com/MontFerret/ferret/pkg/runtime/core"
type (
HtmlNode interface {
HTMLNode interface {
core.Value
NodeType() Int
@ -14,7 +14,7 @@ type (
InnerText() String
InnerHtml() String
InnerHTML() String
Value() core.Value
@ -31,9 +31,9 @@ type (
QuerySelectorAll(selector String) core.Value
}
HtmlDocument interface {
HtmlNode
HTMLDocument interface {
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.ArrayType,
core.ObjectType,
core.HtmlElementType,
core.HtmlDocumentType,
core.HTMLElementType,
core.HTMLDocumentType,
core.BinaryType,
)

View File

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

View File

@ -13,7 +13,7 @@ import (
* @param selector (String) - Selector
* @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)
if err != nil {
@ -23,19 +23,19 @@ func InnerHtml(_ context.Context, args ...core.Value) (core.Value, error) {
arg1 := args[0]
selector := args[1].String()
err = core.ValidateType(arg1, core.HtmlDocumentType)
err = core.ValidateType(arg1, core.HTMLDocumentType)
if err != nil {
return values.None, err
}
doc, ok := arg1.(*dynamic.HtmlDocument)
doc, ok := arg1.(*dynamic.HTMLDocument)
if !ok {
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
* @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)
if err != nil {
@ -54,19 +54,19 @@ func InnerHtmlAll(_ context.Context, args ...core.Value) (core.Value, error) {
arg1 := args[0]
selector := args[1].String()
err = core.ValidateType(arg1, core.HtmlDocumentType)
err = core.ValidateType(arg1, core.HTMLDocumentType)
if err != nil {
return values.None, err
}
doc, ok := arg1.(*dynamic.HtmlDocument)
doc, ok := arg1.(*dynamic.HTMLDocument)
if !ok {
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]
selector := args[1].String()
err = core.ValidateType(arg1, core.HtmlDocumentType)
err = core.ValidateType(arg1, core.HTMLDocumentType)
if err != nil {
return values.None, err
}
doc, ok := arg1.(*dynamic.HtmlDocument)
doc, ok := arg1.(*dynamic.HTMLDocument)
if !ok {
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]
selector := args[1].String()
err = core.ValidateType(arg1, core.HtmlDocumentType)
err = core.ValidateType(arg1, core.HTMLDocumentType)
if err != nil {
return values.None, err
}
doc, ok := arg1.(*dynamic.HtmlDocument)
doc, ok := arg1.(*dynamic.HTMLDocument)
if !ok {
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"
func ToHtmlType(nt html.NodeType) int {
func ToHTMLType(nt html.NodeType) int {
switch nt {
case html.DocumentNode:
return 9

View File

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

View File

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

View File

@ -28,7 +28,7 @@ func NewDriver(address string) *Driver {
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)
if err != nil {
@ -39,7 +39,7 @@ func (drv *Driver) GetDocument(ctx context.Context, url string) (values.HtmlNode
defer cancel()
if url == "" {
url = BlankPageUrl
url = BlankPageURL
}
// 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 LoadHtmlDocument(ctx, conn, url)
return LoadHTMLDocument(ctx, conn, url)
}
func (drv *Driver) Close() error {

View File

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

View File

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

View File

@ -47,10 +47,10 @@ func DispatchEvent(
return values.False, nil
}
evtId := evt.Result.ObjectID
evtID := evt.Result.ObjectID
// 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(
ctx,

View File

@ -51,7 +51,7 @@ func parseAttrs(attrs []string) *values.Object {
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))
if err != nil {

View File

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

View File

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

View File

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

View File

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

View File

@ -28,7 +28,7 @@ func NewDriver(setters ...Option) *Driver {
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)
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 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))
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 NewHtmlDocument("#string", doc)
return NewHTMLDocument("#string", doc)
}
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
}
func elementArgs(inputs []core.Value) (values.HtmlNode, values.String, error) {
func elementArgs(inputs []core.Value) (values.HTMLNode, values.String, error) {
if len(inputs) == 0 {
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]
arg2 := inputs[1]
if arg1.Type() != core.HtmlDocumentType &&
arg1.Type() != core.HtmlElementType {
return nil, values.EmptyString, core.TypeError(arg1.Type(), core.HtmlDocumentType, core.HtmlElementType)
if arg1.Type() != core.HTMLDocumentType &&
arg1.Type() != core.HTMLElementType {
return nil, values.EmptyString, core.TypeError(arg1.Type(), core.HTMLDocumentType, core.HTMLElementType)
}
if 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 {
return values.None, err
}
doc, ok := arg.(*dynamic.HtmlDocument)
doc, ok := arg.(*dynamic.HTMLDocument)
if !ok {
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
}
err = core.ValidateType(args[0], core.HtmlDocumentType)
err = core.ValidateType(args[0], core.HTMLDocumentType)
if err != nil {
return values.None, err
}
doc, ok := args[0].(*dynamic.HtmlDocument)
doc, ok := args[0].(*dynamic.HTMLDocument)
if !ok {
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,
"NAVIGATE": Navigate,
"INPUT": Input,
"INNER_HTML": InnerHtml,
"INNER_HTML_ALL": InnerHtmlAll,
"INNER_HTML": InnerHTML,
"INNER_HTML_ALL": InnerHTMLAll,
"INNER_TEXT": InnerText,
"INNER_TEXT_ALL": InnerTextAll,
}

View File

@ -12,7 +12,7 @@ import (
* @params text (String) - The string to parse as JSON.
* @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)
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.
* @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)
if err != nil {

View File

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

View File

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

View File

@ -60,8 +60,8 @@ func ToArray(_ context.Context, inputs ...core.Value) (core.Value, error) {
core.FloatType,
core.StringType,
core.DateTimeType,
core.HtmlElementType,
core.HtmlDocumentType:
core.HTMLElementType,
core.HTMLDocumentType:
return values.NewArrayWith(value), nil
case core.ArrayType:
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
}
func IsHtmlElement(_ context.Context, inputs ...core.Value) (core.Value, error) {
func IsHTMLElement(_ context.Context, inputs ...core.Value) (core.Value, error) {
if len(inputs) == 0 {
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 {
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) {

View File

@ -18,8 +18,8 @@ func NewLib() map[string]core.Function {
"IS_DATETIME": IsDateTime,
"IS_ARRAY": IsArray,
"IS_OBJECT": IsObject,
"IS_HTML_ELEMENT": IsHtmlElement,
"IS_HTML_DOCUMENT": IsHtmlDocument,
"IS_HTML_ELEMENT": IsHTMLElement,
"IS_HTML_DOCUMENT": IsHTMLDocument,
"IS_BINARY": IsBinary,
"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]