Custom pattern for guard clauses

Answered

Hi, I was configuring Resharper settings for my team and run onto a limitation which I couldn't figure out how to solve. We agreed to force braces for all if statements, even if single line, with one exception which is guard clauses. For example, the following line should not have a warning next to it regarding missing braces:

if (foo is null) return;

Unfortunately, we could not find a way to configure this. We thought about custom patterns, but it seems that those only allow us to add additional warnings, but not suppress existing ones. Furthermore, custom patterns do not seem to have any effect when added to the team-shared layer, only the 'This computer' layer.

Any ideas on how to solve this?

1
1 comment

Hello MagicMushroom, thank you for your request. Unfortunately at this time, ReSharper doesn't have an option to exclude guard clauses for "if" statements in code style settings. While there are a few methods to introduce feature requests, I think your best choice here would be to use our tracker here and submit a request. On the tracker, others can see your request and add their vote if they find such an option would be useful, which helps our team to better understand which features/tools our users are eager for.

As for custom patterns - they provide an option to add new inspections, but they do not exclude them. To add custom patterns to the team-shared layer, please use "Save to | Solution ... team-shared" as shown below:

Please let me know if you have any questions. Have a great day!

0

Please sign in to leave a comment.