A linter for the TypeScript language.
class-nameenforces PascalCased class and interface names.curlyenforces braces forif/for/do/whilestatements.eoflineenforces the file to end with a newline.forinenforces afor ... instatement to be filtered with anifstatement.*indentenforces consistent indentation levels (currently disabled).label-positionenforces labels only on sensible statements.label-undefinedchecks that labels are defined before usage.max-line-lengthsets the maximum length of a line.no-argdisallows access toarguments.callee.no-bitwisedisallows bitwise operators.no-consoledisallows access to the specified properties onconsole. Rule options are properties to ban on the console variable.no-constructdisallows access to the constructors ofString,Number, andBoolean.no-debuggerdisallowsdebuggerstatements.no-duplicate-keydisallows duplicate keys in object literals.no-duplicate-variabledisallows duplicate variable declarations.no-emptydisallows empty blocks.no-evaldisallowsevalfunction invocations.no-string-literaldisallows object access via string literals.no-trailing-whitespacedisallows trailing whitespace at the end of a line.no-unreachabledisallows unreachable code afterbreak,catch,throw, andreturnstatements.one-lineenforces the specified tokens to be on the same line as the expression preceding it. Rule options:"check-catch"checks thatcatchis on the same line as the closing brace fortry"check-else"checks thatelseis on the same line as the closing brace forif"check-open-brace"checks that an open brace falls on the same line as its preceding expression."check-whitespace"checks preceding whitespace for the specified tokens.
quotemarkenforces consistent single or double quoted string literals.radixenforces the radix parameter ofparseIntsemicolonenforces semicolons at the end of every statement.triple-equalsenforces === and !== in favor of == and !=.variable-nameallows only camelCased or UPPER_CASED variable names. Rule options:"allow-leading-underscore"allows underscores at the beginnning.
whitespaceenforces spacing whitespace. Rule options:"check-branch"checks branching statements (if/else/for/while) are followed by whitespace"check-decl"checks that variable declarations have whitespace around the equals token"check-operator"checks for whitespace around operator tokens"check-separator"checks for whitespace after separator tokens (,/;)"check-type"checks for whitespace before a variable type specification
sudo npm install tslint -g
npm install tslint
Please first ensure that the TypeScript source files compile correctly.
usage: tslint
Options:
-c, --config configuration file
-f, --file file to lint [required]
-o, --out output file
-r, --rules-dir rules directory
-s, --formatters-dir formatters directory
-t, --format output format (prose, json) [default: "prose"]
By default, configuration is loaded from .tslintrc or tslint.json, if either exists in the current path.
var options = {
formatter: "json",
configuration: configuration,
rulesDirectory: "customRules/",
formattersDirectory: "customFormatters/"
};
var Linter = require("tslint");
var ll = new Linter(fileName, contents, options);
var result = ll.lint();
git clone git@github.com:palantir/tslint.git
cd tslint
git submodule init
git submodule update
npm install
grunt
- Add more rules from jshint
- Disallow variables referenced outside of their scope definition
- Disallow unused variables
- Support pluggable formatters