Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable whitespace linter and fix errors #456

Merged
merged 1 commit into from
Nov 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
run:
concurrency: 4
deadline: 6m
skip-dirs:
- terst
Expand All @@ -9,17 +8,9 @@ run:
linters-settings:
govet:
check-shadowing: false
gocyclo:
min-complexity: 20
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 4
cyclop:
max-complexity: 15

linters:
enable-all: true
Expand Down Expand Up @@ -62,7 +53,6 @@ linters:
- nakedret
- nestif
- revive
- whitespace
- errorlint
- exhaustive
- forcetypeassert
Expand All @@ -81,8 +71,3 @@ linters:
- dupword
- gci

issues:
exclude:
- .*Id.* should be .*ID.*
exclude-use-default: false
max-same-issues: 0
1 change: 0 additions & 1 deletion builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ func builtin_escape(input string) string {
)
}
index += width

} else {
output = append(output, input[index])
index += 1
Expand Down
1 change: 0 additions & 1 deletion builtin_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ func sortCompare(thisObject *_object, index0, index1 uint, compare *_object) int
}

func arraySortSwap(thisObject *_object, index0, index1 uint) {

j := struct {
name string
exists bool
Expand Down
2 changes: 0 additions & 2 deletions builtin_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ func builtinString_replace(call FunctionCall) Value {
result = append(result, []byte(replacement)...)
lastIndex = match[1]
}

} else {
replace := []byte(replaceValue.string())
for _, match := range found {
Expand Down Expand Up @@ -373,7 +372,6 @@ func builtinString_split(call FunctionCall) Value {

RETURN:
return toValue_object(call.runtime.newArrayOf(valueArray))

} else {
separator := separatorValue.string()

Expand Down
1 change: 0 additions & 1 deletion clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type _clone struct {
}

func (in *_runtime) clone() *_runtime {

in.lck.Lock()
defer in.lck.Unlock()

Expand Down
1 change: 0 additions & 1 deletion cmpl_evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func (self *_runtime) cmpl_evaluate_nodeProgram(node *_nodeProgram, eval bool) V
}

func (self *_runtime) cmpl_call_nodeFunction(function *_object, stash *_fnStash, node *_nodeFunctionLiteral, this Value, argumentList []Value) Value {

indexOfParameterName := make([]string, len(argumentList))
// function(abc, def, ghi)
// indexOfParameterName[0] = "abc"
Expand Down
7 changes: 0 additions & 7 deletions cmpl_evaluate_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func (self *_runtime) cmpl_evaluate_nodeExpression(node _nodeExpression) Value {
}

switch node := node.(type) {

case *_nodeArrayLiteral:
return self.cmpl_evaluate_nodeArrayLiteral(node)

Expand Down Expand Up @@ -102,7 +101,6 @@ func (self *_runtime) cmpl_evaluate_nodeExpression(node _nodeExpression) Value {
}

func (self *_runtime) cmpl_evaluate_nodeArrayLiteral(node *_nodeArrayLiteral) Value {

valueArray := []Value{}

for _, node := range node.value {
Expand All @@ -119,7 +117,6 @@ func (self *_runtime) cmpl_evaluate_nodeArrayLiteral(node *_nodeArrayLiteral) Va
}

func (self *_runtime) cmpl_evaluate_nodeAssignExpression(node *_nodeAssignExpression) Value {

left := self.cmpl_evaluate_nodeExpression(node.left)
right := self.cmpl_evaluate_nodeExpression(node.right)
rightValue := right.resolve()
Expand All @@ -135,7 +132,6 @@ func (self *_runtime) cmpl_evaluate_nodeAssignExpression(node *_nodeAssignExpres
}

func (self *_runtime) cmpl_evaluate_nodeBinaryExpression(node *_nodeBinaryExpression) Value {

left := self.cmpl_evaluate_nodeExpression(node.left)
leftValue := left.resolve()

Expand All @@ -159,7 +155,6 @@ func (self *_runtime) cmpl_evaluate_nodeBinaryExpression(node *_nodeBinaryExpres
}

func (self *_runtime) cmpl_evaluate_nodeBinaryExpression_comparison(node *_nodeBinaryExpression) Value {

left := self.cmpl_evaluate_nodeExpression(node.left).resolve()
right := self.cmpl_evaluate_nodeExpression(node.right).resolve()

Expand Down Expand Up @@ -312,7 +307,6 @@ func (self *_runtime) cmpl_evaluate_nodeNewExpression(node *_nodeNewExpression)
}

func (self *_runtime) cmpl_evaluate_nodeObjectLiteral(node *_nodeObjectLiteral) Value {

result := self.newObject()

for _, property := range node.value {
Expand Down Expand Up @@ -349,7 +343,6 @@ func (self *_runtime) cmpl_evaluate_nodeSequenceExpression(node *_nodeSequenceEx
}

func (self *_runtime) cmpl_evaluate_nodeUnaryExpression(node *_nodeUnaryExpression) Value {

target := self.cmpl_evaluate_nodeExpression(node.operand)
switch node.operator {
case token.TYPEOF, token.DELETE:
Expand Down
7 changes: 0 additions & 7 deletions cmpl_evaluate_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func (self *_runtime) cmpl_evaluate_nodeStatement(node _nodeStatement) Value {
}

switch node := node.(type) {

case *_nodeBlockStatement:
labels := self.labels
self.labels = nil
Expand Down Expand Up @@ -109,7 +108,6 @@ func (self *_runtime) cmpl_evaluate_nodeStatement(node _nodeStatement) Value {

case *_nodeWithStatement:
return self.cmpl_evaluate_nodeWithStatement(node)

}

panic(fmt.Errorf("Here be dragons: evaluate_nodeStatement(%T)", node))
Expand All @@ -136,7 +134,6 @@ func (self *_runtime) cmpl_evaluate_nodeStatementList(list []_nodeStatement) Val
}

func (self *_runtime) cmpl_evaluate_nodeDoWhileStatement(node *_nodeDoWhileStatement) Value {

labels := append(self.labels, "")
self.labels = nil

Expand Down Expand Up @@ -172,7 +169,6 @@ resultBreak:
}

func (self *_runtime) cmpl_evaluate_nodeForInStatement(node *_nodeForInStatement) Value {

labels := append(self.labels, "")
self.labels = nil

Expand Down Expand Up @@ -235,7 +231,6 @@ func (self *_runtime) cmpl_evaluate_nodeForInStatement(node *_nodeForInStatement
}

func (self *_runtime) cmpl_evaluate_nodeForStatement(node *_nodeForStatement) Value {

labels := append(self.labels, "")
self.labels = nil

Expand Down Expand Up @@ -309,7 +304,6 @@ func (self *_runtime) cmpl_evaluate_nodeIfStatement(node *_nodeIfStatement) Valu
}

func (self *_runtime) cmpl_evaluate_nodeSwitchStatement(node *_nodeSwitchStatement) Value {

labels := append(self.labels, "")
self.labels = nil

Expand Down Expand Up @@ -388,7 +382,6 @@ func (self *_runtime) cmpl_evaluate_nodeTryStatement(node *_nodeTryStatement) Va
}

func (self *_runtime) cmpl_evaluate_nodeWhileStatement(node *_nodeWhileStatement) Value {

test := node.test
body := node.body
labels := append(self.labels, "")
Expand Down
4 changes: 0 additions & 4 deletions cmpl_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func (cmpl *_compiler) parseExpression(in ast.Expression) _nodeExpression {
}

switch in := in.(type) {

case *ast.ArrayLiteral:
out := &_nodeArrayLiteral{
value: make([]_nodeExpression, len(in.Value)),
Expand Down Expand Up @@ -190,7 +189,6 @@ func (cmpl *_compiler) parseExpression(in ast.Expression) _nodeExpression {
name: in.Name,
initializer: cmpl.parseExpression(in.Initializer),
}

}

panic(fmt.Errorf("Here be dragons: cmpl.parseExpression(%T)", in))
Expand All @@ -202,7 +200,6 @@ func (cmpl *_compiler) parseStatement(in ast.Statement) _nodeStatement {
}

switch in := in.(type) {

case *ast.BlockStatement:
out := &_nodeBlockStatement{
list: make([]_nodeStatement, len(in.List)),
Expand Down Expand Up @@ -353,7 +350,6 @@ func (cmpl *_compiler) parseStatement(in ast.Statement) _nodeStatement {
object: cmpl.parseExpression(in.Object),
body: cmpl.parseStatement(in.Body),
}

}

panic(fmt.Errorf("Here be dragons: cmpl.parseStatement(%T)", in))
Expand Down
1 change: 0 additions & 1 deletion cmpl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func Test_cmpl(t *testing.T) {

func TestParse_cmpl(t *testing.T) {
tt(t, func() {

test := func(src string) {
program, err := parser.ParseFile(nil, "", src, 0)
is(err, nil)
Expand Down
1 change: 0 additions & 1 deletion console.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,5 @@ func builtinConsole_assert(call FunctionCall) Value {
}

func (runtime *_runtime) newConsole() *_object {

return newConsoleObject(runtime)
}
1 change: 0 additions & 1 deletion error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ func TestErrorContext(t *testing.T) {
is(len(err1.trace), 1)
is(err1.trace[0].location(), "C (file1.js:7:5)")
}

})
}

Expand Down
3 changes: 0 additions & 3 deletions evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ func (self *_runtime) evaluateModulo(left float64, right float64) Value {
}

func (self *_runtime) calculateBinaryExpression(operator token.Token, left Value, right Value) Value {

leftValue := left.resolve()

switch operator {

// Additive
case token.PLUS:
leftValue = toPrimitive(leftValue)
Expand Down Expand Up @@ -209,7 +207,6 @@ var lessThanTable [4](map[_lessThanResult]bool) = [4](map[_lessThanResult]bool){
}

func (self *_runtime) calculateComparison(comparator token.Token, left Value, right Value) bool {

// FIXME Use strictEqualityComparison?
// TODO This might be redundant now (with regards to evaluateComparison)
x := left.resolve()
Expand Down
2 changes: 0 additions & 2 deletions global.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var (
)

func newContext() *_runtime {

self := &_runtime{}

self.globalStash = self.newObjectStash(nil, nil)
Expand Down Expand Up @@ -131,7 +130,6 @@ func (runtime *_runtime) newNumber(value Value) *_object {
}

func (runtime *_runtime) newRegExp(patternValue Value, flagsValue Value) *_object {

pattern := ""
flags := ""
if object := patternValue._object(); object != nil && object.class == classRegExp {
Expand Down
3 changes: 1 addition & 2 deletions issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,6 @@ func Test_issue266(t *testing.T) {
return a - b;
});
`, "-200000000000,0,200000000000")

})
}

Expand Down Expand Up @@ -929,7 +928,7 @@ func Test_issue386(t *testing.T) {
}
}

func Test_issue382(t *testing.T) {
func Test_issue383(t *testing.T) {
vm := New()
vm.Set("panicFunc", func(call FunctionCall) Value {
panic("test")
Expand Down
1 change: 0 additions & 1 deletion object_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ func _objectCanPut(self *_object, name string) (canPut bool, property *_property

// 8.12.5
func objectPut(self *_object, name string, value Value, throw bool) {

if true {
// Shortcut...
//
Expand Down
1 change: 0 additions & 1 deletion otto.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ func (self Otto) ContextSkip(limit int, skipNative bool) (ctx Context) {
// // value is [ 1, 2, 3, undefined, 4, 5, 6, 7, "abc" ]
// value, _ := vm.Call(`[ 1, 2, 3, undefined, 4 ].concat`, nil, 5, 6, 7, "abc")
func (self Otto) Call(source string, this interface{}, argumentList ...interface{}) (Value, error) {

thisValue := Value{}

construct := false
Expand Down
1 change: 0 additions & 1 deletion otto_error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,5 @@ func TestOttoError(t *testing.T) {
xyzzy
`)
is(err, "ReferenceError: 'xyzzy' is not defined")

})
}
2 changes: 0 additions & 2 deletions otto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,6 @@ func TestDotMember(t *testing.T) {

func Test_stringToFloat(t *testing.T) {
tt(t, func() {

is(parseNumber("10e10000"), _Infinity)
is(parseNumber("10e10_."), _NaN)
})
Expand Down Expand Up @@ -1350,7 +1349,6 @@ func TestOttoCall_clone(t *testing.T) {
is(err, nil)
is(value, `function() { return "abc"; },function() { return "ghi"; }`)
}

})
}

Expand Down
2 changes: 0 additions & 2 deletions parser/comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,6 @@ a = /*comment1*/new /*comment2*/ obj/*comment3*/()
is(checkComments((parser.comments.CommentMap)[program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.AssignExpression).Right], []string{"comment1"}, ast.LEADING), nil)
is(checkComments((parser.comments.CommentMap)[program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.AssignExpression).Right.(*ast.NewExpression).Callee], []string{"comment2"}, ast.LEADING), nil)
is(checkComments((parser.comments.CommentMap)[program.Body[0].(*ast.ExpressionStatement).Expression.(*ast.AssignExpression).Right.(*ast.NewExpression).Callee], []string{"comment3"}, ast.TRAILING), nil)

})
}

Expand All @@ -1439,6 +1438,5 @@ a = /*comment1*/new /*comment2*/ obj/*comment3*/()
n := program.Body[0]
fmt.Printf("FOUND NODE: %v, number of comments: %v\n", reflect.TypeOf(n), len(parser.comments.CommentMap[n]))
displayComments(parser.comments.CommentMap)

})
}
Loading