What does it mean to run lint in the code?

Asked

Viewed 3,987 times

11

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

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

3 answers

11


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

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

A linter or lint refers to tools that analyze 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. (...) The term lint is derived from the name of undesirable artifacts (fiber and down) in sheep 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 in order to produce a list of errors, warnings (warnings) and improvement points in your code.

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

Although 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 constructions. Among them are "warnings about syntax errors, uses of unreported variables, obsolete function calls, spacing and formatting conventions, misuse of scope, automatic drop to the next case in switch commands, absence of license headers, [and] ...dangerous language features".

Source

Examples of errors, warnings, etc. (taken from manual 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.

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 construction dependent on the machine in question. For example, the result of (-7/2) by ANSI standard can be truncated up or down depending on the machine.

  • interesting, all my life I thought of compilation errors, I didn’t know with that term

4

A linter is kind of a code formatter with a bit of syntactic analysis attached.

I know two "linters" so to speak, the Htmlhint used to check HTML code in order to slightly override the rules of W3schools, has Tslint, used in Angular to organize the code.

Some Tslint rules include the need or not for the presence of a ; to each command, or the need to place the attribute radix when making a parseint. You can control linter during the Angular code using comments, such as // tslint-disable-nextline:radix semicolon before the code line itself.

  • then you mean it configurable? remembered, on Visual Studio is Eslint

  • Yes. Htmlhint and Tslint are configurable. In the Htmlhint link you can put an HTML code and change the rules to suit what you want, and then download the file .htmlhint page. Tslint is configured in the file tslint.json within the root of an Angular project.

1

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

Other programming languages also have their linters. In Python, there are some and I cite as examples Pylint and Flake8.

The linters, as explained in the @Piovezan and @mutlei responses, end up analyzing the code, whether checking syntax error or good practice.

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.