Giter VIP home page Giter VIP logo

alexandra's Introduction

Alejandra 💅

The Uncompromising Nix Code Formatter

CI/CD Coverage License: The Unlicense style: Alejandra

Try it on your browser! here

Features

  • ✔️ Fast

    It's written in Rust and formats Nixpkgs in just a few seconds. 1

  • ✔️ Powerful

    We define a comprehensive style for all possible combinations of the Nix expression language.

  • ✔️ Reliable

    High coverage, battle tested.

    From Nix's eyes, code is just the same. 2

  • ✔️ Beautiful

    Beauty is subjective, right?

    We started from the original style of Nixpkgs, and then we applied the feedback of developers who have used Nix at scale for several years, producing a very well-grounded style guide.

  • ✔️ Transparent

    You won't notice the formatter after a while.

    Humans care about the content, machines about the style!

  • ✔️ Native

    We integrate with common code editors and workflows:

Getting started

On the web editor

Please visit: kamadorueda.github.io/alejandra.

Prebuilt binaries

You can download a binary for your platform:

Make it executable ($ chmod +x) and run Alejandra with:

$ ./alejandra --help

or:

$ /path/to/alejandra --help

From Nixpkgs

Please visit: search.nixos.org/packages?query=alejandra.

Nix installation

  • Nix stable:

    $ nix-env -ivf https://github.com/kamadorueda/alejandra/tarball/3.0.0
  • Nix with Flakes:

    $ nix profile install github:kamadorueda/alejandra/3.0.0

Then run Alejandra with:

$ alejandra --help

NixOS installation

  • Nix stable:

    let
      alejandra =
        (import (builtins.fetchTarball {
          url = "https://github.com/kamadorueda/alejandra/tarball/3.0.0";
          sha256 = "0000000000000000000000000000000000000000000000000000";
        }) {})
        .outPath;
    in {
      environment.systemPackages = [alejandra];
    }
  • Nix with Flakes:

    {
      inputs = {
        nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    
        alejandra.url = "github:kamadorueda/alejandra/3.0.0";
        alejandra.inputs.nixpkgs.follows = "nixpkgs";
      };
    
      outputs = {alejandra, nixpkgs, ...}: {
        nixosConfigurations = {
          example = nixpkgs.lib.nixosSystem rec {
            # We support: aarch64-darwin, aarch64-linux, i686-linux, x86_64-darwin, x86_64-linux
            system = "x86_64-linux";
    
            modules = [
              {
                environment.systemPackages = [alejandra.defaultPackage.${system}];
              }
              # Import your other modules here
              # ./path/to/my/module.nix
              # ...
            ];
          };
        };
      };
    }

Do I need to configure anything?

  • No.

Discussion

Cool libraries

Alternatives

See why Alejandra was created and a comparison between alternatives here.

Alternatively, checkout the code examples of the different formatters here.

Versioning

We use semver to version Alejandra.

Our public API consists of:

  • The formatting rules (a.k.a. the style).
  • The CLI tool ($ alejandra), command line flags, positional arguments, exit codes, and stdout.

Changelog

Please read: CHANGELOG.

Contributors

The following people have helped improving Alejandra.

Thank you ❤️

Footnotes

Footnotes

  1. Running on a machine with:

    • CPU: 4 physical, 4 logical, 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    • MHz: from 400 to 4700 MHz
    • BogoMips: 5606.40
    • Cache L3: 12 MiB

    Using:

    # x86_64-unknown-linux-gnu
    $ time alejandra --threads $threads /path/to/nixpkgs
    

    Results:

    $threads Seconds
    1 45
    2 25
    4 14
  2. The methodology to claim this is:

    1. Checkout Nixpkgs and run:

      $ nix-env -qaf . --drv-path --xml > before
      
    2. Now format with Alejandra and run:

      $ nix-env -qaf . --drv-path --xml > after
      

    As of 2022-06-22, there are 41 differences in a set of 38109 derivations because of things like this:

    goDeps = ./deps.nix;
    

    Since ./deps.nix was also formatted you get a semantical difference.

    This is something that should be solved on Nixpkgs and not a bug in Alejandra. For example:

alexandra's People

Contributors

kamadorueda avatar tomberek avatar blaggacao avatar l0b0 avatar dependabot[bot] avatar piegamesde avatar loicreynier avatar mic92 avatar soupglasses avatar rehno-lindeque avatar 9999years avatar connorbaker avatar sciencentistguy avatar mkenigs avatar theutz avatar pyrox0 avatar n8henrie avatar tobiasbora avatar usersv4 avatar tazjin avatar

Stargazers

Ludovico avatar jade avatar Mars avatar Katia Esposito avatar Alex Jordan avatar Alex Jackson avatar Federico Damián Schonborn avatar uncenter avatar Jake Hamilton avatar Abhiram avatar Isabel avatar

Watchers

 avatar

alexandra's Issues

Consider: RFC0166 Function application

While preferably I'd like to stick as close as possible to Alejandra, one of my largest pet peeves with Alejandra is how newline happy it is for many function attributes longer than one...

So, I propose to allow having multiple arguments inline, given that the line-length does not get too long.

This however would require building up new logic inside Alejandra to do this measurement of such an "inline" block. If this is done, it would make it a much harder diversion from Alejandra as a project, and Alexandra would no longer be a simple "Alejandra, but with spaces!" project which was its primary goal.

Feedback is welcome.


Example:

For example given the input of:

{ arg1, arg2, arg3, ... }:

Alejandra would format it onto 4 separate lines:

{
  arg1,
  arg2,
  arg3,
  ...
}:

Consideration is to follow the precedent set by RFC 0166 for argument lists, which says notably the following:

As many arguments as possible must be fit onto the first line.
...
RFC 0166: Section for Function Application.

Which would allow the previous formatting to stay unchanged, as it is "small".

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.