diff --git a/_data/develop_sidebar.json b/_data/develop_sidebar.json index d083ccfa97b..55f8f020e34 100644 --- a/_data/develop_sidebar.json +++ b/_data/develop_sidebar.json @@ -12,7 +12,7 @@ }, { "title": "Custom Rules - Migrating to AbstractWalker", - "url": "/custom-rules/performance/migration.html" + "url": "/custom-rules/migration.html" }, { "title": "Custom Formatters", diff --git a/_data/formatters.json b/_data/formatters.json index 1617406a14b..55b689c0f51 100644 --- a/_data/formatters.json +++ b/_data/formatters.json @@ -22,7 +22,7 @@ { "formatterName": "json", "description": "Formats errors as simple JSON.", - "sample": "\n[\n {\n \"endPosition\": {\n \"character\": 13,\n \"line\": 0,\n \"position\": 13\n },\n \"failure\": \"Missing semicolon\",\n \"fix\": {\n \"innerRuleName\": \"semicolon\",\n \"innerReplacements\": [\n {\n \"innerStart\": 13,\n \"innerLength\": 0,\n \"innerText\": \";\"\n }\n ]\n },\n \"name\": \"myFile.ts\",\n \"ruleName\": \"semicolon\",\n \"startPosition\": {\n \"character\": 13,\n \"line\": 0,\n \"position\": 13\n }\n }\n]", + "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" }, { @@ -36,13 +36,13 @@ "formatterName": "pmd", "description": "Formats errors as through they were PMD output.", "descriptionDetails": "Imitates the XML output from PMD. All errors have a priority of 1.", - "sample": "\n\n \n \n \n", + "sample": "\n\n \n \n \n", "consumer": "machine" }, { "formatterName": "prose", "description": "The default formatter which outputs simple human-readable messages.", - "sample": "myFile.ts[1, 14]: Missing semicolon", + "sample": "ERROR: myFile.ts[1, 14]: Missing semicolon", "consumer": "human" }, { @@ -52,11 +52,18 @@ "sample": "\nmyFile.ts\n1:14 semicolon Missing semicolon", "consumer": "human" }, + { + "formatterName": "tap", + "description": "Formats output as TAP stream.", + "descriptionDetails": "Provides error messages output in TAP13 format which can be consumed by any TAP formatter.", + "sample": "\nTAP version 13\n1..1\nnot ok 1 - Some error\n ---\n message: Variable has any type\n severity: error\n data:\n ruleName: no-any\n fileName: test-file.ts\n line: 10\n character: 10\n failureString: Some error\n rawLines: Some raw output\n ...", + "consumer": "machine" + }, { "formatterName": "verbose", "description": "The human-readable formatter which includes the rule name in messages.", "descriptionDetails": "The output is the same as the prose formatter with the rule name included", - "sample": "(semicolon) myFile.ts[1, 14]: Missing semicolon", + "sample": "ERROR: (semicolon) myFile.ts[1, 14]: Missing semicolon", "consumer": "human" }, { diff --git a/_data/rules.json b/_data/rules.json index 2c104d6be78..6646f9999b4 100644 --- a/_data/rules.json +++ b/_data/rules.json @@ -173,7 +173,7 @@ "ruleName": "comment-format", "description": "Enforces formatting rules for single-line comments.", "rationale": "Helps maintain a consistent, readable style in your codebase.", - "optionsDescription": "\nThree arguments may be optionally provided:\n\n* `\"check-space\"` requires that all single-line comments must begin with a space, as in `// comment`\n * note that comments starting with `///` are also allowed, for things such as `///`\n* `\"check-lowercase\"` requires that the first non-whitespace character of a comment must be lowercase, if applicable.\n* `\"check-uppercase\"` requires that the first non-whitespace character of a comment must be uppercase, if applicable.\n\nExceptions to `\"check-lowercase\"` or `\"check-uppercase\"` can be managed with object that may be passed as last argument.\n\nOne of two options can be provided in this object:\n \n * `\"ignore-words\"` - array of strings - words that will be ignored at the beginning of the comment.\n * `\"ignore-pattern\"` - string - RegExp pattern that will be ignored at the beginning of the comment.\n", + "optionsDescription": "\nThree arguments may be optionally provided:\n\n* `\"check-space\"` requires that all single-line comments must begin with a space, as in `// comment`\n * note that comments starting with `///` are also allowed, for things such as `///`\n* `\"check-lowercase\"` requires that the first non-whitespace character of a comment must be lowercase, if applicable.\n* `\"check-uppercase\"` requires that the first non-whitespace character of a comment must be uppercase, if applicable.\n\nExceptions to `\"check-lowercase\"` or `\"check-uppercase\"` can be managed with object that may be passed as last argument.\n\nOne of two options can be provided in this object:\n\n * `\"ignore-words\"` - array of strings - words that will be ignored at the beginning of the comment.\n * `\"ignore-pattern\"` - string - RegExp pattern that will be ignored at the beginning of the comment.\n", "options": { "type": "array", "items": { @@ -218,7 +218,7 @@ { "ruleName": "completed-docs", "description": "Enforces documentation for important items be filled out.", - "optionsDescription": "\n`true` to enable for [\"classes\", \"functions\", \"methods\", \"properties\"],\nor an array with each item in one of two formats:\n\n* `string` to enable for that type\n* `object` keying types to when their documentation is required:\n * `\"methods\"` and `\"properties may specify:\n * `\"privacies\":\n * `\"all\"`\n * `\"private\"`\n * `\"protected\"`\n * `\"public\"`\n * `\"locations:\n * `\"all\"`\n * `\"instance\"`\n * `\"static\"`\n * All other types may specify `\"visibilities\"`:\n * `\"all\"`\n * `\"exported\"`\n * `\"internal\"`\n\nTypes that may be enabled are:\n\n * `\"classes\"`\n * `\"enums\"`\n * `\"functions\"`\n * `\"interfaces\"`\n * `\"methods\"`\n * `\"namespaces\"`\n * `\"properties\"`\n * `\"types\"`\n * `\"variables\"`", + "optionsDescription": "\n`true` to enable for [\"classes\", \"functions\", \"methods\", \"properties\"],\nor an array with each item in one of two formats:\n\n* `string` to enable for that type\n* `object` keying types to when their documentation is required:\n * `\"methods\"` and `\"properties\"` may specify:\n * `\"privacies\"`:\n * `\"all\"`\n * `\"private\"`\n * `\"protected\"`\n * `\"public\"`\n * `\"locations\"`:\n * `\"all\"`\n * `\"instance\"`\n * `\"static\"`\n * All other types may specify `\"visibilities\"`:\n * `\"all\"`\n * `\"exported\"`\n * `\"internal\"`\n\nTypes that may be enabled are:\n\n * `\"classes\"`\n * `\"enums\"`\n * `\"functions\"`\n * `\"interfaces\"`\n * `\"methods\"`\n * `\"namespaces\"`\n * `\"properties\"`\n * `\"types\"`\n * `\"variables\"`", "options": { "type": "array", "items": { @@ -387,10 +387,19 @@ "ruleName": "curly", "description": "Enforces braces for `if`/`for`/`do`/`while` statements.", "rationale": "\n```ts\nif (foo === bar)\n foo++;\n bar++;\n```\n\nIn the code above, the author almost certainly meant for both `foo++` and `bar++`\nto be executed only if `foo === bar`. However, he forgot braces and `bar++` will be executed\nno matter what. This rule could prevent such a mistake.", - "optionsDescription": "Not configurable.", - "options": null, + "optionsDescription": "\nThe rule may be set to `true`, or to the following:\n\n* `\"ignore-same-line\"` skips checking braces for control-flow statements\nthat are on one line and start on the same line as their control-flow keyword\n ", + "options": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "ignore-same-line" + ] + } + }, "optionExamples": [ - "true" + "true", + "[true, \"ignore-same-line\"]" ], "type": "functionality", "typescriptOnly": false @@ -421,6 +430,7 @@ "optionExamples": [ "true" ], + "hasFix": true, "type": "maintainability", "typescriptOnly": false }, @@ -570,7 +580,8 @@ "[true, \"CRLF\"]" ], "type": "maintainability", - "typescriptOnly": false + "typescriptOnly": false, + "hasFix": true }, { "ruleName": "match-default-export-name", @@ -611,7 +622,7 @@ { "ruleName": "max-file-line-count", "description": "Requires files to remain under a certain number of lines", - "rationale": "\nLimiting the number of lines allowed in a file allows files to remain small, \nsingle purpose, and maintainable.", + "rationale": "\nLimiting the number of lines allowed in a file allows files to remain small,\nsingle purpose, and maintainable.", "optionsDescription": "An integer indicating the maximum number of lines.", "options": { "type": "number", @@ -642,21 +653,23 @@ "ruleName": "member-access", "description": "Requires explicit visibility declarations for class members.", "rationale": "Explicit visibility declarations can make code more readable and accessible for those new to TS.", - "optionsDescription": "\nTwo arguments may be optionally provided:\n\n* `\"check-accessor\"` enforces explicit visibility on get/set accessors (can only be public)\n* `\"check-constructor\"` enforces explicit visibility on constructors (can only be public)", + "optionsDescription": "\nThese arguments may be optionally provided:\n\n* `\"no-public\"` forbids public accessibility to be specified, because this is the default.\n* `\"check-accessor\"` enforces explicit visibility on get/set accessors\n* `\"check-constructor\"` enforces explicit visibility on constructors", "options": { "type": "array", "items": { "type": "string", "enum": [ + "no-public", "check-accessor", "check-constructor" ] }, "minLength": 0, - "maxLength": 2 + "maxLength": 3 }, "optionExamples": [ "true", + "[true, \"no-public\"]", "[true, \"check-accessor\"]" ], "type": "typescript", @@ -715,7 +728,7 @@ "\n[true, {\n \"order\": [\n {\n \"name\": \"static non-private\",\n \"kinds\": [\n \"public-static-field\",\n \"protected-static-field\",\n \"public-static-method\",\n \"protected-static-method\"\n ]\n },\n \"constructor\"\n ]\n}]" ], "type": "typescript", - "typescriptOnly": true + "typescriptOnly": false }, { "ruleName": "newline-before-return", @@ -1183,6 +1196,14 @@ "type": "style", "typescriptOnly": true }, + { + "ruleName": "no-reference-import", + "description": "Don't if you import \"foo\" anyway.", + "optionsDescription": "Not configurable.", + "options": null, + "type": "style", + "typescriptOnly": true + }, { "ruleName": "no-reference", "description": "Disallows `/// ` imports (use ES6-style imports instead).", @@ -1257,7 +1278,7 @@ "ruleName": "no-trailing-whitespace", "description": "Disallows trailing whitespace at the end of a line.", "rationale": "Keeps version control diffs clean as it prevents accidental whitespace from being committed.", - "optionsDescription": "\nPossible settings are:\n\n* `\"ignore-comments\"`: Allows trailing whitespace in comments.\n* `\"ignore-jsdoc\"`: Allows trailing whitespace only in JSDoc comments.", + "optionsDescription": "\nPossible settings are:\n\n* `\"ignore-template-strings\"`: Allows trailing whitespace in template strings.\n* `\"ignore-comments\"`: Allows trailing whitespace in comments.\n* `\"ignore-jsdoc\"`: Allows trailing whitespace only in JSDoc comments.", "hasFix": true, "options": { "type": "array", @@ -1265,7 +1286,8 @@ "type": "string", "enum": [ "ignore-comments", - "ignore-jsdoc" + "ignore-jsdoc", + "ignore-template-strings" ] } }, @@ -1289,6 +1311,17 @@ "typescriptOnly": true, "requiresTypeInfo": true }, + { + "ruleName": "no-unnecessary-callback-wrapper", + "description": "\nReplaces `x => f(x)` with just `f`.\nTo catch more cases, enable `only-arrow-functions` and `arrow-return-shorthand` too.", + "optionsDescription": "Not configurable.", + "options": null, + "optionExamples": [ + "true" + ], + "type": "style", + "typescriptOnly": false + }, { "ruleName": "no-unnecessary-initializer", "description": "Forbids a 'var'/'let' statement or destructuring initializer to be initialized to 'undefined'.", @@ -1316,7 +1349,7 @@ }, { "ruleName": "no-unsafe-any", - "description": "\nWarns when using an expression of type 'any' in an unsafe way.\nType casts and tests are allowed.\nExpressions that work on all values (such as '\"\" + x') are allowed.", + "description": "\nWarns when using an expression of type 'any' in a dynamic way.\nUses are only allowed if they would work for `{} | null | undefined`.\nType casts and tests are allowed.\nExpressions that work on all values (such as `\"\" + x`) are allowed.", "optionsDescription": "Not configurable.", "options": null, "optionExamples": [ @@ -1344,7 +1377,7 @@ "description": "Disallows unused expression statements.", "descriptionDetails": "\nUnused expressions are expression statements which are not assignments or function calls\n(and thus usually no-ops).", "rationale": "\nDetects potential errors where an assignment or function call was intended.", - "optionsDescription": "\nOne argument may be optionally provided:\n\n* `allow-fast-null-checks` allows to use logical operators to perform fast null checks and perform\nmethod or function calls for side effects (e.g. `e && e.preventDefault()`).", + "optionsDescription": "\nTwo arguments may be optionally provided:\n\n* `allow-fast-null-checks` allows to use logical operators to perform fast null checks and perform\nmethod or function calls for side effects (e.g. `e && e.preventDefault()`).\n* `allow-new` allows 'new' expressions for side effects (e.g. `new ModifyGlobalState();`.\n* `allow-tagged-template` allows tagged templates for side effects (e.g. `this.add\\`foo\\`;`.", "options": { "type": "array", "items": { @@ -1363,24 +1396,11 @@ "type": "functionality", "typescriptOnly": false }, - { - "ruleName": "no-unused-new", - "description": "Disallows unused 'new' expression statements.", - "descriptionDetails": "\nUnused 'new' expressions indicate that a constructor is being invoked solely for its side effects.", - "rationale": "\nDetects constructs such as `new SomeClass()`, where a constructor is used solely for its side effects, which is considered\npoor style.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality", - "typescriptOnly": false - }, { "ruleName": "no-unused-variable", "description": "Disallows unused imports, variables, functions and\n private class members. Similar to tsc's --noUnusedParameters and --noUnusedLocals\n options, but does not interrupt code compilation.", "hasFix": true, - "optionsDescription": "\nThree optional arguments may be optionally provided:\n\n* `\"check-parameters\"` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n* `\"react\"` relaxes the rule for a namespace import named `React`\n(from either the module `\"react\"` or `\"react/addons\"`).\nAny JSX expression in the file will be treated as a usage of `React`\n(because it expands to `React.createElement `).\n* `{\"ignore-pattern\": \"pattern\"}` where pattern is a case-sensitive regexp.\nVariable names that match the pattern will be ignored.", + "optionsDescription": "\nThree optional arguments may be optionally provided:\n\n* `\"check-parameters\"` disallows unused function and constructor parameters.\n * NOTE: this option is experimental and does not work with classes\n that use abstract method declarations, among other things.\n* `{\"ignore-pattern\": \"pattern\"}` where pattern is a case-sensitive regexp.\nVariable names that match the pattern will be ignored.", "options": { "type": "array", "items": { @@ -1615,13 +1635,25 @@ }, { "ruleName": "prefer-const", - "description": "Requires that variable declarations use `const` instead of `let` if possible.", + "description": "Requires that variable declarations use `const` instead of `let` and `var` if possible.", "descriptionDetails": "\nIf a variable is only assigned to once when it is declared, it should be declared using 'const'", "hasFix": true, - "optionsDescription": "Not configurable.", - "options": null, + "optionsDescription": "\nAn optional object containing the property \"destructuring\" with two possible values:\n\n* \"any\" (default) - If any variable in destructuring can be const, this rule warns for those variables.\n* \"all\" - Only warns if all variables in destructuring can be const.", + "options": { + "type": "object", + "properties": { + "destructuring": { + "type": "string", + "enum": [ + "all", + "any" + ] + } + } + }, "optionExamples": [ - "true" + "true", + "[true, {\"destructuring\": \"all\"}]" ], "type": "maintainability", "typescriptOnly": false @@ -1668,6 +1700,23 @@ "type": "style", "typescriptOnly": false }, + { + "ruleName": "prefer-template", + "description": "Prefer a template expression over string literal concatenation.", + "optionsDescription": "\nIf `allow-single-concat` is specified, then a single concatenation (`x + y`) is allowed, but not more (`x + y + z`).", + "options": { + "type": "string", + "enum": [ + "allow-single-concat" + ] + }, + "optionExamples": [ + "true", + "[true, \"allow-single-concat\"]" + ], + "type": "style", + "typescriptOnly": false + }, { "ruleName": "promise-function-async", "description": "Requires any function or method that returns a promise to be marked async.", @@ -1685,7 +1734,7 @@ "ruleName": "quotemark", "description": "Requires single or double quotes for string literals.", "hasFix": true, - "optionsDescription": "\nFive arguments may be optionally provided:\n\n* `\"single\"` enforces single quotes.\n* `\"double\"` enforces double quotes.\n* `\"jsx-single\"` enforces single quotes for JSX attributes.\n* `\"jsx-double\"` enforces double quotes for JSX attributes.\n* `\"avoid-escape\"` allows you to use the \"other\" quotemark in cases where escaping would normally be required.\nFor example, `[true, \"double\", \"avoid-escape\"]` would not report a failure on the string literal `'Hello \"World\"'`.", + "optionsDescription": "\nFive arguments may be optionally provided:\n\n* `\"single\"` enforces single quotes.\n* `\"double\"` enforces double quotes.\n* `\"jsx-single\"` enforces single quotes for JSX attributes.\n* `\"jsx-double\"` enforces double quotes for JSX attributes.\n* `\"avoid-escape\"` allows you to use the \"other\" quotemark in cases where escaping would normally be required.\nFor example, `[true, \"double\", \"avoid-escape\"]` would not report a failure on the string literal\n`'Hello \"World\"'`.", "options": { "type": "array", "items": { @@ -1732,6 +1781,18 @@ "typescriptOnly": false, "requiresTypeInfo": true }, + { + "ruleName": "return-undefined", + "description": "Prefer `return;` in void functions and `return undefined;` in value-returning functions.", + "optionsDescription": "Not configurable.", + "options": null, + "optionExamples": [ + "true" + ], + "type": "style", + "typescriptOnly": false, + "requiresTypeInfo": true + }, { "ruleName": "semicolon", "description": "Enforces consistent semicolon usage at the end of every statement.", @@ -1870,9 +1931,9 @@ }, { "ruleName": "trailing-comma", - "description": "\nRequires or disallows trailing commas in array and object literals, destructuring assignments, function and tuple typings,\nnamed imports and function parameters.", + "description": "\nRequires or disallows trailing commas in array and object literals, destructuring assignments, function typings,\nnamed imports and exports and function parameters.", "hasFix": true, - "optionsDescription": "\nOne argument which is an object with the keys `multiline` and `singleline`.\nBoth should be set to either `\"always\"` or `\"never\"`.\n\n* `\"multiline\"` checks multi-line object literals.\n* `\"singleline\"` checks single-line object literals.\n\nA array is considered \"multiline\" if its closing bracket is on a line\nafter the last array element. The same general logic is followed for\nobject literals, function and tuple typings, named import statements\nand function parameters.", + "optionsDescription": "\nOne argument which is an object with the keys `multiline` and `singleline`.\nBoth should be set to either `\"always\"` or `\"never\"`.\n\n* `\"multiline\"` checks multi-line object literals.\n* `\"singleline\"` checks single-line object literals.\n\nA array is considered \"multiline\" if its closing bracket is on a line\nafter the last array element. The same general logic is followed for\nobject literals, function typings, named import statements\nand function parameters.", "options": { "type": "object", "properties": { @@ -1926,7 +1987,7 @@ { "ruleName": "typedef", "description": "Requires type definitions to exist.", - "optionsDescription": "\nSeven arguments may be optionally provided:\n\n* `\"call-signature\"` checks return type of functions.\n* `\"arrow-call-signature\"` checks return type of arrow functions.\n* `\"parameter\"` checks type specifier of function parameters for non-arrow functions.\n* `\"arrow-parameter\"` checks type specifier of function parameters for arrow functions.\n* `\"property-declaration\"` checks return types of interface properties.\n* `\"variable-declaration\"` checks non-binding variable declarations.\n* `\"member-variable-declaration\"` checks member variable declarations.\n* `\"object-destructuring\"` checks object destructuring declarations.\n* `\"array-destructuring\"` checks array destructuring declarations.", + "optionsDescription": "\nSeveral arguments may be optionally provided:\n\n* `\"call-signature\"` checks return type of functions.\n* `\"arrow-call-signature\"` checks return type of arrow functions.\n* `\"parameter\"` checks type specifier of function parameters for non-arrow functions.\n* `\"arrow-parameter\"` checks type specifier of function parameters for arrow functions.\n* `\"property-declaration\"` checks return types of interface properties.\n* `\"variable-declaration\"` checks non-binding variable declarations.\n* `\"member-variable-declaration\"` checks member variable declarations.\n* `\"object-destructuring\"` checks object destructuring declarations.\n* `\"array-destructuring\"` checks array destructuring declarations.", "options": { "type": "array", "items": { @@ -2098,7 +2159,7 @@ { "ruleName": "variable-name", "description": "Checks variable names for various errors.", - "optionsDescription": "\nFive arguments may be optionally provided:\n\n* `\"check-format\"`: allows only camelCased or UPPER_CASED variable names\n * `\"allow-leading-underscore\"` allows underscores at the beginning (only has an effect if \"check-format\" specified)\n * `\"allow-trailing-underscore\"` allows underscores at the end. (only has an effect if \"check-format\" specified)\n * `\"allow-pascal-case\"` allows PascalCase in addition to camelCase.\n* `\"ban-keywords\"`: disallows the use of certain TypeScript keywords (`any`, `Number`, `number`, `String`,\n`string`, `Boolean`, `boolean`, `undefined`) as variable or parameter names.", + "optionsDescription": "\nFive arguments may be optionally provided:\n\n* `\"check-format\"`: allows only camelCased or UPPER_CASED variable names\n * `\"allow-leading-underscore\"` allows underscores at the beginning (only has an effect if \"check-format\" specified)\n * `\"allow-trailing-underscore\"` allows underscores at the end. (only has an effect if \"check-format\" specified)\n * `\"allow-pascal-case\"` allows PascalCase in addition to camelCase.\n * `\"allow-snake-case\"` allows snake_case in addition to camelCase.\n* `\"ban-keywords\"`: disallows the use of certain TypeScript keywords as variable or parameter names.\n * These are: `any`, `Number`, `number`, `String`, `string`, `Boolean`, `boolean`, `Undefined`, `undefined`", "options": { "type": "array", "items": { @@ -2108,6 +2169,7 @@ "allow-leading-underscore", "allow-trailing-underscore", "allow-pascal-case", + "allow-snake-case", "ban-keywords" ] }, diff --git a/develop/custom-rules/performance.md b/develop/custom-rules/performance.md index 51c4d6aba1a..e546039d26b 100644 --- a/develop/custom-rules/performance.md +++ b/develop/custom-rules/performance.md @@ -1,12 +1,5 @@ ## Performance tips -### Don't call the LanguageService repeatedly -The LanguageService is designed to serve editors. By design it does as little work to serve requests as possible. -For most requests no cache is used. - -Let's say you need all usages of a variable. The LanguageService needs to check the whole AST subtree in which the variable is in scope. -Doing that once is barely noticable. But doing it over and over again, will result in pretty bad performance (looking at you `no-unused-variable`). - ### Use the TypeChecker only when needed The TypeChecker is a really mighty tool, but that comes with a cost. To create a TypeChecker the Program first has to locate, read, parse and bind all SourceFiles referenced. To avoid that cost, try to avoid the TypeChecker where possible. @@ -21,7 +14,7 @@ Some rules work directly on the content of the source file. `max-file-line-count` and `linebreak-style` don't need to walk the AST at all. Other rules define exceptions: `no-consecutive-blank-lines` ignores template strings. -To optimize for the best case, this rule can first look for failures in the source. +To optimize for the best case, this rule can first look for failures in the source. If and only if there are any failures, walk the AST to find the location of all template strings to filter the failures. ### Implement your own walking algorithm @@ -46,7 +39,7 @@ class MyWalker extends Lint.AbstractWalker { ### Don't walk the whole AST if possible __The Spec is your friend:__ -The language spec defines where each statement can occur. If you are interested in `import` statements for example, you only need to search +The language spec defines where each statement can occur. If you are interested in `import` statements for example, you only need to search in `sourceFile.statements` and nested `NamespaceDeclaration`s. __Don't visit AST branches you're not interested in:__ @@ -76,12 +69,12 @@ Instead of stuffing the whole logic in a single closure, consider splitting it u Each function should handle similar kinds of nodes. Don't worry too much about the function call, since V8 eventually inlines the function if possible. -The AST nodes have different properties, therefore they have a different hidden class in V8. A function can only be optimized for a certain +The AST nodes have different properties, therefore they have a different hidden class in V8. A function can only be optimized for a certain amount of different hidden classes. Above that threshold the function will be deoptimized and is never optimized again. ### Pass the optional `sourceFile` parameter There are serveral methods that have an optional parameter `sourceFile`. Don't omit this parameter if you care for performance. -If ommitted, typescript needs to walk up the node's parent chain until it reaches the SourceFile. This *can* be quite costly when done +If ommitted, typescript needs to walk up the node's parent chain until it reaches the SourceFile. This *can* be quite costly when done frequently on deeply nested nodes. Some examples: @@ -106,7 +99,7 @@ declare node: ts.Identifier; node.getText() === node.text; // prefer node.text where available ``` -__Bonus points:__ If you know the width of the node (either from the `text` property or because it is a keyword of known width), +__Bonus points:__ If you know the width of the node (either from the `text` property or because it is a keyword of known width), you can use `node.getEnd() - width` to calculate the node's start. `node.getEnd()` is effectively for free as it only returns the `end` property. This way you avoid the cost of skipping leading trivia. @@ -114,7 +107,7 @@ you can use `node.getEnd() - width` to calculate the node's start. Tail calls are function or method calls at the end of the control flow of a function. It's only a tail call if the return value of that call is directly returned unchanged. Browsers can optimize this pattern for performance. Further optimization is specced in ES2015 as "Proper Tail Calls". -With proper tail calls the browser reuses the stack frame of the current function. When done right this allows for infinite recursion. +With proper tail calls the browser reuses the stack frame of the current function. When done right this allows for infinite recursion. ```ts function foo() { if (condition) diff --git a/develop/testing-rules/index.md b/develop/testing-rules/index.md index a4bcc151850..9e12592c304 100644 --- a/develop/testing-rules/index.md +++ b/develop/testing-rules/index.md @@ -97,6 +97,20 @@ Then, at the bottom of our test file, we specify what full message each shortcut 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. +##### Typescript version requirement ##### + +Sometimes a rule requires a minimum version of the typescript compiler or your test contains syntax that older versions of the typescript parser cannot handle. +When testing with multiple versions of typescript - like `tslint` does in CI - those tests will fail. + +To avoid failing tests, each test file can specify a version requirement for typescript **in the first line**. If you don't specify one, the test will always be executed. + +Example: +``` +[typescript]: >= 2.1.0 +``` + +The syntax should look familiar, because it is basically the shorthand syntax from the chapter above. It needs to start with `[typescript]:`. +The following part can be any [version range](https://github.com/npm/node-semver#ranges). The prerelease suffix will be removed before matching to allow testing with nightly builds. ### Tips & Tricks ### diff --git a/formatters/json/index.html b/formatters/json/index.html index be794e27a62..7b14554cd02 100644 --- a/formatters/json/index.html +++ b/formatters/json/index.html @@ -12,14 +12,9 @@ }, "failure": "Missing semicolon", "fix": { - "innerRuleName": "semicolon", - "innerReplacements": [ - { - "innerStart": 13, - "innerLength": 0, - "innerText": ";" - } - ] + "innerStart": 13, + "innerLength": 0, + "innerText": ";" }, "name": "myFile.ts", "ruleName": "semicolon", diff --git a/formatters/pmd/index.html b/formatters/pmd/index.html index 6ebb32c7f4c..1b7a53b8d21 100644 --- a/formatters/pmd/index.html +++ b/formatters/pmd/index.html @@ -6,7 +6,7 @@ - + consumer: machine diff --git a/formatters/prose/index.html b/formatters/prose/index.html index 054e16dd3dd..f01f4afd6f7 100644 --- a/formatters/prose/index.html +++ b/formatters/prose/index.html @@ -1,7 +1,7 @@ --- formatterName: prose description: The default formatter which outputs simple human-readable messages. -sample: 'myFile.ts[1, 14]: Missing semicolon' +sample: 'ERROR: myFile.ts[1, 14]: Missing semicolon' consumer: human layout: formatter title: 'Formatter: prose' diff --git a/formatters/tap/index.html b/formatters/tap/index.html new file mode 100644 index 00000000000..f93171ff91c --- /dev/null +++ b/formatters/tap/index.html @@ -0,0 +1,24 @@ +--- +formatterName: tap +description: Formats output as TAP stream. +descriptionDetails: Provides error messages output in TAP13 format which can be consumed by any TAP formatter. +sample: |- + + TAP version 13 + 1..1 + not ok 1 - Some error + --- + message: Variable has any type + severity: error + data: + ruleName: no-any + fileName: test-file.ts + line: 10 + character: 10 + failureString: Some error + rawLines: Some raw output + ... +consumer: machine +layout: formatter +title: 'Formatter: tap' +--- \ No newline at end of file diff --git a/formatters/verbose/index.html b/formatters/verbose/index.html index ad2fd1d4c29..5a7de802b60 100644 --- a/formatters/verbose/index.html +++ b/formatters/verbose/index.html @@ -2,7 +2,7 @@ formatterName: verbose description: The human-readable formatter which includes the rule name in messages. descriptionDetails: The output is the same as the prose formatter with the rule name included -sample: '(semicolon) myFile.ts[1, 14]: Missing semicolon' +sample: 'ERROR: (semicolon) myFile.ts[1, 14]: Missing semicolon' consumer: human layout: formatter title: 'Formatter: verbose' diff --git a/rules/comment-format/index.html b/rules/comment-format/index.html index d77781b0008..f99f9e191fe 100644 --- a/rules/comment-format/index.html +++ b/rules/comment-format/index.html @@ -14,7 +14,7 @@ Exceptions to `"check-lowercase"` or `"check-uppercase"` can be managed with object that may be passed as last argument. One of two options can be provided in this object: - + * `"ignore-words"` - array of strings - words that will be ignored at the beginning of the comment. * `"ignore-pattern"` - string - RegExp pattern that will be ignored at the beginning of the comment. options: diff --git a/rules/completed-docs/index.html b/rules/completed-docs/index.html index e8e0669b68a..f989ad46ae5 100644 --- a/rules/completed-docs/index.html +++ b/rules/completed-docs/index.html @@ -8,13 +8,13 @@ * `string` to enable for that type * `object` keying types to when their documentation is required: - * `"methods"` and `"properties may specify: - * `"privacies": + * `"methods"` and `"properties"` may specify: + * `"privacies"`: * `"all"` * `"private"` * `"protected"` * `"public"` - * `"locations: + * `"locations"`: * `"all"` * `"instance"` * `"static"` diff --git a/rules/curly/index.html b/rules/curly/index.html index 5e9075da7fe..3e7f034b663 100644 --- a/rules/curly/index.html +++ b/rules/curly/index.html @@ -12,13 +12,34 @@ In the code above, the author almost certainly meant for both `foo++` and `bar++` to be executed only if `foo === bar`. However, he forgot braces and `bar++` will be executed no matter what. This rule could prevent such a mistake. -optionsDescription: Not configurable. -options: null +optionsDescription: |- + + The rule may be set to `true`, or to the following: + + * `"ignore-same-line"` skips checking braces for control-flow statements + that are on one line and start on the same line as their control-flow keyword + +options: + type: array + items: + type: string + enum: + - ignore-same-line optionExamples: - 'true' + - '[true, "ignore-same-line"]' type: functionality typescriptOnly: false layout: rule title: 'Rule: curly' -optionsJSON: 'null' +optionsJSON: |- + { + "type": "array", + "items": { + "type": "string", + "enum": [ + "ignore-same-line" + ] + } + } --- \ No newline at end of file diff --git a/rules/eofline/index.html b/rules/eofline/index.html index 985298840d8..153db8c1f81 100644 --- a/rules/eofline/index.html +++ b/rules/eofline/index.html @@ -6,6 +6,7 @@ options: null optionExamples: - 'true' +hasFix: true type: maintainability typescriptOnly: false layout: rule diff --git a/rules/linebreak-style/index.html b/rules/linebreak-style/index.html index 363c990858e..06c06f01cfb 100644 --- a/rules/linebreak-style/index.html +++ b/rules/linebreak-style/index.html @@ -17,6 +17,7 @@ - '[true, "CRLF"]' type: maintainability typescriptOnly: false +hasFix: true layout: rule title: 'Rule: linebreak-style' optionsJSON: |- diff --git a/rules/max-file-line-count/index.html b/rules/max-file-line-count/index.html index 88556799827..5efe8a3dac8 100644 --- a/rules/max-file-line-count/index.html +++ b/rules/max-file-line-count/index.html @@ -3,7 +3,7 @@ description: Requires files to remain under a certain number of lines rationale: |- - Limiting the number of lines allowed in a file allows files to remain small, + Limiting the number of lines allowed in a file allows files to remain small, single purpose, and maintainable. optionsDescription: An integer indicating the maximum number of lines. options: diff --git a/rules/member-access/index.html b/rules/member-access/index.html index ae5c4991013..7c04d723818 100644 --- a/rules/member-access/index.html +++ b/rules/member-access/index.html @@ -4,21 +4,24 @@ rationale: Explicit visibility declarations can make code more readable and accessible for those new to TS. optionsDescription: |- - Two arguments may be optionally provided: + These arguments may be optionally provided: - * `"check-accessor"` enforces explicit visibility on get/set accessors (can only be public) - * `"check-constructor"` enforces explicit visibility on constructors (can only be public) + * `"no-public"` forbids public accessibility to be specified, because this is the default. + * `"check-accessor"` enforces explicit visibility on get/set accessors + * `"check-constructor"` enforces explicit visibility on constructors options: type: array items: type: string enum: + - no-public - check-accessor - check-constructor minLength: 0 - maxLength: 2 + maxLength: 3 optionExamples: - 'true' + - '[true, "no-public"]' - '[true, "check-accessor"]' type: typescript typescriptOnly: true @@ -30,11 +33,12 @@ "items": { "type": "string", "enum": [ + "no-public", "check-accessor", "check-constructor" ] }, "minLength": 0, - "maxLength": 2 + "maxLength": 3 } --- \ No newline at end of file diff --git a/rules/member-ordering/index.html b/rules/member-ordering/index.html index 74a763e4d05..cd02391585f 100644 --- a/rules/member-ordering/index.html +++ b/rules/member-ordering/index.html @@ -106,7 +106,7 @@ ] }] type: typescript -typescriptOnly: true +typescriptOnly: false layout: rule title: 'Rule: member-ordering' optionsJSON: |- diff --git a/rules/no-reference-import/index.html b/rules/no-reference-import/index.html new file mode 100644 index 00000000000..6661b0fc33e --- /dev/null +++ b/rules/no-reference-import/index.html @@ -0,0 +1,11 @@ +--- +ruleName: no-reference-import +description: Don't if you import "foo" anyway. +optionsDescription: Not configurable. +options: null +type: style +typescriptOnly: true +layout: rule +title: 'Rule: no-reference-import' +optionsJSON: 'null' +--- \ No newline at end of file diff --git a/rules/no-trailing-whitespace/index.html b/rules/no-trailing-whitespace/index.html index 14694056c2a..5d2bbfae213 100644 --- a/rules/no-trailing-whitespace/index.html +++ b/rules/no-trailing-whitespace/index.html @@ -6,6 +6,7 @@ Possible settings are: + * `"ignore-template-strings"`: Allows trailing whitespace in template strings. * `"ignore-comments"`: Allows trailing whitespace in comments. * `"ignore-jsdoc"`: Allows trailing whitespace only in JSDoc comments. hasFix: true @@ -16,6 +17,7 @@ enum: - ignore-comments - ignore-jsdoc + - ignore-template-strings optionExamples: - 'true' - '[true, "ignore-comments"]' @@ -31,7 +33,8 @@ "type": "string", "enum": [ "ignore-comments", - "ignore-jsdoc" + "ignore-jsdoc", + "ignore-template-strings" ] } } diff --git a/rules/no-unnecessary-callback-wrapper/index.html b/rules/no-unnecessary-callback-wrapper/index.html new file mode 100644 index 00000000000..5ccfbcc8ff6 --- /dev/null +++ b/rules/no-unnecessary-callback-wrapper/index.html @@ -0,0 +1,16 @@ +--- +ruleName: no-unnecessary-callback-wrapper +description: |- + + Replaces `x => f(x)` with just `f`. + To catch more cases, enable `only-arrow-functions` and `arrow-return-shorthand` too. +optionsDescription: Not configurable. +options: null +optionExamples: + - 'true' +type: style +typescriptOnly: false +layout: rule +title: 'Rule: no-unnecessary-callback-wrapper' +optionsJSON: 'null' +--- \ No newline at end of file diff --git a/rules/no-unsafe-any/index.html b/rules/no-unsafe-any/index.html index 7358ffa6ae4..660f30ff526 100644 --- a/rules/no-unsafe-any/index.html +++ b/rules/no-unsafe-any/index.html @@ -2,9 +2,10 @@ ruleName: no-unsafe-any description: |- - Warns when using an expression of type 'any' in an unsafe way. + Warns when using an expression of type 'any' in a dynamic way. + Uses are only allowed if they would work for `{} | null | undefined`. Type casts and tests are allowed. - Expressions that work on all values (such as '"" + x') are allowed. + Expressions that work on all values (such as `"" + x`) are allowed. optionsDescription: Not configurable. options: null optionExamples: diff --git a/rules/no-unused-expression/index.html b/rules/no-unused-expression/index.html index 6856223df77..343f543656e 100644 --- a/rules/no-unused-expression/index.html +++ b/rules/no-unused-expression/index.html @@ -10,10 +10,12 @@ Detects potential errors where an assignment or function call was intended. optionsDescription: |- - One argument may be optionally provided: + Two arguments may be optionally provided: * `allow-fast-null-checks` allows to use logical operators to perform fast null checks and perform method or function calls for side effects (e.g. `e && e.preventDefault()`). + * `allow-new` allows 'new' expressions for side effects (e.g. `new ModifyGlobalState();`. + * `allow-tagged-template` allows tagged templates for side effects (e.g. `this.add\`foo\`;`. options: type: array items: diff --git a/rules/no-unused-variable/index.html b/rules/no-unused-variable/index.html index c7be95430b1..daef2ba4935 100644 --- a/rules/no-unused-variable/index.html +++ b/rules/no-unused-variable/index.html @@ -12,10 +12,6 @@ * `"check-parameters"` disallows unused function and constructor parameters. * NOTE: this option is experimental and does not work with classes that use abstract method declarations, among other things. - * `"react"` relaxes the rule for a namespace import named `React` - (from either the module `"react"` or `"react/addons"`). - Any JSX expression in the file will be treated as a usage of `React` - (because it expands to `React.createElement `). * `{"ignore-pattern": "pattern"}` where pattern is a case-sensitive regexp. Variable names that match the pattern will be ignored. options: diff --git a/rules/prefer-const/index.html b/rules/prefer-const/index.html index 6ff68747269..9e8e985ad3c 100644 --- a/rules/prefer-const/index.html +++ b/rules/prefer-const/index.html @@ -1,17 +1,42 @@ --- ruleName: prefer-const -description: Requires that variable declarations use `const` instead of `let` if possible. +description: Requires that variable declarations use `const` instead of `let` and `var` if possible. descriptionDetails: |- If a variable is only assigned to once when it is declared, it should be declared using 'const' hasFix: true -optionsDescription: Not configurable. -options: null +optionsDescription: |- + + An optional object containing the property "destructuring" with two possible values: + + * "any" (default) - If any variable in destructuring can be const, this rule warns for those variables. + * "all" - Only warns if all variables in destructuring can be const. +options: + type: object + properties: + destructuring: + type: string + enum: + - all + - any optionExamples: - 'true' + - '[true, {"destructuring": "all"}]' type: maintainability typescriptOnly: false layout: rule title: 'Rule: prefer-const' -optionsJSON: 'null' +optionsJSON: |- + { + "type": "object", + "properties": { + "destructuring": { + "type": "string", + "enum": [ + "all", + "any" + ] + } + } + } --- \ No newline at end of file diff --git a/rules/prefer-template/index.html b/rules/prefer-template/index.html new file mode 100644 index 00000000000..0e3bcfda00d --- /dev/null +++ b/rules/prefer-template/index.html @@ -0,0 +1,25 @@ +--- +ruleName: prefer-template +description: Prefer a template expression over string literal concatenation. +optionsDescription: |- + + If `allow-single-concat` is specified, then a single concatenation (`x + y`) is allowed, but not more (`x + y + z`). +options: + type: string + enum: + - allow-single-concat +optionExamples: + - 'true' + - '[true, "allow-single-concat"]' +type: style +typescriptOnly: false +layout: rule +title: 'Rule: prefer-template' +optionsJSON: |- + { + "type": "string", + "enum": [ + "allow-single-concat" + ] + } +--- \ No newline at end of file diff --git a/rules/quotemark/index.html b/rules/quotemark/index.html index c3c295f2d8e..64f0125348e 100644 --- a/rules/quotemark/index.html +++ b/rules/quotemark/index.html @@ -11,7 +11,8 @@ * `"jsx-single"` enforces single quotes for JSX attributes. * `"jsx-double"` enforces double quotes for JSX attributes. * `"avoid-escape"` allows you to use the "other" quotemark in cases where escaping would normally be required. - For example, `[true, "double", "avoid-escape"]` would not report a failure on the string literal `'Hello "World"'`. + For example, `[true, "double", "avoid-escape"]` would not report a failure on the string literal + `'Hello "World"'`. options: type: array items: diff --git a/rules/return-undefined/index.html b/rules/return-undefined/index.html new file mode 100644 index 00000000000..75374b1a1d5 --- /dev/null +++ b/rules/return-undefined/index.html @@ -0,0 +1,14 @@ +--- +ruleName: return-undefined +description: Prefer `return;` in void functions and `return undefined;` in value-returning functions. +optionsDescription: Not configurable. +options: null +optionExamples: + - 'true' +type: style +typescriptOnly: false +requiresTypeInfo: true +layout: rule +title: 'Rule: return-undefined' +optionsJSON: 'null' +--- \ No newline at end of file diff --git a/rules/trailing-comma/index.html b/rules/trailing-comma/index.html index d41f07af51b..d0246d527e9 100644 --- a/rules/trailing-comma/index.html +++ b/rules/trailing-comma/index.html @@ -2,8 +2,8 @@ ruleName: trailing-comma description: |- - Requires or disallows trailing commas in array and object literals, destructuring assignments, function and tuple typings, - named imports and function parameters. + Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, + named imports and exports and function parameters. hasFix: true optionsDescription: |- @@ -15,7 +15,7 @@ A array is considered "multiline" if its closing bracket is on a line after the last array element. The same general logic is followed for - object literals, function and tuple typings, named import statements + object literals, function typings, named import statements and function parameters. options: type: object diff --git a/rules/typedef/index.html b/rules/typedef/index.html index 39d07cc35d8..daba7b17017 100644 --- a/rules/typedef/index.html +++ b/rules/typedef/index.html @@ -3,7 +3,7 @@ description: Requires type definitions to exist. optionsDescription: |- - Seven arguments may be optionally provided: + Several arguments may be optionally provided: * `"call-signature"` checks return type of functions. * `"arrow-call-signature"` checks return type of arrow functions. diff --git a/rules/variable-name/index.html b/rules/variable-name/index.html index 763fcb68233..49201eb8abb 100644 --- a/rules/variable-name/index.html +++ b/rules/variable-name/index.html @@ -9,8 +9,9 @@ * `"allow-leading-underscore"` allows underscores at the beginning (only has an effect if "check-format" specified) * `"allow-trailing-underscore"` allows underscores at the end. (only has an effect if "check-format" specified) * `"allow-pascal-case"` allows PascalCase in addition to camelCase. - * `"ban-keywords"`: disallows the use of certain TypeScript keywords (`any`, `Number`, `number`, `String`, - `string`, `Boolean`, `boolean`, `undefined`) as variable or parameter names. + * `"allow-snake-case"` allows snake_case in addition to camelCase. + * `"ban-keywords"`: disallows the use of certain TypeScript keywords as variable or parameter names. + * These are: `any`, `Number`, `number`, `String`, `string`, `Boolean`, `boolean`, `Undefined`, `undefined` options: type: array items: @@ -20,6 +21,7 @@ - allow-leading-underscore - allow-trailing-underscore - allow-pascal-case + - allow-snake-case - ban-keywords minLength: 0 maxLength: 5 @@ -39,6 +41,7 @@ "allow-leading-underscore", "allow-trailing-underscore", "allow-pascal-case", + "allow-snake-case", "ban-keywords" ] }, diff --git a/usage/cli/index.md b/usage/cli/index.md index 85b5fca9c57..c426be03d08 100644 --- a/usage/cli/index.md +++ b/usage/cli/index.md @@ -36,7 +36,7 @@ Options: -h, --help display detailed help -i, --init generate a tslint.json config file in the current working directory -o, --out output file ---project tsconfig.json file +-p, --project tsconfig.json file -r, --rules-dir rules directory -s, --formatters-dir formatters directory -t, --format output format (prose, json, stylish, verbose, pmd, msbuild, checkstyle, vso, fileslist, codeFrame) [default: "prose"] @@ -115,7 +115,7 @@ tslint accepts the following command-line options: specified directory as the configuration file for the tests. See the full tslint documentation for more details on how this can be used to test custom rules. ---project: +-p, --project: The location of a tsconfig.json file that will be used to determine which files will be linted. diff --git a/usage/third-party-tools/index.md b/usage/third-party-tools/index.md index e11e3125de4..46abc2c4cfa 100644 --- a/usage/third-party-tools/index.md +++ b/usage/third-party-tools/index.md @@ -18,6 +18,7 @@ _Note: Most of these tools are not maintained by TSLint._ * [Webstorm][14] * [mocha-tslint][15] ([Mocha][16]) * [tslint.tmbundle][17] ([TextMate][18]) +* [generator-tslint][19] [0]: https://github.com/palantir/grunt-tslint @@ -39,3 +40,4 @@ _Note: Most of these tools are not maintained by TSLint._ [16]: https://mochajs.org/ [17]: https://github.com/natesilva/tslint.tmbundle [18]: https://macromates.com +[19]: https://github.com/greybax/generator-tslint diff --git a/usage/tslint-json/index.md b/usage/tslint-json/index.md index 0b3e3135ee0..ab9f6a47091 100644 --- a/usage/tslint-json/index.md +++ b/usage/tslint-json/index.md @@ -9,73 +9,54 @@ configure which rules get run. `tslint.json` files can have the following fields specified: -* `extends?: string | string[]`: -A path(s) to another configuration file which to extend. +* `extends?: string | string[]`: +A path or array of paths to other configuration files which are extended by this configuration. This value is handled using node module resolution semantics. For example a value of "tslint-config" would cause TSLint to try and load the main file of a module named "tslint-config" as a configuration file. A value of "./tslint-config", on the other hand, would be treated as a relative path to file. * `rulesDirectory?: string | string[]`: -A path(s) to a directory of [custom rules][2]. This will always be treated as a relative or absolute path. -* `rules?: any`: Pairs of keys and values where each key is a rule name and each value is the configuration for that rule. -If a rule takes no options, you can simply set its value to a boolean, either `true` or `false`, to enable or disable it. -If a rule takes options, you set its value to an array where the first value is a boolean indicating if the rule is enabled and the next values are options handled by the rule. +A path or array of paths to a directories of [custom rules][2]. This will always be treated as a relative or absolute path. +* `rules?: { [name: string]: RuleSetting }`: A map of rule names to their configuration settings. + - Each rule is associated with an object containing: + - `options?: any`: An array of values that are specific to a rule. + - `severity?: "default" | "error" | "warning" | "off"`: Severity level. Level "error" will cause exit code 2. + - A boolean value may be specified instead of the above object, and is equivalent to setting no options with default severity. Not all possible rules are listed here, be sure to [check out the full list][3]. These rules are applied to `.ts` and `.tsx` files. -* `jsRules?: any`: Same format as `rules`. These rules are applied to `.js` and `.jsx` files. +* `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. `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. An example `tslint.json` file might look like this: -```ts +```json { "rulesDirectory": ["path/to/custom/rules/directory/", "another/path/"], "rules": { - "class-name": true, - "comment-format": [true, "check-space"], - "indent": [true, "spaces"], - "no-duplicate-variable": true, - "no-eval": true, - "no-internal-module": true, - "no-trailing-whitespace": true, - "no-var-keyword": true, - "one-line": [true, "check-open-brace", "check-whitespace"], - "quotemark": [true, "double"], - "semicolon": false, - "triple-equals": [true, "allow-null-check"], - "typedef-whitespace": [true, { - "call-signature": "nospace", - "index-signature": "nospace", - "parameter": "nospace", - "property-declaration": "nospace", - "variable-declaration": "nospace" - }], - "variable-name": [true, "ban-keywords"], - "whitespace": [true, - "check-branch", - "check-decl", - "check-operator", - "check-separator", - "check-type" - ] + "max-line-length": { + "options": [120], + }, + "new-parens": true, + "no-arg": true, + "no-bitwise": true, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": false, + "no-console": { + "options": [ + "debug", + "info", + "log", + "time", + "timeEnd", + "trace", + ], + } }, "jsRules": { - "indent": [true, "spaces"], - "no-duplicate-variable": true, - "no-eval": true, - "no-trailing-whitespace": true, - "one-line": [true, "check-open-brace", "check-whitespace"], - "quotemark": [true, "double"], - "semicolon": false, - "triple-equals": [true, "allow-null-check"], - "variable-name": [true, "ban-keywords"], - "whitespace": [true, - "check-branch", - "check-decl", - "check-operator", - "check-separator", - "check-type" - ] + "max-line-length": { + "options": [120], + } } } ```