Creating custom filters in JetBrains products

In the post about creating custom live templates, I mentioned that this is only one of many useful features. In this post, I’ll show you how to combine these templates with custom filters.

As an example, I’ll use one of the most popular comments: TODO.

Creating a template

Templates for the TODO comment are fast and easy to configure. Here is an example of what my custom TODO template always looks like:

Konfiguracja filtru

The process of creating a new template is described in another post, which I strongly recommend reading

You can effectively use the created template only if you can easily find it in your code. If a number of developers contribute to one project, there are thousands of such TODOs. And this is where custom filters come in handy to keep track of all your comments.

Creating a search filter

In order to create a new filter, open the TODO tool you can find  at the bottom of the screen. Next, find the icon that looks like a funnel, and select the Edit filters option.

Now you have to define a new pattern by clicking the + button at the bottom of the Patterns section.

A window will open where you can specify whether the pattern should be case sensitive, or what it should look like in the editor.

For the template I showed you above, I’ve created the following pattern:

Once the pattern is defined, add it as a filter. Click the + button at the bottom of the Filter section, select the pattern, insert its name, and confirm the settings by clicking OK.

Dodawanie filtru

Using the filter

Finally, you have to activate the filter. Open the TODO tool again, find the funnel icon, and select the filter you created. From now on, the view will display only the comments that are filtered out according to the pattern.

Filtrowanie TODO

Reviewing TODOs before push

JetBrains tools provide you with a version control integration. One of its many features is an inspection before committing changes. You can specify that your IDE will notify you about the TODO comments before each commit. Moreover, you can select the created filter in the commit window.

5-minute configuration and 10 clicks can get you a very powerful tool that will help you prevent pushing unfinished code into your repository.

 

Edited by: Anna

You may also like

Comments