Giter Site home page Giter Site logo

alexkohler / cfmt Goto Github PK

View Code? Open in Web Editor NEW
27.0 4.0 3.0 33 KB

cfmt is a tool to wrap Go comments over a certain length to a new line.

License: MIT License

Go 100.00%
golang go static-code-analysis static-analyzer static-analysis comment commenting comments

cfmt's Introduction

cfmt

cfmt is a tool to wrap Go comments over a certain length to a new line.

Installation

go get -u github.com/alexkohler/cfmt

Note: cfmt requires gofmt.

Usage

Similar to other Go static anaylsis tools (such as golint, go vet), cfmt can be invoked with one or more filenames, directories, or packages named by its import path. cfmt also supports the ... wildcard.

cfmt [flags] files/directories/packages

Flags

  • -m - Maximum comment length before cfmt should insert a line break. (Default 80)
  • -w - Writes changes to file. By default, cfmt will only print the changes it will make, but will not modify the input files.

Examples

cfmt will wrap to a new line or join an existing line as appropriate. See the following before/afters of running cfmt -m=100:

Before

// I am a long comment that is over 100 characters long. I should probably wrap to a new line.

After

// I am a long comment that is over 100 characters long. I should probably wrap
// to a new line.

Before

// I am a long comment that is over 100 characters long. I should probably wrap below to the
// rest of the comment.

After

// I am a long comment that is over 100 characters long. I should probably wrap
// below to the rest of the comment.

Before

//I am a long comment that starts without a space and is over 100 characters long. When I wrap, I should still start without a space

After

//I am a long comment that starts without a space and is over 100 characters
//long. When I wrap, I should still start without a space

cfmt ignores block (/* */) comments and "grouped" comments over a length of 10 (i.e. 10+ consecutive lines starting with //).

Contributing

Pull requests welcome!

Other static analysis tools

If you've enjoyed cfmt, take a look at my other static anaylsis tools!

  • nakedret - Finds naked returns.
  • unimport - Finds unnecessary import aliases.
  • prealloc - Finds slice declarations that could potentially be preallocated.

cfmt's People

Contributors

barryz 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

Watchers

 avatar  avatar  avatar  avatar

cfmt's Issues

Files without comments are purged

Scenario

Create a file test.go with the following contents:

package "test"

type Uncommented struct{}

Then run cfmt -m 100 -w test.go.

Expected

File remains unchanged

Reality

The file's contents are purged. (0 byte file)

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.