All Projects → timakin → Bodyclose

timakin / Bodyclose

Licence: mit
Analyzer: checks whether HTTP response body is closed and a re-use of TCP connection is not blocked.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Bodyclose

Spotbugs
SpotBugs is FindBugs' successor. A tool for static analysis to look for bugs in Java code.
Stars: ✭ 2,569 (+1319.34%)
Mutual labels:  static-analysis, linter, code-analysis
Pmd
An extensible multilanguage static code analyzer.
Stars: ✭ 3,667 (+1925.97%)
Mutual labels:  static-analysis, linter, code-analysis
static-code-analysis-plugin
A plugin to simplify Static Code Analysis on Gradle. Not restricted to, but specially useful, in Android projects, by making sure all analysis can access the SDK classes.
Stars: ✭ 36 (-80.11%)
Mutual labels:  linter, static-analysis, code-analysis
Credo
A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
Stars: ✭ 4,144 (+2189.5%)
Mutual labels:  static-analysis, linter, code-analysis
Wotan
Pluggable TypeScript and JavaScript linter
Stars: ✭ 271 (+49.72%)
Mutual labels:  static-analysis, linter, code-analysis
Eslint Plugin Sonarjs
SonarJS rules for ESLint
Stars: ✭ 458 (+153.04%)
Mutual labels:  static-analysis, linter, code-analysis
Spoon
Spoon is a metaprogramming library to analyze and transform Java source code (up to Java 15). 🥄 is made with ❤️, 🍻 and ✨. It parses source files to build a well-designed AST with powerful analysis and transformation API.
Stars: ✭ 1,078 (+495.58%)
Mutual labels:  static-analysis, code-analysis
Clj Kondo
A linter for Clojure code that sparks joy.
Stars: ✭ 1,083 (+498.34%)
Mutual labels:  static-analysis, linter
Static Analysis
⚙️ A curated list of static analysis (SAST) tools for all programming languages, config files, build tools, and more.
Stars: ✭ 9,310 (+5043.65%)
Mutual labels:  static-analysis, linter
Gopherci
GopherCI was a project to help you maintain high-quality Go projects, by checking each GitHub Pull Request, for backward incompatible changes, and a suite of other third party static analysis tools.
Stars: ✭ 105 (-41.99%)
Mutual labels:  static-analysis, linter
Awesome Go Linters
A curated list of awesome Go linters. More than 60 linters and tools!
Stars: ✭ 801 (+342.54%)
Mutual labels:  static-analysis, linter
Radon
Various code metrics for Python code
Stars: ✭ 1,193 (+559.12%)
Mutual labels:  static-analysis, code-analysis
Rubysonar
an advanced semantic indexer for Ruby
Stars: ✭ 175 (-3.31%)
Mutual labels:  static-analysis, code-analysis
Pysonar2
PySonar2: an advanced semantic indexer for Python
Stars: ✭ 1,074 (+493.37%)
Mutual labels:  static-analysis, code-analysis
Php Language Server
PHP Implementation of the VS Code Language Server Protocol 🆚↔🖥
Stars: ✭ 1,019 (+462.98%)
Mutual labels:  static-analysis, code-analysis
Flake8
The official GitHub mirror of https://gitlab.com/pycqa/flake8
Stars: ✭ 1,112 (+514.36%)
Mutual labels:  static-analysis, linter
Sonar Jproperties Plugin
SonarQube Java Properties Analyzer
Stars: ✭ 5 (-97.24%)
Mutual labels:  static-analysis, linter
Unimport
A linter, formatter for finding and removing unused import statements.
Stars: ✭ 96 (-46.96%)
Mutual labels:  static-analysis, linter
Njsscan
njsscan is a semantic aware SAST tool that can find insecure code patterns in your Node.js applications.
Stars: ✭ 128 (-29.28%)
Mutual labels:  static-analysis, linter
Find Sec Bugs
The SpotBugs plugin for security audits of Java web applications and Android applications. (Also work with Kotlin, Groovy and Scala projects)
Stars: ✭ 1,748 (+865.75%)
Mutual labels:  static-analysis, code-analysis

bodyclose

CircleCI

bodyclose is a static analysis tool which checks whether res.Body is correctly closed.

Install

You can get bodyclose by go get command.

$ go get -u github.com/timakin/bodyclose

How to use

bodyclose run with go vet as below when Go is 1.12 and higher.

$ go vet -vettool=$(which bodyclose) github.com/timakin/go_api/...
# github.com/timakin/go_api
internal/httpclient/httpclient.go:13:13: response body must be closed

When Go is lower than 1.12, just run bodyclose command with the package name (import path).

But it cannot accept some options such as --tags.

$ bodyclose github.com/timakin/go_api/...
~/go/src/github.com/timakin/api/internal/httpclient/httpclient.go:13:13: response body must be closed

Analyzer

bodyclose validates whether *net/http.Response of HTTP request calls method Body.Close() such as below code.

resp, err := http.Get("http://example.com/") // Wrong case
if err != nil {
	// handle error
}
body, err := ioutil.ReadAll(resp.Body)

This code is wrong. You must call resp.Body.Close when finished reading resp.Body.

resp, err := http.Get("http://example.com/")
if err != nil {
	// handle error
}
defer resp.Body.Close() // OK
body, err := ioutil.ReadAll(resp.Body)

In the GoDoc of Client.Do this rule is clearly described.

If you forget this sentence, a HTTP client cannot re-use a persistent TCP connection to the server for a subsequent "keep-alive" request.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].