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

Commit

Permalink
Blog entry for 4.0 release (#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchen63 authored and adidahiya committed Nov 18, 2016
1 parent b56a3ee commit 3c585bf
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/build/
/docs/site/
/scripts/*.js
/scripts/*.js.map
/lib/
/test/executable/tslint.json
node_modules/
Expand Down
77 changes: 77 additions & 0 deletions docs/_posts/2016-11-17-new-for-4.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
layout: post
title: "TSLint 4.0 Released"
date: 2016-11-17 15:19:00
---

TSLint 4.0 has been released! With this release comes a few exciting [changes][0]. Some of the highlights:
* **Fixers** - Do you dread turning on a new rule because of all of the new errors? For some of the most common issues, we'll fix them for you. To use this feature, run `tslint` with the `--fix` option. Rules that support the `--fix` feature:
* [array-type][2]
* [arrow-parens][3]
* [no-unused-variable][4] (for imports)
* [no-var-keyword][5]
* [ordered-imports][6]
* [semicolon][7]
* [trailing-comma][8]
* **Linting `.js` files** - *A much-requested feature from our community*. Simplify your toolset by running the same rules you know and love on your .js and .jsx files. Just add a `jsRules` [section][9] to your `tslint.json` file, and TSLint will your JavaScript files.
* **TypeScript 2.0+ required** - This lets us deprecate/remove rules that are checked by the compiler. These rules now cause compilation errors:
* no-duplicate-key
* no-unreachable
* no-unused-variable
* **Node.js API Change** - [Moved and renamed][11] some things to make more sense. Get it all when you use `import * as TSLint from "tslint"`.
* **[Recommended Rules Updated][12]**
* [adjacent-overload-signatures][13]
* [array-type][14]
* [arrow-parens][15]
* [max-classes-per-file][16]
* [no-unsafe-finally][17]
* [object-literal-key-quotes][18] (as needed)
* [object-literal-shorthand][19]
* [only-arrow-functions][20]
* [ordered-imports][21]
* [prefer-for-of][22]
* **Other rules you might find handy**:
* [completed-docs][23]
* [cyclomatic-complexity][24]

---

## Create your own fixer ##
To create your own fixer, instantiate a `Fix` object and pass it in as an argument to `addFailure`.

This snippet updates the [sample custom rule][25] by adding a fixer which replaces the offending import statement with an empty string:

```typescript
// create a fixer for this failure
const replacement = new Lint.Replacement(node.getStart(), node.getWidth(), "");
const fix = new Lint.Fix("no-imports", [replacement]);

this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING, fix));
```

[0]: https://github.com/palantir/tslint/releases
[1]: https://github.com/palantir/tslint/blob/master/CHANGELOG.md
[2]: {{ site.baseurl }}/rules/array-type
[3]: {{ site.baseurl }}/rules/arrow-parens
[4]: {{ site.baseurl }}/rules/no-unused-variable
[5]: {{ site.baseurl }}/rules/no-var-keyword
[6]: {{ site.baseurl }}/rules/ordered-imports
[7]: {{ site.baseurl }}/rules/semicolon
[8]: {{ site.baseurl }}/rules/trailing-comma
[9]: https://raw.githubusercontent.com/palantir/tslint/master/src/configs/recommended.ts
[10]: {{ site.baseurl }}/usage/third-party-tools/
[11]: https://github.com/palantir/tslint/pull/1720
[12]: https://github.com/palantir/tslint/pull/1717/files#diff-6e3940e8ec3d59837c4435f32975ed2c
[13]: {{ site.baseurl }}/rules/adjacent-overload-signatures
[14]: {{ site.baseurl }}/rules/array-type
[15]: {{ site.baseurl }}/rules/arrow-parens
[16]: {{ site.baseurl }}/rules/max-classes-per-file
[17]: {{ site.baseurl }}/rules/no-unsafe-finally
[18]: {{ site.baseurl }}/rules/object-literal-key-quotes
[19]: {{ site.baseurl }}/rules/object-literal-shorthand
[20]: {{ site.baseurl }}/rules/only-arrow-functions
[21]: {{ site.baseurl }}/rules/ordered-imports
[22]: {{ site.baseurl }}/rules/prefer-for-of
[23]: {{ site.baseurl }}/rules/completed-docs
[24]: {{ site.baseurl }}/rules/cyclomatic-complexity
[25]: {{ site.baseurl }}/develop/custom-rules
15 changes: 15 additions & 0 deletions docs/develop/custom-rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ Then, if using the CLI, provide the directory that contains this rule as an opti

Finally, add a line to your [`tslint.json` config file][0] for each of your custom rules.

---

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:

```typescript
// create a fixer for this failure
const replacement = new Lint.Replacement(node.getStart(), node.getWidth(), "");
const fix = new Lint.Fix("no-imports", [replacement]);

// create a failure at the current position
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING, fix));
```
---
Final notes:

- Core rules cannot be overwritten with a custom implementation.
Expand Down

0 comments on commit 3c585bf

Please sign in to comment.