Skip to content

Commit

Permalink
feat: export engine and finalize gnolang refactor (#76)
Browse files Browse the repository at this point in the history
This PR export the function to create the engine and refactor the
remaining of gnoswap-labs to replace it by gnolang
  • Loading branch information
0xtekgrinder authored Sep 29, 2024
1 parent 49c75b0 commit 71473fa
Show file tree
Hide file tree
Showing 37 changed files with 65 additions and 59 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 gnoswap-labs
Copyright (c) 2024 gnolang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Advance Linter for go-like grammar languages.

![GitHub Workflow Status](https://img.shields.io/github/workflow/status/gnoswap-labs/tlin/CI?label=build)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/gnolang/tlin/CI?label=build)
![License](https://img.shields.io/badge/License-MIT-blue.svg)

## Introduction
Expand Down Expand Up @@ -31,7 +31,7 @@ To install tlin CLI, follow these steps:
1. Clone the repository

```bash
git clone https://github.com/gnoswap-labs/tlin
git clone https://github.com/gnolang/tlin
```

2. Move to the cloned directory
Expand Down
14 changes: 7 additions & 7 deletions cmd/tlin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"strings"
"time"

"github.com/gnoswap-labs/tlin/formatter"
"github.com/gnoswap-labs/tlin/internal"
"github.com/gnoswap-labs/tlin/internal/analysis/cfg"
"github.com/gnoswap-labs/tlin/internal/fixer"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnoswap-labs/tlin/lint"
"github.com/gnolang/tlin/formatter"
"github.com/gnolang/tlin/internal"
"github.com/gnolang/tlin/internal/analysis/cfg"
"github.com/gnolang/tlin/internal/fixer"
tt "github.com/gnolang/tlin/internal/types"
"github.com/gnolang/tlin/lint"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -50,7 +50,7 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), config.Timeout)
defer cancel()

engine, err := internal.NewEngine(".", nil)
engine, err := lint.New(".", nil)
if err != nil {
logger.Fatal("Failed to initialize lint engine", zap.Error(err))
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/tlin/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"testing"
"time"

"github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"go.uber.org/zap"
Expand Down
4 changes: 2 additions & 2 deletions formatter/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strings"

"github.com/fatih/color"
"github.com/gnoswap-labs/tlin/internal"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
tt "github.com/gnolang/tlin/internal/types"
)

// rule set
Expand Down
4 changes: 2 additions & 2 deletions formatter/cyclomatic_complexity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"strings"

"github.com/gnoswap-labs/tlin/internal"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
tt "github.com/gnolang/tlin/internal/types"
)

type CyclomaticComplexityFormatter struct{}
Expand Down
4 changes: 2 additions & 2 deletions formatter/defers.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package formatter

import (
"github.com/gnoswap-labs/tlin/internal"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
tt "github.com/gnolang/tlin/internal/types"
)

type DefersFormatter struct{}
Expand Down
4 changes: 2 additions & 2 deletions formatter/early_return.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package formatter

import (
"github.com/gnoswap-labs/tlin/internal"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
tt "github.com/gnolang/tlin/internal/types"
)

type EarlyReturnOpportunityFormatter struct{}
Expand Down
4 changes: 2 additions & 2 deletions formatter/format_emit.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package formatter

import (
"github.com/gnoswap-labs/tlin/internal"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
tt "github.com/gnolang/tlin/internal/types"
)

type EmitFormatFormatter struct{}
Expand Down
4 changes: 2 additions & 2 deletions formatter/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"go/token"
"testing"

"github.com/gnoswap-labs/tlin/internal"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
tt "github.com/gnolang/tlin/internal/types"
"github.com/stretchr/testify/assert"
)

Expand Down
4 changes: 2 additions & 2 deletions formatter/general.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package formatter

import (
"github.com/gnoswap-labs/tlin/internal"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
tt "github.com/gnolang/tlin/internal/types"
)

// GeneralIssueFormatter is a formatter for general lint issues.
Expand Down
4 changes: 2 additions & 2 deletions formatter/missing_mod_pacakge.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package formatter

import (
"github.com/gnoswap-labs/tlin/internal"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
tt "github.com/gnolang/tlin/internal/types"
)

type MissingModPackageFormatter struct{}
Expand Down
4 changes: 2 additions & 2 deletions formatter/simplify_slice_expr.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package formatter

