FuelLabs / sway

🌴 Empowering everyone to build reliable and efficient smart contracts.
https://docs.fuel.network/docs/sway/
Apache License 2.0
62.64k stars 5.36k forks source link

swayfmt: Support configuration file #6411

Open sdankel opened 2 months ago

sdankel commented 2 months ago

Swayfmt is meant to be configurable. The task here is to:

  1. Support the parsing and loading of swayfmt.toml
  2. Implement the configuration options
    • It's okay if some only support the default option
    • Some of the options are already implemented
  3. Write tests for all options
  4. Update the docs stating which options are configurable.

The main reason it's not currently supported is that our small team hasn't had bandwidth to properly tests the options that are implemented.

The default swayfmt.toml:

max_width = 100
hard_tabs = false
tab_spaces = 4
newline_style = Auto
indent_style = Block
newline_threshold = 1
group_imports = Preserve
imports_granularity = Preserve
imports_indent = Block
reorder_imports = true
reorder_modules = true
reorder_impl_items = false
item_brace_style = SameLineWhere
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
empty_item_single_line = true
format_strings = false
hex_literal_case = Preserve
expr_brace_style = AlwaysSameLine
trailing_semicolon = true
space_before_colon = false
space_after_colon = false
type_combinator_layout = Wide
spaces_around_ranges = false
match_block_trailing_comma = false
match_arm_leading_pipe = Never
force_multiline_blocks = false
fn_args_layout = Tall
fn_single_line = false
heuristics_pref = Scaled
use_small_heuristics = true
field_alignment = Off
small_structures_single_line = true
wrap_comments = false
comment_width = 80
normalize_comments = false
kayagokalp commented 2 months ago

My two piece on this would be not to allow it. This is purely a personal choice so nothing concrete behind it but even if someday we have the bandwidth to do so, I think we still shouldn't do it. I feel like formatter wise go made the correct choice over rust.

Also I believe that being a smart contract development language, conceptually gives us an extra opportunity to say that we are opinionated about standards, this can (and imo should) include the way sway programs supposed to look.

My problem with rustfmt is that the lack of standard look, rust itself enforces some strict rules on how you structure your code, the formatter should have followed a similar philosophy of being opinionated. Also I see bunch of weird diffs in different rust repos, due to different rustfmt configs

sdankel commented 1 month ago

We decided as a team we do not want the formatter to be configurable. The next step is to remove the configuration code that currently exists in the formatter but isn't exposed in swayfmt/src/config.