feat: align example treefmt config with flake treefmt config
Prevent unnecessary reformatting
This commit is contained in:
parent
0c93d98483
commit
12452b01b6
|
@ -55,7 +55,7 @@ func TestConfig(t *testing.T) {
|
||||||
// nix
|
// nix
|
||||||
nix, ok := cfg.Formatters["nix"]
|
nix, ok := cfg.Formatters["nix"]
|
||||||
as.True(ok, "nix formatter not found")
|
as.True(ok, "nix formatter not found")
|
||||||
as.Equal("nixpkgs-fmt", nix.Command)
|
as.Equal("alejandra", nix.Command)
|
||||||
as.Nil(nix.Options)
|
as.Nil(nix.Options)
|
||||||
as.Equal([]string{"*.nix"}, nix.Includes)
|
as.Equal([]string{"*.nix"}, nix.Includes)
|
||||||
as.Equal([]string{"examples/nix/sources.nix"}, nix.Excludes)
|
as.Equal([]string{"examples/nix/sources.nix"}, nix.Excludes)
|
||||||
|
@ -72,7 +72,7 @@ func TestConfig(t *testing.T) {
|
||||||
prettier, ok := cfg.Formatters["prettier"]
|
prettier, ok := cfg.Formatters["prettier"]
|
||||||
as.True(ok, "prettier formatter not found")
|
as.True(ok, "prettier formatter not found")
|
||||||
as.Equal("prettier", prettier.Command)
|
as.Equal("prettier", prettier.Command)
|
||||||
as.Equal([]string{"--write"}, prettier.Options)
|
as.Equal([]string{"--write", "--tab-width", "4"}, prettier.Options)
|
||||||
as.Equal([]string{
|
as.Equal([]string{
|
||||||
"*.css",
|
"*.css",
|
||||||
"*.html",
|
"*.html",
|
||||||
|
@ -88,12 +88,12 @@ func TestConfig(t *testing.T) {
|
||||||
as.Equal([]string{"CHANGELOG.md"}, prettier.Excludes)
|
as.Equal([]string{"CHANGELOG.md"}, prettier.Excludes)
|
||||||
|
|
||||||
// rust
|
// rust
|
||||||
// rust, ok := cfg.Formatters["rust"]
|
rust, ok := cfg.Formatters["rust"]
|
||||||
// as.True(ok, "rust formatter not found")
|
as.True(ok, "rust formatter not found")
|
||||||
// as.Equal("rustfmt", rust.Command)
|
as.Equal("rustfmt", rust.Command)
|
||||||
// as.Equal([]string{"--edition", "2018"}, rust.Options)
|
as.Equal([]string{"--edition", "2018"}, rust.Options)
|
||||||
// as.Equal([]string{"*.rs"}, rust.Includes)
|
as.Equal([]string{"*.rs"}, rust.Includes)
|
||||||
// as.Nil(rust.Excludes)
|
as.Nil(rust.Excludes)
|
||||||
|
|
||||||
// shell
|
// shell
|
||||||
shell, ok := cfg.Formatters["shell"]
|
shell, ok := cfg.Formatters["shell"]
|
||||||
|
|
|
@ -28,12 +28,11 @@
|
||||||
golangci-lint
|
golangci-lint
|
||||||
|
|
||||||
# formatters for testing
|
# formatters for testing
|
||||||
|
alejandra
|
||||||
elmPackages.elm-format
|
elmPackages.elm-format
|
||||||
haskellPackages.cabal-fmt
|
haskellPackages.cabal-fmt
|
||||||
haskellPackages.ormolu
|
haskellPackages.ormolu
|
||||||
mdsh
|
mdsh
|
||||||
nixpkgs-fmt
|
|
||||||
nodePackages.prettier
|
nodePackages.prettier
|
||||||
python3.pkgs.black
|
python3.pkgs.black
|
||||||
rufo
|
rufo
|
||||||
|
|
|
@ -15,7 +15,21 @@
|
||||||
statix.enable = true;
|
statix.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
settings.formatter.prettier.options = ["--tab-width" "4"];
|
settings.formatter.prettier = {
|
||||||
|
options = ["--tab-width" "4"];
|
||||||
|
includes = [
|
||||||
|
"*.css"
|
||||||
|
"*.html"
|
||||||
|
"*.js"
|
||||||
|
"*.json"
|
||||||
|
"*.jsx"
|
||||||
|
"*.md"
|
||||||
|
"*.mdx"
|
||||||
|
"*.scss"
|
||||||
|
"*.ts"
|
||||||
|
"*.yaml"
|
||||||
|
];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
devshells.default = {
|
devshells.default = {
|
||||||
|
|
|
@ -46,7 +46,10 @@ const helloFactory = function ({ React }) {
|
||||||
return (
|
return (
|
||||||
<p>
|
<p>
|
||||||
Hello,
|
Hello,
|
||||||
<span style={styles.displayMode} onClick={() => setMode("edit")}>
|
<span
|
||||||
|
style={styles.displayMode}
|
||||||
|
onClick={() => setMode("edit")}
|
||||||
|
>
|
||||||
{word}!
|
{word}!
|
||||||
</span>
|
</span>
|
||||||
<input
|
<input
|
||||||
|
|
|
@ -3,8 +3,7 @@ let
|
||||||
#
|
#
|
||||||
# The fetchers. fetch_<type> fetches specs of type <type>.
|
# The fetchers. fetch_<type> fetches specs of type <type>.
|
||||||
#
|
#
|
||||||
fetch_file = pkgs: name: spec:
|
fetch_file = pkgs: name: spec: let
|
||||||
let
|
|
||||||
name' = sanitizeName name + "-src";
|
name' = sanitizeName name + "-src";
|
||||||
in
|
in
|
||||||
if spec.builtin or true
|
if spec.builtin or true
|
||||||
|
@ -20,8 +19,7 @@ let
|
||||||
name = name';
|
name = name';
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch_tarball = pkgs: name: spec:
|
fetch_tarball = pkgs: name: spec: let
|
||||||
let
|
|
||||||
name' = sanitizeName name + "-src";
|
name' = sanitizeName name + "-src";
|
||||||
in
|
in
|
||||||
if spec.builtin or true
|
if spec.builtin or true
|
||||||
|
@ -37,8 +35,7 @@ let
|
||||||
inherit (spec) url sha256;
|
inherit (spec) url sha256;
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch_git = name: spec:
|
fetch_git = name: spec: let
|
||||||
let
|
|
||||||
ref =
|
ref =
|
||||||
spec.ref
|
spec.ref
|
||||||
or (
|
or (
|
||||||
|
@ -85,8 +82,7 @@ let
|
||||||
);
|
);
|
||||||
|
|
||||||
# The set of packages used when specs are fetched using non-builtins.
|
# The set of packages used when specs are fetched using non-builtins.
|
||||||
mkPkgs = sources: system:
|
mkPkgs = sources: system: let
|
||||||
let
|
|
||||||
sourcesNixpkgs =
|
sourcesNixpkgs =
|
||||||
import (builtins_fetchTarball {inherit (sources.nixpkgs) url sha256;}) {inherit system;};
|
import (builtins_fetchTarball {inherit (sources.nixpkgs) url sha256;}) {inherit system;};
|
||||||
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
|
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
|
||||||
|
@ -123,8 +119,7 @@ let
|
||||||
|
|
||||||
# If the environment variable NIV_OVERRIDE_${name} is set, then use
|
# If the environment variable NIV_OVERRIDE_${name} is set, then use
|
||||||
# the path directly as opposed to the fetched source.
|
# the path directly as opposed to the fetched source.
|
||||||
replace = name: drv:
|
replace = name: drv: let
|
||||||
let
|
|
||||||
saneName =
|
saneName =
|
||||||
stringAsChars
|
stringAsChars
|
||||||
(c:
|
(c:
|
||||||
|
@ -180,13 +175,10 @@ let
|
||||||
else {};
|
else {};
|
||||||
|
|
||||||
# fetchTarball version that is compatible between all the versions of Nix
|
# fetchTarball version that is compatible between all the versions of Nix
|
||||||
builtins_fetchTarball =
|
builtins_fetchTarball = {
|
||||||
{ url
|
url,
|
||||||
, name ? null
|
name ? null,
|
||||||
, sha256
|
} @ attrs: let
|
||||||
,
|
|
||||||
} @ attrs:
|
|
||||||
let
|
|
||||||
inherit (builtins) lessThan nixVersion fetchTarball;
|
inherit (builtins) lessThan nixVersion fetchTarball;
|
||||||
in
|
in
|
||||||
if lessThan nixVersion "1.12"
|
if lessThan nixVersion "1.12"
|
||||||
|
@ -194,13 +186,10 @@ let
|
||||||
else fetchTarball attrs;
|
else fetchTarball attrs;
|
||||||
|
|
||||||
# fetchurl version that is compatible between all the versions of Nix
|
# fetchurl version that is compatible between all the versions of Nix
|
||||||
builtins_fetchurl =
|
builtins_fetchurl = {
|
||||||
{ url
|
url,
|
||||||
, name ? null
|
name ? null,
|
||||||
, sha256
|
} @ attrs: let
|
||||||
,
|
|
||||||
} @ attrs:
|
|
||||||
let
|
|
||||||
inherit (builtins) lessThan nixVersion fetchurl;
|
inherit (builtins) lessThan nixVersion fetchurl;
|
||||||
in
|
in
|
||||||
if lessThan nixVersion "1.12"
|
if lessThan nixVersion "1.12"
|
||||||
|
@ -221,16 +210,17 @@ let
|
||||||
config.sources;
|
config.sources;
|
||||||
|
|
||||||
# The "config" used by the fetchers
|
# The "config" used by the fetchers
|
||||||
mkConfig =
|
mkConfig = {
|
||||||
{ sourcesFile ? if builtins.pathExists ./sources.json
|
sourcesFile ?
|
||||||
|
if builtins.pathExists ./sources.json
|
||||||
then ./sources.json
|
then ./sources.json
|
||||||
else null
|
else null,
|
||||||
, sources ? if (sourcesFile == null)
|
sources ?
|
||||||
|
if (sourcesFile == null)
|
||||||
then {}
|
then {}
|
||||||
else builtins.fromJSON (builtins.readFile sourcesFile)
|
else builtins.fromJSON (builtins.readFile sourcesFile),
|
||||||
, system ? builtins.currentSystem
|
system ? builtins.currentSystem,
|
||||||
, pkgs ? mkPkgs sources system
|
pkgs ? mkPkgs sources system,
|
||||||
,
|
|
||||||
}: rec {
|
}: rec {
|
||||||
# The sources, i.e. the attribute set of spec name to spec
|
# The sources, i.e. the attribute set of spec name to spec
|
||||||
inherit sources;
|
inherit sources;
|
||||||
|
|
|
@ -27,7 +27,7 @@ includes = ["*.hs"]
|
||||||
excludes = ["examples/haskell/"]
|
excludes = ["examples/haskell/"]
|
||||||
|
|
||||||
[formatter.nix]
|
[formatter.nix]
|
||||||
command = "nixpkgs-fmt"
|
command = "alejandra"
|
||||||
includes = ["*.nix"]
|
includes = ["*.nix"]
|
||||||
# Act as an example on how to exclude specific files
|
# Act as an example on how to exclude specific files
|
||||||
excludes = ["examples/nix/sources.nix"]
|
excludes = ["examples/nix/sources.nix"]
|
||||||
|
@ -39,7 +39,7 @@ includes = ["*.rb"]
|
||||||
|
|
||||||
[formatter.prettier]
|
[formatter.prettier]
|
||||||
command = "prettier"
|
command = "prettier"
|
||||||
options = ["--write"]
|
options = ["--write", "--tab-width", "4"]
|
||||||
includes = [
|
includes = [
|
||||||
"*.css",
|
"*.css",
|
||||||
"*.html",
|
"*.html",
|
||||||
|
|
Reference in New Issue
Block a user