What does it mean to run lint in code?

7

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

What does it mean?
What exactly does lints code do?

    
asked by anonymous 19.09.2018 / 22:11

2 answers

6

A linter or lint is a static code analysis tool.

link

  

A linter or lint refers to tools that parse source code to accuse programming errors, bugs, stylistic errors, and suspicious constructs. The term originates from a Unix utility that examined source code in C language. (...) The term lint is derived from the name of undesirable artifacts (fiber and down) in sheep's wool. / p>

link

  Static program analysis is computer software analysis 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 some cases in some form of the object code.

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

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

  Although modern compilers have evolved to include much of the historical functions of a lint, 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, obsolete function calls, spacing and formatting conventions, scope misuse, automatic fall for the next switch case, no headers license, [and] ... dangerous language features. .

Font

Examples of errors, warnings , etc. (taken from a linter manual ):

Error

The same errors produced by a compiler: Invalid syntax, expected } and found : , 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.

Note

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 dependent build of 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.

    
19.09.2018 / 22:29
3

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

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

Some TSLint rules include whether or not a ; is required for each command, or the need to set the radix attribute when parseInt. You can control the linter during the angle code using comments like // tslint-disable-nextline:radix semicolon before the line of code itself.

    
19.09.2018 / 22:31