Fgoi is a simple sorter for go imports written in rust

Related tags

Command-line fgoi
Overview

fgoi

Fgoi is a simple sorter for go imports written in rust.

Why did you do that??

Goimports is not exceptionally good with organizing blocks of imports unless those imports are already organized by somebody. There are weird artifacts that goimports produces that require manual organizing and I just don't like to do that.

Why fgoi?

Goimports is already taken, so I had to come up with some other name. Fgoi can be read as ffff goimports, or maybe fast goimports (it is written in rust so it has to be very fast, right? right?..), or whatever other way you like.

Why rust?

Because I like it.

How do I use thing bloody thing?

Very easy! Let me quote the help page of the app:

Usage: fgoi [OPTIONS] [FILES]...

Arguments:
  [FILES]...  

Options:
  -p, --package   Packages that need to be sorted separately from all the rest
  -h, --help               Print help information
  • FILES - list of files (or directories) to be organized
    • Files should have *.go format
    • Directories will be traversed recursively in search of go files
  • -p - [multiple] package masks to be separated in separate blocks

Every import in the file will be compared with the package mask provided in the -p key by the user, and if said import begins with whatever is in the arg, this import will go in its own block. With other imports that suit the mask.

Example!

Let's say we have the main.go file with some messed up imports.

import (
	pkgname "github.com/alice/pakcage"
	
	"net/http"
	"core"
	
	"github.com/some/package"
	"github.com/alice/pkg2"
)

Then we run command on this file:

fgoi -p 'github.com/alice' main.go

And voila, our imports are all fancy and sorted!

import (
	"core"
	"net/http"
	
	"github.com/some/package"
	
	pkgname "github.com/alice/pakcage"
	"github.com/alice/pkg2"
)

Phew, this looks much better, and my OCD is finally happy.

You might also like...
A simple CLI tool to create python project file structure, written in Rust
A simple CLI tool to create python project file structure, written in Rust

Ezpie Create python projects blazingly fast What Ezpie can do? It can create a python project directory What kind of directory can Ezpie create? For c

Dead simple, memoized cargo subcommand to hoist cargo-built binaries into the current working directory, written in Rust.
Dead simple, memoized cargo subcommand to hoist cargo-built binaries into the current working directory, written in Rust.

cargo-hoist Dead simple cargo subcommand to hoist cargo-built binaries into scope. stable Install | User Docs | Crate Docs | Reference | Contributing

A dead simple ANSI terminal color painting library for Rust.

