Compare commits
14 Commits
fe3333eaa1
...
422bc1be2a
Author | SHA1 | Date | |
---|---|---|---|
422bc1be2a | |||
83de5b485e | |||
6049472610 | |||
1e6a0ad963 | |||
1b62b19f21 | |||
b83c13852e | |||
1aac5ffda8 | |||
eaa5088eba | |||
b5b616ceb6 | |||
8bfe968645 | |||
bdd76f8c42 | |||
435abb9537 | |||
40221a6d61 | |||
8d5cf63440 |
@ -1,50 +1,32 @@
|
|||||||
# About the project
|
# About the project
|
||||||
|
|
||||||
`treefmt` is a formatting tool that saves you time: it provides developers with a universal way to trigger all
|
`treefmt` is a formatting tool that saves you time: it provides developers with a universal way to trigger all formatters needed for the project in one place.
|
||||||
formatters needed for the project in one place.
|
|
||||||
|
|
||||||
## Background
|
## Background
|
||||||
|
|
||||||
Typically, each project has its own code standards enforced by the project's owner. Any code contributions must match
|
Typically, each project has its own code standards enforced by the project's owner. Any code contributions must match that given standard, i.e. be formatted in a specific manner.
|
||||||
that given standard, i.e. be formatted in a specific manner.
|
|
||||||
|
|
||||||
At first glance, the task of code formatting may seem trivial: the formatter can be automatically triggered when you
|
At first glance, the task of code formatting may seem trivial: the formatter can be automatically triggered when you save a file in your IDE. Indeed, formatting doesn't take much effort if you're working on a single project long term: setting up the formatters in your IDE won't take much of your time, and then you're ready to go.
|
||||||
save a file in your IDE. Indeed, formatting doesn't take much effort if you're working on a single project long term:
|
|
||||||
setting up the formatters in your IDE won't take much of your time, and then you're ready to go.
|
|
||||||
|
|
||||||
Contrary to that, if you're working on multiple projects at the same time, you may have to update your formatter
|
Contrary to that, if you're working on multiple projects at the same time, you may have to update your formatter configs in the IDE each time you switch between the projects. This is because formatter settings aren't project-specific --- they are set up globally for all projects.
|
||||||
configs in the IDE each time you switch between the projects. This is because formatter settings aren't
|
|
||||||
project-specific --- they are set up globally for all projects.
|
|
||||||
|
|
||||||
Alternatively, you can trigger formatters manually, one-by-one or in a script. Actually, for bigger projects, it's
|
Alternatively, you can trigger formatters manually, one-by-one or in a script. Actually, for bigger projects, it's common to have a script that runs over your project's directories and calls formatters consequently. But it takes time to iterate through all the files.
|
||||||
common to have a script that runs over your project's directories and calls formatters consequently. But it takes time
|
|
||||||
to iterate through all the files.
|
|
||||||
|
|
||||||
All the solutions take up a significant amount of time which a developer could spend doing the actual work. They also
|
All the solutions take up a significant amount of time which a developer could spend doing the actual work. They also require you to remember which formatters and options are used by each project you are working on.
|
||||||
require you to remember which formatters and options are used by each project you are working on.
|
|
||||||
|
|
||||||
`treefmt` solves these issues.
|
`treefmt` solves these issues.
|
||||||
|
|
||||||
## Why treefmt?
|
## Why treefmt?
|
||||||
|
|
||||||
`treefmt`'s configuration is project-specific, so you don't need to re-configure formatters each time you switch
|
`treefmt`'s configuration is project-specific, so you don't need to re-configure formatters each time you switch between projects, like you have to when working with formatters in the IDE.
|
||||||
between projects, like you have to when working with formatters in the IDE.
|
|
||||||
|
|
||||||
Contrary to calling formatters from the command line, there's no need to remember all the specific formatters required
|
Contrary to calling formatters from the command line, there's no need to remember all the specific formatters required for each project. Once you set up the config, you can run the tool in any of your project's folders without any additional flags or options.
|
||||||
for each project. Once you set up the config, you can run the tool in any of your project's folders without any
|
|
||||||
additional flags or options.
|
|
||||||
|
|
||||||
Typically, formatters have different ways to say there was a specific error. With `treefmt`, you get a standardized
|
Typically, formatters have different ways to say there was a specific error. With `treefmt`, you get a standardized output which is easier to understand than the variegated outputs of different formatters, so it takes less time to grasp what's wrong.
|
||||||
output which is easier to understand than the variegated outputs of different formatters, so it takes less time to
|
|
||||||
grasp what's wrong.
|
|
||||||
|
|
||||||
In addition, `treefmt` works faster than the custom script solution because the changed files are cached and the
|
In addition, `treefmt` works faster than the custom script solution because the changed files are cached and the formatters run only against them. Moreover, formatters are run in parallel, which makes the tool even faster.
|
||||||
formatters run only against them. Moreover, formatters are run in parallel, which makes the tool even faster.
|
|
||||||
|
|
||||||
The difference may not be significant for smaller projects, but it gets quite visible as the project grows. For
|
The difference may not be significant for smaller projects, but it gets quite visible as the project grows. For instance, take the caching optimization. It takes 9 seconds to traverse a project of 1507 files and no changes without caching:
|
||||||
instance, take the caching optimization.
|
|
||||||
|
|
||||||
It takes 9 seconds to traverse a project of 1507 files and no changes without caching:
|
|
||||||
|
|
||||||
```
|
```
|
||||||
traversed 1507 files
|
traversed 1507 files
|
||||||
|
11
flake.lock
11
flake.lock
@ -208,16 +208,15 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1714382886,
|
"lastModified": 1707300477,
|
||||||
"narHash": "sha256-+gooxbbYcP+MORKQ7W/C2ATvlonW+dyHgCUPnu5dfco=",
|
"narHash": "sha256-qQF0fEkHlnxHcrKIMRzOETnRBksUK048MXkX0SOmxvA=",
|
||||||
"owner": "brianmcgee",
|
"owner": "numtide",
|
||||||
"repo": "treefmt-nix",
|
"repo": "treefmt-nix",
|
||||||
"rev": "535e6904c34964ce56d8c092835c11fe6341acc8",
|
"rev": "ac599dab59a66304eb511af07b3883114f061b9d",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "brianmcgee",
|
"owner": "numtide",
|
||||||
"ref": "feat/pipelines",
|
|
||||||
"repo": "treefmt-nix",
|
"repo": "treefmt-nix",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,7 @@
|
|||||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
flake-root.url = "github:srid/flake-root";
|
flake-root.url = "github:srid/flake-root";
|
||||||
treefmt-nix = {
|
treefmt-nix = {
|
||||||
# todo switch back to numtide/treefmt-nix once merged
|
url = "github:numtide/treefmt-nix";
|
||||||
url = "github:brianmcgee/treefmt-nix/feat/pipelines";
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
devshell = {
|
devshell = {
|
||||||
|
@ -22,37 +22,20 @@
|
|||||||
statix.enable = true;
|
statix.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
settings.formatter = {
|
settings.formatter.prettier = {
|
||||||
deadnix = {
|
options = ["--tab-width" "4"];
|
||||||
pipeline = "nix";
|
includes = [
|
||||||
priority = 1;
|
"*.css"
|
||||||
};
|
"*.html"
|
||||||
|
"*.js"
|
||||||
statix = {
|
"*.json"
|
||||||
pipeline = "nix";
|
"*.jsx"
|
||||||
priority = 2;
|
"*.md"
|
||||||
};
|
"*.mdx"
|
||||||
|
"*.scss"
|
||||||
alejandra = {
|
"*.ts"
|
||||||
pipeline = "nix";
|
"*.yaml"
|
||||||
priority = 3;
|
];
|
||||||
};
|
|
||||||
|
|
||||||
prettier = {
|
|
||||||
options = ["--tab-width" "4"];
|
|
||||||
includes = [
|
|
||||||
"*.css"
|
|
||||||
"*.html"
|
|
||||||
"*.js"
|
|
||||||
"*.json"
|
|
||||||
"*.jsx"
|
|
||||||
"*.md"
|
|
||||||
"*.mdx"
|
|
||||||
"*.scss"
|
|
||||||
"*.ts"
|
|
||||||
"*.yaml"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user