Telerik blogs

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.

What are the Code Style settings?

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.

Code Style settings for C#

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:

  • General
  • Indentation
  • Spacing
  • New Lines
  • Blank Lines
  • Ordering
  • Brace Positioning
  • Wrapping
  • Using Directives
  • Naming Conventions

In this post, we will look at the first five categories – General, Indentation, Spacing, New Lines, and Blank Lines.

General

JustCode style settings image
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.

Indentation

JustCode style settings image
 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.

JustCode style settings image 
Image 3. Changing the preview in result of setting change.

Spacing

JustCode style settings image
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.

New Lines

JustCode style settings image
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.

Blank Lines

JustCode style settings image
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.

Summary

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.

Happy Coding!

The JustCode team

JC


About the Author

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.

Comments

Comments are disabled in preview mode.