LinuxCommandLibrary

tslint

Analyze TypeScript code for style and potential errors

TLDR

Create TSLint config

$ tslint --init
copy

Lint on a given set of files
$ tslint [path/to/file1.js path/to/file2.js ...]
copy

Fix lint issues
$ tslint --fix
copy

Lint with the configuration file in the project root
$ tslint --project [path/to/project_root]
copy

SYNOPSIS

tslint [options] file1 file2 ...

PARAMETERS

--config
    Path to the configuration file (tslint.json).

--fix
    Automatically fixes some linting errors.

--force
    Suppress program failure on file errors.

--format
    Use a specific formatter to output results (e.g., json, stylish).

--init
    Generate a tslint.json file in the current directory.

--project
    Path to the tsconfig.json file.

--exclude
    Exclude files matching the given glob from linting.

--test
    Run in test mode.

-p, --project
    Specifies the project directory or tsconfig.json file to use.

-t, --format
    Specifies the output format of the linting results.

-f, --fix
    Automatically fixes some linting errors.

DESCRIPTION

tslint is a static analysis tool that checks TypeScript code for readability, maintainability, and functionality errors. It enforces a set of coding rules based on configurable settings in a `tslint.json` file. TSLint analyzes code for potential problems such as unused variables, stylistic inconsistencies, and potential runtime errors, helping developers catch issues early in the development cycle and improve code quality. It is highly configurable, allowing teams to customize the linting rules to fit their specific project needs and coding style preferences. While officially deprecated in favor of ESLint with the TypeScript ESLint plugins, understanding TSLint is valuable because many older projects still rely on it, and its concepts are relevant to modern linting practices.

CAVEATS

tslint is deprecated. Consider migrating to ESLint with the TypeScript ESLint plugins. Many rules defined in tslint doesn't have automatic fix.

CONFIGURATION

tslint is configured via a tslint.json file. This file specifies the rules to be enforced, as well as other settings like which files to include or exclude.
Example configuration:
{ "rules": { "semicolon": [true, "always"], "no-unused-variable": true } }

EXIT CODES

tslint returns a non-zero exit code if any linting errors are found, allowing it to be used in continuous integration pipelines to prevent code with errors from being committed. A zero exist code means, that the code is ok.

INTEGRATION WITH EDITORS

tslint integrates with many popular code editors and IDEs, such as Visual Studio Code, Atom, and Sublime Text, providing real-time feedback as you type.

HISTORY

TSLint was created to provide static analysis for TypeScript code, aiming to enforce coding style and detect potential errors early in development. It gained widespread adoption in the TypeScript community and became the standard linter for TypeScript projects. However, due to the rise of ESLint and the availability of TypeScript ESLint plugins that provide similar functionality, TSLint has been deprecated and is no longer actively maintained.

SEE ALSO

eslint(1)

Copied to clipboard