Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Checking Your Code Continuously

00:00 You can run the subcommand ruff check, as often as you like, and hopefully you’ll run it more often than not because the sooner you catch the linking errors, the easier it is to fix them.

00:11 You don’t want hundreds of errors piling up in your codebase, but there’s also a functionality that ruff provides to make it even easier to check your code frequently.

00:21 And that’s the option --watch. So running ruff check --watch sets up a file watcher that will continuously lint your files. To see that in action, you can open the terminal in a folder where you have Python code, ideally the file one_ring.py, which is the file you’re working with, and also open the code.

00:46 So ideally, side by side so you can see both things happening at the same time. So in the terminal you will run the command ruff check with the option --watch, and you will immediately see some output saying that the linting is starting and that there are zero errors because in the last lesson you fixed all errors in your file.

01:09 So go ahead and cut the function, ring_bearer() from the file, delete it, and save the file. And as soon as you save the file, essentially instantaneously ruff tells you that there’s a problem in the file one_ring.py because you’re trying to use a name that has not been defined, which is ring_bearer.

01:29 So you can fix this error because ruff told you about it. You can define the function ring_bearer(),

01:36 and then you can just check that everything is fine.

01:42 So you redefine the function again, you save it, but wait, ruff immediately tells you that now there’s an undefined name, name, because the variable name that you’re checking to see if it is inside the pair Frodo and Sam is now missing again.

01:58 So this was the original error you had in the previous lesson. So you already know how to fix this. You need the parameter name in the function ring_bearer().

02:08 So now if you save this one more time after adding the name parameter to the function signature, you see that ruff now has zero errors again.

02:19 So by using this --watch option, you can get feedback in real time. Whenever you save your file, ruff will lint your code, which in my opinion is pretty neat.

02:31 As a linter, ruff implements a series of rules that will help you write clearer, more readable, more maintainable code. But ruff doesn’t check all of its rules by default.

02:44 So in the next lesson, you will learn how to select more rules for ruff to check.

Become a Member to join the conversation.