incu6us / goimports-reviser

Right imports sorting & code formatting tool (goimports alternative)
MIT License
600 stars 72 forks source link

support for CGO #75

Closed CodingCrush closed 2 years ago

CodingCrush commented 2 years ago

when cgo is enabled, the "C" package should always be imported after the c include comment like this:

/*
#cgo CFLAGS: -I
#cgo LDFLAGS: -L
#include <stdio.h>
#include <stdlib.h>
*/
import "C"
import (
    "reflect"
    "runtime"
    "unsafe"
)

However, with -rm-unused, "C" will be removed. without this flag, "C" import will be re-ordered, this operation results in compile failure

import (
    "fmt"

    "C"
)
incu6us commented 2 years ago

I've added test here https://github.com/incu6us/goimports-reviser/blob/master/reviser/reviser_test.go#L701 Seems, everything is working fine. Try to update the tool to the latest version

CodingCrush commented 2 years ago

Thank you, i found it works well with 1.18 built binary before v2.5.3 is released.

This job helps a lot for my projects

I've added test here https://github.com/incu6us/goimports-reviser/blob/master/reviser/reviser_test.go#L701 Seems, everything is working fine. Try to update the tool to the latest version