Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'palantir/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
calebegg committed Sep 18, 2017
2 parents 6b6f43a + c434183 commit cffa68e
Show file tree
Hide file tree
Showing 152 changed files with 2,789 additions and 448 deletions.
44 changes: 44 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,50 @@
Change Log
===

v5.7.0
---

## :tada: New rules, options, and fixers

- [new-rule] [`no-parameter-reassignment`](https://palantir.github.io/tslint/rules/no-parameter-reassignment/) (#3045)
- [new-rule-option]: [`object-literal-sort-keys`](https://palantir.github.io/tslint/rules/object-literal-sort-keys/): Add `match-declaration-order` option (#2829)
- [new-rule-option] `check-type-operator` for [`whitespace`](https://palantir.github.io/tslint/rules/whitespace/) rule (#3083)
- [new-rule-option] [`whitespace`](https://palantir.github.io/tslint/rules/whitespace/): Add `check-rest-spread` option (#3089)

## :hammer_and_wrench: Bugfixes & enhancements

- [api] `AbstractRule#applyWithFunction` allows additional parameter that is passed through to `walkFn` (#3140)
- [api] `AbstractRule#applyWithFunction` has better type checking for its type parameter (#2660)
- [bugfix] [`member-access`](https://palantir.github.io/tslint/rules/member-access/) autofix now correcly inserts `public` keyword after decorators (#3162)
- [bugfix] [`prefer-const`](https://palantir.github.io/tslint/rules/prefer-const/) correctly handle `catch` without binding parameter introduced in `typescript@2.5.1` (#3151)
- [bugfix] [`no-invalid-template-strings`](https://palantir.github.io/tslint/rules/no-invalid-template-strings/) allows backslash-prefixed template expressions (#3116)
- [bugfix] [`deprecation`](https://palantir.github.io/tslint/rules/deprecation/) no longer shows errors on imports and exports (#3141)
- [bugfix] [`deprecation`](https://palantir.github.io/tslint/rules/deprecation/): fix false positive when calling a function or method where another overload is deprecated (#2883)
- [bugfix] [`whitespace`](https://palantir.github.io/tslint/rules/whitespace/): fixed `"check-separator"` for trivial `for` cases. (#3132)
- [bugfix] [`prefer-object-spread`](https://palantir.github.io/tslint/rules/prefer-object-spread/) prevent spreading `this` as it is not allowed by the compiler (#3126)
- [bugfix] `msbuild` formatter uses backslashes in paths on Windows (#3145)
- [bugfix] [`no-namespace`](https://palantir.github.io/tslint/rules/no-namespace/) ignores global augmentation (#3161)
- [enhancement] remove superfluous empty lines on tslint output. (#3121)
- [enhancement] [`no-submodule-imports`](https://palantir.github.io/tslint/rules/no-submodule-imports/) allows whitelisting of submodules like `@angular/core/testing` (#3129)
- [enhancement] custom lint rules will be resolved using node's path resolution to allow for loaders like `ts-node` (#3108)
- [enhancement] [`quotemark`](https://palantir.github.io/tslint/rules/quotemark/) no longer requires `"single"` or `"double"` to be the first option. The rule defaults to `"double"` if none is specified. (#3114)
- [enhancement] [`no-unused-variable`](https://palantir.github.io/tslint/rules/no-unused-variable/) autofix removes trailing comments of imports (#3156)
- [enhancement] [`no-unnecessary-type-assertion`](https://palantir.github.io/tslint/rules/no-unnecessary-type-assertion/) allows certain necessary assertions to prevent type widening (#3120)

Thanks to our contributors!

- Paul Gschwendtner
- Andy Hanson
- ksvitkovsky
- Santi Albo
- aervin
- Junle Li
- Joscha Feth
- WiseBird
- Caleb Eggensperger
- WGroenestein
- Bowen Ni

v5.6.0
---

Expand Down
7 changes: 7 additions & 0 deletions docs/_data/formatters.json
Expand Up @@ -25,6 +25,13 @@
"sample": "\n[\n {\n \"endPosition\": {\n \"character\": 13,\n \"line\": 0,\n \"position\": 13\n },\n \"failure\": \"Missing semicolon\",\n \"fix\": {\n \"innerStart\": 13,\n \"innerLength\": 0,\n \"innerText\": \";\"\n },\n \"name\": \"myFile.ts\",\n \"ruleName\": \"semicolon\",\n \"startPosition\": {\n \"character\": 13,\n \"line\": 0,\n \"position\": 13\n }\n }\n]",
"consumer": "machine"
},
{
"formatterName": "junit",
"description": "Formats errors as through they were JUnit output.",
"descriptionDetails": "\nImitates the JUnit XML Output",
"sample": "\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<testsuites package=\"tslint\">\n <testsuite name=\"myFile.ts\">\n <testcase name=\"Line 1, Column 14: semicolon\">\n <failure type=\"warning\">Missing semicolon</failure>\n </testcase>\n </testsuite>\n</testsuites>\n",
"consumer": "machine"
},
{
"formatterName": "msbuild",
"description": "Formats errors for consumption by msbuild.",
Expand Down
15 changes: 12 additions & 3 deletions docs/develop/custom-rules/index.md
Expand Up @@ -8,11 +8,11 @@ TSLint ships with a set of core rules that can be configured. However, users are

Let us take the example of how to write a new rule to forbid all import statements (you know, *for science*). Let us name the rule file `noImportsRule.ts`. Rules are referenced in `tslint.json` with their kebab-cased identifer, so `"no-imports": true` would configure the rule.

__Important conventions__:
__Important conventions__:

- Rule identifiers are always kebab-cased.
- Rule files are always camel-cased (`camelCasedRule.ts`).
- Rule files *must* contain the suffix `Rule`.
- Rule files *must* contain the suffix `Rule`.
- The exported class must always be named `Rule` and extend from `Lint.Rules.AbstractRule`.

Now, let us first write the rule in TypeScript:
Expand Down Expand Up @@ -55,7 +55,7 @@ Finally, add a line to your [`tslint.json` config file][0] for each of your cust

---

Now that you're written a rule to detect problems, let's modify it to *fix* them.
Now that you're written a rule to detect problems, let's modify it to *fix* them.

Instantiate a `Fix` object and pass it in as an argument to `addFailure`. This snippet replaces the offending import statement with an empty string:

Expand All @@ -71,5 +71,14 @@ Final notes:

- Core rules cannot be overwritten with a custom implementation.
- Custom rules can also take in options just like core rules (retrieved via `this.getOptions()`).
- As of TSLint v5.7.0 you no longer need to compile your custom rules before using them. You need to tell node.js how to load `.ts` files for example by using `ts-node`:

```sh
ts-node node_modules/.bin/tslint <your options>
# or
node -r ts-node/register node_modules/.bin/tslint <your options>
# or
NODE_OPTIONS="-r ts-node/register" tslint <your options>
```

[0]: {{site.baseurl | append: "/usage/tslint-json/"}}
14 changes: 7 additions & 7 deletions docs/develop/testing-rules/index.md
Expand Up @@ -9,7 +9,7 @@ Every TSLint rule has a corresponding directory inside `test/rules/` which conta
Each test case contains:

* A `tslint.json` file which specifies the configuration for TSLint to use
* `.ts.lint` test files which contain TypeScript code and a special markup which indicate where lint failures should be found
* `.ts.lint` test files which contain TypeScript code and a special markup which indicate where lint failures should be found

The test system lints the `.ts.lint` files with the settings specified in `tslint.json` and makes sure that failures generated by the TSLint match the failures marked in the `.ts.lint` files.

Expand All @@ -35,7 +35,7 @@ Now let's make the actual test file:

`test/rules/no-animal-variable-names/default/test.ts.lint`:

```
```
const octopus = 5;
~~~~~~~ [Variables named after animals are not allowed!]
Expand All @@ -56,7 +56,7 @@ as shown in the above example with the line `let giraffe: number, tiger: number;
Notice how we also include lines of code that *shouldn't* generate lint failures.
This is important to ensure that the rule isn't creating false-positives.

We can now run `grunt test` to make sure that our rule produces the output we expect.
We can now run `yarn compile:test && yarn test:rules` to make sure that our rule produces the output we expect.

##### Testing a New Rule Option #####

Expand All @@ -74,7 +74,7 @@ Let's look at one more example. Say we've added an `also-no-plants` option to ou

`test/rules/no-animal-variable-names/also-no-plants/test.ts.lint`:

```
```
const octopus = 5;
~~~~~~~ [no-animal]
Expand All @@ -95,11 +95,11 @@ Instead of writing out the full lint failure message after each occurance of it,
(Shortcut names can only consist of letters, numbers, underscores, and hyphens.)
Then, at the bottom of our test file, we specify what full message each shortcut should expand to.

Again, we can run `grunt test` to make sure our rule is producing the output we expect. If it isn't we'll see the difference between the output from the rule and the output we marked.
Again, we can run `yarn compile:test && yarn test:rules` to make sure our rule is producing the output we expect. If it isn't we'll see the difference between the output from the rule and the output we marked.

You can also use placeholders to format messages. That's useful if the error message contains non-static parts, e.g. variable names. But let's stick to the above example for now.

```
```
const octopus = 5;
~~~~~~~ [no-animal]
Expand All @@ -124,7 +124,7 @@ If you use formatting in another message shorthand (like we did for `[no-animal]

Now let's pretend the rule changed its error message to include the variable name at the end. The following example shows how to substitute multiple placeholders.

```
```
const octopus = 5;
~~~~~~~ [no-animal % ('octopus')]
Expand Down
20 changes: 20 additions & 0 deletions docs/formatters/junit/index.html
@@ -0,0 +1,20 @@
---
formatterName: junit
description: Formats errors as through they were JUnit output.
descriptionDetails: |-

Imitates the JUnit XML Output
sample: |

<?xml version="1.0" encoding="utf-8"?>
<testsuites package="tslint">
<testsuite name="myFile.ts">
<testcase name="Line 1, Column 14: semicolon">
<failure type="warning">Missing semicolon</failure>
</testcase>
</testsuite>
</testsuites>
consumer: machine
layout: formatter
title: 'TSLint formatter: junit'
---
2 changes: 2 additions & 0 deletions docs/usage/configuration/index.md
Expand Up @@ -31,6 +31,8 @@ A path to a directory or an array of paths to directories of [custom rules][2].
- [Check out the full rules list here][3].
* `jsRules?: any`: Same format as `rules`. These rules are applied to `.js` and `.jsx` files.
* `defaultSeverity?: "error" | "warning" | "off"`: The severity level used when a rule specifies a default warning level. If undefined, "error" is used. This value is not inherited and is only applied to rules in this file.
* `linterOptions?: { exclude?: string[] }`:
- `exclude: string[]`: An array of globs. Any file matching these globs will not be linted. All exclude patterns are relative to the configuration file they were specified in.

`tslint.json` configuration files may have JavaScript-style `// single-line` and `/* multi-line */` comments in them (even though this is technically invalid JSON). If this confuses your syntax highlighter, you may want to switch it to JavaScript format.

Expand Down
22 changes: 18 additions & 4 deletions docs/usage/type-checking/index.md
Expand Up @@ -19,18 +19,32 @@ tslint -p tsconfig.json --exclude '**/*.d.ts' # lint all files in the project ex
tslint -p tsconfig.json **/*.ts # ignores files in tsconfig.json and uses the provided glob instead
```

Use the `--type-check` flag to make sure your program has no type errors. TSLint will check for any errors before before linting. This flag requires `--project` to be specified.
Use the `--type-check` flag to make sure your program has no type errors. TSLint will check for any errors before linting. This flag requires `--project` to be specified.

##### Library

To enable rules that work with the type checker, a TypeScript program object must be passed to the linter when using the programmatic API. Helper functions are provided to create a program from a `tsconfig.json` file. A project directory can be specified if project files do not lie in the same directory as the `tsconfig.json` file.

```js
import { Linter, Configuration } from "tslint";

const configurationFilename = "Specify configuration file name";
const options = {
fix: false,
formatter: "json",
rulesDirectory: "customRules/",
formattersDirectory: "customFormatters/"
};

const program = Linter.createProgram("tsconfig.json", "projectDir/");
const linter = new Linter(options, program);

const files = Linter.getFileNames(program);
const results = files.map(file => {
files.forEach(file => {
const fileContents = program.getSourceFile(file).getFullText();
const linter = new Linter(file, fileContents, options, program);
return linter.lint();
const configuration = Configuration.findConfiguration(configurationFilename, file).results;
linter.lint(file, fileContents, configuration);
});

const results = linter.getResult();
```
11 changes: 6 additions & 5 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "tslint",
"version": "5.6.0",
"version": "5.7.0",
"description": "An extensible static analysis linter for the TypeScript language",
"bin": {
"tslint": "./bin/tslint"
Expand Down Expand Up @@ -46,10 +46,10 @@
"resolve": "^1.3.2",
"semver": "^5.3.0",
"tslib": "^1.7.1",
"tsutils": "^2.7.1"
"tsutils": "^2.8.1"
},
"peerDependencies": {
"typescript": ">=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev"
"typescript": ">=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev || >=2.5.0-dev || >=2.6.0-dev || >=2.7.0-dev"
},
"devDependencies": {
"@types/babel-code-frame": "^6.20.0",
Expand All @@ -72,9 +72,10 @@
"npm-run-all": "^4.0.2",
"nyc": "^10.2.0",
"rimraf": "^2.5.4",
"tslint": "^5.5.0",
"ts-node": "^3.3.0",
"tslint": "^5.7.0",
"tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative",
"typescript": "~2.4.1"
"typescript": "~2.5.1"
},
"license": "Apache-2.0",
"engines": {
Expand Down
6 changes: 5 additions & 1 deletion src/configs/all.ts
Expand Up @@ -99,6 +99,7 @@ export const rules = {
"no-construct": true,
"no-debugger": true,
"no-duplicate-super": true,
"no-duplicate-switch-case": true,
"no-duplicate-variable": [
true,
"check-parameters",
Expand Down Expand Up @@ -149,6 +150,7 @@ export const rules = {
"no-duplicate-imports": true,
"no-irregular-whitespace": true,
"no-mergeable-namespace": true,
"no-parameter-reassignment": true,
"no-require-imports": true,
"no-trailing-whitespace": true,
"object-literal-sort-keys": true,
Expand Down Expand Up @@ -186,7 +188,7 @@ export const rules = {
"import-spacing": true,
"interface-name": true,
"interface-over-type-literal": true,
"jsdoc-format": true,
"jsdoc-format": [true, "check-multiline-start"],
"match-default-export-name": true,
"new-parens": true,
"newline-before-return": true,
Expand Down Expand Up @@ -253,6 +255,8 @@ export const rules = {
"check-type",
"check-typecast",
"check-preblock",
"check-type-operator",
"check-rest-spread",
],
};

Expand Down
21 changes: 21 additions & 0 deletions src/configs/latest.ts
Expand Up @@ -48,6 +48,27 @@ export const rules = {
// added in v5.6
"no-duplicate-imports": true,
"space-within-parens": [true, 0],
"no-submodule-imports": true,

// added in v5.7
"whitespace": {
options: [
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type",
"check-typecast",
"check-type-operator",
"check-rest-spread",
],
},

// added in v5.8
"no-duplicate-switch-case": true,
"jsdoc-format": {
options: "check-multiline-start",
},
};
// tslint:enable object-literal-sort-keys

Expand Down

0 comments on commit cffa68e

Please sign in to comment.