What is “Linting” in programming?


PHPLintJSLint, and I recently came across “you can lint your JS code on the fly” while reading something about some IDE.

So, what is “linting”?

What is “Linting”?

Linting is the process of running a program that will analyze code for potential errors.

As per Wikipedia:

lint was the name originally given to a particular program that flagged some suspicious and non-portable constructs (likely to be bugs) in C language source code. The term is now applied generically to tools that flag suspicious usage in software written in any computer language.

Lint was the name of a program that would go through your C code and identify problems before you compiled, linked, and ran it. It was a static checker, much like FindBugs today for Java.

Like Google, “lint” became a verb that meant static checking your source code.

Or, Linting in programming can be understood as:

Linting is the process of checking the source code for Programmatic as well as Stylistic errors. This is most helpful in identifying some common and uncommon mistakes that are made during coding.

Lint or a Linter is a program that supports linting (verifying code quality). They are available for most languages like JavaScript, CSS, HTML, Python, etc..

Some of the useful linters are JSLint, CSSLint, JSHint, and Pylint.

Apart from what have been mentioned above, I would like to add that, Linting will run through your source code to find

 -  formatting discrepancy 
 -  non-adherence to coding standards and conventions 
 -  pinpointing possible logical errors in your program

Running a Lint program over your source code, helps to ensure that source code is legible, readable, less polluted, and easier to maintain.

What is linter?

Linter is a tool that is used to mark the source code with some suspicious and non-structural (may cause bug). It is a static code analysis tool in C at the beginning. Now it became the generic term used to describe the software analysis tool that marks the suspicious code.

Interpreted languages like Python and JavaScript benefit greatly from linting, as these languages don’t have a compiling phase to display errors before execution.

Linters are also useful for code formatting and/or adhering to language-specific best practices.

Lately, I have been using ESLint for JS/React and will occasionally use it with an Airbnb-config file.

What is linting?

Linting is a process by a linter program that analyzes source code in a particular programming language and flags potential problems like syntax errors, deviations from a prescribed coding style or using constructs known to be unsafe.

For example, a JavaScript linter would flag the first use of parseInt below as unsafe:

// without a radix argument - Unsafe
var count = parseInt(countString);

// with a radix paremeter specified - Safe
var count = parseInt(countString, 10);

What are the benefits of linting?

According to Ferit T., linting improves readability, removes silly errors before execution and code review. But, as mentioned, linting may do more complex jobs, like detecting code smells or performing static analysis of your codebase.

But, in practice, what are the advantages of linting?

It improves code review discussion level

If your Pull Request has no typos, nor unused variables, and is compliant with the style guide, the conversation tends to focus on the architecture point of view. That’s it. Pull Request is a great place to point performance issuessecurities vulnerabilities, or suggesting better abstractions. You don’t need to get in that single or double quotes or tab vs. spaces discussion. It is a productivity gain for sure.

Makes code look like written by a single person

To the medium and long term having a reliable code base that looks like written by the same person is excellent. Maintainability and evolution are easier because everyone tends to understand what’s written faster and more precisely. It prevents bugs, makes the job more joyful for developers, and accelerates the time to market new features.

Gives visibility of your codebase health

Is your code healthy? You won’t know until you measure it. An exciting way of doing so is to adding a step in your CI/CD pipeline to measure the evolution of your code health status. Better than that, you can take action as soon as possible when you see its health to decay. Such actions may imply on creating technical debit cards in your board or even raise the issue during your agile retrospective or architecture committee meeting.

Spreads awareness and ownership over code quality

Experienced developers can look into a diff and raise relevant issues about the proposed change. They probably know where to look: are variables names descriptives? How many lines does a method take? Is there any superclass?

But how about newcomers? The knowledge in a team is often heterogeneous. It means not every developer knows what to look over the code. Having a linter to tell where code smells are automatically is an excellent way to spread this knowledge and make the team responsible for the changes.

Quality is not a single-person responsibility. It’s essential to measure and control code quality over time. Otherwise, the code gets messy, which slows down development and time to market.

Controls technical debts

As many modern linters look for possible technical debts, like code smells, style guide mismatches, or poorly designed code (deep chains of if statements, or too complex methods, for instance), linters correlate with technical debt.

Making technical debts explicit during the code review process help software developers or engineers to spot, discuss, and fix them before they merge into the master  branch. It’s a very convenient practice that controls the technical debt insertions.

Hope you learned something from this post.

Follow Programming Articles for more!

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →