Transcription
There are very many, therefore tools are also created to make your code better. But there are such tools that can simply change the entire approach to your development and provide much more advantages than we get from the tools we already use. So that you understand, many cool developers talk about how it is such a fast tool that sometimes they deliberately introduce errors into the code to check if it has actually executed. They don't believe that it can be so fast. In this video, there will be exactly such a tool that sooner or later everyone will start using. But what is this tool? If you are familiar with Flake8 and all similar tools, then you most likely know both its advantages and disadvantages. If you take the tool Pylint, it is very far behind in speed. But why is it important for these tools to work quickly? The thing is, the faster they work, the less time we need to spend on development, and the fewer mistakes we will make. And a new tool called Ruff, almost no one talks about it, but it performs this task perfectly. For example, there was such a test on the same code, different linters were run, and the result was this: Pylint performed its task in 60 seconds. You have 60 seconds just for it to tidy up your code and show some corrections. The same Flake8, which almost everyone uses, coped in 12 seconds, and that's already 5 times faster. But in how much time will Ruff do this same task? You think I was joking when I said it's a crazy fast tool? No, I wasn't joking, because it did it in 0.2 seconds. If they are not mistaken, it's 60 to 100 times faster. So that you understand, if you have a codebase of 500 thousand lines, it can process it in about 2-3 seconds. Multiply this by 60, or even 200, to get the approximate speed of other tools. Moreover, it is written in Rust, it contains many features from other technologies. In addition to all this, it is also very easy to use. In this video, I will show all these advantages that will take your projects to a new level and rid you of many problems. Throughout the video, or at the end of the video, I will now always leave some cool feature, so I advise you to watch until the end so as not to miss important material. Even at the installation stage, an interesting moment awaits us. We install it via pip or pip3, and you know what we did now? We could install Flake8 and add all these plugins, but by installing Ruff, we already have all this, and the functionality here is many times greater than in Flake8. Some powerful projects have already switched to Ruff. If we go into several projects and look, we will find these very linter settings that we will now analyze. Large frameworks have already implemented more powerful technology. That's why it's important to sometimes analyze such large projects, but this is a topic for another video. If you are interested, let's get 5000 likes, because the information is very powerful.
When we open a website or application, the first thing that instantly attracts our attention is the appearance and interactive elements. This visual and functional part of the interface plays an important role in defining our user experience, and it is created by front-end developers. Front-end developers write the logic for data processing, user forms, button functions, and other interface interaction elements. They use HTML for structure, CSS for style and design, and JavaScript for adding functionality. If you are a creative person and want to create interactive websites and applications using code, then at Yandex.Practicum, you can try yourself in the profession for free. But in the introductory part of the course, you will learn what tasks front-end developers solve, test the learning format, find out how work on projects will be structured, and even write your first code. If you like the learning format on the platform and want to continue your development in this area, then you can switch to a paid course. The main task of the course is to teach the skills of writing websites and applications in HTML, CSS, and JavaScript. You will learn to work on projects in a team and complete many classic works. Some projects will be from real clients. Courses are regularly updated to meet current market demands. All training takes place online, and at all stages, you will be supported by experienced front-end developers from large IT companies who will check your code and provide detailed feedback. After training, you will receive a diploma of professional retraining, and the Yandex.Practicum career center will assist with employment. They have already employed over 10 thousand of their graduates. If you are interested in creating website and application interfaces, try the free part of the course via the link below the video or scan the QR code on the screen.
And so that the linter checks if everything is in order here, we need to enter the following command. It detected that there are minor errors here. If we add the --fix flag, it will fix everything itself. If we enter git diff to see the changes, we will find that it has removed that very unused module, as stated in the error. And then we have more such commands. So, we can check all directories or only a specific one. We can also add filters or only one file. Moreover, there is an option to run continuous listening. If we change the code, it will analyze everything itself and give a new result. There is also a more advanced feature directly in the tool itself, this is the default behavior of Ruff, but we can configure it exactly like Flake8 and set a general code formatting rule for it, based on which it will analyze everything. But how does Ruff differ here? Let's look at the config visually. You can create either a pyproject.toml or a .ruff.toml and put the settings there. Then, let's see how to very quickly and finely tune the analysis parameters and other rules. You can write such a config just once and then simply use ready-made ones in other projects, and configuration will take literally a couple of seconds. So, how do we need to configure all this? Initially, there is the very project. We need to open this file. Here is all the configuration from Ruff. I have placed the settings separately. I wrote some parameters. Initially, we look precisely at this. These are general linter settings. We specify the Python version, then the maximum length, and so on. If we go to the settings, we get this result. These are all the settings that we can add to the config. We just choose the ones we need and list them in the config. For example, we need to add this parameter. I just copy this value and paste it under this key from the config. And then, when you have written all the necessary settings from this page, you can also add a rule. There are more than 600 of them. These 600 rules are divided into approximately 40 built-in plugins that you do not need to install additionally. So, what do they give? This is essentially a collection of such code writing rules. Therefore, they are placed in separate blocks. For example, this component rule checks that we use the equality operator from Rust directly instead of the standard one, because all this refers to Python 3.8. Then, sometimes very strange decisions. Some people put a semicolon at the end of Python lines. This component will also give a warning and provide a code example, for example, Python should not be done like this. And the most interesting thing is that there are simply a huge number of such rules. They are divided into groups. There is the F group, then such groups are errors, and also warnings, and then all other rules are also divided into components. Here there are also many ready-made components that already act as separate plugins in Flake8. In Ruff, all this is native, i.e., built into the technology. As a result, if we need to enable this group, we specify a separate key and thus enable the desired group of checks. And catch the feature that I promised at the beginning of the video. Even if you don't work in a team, but just develop your own projects or are learning, you need to study Ruff and configure it in detail. If you notice, it says there are many different rules of good practice. Using Ruff when writing code, it will prompt you where good practices are and where they are not. You can also go into the documentation where the rules are described and see why it is a bad practice, and as a result, you will start writing correctly. And such use of this tool will constantly improve your knowledge and code quality.
Next, a very cool feature is the ability to ignore the types of errors that you don't need. You simply find the error code after Ruff's analysis and add a comment to the file itself. So, for example, we have such code. This is the very comment that needs to be specified, and this is the error code that can be taken from here. As a result, if you write all this like this for this function, this error will not work. But if we need to apply the rule to the entire file, we do the following comment. For you, the code is also available as a ready-made extension that you can install and use. And through RLS, you can install the tool in Neovim, Text, Max, etc. Essentially, you can add it absolutely anywhere. Many people ask me to show my Vim config. I will try to add Ruff and many other technologies to it. If there are many comments and likes on this topic, then I will finish my Linux shell and after that, I will make a separate video about both Neovim and my Linux setup. And also, another question: how does Ruff differ from Pylint if we don't consider speed and a huge number of ready-made rules? It differs at least in that it contains those very popular plugins from Flake8. If you want to simply install the tool and immediately use any features, then in that case, Ruff easily replaces Flake8. Personally, I would still install Ruff, at least because of its speed and all the advantages listed above. Just in case, I'll add that my Pyright is used in conjunction with this tool. It cannot replace it in any way. The whole point here is that the linter will find its types of errors, and Pyright will find other errors that it might not notice. Therefore, they need to be used together. But Ruff is still capable of replacing some tools. For example, here is that very list of what it can replace, and there are very many technologies, plugins, and so on. Under the previous video, we used the number 7 comments. It was very funny. This time, if you watched the video to the end, write in the comments how you like Ruff, but use the word "implementation" when doing so. Let other people read the comments and not understand what it's about and what implementation has to do with it.