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

Commit

Permalink
Merge branch 'master' into use-default-type-parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson committed May 22, 2017
2 parents 5633795 + ce4dbfe commit 61364b6
Show file tree
Hide file tree
Showing 613 changed files with 13,450 additions and 10,363 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
*.fix text eol=lf
/test/rules/linebreak-style/**/CRLF/*.lint text eol=crlf
/test/rules/linebreak-style/**/LF/*.fix text eol=crlf
/test/rules/jsdoc-format/**/jsdoc-windows.ts.lint text eol=crlf
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"editor.wrappingIndent": "none",

// The folders to exclude when doing a full text search in the workspace.
"files.exclude": {
"search.exclude": {
".git": true,
".tscache": true,
"bower_components": true,
Expand Down
60 changes: 59 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,64 @@
Change Log
===

v5.2.0
---

- [rule-change] [`no-console`](https://palantir.github.io/tslint/rules/no-console/) bans all console methods when no methods are specified (#2610)
- [new-rule] [`no-object-literal-type-assertion`](https://palantir.github.io/tslint/rules/no-object-literal-type-assertion/) (#2580)
- [new-rule] [`no-irregular-whitespace`](https://palantir.github.io/tslint/rules/no-irregular-whitespace/) (#2487)
- [new-rule] [`prefer-switch`](https://palantir.github.io/tslint/rules/prefer-switch/) (#2331)
- [new-rule] [`number-literal-format`](https://palantir.github.io/tslint/rules/number-literal-format/) (#2526)
- [new-rule] [`deprecation`](https://palantir.github.io/tslint/rules/deprecation/) (#2395)
- [new-rule] [`no-unnecessary-type-assertion`](https://palantir.github.io/tslint/rules/no-unnecessary-type-assertion/) (#2519)
- [new-fixer] [`interface-over-type-literal`](https://palantir.github.io/tslint/rules/interface-over-type-literal/) (#2617)
- [new-fixer] [`callable-types`](https://palantir.github.io/tslint/rules/callable-types/) (#2552)
- [new-fixer] [`no-string-literal`](https://palantir.github.io/tslint/rules/no-string-literal/) (#2495)
- [new-fixer] [`no-internal-module`](https://palantir.github.io/tslint/rules/no-internal-module/) (#2517)
- [new-rule-option] [`align`](https://palantir.github.io/tslint/rules/align/) rule added `members` option, which checks alignment of methods and properties of classes, objects, interfaces, type literals and object destructuring (#2387)
- [new-rule-option] [`align`](https://palantir.github.io/tslint/rules/align/) rule added `elements` option, which checks alignment of elements in array literals, array destructuring and tuple types (#2387)
- [new-rule-option] [`trailing-comma`](https://palantir.github.io/tslint/rules/trailing-comma/) adds more granular options to specify trailing commas for arrays, objects, functions, type literals, imports, and exports (#2538)
- [api] Deprecate `ScopeAwareRuleWalker` and `BlockScopeAwareRuleWalker`. (#2561)
- [develop] added support for [error templates in rule tests](https://palantir.github.io/tslint/develop/testing-rules/) (#2481)
- [bugfix] Fixes "Severity for rule not found" error (#2516)
- [bugfix] [`no-unused-expression`](https://palantir.github.io/tslint/rules/no-unused-expression/): allow `void(0)` in addition to `void 0` and `void` in expression and statement position (#2645)
- [bugfix] [`align`](https://palantir.github.io/tslint/rules/align/): fix false positive for files with BOM (#2642)
- [bugfix] [`return-undefined`](https://palantir.github.io/tslint/rules/return-undefined/): Handle contextual types with ambiguous signatures; allow `any`; and handle async functions. (#2576)
- [bugfix] [`semicolon`](https://palantir.github.io/tslint/rules/semicolon/): don't mark semicolon as unnecessary when the next statement is on the same line (#2591)
- [bugfix] [`no-internal-module`](https://palantir.github.io/tslint/rules/no-internal-module/): no more false positives for global augmentation (#2517)
- [bugfix] [`no-unnecessary-qualifier`](https://palantir.github.io/tslint/rules/no-unnecessary-qualifier/): no longer breaks when walking a function that references `arguments` (#2555)
- [bugfix] [`prefer-const`](https://palantir.github.io/tslint/rules/prefer-const/) no longer shows warnings on ambient declarations (#2391)
- [bugfix] [`callable-types`](https://palantir.github.io/tslint/rules/callable-types/): suggest correct fix for interfaces with type arguments (#2552)
- [bugfix] [`quotemark`](https://palantir.github.io/tslint/rules/quotemark/): fix regression with jsx attributes (#2605)
- [bugfix] [`adjacent-overload-signatures`](https://palantir.github.io/tslint/rules/adjacent-overload-signatures/) handles functions ending in semicolon (#2412)
- [bugfix] [`object-literal-key-quotes`](https://palantir.github.io/tslint/rules/object-literal-key-quotes/): correctly stringify numbers when fixing (#2515)
- [bugfix] [`object-literal-key-quotes`](https://palantir.github.io/tslint/rules/object-literal-key-quotes/): does no longer require quotes for property names containing digits (#2515)
- [enhancement] Failures in extended config files now indicate which file (#2588)
- [enhancement] [`align`](https://palantir.github.io/tslint/rules/align/): Don't report 'statements are not aligned' for empty statements (#2653)
- [enhancement] [`class-name`](https://palantir.github.io/tslint/rules/class-name/) now also checks class expressions (#2553)
- [enhancement] `optionExamples`: Allow to use an options array directly instead of a string representation. (#2527)
- [enhancement] `rulesDirectory` can now be resolved with Nodes resolve logic, if the directory contains an `index.js` (#2163) (#2358)
- [enhancement] [`no-unused-expression`](https://palantir.github.io/tslint/rules/no-unused-expression/): narrow error location for comma separated expressions and conditional expressions (#2645)
- [enhancement] [`no-string-literal`](https://palantir.github.io/tslint/rules/no-string-literal/) now handles escaped strings (#2495)
- [enhancement] [`no-unnecessary-callback-wrapper`](https://palantir.github.io/tslint/rules/no-unnecessary-callback-wrapper/): Allow `x => x(x)` (#2524)
- [enhancement] [`no-var-keyword`](https://palantir.github.io/tslint/rules/no-var-keyword/): Allow global var declarations (#2513)

Thanks to our contributors!
- Andy Hanson
- Alex Eagle
- Donald Pipowitch
- Klaus Meinhardt
- Gord P
- Andy
- Quentin
- Mitchell Wills
- Vito
- CSchulz
- Josh Goldberg
- Brian Olore
- Manuel Lopez
- James Clark

v5.1.0
---

Expand Down Expand Up @@ -60,7 +118,7 @@ v5.0.0
+ public applyWithProgram(srcFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] {
+ return this.applyWithWalker(new Walker(srcFile, this.getOptions(), program));
```

- N.B. If you are refactoring your custom rules, consider [these performance tips for writing custom rules](https://palantir.github.io/tslint/develop/custom-rules/performance.html).

- Removed `createFix`. Replacements should be passed directly into addFailure. (#2403)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ If we don't have all the rules you're looking for, you can either write your own
- [codelyzer](https://github.com/mgechev/codelyzer) - A set of tslint rules for static code analysis of Angular TypeScript projects
- [vrsource-tslint-rules](https://github.com/vrsource/vrsource-tslint-rules)
- [tslint-immutable](https://github.com/jonaskello/tslint-immutable) - TSLint rules to disable mutation in TypeScript
- [tslint-consistent-codestyle](https://github.com/ajafff/tslint-consistent-codestyle) - TSLint rules to enforce consistent code style in TypeScript

Development
-----------
Expand Down
2 changes: 2 additions & 0 deletions docs/develop/testing-rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ The following part can be any [version range](https://github.com/npm/node-semver
* You can use this system to test rules outside of the TSLint build! Use the `tslint --test path/to/dir` command to test your own custom rules.
The directory you pass should contain a `tslint.json` file and `.ts.lint` files. You can try this out on the TSLint rule test cases, for example, `tslint --test path/to/tslint-code/test/rules/quotemark/single`.

* To test rules that need type information, you can simply add a `tsconfig.json` with the desired configuration next to `tslint.json`.

* Lint failures sometimes span over multiple lines. To handle this case, don't specify a message until the end of the error. For example:

```
Expand Down
4 changes: 4 additions & 0 deletions docs/usage/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Options:
-h, --help display detailed help
-i, --init generate a tslint.json config file in the current working directory
-o, --out output file
--outputAbsolutePaths whether or not outputted file paths are absolute
-p, --project tsconfig.json file
-r, --rules-dir rules directory
-s, --formatters-dir formatters directory
Expand Down Expand Up @@ -89,6 +90,9 @@ tslint accepts the following command-line options:
A filename to output the results to. By default, tslint outputs to
stdout, which is usually the console where you're running it from.
--outputAbsolutePaths:
Indicates whether or not outputted file paths are absolute paths.
-r, --rules-dir:
An additional rules directory, for user-created rules.
tslint will always check its default rules directory, in
Expand Down
28 changes: 28 additions & 0 deletions docs/usage/library/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ yarn add tslint typescript

Please ensure that the TypeScript source files compile correctly _before_ running the linter.

#### TypeScript

This code will need to be transpiled to JavaScript to run under Node.js.

```ts
import { Linter, Configuration } from "tslint";
import * as fs from "fs";

const fileName = "Specify input file name";
const configurationFilename = "Specify configuration file name";
const options = {
fix: false,
formatter: "json",
rulesDirectory: "customRules/",
formattersDirectory: "customFormatters/"
Expand All @@ -36,3 +41,26 @@ const configuration = Configuration.findConfiguration(configurationFilename, fil
linter.lint(fileName, fileContents, configuration);
const result = linter.getResult();
```

#### JavaScript (ES5)

This code will run directly under Node.js, including if it's called from the command line.

```js
"use strict";
var tslint = require("tslint");
var fs = require("fs");
var fileName = "Specify input file name";
var configurationFilename = "Specify configuration file name";
var options = {
fix: false,
formatter: "json",
rulesDirectory: "customRules/",
formattersDirectory: "customFormatters/"
};
var fileContents = fs.readFileSync(fileName, "utf8");
var linter = new tslint.Linter(options);
var configuration = tslint.Configuration.findConfiguration(configurationFilename, fileName).results;
linter.lint(fileName, fileContents, configuration);
var result = linter.getResult();
```
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tslint",
"version": "5.1.0",
"version": "5.2.0",
"description": "An extensible static analysis linter for the TypeScript language",
"bin": {
"tslint": "./bin/tslint"
Expand All @@ -26,8 +26,8 @@
"compile:scripts": "tsc -p scripts",
"compile:test": "tsc -p test",
"lint": "npm-run-all -p lint:global lint:from-bin",
"lint:global": "tslint --project test/tsconfig.json --format stylish # test includes 'src' too",
"lint:from-bin": "node bin/tslint --project test/tsconfig.json --format stylish",
"lint:global": "tslint --project test/tsconfig.json --format stylish --type-check # test includes 'src' too",
"lint:from-bin": "node bin/tslint --project test/tsconfig.json --format stylish --type-check",
"test": "npm-run-all test:pre -p test:mocha test:rules",
"test:pre": "cd ./test/config && npm install",
"test:mocha": "mocha --reporter spec --colors \"build/test/**/*Tests.js\"",
Expand All @@ -39,34 +39,33 @@
"babel-code-frame": "^6.22.0",
"colors": "^1.1.2",
"diff": "^3.2.0",
"findup-sync": "~0.3.0",
"glob": "^7.1.1",
"optimist": "~0.6.0",
"resolve": "^1.3.2",
"semver": "^5.3.0",
"tsutils": "^1.6.0"
"tslib": "^1.6.0",
"tsutils": "^2.0.0"
},
"peerDependencies": {
"typescript": ">=2.1.0 || >=2.1.0-dev || >=2.2.0-dev || >=2.3.0-dev || >=2.4.0-dev"
},
"devDependencies": {
"@types/babel-code-frame": "^6.20.0",
"@types/chai": "~3.4.34",
"@types/colors": "^0.6.33",
"@types/chai": "^3.5.0",
"@types/colors": "^1.1.3",
"@types/diff": "0.0.31",
"@types/findup-sync": "^0.3.29",
"@types/github": "^0.0.0",
"@types/glob": "^5.0.30",
"@types/js-yaml": "^3.5.29",
"@types/mocha": "^2.2.35",
"@types/node": "^6.0.56",
"@types/node": "^7.0.16",
"@types/optimist": "0.0.29",
"@types/resolve": "0.0.4",
"@types/semver": "^5.3.30",
"chai": "^3.5.0",
"github": "^8.1.1",
"js-yaml": "^3.7.0",
"json-stringify-pretty-compact": "^1.0.3",
"memory-streams": "^0.1.2",
"mocha": "^3.2.0",
"npm-run-all": "^3.1.0",
"nyc": "^10.2.0",
Expand Down
5 changes: 3 additions & 2 deletions scripts/buildDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,11 @@ function buildDocumentationDataFile(documentation: IDocumentation, metadataJson:
* Generates Jekyll data from any item's metadata.
*/
function generateJekyllData(metadata: any, layout: string, type: string, name: string): any {
return Object.assign({}, metadata, {
return {
...metadata,
layout,
title: `${type}: ${name}`,
});
};
}

/**
Expand Down
5 changes: 0 additions & 5 deletions scripts/custom-typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// Node v4+ support Object.assign
interface ObjectConstructor {
assign(target: any, ...sources: any[]): any;
}

declare module "json-stringify-pretty-compact" {
function stringify(x: any): string;
export = stringify;
Expand Down
36 changes: 34 additions & 2 deletions scripts/generate-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import * as fs from "fs";
import * as os from "os";
import * as path from "path";

import { camelize } from "../lib/utils";

const github = new GitHubApi({
host: "api.github.com",
protocol: "https",
Expand Down Expand Up @@ -89,7 +91,7 @@ github.repos.getLatestRelease(repoInfo).then((value) => {
if (fieldMatch) {
commit.fields.push({
tag: fieldMatch[1],
text: line + " (#" + commit.pushRequestNum + ")",
text: addLinks(line) + " (#" + commit.pushRequestNum + ")",
});
}
}
Expand All @@ -105,7 +107,9 @@ github.repos.getLatestRelease(repoInfo).then((value) => {
for (const commit of commits) {
if (commit.fields.length > 0) {
for (const field of commit.fields) {
entries.push(field);
if (field.tag !== "[no-log]") {
entries.push(field);
}
}
} else {
noFields.push(commit.title);
Expand Down Expand Up @@ -135,6 +139,34 @@ github.repos.getLatestRelease(repoInfo).then((value) => {
console.log("Error:" + error);
});

const cache = new Map<string, boolean>();

function isRule(ruleName: string): boolean {
let result = cache.get(ruleName);
if (result === undefined) {
result = fs.existsSync(`./src/rules/${camelize(ruleName)}Rule.ts`);
cache.set(ruleName, result);
}
return result;
}

/** Replace rule names with links to the docs website */
function addLinks(text: string): string {
let result = "";
let lastIndex = 0;
// match everything that looks like a rule name and is enclosed in backticks
const regex = /`([a-z][-a-z]*[a-z])+`/g;
let match = regex.exec(text);
while (match !== null) {
if (isRule(match[1])) {
result += text.slice(lastIndex, match.index) + `[${match[0]}](https://palantir.github.io/tslint/rules/${match[1]}/)`;
lastIndex = regex.lastIndex;
}
match = regex.exec(text);
}
return result + text.slice(lastIndex);
}

interface IField {
tag: string;
text: string;
Expand Down
Loading

0 comments on commit 61364b6

Please sign in to comment.