GithubHelp home page GithubHelp logo

wjohnsto / tsconfig-lint Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 1.0 33 KB

A tslint library focused on exposing an easy way to access tslint through the cli and use tsconfig.json to specify lint rules.

License: MIT License

JavaScript 12.82% TypeScript 87.18%

tsconfig-lint's Introduction

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

npm version Downloads Dependency Status devDependency Status

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:

  1. 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 an exclude, files or filesGlob property along with your tslint rules.
  1. You specify an exclude, files, or filesGlob pattern in your tsconfig.json
  2. 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"
    ]
}

tsconfig-lint's People

Contributors

dsebastien avatar wjohnsto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

dsebastien

tsconfig-lint's Issues

Exit/status code is always 0

I can run tslint on a file that has failures and the exit status is non-zero and the exit status for a file with no failures is 0, both as they should be:

rpatterson@rpatterson:~/src/work/newcontext/Soltra/argos/argos-ui$ ./node_modules/.bin/tslint
...
src/app/....ts[63, 56]: missing whitespace
$ echo $?
2
$ ./node_modules/.bin/tslint src/app/...ts
$ echo $?
0

But running tsconfig-lint with a config that includes the same files and reports the same failures has an exit status of 0:

$ ./node_modules/.bin/tsconfig-lint                                                                                          
Linting 28 files
...
src/app/...ts[63, 56]: missing whitespace

Done with 63 failures.
$ echo $?
0

This makes using tsconfig-lint in CI is much more difficult than it need be.

Error: Cannot find module 'tsconfig-glob'

Installed and tried to run on the command line with tsconfig-lint . but getting the following error:

module.js:341
    throw err;
    ^

Error: Cannot find module 'tsconfig-glob'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/tsconfig-lint/index.js:10:16)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)

tsconfig lint swallows unknown rule errors silently

tsconfig lint swallows unknown rule errors silently

When tslint raises an error like this:

Could not find implementations for the following rules specified in the configuration:
no-parameter-properties
Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed.
If TSLint was recently upgraded, you may have old rules configured which need to be cleaned up.

It is silently swallowed by the lintFile function.

Path bug + lintfile() should throw an error when a file is not found

Currently if the lintfile() method does not find a file, this is silently ignored and it seems like the file contains 0 errors. This should not be the case. If a file is not found, an error should be thrown specifiying the failing file path.

You might wonder how it might not be able find a file, since the file list is build from a glob pattern. Well I think this is a bug (although maybe not an easy one to solve).

Suppose have you the following file structure:

package.json
src/
src/tsconfig.json
src/**/*.ts

package.json contains the following script:

"tslint": "tsconfig-lint --use-glob src"

tsconfig contains the following glob pattern:

"filesGlob": "**/*.ts",

this results in file entries like

    "files": [
        "./form/dropdown/scripts/dropdown.ts",
        "./form/modal-popup/scripts/modal-popup-controller.ts",

But the current working dir for tsconfig-lint is the root folder (where package.json is located) and not 'src' so none of the files is found by the linter.

I was able to solve this by putting tsconfig.json also in the root folder, but had to dig into the code to figure out why it was not working. So getting an error, specifying that a file was not found would make this more obvious.

A fix for the path issue would of course be better. The paths are now relative to the location of tsconfig.json and this works fine for tsc, but not for the linter (which should also use the location of tsconfig as CWD).

Missing support for comments

Recently, tslint added support for comments in tslint.json.
tsconfig-lint doesn't seem to like comments in the config file. It fails silently and uses default rules it embeds

Missing support for output format

It would be nice if we could specify an output format used for the linting errors report, so that we can integrate this with our CI environment (TeamCity in our case).

TSLInt supports the following output format options:

  • prose
  • json
  • verbose
  • pmd
  • msbuild
  • checkstyle

But it looks like the current output format used by tsconfig-lint is 'prose' (the default of TSLint) and TeamCity cannot deal with this format.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.