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

Splitting and indenting variable declarations when necesary #230

Merged
merged 1 commit into from
Feb 19, 2020

Conversation

Janther
Copy link
Contributor

@Janther Janther commented Feb 18, 2020

Fixes #225

Before PR:

(string memory holderId,string memory containerId, string memory parentContainerId, bytes32 volumeId, bytes32 subUnitId, bytes32 requestId) = getParamsById(
    paramsId
);

After PR:

(
    string memory holderId,
    string memory containerId,
    string memory parentContainerId,
    bytes32 volumeId,
    bytes32 subUnitId,
    bytes32 requestId
) = getParamsById(paramsId);

@codecov
Copy link

codecov bot commented Feb 18, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@618a1b6). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff            @@
##             master    #230   +/-   ##
========================================
  Coverage          ?   99.2%           
========================================
  Files             ?      78           
  Lines             ?     632           
  Branches          ?     102           
========================================
  Hits              ?     627           
  Misses            ?       5           
  Partials          ?       0
Impacted Files Coverage Δ
src/nodes/VariableDeclarationStatement.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 618a1b6...b490b61. Read the comment docs.

embrace ? concat(['(', doc, ')']) : doc;

const variables = (node, path, print) =>
group(
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can (and if we should) make a helper for this pattern, since we use it a lot. I guess something like this:

const printList = (node, path, print, key, separator = ',') => 
  group(
    concat([
      indent(
        concat([
          softline,
          join(
            concat([separator, line]),
            path.map(statementPath => print(statementPath), key)
          )
        ])
      ),
      softline
    ])
  );

(with better names for the function and the parameters).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a tricky one.
The pattern is used a lot but with small differences.
Sometimes times is a softline and sometimes is a line, the separator and the content also changes I’ll see how it looks having a function with many variables in one go vs a step by step declaration.
The system is already modular and there aren’t many files bigger than a screen.
I’ll give it a thought and play with the idea a little but probably for another PR.

Copy link
Member

Choose a reason for hiding this comment

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

Sure. Just for the record: I'm fine with merging this as it is, I was just thinking out loud.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Me too, I already got over my phase of having the driest possible code without really thinking of maintainability

Copy link
Member

@mattiaerre mattiaerre left a comment

Choose a reason for hiding this comment

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

👍

@mattiaerre mattiaerre merged commit 95cae7a into master Feb 19, 2020
@mattiaerre mattiaerre deleted the long_multiple_variable_declaration branch February 19, 2020 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

long tuple assignment formatted to single line
3 participants