From the course: Debugging in C++ with Visual Studio Code

Linting

- [Speaker] Linting is the process of analyzing code to flag programming errors, bug, and suspicious statements. In many integrated environments, lint runs as a background process to show you these warnings and errors on the fly by means of wavy underlines known as squiggles, technically squiggles may come from a linting tool or from other running processes like the compiler itself. For this video, we have another faulty version of the same battery drain simulation. This time, we have a different set of errors in it. So to showcase squiggles, all we have to do is look for them in the code. Note that in addition to the squiggles in the code, the vertical scroll bar at the right shows red markers indicating the squiggle locations. Let me scroll down. Aha! We have one in line 37 and another one in line 43. Let me hover over the first one. The tool tip claims that the normaDrain identifier is undefined and it's right, it's a typo. Now let's see the next one. This one reads expected a semicolon, but this line does have a semicolon at the end. So what's going on? Well, the squiggle is under the std identifier, meaning that the linter didn't expect an identifier at that point. So whenever this happens, look at the previous line of code. Sure enough, line 41 is lacking a semicolon at the end. Before fixing both errors. Let me show you that you may get even more useful messages if you attempt to compile. So let me try that. This dialog box is telling me that there are errors in the code and so, it cannot build. It's almost never a good idea to press the blue debug anyway button as it would run the latest successful build, if any. Instead, I'll select to show the errors. This takes us to the problems tab. As you can see, we now have three problems, not just two. If I click on any of these problems, the editor will select the part of the code responsible for this violation and it will have a squiggle. The first two are related to the first squiggle. Let me hover over it again. And now, we see two messages. The new one reads normaDrain was not declared in this scope, did you mean normalDrain? Yes, that's what I meant. Thank you squiggle. So these two messages came from two different sources and we can see their signatures in gray at the end of each message, both in the hover tool tip and in the problems tab. The first message came from the C/C++ IntelliSense engine, the linting tool, and the second one came from the GCC compiler. So that's an actual compiler error. Let me fix that typo. And now we would expect the squiggle to be gone, but it's still there. That's because unfortunately,compiler errors stay there until we reattempt to compile, and this particular squiggle had two errors. In fact, notice that the linting error is gone in the hover tooltip and in the problem tab. The squiggle is still there only because of the compiler error. So we need to rebuild to make this squiggle go away. Before we do that, let me show you the compiler errors in the command line. Let's go to the terminal. Here, we can see the original compiler errors showing the problems in red and the suggested solutions in green. The second one we see there points to the end of the line that lacks a semicolon, so it seems more accurate. Alright, let me rebuild. And the squiggle in line 37 is gone. Now notice, there's an extra squiggle at the end of line 41. This is the more accurate compiler error we just saw in the terminal, which now has its own squiggle. The message reads expected semicolon before std. So this refers to the same problem we saw for the squiggle at line 43. Let me fix it. Once again, notice that the squiggle at line 43 is gone because it came from the linter and the one at the end of line 41 is still there because it came from the compiler. Alright, now that the problems are solved, let's try to build. There you go. It compiled with no errors. Let's keep going.

Contents