Automate code formatting with Transformers

Automate code formatting with Transformers

DeepSource now supports running Black, YAPF, and gofmt to automate code-formatting of Python and Go code. More formatters and language support coming soon.

Do you run code formatters on your local machine to make code look uniform? Or do you run them in CI builds, and manually push the changes to the repository? If you answered “yes” to either of these questions, meet Transformers.

DeepSource Transformers remove the need to have tedious manual setup to make your project’s code stick to a style guide. You set it up once, and watch as DeepSource sends pull requests to your repository, or updates commits with formatted code in an existing pull request, each time a changeset does not adhere to chosen style guides.

No more fumbling with CI scripts. No more mangled commit history in repositories. No more asking a fellow developer to fix their code style before merging.

With this release, you can enable Black and YAPF for Python, and gofmt for Go code, directly in the DeepSource configuration file.

Why we need Transformers

We all have our own preferences when it comes to how we write our code. Some of us like semicolons only when they represent a small pause; some of us like it at the end of every line. When we work on software projects with others, we must not let these differences in code style creep in.

There are code formatters like Black, YAPF, or autopep8 for Python, gofmt for Go, Prettier for JavaScript, and so on. These tools typically are part of code authoring processes — we add them to our code editors and IDEs, or pre-commit hooks, and they help keep the code we write in good shape.

However, only a handful of software teams globally enable automated code-formatting at the repository level. This needs setting up CI pipelines that run these tools on every commit or pull requests. push formatted code back to the repository on every merge, or every pull request.

DeepSource has already made actionable static code analysis easier to setup and maintain. We have also shipped Autofix which generates automated code patches based on issues DeepSource detects. We realized that we can extend what Autofix does, to code formatters. This will let developers to run their chosen code formatters on each commit, alongside analysis runs and autofixes.

This is a great way of reducing noise in issues detected. Instead of just flagging style issues in code, we can take a step ahead and fix it for you, using the tools you trust.

Enable Transformers

Enabling transformers requires you to grant DeepSource write access to your repository. Behind the scenes, transformers use the same app and authorization scopes as autofixes. If you have already given DeepSource Autofix access to create pull requests in your repository, you don’t need to install anything else.

If you haven’t, you can trigger the Autofix installation from “Generate configuration” screen (shown in video below), or you can open your repository’s dashboard in DeepSource and go to “Settings” → “Autofix” and trigger the installation.

Once installed, you can use the configuration screen’s “Transformers” section to add one of the available tools. This will add a [[transformers]] block to .deepsource.toml. Commit the updated code to your repository, or manually edit the configuration, and you are all set.

visual studio code visual studio code

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

COMO USAR e trabalhar com Code Review no Visual Studio Code

💲 Live CollabPlay: https://youtu.be/B6LCFSPdsE0 💲 Hospedagem com Desconto Exclusivo: https://tekers.tech/4e587 Não é todo programador que gosta de compartilh...

User Snippets (Code Shortcuts) in Visual Studio Code

#vscode Hello, my friends and fellow developers, this video is all about User Snippets. That means the Snippets (Code Shortcuts) that you can make for yourse...

Python в Visual Studio Code

We are pleased to announce that the July release of the Python extension is now available for Visual Studio Code. You can download the Python extension from the Marketplace, or install it directly from the extension gallery in Visual Studio Code. If you already have the Python extension installed, you can also get the latest update by restarting Visual Studio Code. You can read more about Python support in Visual Studio Code in the documentation .

C++ Development with Visual Studio Code

If you’re looking for a fast and lightweight open-source code editor, Visual Studio Code has you covered. Come for a deep dive into the features of Visual Studio Code which provide a rich, productive environment for C++ development.

The History of Visual Studio Code

We speak to the creator of Visual Studio Code about the early challenges to now becoming the most popular development environment in the world.