In our previous blog posts on the JustCode Formatter, we’ve showed you what it is and how it works. If you haven’t read those yet, please see our post on "Introducing the Formatter" and "Comparing the JustCode Formatter to the Visual Studio Formatter".
One of our design goals was to make sure the Formatter is much more customizable than Visual Studio’s, and in this post, we will show you how easy it is to customize it.
When you utilize JustCode’s refactorings, expand code templates, format and/or clean your code, or make other changes to your code, JustCode needs to know how to structure the affected code. JustCode has a set of rules that are taken into account when modifying code. These rules are called the “Code Style” settings. You can find them in the JustCode -> Options -> Code Style pages.
You can easily customize rules using these settings pages, such as where the block braces will be positioned, whether to put spaces or not between given code constructs, or whether to wrap code and even how to wrap it if the line length is larger than a customizable value.
Code Style settings can also be customized per solution. That way all the people working on that solution will use the same coding rules and the code they produce will be styled in the same manner.
For a more clear and concise user experience, JustCode separates Code Style settings by language and functionality.
C# Code Style Settings are separated into ten categories:
In this post, we will look at the first five categories – General, Indentation, Spacing, New Lines, and Blank Lines.
Image 1. General page.
The General Settings page (shown in Image 1) contains settings that are unrelated to any of the other functional groups. The main settings on this page define whether code blocks should be introduced or not by the specified JustCode code generation features.
Image 2. Indentation page.
The Indentation Settings page (shown in Image 2) contains settings that allow for customizing how certain code constructs will be indented related to their parent constructs.
Each setting has a code preview window at the bottom of the page for immediate feedback of how changing the setting will affect your code. To show the preview, select the setting that you want to view. The images below (Image 3) show the code preview changing when the setting is changed.
Image 3. Changing the preview in result of setting change.
Image 4. Spacing page.
Customizing the spacing settings will help make your code more readable by automatically adding spaces based on your selected settings.
As you can see in Image 4, JustCode has a significant number of spacing settings that you can customize. We have set the default values based on user feedback so most developers won’t have to spend much time customizing them, but the defaults are easy to change if they don’t match your preferred code spacing style.
As with all of the settings pages, the Spacing settings page also provides previews so you can see how your code will be affected by a settings change before applying them.
Image 5. New Lines page.
The New Lines settings (Image 5) customize whether braces, bracket, parentheses, certain keywords, and other constructs are placed on their own line or not.
This settings page also provides a preview so you can see how your code will be affected before applying a change.
Image 6. Blank Lines page.
Putting empty lines between code constructs can greatly improve readability and the structure of your code. As shown in Image 6, there are several options for each setting. Take for example “Blank lines after Events” (highlighted in group 1). There are sets of options (see groups 2 and 3) allowing for additional customization based on the following code construct. If in your code there are less than “Min” value blank lines, additional blank lines will be added. Likewise, if in your code there are more than the “Max” blank lines, the extra lines will be removed.
If you just want to put a set number of blank lines after a given code element, regardless the following element, you can use the edit-box after the setting name (see group 4). Modifying this edit-box’s value will automatically modify all values in the underlying group.
We have only scratched the surface covering just half of the settings for C# - General, Indentation, Spacing, New Lines, and Blank Lines. There are a host of additional settings that we will cover in the next blog post, and that’s just for C#!
We welcome you to experiment with the Code Style settings. We are confident you’ll be able to make your code look exactly like you want it. Your previous settings are safe with JustCode’s Visual Studio Cloud Backup - just be sure to create a backup before you begin.
If you have a suggestion for more customization, please leave us feedback on the JustCode Feedback Portal. You can also write to us in the forum as well as contact support directly.
The JustCode team
Borislav Kulov he has more than 10 years of experience in the development field. Borislav is a motorcycle enthusiast and in his free time he enjoys swimming and other sports.
Copyright © 2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks or appropriate markings.