Skip to content

Commit 12452b0

Browse files
committed
feat: align example treefmt config with flake treefmt config
Prevent unnecessary reformatting
1 parent 0c93d98 commit 12452b0

File tree

8 files changed

+211
-205
lines changed

8 files changed

+211
-205
lines changed

internal/format/config_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestConfig(t *testing.T) {
5555
// nix
5656
nix, ok := cfg.Formatters["nix"]
5757
as.True(ok, "nix formatter not found")
58-
as.Equal("nixpkgs-fmt", nix.Command)
58+
as.Equal("alejandra", nix.Command)
5959
as.Nil(nix.Options)
6060
as.Equal([]string{"*.nix"}, nix.Includes)
6161
as.Equal([]string{"examples/nix/sources.nix"}, nix.Excludes)
@@ -72,7 +72,7 @@ func TestConfig(t *testing.T) {
7272
prettier, ok := cfg.Formatters["prettier"]
7373
as.True(ok, "prettier formatter not found")
7474
as.Equal("prettier", prettier.Command)
75-
as.Equal([]string{"--write"}, prettier.Options)
75+
as.Equal([]string{"--write", "--tab-width", "4"}, prettier.Options)
7676
as.Equal([]string{
7777
"*.css",
7878
"*.html",
@@ -88,12 +88,12 @@ func TestConfig(t *testing.T) {
8888
as.Equal([]string{"CHANGELOG.md"}, prettier.Excludes)
8989

9090
// rust
91-
// rust, ok := cfg.Formatters["rust"]
92-
// as.True(ok, "rust formatter not found")
93-
// as.Equal("rustfmt", rust.Command)
94-
// as.Equal([]string{"--edition", "2018"}, rust.Options)
95-
// as.Equal([]string{"*.rs"}, rust.Includes)
96-
// as.Nil(rust.Excludes)
91+
rust, ok := cfg.Formatters["rust"]
92+
as.True(ok, "rust formatter not found")
93+
as.Equal("rustfmt", rust.Command)
94+
as.Equal([]string{"--edition", "2018"}, rust.Options)
95+
as.Equal([]string{"*.rs"}, rust.Includes)
96+
as.Nil(rust.Excludes)
9797

9898
// shell
9999
shell, ok := cfg.Formatters["shell"]

nix/devshell.nix

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@
2828
golangci-lint
2929

3030
# formatters for testing
31-
31+
alejandra
3232
elmPackages.elm-format
3333
haskellPackages.cabal-fmt
3434
haskellPackages.ormolu
3535
mdsh
36-
nixpkgs-fmt
3736
nodePackages.prettier
3837
python3.pkgs.black
3938
rufo

nix/treefmt.nix

+15-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,21 @@
1515
statix.enable = true;
1616
};
1717

18-
settings.formatter.prettier.options = ["--tab-width" "4"];
18+
settings.formatter.prettier = {
19+
options = ["--tab-width" "4"];
20+
includes = [
21+
"*.css"
22+
"*.html"
23+
"*.js"
24+
"*.json"
25+
"*.jsx"
26+
"*.md"
27+
"*.mdx"
28+
"*.scss"
29+
"*.ts"
30+
"*.yaml"
31+
];
32+
};
1933
};
2034

2135
devshells.default = {

test/examples/elm/elm.json

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
{
2-
"type": "application",
3-
"source-directories": ["src"],
4-
"elm-version": "0.19.1",
5-
"dependencies": {
6-
"direct": {
7-
"elm/browser": "1.0.2",
8-
"elm/core": "1.0.5",
9-
"elm/html": "1.0.0"
2+
"type": "application",
3+
"source-directories": ["src"],
4+
"elm-version": "0.19.1",
5+
"dependencies": {
6+
"direct": {
7+
"elm/browser": "1.0.2",
8+
"elm/core": "1.0.5",
9+
"elm/html": "1.0.0"
10+
},
11+
"indirect": {
12+
"elm/json": "1.1.3",
13+
"elm/time": "1.0.0",
14+
"elm/url": "1.0.0",
15+
"elm/virtual-dom": "1.0.2"
16+
}
1017
},
11-
"indirect": {
12-
"elm/json": "1.1.3",
13-
"elm/time": "1.0.0",
14-
"elm/url": "1.0.0",
15-
"elm/virtual-dom": "1.0.2"
18+
"test-dependencies": {
19+
"direct": {},
20+
"indirect": {}
1621
}
17-
},
18-
"test-dependencies": {
19-
"direct": {},
20-
"indirect": {}
21-
}
2222
}

test/examples/html/index.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!doctype html>
22
<html>
3-
<head>
4-
<meta charset="utf-8" />
5-
<title>Title</title>
6-
</head>
7-
<body>
8-
<h1>Hi!</h1>
9-
</body>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Title</title>
6+
</head>
7+
<body>
8+
<h1>Hi!</h1>
9+
</body>
1010
</html>
+52-49
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,68 @@
11
const helloFactory = function ({ React }) {
2-
const { string, func } = React.PropTypes;
2+
const { string, func } = React.PropTypes;
33

4-
return function Hello(props) {
5-
// React wants propTypes & defaultProps
6-
// to be static.
7-
Hello.propTypes = {
8-
word: string,
9-
mode: string,
4+
return function Hello(props) {
5+
// React wants propTypes & defaultProps
6+
// to be static.
7+
Hello.propTypes = {
8+
word: string,
9+
mode: string,
1010

11-
actions: React.PropTypes.shape({
12-
setWord: func.isRequired,
13-
setMode: func.isRequired,
14-
}),
15-
};
11+
actions: React.PropTypes.shape({
12+
setWord: func.isRequired,
13+
setMode: func.isRequired,
14+
}),
15+
};
1616

17-
return {
18-
props, // set props
17+
return {
18+
props, // set props
1919

20-
componentDidUpdate() {
21-
this.refs.wordInput.getDOMNode().focus();
22-
},
20+
componentDidUpdate() {
21+
this.refs.wordInput.getDOMNode().focus();
22+
},
2323

24-
render() {
25-
const { word, mode } = this.props;
24+
render() {
25+
const { word, mode } = this.props;
2626

27-
const { setMode, setWord } = this.props.actions;
27+
const { setMode, setWord } = this.props.actions;
2828

29-
const styles = {
30-
displayMode: {
31-
display: mode === "display" ? "inline" : "none",
32-
},
29+
const styles = {
30+
displayMode: {
31+
display: mode === "display" ? "inline" : "none",
32+
},
3333

34-
editMode: {
35-
display: mode === "edit" ? "inline" : "none",
36-
},
37-
};
34+
editMode: {
35+
display: mode === "edit" ? "inline" : "none",
36+
},
37+
};
3838

39-
const onKeyUp = function (e) {
40-
if (e.key !== "Enter") return;
39+
const onKeyUp = function (e) {
40+
if (e.key !== "Enter") return;
4141

42-
setWord(e.target.value);
43-
setMode("display");
44-
};
42+
setWord(e.target.value);
43+
setMode("display");
44+
};
4545

46-
return (
47-
<p>
48-
Hello,&nbsp;
49-
<span style={styles.displayMode} onClick={() => setMode("edit")}>
50-
{word}!
51-
</span>
52-
<input
53-
ref="wordInput"
54-
style={styles.editMode}
55-
placeholder={word}
56-
onKeyUp={onKeyUp}
57-
/>
58-
</p>
59-
);
60-
},
46+
return (
47+
<p>
48+
Hello,&nbsp;
49+
<span
50+
style={styles.displayMode}
51+
onClick={() => setMode("edit")}
52+
>
53+
{word}!
54+
</span>
55+
<input
56+
ref="wordInput"
57+
style={styles.editMode}
58+
placeholder={word}
59+
onKeyUp={onKeyUp}
60+
/>
61+
</p>
62+
);
63+
},
64+
};
6165
};
62-
};
6366
};
6467

6568
export default helloFactory;

0 commit comments

Comments
 (0)