Lint is a Unixutility that performs static program analysis on C language source code.[1] The software gives its name to modern computing tools responsible for checking for coding style or formatting errors, known as a "linters" or "linting tools", even though the original Lint program performed static program analysis.
History
Stephen C. Johnson, a computer scientist at Bell Labs, came up with the term "lint" in 1978 while debugging the yacc grammar he was writing for C and dealing with portability issues stemming from porting Unix to a 32-bit machine.[1] The term was borrowed from lint, the tiny bits of fiber and fluff shed by clothing, as the command he wrote would act like a lint trap in a clothes dryer, capturing waste fibers while leaving whole fabrics intact. The lint program was released outside of Bell Labs in Unix V7, in 1979.
In his 1978 paper, Johnson explained his reasons for creating a new program to detect errors: "...the general notion of having two programs is a good one" because they concentrate on different things, thereby allowing the programmer to "concentrate at one stage of the programming process solely on the algorithms, data structures, and correctness of the program, and then later retrofit, with the aid of lint, the desirable properties of universality and portability".[1]
The paper lists lint's additional checks as:
- checks for unused variables and functions;
- checks for variables used before they're set or set but never used;
- checks for unreachable code;
- checks for functions that sometimes return with a return value and sometimes return with no return value;
- additional type checking;
- optional checks for non-portable type casts;
- checks for
charvalues being non-portably tested for being negative; - assignments of values that might not fit in the target variable, e.g.
longvalues being assigned to anintvariable; - valid C statements that don't make sense, such as a statement
*p++;, which incrementspbut does not use the pre-incremented value; - possible pointer misalignment;
- code that behaves differently if the order of expression evaluation is done differently on different platforms or compilers;
- type mismatches between formal and actual parameters to functions.
ANSI C introdujo los prototipos de función , lo que permite a los compiladores de ANSI C realizar comprobaciones de incompatibilidades de tipo entre los parámetros formales y reales de una función si se ha visto un prototipo de función antes de que se llame a la función; también añadió el voidtipo para funciones que no devuelven ningún valor, lo que permite a los compiladores comprobar las voidfunciones que sí devuelven un valor, además de comprobar las funciones que tienen un tipo de valor de retorno pero que no devuelven ningún valor. Muchas de las comprobaciones de lint también pueden realizarse como parte del análisis realizado por los compiladores optimizadores , por lo que, cuando se realiza un nivel de optimización suficientemente alto, los compiladores de C también realizarían comprobaciones de variables y funciones no utilizadas, comprobaciones de variables usadas antes de ser asignadas y asignadas y no utilizadas, y comprobaciones de código inalcanzable. Con el tiempo, también se han añadido otras comprobaciones de lint a los compiladores de C.
Sucesores de Lint
Se siguen desarrollando programas similares a lint para realizar comprobaciones de código adicionales, como revisiones de estilo de código y análisis estático de programas . Aunque los compiladores modernos han evolucionado para incluir muchas de las funciones históricas de lint, las herramientas similares a lint también han evolucionado para detectar una variedad aún mayor de construcciones sospechosas. Estas incluyen "advertencias sobre errores de sintaxis, uso de variables no declaradas , llamadas a funciones obsoletas, convenciones de espaciado y formato, mal uso del ámbito, ejecución implícita en sentencias switch , encabezados de licencia faltantes, [y]... características peligrosas del lenguaje". [ 4 ]
Las comprobaciones para hacer cumplir las guías de gramática y estilo para el código fuente de un lenguaje determinado ahora se denominan linting . clang-format de LLVM para C y C++ , Rustfmt para Rust , [ 5 ] PHP CodeSniffer para PHP , ESLint para JavaScript , Stylelint para CSS , Pylint para Python , RuboCop para Ruby y golint para Go son ejemplos de estas herramientas. Algunas de estas herramientas, como ESLint, también permiten que las reglas sean autocorregibles: una definición de regla también puede venir con la definición de una transformación que resuelve la advertencia. Las reglas sobre estilo son especialmente propensas a venir con una autocorrección. Si el linter se ejecuta en modo "corregir todo" en un archivo que activa solo reglas sobre formato, el linter actuará como un formateador.
Tools that perform more detailed static program analysis than compilers have also been developed, such as Coverity, cppcheck, and the Clang static analyzer. For JavaScript, ESLint performs static program analysis in addition to code style analysis.
Lint-like tools are especially useful for dynamically typed languages like JavaScript and Python. Because the interpreters of such languages typically do not enforce as many and as strict rules during execution, linter tools can also be used as simple debuggers for finding common errors (e.g. syntactic discrepancies) as well as hard-to-find errors such as heisenbugs (drawing attention to suspicious code as "possible errors").[6] Lint-like tools generally perform static analysis of source code.[7]
See also
References
- 1234Johnson, Stephen C. (25 October 1978). "Lint, a C Program Checker". Comp. Sci. Tech. Rep. Bell Labs: 78–1273. CiteSeerX 10.1.1.56.1841. Archived from the original on 2022-01-23.
- ↑"UNIX is free!". lemis.com. 2002-01-24.
- ↑Broderick, Bill (January 23, 2002). "Dear Unix enthusiasts"(PDF). Caldera International. Archived from the original(PDF) on February 19, 2009.
- ↑"Arcanist User Guide: Lint". Phabricator. Retrieved 19 January 2018.
- ↑rust-lang/rustfmt, The Rust Programming Language, 2025-01-20, retrieved 2025-01-21
- ↑"ESLint - Customizable JavaScript linting tool (1)". theCodeCampus. 2015-06-09. Retrieved 2019-04-21.
- ↑Jones, Nigel (1 May 2002). "How to Use Lint for Static Code Analysis". Barr Group.
Further reading
- Darwin, Ian F. (1991). Checking C Programs with Lint: C Programming Utility (Revised ed.). United States: O'Reilly Media. ISBN 978-0937175309.
- "LINT(1)". NetBSD General Commands Manual. 2024-01-24.
- Static program analysis tools
- Unix software
- Formerly proprietary software
- Software using the BSD license