Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/Microsoft/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Goldberg committed Dec 6, 2017
2 parents 051abda + 42e11d6 commit d662964
Show file tree
Hide file tree
Showing 136 changed files with 1,118 additions and 1,830 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
"editor.insertSpaces": true,
"editor.tabSize": 4,
"tslint.nodePath": "./node_modules/tslint/bin/tslint",
"typescript.tsdk": "./node_modules/typescript/lib",
"files.trimTrailingWhitespace": true
}
73 changes: 33 additions & 40 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,29 +200,19 @@ module.exports = function(grunt) {

ts: {
default: {
src: [
'./src/**/*.ts{,x}'
],
outDir: 'dist/src',
options: {
module: 'commonjs',
target: 'es5',
declaration: true,
failOnTypeErrors: true,
jsx: 'react'
tsconfig: {
tsconfig: './tsconfig.json',
passThrough: true,
updateFiles: true,
overwriteFiles: true,
}
},
'test-data': {
src: [
'./test-data/**/*.ts{,x}'
],
outDir: 'dist/test-data',
options: {
module: 'commonjs',
target: 'es5',
declaration: false,
failOnTypeErrors: true,
jsx: 'react'
tsconfig: {
tsconfig: './tsconfig.testdata.json',
passThrough: true,
updateFiles: true,
overwriteFiles: true
}
}
},
Expand All @@ -248,6 +238,7 @@ module.exports = function(grunt) {
let tslintJson = grunt.file.readJSON("tslint.json", { encoding: 'UTF-8' });
tslintJson.rules['no-multiline-string'] = false;
tslintJson.rules['quotemark'] = false;
tslintJson.rules['object-literal-key-quotes'] = false;
tslintJson.rules['max-func-body-length'] = false;
return tslintJson;
})()
Expand Down Expand Up @@ -321,26 +312,28 @@ module.exports = function(grunt) {

var tslintConfig = grunt.file.readJSON('tslint.json', { encoding: 'UTF-8' });
var rulesToSkip = {
'no-unused-variable': true,
'no-unexternalized-strings': true,
'object-literal-key-quotes': true,
'no-relative-imports': true,
'no-empty-line-after-opening-brace': true,
'no-duplicate-key': true,
'align': true,
'comment-format': true,
'interface-name': true,
'max-file-line-count': true,
'member-ordering': true,
'no-inferrable-types': true,
'only-arrow-functions': true,
'ordered-imports': true,
'typedef-whitespace': true,
'array-type': true,
'completed-docs': true,
'cyclomatic-complexity': true,
'file-header': true,
'max-classes-per-file': true
'ban-types': true,
'match-default-export-name': true, // requires type checking
'newline-before-return': true, // kind of a silly rule
'no-non-null-assertion': true, // in fact we prefer the opposite rule
'prefer-template': true, // rule does not handle multi-line strings nicely
'return-undefined': true, // requires type checking
'no-unused-variable': true, // requires type checking
'no-unexternalized-strings': true, // this is a VS Code specific rule
'no-relative-imports': true, // this project uses relative imports
'no-empty-line-after-opening-brace': true, // too strict
'align': true, // no need
'comment-format': true, // no need
'interface-name': true, // no need
'max-file-line-count': true, // no need
'member-ordering': true, // too strict
'no-inferrable-types': true, // we prefer the opposite
'ordered-imports': true, // too difficult to turn on
'typedef-whitespace': true, // too strict
'completed-docs': true, // no need
'cyclomatic-complexity': true, // too strict
'file-header': true, // no need
'max-classes-per-file': true // no need
};
var errors = [];
getAllRuleNames().forEach(function(ruleName) {
Expand Down
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ tslint-microsoft-contrib

A set of [TSLint](https://github.com/palantir/tslint) rules used on some Microsoft projects.

Version 4.0.1 (Stable)
Version 5.0.1 (Stable)
-------------
The project has been in use for several years on multiple projects. Please report any bugs or false positives you might find!

See our [Release Notes](https://github.com/Microsoft/tslint-microsoft-contrib/wiki/Release-Notes) to find the latest new rules.

Version 4.0.2 (In-Development)
Version 5.0.2 (In-Development)
-------------
The [Latest Development Version](https://github.com/Microsoft/tslint-microsoft-contrib/tree/releases) is available online.
To use the nightly build set your npm version to `git://github.com/Microsoft/tslint-microsoft-contrib.git#releases`

Installation
------------
Expand All @@ -25,18 +26,19 @@ Installation

Alternately, you can download the files directly from GitHub:

* [4.0.0](https://github.com/Microsoft/tslint-microsoft-contrib/tree/npm-4.0.0)
* [2.0.14](https://github.com/Microsoft/tslint-microsoft-contrib/tree/npm-2.0.14)
* [5.0.1](https://github.com/Microsoft/tslint-microsoft-contrib/tree/npm-5.0.1)
* [4.0.1](https://github.com/Microsoft/tslint-microsoft-contrib/tree/npm-4.0.1)

#### TSLint and corresponding tslint-microsoft-contrib version

| TSLint version | tslint-microsoft-contrib version |
| --- | --- |
| **>= 4.x** | 4.x |
| **>= 5.x** | 5.x (supporting TypeScript 2.3.x)|
| **>= 4.x** | 4.x (supporting TypeScript 2.1.x) |
| **>= 3.2.x** | 2.x |
| **3.1.x** | unsupported |
| **3.0.x** | unsupported |
| **2.x** | 1.x |
| **3.1.x** | unsupported |
| **3.0.x** | unsupported |
| **2.x** | 1.x |

Configuration
-------------
Expand All @@ -61,7 +63,7 @@ The tslint.json file does not change format when using this package. Just add ou

##### Which Rules Should I Turn On?
There certainly are a lot of options! Here are some links to get you started.
* Easiest Option - Our recommended ruleset is here: [recommended_ruleset.js](recommended_ruleset.js). You can also easily extend the ruleset by adding `"extends": "tslint-microsoft-contrib"` to your configuration. Please note, the default rules require the `--type-check` and `--project` TSLint options.
* Easiest Option - Our recommended ruleset is here: [recommended_ruleset.js](recommended_ruleset.js). You can also easily extend the ruleset by adding `"extends": "tslint-microsoft-contrib"` to your configuration. Please note, the default rules require the `--type-check` and `--project` TSLint options. Also, please note that adding a rule to the recommended ruleset is considered backwards compatible. If you reply on version ranges in your dependencies then you may find that new rules being added to the product create violations and fail your build.
* A nice blog post on the MSDN secure development blog can be found here: [Automating Secure Development Lifecycle Checks in TypeScript with TSLint](https://blogs.msdn.microsoft.com/secdevblog/2016/05/11/automating-secure-development-lifecycle-checks-in-typescript-with-tslint/)
* A wiki briefly describing the SDL and related rules is here: [TSLint and the Microsoft Security Development Lifecycle](https://github.com/Microsoft/tslint-microsoft-contrib/wiki/TSLint-and-the-Microsoft-Security-Development-Lifecycle)
* And our configuration file with all options is available here: [tslint.json](tslint.json)
Expand Down Expand Up @@ -114,7 +116,6 @@ Rule Name | Description | Since
`no-relative-imports` | Do not use relative paths when importing external modules or ES6 import declarations. The advantages of removing all relative paths from imports is that 1) the import name will be consistent across all files and subdirectories so searching for usages is much easier. 2) Moving source files to different folders will not require you to edit your import statements. 3) It will be possible to copy and paste import lines between files regardless of the file location. And 4) version control diffs will be simplified by having overall fewer edits to the import lines.| 2.0.5
`no-reserved-keywords` | Do not use reserved keywords as names of local variables, fields, functions, or other identifiers. Since version 2.0.9 this rule accepts a parameter called allow-quoted-properties. If true, interface properties in quotes will be ignored. This can be a useful way to avoid verbose suppress-warning comments for generated d.ts files.| 0.0.1, 2.0.9
`no-single-line-block-comment` | Avoid single line block comments and use single line comments instead. Block comments do not nest properly and have no advantages over normal single-line comments| 2.0.10
`no-sparse-arrays` | Do not use sparse arrays. Sparse arrays contain empty slots, most frequently due to multiple commas being used in an array literal. Based on the [ESLint no-sparse-arrays](http://eslint.org/docs/rules/no-sparse-arrays) rule | 1.0
`no-stateless-class` | A stateless class represents a failure in the object oriented design of the system. A class without state is better modeled as a module or given some state. A stateless class is defined as a class with only static members and no parent class.| 2.0.4
`no-string-based-set-immediate` | Do not use the version of setImmediate that accepts code as a string argument. However, it is acceptable to use the version of setImmediate where a direct reference to a function is provided as the callback argument | 0.0.1
`no-string-based-set-interval` | Do not use the version of setInterval that accepts code as a string argument. However, it is acceptable to use the version of setInterval where a direct reference to a function is provided as the callback argument | 0.0.1
Expand All @@ -128,9 +129,8 @@ Rule Name | Description | Since
`no-unnecessary-override` | Do not write a method that only calls super() on the parent method with the same arguments. You can safely remove methods like this and Javascript will correctly dispatch the method to the parent object. | 2.0.4
`no-unnecessary-semicolons` | Remove unnecessary semicolons | 0.0.1
`no-unsupported-browser-code` | Avoid writing browser-specific code for unsupported browser versions. Browser versions are specified in the rule configuration options, eg: `[true, [ "IE 11", "Firefox > 40", "Chrome >= 45" ] ]`. Browser-specific blocks of code can then be designated with a single-line comment, like so: `// Browser specific: IE 10`, or with a jsdoc like this: `@browserspecific chrome 40`. | 2.0.10
`no-unused-imports` | Deprecated - This rule is now covered by TSLint's no-unused-variables rule. However, it can still be useful to enable this rule and pair it with the fix-no-unused-imports formatter. | 0.0.1
`no-useless-files` | Avoid keeping files around that only contain commented out code, are completely empty, or only contain whitespace characters | 4.0.2
`no-var-self` | Do not use `var self = this`; instead, manage scope with arrow functions/lambdas. Self variables are a common practice in JavaScript but can be avoided in TypeScript. By default the rule bans any assignments of the `this` reference. If you want to enforce a naming convention or allow some usages then configure the rule with a regex. By default the rule is configured with `(?!)` which matches nothing. You can pass `^self$` to allow variables named self or pass `^(?!self$)` to allow anything other than self, for example| 2.0.8
`no-var-self` | Deprecated - This rule can be replaced with TSLint's no-this-assignment. Do not use `var self = this`; instead, manage scope with arrow functions/lambdas. Self variables are a common practice in JavaScript but can be avoided in TypeScript. By default the rule bans any assignments of the `this` reference. If you want to enforce a naming convention or allow some usages then configure the rule with a regex. By default the rule is configured with `(?!)` which matches nothing. You can pass `^self$` to allow variables named self or pass `^(?!self$)` to allow anything other than self, for example| 2.0.8
`no-with-statement` | Do not use with statements. Assign the item to a new variable instead | 0.0.1
`non-literal-require` | Detect `require()` function calls for something that is not a string literal. For security reasons, it is best to only require() string literals. Otherwise, it is perhaps possible for an attacker to somehow change the value and download arbitrary Javascript into your page. | 2.0.14
`possible-timing-attack` | Avoid timing attacks by not making direct string comparisons to sensitive data. Do not compare against variables named password, secret, api, apiKey, token, auth, pass, or hash. For more info see [Using Node.js Event Loop for Timing Attacks](https://snyk.io/blog/node-js-timing-attack-ccc-ctf/) | 2.0.11
Expand Down Expand Up @@ -158,7 +158,6 @@ Rule Name | Description | Since
`react-tsx-curly-spacing` | Consistently use spaces around the brace characters of JSX attributes.You can either allow or bad spaces between the braces and the values they enclose. <br/><br/>One of the two following options are required:<br/>* "always" enforces a space inside of curly braces (default)<br/>* "never" disallows spaces inside of curly braces<br/><br/>By default, braces spanning multiple lines are not allowed with either setting. If you want to allow them you can specify an additional allowMultiline property with the value false. <br/><br/>Examples: <br/>* "react-tsx-curly-spacing": [true, "always"]<br/>* "react-tsx-curly-spacing": [true, "never"]<br/>* "react-tsx-curly-spacing": [true, "never", {"allowMultiline": false}]<br/><br/>References<br/>* [eslint-plugin-react jsx-curly-spacing rule](https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-spacing.md) | 2.0.14
`react-unused-props-and-state` | Remove unneeded properties defined in React Props and State interfaces. Any interface named Props or State is defined as a React interface. All fields in these interfaces must be referenced. This rule can be configured with regexes to match custom Props and State interface names. <br/><br/>Example for including all interfaces ending with Props or State: <br/>*[ true, { 'props-interface-regex': 'Props$', 'state-interface-regex': 'State$' } ]* | 2.0.10
`underscore-consistent-invocation` | Enforce a consistent usage of the _ functions. By default, invoking underscore functions should begin with wrapping a variable in an underscore instance: `_(list).map(...)`. An alternative is to prefer using the static methods on the _ variable: `_.map(list, ...)`. The rule accepts single parameter called 'style' which can be the value 'static' or 'instance': `[true, { "style": "static" }]`| 2.0.10
`use-isnan` | Deprecated - This rule is now part of the base TSLint product. Ensures that you use the isNaN() function to check for NaN references instead of a comparison to the NaN constant. Similar to the [use-isnan ESLint rule](http://eslint.org/docs/rules/use-isnan).| 1.0
`use-named-parameter` | Do not reference the arguments object by numerical index; instead, use a named parameter. This rule is similar to JSLint's [Use a named parameter](https://jslinterrors.com/use-a-named-parameter) rule. | 0.0.3
`valid-typeof` | Ensures that the results of typeof are compared against a valid string. This rule aims to prevent errors from likely typos by ensuring that when the result of a typeof operation is compared against a string, that the string is a valid value. Similar to the [valid-typeof ESLint rule](http://eslint.org/docs/rules/valid-typeof).| 1.0

Expand All @@ -170,7 +169,6 @@ These formatters assume that you use the UTF-8 file encoding. They may not work
Formatter Name | Description | Since
:---------- | :------------ | -------------
`fix-no-require-imports`| This formatter automatically converts imports from the require syntax to the ES6 syntax. For example `import Utils = require('Utils');` becomes `import {Utils} from 'Utils';`. However, be warned that the fix assumes that your imported module exports the correct thing. If anything goes wrong with your exports then you'll get a compiler failure saying there is no default export. | 2.0.8
`fix-no-unused-imports` | This formatter automatically fixes any unused imports found by the no-unused-imports rule. | 2.0.8
`fix-no-var-keyword` | This formatter automatically converts var variable declarations into let variable declarations found by the no-var-keyword rule. | 2.0.8

Development
Expand Down
Loading

0 comments on commit d662964

Please sign in to comment.