Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/sharing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,42 @@ For local coverage analysis, [LocalCoverage.jl](https://github.com/JuliaCI/Local
## Style

To make your code easy to read, it is essential to follow a consistent set of guidelines.
The official [style guide](https://docs.julialang.org/en/v1/manual/style-guide/) is very short, so most people use third party style guides like [BlueStyle](https://github.com/JuliaDiff/BlueStyle) or [SciMLStyle](https://github.com/SciML/SciMLStyle).
The official [style guide](https://docs.julialang.org/en/v1/manual/style-guide/) is very short, so most people use third party style guides like [BlueStyle](https://github.com/JuliaDiff/BlueStyle), [SciMLStyle](https://github.com/SciML/SciMLStyle), or [YASGuide](https://github.com/jrevels/YASGuide).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "YASGuide" is as popular as Blue/SciML/Runic, is there a particular reason you want to add it?


[JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) is an automated formatter for Julia files which can help you enforce the style guide of your choice.
### JuliaFormatter.jl

[JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) is an automated formatter for Julia files which can help you enforce the style of your choice, being either a predefined style (["default"](https://juliaeditorsupport.github.io/JuliaFormatter.jl/stable/default_style/), ["blue"](https://juliaeditorsupport.github.io/JuliaFormatter.jl/stable/blue_style/), ["sciml"](https://juliaeditorsupport.github.io/JuliaFormatter.jl/stable/sciml_style/), or ["yas"](https://juliaeditorsupport.github.io/JuliaFormatter.jl/stable/yas_style/)) or a customized version of them.
Just add a file `.JuliaFormatter.toml` at the root of your repository, containing a single line like

```toml
style = "blue"
```

To override the defaults of the chosen style, you can add additional lines:

```toml
style = "blue"
indent = 2
margin = 100
remove_extra_newlines = false
```

Comment on lines +175 to +183

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could keep MoJuWo a bit more concise by linking to the JuliaFormatter options instead: https://juliaeditorsupport.github.io/JuliaFormatter.jl/stable/formatting_options/#formatting-options

This also helps avoid drift.

Then, the package directory will be formatted in the BlueStyle whenever you call

```>format
using JuliaFormatter
JuliaFormatter.format(MyAwesomePackage)
```

Or you can install it as a command-line application:
```bash
# Install it once with:
julia -e 'using Pkg; Pkg.Apps.add("JuliaFormatter")'

# Then you can use it to format all files in a directory with multiple threads:
jlfmt --threads=6 -- --inplace -v src/
```
Comment on lines +191 to +198

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this section is a great addition.
I'd suggest we keep it vanilla and drop the --threads argument though, leaving such defaults to JuliaFormatter.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also wondering what the extra -- does?


{% <vscode> %}

The [default formatter](https://www.julia-vscode.org/docs/stable/userguide/formatter/) falls back on JuliaFormatter.jl.
Expand All @@ -187,6 +207,20 @@ The [default formatter](https://www.julia-vscode.org/docs/stable/userguide/forma
You can format code automatically in GitHub pull requests with the [`julia-format` action](https://github.com/julia-actions/julia-format), or add the formatting check directly to your test suite.
{% </advanced> %}

### Runic.jl

Another approach, taken by [Runic.jl](https://github.com/fredrikekre/Runic.jl), is not to allow any customization, and format the code with a fixed set of rules (_"A code formatter with rules set in stone."_). It is known for its ease of use and very fast execution.

Run the following to install and run as a command-line application:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Run the following to install and run as a command-line application:
Run the following to install Runic and run it as a command-line application:

```bash
# Install it once as a Julia App:
julia -e 'using Pkg; Pkg.Apps.add("Runic")'

# Run this to format all files in-place in the current directory (recursively)
runic --inplace .
```


## Code quality

Of course, there is more to code quality than just formatting.
Expand Down