Go lintpack: composable linker manager
3r3757. 3r3-31. 3r33744. lintpack
Is a utility for building linters (static analyzers) that are written using the provided API. On the basis of it, the static analyzer
? familiar to some, is now being rewritten. go-critic
. 3r33737. 3r3742. 3r3757. 3r33744. Today, we will examine in more detail what is. lintpack
from the user's point of view. 3r33737. go-critic It began as a pilot project that was a sandbox for prototyping virtually any static analysis idea for Go. 3r33737. 3r3742. 3r3757. 3r33744. It was a pleasant surprise that some people actually sent implementations of detectors of various problems in the code. Everything was under control until technical debt began to accumulate, which was virtually no one to eliminate. People came, added checks, and then disappeared. Who then should correct the errors and refine the implementation? 3r33737. 3r3742. 3r3757. 3r33744. A significant event was the proposal to add checks that require additional configuration, that is, those that depend on local agreements for the project. An example is the detection of the presence of a copyright header in a file (license header) according to a specific pattern or the prohibition of importing some packages with a suggestion of a given alternative. 3r33737. 3r3742. 3r3757. 3r33744. Another difficulty was extensibility. It’s not convenient for everyone to send their code to someone else’s repository. Some wanted to dynamically connect their checks so that they did not need to modify the source codes 3r3739. go-critic . 3r33737. 3r3742. 3r3757. 3r33744. In summary, here are the problems that stood in the way of development go-critic
: 3r3742. 3r3757.
- 3r3757. 3r33557. Load of complexity. Too much to maintain, the presence of ownerless code. 3r33560. 3r3757. 3r33557. Low average quality level.
experimental
meant both "almost ready to use", and "it is better not to run at all." 3r33560. 3r3757. 3r33557. It is sometimes difficult to make the decision to include a check in 3r3739. go-critic , and rejecting them contradicts the original philosophy of the project. 3r33560. 3r3757. 3r33557. Different people have seen go-critic
differently. Most wanted to have it in the form of a CI linter, which comes in delivery with 3r3739. gometalinter . 3r33560. 3r3757. 3r33434. 3r3742. 3r3757. 3r33744. In order to somehow limit the number of discrepancies and mismatched interpretations of the project, 3-3379 was written. manifesto . 3r33737. 3r3742. 3r3757. 3r33571. If you want an additional historical context and even more thoughts on the categorization of static analyzers, you can listen to the recording 3r3385. GoCritic is a new static analyzer for Go . At that moment, lintpack did not exist yet, but some of the ideas were born on that day, after the report. 3r33576. 3r33744. But what if we didn’t have to store all the checks in one repository? 3r33737. 3r3742. 3r3757. 3r33939. Meet - lintpack 3r3742. 3r3757. 3r33744. 3r399. 3r3742. 3r3757. 3r33737. 3r3742. 3r3757. 3r33744. go-critic
consists of two main components: 3r3742. 3r3757. 3r33555. 3r3757. 3r33557. The implementation of the checks themselves. 3r33560. 3r3757. 3r33557. A program that loads packages checked by Go and runs checks on them. 3r33560. 3r3757. 3r? 3562. 3r3742. 3r3757. 3r33744. Our goal: to be able to store the checks for the linter in different repositories and put them together when necessary. 3r33737. 3r3742. 3r3757. 3r33744. lintpack does exactly that. It defines functions that allow you to describe your checks in such a way that they can then be run through the generated linter. 3r33737. 3r3742. 3r3757. 3r33571. Packages that are implemented using lintpack
as a framework, we will call lintpack
-compatible or lintpack
-compatible packages. 3r33576. 3r33744. If he himself go-critic
was implemented based on lintpack
, all checks could be divided into several repositories. One of the options for separation may be the following: 3r3742. 3r3757. 3r33555. 3r3757. 3r33557. The core set, where all the stable and supported checks fall. 3r33560. 3r3757. 3r33557. The contrib repository contains code that is either too experimental or does not have a maintainer. 3r33560. 3r3757. 3r33557. Something like go-police where you can find the most customizable for a specific project verification. 3r33560. 3r3757. 3r? 3562. 3r3742. 3r3757. 3r33744. The first point is particularly important in relation to 3r3165. integration of go-critic in golangci-lint . 3r33737. 3r3742. 3r3757. 3r33744. If you stay at go-critic
, then for users almost nothing has changed. lintpack
creates an almost identical linter, but golangci-lint
encapsulates all the different implementation details. 3r33737. 3r3742. 3r3757. 3r33744. But something has changed. If based on 3r3739. lintpack new linters will be created, you will have a richer selection of ready-made diagnostics for the linter generation. Imagine for a moment that this is so, and there are more than 10 different sets of checks in the world. 3r33737. 3r3742. 3r3757. 3r3186. Quick start 3r3742. 3r3757. 3r33744. 3r3191. 3r33737. 3r3742. 3r3757. 3r33744. First, you need to install yourself. lintpack
: 3r3742. 3r3757. # lintpack will be set to `$ (go env GOPATH) /bin`. 3r3757. go get -v github.com/go-lintpack/lintpack /
3r33737. 3r3742. 3r3757. 3r33744. Create a linter using the 333-3739 test package. lintpack : 3r3742. 3r3757.
lintpack build -o mylinter github.com/go-lintpack/lintpack/checkers
3r33737. 3r3742. 3r3757. 3r33744. The set includes 3r3739. panicNil which finds in the codepanic (nil)
and ask to make a replacement for something distinguishable, because otherwiserecover () 3r33737. will not be able to tell whether 3r3739 was called. panic
from 3r3739. nil 3r340 argument or panic was not at all. 3r33737. 3r3742. 3r3757. 3r?383. 3r33584. The example with panic (nil) [/b] 3r33586. 3r3645. 3r3742. 3r3757. 3r33744. The code below attempts to describe the value obtained fromrecover () 3r33737. : 3r3742. 3r3757.
3r? 3530. r: = recover ()
fmt.Printf ("% T,% vn", r, r) 3r3740. 3r33737. 3r3742. 3r3757. 3r33744. The result will be identical for panic (nil)
and for a program that does not panic. 3r33737. 3r3742. 3r3757. 3r33744. A runable example of the described behavior . 3r33737. 3r3742. 3r3757. 3r3645. 3r3753. 3r3753. 3r3742. 3r3757. 3r33744. You can run the linter on separate files, with arguments like . /3r340. or packages (by their import path). 3r33737. 3r3742. 3r3757.
./mylinter check bytes
$ GOROOT /src /bytes /buffer_test.go: 276: 3: panicNil: panic (nil) calls are discouraged
3r33737. 3r3742. 3r3757.
# Next, it is assumed that go-lintpack is under your $ GOPATH. 3r3757. mylinter = $ (pwd) /mylinter
3r3757. cd $ (go env GOPATH) /src/github.com/go-lintpack/lintpack/checkers/testdata
3r3757. $ mylinter check ./panicNil/
./panicNil/positive_tests.go 57: panicNil: panic (nil) calls are discouraged
./panicNil/positive_tests.go:9: panicNil: panic (interface {} (nil)) calls are discouraged
3r33737. 3r3742. 3r3757. 3r33744. By default, this check also responds to r3r3739. panic (interface {} (nil)) 3r3373740. . To override this behavior, you need to set the value to skipNilEfaceLit
in 3r3739. true
. This can be done via the command line: 3r3742. 3r3757.
$ mylinter check [email protected]=true ./panicNil/
./panicNil/positive_tests.go 57: panicNil: panic (nil) calls are discouraged
3r33737. 3r3742. 3r3757. 3r?383. 3r33584. usage for cmd /lintpack and generated linter [/b] 3r33586. 3r3645. 3r3742. 3r3757. 3r33744. And lintpack
, and the generated linter, use the first argument to select a subcommand. A list of available subcommands and examples of their launch can be obtained by calling the utility with no arguments. 3r33737. 3r3742. 3r3757.
lintpack
not enough arguments, expected sub-command name
3r3757. Supported sub-commands:
build - build linter from 3g3r3757. $ lintpack build -help
$ lintpack build -o gocritic github.com/go-critic/checkers
$ lintpack build -linter.version = v???. 3r3757. version - print lintpack version
$ lintpack version
3r33737. 3r3742. 3r3757. 3r33744. Suppose we called the created linter named gocritic
: 3r3742. 3r3757.
./gocritic
not enough arguments, expected sub-command name
3r3757. Supported sub-commands:
check - run linter over specified targets
$ linter check -help
$ linter check -disableTags = none strings bytes
$ linter check -enableTags = diagnostic. /3r3757. version - print linter version
$ linter version
doc - get installed checkers documentation
$ linter doc -help
$ linter doc
$ linter doc checkerName
3r33737. 3r3742. 3r3757. 3r33744. For some subcommands, the flag is available. -help
which provides additional information (I cut some too wide lines): 3r3742. 3r3757.
./gocritic check -help
# Information on all available flags. 3r33737. 3r33737. 3r3742. 3r3757. 3r3645. 3r3753. 3r3753. 3r3742. 3r3757. 3r33385. Documentation installed checks 3r3729. 3r3742. 3r3757. 3r33744. The answer to the question "how do I know about that skipNilEfaceLit parameter?" - read the fancy manual (RTFM)! 3r33737. 3r3742. 3r3757. 3r33744. All documentation of the installed checks is inside 3r3739. mylinter
. This documentation is available through the subcommand doc 3r340 : 3r3742. 3r3757.
# Displays a list of all installed checks:
$ mylinter doc
panicNil[diagnostic]3r3757. 3r3757. # Displays detailed documentation for the requested check:
$ mylinter doc panicNil
panicNil checker documentation
URL: github.com/go-lintpack/lintpack
Tags:[diagnostic]3r3757. 3r3757. Detects panic (nil) calls. 3r3757. 3r3757. Such panic calls are hard to handle during recover. 3r3757. 3r3757. Non-compliant code:
panic (nil)
3r3757. Compliant code:
panic ("something meaningful")
3r3757. Checker parameters:
[email protected] bool
whether to ignore interface {} (nil) arguments (default false)
3r33737. 3r3742. 3r3757. 3r33744. Similar to template support in go list -f
, you can pass a template string that is responsible for the output format of the documentation, which can be useful when drawing up markdown documents. 3r33737. 3r3742. 3r3757. 3r33434. Where to find checks for installation? 3r3742. 3r3757. 3r33744. To simplify the search for useful sets of checks, there is a centralized list for lintpack
-compatible packages: https://go-lintpack.github.io/ . 3r33737. 3r3742. 3r3757. 3r33744. Here are some of the list: 3r3742. 3r3757.
3r3757. 3r33557. https://github.com/go-critic/go-critic/checkers 3r33560. 3r3757. 3r33557. https://github.com/go-critic/checkers-contrib 3r33560. 3r3757. 3r33557. 3r33464. https://github.com/Quasilyte/go-police 3r33560. 3r3757. 3r33434. 3r3742. 3r3757. 3r33744. This list is periodically updated and is open to requests for addition. Any of these packages can be used to create a linter. 3r33737. 3r3742. 3r3757. 3r33744. The command below creates a linter that contains all the checks from the list above: 3r3742. 3r3757.
# First you need to make sure the source codes of all the checks are
# available for Go compiler. 3r3757. go get -v github.com /go-critic /go-critic /checkers
go get -v github.com/go-critic/checkers-contrib
go get -v github.com/Quasilyte/go-police
3r3757. # build accepts a list of packages. 3r3757. lintpack build
github.com/go-critic/go-critic/checkers
github.com/go-critic/checkers-contrib
github.com/Quasilyte/go-police
3r33737. 3r3742. 3r3757. 3r33744. lintpack build
includes all checks at the compilation stage, the resulting linter can be placed in an environment where there are no source codes for the implementation of installed diagnostics, all as usual with static linking. 3r33737. 3r3742. 3r3757. 3r301501. Dynamic Packet Connection 3r3742. 3r3757. 3r33744. In addition to the static build, it is possible to load plugins that provide additional checks. 3r33737. 3r3742. 3r3757. 3r33744. The peculiarity is that the checker implementation does not know whether it will be used in static compilation or will be loaded as a plugin. No code changes are required. 3r33737. 3r3742. 3r3757. 3r33744. Suppose we want to add panicNil
into the linter, but we are not able to rebuild it from all the sources that were used during the first compilation. 3r33737. 3r3742. 3r3757. 3r33555. 3r3757. 3r33557. Create 3r3739. linterPlugin.go
: 3r33560. 3r3757. 3r? 3562. 3r3742. 3r3757.
3r? 3530. package main
3r3757. //If you want to include in the plugin more than one set of checks,
//just add the required imports. 3r3757. import (3r3757. _ "github.com/go-lintpack/lintpack/checkers"
)
3r33737. 3r3742. 3r3757. 3r33555. 3r3757. 3r33557. We collected dynamic library: 3r33535. 3r3757. 3r? 3562. 3r3742. 3r3757. go build -buildmode = plugin -o linterPlugin.so linterPlugin.go
3r33737. 3r3742. 3r3757. 3r33555. 3r3757. 3r33557. We start the linter with the parameter-pluginPath
: 3r33560. 3r3757. 3r? 3562. 3r3742. 3r3757.
./linter check -pluginPath = linterPlugin.so bytes
3r33737. 3r3742. 3r3757. 3r33571. 3r? 3572. Warning: 3r37373. Support for dynamic modules is implemented through the package. plugin that does not work on windows. 3r33576. 3r33744. Flag-verbose
It can help to figure out which check is on or off, and, most importantly, which filter will turn off the check. 3r33737. 3r3742. 3r3757. 3r?383. 3r33584. Example with -verbose [/b] 3r33586. 3r3645. 3r3742. 3r3757. 3r33744. Please note thatpanicNil
displayed in the list of included checks. If we remove the argument-pluginPath
it will cease to be true. 3r33737. 3r3742. 3r3757.
./linter check -verbose -pluginPath =. /linterPlugin.so bytes
, but if we are talking about an error in the implementation of the test itself, this is the problem of the authors of the test, the lintpack ecosystem. 3r33737. 3r3742. 3r3757. 3r33744. In other words, these projects solve various problems. 3r33737. 3r3742. 3r3757. 3r3690. And what about the go-critic? 3r3742. 3r3757. 3r33744. The process of porting
debug: appendCombine: disabled by tags tags (-disableTags)
debug: boolExprSimplify: disabled by tags (-disableTags)
debug: builtinShadow: disabled by tags tags (-disableTags)
debug: commentedOutCode: disabled by tags (-disableTags)
debug: deprecatedComment: disabled tags tags (-disableTags)
debug: docStub: disabled by tags tags (-disableTags)
debug: emptyFallthrough: disabled by tags tags (-disableTags)
debug: hugeParam: disabled by tags tags (-disableTags)
debug: importShadow: disabled tags tags (-disableTags)
debug: indexAlloc: disabled by tags tags (-disableTags)
debug: methodExprCall: disabled by tags tags (-disableTags)
debug: nilValReturn: disabled by tags (-disableTags)
debug: paramTypeCombine: disabled by tags (-disableTags)
debug: rangeExprCopy: disabled by tags tags (-disableTags)
debug: rangeValCopy: disabled by tags tags (-disableTags)
debug: sloppyReassign: disabled by tags tags (-disableTags)
debug: typeUnparen: disabled by tags tags (-disableTags)
debug: unlabelStmt: disabled by tags (-disableTags)
debug: wrapperFunc: disabled tags tags (-disableTags)
debug: appendAssign is enabled
debug: assignOp is enabled
debug: captLocal is enabled
debug: caseOrder is enabled
debug: defaultCaseOrder is enabled
debug: dupArg is enabled
debug: dupBranchBody is enabled
debug: dupCase is enabled
debug: dupSubExpr is enabled
debug: elseif is enabled
debug: flagDeref is enabled
debug: ifElseChain is enabled
debug: panicNil is enabled
debug: regexpMust is enabled
debug: singleCaseSwitch is enabled
debug: sloppyLen is enabled
debug: switchTrue is enabled
debug: typeSwitchVar is enabled
debug: underef is enabled
debug: unlambda is enabled
debug: unslice is enabled
# the result of the linter. 3r33737. 3r33737. 3r3742. 3r3757. 3r3645. 3r3753. 3r3753. 3r3742. 3r3757. 3r3650. Comparison with 3r3663. gometalinter and 3r3665. golangci-lint 3r3742. 3r3757. 3r33744. To avoid confusion, it is worth describing the main differences between the projects. 3r33737. 3r3742. 3r3757. 3r33744. 3r3663. gometalinter and 3r3665. golangci-lint First of all, they integrate other, often very differently implemented, linters, providing them with easy access. They target end users who will use static analyzers. 3r33737. 3r3742. 3r3757. 3r33744. lintpack simplifies the creation of new linters, provides a framework that makes different packages, implemented on its basis, compatible within one executable file. These checks (for golangci-lint) or the executable file (for the gometalinter) can then be embedded in the aforementioned meta linters. 3r33737. 3r3742. 3r3757. 3r33744. Suppose some oflintpack
-compatible checks are part ofgolangci-lint
. If there is any problem with the convenience of its use - this may be the responsibility area of 3r3739. golangci-lintgo-critic
on 3r3739. lintpack is almost complete. work-in-progress can be found in the repository 3r336996. go-critic /checkers . After the transition is complete, the checks will be moved togo-critic /go-critic /checkers
. 3r33737. 3r3742. 3r3757.
# Install go-critic to:
3r33737. 3r3742. 3r3757. 3r33744. Great sense to use
go get -v github.com/go-critic/go-critic /
3r3757. # Install go-critic after:
lintpack -o gocritic github.com/go-critic/go-critic/checkersgo-critic
outsidegolangci-lint
no, butlintpack
may allow to install those checks that are not included in the setgo-critic
. For example, it may be a diagnosis written by you. 3r33737. 3r3742. 3r3757.
To be continued
3r3742. 3r3757. 3r33744. How to create your 3r3739. lintpack -compatible checks you will learn in the next article. 3r33737. 3r3742. 3r3757. 3r33744. In the same place we will analyze what advantages you get when you implement your linter based on lintpack
compared with the implementation of a clean slate. 3r33737. 3r3742. 3r3757. 3r33744. I hope you have an appetite for new checks for Go. Let us know how static analysis will become too much, we will quickly solve this problem together. 3r33737. 3r3753. 3r3757. 3r3757. 3r3757. 3r33750. ! function (e) {function t (t, n) {if (! (n in e)) {for (var r, a = e.document, i = a.scripts, o = i.length; o-- ;) if (-1! == i[o].src.indexOf (t)) {r = i[o]; break} if (! r) {r = a.createElement ("script"), r.type = "text /jаvascript", r.async =! ? r.defer =! ? r.src = t, r.charset = "UTF-8"; var d = function () {var e = a.getElementsByTagName ("script")[0]; e. ): d ()}}} t ("//mediator.mail.ru/script/2820404/"""_mediator") () (); 3r3751. 3r3757. 3r3753. 3r3757. 3r3757. 3r3757. 3r3757.
It may be interesting
weber
Author17-11-2018, 18:37
Publication DateOpen source / Programming / Perfect code
Category- Comments: 0
- Views: 354
entegrasyon programları
entegrasyon programları
Corvus Health provides medical training services as well as recruiting high quality health workers for you or placing our own best team in your facility. Check Out: Health Workforce Recruitment
I.T HATCH offers a wide range of IT services including remote access setup, small business servers, data storage solutions, IT strategy services, and more. Check Out: IT strategy services