Giter VIP home page Giter VIP logo

maligned's Introduction

maligned's People

Contributors

dgryski avatar dmitshur avatar kortschak avatar mdempsky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

maligned's Issues

No args should mean .

$ golint
[works on .]
$ go vet
[works on .]
$ maligned
2016/07/07 17:42:30 no initial packages were loaded
$ maligned .
[works on .]

maligned ignores custom build tags recently

Since c37866e, maligned complains on duplicate methods in different custom build tags.

main.go

package main

func main() {
	debug("x")
}

debug.go

// +build debug

package main

func debug(s string) { println(s) }

release.go

// +build !debug

package main

func debug(string) {}
 % maligned *.go
/tmp/release.go:5:6: debug redeclared in this block
/tmp/debug.go:5:6:      other declaration of debug
/tmp/release.go:5:6: debug redeclared in this block
/tmp/debug.go:5:6:      other declaration of debug
maligned: 4 errors during loading

Before c37866e, maligned worked well in this situation.

github.com/golang/tools API change

I got this compilation error while executing go get github.com/mdempsky/maligned with Go1.5.1:

./maligned.go:50: impossible type assertion:
*"golang.org/x/tools/go/types".Struct does not implement "go/types".Type (wrong type for Underlying method)
have Underlying() "golang.org/x/tools/go/types".Type
want Underlying() "go/types".Type

github.com/golang/tools introduced an API change for go/types around commit: golang/tools@2477c0d.

Possible defect on malaligned calc

Given the code:

model.go

package addrs

// ASDExchanger bla bla
type ASDExchanger struct {
	ASDBtcExchangeRate    string `mapstructure:"asd_btc_exchange_rate"`
	ASDBtcExchangeRateUSD string `mapstructure:"asd_btc_exchange_rate_usd"`
	ASDBtcExchangeLabel   string `mapstructure:"asd_btc_exchange_label"`
	ASDBtcExchangeEnabled bool   `mapstructure:"asd_btc_exchange_enabled"`

	ASDEthExchangeRate    string `mapstructure:"asd_eth_exchange_rate"`
	ASDEthExchangeRateUSD string `mapstructure:"asd_eth_exchange_rate_usd"`
	ASDEthExchangeLabel   string `mapstructure:"asd_eth_exchange_label"`
	ASDEthExchangeEnabled bool   `mapstructure:"asd_eth_exchange_enabled"`

	ASDSkyExchangeRate    string `mapstructure:"asd_sky_exchange_rate"`
	ASDSkyExchangeRateUSD string `mapstructure:"asd_sky_exchange_rate_usd"`
	ASDSkyExchangeLabel   string `mapstructure:"asd_sky_exchange_label"`
	ASDSkyExchangeEnabled bool   `mapstructure:"asd_sky_exchange_enabled"`

	ASDWavesExchangeRate    string `mapstructure:"asd_waves_exchange_rate"`
	ASDWavesExchangeRateUSD string `mapstructure:"asd_waves_exchange_rate_usd"`
	ASDWavesExchangeLabel   string `mapstructure:"asd_waves_exchange_label"`
	ASDWavesExchangeEnabled bool   `mapstructure:"asd_waves_exchange_enabled"`

	ASDWavesASDExchangeRate    string `mapstructure:"asd_waves_asd_exchange_rate"`
	ASDWavesASDExchangeRateUSD string `mapstructure:"asd_waves_asd_exchange_rate_usd"`
	ASDWavesASDExchangeLabel   string `mapstructure:"asd_waves_asd_exchange_label"`
	ASDWavesASDExchangeEnabled bool   `mapstructure:"asd_waves_asd_exchange_enabled"`
}

When I run gometalinter and maligned:

gometalinter --deadline=3m -j 2 --disable-all --tests --vendor \                                                                                             
        -E maligned \       
        ./...

Then throws me err:

model.go:4:19:warning: struct of size 280 could be 248 (maligned)

When I remove the bool and or replace with string, it works with no errs.

Any ideas ?

Add brief summary of memory alignment to README

This is a great project. Thank you for sharing it with the community.

I discovered the project when gometalinter ran against some of my code and found an inefficient alignment in one of my code's structs. But when I looked up the project, I found nothing in the README or the GoDoc that explained why memory alignment is a good thing or how I might achieve it.

I read Padding is hard which helped, but wonder if we might add something in the README or even the source code to help others who might have the same problem.

/cc @markmandel

Optimize for pointer slots too

When scanning objects during GC, the standard compiler/runtime only scan as far as the last pointer slot in an object. If fields are sorted so that all of the pointer-y fields come first, then the GC may be able to short-circuit its scan work slightly.

using autofixing in own code

hi, i know that fieldalignment now preferred way to check/fix field alignment in golang structs.
how to deal with it if i want to have automatic align fields via own golang program? (for example i'm generate code from protobuf)

Skipping check per struct

Hi,

I am wondering if I can explicitly skip running maligned check on any given struct rather than globally checking either all or none?

Regards

This is how I wish to return JSON response

{
   "id": 1,
   "name": "hello",
   "is_active": true,
   "created_at": "2019-01-01"
}
struct{
	ID       	uint16
	Name     	string
	IsActive 	bool
	CreatedAt	string
}

However, it is not possible because struct is not maligned and I have to malign it and the response looks odd.

struct{
	Name     	string
	CreatedAt	string
	ID       	uint16
	IsActive 	bool
}
{
   "name": "hello",
   "created_at": "2019-01-01",
   "id": 1,
   "is_active": true
}

Some annotation solution like this, maybe!

// @skip: maligned
struct{
	ID       	uint16
	Name     	string
	IsActive 	bool
	CreatedAt	string
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.