import (
"github.com/gnoswap-labs/tlin/internal"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
tt "github.com/gnolang/tlin/internal/types"
)

type SimplifySliceExpressionFormatter struct{}
Expand Down
4 changes: 2 additions & 2 deletions formatter/slice_bound.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package formatter

import (
"github.com/gnoswap-labs/tlin/internal"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
tt "github.com/gnolang/tlin/internal/types"
)

type SliceBoundsCheckFormatter struct{}
Expand Down
4 changes: 2 additions & 2 deletions formatter/unnecessary_type_conv.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package formatter

import (
"github.com/gnoswap-labs/tlin/internal"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
tt "github.com/gnolang/tlin/internal/types"
)

type UnnecessaryTypeConversionFormatter struct{}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/gnoswap-labs/tlin
module github.com/gnolang/tlin

go 1.22.2

Expand Down
4 changes: 2 additions & 2 deletions internal/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strings"
"sync"

"github.com/gnoswap-labs/tlin/internal/lints"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal/lints"
tt "github.com/gnolang/tlin/internal/types"
)

// Engine manages the linting process.
Expand Down
2 changes: 1 addition & 1 deletion internal/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"testing"

"github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/fixer/fixer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"sort"
"strings"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

type Fixer struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/fixer/fixer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"
"testing"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/cyclomatic_complexity.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"go/token"

"github.com/fzipp/gocyclo"
tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

func DetectHighCyclomaticComplexity(filename string, threshold int) ([]tt.Issue, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/default_golangci.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go/token"
"os/exec"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

func ParseFile(filename string, content []byte) (*ast.File, *token.FileSet, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/defers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"go/ast"
"go/token"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

type DeferChecker struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/detect_cycles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"go/ast"
"go/token"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

func DetectCycle(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/lints/early_return.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"os"
"strings"

"github.com/gnoswap-labs/tlin/internal/branch"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal/branch"
tt "github.com/gnolang/tlin/internal/types"
)

// DetectEarlyReturnOpportunities detects if-else chains that can be simplified using early returns.
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/format_emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"go/token"
"strings"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

func DetectEmitFormat(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/gno_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"
"strings"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/loop_allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"go/ast"
"go/token"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

func DetectLoopAllocation(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/missing_package_mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
"strings"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

func DetectMissingModPackage(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/repeated_regex_compilation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"go/ast"
"go/token"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/packages"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/simplify_slice_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"go/ast"
"go/token"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

func DetectUnnecessarySliceLength(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/slice_bound.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"go/ast"
"go/token"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

// TODO: Make more precisely.
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/unncessary_type_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"go/token"
"go/types"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

func DetectUnnecessaryConversions(filename string, node *ast.File, fset *token.FileSet) ([]tt.Issue, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/lints/useless_break.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"go/ast"
"go/token"

tt "github.com/gnoswap-labs/tlin/internal/types"
tt "github.com/gnolang/tlin/internal/types"
)

// DetectUselessBreak detects useless break statements in switch or select statements.
Expand Down
4 changes: 2 additions & 2 deletions internal/rule_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"go/ast"
"go/token"

"github.com/gnoswap-labs/tlin/internal/lints"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal/lints"
tt "github.com/gnolang/tlin/internal/types"
)

/*
Expand Down
10 changes: 8 additions & 2 deletions lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"os"
"path/filepath"

"github.com/gnoswap-labs/tlin/internal/lints"
tt "github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal"
"github.com/gnolang/tlin/internal/lints"
tt "github.com/gnolang/tlin/internal/types"
"go.uber.org/zap"
)

Expand All @@ -17,6 +18,11 @@ type LintEngine interface {
IgnoreRule(rule string)
}

// export the function NewEngine to be used in other packages
func New(rootDir string, source []byte) (*internal.Engine, error) {
return internal.NewEngine(rootDir, source)
}

func ProcessSources(ctx context.Context, logger *zap.Logger, engine LintEngine, sources [][]byte, processor func(LintEngine, []byte) ([]tt.Issue, error)) ([]tt.Issue, error) {
var allIssues []tt.Issue
for i, source := range sources {
Expand Down
2 changes: 1 addition & 1 deletion lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"path/filepath"
"testing"

"github.com/gnoswap-labs/tlin/internal/types"
"github.com/gnolang/tlin/internal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"go.uber.org/zap"
Expand Down

0 comments on commit 71473fa

Please sign in to comment.