Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure & activate JuliaFormatter #946

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
14 changes: 11 additions & 3 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
margin = 120
margin = 119
always_for_in = true
whitespace_in_kwargs = false
remove_extra_newlines = true
whitespace_ops_in_indices = true
format_docstrings = true
whitespace_in_kwargs = false
format_docstrings = false
separate_kwargs_with_semicolon = false
verbose = true
whitespace_typedefs = false
join_lines_based_on_source = true
surround_whereop_typeparameters = true
trailing_comma = "nothing"
align_conditional = true
annotate_untyped_fields_with_any = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

annotate_untyped_fields_with_any = true? I think this should be false.

trailing_comma = "nothing"? we could have true here I think.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah we can set untyped_fields to false.
For the trailing_comma, I set it to nothing because it seems we like using it in some cases and not in others, and I assumed there was a reason. But if there's no reason we can just enforce it. :)

21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-json
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: file-contents-sorter
files: .JuliaFormatter.toml
args: [--unique]
- id: mixed-line-ending
args: [--fix=lf]
- id: no-commit-to-branch
- id: pretty-format-json
args: [--autofix, --indent=4]
- id: trailing-whitespace
- repo: https://github.com/domluna/JuliaFormatter.jl
rev: v1.0.35
hooks:
- id: julia-formatter
51 changes: 33 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,43 @@ Thanks for taking the plunge!

* Feel free to open, or comment on, an issue and solicit feedback early on, especially if you're unsure about aligning with design goals and direction, or if relevant historical comments are ambiguous
* When developing a new functionality or modifying an existing one, considering the following to work on (possibly in one pull request)
+ Add the new functionality or modifying an existing one
+ Pair the new functionality with tests, and bug fixes with tests that fail pre-fix. Increasing test coverage as you go is always nice
+ Update the documentation (seen implementation details in the documentation for some advanced features)
* Add the new functionality or modifying an existing one
* Pair the new functionality with tests, and bug fixes with tests that fail pre-fix. Increasing test coverage as you go is always nice
* Update the documentation (seen implementation details in the documentation for some advanced features)
* Aim for atomic commits, if possible, e.g. `change 'foo' behavior like so` & `'bar' handles such and such corner case`, rather than `update 'foo' and 'bar'` & `fix typo` & `fix 'bar' better`
* Pull requests will be tested against release and development branches of Julia, so using `Pkg.test("SpineOpt")` as you develop can be helpful
* The style guidelines outlined below are not the personal style of most contributors, but for consistency throughout the project, we should adopt them
* If you'd like to join our monthly developer meetings, just send us a message ([email protected])

## Style Guidelines

* Include spaces
+ After commas
+ Around operators: `=`, `<:`, comparison operators, and generally around others
+ But not after opening parentheses or before closing parentheses
* Use four spaces for indentation (test data files and Makefiles excepted)
* Don't leave trailing whitespace at the end of lines
* Don't go over the 119 per-line character limit
* Avoid squashing code blocks onto one line, e.g. `for foo in bar; baz += qux(foo); end`
* Don't explicitly parameterize types unless it's necessary
* Never leave things without type qualifications. Use an explicit `::Any`.
* Order method definitions from most specific to least specific type constraints
* If you'd like to join our monthly developer meetings, just send us a message (<[email protected]>)

## Using JuliaFormatter

We use [JuliaFormatter.jl](https://github.com/domluna/JuliaFormatter.jl) for code
formatting and style.

To install it, open Julia REPL, for example, by typing in the
command line:

```bash
julia
```

> **Note**:
> `julia` must be part of your environment variables to call it from the
> command line.

Then press <kbd>]</kbd> to enter the package mode.
In the package mode, enter the following:

```julia
pkg> activate
pkg> add JuliaFormatter
```

In VSCode, you can activate "Format on Save" for `JuliaFormatter`.
To do so, open VSCode Settings (<kbd>Ctrl</kbd> + <kbd>,</kbd>), then in "Search
Settings", type "Format on Save" and tick the first result.

## Further questions

* For developers there is some additional information in the implementation details (e.g. how to write a constraint).
* You can talk to your fellow developers over gitter if the above is insufficient.