Skip to content

Commit

Permalink
feat: align example treefmt config with flake treefmt config
Browse files Browse the repository at this point in the history
Prevent unnecessary reformatting
  • Loading branch information
brianmcgee committed Dec 23, 2023
1 parent 0c93d98 commit 12452b0
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 205 deletions.
16 changes: 8 additions & 8 deletions internal/format/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestConfig(t *testing.T) {
// nix
nix, ok := cfg.Formatters["nix"]
as.True(ok, "nix formatter not found")
as.Equal("nixpkgs-fmt", nix.Command)
as.Equal("alejandra", nix.Command)
as.Nil(nix.Options)
as.Equal([]string{"*.nix"}, nix.Includes)
as.Equal([]string{"examples/nix/sources.nix"}, nix.Excludes)
Expand All @@ -72,7 +72,7 @@ func TestConfig(t *testing.T) {
prettier, ok := cfg.Formatters["prettier"]
as.True(ok, "prettier formatter not found")
as.Equal("prettier", prettier.Command)
as.Equal([]string{"--write"}, prettier.Options)
as.Equal([]string{"--write", "--tab-width", "4"}, prettier.Options)
as.Equal([]string{
"*.css",
"*.html",
Expand All @@ -88,12 +88,12 @@ func TestConfig(t *testing.T) {
as.Equal([]string{"CHANGELOG.md"}, prettier.Excludes)

// rust
// rust, ok := cfg.Formatters["rust"]
// as.True(ok, "rust formatter not found")
// as.Equal("rustfmt", rust.Command)
// as.Equal([]string{"--edition", "2018"}, rust.Options)
// as.Equal([]string{"*.rs"}, rust.Includes)
// as.Nil(rust.Excludes)
rust, ok := cfg.Formatters["rust"]
as.True(ok, "rust formatter not found")
as.Equal("rustfmt", rust.Command)
as.Equal([]string{"--edition", "2018"}, rust.Options)
as.Equal([]string{"*.rs"}, rust.Includes)
as.Nil(rust.Excludes)

// shell
shell, ok := cfg.Formatters["shell"]
Expand Down
3 changes: 1 addition & 2 deletions nix/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
golangci-lint

# formatters for testing

alejandra
elmPackages.elm-format
haskellPackages.cabal-fmt
haskellPackages.ormolu
mdsh
nixpkgs-fmt
nodePackages.prettier
python3.pkgs.black
rufo
Expand Down
16 changes: 15 additions & 1 deletion nix/treefmt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,21 @@
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 = {
Expand Down
36 changes: 18 additions & 18 deletions test/examples/elm/elm.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"type": "application",
"source-directories": ["src"],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0"
"type": "application",
"source-directories": ["src"],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
"test-dependencies": {
"direct": {},
"indirect": {}
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
14 changes: 7 additions & 7 deletions test/examples/html/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Title</title>
</head>
<body>
<h1>Hi!</h1>
</body>
<head>
<meta charset="utf-8" />
<title>Title</title>
</head>
<body>
<h1>Hi!</h1>
</body>
</html>
101 changes: 52 additions & 49 deletions test/examples/javascript/source/hello.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,68 @@
const helloFactory = function ({ React }) {
const { string, func } = React.PropTypes;
const { string, func } = React.PropTypes;

return function Hello(props) {
// React wants propTypes & defaultProps
// to be static.
Hello.propTypes = {
word: string,
mode: string,
return function Hello(props) {
// React wants propTypes & defaultProps
// to be static.
Hello.propTypes = {
word: string,
mode: string,

actions: React.PropTypes.shape({
setWord: func.isRequired,
setMode: func.isRequired,
}),
};
actions: React.PropTypes.shape({
setWord: func.isRequired,
setMode: func.isRequired,
}),
};

return {
props, // set props
return {
props, // set props

componentDidUpdate() {
this.refs.wordInput.getDOMNode().focus();
},
componentDidUpdate() {
this.refs.wordInput.getDOMNode().focus();
},

render() {
const { word, mode } = this.props;
render() {
const { word, mode } = this.props;

const { setMode, setWord } = this.props.actions;
const { setMode, setWord } = this.props.actions;

const styles = {
displayMode: {
display: mode === "display" ? "inline" : "none",
},
const styles = {
displayMode: {
display: mode === "display" ? "inline" : "none",
},

editMode: {
display: mode === "edit" ? "inline" : "none",
},
};
editMode: {
display: mode === "edit" ? "inline" : "none",
},
};

const onKeyUp = function (e) {
if (e.key !== "Enter") return;
const onKeyUp = function (e) {
if (e.key !== "Enter") return;

setWord(e.target.value);
setMode("display");
};
setWord(e.target.value);
setMode("display");
};

return (
<p>
Hello,&nbsp;
<span style={styles.displayMode} onClick={() => setMode("edit")}>
{word}!
</span>
<input
ref="wordInput"
style={styles.editMode}
placeholder={word}
onKeyUp={onKeyUp}
/>
</p>
);
},
return (
<p>
Hello,&nbsp;
<span
style={styles.displayMode}
onClick={() => setMode("edit")}
>
{word}!
</span>
<input
ref="wordInput"
style={styles.editMode}
placeholder={word}
onKeyUp={onKeyUp}
/>
</p>
);
},
};
};
};
};

export default helloFactory;
Loading

0 comments on commit 12452b0

Please sign in to comment.