What does it mean to run lint in code?

I saw this expression "lint code" in some places, in the IDE of Visual Studio and also when running the NG CLI, the Angular client.

What does that mean?
What exactly does " lint code " do?

Author: Cmte Cardeal, 2018-09-19

3 answers

A linter or lint is a tool for static code analysis .

Https://en.wikipedia.org/wiki/Lint_ (software)

A linteror lint refers to tools that analyze source code for programming errors, bugs, stylistic errors, and suspicious constructs. The term originates from a Unix utility that examined source code in the C. (...) The term lint is derived from the name of undesirable artifacts (fiber and fluff) in sheep's wool.

Https://en.wikipedia.org/wiki/Static_program_analysis

Static analysis of programs is the analysis of computer software that is performed without actually running programs, in contrast to dynamic analysis, which is the analysis performed on programs while they are running. In most cases the analysis is done in some version of the source code, and in other cases, in some form of the object code.

Static analysis is the process similar to what the compiler does, but with the aim of producing a list of errors, warnings (warnings) and improvement points in your code.

Code analysis may be more comprehensive than the compiler does, but due to the lack of cross-references between code units (i.e. between source files) it may lose context and not be perfect.

Though modern compilers have evolved to include much of a lint's historical functions, lint-like tools have also evolved to detect an even greater variety of suspicious constructs. These include "warnings about syntax errors, uses of undeclared variables, deprecated function calls, spacing and formatting conventions, scoping misuse, automatic drop to next case in switch commands, absence of license headers, [and] ...dangerous features of the language " .

Source

Error examples, warnings , etc. (taken from the manual of a linter):

Error

The same errors produced by a compiler: invalid syntax, expected a } and found a :, etc.

Warning

The ANSI standard does not allow assignments between pointers of different types, but most compilers can still generate reasonable object code for such an operation.

Unusual

i=i; // Válido, porém suspeito.

Notes

printf("%ld",1); // Inválido, uma vez que %ld requer um long e está
                 // recebendo um int, porém sempre funciona em
                 // máquinas em que ambos têm o mesmo comprimento.

MachDepd

Signals a construction dependent on the machine in question. For example, the result of (-7/2) by the ANSI standard can be truncated up or down depending on the machine.

 10
Author: Piovezan, 2021-02-11 22:58:55

A linter is kind of a code formatter with a bit of parsing along.

I know two "linters" so to speak, the HTMLHint used to check HTML code in order to slightly overlap the rules of W3Schools, has the TSLint, used in Angular to organize the code.

Some TSLint rules include whether or not to have a ; at each command, or the need to put the radix attribute when making a parseInt. One can control the linter during Angular code with the use of comments, such as // tslint-disable-nextline:radix semicolon before the line of code itself.

 4
Author: mutlei, 2018-09-19 20:31:35

I know the question is old and has already been answered, but I would like to add information for anyone who can find this topic.

Other programming languages also have their linters. In Python, there are some and I cite as an example PyLint and Flake8.

The linters, as explained in the answers of @ Piovezan and @ mutlei, end up analyzing the code, either by checking syntax error or good practices.

Flake8 gives a warning if the code line exceeds 79 characters. Flake8 also gives a warning when the distance between imports and the beginning of the class code is not two lines. In both cases, the code works normally if it doesn't follow what linter asks for, because the problem is good practice and not syntax.

In short, the linters serve for the programmer to enter a correct code, without the syntax errors and following a good programming practice related to the language. There are good practices that serve all languages and there are more language-specific best practices and linter will help you follow a pattern.

 1
Author: Diego Feitosa, 2021-02-12 02:23:41