diff --git a/.JuliaFormatter.toml b/.JuliaFormatter.toml index 3bee76771a..0f07d9ae4f 100644 --- a/.JuliaFormatter.toml +++ b/.JuliaFormatter.toml @@ -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 \ No newline at end of file +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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..2e3ed207fe --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f6640f6d28..016754bc7a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 (spine_info@vtt.fi) - -## 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 () + +## 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 ] 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 (Ctrl + ,), 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.