From 44e1b15203fd76e0e5fe4fb07e3582ee3bfcc4fa Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Thu, 17 Nov 2016 15:09:05 -0500 Subject: [PATCH 1/4] Blog entry for 4.0 --- .gitignore | 1 + docs/_posts/2016-11-17-new-for-4.0.md | 58 +++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 docs/_posts/2016-11-17-new-for-4.0.md diff --git a/.gitignore b/.gitignore index 60b5c5e8d98..7b4feb5fd1c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /build/ /docs/site/ /scripts/*.js +/scripts/*.js.map /lib/ /test/executable/tslint.json node_modules/ diff --git a/docs/_posts/2016-11-17-new-for-4.0.md b/docs/_posts/2016-11-17-new-for-4.0.md new file mode 100644 index 00000000000..e769cdb9886 --- /dev/null +++ b/docs/_posts/2016-11-17-new-for-4.0.md @@ -0,0 +1,58 @@ +--- +layout: post +title: "New for 4.0" +date: 2016-11-17 15:19:00 +--- + +TSLint [4.0][0] has been released! With this release comes a few exciting [changes][1]. 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. Here are the rules we fix right now: + * [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** - Make migrating from JavaScript even easier! Just add a `jsRules` [section][9] to your `tslint.json` file. +* **TypeScript 2.0+ required** - This lets us deprecate/remove rules that are checked by the compiler. +* **API Change** - [Moved and renamed][11] some things to make more sense. +* **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] + +[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 \ No newline at end of file From 43005f47bf91dd01e6bdd4df6cb99a847ce54551 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Thu, 17 Nov 2016 23:52:26 -0500 Subject: [PATCH 2/4] Update 2016-11-17-new-for-4.0.md --- docs/_posts/2016-11-17-new-for-4.0.md | 33 +++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/docs/_posts/2016-11-17-new-for-4.0.md b/docs/_posts/2016-11-17-new-for-4.0.md index e769cdb9886..56f5cab683f 100644 --- a/docs/_posts/2016-11-17-new-for-4.0.md +++ b/docs/_posts/2016-11-17-new-for-4.0.md @@ -1,11 +1,11 @@ --- layout: post -title: "New for 4.0" +title: "TSLint 4.0 Released" date: 2016-11-17 15:19:00 --- -TSLint [4.0][0] has been released! With this release comes a few exciting [changes][1]. 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. Here are the rules we fix right now: +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) @@ -13,9 +13,12 @@ TSLint [4.0][0] has been released! With this release comes a few exciting [chang * [ordered-imports][6] * [semicolon][7] * [trailing-comma][8] -* **Linting `.js` files** - Make migrating from JavaScript even easier! Just add a `jsRules` [section][9] to your `tslint.json` file. -* **TypeScript 2.0+ required** - This lets us deprecate/remove rules that are checked by the compiler. -* **API Change** - [Moved and renamed][11] some things to make more sense. +* **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] @@ -30,6 +33,21 @@ TSLint [4.0][0] has been released! With this release comes a few exciting [chang * **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 @@ -55,4 +73,5 @@ TSLint [4.0][0] has been released! With this release comes a few exciting [chang [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 \ No newline at end of file +[24]: {{ site.baseurl }}/rules/cyclomatic-complexity +[25]: {{ site.baseurl }}/develop/custom-rules From e46f1e41218a33cbee82255c2fe42a5f9e909e84 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Thu, 17 Nov 2016 23:53:34 -0500 Subject: [PATCH 3/4] Update 2016-11-17-new-for-4.0.md --- docs/_posts/2016-11-17-new-for-4.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_posts/2016-11-17-new-for-4.0.md b/docs/_posts/2016-11-17-new-for-4.0.md index 56f5cab683f..454d20bfac7 100644 --- a/docs/_posts/2016-11-17-new-for-4.0.md +++ b/docs/_posts/2016-11-17-new-for-4.0.md @@ -19,7 +19,7 @@ TSLint 4.0 has been released! With this release comes a few exciting [changes][0 * 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]** +* **[Recommended Rules Updated][12]** * [adjacent-overload-signatures][13] * [array-type][14] * [arrow-parens][15] From c9ad9dc2c24657570af0b8884f608ee98f93cd30 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Thu, 17 Nov 2016 23:56:31 -0500 Subject: [PATCH 4/4] Update index.md --- docs/develop/custom-rules/index.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/develop/custom-rules/index.md b/docs/develop/custom-rules/index.md index dad79e04c04..c9d45c7308f 100644 --- a/docs/develop/custom-rules/index.md +++ b/docs/develop/custom-rules/index.md @@ -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.