tsconfig-lint
v0.12.0
Published
A tsconfig tool for running tslint on files found in the tsconfig. Integrates with tsconfig-glob to allow for `filesGlob` in the tsconfig.json.
Downloads
5,941
Readme
ts-glob deprecation notice
This package currently uses tsconfig-glob. However in the next major release it will be removed in favor of using the "include" property for TypeScript 2.0
tsconfig-lint
A tsconfig tool for running tslint on files found in the tsconfig. Integrates with tsconfig-glob to allow for filesGlob
in the tsconfig.json.
Install
Use npm
to install this package.
Locally:
npm install tsconfig-lint --save-dev
or, Globally:
npm install -g tsconfig-lint --save-dev
Usage
You can use this library as either a CLI or in a node script. It follows a similar format to the atom-typescript plugin:
- You provide a path to a directory containing a tsconfig.json file
- You can also provide the full path to a
.json
file that contains anexclude
,files
orfilesGlob
property along with your tslint rules.
- You specify an
exclude
,files
, orfilesGlob
pattern in your tsconfig.json - You specify a
lintOptions
property in your tsconfig.json that contains your tslint rules.
- If you do not specify
lintOptions
, the default tslint rules will be used
You can also put your tslint rules in a separate file. By default, tsconfig-lint will look for tslint.json
(you can override the name if needed).
If the file is found, then:
- the rules defined in it will be used
- lintOptions will be ignored
Using the CLI
tsconfig-lint .
Options
-c, --config The name of the tslint configuration file; if not provided, 'tslint.json' will be used
-u, --use-glob A flag indicating that `filesGlob` should be used in place of `files` for determining the files to lint.
-i, --indent <number> The number of spaces to indent the tsconfig.json file (defaults to 4). Only necessary if using --use-glob
-p, --passive A flag indicating whether or not the script should exit with 1 on fail. If `passive` is specified, failures will still be sent with 0.
Using with Node
import * as lint from 'tsconfig-lint';
lint(undefined, (err) => {
//...
});
Options
{
/**
* A relative path from cwd to the directory containing a tsconfig.json. If not specified, the '.' is used.
*/
configPath?: string;
/**
* The current working directory, defaults to `process.cwd()`
*/
cwd?: string;
/**
* Whether or not `filesGlob` should be used in place of `files` for determining the files to lint.
*/
useGlob?: boolean;
tsconfigOptions: {
/**
* The number of spaces to indent the tsconfig.json
*/
indent?: number;
};
/**
* A relative path from the configPath to the tslint configuration file.
*/
tsLintConfigFilePath?: string;
}
Realistic Node Usage
import * as lint from 'tsconfig-lint';
lint({
configPath: '.',
cwd: process.cwd(),
useGlob: true,
tsconfigOptions: {
indent: 2
}
}, (err) => {
//...
});
Default Rules
The default rules (found in the tsconfig.json) are below:
"rules": {
"class-name": true,
"curly": true,
"eofline": true,
"forin": true,
"indent": [
true,
4
],
"interface-name": true,
"jsdoc-format": true,
"label-position": true,
"label-undefined": true,
"max-line-length": false,
"member-ordering": [
true,
"public-before-private",
"static-before-instance",
"variables-before-functions"
],
"no-any": false,
"no-arg": true,
"no-bitwise": false,
"no-console": [
true,
"debug",
"info",
"time",
"timeEnd",
"trace"
],
"no-consecutive-blank-lines": true,
"no-construct": true,
"no-constructor-vars": false,
"no-debugger": true,
"no-duplicate-key": true,
"no-duplicate-variable": true,
"no-empty": false,
"no-eval": true,
"no-string-literal": true,
"no-trailing-comma": true,
"no-trailing-whitespace": true,
"no-unreachable": true,
"no-unused-expression": true,
"no-unused-variable": false,
"no-use-before-declare": true,
"one-line": [
true,
"check-open-brace",
"check-catch",
"check-else",
"check-whitespace"
],
"quotemark": [
true,
"single"
],
"radix": true,
"semicolon": true,
"triple-equals": [
true,
"allow-null-check"
],
"typedef": [
true,
"property-declaration",
"member-variable-declaration",
"call-signature"
],
"typedef-whitespace": [
true,
[
"call-signature",
"nospace"
],
[
"catch-clause",
"nospace"
],
[
"index-signature",
"space"
],
[
"parameter",
"nospace"
],
[
"property-declaration",
"nospace"
],
[
"variable-declaration",
"nospace"
]
],
"use-strict": [
true,
"check-module"
],
"variable-name": false,
"whitespace": [
false,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
]
}