Transcription
There are many tools created to improve your code. However, some tools can completely change your development approach and offer far more advantages than the tools we currently use.
To give you an idea, many great developers say that this tool is so fast that sometimes they intentionally introduce errors in their code just to test its speed. They can't believe it can be that quick.
In this video, I will introduce such a tool that everyone will start using sooner or later. So, what is this tool? If you are familiar with Flake8 and similar tools, you probably know both their advantages and disadvantages.
For instance, if we take the tool Pylint, it significantly lags in speed. But why is it important for these tools to work quickly? The faster they operate, the less time we spend on development, and the fewer mistakes we make.
The new tool, which is hardly ever mentioned, performs this task perfectly. For example, there was a test where the same code was run through different linters, and the results were as follows: Pylint completed its task in 60 seconds. You have 60 seconds just for it to tidy up your code and show some corrections.
Flake8, which is used by almost everyone, managed to do it in 12 seconds, which is already five times faster. But how long do you think it took this new tool to complete the same task?
You might think I’m joking when I say it’s an incredibly fast tool. No, I’m not joking because it did it in 0.2 seconds. If it makes mistakes, it’s still 60 to 100 times faster. To give you an idea, if you have a codebase of 500,000 lines, it can process that in about 2-3 seconds. Multiply that by 60 or even 200 to get an approximate speed of other tools.
Moreover, it incorporates many features from other technologies and is very easy to use. In this video, I will show you all these advantages that will elevate your projects to a new level and eliminate many problems.
Throughout the video, or at the end, I will always leave some cool tip, so I recommend watching until the end to not miss important material.
Also, during the installation phase, we have an interesting moment. We install it via pip or poetry. And you know what we just did? We could have installed Flake8 and added a bunch of plugins, but by installing this tool, we already have all of that.
In fact, its functionality is many times greater than that of Flake8. Some powerful projects have already switched to this tool. If we look into several projects, we will find those very linter settings that we will now discuss. Major frameworks have already implemented this more powerful technology.
That’s why it’s important to analyze such large projects sometimes. But that’s a topic for another video. If you’re interested, let’s aim for 5,000 likes because the information is very powerful.
When we open a website or application, the first thing that instantly grabs our attention is the appearance and interactive elements. The visual and functional parts of the interface play a crucial role in defining our user experience, and they are created by frontend developers.
Frontend developers write the logic for processing user data forms, button functions, and other interactive elements. They use HTML for structure, CSS for styling, and JavaScript for adding functionality.
If you are a creative person who wants to create interactive websites and applications using code, you can try your hand at the profession for free with Yandex Practicum. In the introductory part of the course, you will learn what tasks frontend developers solve, test the learning format, understand how project work will be structured, and even write your first code.
If you enjoy the learning format on the platform and want to continue your development in this field, you can transition to the paid course. The main goal of the course is to teach you the skills to write websites and applications using HTML, CSS, and JavaScript.
You will learn to work on projects in a team and complete many classic tasks. Some projects will be from real clients. The courses are regularly updated to meet current market demands. All training is conducted online, and at every stage, you will be supported by experienced frontend developers from major IT companies who will review your code and provide detailed feedback.
After completing the training, you will receive a diploma in professional retraining, and the career center at Yandex Practicum will assist you with job placement. They have already helped over 10,000 of their graduates find jobs.
If you are interested in creating interfaces for websites and applications, try the free part of the course via the link below the video or scan the QR code on the screen.
To check if everything is in order, we need to enter the following command. It detected that there are some minor errors. Here we will add the fix flag, and it will automatically correct everything.
If we enter git diff to see the changes, we will find that it removed that unused module mentioned in the error. Next, we have more commands.
We can check all directories or just a specific one. We can also add filters or check just one file. Moreover, there is an option to run a continuous watch. If we change the code, it will automatically analyze everything and provide a new result.
There’s also a more advanced feature directly in the tool. This is the default behavior of the tool, but we can configure it just like Flake8 and set general code formatting rules based on which it will analyze everything.
But how does this tool differ? Let’s look at the configuration. You can create it either as a `project.toml` or `ruff.toml` and place the settings there.
Next, we see how to quickly and finely tune the analysis parameters and other rules. You can write such a config just once and then use it in other projects. The setup will take just a couple of seconds.
So, how do we need to configure everything? Initially, we have that project. We need to open this file. Here are all the configurations for the tool. I placed the settings separately.
I wrote some parameters. Initially, we look at this: these are the general linter settings. We specify the Python version, then the maximum line length, and so on. If we go to the settings, we will get this result.
These are all the settings we can add to the config. We simply choose the ones we need and list them in the config. For example, if we need to add a certain parameter, I just copy that value and paste it under the corresponding key in the config.
Once you’ve written all the necessary settings from this page, you can also add rules from their collection of over 600 rules. These 600 rules are divided into about 40 structured plugins that you don’t need to install separately.
So, what do they provide? Essentially, they are a collection of coding rules, organized into separate blocks. For example, this component rule checks that we use the equality operator instead of directly referencing it, as this relates to PEP 8.
Sometimes, very strange solutions arise; some people put a semicolon at the end of lines in Python. This component will also give a warning and provide an example of code, indicating that this is not how it should be done in Python.
And the most interesting thing is that there are just a huge number of such rules. They are divided into groups. There’s a group for errors and warnings, and then all other rules are also divided into components.
There are also many ready-made components that already exist in Flake8, acting as separate plugins. This tool has everything natively built into the technology.
In the end, if we need to enable this group, we specify a separate key and thus enable the necessary group of checks.
And here’s the tip I promised at the beginning of the video: even if you are not working in a team and are just developing your projects or learning, you need to study this tool in detail and configure it.
If you noticed, there are many different rules of good practice. Using this tool while writing code will guide you on where good practices are and where they are not. You can also access the documentation, which describes the rules and explains why certain practices are considered poor.
Ultimately, you will start writing correctly, and using this tool will continuously enhance your knowledge and the quality of your code.
Next, a very cool feature is the ability to ignore types of errors that you don’t need. You simply search for the error code after analyzing with the tool and add a comment in the file itself.
For example, we have this code. This is the comment that needs to be specified, and this is the error code that can be found here.
In the end, if you write it all like this for this function, it will not work. But if we need to apply a rule to the entire file, we make the following comment.
There is also a ready-made extension that can be installed and used. Through the tool, you can also set it up in Neovim, TextMate, and so on. Essentially, you can add it anywhere.
Many people ask me to show my config in Vim. I will try to add this tool and many other technologies. If there are many comments and likes on this topic, I will finish my Linux shell and then make a separate video about both Neovim and my Linux setup.
Also, one more question: how does this tool differ from Flake8? If we don’t consider speed, the vast number of ready-made rules is one difference. It also contains the plugins used in Flake8.
If you want to simply install a tool and immediately use all its features, then this tool easily replaces Flake8. Personally, I would still choose this tool, at least for its speed and all the advantages mentioned above.
Just to clarify, my Pyright is used in conjunction with this tool; it cannot replace it in any way. The point is that the linter will find its types of errors, while Pyright will find other errors that it might not catch. Therefore, they need to be used together.
However, this tool can replace some other tools. Here’s a list of what it can replace, and there are many technologies, plugins, and so on.
In the previous video, we used the number 7 in the comments. That was quite funny. This time, if you watched the video to the end, write in the comments how you feel about this tool, but use the word "implementation." Let others read the comments and not understand what it’s about and how it relates to implementation.