Skip to content

Conversation

@drgrice1
Copy link
Member

The first commit adds perltidy to the workflow.

The second commit just runs perltidy on the code base.

Note that you need the latest version of perltidy from cpan for this (20210717). The Ubuntu version 20190601-1 does not work the same.

@drgrice1
Copy link
Member Author

Please add any comments/discussion for changes to the .perltidyrc file. We want this to be set before this is merged. We definitely don't want this to change much. Every time that is done the entire code base will need to have perltidy run on, and that will get messy.

@drgrice1
Copy link
Member Author

drgrice1 commented Oct 14, 2021

@drdrew42: I looked into the -nbot rule and why I chose that. Basically, with either -nbot or -bot if the entire ternary statement fits onto the line, then it will be put onto a single line. The difference comes when the statement does not fit onto a single line. With the -bot rule in this case you are forced to have each part of the ternary statement on a new line, but with the -nbot rule, you may have the entire statement on the next line. With the -nbot rule, if that still doesn't fit, then it does the same thing as the -bot rule.

At this point the only difference in our code is in lib/DB/Utils.pm starting on line 76. With the -nbot rule that becomes:

	$fields_to_return->{$key} =
		defined($updated_fields->{$key}) ? $updated_fields->{$key} : $current_fields->{$key};

With the -bot rule that becomes:

	$fields_to_return->{$key} =
		defined($updated_fields->{$key})
		? $updated_fields->{$key}
		: $current_fields->{$key};

Note that if you make the ternary statement longer than 120 characters then both rules make it look like the second case. If the statement is short enough to fit onto the same line as the equality, then both rules will let that happen. However, in this case, -nbot forces it onto a single line if written on multiple lines, and -bot will leave it however you write it. Both rules will enforce the placement of the ? and the : at the beginning of the line if broken onto multiple lines.

@drgrice1
Copy link
Member Author

Also, note that with my example above (of the only place the rule makes a difference in our code), if you write the code the way that perltidy changes it to with the -nbot rule, and then run perltidy with the -bot rule, it will leave it that way.

@pstaabp
Copy link
Member

pstaabp commented Oct 15, 2021

Overall, this looks good and didn't change too much. About the ternary statements, I would go with the -nbot feature, but not a strong vote.

@drgrice1
Copy link
Member Author

@pstaapb: Is there any reason why you don't like the -nbot rule?

@pstaabp
Copy link
Member

pstaabp commented Oct 15, 2021

I don't feel that strongly either way.

@drgrice1
Copy link
Member Author

Actually, I don't feel strongly one way or the other on the -nbot versus -bot rules either. Particularly since it seems that either rule makes very little difference on the way that perltidy formats the code.

@drdrew42
Copy link
Member

I'm okay with -nbot... any other debate before merging?

@pstaabp pstaabp merged commit 6cf3c93 into openwebwork:main Oct 15, 2021
@drgrice1 drgrice1 deleted the add-perltidy-to-lint-workflow branch October 15, 2021 19:05
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.

3 participants