yansi A dead simple ANSI terminal color painting library for Rust. use yansi::Paint; print!("{} light, {} light!", Paint::green("Green"), Paint::red(

(Rust) Coloring terminal so simple you already know how to do it !

Colored Coloring terminal so simple, you already know how to do it! "this is blue".blue(); "this is red".red(); "this is red on blue".red(

Simple Interactive Terminal Todo App in Rust
Simple Interactive Terminal Todo App in Rust

todo-rs Simple Interactive Terminal Todo App in Rust Quick Start $ cargo run TODO Controls Keys Description k, j Move cursor up and down Shift+K, Shif

Simple test app based on rust-psp

PSP Test App Simple test app based on rust-psp. Demonstrating the usage of C libs. Build Download and unzip the prebuilt PSPSDK (built from clang-psp)

Simple system monitoring app that runs on terminal. Made purely with Rust.
Simple system monitoring app that runs on terminal. Made purely with Rust.

What is it? RCTOP is a simple WIP system monitoring app that runs purely on terminal and doesn't feature GUI. One can compare it to htop, but more str

My solutions for the 2021 edition of the Advent of Code, using Rust and SOM (Simple Object Machine)

Advent of Code 2021 These are my solutions for the 2021 edition of the Advent of Code. The solutions are all implemented using both Rust and SOM (Simp

Simple command line flag parser for rust.

easy_flag Simple command line flag parser for rust. use easy_flag::FlagSet; fn main() - Result(), String{ let mut help = false; let mut my

Comments
  • refactor: Simplify imports iter

    refactor: Simplify imports iter

    Overview

    ImportSorter stores 3 types of imports in separate allocations, which removes the need for the ImportType enum. Though, some things are slower now (e.g. get_single_count as it iterates over 3 vectors) - probably not much slower, but it could make sense to check what usage patterns are the most common ones & adjust the data structure to optimize those patterns.

    HashMap is replaced with a vector, since only the suitable_custom_bucket function needs it and iterates over its keys. suitable_custom_bucket returns the proper bucket directly, so there is no need for value access later on inside insert, so, using a vector is simpler.

    ImportSorterIter over different buckets is replaced with:

    [&self.core, &self.third_party]
        .into_iter()
        .chain(self.custom.iter().map(|(_, b)| b))
    

    Which is effectively the same though, it might occupy a bit more space on the stack (I didn't check it).

    Also added a few more tests.

    opened by Stranger6667 0
  • chore: Add benchmarks for `GoFile`

    chore: Add benchmarks for `GoFile`

    This PR exposes a few structs (probably it would make sense to expose them anyway, so the crate could be used as a building block for other tools).

    As a follow-up, it might be nice to adjust a few APIs in terms of ergonomics (e.g. use some impl Into, add write_to to use it with custom writers, etc)

    At the moment, these benches include fs operations, it would be good to work with memory only inside benchmarks.

    opened by Stranger6667 0
  • Empty output if file has only an import block

    Empty output if file has only an import block

    Example from README.md:

    import (
    	pkgname "github.com/alice/pakcage"
    
    	"net/http"
    	"core"
    
    	"github.com/some/package"
    	"github.com/alice/pkg2"
    )
    

    with

    cargo r -- -p 'github.com/alice' example.go
    

    becomes a file with 3 newlines

    opened by Stranger6667 0
Releases(v0.1.0)
Owner
Alice Rum
Alice Rum
A simple CLI pomodoro timer written in Rust.

Pomodoro A simple CLI pomodoro timer written in Rust. Based on the Pomodoro Technique. Works on any platform that supports desktop notifications. Exam

null 6 Nov 26, 2021
Simple cli clipboard manager written in rust

Simple cli clipboard manager written in rust

null 5 Nov 13, 2022
A simple, fast and interruptable download accelerator, written in Rust

snatch A simple, fast and interruptable download accelerator, written in Rust WARNING This project is no longer maintained by @k0pernicus and @jean-se

Dernier Cri ® 657 Jan 3, 2023
This is a simple command line application to convert bibtex to json written in Rust and Python

bibtex-to-json This is a simple command line application to convert bibtex to json written in Rust and Python. Why? To enable you to convert very big

null 3 Mar 23, 2022
A simple program for C program IO testing. Written in Rust

A simple program for C program IO testing. Written in Rust, using concurrency to speed up valgrind testing. Make sure to update settings at your first run of the program!

null 1 Feb 22, 2022
A simple to-do list manager written in Rust

A simple To-Do list manager written in Rust I wrote this project while I'm learning Rust for practice. I decided to put this project online so that ot

Tiago Correia 4 Jan 5, 2023
Just a simple object renderer, written in under 500 lines using Rust.

All cargoes that the project runs are: bitflags: a crate for defining bitflag types cfg-if: a small macro crate for defining cfg-based - conditional c

null 3 May 4, 2023
F-Fetch targets low systems. Written in Rust. It's very simple, designed so you can pick it up and replace it.

F-Fetch F-Fetch targets low systems. Written in Rust. It's very simple, designed so you can pick it up and replace it. First Look ~/.config/ffetch/con

cd 3 Jul 10, 2023
Simple OpenAI CLI wrapper written in Rust, feat. configurable prompts and models

Quick Start git clone https://github.com/ryantinder/ask-rs cd ask cargo install --path . Example ask tell me about the Lockheed Martin SR71 >> The Loc

Ryan Tinder 3 Aug 9, 2023
Simple terminal file manager(vi-style keybindings) written in rust

rust-tfm rust-tfm is a terminal file manager written in rust heavily inspired by lf and ranger, and also inspired by suckless software. rust-tfm.mp4 F

Jiao ShiJie 9 Sep 26, 2023