From ea72c7f31d88d3445ee40964955b375f18ec81d8 Mon Sep 17 00:00:00 2001 From: Ben Coveney Date: Sun, 9 Oct 2016 20:23:16 +0100 Subject: [PATCH 001/111] Documentation for formatters (#1564) Resolves #1378. - Added IFormatterMetadata and populated for each formatter. - Altered BuildDocs.ts script to generate docs for formatters as well as rules. - Added formatter pages to `/docs` site (layout, navigation etc). --- docs/_data/formatters.json | 69 ++++++++++ docs/_includes/header.html | 1 + docs/_layouts/formatter.html | 11 ++ docs/formatters/applyFixes/index.html | 14 ++ docs/formatters/checkstyle/index.html | 18 +++ docs/formatters/filesList/index.html | 8 ++ docs/formatters/index.html | 13 ++ docs/formatters/json/index.html | 36 +++++ docs/formatters/msbuild/index.html | 12 ++ docs/formatters/pmd/index.html | 15 ++ docs/formatters/prose/index.html | 8 ++ docs/formatters/stylish/index.html | 15 ++ docs/formatters/verbose/index.html | 9 ++ docs/formatters/vso/index.html | 12 ++ scripts/buildDocs.ts | 145 ++++++++++++++++---- src/formatters/applyFixesFormatter.ts | 15 ++ src/formatters/checkstyleFormatter.ts | 20 +++ src/formatters/fileslistFormatter.ts | 10 ++ src/formatters/jsonFormatter.ts | 39 ++++++ src/formatters/msbuildFormatter.ts | 15 ++ src/formatters/pmdFormatter.ts | 18 +++ src/formatters/proseFormatter.ts | 10 ++ src/formatters/stylishFormatter.ts | 17 +++ src/formatters/verboseFormatter.ts | 11 ++ src/formatters/vsoFormatter.ts | 15 ++ src/language/formatter/abstractFormatter.ts | 3 +- src/language/formatter/formatter.ts | 29 ++++ 27 files changed, 563 insertions(+), 25 deletions(-) create mode 100644 docs/_data/formatters.json create mode 100644 docs/_layouts/formatter.html create mode 100644 docs/formatters/applyFixes/index.html create mode 100644 docs/formatters/checkstyle/index.html create mode 100644 docs/formatters/filesList/index.html create mode 100644 docs/formatters/index.html create mode 100644 docs/formatters/json/index.html create mode 100644 docs/formatters/msbuild/index.html create mode 100644 docs/formatters/pmd/index.html create mode 100644 docs/formatters/prose/index.html create mode 100644 docs/formatters/stylish/index.html create mode 100644 docs/formatters/verbose/index.html create mode 100644 docs/formatters/vso/index.html diff --git a/docs/_data/formatters.json b/docs/_data/formatters.json new file mode 100644 index 00000000000..83a81e7bf9d --- /dev/null +++ b/docs/_data/formatters.json @@ -0,0 +1,69 @@ +[ + { + "formatterName": "applyFixes", + "description": "Automatically fixes lint failures.", + "descriptionDetails": "\nModifies source files and applies fixes for lint failures where possible. Changes\nshould be tested as not all fixes preserve semantics.", + "sample": "\nAll done. Remember to test the changes, as not all fixes preserve semantics.", + "consumer": "machine" + }, + { + "formatterName": "checkstyle", + "description": "Formats errors as through they were Checkstyle output.", + "descriptionDetails": "\nImitates the XMLLogger from Checkstyle 4.3. All failures have the 'warning' severity.", + "sample": "\n\n\n \n \n \n", + "consumer": "machine" + }, + { + "formatterName": "filesList", + "description": "Lists files containing lint errors.", + "sample": "directory/myFile.ts", + "consumer": "machine" + }, + { + "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]", + "consumer": "machine" + }, + { + "formatterName": "msbuild", + "description": "Formats errors for consumption by msbuild.", + "descriptionDetails": "\nThe output is compatible with both msbuild and Visual Studio. All failures have the\n'warning' severity.", + "sample": "myFile.ts(1,14): warning: Missing semicolon", + "consumer": "machine" + }, + { + "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", + "consumer": "machine" + }, + { + "formatterName": "prose", + "description": "The default formatter which outputs simple human-readable messages.", + "sample": "myFile.ts[1, 14]: Missing semicolon", + "consumer": "human" + }, + { + "formatterName": "stylish", + "description": "Human-readable formatter which creates stylish messages.", + "descriptionDetails": "\nThe output matches that produced by eslint's stylish formatter. Its readability\nenhanced through spacing and colouring", + "sample": "\nmyFile.ts\n1:14 semicolon Missing semicolon", + "consumer": "human" + }, + { + "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", + "consumer": "human" + }, + { + "formatterName": "vso", + "description": "Formats output as VSO/TFS logging commands.", + "descriptionDetails": "\nIntegrates with Visual Studio Online and Team Foundation Server by outputting errors\nas 'warning' logging commands.", + "sample": "##vso[task.logissue type=warning;sourcepath=myFile.ts;linenumber=1;columnnumber=14;code=semicolon;]Missing semicolon", + "consumer": "machine" + } +] \ No newline at end of file diff --git a/docs/_includes/header.html b/docs/_includes/header.html index bc984d1b418..32a83ccfef0 100644 --- a/docs/_includes/header.html +++ b/docs/_includes/header.html @@ -6,6 +6,7 @@ diff --git a/docs/_layouts/formatter.html b/docs/_layouts/formatter.html new file mode 100644 index 00000000000..f230db51c88 --- /dev/null +++ b/docs/_layouts/formatter.html @@ -0,0 +1,11 @@ +--- +layout: page +--- +{{page.description | markdownify}} +{% if page.descriptionDetails %} + {{page.descriptionDetails | markdownify}} +{% endif %} +{% if page.sample %} +
Sample Output
+
{{page.sample | xml_escape | markdownify}}
+{% endif %} diff --git a/docs/formatters/applyFixes/index.html b/docs/formatters/applyFixes/index.html new file mode 100644 index 00000000000..b860632660b --- /dev/null +++ b/docs/formatters/applyFixes/index.html @@ -0,0 +1,14 @@ +--- +formatterName: applyFixes +description: Automatically fixes lint failures. +descriptionDetails: |- + + Modifies source files and applies fixes for lint failures where possible. Changes + should be tested as not all fixes preserve semantics. +sample: |- + + All done. Remember to test the changes, as not all fixes preserve semantics. +consumer: machine +layout: formatter +title: 'Formatter: applyFixes' +--- \ No newline at end of file diff --git a/docs/formatters/checkstyle/index.html b/docs/formatters/checkstyle/index.html new file mode 100644 index 00000000000..227de4fe73e --- /dev/null +++ b/docs/formatters/checkstyle/index.html @@ -0,0 +1,18 @@ +--- +formatterName: checkstyle +description: Formats errors as through they were Checkstyle output. +descriptionDetails: |- + + Imitates the XMLLogger from Checkstyle 4.3. All failures have the 'warning' severity. +sample: |- + + + + + + + +consumer: machine +layout: formatter +title: 'Formatter: checkstyle' +--- \ No newline at end of file diff --git a/docs/formatters/filesList/index.html b/docs/formatters/filesList/index.html new file mode 100644 index 00000000000..355edf42f8a --- /dev/null +++ b/docs/formatters/filesList/index.html @@ -0,0 +1,8 @@ +--- +formatterName: filesList +description: Lists files containing lint errors. +sample: directory/myFile.ts +consumer: machine +layout: formatter +title: 'Formatter: filesList' +--- \ No newline at end of file diff --git a/docs/formatters/index.html b/docs/formatters/index.html new file mode 100644 index 00000000000..a7d085cb007 --- /dev/null +++ b/docs/formatters/index.html @@ -0,0 +1,13 @@ +--- +layout: page +title: Formatters +permalink: /formatters/ +menu: main +order: 2 +--- + \ No newline at end of file diff --git a/docs/formatters/json/index.html b/docs/formatters/json/index.html new file mode 100644 index 00000000000..be794e27a62 --- /dev/null +++ b/docs/formatters/json/index.html @@ -0,0 +1,36 @@ +--- +formatterName: json +description: Formats errors as simple JSON. +sample: |- + + [ + { + "endPosition": { + "character": 13, + "line": 0, + "position": 13 + }, + "failure": "Missing semicolon", + "fix": { + "innerRuleName": "semicolon", + "innerReplacements": [ + { + "innerStart": 13, + "innerLength": 0, + "innerText": ";" + } + ] + }, + "name": "myFile.ts", + "ruleName": "semicolon", + "startPosition": { + "character": 13, + "line": 0, + "position": 13 + } + } + ] +consumer: machine +layout: formatter +title: 'Formatter: json' +--- \ No newline at end of file diff --git a/docs/formatters/msbuild/index.html b/docs/formatters/msbuild/index.html new file mode 100644 index 00000000000..9478c0b2805 --- /dev/null +++ b/docs/formatters/msbuild/index.html @@ -0,0 +1,12 @@ +--- +formatterName: msbuild +description: Formats errors for consumption by msbuild. +descriptionDetails: |- + + The output is compatible with both msbuild and Visual Studio. All failures have the + 'warning' severity. +sample: 'myFile.ts(1,14): warning: Missing semicolon' +consumer: machine +layout: formatter +title: 'Formatter: msbuild' +--- \ No newline at end of file diff --git a/docs/formatters/pmd/index.html b/docs/formatters/pmd/index.html new file mode 100644 index 00000000000..6ebb32c7f4c --- /dev/null +++ b/docs/formatters/pmd/index.html @@ -0,0 +1,15 @@ +--- +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: |- + + + + + + +consumer: machine +layout: formatter +title: 'Formatter: pmd' +--- \ No newline at end of file diff --git a/docs/formatters/prose/index.html b/docs/formatters/prose/index.html new file mode 100644 index 00000000000..054e16dd3dd --- /dev/null +++ b/docs/formatters/prose/index.html @@ -0,0 +1,8 @@ +--- +formatterName: prose +description: The default formatter which outputs simple human-readable messages. +sample: 'myFile.ts[1, 14]: Missing semicolon' +consumer: human +layout: formatter +title: 'Formatter: prose' +--- \ No newline at end of file diff --git a/docs/formatters/stylish/index.html b/docs/formatters/stylish/index.html new file mode 100644 index 00000000000..6bcc4671f9b --- /dev/null +++ b/docs/formatters/stylish/index.html @@ -0,0 +1,15 @@ +--- +formatterName: stylish +description: Human-readable formatter which creates stylish messages. +descriptionDetails: |- + + The output matches that produced by eslint's stylish formatter. Its readability + enhanced through spacing and colouring +sample: |- + + myFile.ts + 1:14 semicolon Missing semicolon +consumer: human +layout: formatter +title: 'Formatter: stylish' +--- \ No newline at end of file diff --git a/docs/formatters/verbose/index.html b/docs/formatters/verbose/index.html new file mode 100644 index 00000000000..ad2fd1d4c29 --- /dev/null +++ b/docs/formatters/verbose/index.html @@ -0,0 +1,9 @@ +--- +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' +consumer: human +layout: formatter +title: 'Formatter: verbose' +--- \ No newline at end of file diff --git a/docs/formatters/vso/index.html b/docs/formatters/vso/index.html new file mode 100644 index 00000000000..33e0e2c1db5 --- /dev/null +++ b/docs/formatters/vso/index.html @@ -0,0 +1,12 @@ +--- +formatterName: vso +description: Formats output as VSO/TFS logging commands. +descriptionDetails: |- + + Integrates with Visual Studio Online and Team Foundation Server by outputting errors + as 'warning' logging commands. +sample: '##vso[task.logissue type=warning;sourcepath=myFile.ts;linenumber=1;columnnumber=14;code=semicolon;]Missing semicolon' +consumer: machine +layout: formatter +title: 'Formatter: vso' +--- \ No newline at end of file diff --git a/scripts/buildDocs.ts b/scripts/buildDocs.ts index 337164c3a5b..17ae7b80fa5 100644 --- a/scripts/buildDocs.ts +++ b/scripts/buildDocs.ts @@ -36,49 +36,146 @@ import * as glob from "glob"; import * as yaml from "js-yaml"; import * as path from "path"; -import {AbstractRule} from "../lib/language/rule/abstractRule"; +import {IFormatterMetadata} from "../lib/language/formatter/formatter"; import {IRuleMetadata} from "../lib/language/rule/rule"; +type Metadata = IRuleMetadata | IFormatterMetadata; +type Documented = { metadata: Metadata }; + +interface IDocumentation { + /** + * File name for the json data file listing. + */ + dataFileName: string; + + /** + * Exported item name from each file. + */ + exportName: string; + + /** + * Pattern matching files to be documented. + */ + globPattern: string; + + /** + * Key of the item's name within the metadata object. + */ + nameMetadataKey: string; + + /** + * Function to generate individual documentation pages. + */ + pageGenerator: (metadata: any) => string; + + /** + * Documentation subdirectory to output to. + */ + subDirectory: string; +} + const DOCS_DIR = "../docs"; -const DOCS_RULE_DIR = path.join(DOCS_DIR, "rules"); -const rulePaths = glob.sync("../lib/rules/*Rule.js"); -const rulesJson: IRuleMetadata[] = []; -for (const rulePath of rulePaths) { +/** + * Documentation definition for rule modules. + */ +const ruleDocumentation: IDocumentation = { + dataFileName: "rules.json", + exportName: "Rule", + globPattern: "../lib/rules/*Rule.js", + nameMetadataKey: "ruleName", + pageGenerator: generateRuleFile, + subDirectory: path.join(DOCS_DIR, "rules"), +}; + +/** + * Documentation definition for formatter modules. + */ +const formatterDocumentation: IDocumentation = { + dataFileName: "formatters.json", + exportName: "Formatter", + globPattern: "../lib/formatters/*Formatter.js", + nameMetadataKey: "formatterName", + pageGenerator: generateFormatterFile, + subDirectory: path.join(DOCS_DIR, "formatters"), +}; + +/** + * Builds complete documentation. + */ +function buildDocumentation(documentation: IDocumentation) { + // Create each module's documentation file. + const paths = glob.sync(documentation.globPattern); + const metadataJson = paths.map((path: string) => { + return buildSingleModuleDocumentation(documentation, path); + }); + + // Create a data file with details of every module. + buildDocumentationDataFile(documentation, metadataJson); +} + +/** + * Produces documentation for a single file/module. + */ +function buildSingleModuleDocumentation(documentation: IDocumentation, modulePath: string): Metadata { + // Load the module. // tslint:disable-next-line:no-var-requires - const ruleModule = require(rulePath); - const Rule = ruleModule.Rule as typeof AbstractRule; - if (Rule != null && Rule.metadata != null) { - const { metadata } = Rule; - const fileData = generateRuleFile(metadata); - const fileDirectory = path.join(DOCS_RULE_DIR, metadata.ruleName); - - // write file for each specific rule + const module = require(modulePath); + const DocumentedItem = module[documentation.exportName] as Documented; + if (DocumentedItem != null && DocumentedItem.metadata != null) { + // Build the module's page. + const { metadata } = DocumentedItem; + const fileData = documentation.pageGenerator(metadata); + + // Ensure a directory exists and write the module's file. + const moduleName = (metadata as any)[documentation.nameMetadataKey]; + const fileDirectory = path.join(documentation.subDirectory, moduleName); if (!fs.existsSync(fileDirectory)) { fs.mkdirSync(fileDirectory); } fs.writeFileSync(path.join(fileDirectory, "index.html"), fileData); - rulesJson.push(metadata); + return metadata; } } -// write overall data file, this is used to generate the index page for the rules -const fileData = JSON.stringify(rulesJson, undefined, 2); -fs.writeFileSync(path.join(DOCS_DIR, "_data", "rules.json"), fileData); +function buildDocumentationDataFile(documentation: IDocumentation, metadataJson: any[]) { + const dataJson = JSON.stringify(metadataJson, undefined, 2); + fs.writeFileSync(path.join(DOCS_DIR, "_data", documentation.dataFileName), dataJson); +} /** - * Based off a rule's metadata, generates a string Jekyll "HTML" file - * that only consists of a YAML front matter block. + * Generates Jekyll data from any item's metadata. */ -function generateRuleFile(metadata: IRuleMetadata) { - const yamlData: any = {}; +function generateJekyllData(metadata: any, type: string, name: string): any { + const jekyllData: any = {}; // TODO: Use Object.assign when Node 0.12 support is dropped (#1181) for (const key of Object.keys(metadata)) { - yamlData[key] = ( metadata)[key]; + jekyllData[key] = ( metadata)[key]; } + jekyllData.layout = type.toLowerCase(); + jekyllData.title = `${type}: ${name}`; + return jekyllData; +} + +/** + * Based off a rule's metadata, generates a Jekyll "HTML" file + * that only consists of a YAML front matter block. + */ +function generateRuleFile(metadata: IRuleMetadata): string { + const yamlData: any = generateJekyllData(metadata, "Rule", metadata.ruleName); yamlData.optionsJSON = JSON.stringify(metadata.options, undefined, 2); - yamlData.layout = "rule"; - yamlData.title = `Rule: ${metadata.ruleName}`; return `---\n${yaml.safeDump(yamlData, {lineWidth: 140})}---`; } + +/** + * Based off a formatter's metadata, generates a Jekyll "HTML" file + * that only consists of a YAML front matter block. + */ +function generateFormatterFile(metadata: IFormatterMetadata): string { + const yamlData: any = generateJekyllData(metadata, "Formatter", metadata.formatterName); + return `---\n${yaml.safeDump(yamlData, {lineWidth: 140})}---`; +} + +buildDocumentation(ruleDocumentation); +buildDocumentation(formatterDocumentation); diff --git a/src/formatters/applyFixesFormatter.ts b/src/formatters/applyFixesFormatter.ts index 036a0a86f64..e012ef40ad4 100644 --- a/src/formatters/applyFixesFormatter.ts +++ b/src/formatters/applyFixesFormatter.ts @@ -1,8 +1,23 @@ import {AbstractFormatter} from "../language/formatter/abstractFormatter"; +import {IFormatterMetadata} from "../language/formatter/formatter"; import {Fix, RuleFailure} from "../language/rule/rule"; +import * as Utils from "../utils"; import * as fs from "fs"; export class Formatter extends AbstractFormatter { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: IFormatterMetadata = { + formatterName: "applyFixes", + description: "Automatically fixes lint failures.", + descriptionDetails: Utils.dedent` + Modifies source files and applies fixes for lint failures where possible. Changes + should be tested as not all fixes preserve semantics.`, + sample: Utils.dedent` + All done. Remember to test the changes, as not all fixes preserve semantics.`, + consumer: "machine", + }; + /* tslint:enable:object-literal-sort-keys */ + public format(failures: RuleFailure[]): string { const files: {[file: string]: boolean} = {}; failures.map(f => files[f.getFileName()] = true); diff --git a/src/formatters/checkstyleFormatter.ts b/src/formatters/checkstyleFormatter.ts index 6a49dd46e4c..3360b409bed 100644 --- a/src/formatters/checkstyleFormatter.ts +++ b/src/formatters/checkstyleFormatter.ts @@ -1,7 +1,27 @@ import {AbstractFormatter} from "../language/formatter/abstractFormatter"; +import {IFormatterMetadata} from "../language/formatter/formatter"; import {RuleFailure} from "../language/rule/rule"; +import * as Utils from "../utils"; + export class Formatter extends AbstractFormatter { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: IFormatterMetadata = { + formatterName: "checkstyle", + description: "Formats errors as through they were Checkstyle output.", + descriptionDetails: Utils.dedent` + Imitates the XMLLogger from Checkstyle 4.3. All failures have the 'warning' severity.`, + sample: Utils.dedent` + + + + + + `, + consumer: "machine", + }; + /* tslint:enable:object-literal-sort-keys */ + public format(failures: RuleFailure[]): string { let output = ''; diff --git a/src/formatters/fileslistFormatter.ts b/src/formatters/fileslistFormatter.ts index 27c26c7a7cf..eb1bb58c3ab 100644 --- a/src/formatters/fileslistFormatter.ts +++ b/src/formatters/fileslistFormatter.ts @@ -16,9 +16,19 @@ */ import {AbstractFormatter} from "../language/formatter/abstractFormatter"; +import {IFormatterMetadata} from "../language/formatter/formatter"; import {RuleFailure} from "../language/rule/rule"; export class Formatter extends AbstractFormatter { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: IFormatterMetadata = { + formatterName: "filesList", + description: "Lists files containing lint errors.", + sample: "directory/myFile.ts", + consumer: "machine", + }; + /* tslint:enable:object-literal-sort-keys */ + public format(failures: RuleFailure[]): string { if (failures.length === 0) { return ""; diff --git a/src/formatters/jsonFormatter.ts b/src/formatters/jsonFormatter.ts index f0114b1a82d..917ffd8a2f5 100644 --- a/src/formatters/jsonFormatter.ts +++ b/src/formatters/jsonFormatter.ts @@ -16,9 +16,48 @@ */ import {AbstractFormatter} from "../language/formatter/abstractFormatter"; +import {IFormatterMetadata} from "../language/formatter/formatter"; import {RuleFailure} from "../language/rule/rule"; +import * as Utils from "../utils"; + export class Formatter extends AbstractFormatter { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: IFormatterMetadata = { + formatterName: "json", + description: "Formats errors as simple JSON.", + sample: Utils.dedent` + [ + { + "endPosition": { + "character": 13, + "line": 0, + "position": 13 + }, + "failure": "Missing semicolon", + "fix": { + "innerRuleName": "semicolon", + "innerReplacements": [ + { + "innerStart": 13, + "innerLength": 0, + "innerText": ";" + } + ] + }, + "name": "myFile.ts", + "ruleName": "semicolon", + "startPosition": { + "character": 13, + "line": 0, + "position": 13 + } + } + ]`, + consumer: "machine", + }; + /* tslint:enable:object-literal-sort-keys */ + public format(failures: RuleFailure[]): string { const failuresJSON = failures.map((failure) => failure.toJson()); return JSON.stringify(failuresJSON); diff --git a/src/formatters/msbuildFormatter.ts b/src/formatters/msbuildFormatter.ts index 2830a2e1a5c..1239093cfd7 100644 --- a/src/formatters/msbuildFormatter.ts +++ b/src/formatters/msbuildFormatter.ts @@ -15,9 +15,24 @@ */ import {AbstractFormatter} from "../language/formatter/abstractFormatter"; +import {IFormatterMetadata} from "../language/formatter/formatter"; import {RuleFailure} from "../language/rule/rule"; +import * as Utils from "../utils"; + export class Formatter extends AbstractFormatter { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: IFormatterMetadata = { + formatterName: "msbuild", + description: "Formats errors for consumption by msbuild.", + descriptionDetails: Utils.dedent` + The output is compatible with both msbuild and Visual Studio. All failures have the + 'warning' severity.`, + sample: "myFile.ts(1,14): warning: Missing semicolon", + consumer: "machine", + }; + /* tslint:enable:object-literal-sort-keys */ + public format(failures: RuleFailure[]): string { const outputLines = failures.map((failure: RuleFailure) => { const fileName = failure.getFileName(); diff --git a/src/formatters/pmdFormatter.ts b/src/formatters/pmdFormatter.ts index 33acda65771..7494e31c642 100644 --- a/src/formatters/pmdFormatter.ts +++ b/src/formatters/pmdFormatter.ts @@ -16,9 +16,27 @@ */ import {AbstractFormatter} from "../language/formatter/abstractFormatter"; +import {IFormatterMetadata} from "../language/formatter/formatter"; import {RuleFailure} from "../language/rule/rule"; +import * as Utils from "../utils"; + export class Formatter extends AbstractFormatter { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: IFormatterMetadata = { + 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: Utils.dedent` + + + + + `, + consumer: "machine", + }; + /* tslint:enable:object-literal-sort-keys */ + public format(failures: RuleFailure[]): string { let output = ""; diff --git a/src/formatters/proseFormatter.ts b/src/formatters/proseFormatter.ts index 132623b0306..1331c9248ab 100644 --- a/src/formatters/proseFormatter.ts +++ b/src/formatters/proseFormatter.ts @@ -16,9 +16,19 @@ */ import {AbstractFormatter} from "../language/formatter/abstractFormatter"; +import {IFormatterMetadata} from "../language/formatter/formatter"; import {RuleFailure} from "../language/rule/rule"; export class Formatter extends AbstractFormatter { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: IFormatterMetadata = { + formatterName: "prose", + description: "The default formatter which outputs simple human-readable messages.", + sample: "myFile.ts[1, 14]: Missing semicolon", + consumer: "human", + }; + /* tslint:enable:object-literal-sort-keys */ + public format(failures: RuleFailure[]): string { if (failures.length === 0) { return ""; diff --git a/src/formatters/stylishFormatter.ts b/src/formatters/stylishFormatter.ts index bb35cf0d7f2..bd65d14e2f1 100644 --- a/src/formatters/stylishFormatter.ts +++ b/src/formatters/stylishFormatter.ts @@ -16,11 +16,28 @@ */ import {AbstractFormatter} from "../language/formatter/abstractFormatter"; +import {IFormatterMetadata} from "../language/formatter/formatter"; import {RuleFailure} from "../language/rule/rule"; import * as colors from "colors"; +import * as Utils from "../utils"; + export class Formatter extends AbstractFormatter { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: IFormatterMetadata = { + formatterName: "stylish", + description: "Human-readable formatter which creates stylish messages.", + descriptionDetails: Utils.dedent` + The output matches that produced by eslint's stylish formatter. Its readability + enhanced through spacing and colouring`, + sample: Utils.dedent` + myFile.ts + 1:14 semicolon Missing semicolon`, + consumer: "human", + }; + /* tslint:enable:object-literal-sort-keys */ + public format(failures: RuleFailure[]): string { if (typeof failures[0] === "undefined") { return "\n"; diff --git a/src/formatters/verboseFormatter.ts b/src/formatters/verboseFormatter.ts index cfa57ddbef1..fad23a9fad0 100644 --- a/src/formatters/verboseFormatter.ts +++ b/src/formatters/verboseFormatter.ts @@ -16,9 +16,20 @@ */ import {AbstractFormatter} from "../language/formatter/abstractFormatter"; +import {IFormatterMetadata} from "../language/formatter/formatter"; import {RuleFailure} from "../language/rule/rule"; export class Formatter extends AbstractFormatter { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: IFormatterMetadata = { + 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", + consumer: "human", + }; + /* tslint:enable:object-literal-sort-keys */ + public format(failures: RuleFailure[]): string { const outputLines = failures.map((failure: RuleFailure) => { const fileName = failure.getFileName(); diff --git a/src/formatters/vsoFormatter.ts b/src/formatters/vsoFormatter.ts index 3692bf6f201..d1dcc6baab3 100644 --- a/src/formatters/vsoFormatter.ts +++ b/src/formatters/vsoFormatter.ts @@ -15,9 +15,24 @@ */ import {AbstractFormatter} from "../language/formatter/abstractFormatter"; +import {IFormatterMetadata} from "../language/formatter/formatter"; import {RuleFailure} from "../language/rule/rule"; +import * as Utils from "../utils"; + export class Formatter extends AbstractFormatter { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: IFormatterMetadata = { + formatterName: "vso", + description: "Formats output as VSO/TFS logging commands.", + descriptionDetails: Utils.dedent` + Integrates with Visual Studio Online and Team Foundation Server by outputting errors + as 'warning' logging commands.`, + sample: "##vso[task.logissue type=warning;sourcepath=myFile.ts;linenumber=1;columnnumber=14;code=semicolon;]Missing semicolon", + consumer: "machine", + }; + /* tslint:enable:object-literal-sort-keys */ + public format(failures: RuleFailure[]): string { const outputLines = failures.map((failure: RuleFailure) => { const fileName = failure.getFileName(); diff --git a/src/language/formatter/abstractFormatter.ts b/src/language/formatter/abstractFormatter.ts index 6294a2c2c23..404f072ec08 100644 --- a/src/language/formatter/abstractFormatter.ts +++ b/src/language/formatter/abstractFormatter.ts @@ -16,8 +16,9 @@ */ import {RuleFailure} from "../rule/rule"; -import {IFormatter} from "./formatter"; +import {IFormatter, IFormatterMetadata} from "./formatter"; export abstract class AbstractFormatter implements IFormatter { + public static metadata: IFormatterMetadata; public abstract format(failures: RuleFailure[]): string; } diff --git a/src/language/formatter/formatter.ts b/src/language/formatter/formatter.ts index 433255ab293..50b4de7c9e0 100644 --- a/src/language/formatter/formatter.ts +++ b/src/language/formatter/formatter.ts @@ -17,6 +17,35 @@ import {RuleFailure} from "../rule/rule"; +export interface IFormatterMetadata { + /** + * The name of the formatter. + */ + formatterName: string; + + /** + * A short, one line description of what the formatter does. + */ + description: string; + + /** + * More elaborate details about the formatter. + */ + descriptionDetails?: string; + + /** + * Sample output from the formatter. + */ + sample: string; + + /** + * Sample output from the formatter. + */ + consumer: ConsumerType; +} + +export type ConsumerType = "human" | "machine"; + export interface IFormatter { format(failures: RuleFailure[]): string; } From 08496c383ff403b93103fed8764a4b0953f9ff8a Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 15:33:11 -0400 Subject: [PATCH 002/111] Run CI builds with node 4.2, 5.7, and 6.1 Resolves #1181 --- appveyor.yml | 7 +++---- circle.yml | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 4d741e89158..345574d588c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,8 @@ environment: matrix: - - nodejs_version: "0.10" - - nodejs_version: "0.12" - nodejs_version: "4.2" - - nodejs_version: "5.0" + - nodejs_version: "5.7" + - nodejs_version: "6.1" install: - ps: Install-Product node $env:nodejs_version @@ -16,4 +15,4 @@ test_script: - grunt --version - grunt -build: off \ No newline at end of file +build: off diff --git a/circle.yml b/circle.yml index 745e2896336..6530894cdfb 100644 --- a/circle.yml +++ b/circle.yml @@ -4,7 +4,7 @@ general: - gh-pages dependencies: pre: - - case $CIRCLE_NODE_INDEX in 0) nvm use 0.10 ;; 1) nvm use 0.12 ;; 2) nvm use 4.2 ;; 3) nvm use 5.5 ;; esac + - case $CIRCLE_NODE_INDEX in 0) nvm use 4.2 ;; 1) nvm use 5.7 ;; 2) nvm use 6.1 ;; esac deployment: npm-latest: # match semver tag (e.g. 3.12.7) From f9272d1f9224714b409fe544c1507cf12982db2b Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 16:01:42 -0400 Subject: [PATCH 003/111] Update typings --- custom-typings/object.d.ts | 4 + scripts/tsconfig.json | 4 + src/tsconfig.json | 6 +- test/tsconfig.json | 6 +- tsd.json | 20 +- typings/colors/colors.d.ts | 18 +- typings/diff/diff.d.ts | 37 +- typings/findup-sync/findup-sync.d.ts | 2 +- typings/glob/glob.d.ts | 4 +- typings/js-yaml/js-yaml.d.ts | 45 +- typings/minimatch/minimatch.d.ts | 6 +- typings/node/node.d.ts | 2695 +++++++++++++--- typings/tsd.d.ts | 10 + .../underscore.string/underscore.string.d.ts | 11 +- typings/underscore/underscore.d.ts | 2872 ++++++++++++++++- 15 files changed, 5087 insertions(+), 653 deletions(-) create mode 100644 custom-typings/object.d.ts create mode 100644 typings/tsd.d.ts diff --git a/custom-typings/object.d.ts b/custom-typings/object.d.ts new file mode 100644 index 00000000000..9788f1bee3c --- /dev/null +++ b/custom-typings/object.d.ts @@ -0,0 +1,4 @@ +// Node v4+ support Object.assign +interface ObjectConstructor { + assign(target: any, ...sources: any[]): any; +} diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index cd7a2427adb..f48ffa18db7 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -12,10 +12,13 @@ "rewriteTsconfig": false }, "filesGlob": [ + "../custom-typings/**/*.d.ts", "../typings/**/*.d.ts", "./*.ts" ], "files": [ + "../custom-typings/object.d.ts", + "../custom-typings/resolve.d.ts", "../typings/colors/colors.d.ts", "../typings/diff/diff.d.ts", "../typings/findup-sync/findup-sync.d.ts", @@ -24,6 +27,7 @@ "../typings/minimatch/minimatch.d.ts", "../typings/node/node.d.ts", "../typings/optimist/optimist.d.ts", + "../typings/tsd.d.ts", "../typings/underscore.string/underscore.string.d.ts", "../typings/underscore/underscore.d.ts", "buildDocs.ts" diff --git a/src/tsconfig.json b/src/tsconfig.json index f22a846b63a..55607a2a7c7 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,5 +1,5 @@ { - "version": "1.6.2", + "version": "1.8.10", "compilerOptions": { "module": "commonjs", "noImplicitAny": true, @@ -22,6 +22,7 @@ "./test/**/*.ts" ], "files": [ + "../custom-typings/object.d.ts", "../custom-typings/resolve.d.ts", "../typings/colors/colors.d.ts", "../typings/diff/diff.d.ts", @@ -31,6 +32,7 @@ "../typings/minimatch/minimatch.d.ts", "../typings/node/node.d.ts", "../typings/optimist/optimist.d.ts", + "../typings/tsd.d.ts", "../typings/underscore.string/underscore.string.d.ts", "../typings/underscore/underscore.d.ts", "configuration.ts", @@ -157,4 +159,4 @@ "test/parse.ts", "test/utils.ts" ] -} \ No newline at end of file +} diff --git a/test/tsconfig.json b/test/tsconfig.json index eb5fa0c86f0..4d8f1f8a7a9 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,5 +1,5 @@ { - "version": "1.6.2", + "version": "1.8.10", "compilerOptions": { "module": "commonjs", "noImplicitAny": true, @@ -20,6 +20,7 @@ "./rule-tester/*.ts" ], "files": [ + "../custom-typings/object.d.ts", "../custom-typings/resolve.d.ts", "../typings/colors/colors.d.ts", "../typings/diff/diff.d.ts", @@ -29,6 +30,7 @@ "../typings/minimatch/minimatch.d.ts", "../typings/node/node.d.ts", "../typings/optimist/optimist.d.ts", + "../typings/tsd.d.ts", "../typings/underscore.string/underscore.string.d.ts", "../typings/underscore/underscore.d.ts", "typings/chai/chai.d.ts", @@ -179,4 +181,4 @@ "rule-tester/testData.ts", "rule-tester/utilsTests.ts" ] -} \ No newline at end of file +} diff --git a/tsd.json b/tsd.json index f3f35ec623c..5e2c7dcdbb9 100644 --- a/tsd.json +++ b/tsd.json @@ -6,34 +6,34 @@ "bundle": "typings/tsd.d.ts", "installed": { "colors/colors.d.ts": { - "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" + "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" }, "diff/diff.d.ts": { - "commit": "78ba6e41543e5ababbd1dda19797601be3c1f304" + "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" }, "findup-sync/findup-sync.d.ts": { - "commit": "98d3168c2c570352a3a7393788e2ec9fbb08ade6" + "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" }, "glob/glob.d.ts": { - "commit": "fb2b3b1e068c9ff7d8f9b0851c08d37d96c95c38" + "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" }, "js-yaml/js-yaml.d.ts": { - "commit": "8ea42cd8bb11863ed6f242d67c502288ebc45a7b" + "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" }, "minimatch/minimatch.d.ts": { - "commit": "98d3168c2c570352a3a7393788e2ec9fbb08ade6" + "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" }, "node/node.d.ts": { - "commit": "98d3168c2c570352a3a7393788e2ec9fbb08ade6" + "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" }, "optimist/optimist.d.ts": { - "commit": "e8f8e7471b8ca92ca417f8c878f64ae4d1067972" + "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" }, "underscore.string/underscore.string.d.ts": { - "commit": "98d3168c2c570352a3a7393788e2ec9fbb08ade6" + "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" }, "underscore/underscore.d.ts": { - "commit": "98d3168c2c570352a3a7393788e2ec9fbb08ade6" + "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" } } } diff --git a/typings/colors/colors.d.ts b/typings/colors/colors.d.ts index 5aa28553a39..50e960c4167 100644 --- a/typings/colors/colors.d.ts +++ b/typings/colors/colors.d.ts @@ -1,12 +1,15 @@ // Type definitions for Colors.js 0.6.0-1 // Project: https://github.com/Marak/colors.js // Definitions by: Bart van der Schoor -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare module "colors" { interface Color { (text: string): string; + strip: Color; + stripColors: Color; + black: Color; red: Color; green: Color; @@ -41,11 +44,17 @@ declare module "colors" { america: Color; trap: Color; random: Color; + zalgo: Color; } - module e { + namespace e { export function setTheme(theme:any): void; + export var enabled: boolean; + + export var strip: Color; + export var stripColors: Color; + export var black: Color; export var red: Color; export var green: Color; @@ -80,12 +89,16 @@ declare module "colors" { export var america: Color; export var trap: Color; export var random: Color; + export var zalgo: Color; } export = e; } interface String { + strip: string; + stripColors: string; + black: string; red: string; green: string; @@ -120,4 +133,5 @@ interface String { america: string; trap: string; random: string; + zalgo: string; } diff --git a/typings/diff/diff.d.ts b/typings/diff/diff.d.ts index f5c2cc48f83..fc4708c2a1f 100644 --- a/typings/diff/diff.d.ts +++ b/typings/diff/diff.d.ts @@ -1,11 +1,12 @@ // Type definitions for diff // Project: https://github.com/kpdecker/jsdiff // Definitions by: vvakame -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module JsDiff { +declare namespace JsDiff { interface IDiffResult { value: string; + count?: number; added?: boolean; removed?: boolean; } @@ -15,6 +16,22 @@ declare module JsDiff { componenets: IDiffResult[]; } + interface IHunk { + oldStart: number; + oldLines: number; + newStart: number; + newLines: number; + lines: string[]; + } + + interface IUniDiff { + oldFileName: string; + newFileName: string; + oldHeader: string; + newHeader: string; + hunks: IHunk[]; + } + class Diff { ignoreWhitespace:boolean; @@ -45,9 +62,21 @@ declare module JsDiff { function diffCss(oldStr:string, newStr:string):IDiffResult[]; - function createPatch(fileName:string, oldStr:string, newStr:string, oldHeader:string, newHeader:string):string; + function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string; + + function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string; + + function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): IUniDiff; + + function applyPatch(oldStr: string, uniDiff: string | IUniDiff | IUniDiff[]): string; + + function applyPatches(uniDiff: IUniDiff[], options: { + loadFile: (index: number, callback: (err: Error, data: string) => void) => void, + patched: (index: number, content: string) => void, + complete: (err?: Error) => void + }): void; - function applyPatch(oldStr:string, uniDiff:string):string; + function parsePatch(diffStr: string, options?: {strict: boolean}): IUniDiff[]; function convertChangesToXML(changes:IDiffResult[]):string; diff --git a/typings/findup-sync/findup-sync.d.ts b/typings/findup-sync/findup-sync.d.ts index b7bf674e231..71ff2672cdc 100644 --- a/typings/findup-sync/findup-sync.d.ts +++ b/typings/findup-sync/findup-sync.d.ts @@ -1,7 +1,7 @@ // Type definitions for findup-sync v0.3.0 // Project: https://github.com/cowboy/node-findup-sync // Definitions by: Bart van der Schoor , Nathan Brown -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// diff --git a/typings/glob/glob.d.ts b/typings/glob/glob.d.ts index 6e971437587..2957204f2c5 100644 --- a/typings/glob/glob.d.ts +++ b/typings/glob/glob.d.ts @@ -1,7 +1,7 @@ // Type definitions for Glob 5.0.10 // Project: https://github.com/isaacs/node-glob // Definitions by: vvakame -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// /// @@ -15,7 +15,7 @@ declare module "glob" { function G(pattern: string, cb: (err: Error, matches: string[]) => void): void; function G(pattern: string, options: G.IOptions, cb: (err: Error, matches: string[]) => void): void; - module G { + namespace G { function sync(pattern: string, options?: IOptions): string[]; function hasMagic(pattern: string, options?: IOptions): boolean; diff --git a/typings/js-yaml/js-yaml.d.ts b/typings/js-yaml/js-yaml.d.ts index 0de5a8f6b38..dca80dc228c 100644 --- a/typings/js-yaml/js-yaml.d.ts +++ b/typings/js-yaml/js-yaml.d.ts @@ -1,17 +1,26 @@ -// Type definitions for js-yaml 3.0.2 +// Type definitions for js-yaml 3.5.2 // Project: https://github.com/nodeca/js-yaml -// Definitions by: Bart van der Schoor -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions by: Bart van der Schoor , Sebastian Clausen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module jsyaml { +declare namespace jsyaml { export function safeLoad(str: string, opts?: LoadOptions): any; export function load(str: string, opts?: LoadOptions): any; + export class Type implements TypeConstructorOptions { + constructor(tag: string, opts?: TypeConstructorOptions); + tag: string; + } + export class Schema { + constructor(definition: SchemaDefinition); + public static create(args: any[]): Schema; + } + export function safeLoadAll(str: string, iterator: (doc: any) => void, opts?: LoadOptions): any; export function loadAll(str: string, iterator: (doc: any) => void, opts?: LoadOptions): any; export function safeDump(obj: any, opts?: DumpOptions): string; - export function dump(obj: any, opts?: DumpOptions): string + export function dump(obj: any, opts?: DumpOptions): string; export interface LoadOptions { // string to be used as a file path in error/warning messages. @@ -29,12 +38,29 @@ declare module jsyaml { skipInvalid?: boolean; // specifies level of nesting, when to switch from block to flow style for collections. -1 means block style everwhere flowLevel?: number; - // Each tag may have own set of styles. - "tag" => "style" map. + // Each tag may have own set of styles. - "tag" => "style" map. styles?: Object; // specifies a schema to use. schema?: any; } + export interface TypeConstructorOptions { + kind?: string; + resolve?: Function; + construct?: Function; + instanceOf?: Object; + predicate?: string; + represent?: Function; + defaultStyle?: string; + styleAliases?: Object; + } + + export interface SchemaDefinition { + implicit?: any[]; + explicit?: any[]; + include?: any[]; + } + // only strings, arrays and plain objects: http://www.yaml.org/spec/1.2/spec.html#id2802346 export var FAILSAFE_SCHEMA: any; // only strings, arrays and plain objects: http://www.yaml.org/spec/1.2/spec.html#id2802346 @@ -45,6 +71,13 @@ declare module jsyaml { export var DEFAULT_SAFE_SCHEMA: any; // all supported YAML types. export var DEFAULT_FULL_SCHEMA: any; + export var MINIMAL_SCHEMA: any; + export var SAFE_SCHEMA: any; + + export class YAMLException extends Error { + constructor(reason?: any, mark?: any); + toString(compact?: boolean): string; + } } declare module 'js-yaml' { diff --git a/typings/minimatch/minimatch.d.ts b/typings/minimatch/minimatch.d.ts index a79c6ff114d..5a6c7215ae1 100644 --- a/typings/minimatch/minimatch.d.ts +++ b/typings/minimatch/minimatch.d.ts @@ -1,19 +1,19 @@ // Type definitions for Minimatch 2.0.8 // Project: https://github.com/isaacs/minimatch // Definitions by: vvakame -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare module "minimatch" { function M(target: string, pattern: string, options?: M.IOptions): boolean; - module M { + namespace M { function match(list: string[], pattern: string, options?: IOptions): string[]; function filter(pattern: string, options?: IOptions): (element: string, indexed: number, array: string[]) => boolean; function makeRe(pattern: string, options?: IOptions): RegExp; var Minimatch: IMinimatchStatic; - + interface IOptions { debug?: boolean; nobrace?: boolean; diff --git a/typings/node/node.d.ts b/typings/node/node.d.ts index d7e23cb1e63..0b91d8095ca 100644 --- a/typings/node/node.d.ts +++ b/typings/node/node.d.ts @@ -1,11 +1,11 @@ -// Type definitions for Node.js v0.12.0 +// Type definitions for Node.js v6.x // Project: http://nodejs.org/ -// Definitions by: Microsoft TypeScript , DefinitelyTyped -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions by: Microsoft TypeScript , DefinitelyTyped +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /************************************************ * * -* Node.js v0.12.0 API * +* Node.js v6.x API * * * ************************************************/ @@ -13,14 +13,18 @@ interface Error { stack?: string; } +interface ErrorConstructor { + captureStackTrace(targetObject: Object, constructorOpt?: Function): void; + stackTraceLimit: number; +} -// compat for TypeScript 1.5.3 +// compat for TypeScript 1.8 // if you use with --target es3 or --target es5 and use below definitions, -// use the lib.es6.d.ts that is bundled with TypeScript 1.5.3. -interface MapConstructor {} -interface WeakMapConstructor {} -interface SetConstructor {} -interface WeakSetConstructor {} +// use the lib.es6.d.ts that is bundled with TypeScript 1.8. +interface MapConstructor { } +interface WeakMapConstructor { } +interface SetConstructor { } +interface WeakSetConstructor { } /************************************************ * * @@ -45,7 +49,7 @@ interface NodeRequireFunction { } interface NodeRequire extends NodeRequireFunction { - resolve(id:string): string; + resolve(id: string): string; cache: any; extensions: any; main: any; @@ -80,7 +84,8 @@ declare var SlowBuffer: { // Buffer class -interface Buffer extends NodeBuffer {} +type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "binary" | "hex"; +interface Buffer extends NodeBuffer { } /** * Raw data is stored in instances of the Buffer class. @@ -107,19 +112,64 @@ declare var Buffer: { * @param array The octets to store. */ new (array: Uint8Array): Buffer; + /** + * Produces a Buffer backed by the same allocated memory as + * the given {ArrayBuffer}. + * + * + * @param arrayBuffer The ArrayBuffer with which to share memory. + */ + new (arrayBuffer: ArrayBuffer): Buffer; /** * Allocates a new buffer containing the given {array} of octets. * * @param array The octets to store. */ new (array: any[]): Buffer; + /** + * Copies the passed {buffer} data onto a new {Buffer} instance. + * + * @param buffer The buffer to copy. + */ + new (buffer: Buffer): Buffer; prototype: Buffer; + /** + * Allocates a new Buffer using an {array} of octets. + * + * @param array + */ + from(array: any[]): Buffer; + /** + * When passed a reference to the .buffer property of a TypedArray instance, + * the newly created Buffer will share the same allocated memory as the TypedArray. + * The optional {byteOffset} and {length} arguments specify a memory range + * within the {arrayBuffer} that will be shared by the Buffer. + * + * @param arrayBuffer The .buffer property of a TypedArray or a new ArrayBuffer() + * @param byteOffset + * @param length + */ + from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer; + /** + * Copies the passed {buffer} data onto a new Buffer instance. + * + * @param buffer + */ + from(buffer: Buffer): Buffer; + /** + * Creates a new Buffer containing the given JavaScript string {str}. + * If provided, the {encoding} parameter identifies the character encoding. + * If not provided, {encoding} defaults to 'utf8'. + * + * @param str + */ + from(str: string, encoding?: string): Buffer; /** * Returns true if {obj} is a Buffer * * @param obj object to test. */ - isBuffer(obj: any): boolean; + isBuffer(obj: any): obj is Buffer; /** * Returns true if {encoding} is a valid encoding argument. * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' @@ -151,6 +201,29 @@ declare var Buffer: { * The same as buf1.compare(buf2). */ compare(buf1: Buffer, buf2: Buffer): number; + /** + * Allocates a new buffer of {size} octets. + * + * @param size count of octets to allocate. + * @param fill if specified, buffer will be initialized by calling buf.fill(fill). + * If parameter is omitted, buffer will be filled with zeros. + * @param encoding encoding used for call to buf.fill while initalizing + */ + alloc(size: number, fill?: string | Buffer | number, encoding?: string): Buffer; + /** + * Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents + * of the newly created Buffer are unknown and may contain sensitive data. + * + * @param size count of octets to allocate + */ + allocUnsafe(size: number): Buffer; + /** + * Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents + * of the newly created Buffer are unknown and may contain sensitive data. + * + * @param size count of octets to allocate + */ + allocUnsafeSlow(size: number): Buffer; }; /************************************************ @@ -158,32 +231,38 @@ declare var Buffer: { * GLOBAL INTERFACES * * * ************************************************/ -declare module NodeJS { +declare namespace NodeJS { export interface ErrnoException extends Error { - errno?: number; + errno?: string; code?: string; path?: string; syscall?: string; stack?: string; } - export interface EventEmitter { - addListener(event: string, listener: Function): EventEmitter; - on(event: string, listener: Function): EventEmitter; - once(event: string, listener: Function): EventEmitter; - removeListener(event: string, listener: Function): EventEmitter; - removeAllListeners(event?: string): EventEmitter; - setMaxListeners(n: number): void; - listeners(event: string): Function[]; - emit(event: string, ...args: any[]): boolean; + export class EventEmitter { + addListener(event: string | symbol, listener: Function): this; + on(event: string | symbol, listener: Function): this; + once(event: string | symbol, listener: Function): this; + removeListener(event: string | symbol, listener: Function): this; + removeAllListeners(event?: string | symbol): this; + setMaxListeners(n: number): this; + getMaxListeners(): number; + listeners(event: string | symbol): Function[]; + emit(event: string | symbol, ...args: any[]): boolean; + listenerCount(type: string | symbol): number; + // Added in Node 6... + prependListener(event: string | symbol, listener: Function): this; + prependOnceListener(event: string | symbol, listener: Function): this; + eventNames(): (string | symbol)[]; } export interface ReadableStream extends EventEmitter { readable: boolean; - read(size?: number): string|Buffer; + read(size?: number): string | Buffer; setEncoding(encoding: string): void; - pause(): void; - resume(): void; + pause(): ReadableStream; + resume(): ReadableStream; pipe(destination: T, options?: { end?: boolean; }): T; unpipe(destination?: T): void; unshift(chunk: string): void; @@ -193,7 +272,7 @@ declare module NodeJS { export interface WritableStream extends EventEmitter { writable: boolean; - write(buffer: Buffer|string, cb?: Function): boolean; + write(buffer: Buffer | string, cb?: Function): boolean; write(str: string, encoding?: string, cb?: Function): boolean; end(): void; end(buffer: Buffer, cb?: Function): void; @@ -201,19 +280,58 @@ declare module NodeJS { end(str: string, encoding?: string, cb?: Function): void; } - export interface ReadWriteStream extends ReadableStream, WritableStream {} + export interface ReadWriteStream extends ReadableStream, WritableStream { + pause(): ReadWriteStream; + resume(): ReadWriteStream; + } + + export interface Events extends EventEmitter { } + + export interface Domain extends Events { + run(fn: Function): void; + add(emitter: Events): void; + remove(emitter: Events): void; + bind(cb: (err: Error, data: any) => any): any; + intercept(cb: (data: any) => any): any; + dispose(): void; + + addListener(event: string, listener: Function): this; + on(event: string, listener: Function): this; + once(event: string, listener: Function): this; + removeListener(event: string, listener: Function): this; + removeAllListeners(event?: string): this; + } + + export interface MemoryUsage { + rss: number; + heapTotal: number; + heapUsed: number; + } + + export interface ProcessVersions { + http_parser: string; + node: string; + v8: string; + ares: string; + uv: string; + zlib: string; + modules: string; + openssl: string; + } export interface Process extends EventEmitter { stdout: WritableStream; stderr: WritableStream; stdin: ReadableStream; argv: string[]; + execArgv: string[]; execPath: string; abort(): void; chdir(directory: string): void; cwd(): string; env: any; exit(code?: number): void; + exitCode: number; getgid(): number; setgid(id: number): void; setgid(id: string): void; @@ -221,15 +339,7 @@ declare module NodeJS { setuid(id: number): void; setuid(id: string): void; version: string; - versions: { - http_parser: string; - node: string; - v8: string; - ares: string; - uv: string; - zlib: string; - openssl: string; - }; + versions: ProcessVersions; config: { target_defaults: { cflags: any[]; @@ -256,19 +366,22 @@ declare module NodeJS { visibility: string; }; }; - kill(pid: number, signal?: string): void; + kill(pid: number, signal?: string | number): void; pid: number; title: string; arch: string; platform: string; - memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; }; - nextTick(callback: Function): void; + memoryUsage(): MemoryUsage; + nextTick(callback: Function, ...args: any[]): void; umask(mask?: number): number; uptime(): number; - hrtime(time?:number[]): number[]; + hrtime(time?: number[]): number[]; + domain: Domain; // Worker send?(message: any, sendHandle?: any): void; + disconnect(): void; + connected: boolean; } export interface Global { @@ -334,25 +447,26 @@ declare module NodeJS { undefined: typeof undefined; unescape: (str: string) => string; gc: () => void; + v8debug?: any; } export interface Timer { - ref() : void; - unref() : void; + ref(): void; + unref(): void; } } +interface IterableIterator { } + /** * @deprecated */ -interface NodeBuffer { - [index: number]: number; +interface NodeBuffer extends Uint8Array { write(string: string, offset?: number, length?: number, encoding?: string): number; toString(encoding?: string, start?: number, end?: number): string; - toJSON(): any; - length: number; + toJSON(): { type: 'Buffer', data: any[] }; equals(otherBuffer: Buffer): boolean; - compare(otherBuffer: Buffer): number; + compare(otherBuffer: Buffer, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number; copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; slice(start?: number, end?: number): Buffer; writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; @@ -363,7 +477,7 @@ interface NodeBuffer { readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number; readIntLE(offset: number, byteLength: number, noAssert?: boolean): number; readIntBE(offset: number, byteLength: number, noAssert?: boolean): number; - readUInt8(offset: number, noAsset?: boolean): number; + readUInt8(offset: number, noAssert?: boolean): number; readUInt16LE(offset: number, noAssert?: boolean): number; readUInt16BE(offset: number, noAssert?: boolean): number; readUInt32LE(offset: number, noAssert?: boolean): number; @@ -377,21 +491,30 @@ interface NodeBuffer { readFloatBE(offset: number, noAssert?: boolean): number; readDoubleLE(offset: number, noAssert?: boolean): number; readDoubleBE(offset: number, noAssert?: boolean): number; - writeUInt8(value: number, offset: number, noAssert?: boolean): void; - writeUInt16LE(value: number, offset: number, noAssert?: boolean): void; - writeUInt16BE(value: number, offset: number, noAssert?: boolean): void; - writeUInt32LE(value: number, offset: number, noAssert?: boolean): void; - writeUInt32BE(value: number, offset: number, noAssert?: boolean): void; - writeInt8(value: number, offset: number, noAssert?: boolean): void; - writeInt16LE(value: number, offset: number, noAssert?: boolean): void; - writeInt16BE(value: number, offset: number, noAssert?: boolean): void; - writeInt32LE(value: number, offset: number, noAssert?: boolean): void; - writeInt32BE(value: number, offset: number, noAssert?: boolean): void; - writeFloatLE(value: number, offset: number, noAssert?: boolean): void; - writeFloatBE(value: number, offset: number, noAssert?: boolean): void; - writeDoubleLE(value: number, offset: number, noAssert?: boolean): void; - writeDoubleBE(value: number, offset: number, noAssert?: boolean): void; - fill(value: any, offset?: number, end?: number): void; + swap16(): Buffer; + swap32(): Buffer; + swap64(): Buffer; + writeUInt8(value: number, offset: number, noAssert?: boolean): number; + writeUInt16LE(value: number, offset: number, noAssert?: boolean): number; + writeUInt16BE(value: number, offset: number, noAssert?: boolean): number; + writeUInt32LE(value: number, offset: number, noAssert?: boolean): number; + writeUInt32BE(value: number, offset: number, noAssert?: boolean): number; + writeInt8(value: number, offset: number, noAssert?: boolean): number; + writeInt16LE(value: number, offset: number, noAssert?: boolean): number; + writeInt16BE(value: number, offset: number, noAssert?: boolean): number; + writeInt32LE(value: number, offset: number, noAssert?: boolean): number; + writeInt32BE(value: number, offset: number, noAssert?: boolean): number; + writeFloatLE(value: number, offset: number, noAssert?: boolean): number; + writeFloatBE(value: number, offset: number, noAssert?: boolean): number; + writeDoubleLE(value: number, offset: number, noAssert?: boolean): number; + writeDoubleBE(value: number, offset: number, noAssert?: boolean): number; + fill(value: any, offset?: number, end?: number): this; + indexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number; + lastIndexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number; + entries(): IterableIterator<[number, number]>; + includes(value: string | number | Buffer, byteOffset?: number, encoding?: string): boolean; + keys(): IterableIterator; + values(): IterableIterator; } /************************************************ @@ -401,28 +524,48 @@ interface NodeBuffer { ************************************************/ declare module "buffer" { export var INSPECT_MAX_BYTES: number; + var BuffType: typeof Buffer; + var SlowBuffType: typeof SlowBuffer; + export { BuffType as Buffer, SlowBuffType as SlowBuffer }; } declare module "querystring" { - export function stringify(obj: any, sep?: string, eq?: string): string; - export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; + export interface StringifyOptions { + encodeURIComponent?: Function; + } + + export interface ParseOptions { + maxKeys?: number; + decodeURIComponent?: Function; + } + + export function stringify(obj: T, sep?: string, eq?: string, options?: StringifyOptions): string; + export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): any; + export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): T; export function escape(str: string): string; export function unescape(str: string): string; } declare module "events" { - export class EventEmitter implements NodeJS.EventEmitter { - static listenerCount(emitter: EventEmitter, event: string): number; - - addListener(event: string, listener: Function): EventEmitter; - on(event: string, listener: Function): EventEmitter; - once(event: string, listener: Function): EventEmitter; - removeListener(event: string, listener: Function): EventEmitter; - removeAllListeners(event?: string): EventEmitter; - setMaxListeners(n: number): void; - listeners(event: string): Function[]; - emit(event: string, ...args: any[]): boolean; - } + export class EventEmitter extends NodeJS.EventEmitter { + static EventEmitter: EventEmitter; + static listenerCount(emitter: EventEmitter, event: string | symbol): number; // deprecated + static defaultMaxListeners: number; + + addListener(event: string | symbol, listener: Function): this; + on(event: string | symbol, listener: Function): this; + once(event: string | symbol, listener: Function): this; + prependListener(event: string | symbol, listener: Function): this; + prependOnceListener(event: string | symbol, listener: Function): this; + removeListener(event: string | symbol, listener: Function): this; + removeAllListeners(event?: string | symbol): this; + setMaxListeners(n: number): this; + getMaxListeners(): number; + listeners(event: string | symbol): Function[]; + emit(event: string | symbol, ...args: any[]): boolean; + eventNames(): (string | symbol)[]; + listenerCount(type: string | symbol): number; + } } declare module "http" { @@ -430,14 +573,26 @@ declare module "http" { import * as net from "net"; import * as stream from "stream"; - export interface Server extends events.EventEmitter { - listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; - listen(port: number, hostname?: string, callback?: Function): Server; - listen(path: string, callback?: Function): Server; - listen(handle: any, listeningListener?: Function): Server; - close(cb?: any): Server; - address(): { port: number; family: string; address: string; }; + export interface RequestOptions { + protocol?: string; + host?: string; + hostname?: string; + family?: number; + port?: number; + localAddress?: string; + socketPath?: string; + method?: string; + path?: string; + headers?: { [key: string]: any }; + auth?: string; + agent?: Agent | boolean; + } + + export interface Server extends net.Server { + setTimeout(msecs: number, callback: Function): void; maxHeadersCount: number; + timeout: number; + listening: boolean; } /** * @deprecated Use IncomingMessage @@ -445,7 +600,7 @@ declare module "http" { export interface ServerRequest extends IncomingMessage { connection: net.Socket; } - export interface ServerResponse extends events.EventEmitter, stream.Writable { + export interface ServerResponse extends stream.Writable { // Extended base methods write(buffer: Buffer): boolean; write(buffer: Buffer, cb?: Function): boolean; @@ -458,12 +613,15 @@ declare module "http" { writeHead(statusCode: number, headers?: any): void; statusCode: number; statusMessage: string; - setHeader(name: string, value: string): void; + headersSent: boolean; + setHeader(name: string, value: string | string[]): void; + setTimeout(msecs: number, callback: Function): ServerResponse; sendDate: boolean; getHeader(name: string): string; removeHeader(name: string): void; write(chunk: any, encoding?: string): any; addTrailers(headers: any): void; + finished: boolean; // Extended base methods end(): void; @@ -472,7 +630,7 @@ declare module "http" { end(str: string, encoding?: string, cb?: Function): void; end(data?: any, encoding?: string): void; } - export interface ClientRequest extends events.EventEmitter, stream.Writable { + export interface ClientRequest extends stream.Writable { // Extended base methods write(buffer: Buffer): boolean; write(buffer: Buffer, cb?: Function): boolean; @@ -486,6 +644,11 @@ declare module "http" { setNoDelay(noDelay?: boolean): void; setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; + setHeader(name: string, value: string | string[]): void; + getHeader(name: string): string; + removeHeader(name: string): void; + addTrailers(headers: any): void; + // Extended base methods end(): void; end(buffer: Buffer, cb?: Function): void; @@ -493,8 +656,11 @@ declare module "http" { end(str: string, encoding?: string, cb?: Function): void; end(data?: any, encoding?: string): void; } - export interface IncomingMessage extends events.EventEmitter, stream.Readable { + export interface IncomingMessage extends stream.Readable { httpVersion: string; + httpVersionMajor: number; + httpVersionMinor: number; + connection: net.Socket; headers: any; rawHeaders: string[]; trailers: any; @@ -517,47 +683,48 @@ declare module "http" { */ statusMessage?: string; socket: net.Socket; + destroy(error?: Error): void; } /** * @deprecated Use IncomingMessage */ export interface ClientResponse extends IncomingMessage { } - export interface AgentOptions { - /** - * Keep sockets around in a pool to be used by other requests in the future. Default = false - */ - keepAlive?: boolean; - /** - * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. - * Only relevant if keepAlive is set to true. - */ - keepAliveMsecs?: number; - /** - * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity - */ - maxSockets?: number; - /** - * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. - */ - maxFreeSockets?: number; - } + export interface AgentOptions { + /** + * Keep sockets around in a pool to be used by other requests in the future. Default = false + */ + keepAlive?: boolean; + /** + * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. + * Only relevant if keepAlive is set to true. + */ + keepAliveMsecs?: number; + /** + * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity + */ + maxSockets?: number; + /** + * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. + */ + maxFreeSockets?: number; + } export class Agent { - maxSockets: number; - sockets: any; - requests: any; + maxSockets: number; + sockets: any; + requests: any; - constructor(opts?: AgentOptions); + constructor(opts?: AgentOptions); - /** - * Destroy any sockets that are currently in use by the agent. - * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, - * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, - * sockets may hang open for quite a long time before the server terminates them. - */ - destroy(): void; - } + /** + * Destroy any sockets that are currently in use by the agent. + * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, + * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, + * sockets may hang open for quite a long time before the server terminates them. + */ + destroy(): void; + } export var METHODS: string[]; @@ -565,9 +732,9 @@ declare module "http" { [errorCode: number]: string; [errorCode: string]: string; }; - export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) =>void ): Server; + export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) => void): Server; export function createClient(port?: number, host?: string): any; - export function request(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; + export function request(options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest; export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; export var globalAgent: Agent; } @@ -575,41 +742,266 @@ declare module "http" { declare module "cluster" { import * as child from "child_process"; import * as events from "events"; + import * as net from "net"; + // interfaces export interface ClusterSettings { + execArgv?: string[]; // default: process.execArgv exec?: string; args?: string[]; silent?: boolean; + stdio?: any[]; + uid?: number; + gid?: number; + } + + export interface ClusterSetupMasterSettings { + exec?: string; // default: process.argv[1] + args?: string[]; // default: process.argv.slice(2) + silent?: boolean; // default: false + stdio?: any[]; + } + + export interface Address { + address: string; + port: number; + addressType: number | "udp4" | "udp6"; // 4, 6, -1, "udp4", "udp6" } export class Worker extends events.EventEmitter { id: string; process: child.ChildProcess; suicide: boolean; - send(message: any, sendHandle?: any): void; + send(message: any, sendHandle?: any): boolean; kill(signal?: string): void; destroy(signal?: string): void; disconnect(): void; + isConnected(): boolean; + isDead(): boolean; + exitedAfterDisconnect: boolean; + + /** + * events.EventEmitter + * 1. disconnect + * 2. error + * 3. exit + * 4. listening + * 5. message + * 6. online + */ + addListener(event: string, listener: Function): this; + addListener(event: "disconnect", listener: () => void): this; + addListener(event: "error", listener: (code: number, signal: string) => void): this; + addListener(event: "exit", listener: (code: number, signal: string) => void): this; + addListener(event: "listening", listener: (address: Address) => void): this; + addListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. + addListener(event: "online", listener: () => void): this; + + emit(event: string, listener: Function): boolean + emit(event: "disconnect", listener: () => void): boolean + emit(event: "error", listener: (code: number, signal: string) => void): boolean + emit(event: "exit", listener: (code: number, signal: string) => void): boolean + emit(event: "listening", listener: (address: Address) => void): boolean + emit(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): boolean + emit(event: "online", listener: () => void): boolean + + on(event: string, listener: Function): this; + on(event: "disconnect", listener: () => void): this; + on(event: "error", listener: (code: number, signal: string) => void): this; + on(event: "exit", listener: (code: number, signal: string) => void): this; + on(event: "listening", listener: (address: Address) => void): this; + on(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. + on(event: "online", listener: () => void): this; + + once(event: string, listener: Function): this; + once(event: "disconnect", listener: () => void): this; + once(event: "error", listener: (code: number, signal: string) => void): this; + once(event: "exit", listener: (code: number, signal: string) => void): this; + once(event: "listening", listener: (address: Address) => void): this; + once(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. + once(event: "online", listener: () => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "disconnect", listener: () => void): this; + prependListener(event: "error", listener: (code: number, signal: string) => void): this; + prependListener(event: "exit", listener: (code: number, signal: string) => void): this; + prependListener(event: "listening", listener: (address: Address) => void): this; + prependListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. + prependListener(event: "online", listener: () => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "disconnect", listener: () => void): this; + prependOnceListener(event: "error", listener: (code: number, signal: string) => void): this; + prependOnceListener(event: "exit", listener: (code: number, signal: string) => void): this; + prependOnceListener(event: "listening", listener: (address: Address) => void): this; + prependOnceListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. + prependOnceListener(event: "online", listener: () => void): this; + } + + export interface Cluster extends events.EventEmitter { + Worker: Worker; + disconnect(callback?: Function): void; + fork(env?: any): Worker; + isMaster: boolean; + isWorker: boolean; + // TODO: cluster.schedulingPolicy + settings: ClusterSettings; + setupMaster(settings?: ClusterSetupMasterSettings): void; + worker: Worker; + workers: { + [index: string]: Worker + }; + + /** + * events.EventEmitter + * 1. disconnect + * 2. exit + * 3. fork + * 4. listening + * 5. message + * 6. online + * 7. setup + */ + addListener(event: string, listener: Function): this; + addListener(event: "disconnect", listener: (worker: Worker) => void): this; + addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; + addListener(event: "fork", listener: (worker: Worker) => void): this; + addListener(event: "listening", listener: (worker: Worker, address: Address) => void): this; + addListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. + addListener(event: "online", listener: (worker: Worker) => void): this; + addListener(event: "setup", listener: (settings: any) => void): this; + + emit(event: string, listener: Function): boolean; + emit(event: "disconnect", listener: (worker: Worker) => void): boolean; + emit(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): boolean; + emit(event: "fork", listener: (worker: Worker) => void): boolean; + emit(event: "listening", listener: (worker: Worker, address: Address) => void): boolean; + emit(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): boolean; + emit(event: "online", listener: (worker: Worker) => void): boolean; + emit(event: "setup", listener: (settings: any) => void): boolean; + + on(event: string, listener: Function): this; + on(event: "disconnect", listener: (worker: Worker) => void): this; + on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; + on(event: "fork", listener: (worker: Worker) => void): this; + on(event: "listening", listener: (worker: Worker, address: Address) => void): this; + on(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. + on(event: "online", listener: (worker: Worker) => void): this; + on(event: "setup", listener: (settings: any) => void): this; + + once(event: string, listener: Function): this; + once(event: "disconnect", listener: (worker: Worker) => void): this; + once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; + once(event: "fork", listener: (worker: Worker) => void): this; + once(event: "listening", listener: (worker: Worker, address: Address) => void): this; + once(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. + once(event: "online", listener: (worker: Worker) => void): this; + once(event: "setup", listener: (settings: any) => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "disconnect", listener: (worker: Worker) => void): this; + prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; + prependListener(event: "fork", listener: (worker: Worker) => void): this; + prependListener(event: "listening", listener: (worker: Worker, address: Address) => void): this; + prependListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. + prependListener(event: "online", listener: (worker: Worker) => void): this; + prependListener(event: "setup", listener: (settings: any) => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): this; + prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; + prependOnceListener(event: "fork", listener: (worker: Worker) => void): this; + prependOnceListener(event: "listening", listener: (worker: Worker, address: Address) => void): this; + prependOnceListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. + prependOnceListener(event: "online", listener: (worker: Worker) => void): this; + prependOnceListener(event: "setup", listener: (settings: any) => void): this; + } - export var settings: ClusterSettings; + export function disconnect(callback?: Function): void; + export function fork(env?: any): Worker; export var isMaster: boolean; export var isWorker: boolean; - export function setupMaster(settings?: ClusterSettings): void; - export function fork(env?: any): Worker; - export function disconnect(callback?: Function): void; + // TODO: cluster.schedulingPolicy + export var settings: ClusterSettings; + export function setupMaster(settings?: ClusterSetupMasterSettings): void; export var worker: Worker; - export var workers: Worker[]; - - // Event emitter - export function addListener(event: string, listener: Function): void; - export function on(event: string, listener: Function): any; - export function once(event: string, listener: Function): void; - export function removeListener(event: string, listener: Function): void; - export function removeAllListeners(event?: string): void; - export function setMaxListeners(n: number): void; + export var workers: { + [index: string]: Worker + }; + + /** + * events.EventEmitter + * 1. disconnect + * 2. exit + * 3. fork + * 4. listening + * 5. message + * 6. online + * 7. setup + */ + export function addListener(event: string, listener: Function): Cluster; + export function addListener(event: "disconnect", listener: (worker: Worker) => void): Cluster; + export function addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster; + export function addListener(event: "fork", listener: (worker: Worker) => void): Cluster; + export function addListener(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster; + export function addListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined. + export function addListener(event: "online", listener: (worker: Worker) => void): Cluster; + export function addListener(event: "setup", listener: (settings: any) => void): Cluster; + + export function emit(event: string, listener: Function): boolean; + export function emit(event: "disconnect", listener: (worker: Worker) => void): boolean; + export function emit(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): boolean; + export function emit(event: "fork", listener: (worker: Worker) => void): boolean; + export function emit(event: "listening", listener: (worker: Worker, address: Address) => void): boolean; + export function emit(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): boolean; + export function emit(event: "online", listener: (worker: Worker) => void): boolean; + export function emit(event: "setup", listener: (settings: any) => void): boolean; + + export function on(event: string, listener: Function): Cluster; + export function on(event: "disconnect", listener: (worker: Worker) => void): Cluster; + export function on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster; + export function on(event: "fork", listener: (worker: Worker) => void): Cluster; + export function on(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster; + export function on(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined. + export function on(event: "online", listener: (worker: Worker) => void): Cluster; + export function on(event: "setup", listener: (settings: any) => void): Cluster; + + export function once(event: string, listener: Function): Cluster; + export function once(event: "disconnect", listener: (worker: Worker) => void): Cluster; + export function once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster; + export function once(event: "fork", listener: (worker: Worker) => void): Cluster; + export function once(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster; + export function once(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined. + export function once(event: "online", listener: (worker: Worker) => void): Cluster; + export function once(event: "setup", listener: (settings: any) => void): Cluster; + + export function removeListener(event: string, listener: Function): Cluster; + export function removeAllListeners(event?: string): Cluster; + export function setMaxListeners(n: number): Cluster; + export function getMaxListeners(): number; export function listeners(event: string): Function[]; - export function emit(event: string, ...args: any[]): boolean; + export function listenerCount(type: string): number; + + export function prependListener(event: string, listener: Function): Cluster; + export function prependListener(event: "disconnect", listener: (worker: Worker) => void): Cluster; + export function prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster; + export function prependListener(event: "fork", listener: (worker: Worker) => void): Cluster; + export function prependListener(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster; + export function prependListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined. + export function prependListener(event: "online", listener: (worker: Worker) => void): Cluster; + export function prependListener(event: "setup", listener: (settings: any) => void): Cluster; + + export function prependOnceListener(event: string, listener: Function): Cluster; + export function prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): Cluster; + export function prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster; + export function prependOnceListener(event: "fork", listener: (worker: Worker) => void): Cluster; + export function prependOnceListener(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster; + export function prependOnceListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined. + export function prependOnceListener(event: "online", listener: (worker: Worker) => void): Cluster; + export function prependOnceListener(event: "setup", listener: (settings: any) => void): Cluster; + + export function eventNames(): string[]; } declare module "zlib" { @@ -632,19 +1024,19 @@ declare module "zlib" { export function createInflateRaw(options?: ZlibOptions): InflateRaw; export function createUnzip(options?: ZlibOptions): Unzip; - export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function deflate(buf: Buffer, callback: (error: Error, result: any) => void): void; export function deflateSync(buf: Buffer, options?: ZlibOptions): any; - export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) => void): void; export function deflateRawSync(buf: Buffer, options?: ZlibOptions): any; - export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function gzip(buf: Buffer, callback: (error: Error, result: any) => void): void; export function gzipSync(buf: Buffer, options?: ZlibOptions): any; - export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function gunzip(buf: Buffer, callback: (error: Error, result: any) => void): void; export function gunzipSync(buf: Buffer, options?: ZlibOptions): any; - export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function inflate(buf: Buffer, callback: (error: Error, result: any) => void): void; export function inflateSync(buf: Buffer, options?: ZlibOptions): any; - export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) => void): void; export function inflateRawSync(buf: Buffer, options?: ZlibOptions): any; - export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function unzip(buf: Buffer, callback: (error: Error, result: any) => void): void; export function unzipSync(buf: Buffer, options?: ZlibOptions): any; // Constants @@ -682,19 +1074,162 @@ declare module "zlib" { } declare module "os" { - export function tmpdir(): string; + export interface CpuInfo { + model: string; + speed: number; + times: { + user: number; + nice: number; + sys: number; + idle: number; + irq: number; + }; + } + + export interface NetworkInterfaceInfo { + address: string; + netmask: string; + family: string; + mac: string; + internal: boolean; + } + export function hostname(): string; - export function type(): string; - export function platform(): string; - export function arch(): string; - export function release(): string; - export function uptime(): number; export function loadavg(): number[]; - export function totalmem(): number; + export function uptime(): number; export function freemem(): number; - export function cpus(): { model: string; speed: number; times: { user: number; nice: number; sys: number; idle: number; irq: number; }; }[]; - export function networkInterfaces(): any; + export function totalmem(): number; + export function cpus(): CpuInfo[]; + export function type(): string; + export function release(): string; + export function networkInterfaces(): { [index: string]: NetworkInterfaceInfo[] }; + export function homedir(): string; + export function userInfo(options?: { encoding: string }): { username: string, uid: number, gid: number, shell: any, homedir: string } + export var constants: { + UV_UDP_REUSEADDR: number, + errno: { + SIGHUP: number; + SIGINT: number; + SIGQUIT: number; + SIGILL: number; + SIGTRAP: number; + SIGABRT: number; + SIGIOT: number; + SIGBUS: number; + SIGFPE: number; + SIGKILL: number; + SIGUSR1: number; + SIGSEGV: number; + SIGUSR2: number; + SIGPIPE: number; + SIGALRM: number; + SIGTERM: number; + SIGCHLD: number; + SIGSTKFLT: number; + SIGCONT: number; + SIGSTOP: number; + SIGTSTP: number; + SIGTTIN: number; + SIGTTOU: number; + SIGURG: number; + SIGXCPU: number; + SIGXFSZ: number; + SIGVTALRM: number; + SIGPROF: number; + SIGWINCH: number; + SIGIO: number; + SIGPOLL: number; + SIGPWR: number; + SIGSYS: number; + SIGUNUSED: number; + }, + signals: { + E2BIG: number; + EACCES: number; + EADDRINUSE: number; + EADDRNOTAVAIL: number; + EAFNOSUPPORT: number; + EAGAIN: number; + EALREADY: number; + EBADF: number; + EBADMSG: number; + EBUSY: number; + ECANCELED: number; + ECHILD: number; + ECONNABORTED: number; + ECONNREFUSED: number; + ECONNRESET: number; + EDEADLK: number; + EDESTADDRREQ: number; + EDOM: number; + EDQUOT: number; + EEXIST: number; + EFAULT: number; + EFBIG: number; + EHOSTUNREACH: number; + EIDRM: number; + EILSEQ: number; + EINPROGRESS: number; + EINTR: number; + EINVAL: number; + EIO: number; + EISCONN: number; + EISDIR: number; + ELOOP: number; + EMFILE: number; + EMLINK: number; + EMSGSIZE: number; + EMULTIHOP: number; + ENAMETOOLONG: number; + ENETDOWN: number; + ENETRESET: number; + ENETUNREACH: number; + ENFILE: number; + ENOBUFS: number; + ENODATA: number; + ENODEV: number; + ENOENT: number; + ENOEXEC: number; + ENOLCK: number; + ENOLINK: number; + ENOMEM: number; + ENOMSG: number; + ENOPROTOOPT: number; + ENOSPC: number; + ENOSR: number; + ENOSTR: number; + ENOSYS: number; + ENOTCONN: number; + ENOTDIR: number; + ENOTEMPTY: number; + ENOTSOCK: number; + ENOTSUP: number; + ENOTTY: number; + ENXIO: number; + EOPNOTSUPP: number; + EOVERFLOW: number; + EPERM: number; + EPIPE: number; + EPROTO: number; + EPROTONOSUPPORT: number; + EPROTOTYPE: number; + ERANGE: number; + EROFS: number; + ESPIPE: number; + ESRCH: number; + ESTALE: number; + ETIME: number; + ETIMEDOUT: number; + ETXTBSY: number; + EWOULDBLOCK: number; + EXDEV: number; + }, + }; + export function arch(): string; + export function platform(): string; + export function tmpdir(): string; export var EOL: string; + export function endianness(): "BE" | "LE"; } declare module "https" { @@ -714,18 +1249,10 @@ declare module "https" { requestCert?: boolean; rejectUnauthorized?: boolean; NPNProtocols?: any; - SNICallback?: (servername: string) => any; + SNICallback?: (servername: string, cb: (err: Error, ctx: tls.SecureContext) => any) => any; } - export interface RequestOptions { - host?: string; - hostname?: string; - port?: number; - path?: string; - method?: string; - headers?: any; - auth?: string; - agent?: any; + export interface RequestOptions extends http.RequestOptions { pfx?: any; key?: any; passphrase?: string; @@ -733,20 +1260,30 @@ declare module "https" { ca?: any; ciphers?: string; rejectUnauthorized?: boolean; + secureProtocol?: string; } - export interface Agent { - maxSockets: number; - sockets: any; - requests: any; + export interface Agent extends http.Agent { } + + export interface AgentOptions extends http.AgentOptions { + pfx?: any; + key?: any; + passphrase?: string; + cert?: any; + ca?: any; + ciphers?: string; + rejectUnauthorized?: boolean; + secureProtocol?: string; + maxCachedSessions?: number; } + export var Agent: { - new (options?: RequestOptions): Agent; + new (options?: AgentOptions): Agent; }; export interface Server extends tls.Server { } export function createServer(options: ServerOptions, requestListener?: Function): Server; - export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; - export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) =>void ): http.ClientRequest; + export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest; + export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest; export var globalAgent: Agent; } @@ -757,7 +1294,7 @@ declare module "punycode" { export function toASCII(domain: string): string; export var ucs2: ucs2; interface ucs2 { - decode(string: string): string; + decode(string: string): number[]; encode(codePoints: number[]): string; } export var version: any; @@ -765,7 +1302,7 @@ declare module "punycode" { declare module "repl" { import * as stream from "stream"; - import * as events from "events"; + import * as readline from "readline"; export interface ReplOptions { prompt?: string; @@ -777,43 +1314,98 @@ declare module "repl" { useGlobal?: boolean; ignoreUndefined?: boolean; writer?: Function; + completer?: Function; + replMode?: any; + breakEvalOnSigint?: any; } - export function start(options: ReplOptions): events.EventEmitter; + + export interface REPLServer extends readline.ReadLine { + defineCommand(keyword: string, cmd: Function | { help: string, action: Function }): void; + displayPrompt(preserveCursor?: boolean): void + } + + export function start(options: ReplOptions): REPLServer; } declare module "readline" { import * as events from "events"; import * as stream from "stream"; + export interface Key { + sequence?: string; + name?: string; + ctrl?: boolean; + meta?: boolean; + shift?: boolean; + } + export interface ReadLine extends events.EventEmitter { setPrompt(prompt: string): void; prompt(preserveCursor?: boolean): void; - question(query: string, callback: Function): void; - pause(): void; - resume(): void; + question(query: string, callback: (answer: string) => void): void; + pause(): ReadLine; + resume(): ReadLine; close(): void; - write(data: any, key?: any): void; + write(data: string | Buffer, key?: Key): void; + } + + export interface Completer { + (line: string): CompleterResult; + (line: string, callback: (err: any, result: CompleterResult) => void): any; } + + export interface CompleterResult { + completions: string[]; + line: string; + } + export interface ReadLineOptions { input: NodeJS.ReadableStream; - output: NodeJS.WritableStream; - completer?: Function; + output?: NodeJS.WritableStream; + completer?: Completer; terminal?: boolean; + historySize?: number; } + + export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer, terminal?: boolean): ReadLine; export function createInterface(options: ReadLineOptions): ReadLine; + + export function cursorTo(stream: NodeJS.WritableStream, x: number, y: number): void; + export function moveCursor(stream: NodeJS.WritableStream, dx: number | string, dy: number | string): void; + export function clearLine(stream: NodeJS.WritableStream, dir: number): void; + export function clearScreenDown(stream: NodeJS.WritableStream): void; } declare module "vm" { export interface Context { } - export interface Script { - runInThisContext(): void; - runInNewContext(sandbox?: Context): void; - } - export function runInThisContext(code: string, filename?: string): void; - export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; - export function runInContext(code: string, context: Context, filename?: string): void; - export function createContext(initSandbox?: Context): Context; - export function createScript(code: string, filename?: string): Script; + export interface ScriptOptions { + filename?: string; + lineOffset?: number; + columnOffset?: number; + displayErrors?: boolean; + timeout?: number; + cachedData?: Buffer; + produceCachedData?: boolean; + } + export interface RunningScriptOptions { + filename?: string; + lineOffset?: number; + columnOffset?: number; + displayErrors?: boolean; + timeout?: number; + } + export class Script { + constructor(code: string, options?: ScriptOptions); + runInContext(contextifiedSandbox: Context, options?: RunningScriptOptions): any; + runInNewContext(sandbox?: Context, options?: RunningScriptOptions): any; + runInThisContext(options?: RunningScriptOptions): any; + } + export function createContext(sandbox?: Context): Context; + export function isContext(sandbox: Context): boolean; + export function runInContext(code: string, contextifiedSandbox: Context, options?: RunningScriptOptions): any; + export function runInDebugContext(code: string): any; + export function runInNewContext(code: string, sandbox?: Context, options?: RunningScriptOptions): any; + export function runInThisContext(code: string, options?: RunningScriptOptions): any; } declare module "child_process" { @@ -821,96 +1413,179 @@ declare module "child_process" { import * as stream from "stream"; export interface ChildProcess extends events.EventEmitter { - stdin: stream.Writable; + stdin: stream.Writable; stdout: stream.Readable; stderr: stream.Readable; + stdio: [stream.Writable, stream.Readable, stream.Readable]; pid: number; kill(signal?: string): void; - send(message: any, sendHandle?: any): void; + send(message: any, sendHandle?: any): boolean; + connected: boolean; disconnect(): void; unref(): void; + ref(): void; } - export function spawn(command: string, args?: string[], options?: { + export interface SpawnOptions { cwd?: string; - stdio?: any; - custom?: any; env?: any; + stdio?: any; detached?: boolean; - }): ChildProcess; - export function exec(command: string, options: { + uid?: number; + gid?: number; + shell?: boolean | string; + } + export function spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess; + + export interface ExecOptions { cwd?: string; - stdio?: any; - customFds?: any; env?: any; - encoding?: string; + shell?: string; timeout?: number; maxBuffer?: number; killSignal?: string; - }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function exec(command: string, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function execFile(file: string, - callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function execFile(file: string, args?: string[], - callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function execFile(file: string, args?: string[], options?: { + uid?: number; + gid?: number; + } + export interface ExecOptionsWithStringEncoding extends ExecOptions { + encoding: BufferEncoding; + } + export interface ExecOptionsWithBufferEncoding extends ExecOptions { + encoding: string; // specify `null`. + } + export function exec(command: string, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; + export function exec(command: string, options: ExecOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; + // usage. child_process.exec("tsc", {encoding: null as string}, (err, stdout, stderr) => {}); + export function exec(command: string, options: ExecOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess; + export function exec(command: string, options: ExecOptions, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; + + export interface ExecFileOptions { cwd?: string; - stdio?: any; - customFds?: any; env?: any; - encoding?: string; timeout?: number; - maxBuffer?: string; + maxBuffer?: number; killSignal?: string; - }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function fork(modulePath: string, args?: string[], options?: { + uid?: number; + gid?: number; + } + export interface ExecFileOptionsWithStringEncoding extends ExecFileOptions { + encoding: BufferEncoding; + } + export interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions { + encoding: string; // specify `null`. + } + export function execFile(file: string, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; + export function execFile(file: string, options?: ExecFileOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; + // usage. child_process.execFile("file.sh", {encoding: null as string}, (err, stdout, stderr) => {}); + export function execFile(file: string, options?: ExecFileOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess; + export function execFile(file: string, options?: ExecFileOptions, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; + export function execFile(file: string, args?: string[], callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; + export function execFile(file: string, args?: string[], options?: ExecFileOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; + // usage. child_process.execFile("file.sh", ["foo"], {encoding: null as string}, (err, stdout, stderr) => {}); + export function execFile(file: string, args?: string[], options?: ExecFileOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess; + export function execFile(file: string, args?: string[], options?: ExecFileOptions, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; + + export interface ForkOptions { cwd?: string; env?: any; - encoding?: string; - }): ChildProcess; - export function execSync(command: string, options?: { + execPath?: string; + execArgv?: string[]; + silent?: boolean; + uid?: number; + gid?: number; + } + export function fork(modulePath: string, args?: string[], options?: ForkOptions): ChildProcess; + + export interface SpawnSyncOptions { cwd?: string; - input?: string|Buffer; + input?: string | Buffer; stdio?: any; env?: any; uid?: number; gid?: number; timeout?: number; - maxBuffer?: number; killSignal?: string; + maxBuffer?: number; encoding?: string; - }): ChildProcess; - export function execFileSync(command: string, args?: string[], options?: { + shell?: boolean | string; + } + export interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions { + encoding: BufferEncoding; + } + export interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions { + encoding: string; // specify `null`. + } + export interface SpawnSyncReturns { + pid: number; + output: string[]; + stdout: T; + stderr: T; + status: number; + signal: string; + error: Error; + } + export function spawnSync(command: string): SpawnSyncReturns; + export function spawnSync(command: string, options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns; + export function spawnSync(command: string, options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; + export function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns; + export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns; + export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; + export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptions): SpawnSyncReturns; + + export interface ExecSyncOptions { cwd?: string; - input?: string|Buffer; + input?: string | Buffer; stdio?: any; env?: any; + shell?: string; uid?: number; gid?: number; timeout?: number; + killSignal?: string; maxBuffer?: number; + encoding?: string; + } + export interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions { + encoding: BufferEncoding; + } + export interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions { + encoding: string; // specify `null`. + } + export function execSync(command: string): Buffer; + export function execSync(command: string, options?: ExecSyncOptionsWithStringEncoding): string; + export function execSync(command: string, options?: ExecSyncOptionsWithBufferEncoding): Buffer; + export function execSync(command: string, options?: ExecSyncOptions): Buffer; + + export interface ExecFileSyncOptions { + cwd?: string; + input?: string | Buffer; + stdio?: any; + env?: any; + uid?: number; + gid?: number; + timeout?: number; killSignal?: string; + maxBuffer?: number; encoding?: string; - }): ChildProcess; + } + export interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions { + encoding: BufferEncoding; + } + export interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions { + encoding: string; // specify `null`. + } + export function execFileSync(command: string): Buffer; + export function execFileSync(command: string, options?: ExecFileSyncOptionsWithStringEncoding): string; + export function execFileSync(command: string, options?: ExecFileSyncOptionsWithBufferEncoding): Buffer; + export function execFileSync(command: string, options?: ExecFileSyncOptions): Buffer; + export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptionsWithStringEncoding): string; + export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptionsWithBufferEncoding): Buffer; + export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptions): Buffer; } declare module "url" { export interface Url { - href: string; - protocol: string; - auth: string; - hostname: string; - port: string; - host: string; - pathname: string; - search: string; - query: any; // string | Object - slashes: boolean; - hash?: string; - path?: string; - } - - export interface UrlOptions { + href?: string; protocol?: string; auth?: string; hostname?: string; @@ -918,29 +1593,62 @@ declare module "url" { host?: string; pathname?: string; search?: string; - query?: any; + query?: string | any; + slashes?: boolean; hash?: string; path?: string; } - export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; - export function format(url: UrlOptions): string; + export function parse(urlStr: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): Url; + export function format(url: Url): string; export function resolve(from: string, to: string): string; } declare module "dns" { - export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; - export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; - export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; + export interface MxRecord { + exchange: string, + priority: number + } + + export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) => void): string; + export function lookup(domain: string, callback: (err: Error, address: string, family: number) => void): string; + export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) => void): string[]; + export function resolve(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; + export function resolve4(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; + export function resolve6(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; + export function resolveMx(domain: string, callback: (err: Error, addresses: MxRecord[]) => void): string[]; + export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; + export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; + export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; + export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; + export function reverse(ip: string, callback: (err: Error, domains: string[]) => void): string[]; + export function setServers(servers: string[]): void; + + //Error codes + export var NODATA: string; + export var FORMERR: string; + export var SERVFAIL: string; + export var NOTFOUND: string; + export var NOTIMP: string; + export var REFUSED: string; + export var BADQUERY: string; + export var BADNAME: string; + export var BADFAMILY: string; + export var BADRESP: string; + export var CONNREFUSED: string; + export var TIMEOUT: string; + export var EOF: string; + export var FILE: string; + export var NOMEM: string; + export var DESTRUCTION: string; + export var BADSTR: string; + export var BADFLAGS: string; + export var NONAME: string; + export var BADHINTS: string; + export var NOTINITIALIZED: string; + export var LOADIPHLPAPI: string; + export var ADDRGETNETWORKPARAMS: string; + export var CANCELLED: string; } declare module "net" { @@ -960,8 +1668,8 @@ declare module "net" { setEncoding(encoding?: string): void; write(data: any, encoding?: string, callback?: Function): void; destroy(): void; - pause(): void; - resume(): void; + pause(): Socket; + resume(): Socket; setTimeout(timeout: number, callback?: Function): void; setNoDelay(noDelay?: boolean): void; setKeepAlive(enable?: boolean, initialDelay?: number): void; @@ -983,27 +1691,158 @@ declare module "net" { end(str: string, cb?: Function): void; end(str: string, encoding?: string, cb?: Function): void; end(data?: any, encoding?: string): void; + + /** + * events.EventEmitter + * 1. close + * 2. connect + * 3. data + * 4. drain + * 5. end + * 6. error + * 7. lookup + * 8. timeout + */ + addListener(event: string, listener: Function): this; + addListener(event: "close", listener: (had_error: boolean) => void): this; + addListener(event: "connect", listener: () => void): this; + addListener(event: "data", listener: (data: Buffer) => void): this; + addListener(event: "drain", listener: () => void): this; + addListener(event: "end", listener: () => void): this; + addListener(event: "error", listener: (err: Error) => void): this; + addListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; + addListener(event: "timeout", listener: () => void): this; + + emit(event: string, ...args: any[]): boolean; + emit(event: "close", had_error: boolean): boolean; + emit(event: "connect"): boolean; + emit(event: "data", data: Buffer): boolean; + emit(event: "drain"): boolean; + emit(event: "end"): boolean; + emit(event: "error", err: Error): boolean; + emit(event: "lookup", err: Error, address: string, family: string | number, host: string): boolean; + emit(event: "timeout"): boolean; + + on(event: string, listener: Function): this; + on(event: "close", listener: (had_error: boolean) => void): this; + on(event: "connect", listener: () => void): this; + on(event: "data", listener: (data: Buffer) => void): this; + on(event: "drain", listener: () => void): this; + on(event: "end", listener: () => void): this; + on(event: "error", listener: (err: Error) => void): this; + on(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; + on(event: "timeout", listener: () => void): this; + + once(event: string, listener: Function): this; + once(event: "close", listener: (had_error: boolean) => void): this; + once(event: "connect", listener: () => void): this; + once(event: "data", listener: (data: Buffer) => void): this; + once(event: "drain", listener: () => void): this; + once(event: "end", listener: () => void): this; + once(event: "error", listener: (err: Error) => void): this; + once(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; + once(event: "timeout", listener: () => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "close", listener: (had_error: boolean) => void): this; + prependListener(event: "connect", listener: () => void): this; + prependListener(event: "data", listener: (data: Buffer) => void): this; + prependListener(event: "drain", listener: () => void): this; + prependListener(event: "end", listener: () => void): this; + prependListener(event: "error", listener: (err: Error) => void): this; + prependListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; + prependListener(event: "timeout", listener: () => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "close", listener: (had_error: boolean) => void): this; + prependOnceListener(event: "connect", listener: () => void): this; + prependOnceListener(event: "data", listener: (data: Buffer) => void): this; + prependOnceListener(event: "drain", listener: () => void): this; + prependOnceListener(event: "end", listener: () => void): this; + prependOnceListener(event: "error", listener: (err: Error) => void): this; + prependOnceListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; + prependOnceListener(event: "timeout", listener: () => void): this; } export var Socket: { new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; }; + export interface ListenOptions { + port?: number; + host?: string; + backlog?: number; + path?: string; + exclusive?: boolean; + } + export interface Server extends Socket { - listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; + listen(port: number, hostname?: string, backlog?: number, listeningListener?: Function): Server; + listen(port: number, hostname?: string, listeningListener?: Function): Server; + listen(port: number, backlog?: number, listeningListener?: Function): Server; + listen(port: number, listeningListener?: Function): Server; + listen(path: string, backlog?: number, listeningListener?: Function): Server; listen(path: string, listeningListener?: Function): Server; + listen(handle: any, backlog?: number, listeningListener?: Function): Server; listen(handle: any, listeningListener?: Function): Server; + listen(options: ListenOptions, listeningListener?: Function): Server; close(callback?: Function): Server; address(): { port: number; family: string; address: string; }; + getConnections(cb: (error: Error, count: number) => void): void; + ref(): Server; + unref(): Server; maxConnections: number; connections: number; - } - export function createServer(connectionListener?: (socket: Socket) =>void ): Server; - export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server; - export function connect(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; + + /** + * events.EventEmitter + * 1. close + * 2. connection + * 3. error + * 4. listening + */ + addListener(event: string, listener: Function): this; + addListener(event: "close", listener: () => void): this; + addListener(event: "connection", listener: (socket: Socket) => void): this; + addListener(event: "error", listener: (err: Error) => void): this; + addListener(event: "listening", listener: () => void): this; + + emit(event: string, ...args: any[]): boolean; + emit(event: "close"): boolean; + emit(event: "connection", socket: Socket): boolean; + emit(event: "error", err: Error): boolean; + emit(event: "listening"): boolean; + + on(event: string, listener: Function): this; + on(event: "close", listener: () => void): this; + on(event: "connection", listener: (socket: Socket) => void): this; + on(event: "error", listener: (err: Error) => void): this; + on(event: "listening", listener: () => void): this; + + once(event: string, listener: Function): this; + once(event: "close", listener: () => void): this; + once(event: "connection", listener: (socket: Socket) => void): this; + once(event: "error", listener: (err: Error) => void): this; + once(event: "listening", listener: () => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "close", listener: () => void): this; + prependListener(event: "connection", listener: (socket: Socket) => void): this; + prependListener(event: "error", listener: (err: Error) => void): this; + prependListener(event: "listening", listener: () => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "close", listener: () => void): this; + prependOnceListener(event: "connection", listener: (socket: Socket) => void): this; + prependOnceListener(event: "error", listener: (err: Error) => void): this; + prependOnceListener(event: "listening", listener: () => void): this; + } + export function createServer(connectionListener?: (socket: Socket) => void): Server; + export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) => void): Server; + export function connect(options: { port: number, host?: string, localAddress?: string, localPort?: string, family?: number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; export function connect(port: number, host?: string, connectionListener?: Function): Socket; export function connect(path: string, connectionListener?: Function): Socket; - export function createConnection(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; + export function createConnection(options: { port: number, host?: string, localAddress?: string, localPort?: string, family?: number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; export function createConnection(path: string, connectionListener?: Function): Socket; export function isIP(input: string): number; @@ -1016,8 +1855,8 @@ declare module "dgram" { interface RemoteInfo { address: string; + family: string; port: number; - size: number; } interface AddressInfo { @@ -1026,18 +1865,78 @@ declare module "dgram" { port: number; } - export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; + interface BindOptions { + port: number; + address?: string; + exclusive?: boolean; + } - interface Socket extends events.EventEmitter { - send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; - bind(port: number, address?: string, callback?: () => void): void; - close(): void; + interface SocketOptions { + type: "udp4" | "udp6"; + reuseAddr?: boolean; + } + + export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; + export function createSocket(options: SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; + + export interface Socket extends events.EventEmitter { + send(msg: Buffer | String | any[], port: number, address: string, callback?: (error: Error, bytes: number) => void): void; + send(msg: Buffer | String | any[], offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; + bind(port?: number, address?: string, callback?: () => void): void; + bind(options: BindOptions, callback?: Function): void; + close(callback?: any): void; address(): AddressInfo; setBroadcast(flag: boolean): void; + setTTL(ttl: number): void; setMulticastTTL(ttl: number): void; setMulticastLoopback(flag: boolean): void; addMembership(multicastAddress: string, multicastInterface?: string): void; dropMembership(multicastAddress: string, multicastInterface?: string): void; + ref(): void; + unref(): void; + + /** + * events.EventEmitter + * 1. close + * 2. error + * 3. listening + * 4. message + **/ + addListener(event: string, listener: Function): this; + addListener(event: "close", listener: () => void): this; + addListener(event: "error", listener: (err: Error) => void): this; + addListener(event: "listening", listener: () => void): this; + addListener(event: "message", listener: (msg: string, rinfo: AddressInfo) => void): this; + + emit(event: string, ...args: any[]): boolean; + emit(event: "close"): boolean; + emit(event: "error", err: Error): boolean; + emit(event: "listening"): boolean; + emit(event: "message", msg: string, rinfo: AddressInfo): boolean; + + on(event: string, listener: Function): this; + on(event: "close", listener: () => void): this; + on(event: "error", listener: (err: Error) => void): this; + on(event: "listening", listener: () => void): this; + on(event: "message", listener: (msg: string, rinfo: AddressInfo) => void): this; + + once(event: string, listener: Function): this; + once(event: "close", listener: () => void): this; + once(event: "error", listener: (err: Error) => void): this; + once(event: "listening", listener: () => void): this; + once(event: "message", listener: (msg: string, rinfo: AddressInfo) => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "close", listener: () => void): this; + prependListener(event: "error", listener: (err: Error) => void): this; + prependListener(event: "listening", listener: () => void): this; + prependListener(event: "message", listener: (msg: string, rinfo: AddressInfo) => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "close", listener: () => void): this; + prependOnceListener(event: "error", listener: (err: Error) => void): this; + prependOnceListener(event: "listening", listener: () => void): this; + prependOnceListener(event: "message", listener: (msg: string, rinfo: AddressInfo) => void): this; } } @@ -1071,14 +1970,92 @@ declare module "fs" { interface FSWatcher extends events.EventEmitter { close(): void; + + /** + * events.EventEmitter + * 1. change + * 2. error + */ + addListener(event: string, listener: Function): this; + addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + addListener(event: "error", listener: (code: number, signal: string) => void): this; + + on(event: string, listener: Function): this; + on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + on(event: "error", listener: (code: number, signal: string) => void): this; + + once(event: string, listener: Function): this; + once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + once(event: "error", listener: (code: number, signal: string) => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + prependListener(event: "error", listener: (code: number, signal: string) => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; + prependOnceListener(event: "error", listener: (code: number, signal: string) => void): this; } export interface ReadStream extends stream.Readable { close(): void; + destroy(): void; + + /** + * events.EventEmitter + * 1. open + * 2. close + */ + addListener(event: string, listener: Function): this; + addListener(event: "open", listener: (fd: number) => void): this; + addListener(event: "close", listener: () => void): this; + + on(event: string, listener: Function): this; + on(event: "open", listener: (fd: number) => void): this; + on(event: "close", listener: () => void): this; + + once(event: string, listener: Function): this; + once(event: "open", listener: (fd: number) => void): this; + once(event: "close", listener: () => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "open", listener: (fd: number) => void): this; + prependListener(event: "close", listener: () => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "open", listener: (fd: number) => void): this; + prependOnceListener(event: "close", listener: () => void): this; } + export interface WriteStream extends stream.Writable { close(): void; bytesWritten: number; + path: string | Buffer; + + /** + * events.EventEmitter + * 1. open + * 2. close + */ + addListener(event: string, listener: Function): this; + addListener(event: "open", listener: (fd: number) => void): this; + addListener(event: "close", listener: () => void): this; + + on(event: string, listener: Function): this; + on(event: "open", listener: (fd: number) => void): this; + on(event: "close", listener: () => void): this; + + once(event: string, listener: Function): this; + once(event: "open", listener: (fd: number) => void): this; + once(event: "close", listener: () => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "open", listener: (fd: number) => void): this; + prependListener(event: "close", listener: () => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "open", listener: (fd: number) => void): this; + prependOnceListener(event: "close", listener: () => void): this; } /** @@ -1094,78 +2071,78 @@ declare module "fs" { * @param newPath */ export function renameSync(oldPath: string, newPath: string): void; - export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function truncateSync(path: string, len?: number): void; + export function truncate(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function truncate(path: string | Buffer, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function truncateSync(path: string | Buffer, len?: number): void; export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; export function ftruncateSync(fd: number, len?: number): void; - export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chownSync(path: string, uid: number, gid: number): void; + export function chown(path: string | Buffer, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chownSync(path: string | Buffer, uid: number, gid: number): void; export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; export function fchownSync(fd: number, uid: number, gid: number): void; - export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchownSync(path: string, uid: number, gid: number): void; - export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chmodSync(path: string, mode: number): void; - export function chmodSync(path: string, mode: string): void; + export function lchown(path: string | Buffer, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchownSync(path: string | Buffer, uid: number, gid: number): void; + export function chmod(path: string | Buffer, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chmod(path: string | Buffer, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chmodSync(path: string | Buffer, mode: number): void; + export function chmodSync(path: string | Buffer, mode: string): void; export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; export function fchmodSync(fd: number, mode: number): void; export function fchmodSync(fd: number, mode: string): void; - export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchmodSync(path: string, mode: number): void; - export function lchmodSync(path: string, mode: string): void; - export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; - export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; + export function lchmod(path: string | Buffer, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchmod(path: string | Buffer, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchmodSync(path: string | Buffer, mode: number): void; + export function lchmodSync(path: string | Buffer, mode: string): void; + export function stat(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; + export function lstat(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; - export function statSync(path: string): Stats; - export function lstatSync(path: string): Stats; + export function statSync(path: string | Buffer): Stats; + export function lstatSync(path: string | Buffer): Stats; export function fstatSync(fd: number): Stats; - export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function linkSync(srcpath: string, dstpath: string): void; - export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; - export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; - export function readlinkSync(path: string): string; - export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; - export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void; - export function realpathSync(path: string, cache?: { [path: string]: string }): string; + export function link(srcpath: string | Buffer, dstpath: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function linkSync(srcpath: string | Buffer, dstpath: string | Buffer): void; + export function symlink(srcpath: string | Buffer, dstpath: string | Buffer, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function symlinkSync(srcpath: string | Buffer, dstpath: string | Buffer, type?: string): void; + export function readlink(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; + export function readlinkSync(path: string | Buffer): string; + export function realpath(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; + export function realpath(path: string | Buffer, cache: { [path: string]: string }, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; + export function realpathSync(path: string | Buffer, cache?: { [path: string]: string }): string; /* * Asynchronous unlink - deletes the file specified in {path} * * @param path * @param callback No arguments other than a possible exception are given to the completion callback. */ - export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function unlink(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void; /* * Synchronous unlink - deletes the file specified in {path} * * @param path */ - export function unlinkSync(path: string): void; + export function unlinkSync(path: string | Buffer): void; /* * Asynchronous rmdir - removes the directory specified in {path} * * @param path * @param callback No arguments other than a possible exception are given to the completion callback. */ - export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function rmdir(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void; /* * Synchronous rmdir - removes the directory specified in {path} * * @param path */ - export function rmdirSync(path: string): void; + export function rmdirSync(path: string | Buffer): void; /* * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. * * @param path * @param callback No arguments other than a possible exception are given to the completion callback. */ - export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdir(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void; /* * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. * @@ -1173,7 +2150,7 @@ declare module "fs" { * @param mode * @param callback No arguments other than a possible exception are given to the completion callback. */ - export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdir(path: string | Buffer, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; /* * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. * @@ -1181,7 +2158,7 @@ declare module "fs" { * @param mode * @param callback No arguments other than a possible exception are given to the completion callback. */ - export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdir(path: string | Buffer, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; /* * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. * @@ -1189,7 +2166,7 @@ declare module "fs" { * @param mode * @param callback No arguments other than a possible exception are given to the completion callback. */ - export function mkdirSync(path: string, mode?: number): void; + export function mkdirSync(path: string | Buffer, mode?: number): void; /* * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. * @@ -1197,20 +2174,32 @@ declare module "fs" { * @param mode * @param callback No arguments other than a possible exception are given to the completion callback. */ - export function mkdirSync(path: string, mode?: string): void; - export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; - export function readdirSync(path: string): string[]; + export function mkdirSync(path: string | Buffer, mode?: string): void; + /* + * Asynchronous mkdtemp - Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory. + * + * @param prefix + * @param callback The created folder path is passed as a string to the callback's second parameter. + */ + export function mkdtemp(prefix: string, callback?: (err: NodeJS.ErrnoException, folder: string) => void): void; + /* + * Synchronous mkdtemp - Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory. + * + * @param prefix + * @returns Returns the created folder path. + */ + export function mkdtempSync(prefix: string): string; + export function readdir(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; + export function readdirSync(path: string | Buffer): string[]; export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; export function closeSync(fd: number): void; - export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; - export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; - export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; - export function openSync(path: string, flags: string, mode?: number): number; - export function openSync(path: string, flags: string, mode?: string): number; - export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function utimesSync(path: string, atime: number, mtime: number): void; - export function utimesSync(path: string, atime: Date, mtime: Date): void; + export function open(path: string | Buffer, flags: string | number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void; + export function open(path: string | Buffer, flags: string | number, mode: number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void; + export function openSync(path: string | Buffer, flags: string | number, mode?: number): number; + export function utimes(path: string | Buffer, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function utimes(path: string | Buffer, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function utimesSync(path: string | Buffer, atime: number, mtime: number): void; + export function utimesSync(path: string | Buffer, atime: Date, mtime: Date): void; export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; export function futimesSync(fd: number, atime: number, mtime: number): void; @@ -1222,7 +2211,8 @@ declare module "fs" { export function write(fd: number, data: any, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; export function write(fd: number, data: any, offset: number, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; export function write(fd: number, data: any, offset: number, encoding: string, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; - export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; + export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number): number; + export function writeSync(fd: number, data: any, position?: number, enconding?: string): number; export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; /* @@ -1291,41 +2281,162 @@ declare module "fs" { export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; - export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; - export function exists(path: string, callback?: (exists: boolean) => void): void; - export function existsSync(path: string): boolean; - /** Constant for fs.access(). File is visible to the calling process. */ - export var F_OK: number; - /** Constant for fs.access(). File can be read by the calling process. */ - export var R_OK: number; - /** Constant for fs.access(). File can be written by the calling process. */ - export var W_OK: number; - /** Constant for fs.access(). File can be executed by the calling process. */ - export var X_OK: number; + export function watch(filename: string, encoding: string, listener?: (event: string, filename: string | Buffer) => any): FSWatcher; + export function watch(filename: string, options: { persistent?: boolean; recursive?: boolean; encoding?: string }, listener?: (event: string, filename: string | Buffer) => any): FSWatcher; + export function exists(path: string | Buffer, callback?: (exists: boolean) => void): void; + export function existsSync(path: string | Buffer): boolean; + + export namespace constants { + // File Access Constants + + /** Constant for fs.access(). File is visible to the calling process. */ + export const F_OK: number; + + /** Constant for fs.access(). File can be read by the calling process. */ + export const R_OK: number; + + /** Constant for fs.access(). File can be written by the calling process. */ + export const W_OK: number; + + /** Constant for fs.access(). File can be executed by the calling process. */ + export const X_OK: number; + + // File Open Constants + + /** Constant for fs.open(). Flag indicating to open a file for read-only access. */ + export const O_RDONLY: number; + + /** Constant for fs.open(). Flag indicating to open a file for write-only access. */ + export const O_WRONLY: number; + + /** Constant for fs.open(). Flag indicating to open a file for read-write access. */ + export const O_RDWR: number; + + /** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */ + export const O_CREAT: number; + + /** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */ + export const O_EXCL: number; + + /** Constant for fs.open(). Flag indicating that if path identifies a terminal device, opening the path shall not cause that terminal to become the controlling terminal for the process (if the process does not already have one). */ + export const O_NOCTTY: number; + + /** Constant for fs.open(). Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */ + export const O_TRUNC: number; + + /** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */ + export const O_APPEND: number; + + /** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */ + export const O_DIRECTORY: number; + + /** Constant for fs.open(). Flag indicating reading accesses to the file system will no longer result in an update to the atime information associated with the file. This flag is available on Linux operating systems only. */ + export const O_NOATIME: number; + + /** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */ + export const O_NOFOLLOW: number; + + /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */ + export const O_SYNC: number; + + /** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */ + export const O_SYMLINK: number; + + /** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */ + export const O_DIRECT: number; + + /** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */ + export const O_NONBLOCK: number; + + // File Type Constants + + /** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */ + export const S_IFMT: number; + + /** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */ + export const S_IFREG: number; + + /** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */ + export const S_IFDIR: number; + + /** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */ + export const S_IFCHR: number; + + /** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */ + export const S_IFBLK: number; + + /** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */ + export const S_IFIFO: number; + + /** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */ + export const S_IFLNK: number; + + /** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */ + export const S_IFSOCK: number; + + // File Mode Constants + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */ + export const S_IRWXU: number; + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */ + export const S_IRUSR: number; + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */ + export const S_IWUSR: number; + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */ + export const S_IXUSR: number; + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */ + export const S_IRWXG: number; + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */ + export const S_IRGRP: number; + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */ + export const S_IWGRP: number; + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */ + export const S_IXGRP: number; + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */ + export const S_IRWXO: number; + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */ + export const S_IROTH: number; + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */ + export const S_IWOTH: number; + + /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */ + export const S_IXOTH: number; + } + /** Tests a user's permissions for the file specified by path. */ - export function access(path: string, callback: (err: NodeJS.ErrnoException) => void): void; - export function access(path: string, mode: number, callback: (err: NodeJS.ErrnoException) => void): void; + export function access(path: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void; + export function access(path: string | Buffer, mode: number, callback: (err: NodeJS.ErrnoException) => void): void; /** Synchronous version of fs.access. This throws if any accessibility checks fail, and does nothing otherwise. */ - export function accessSync(path: string, mode ?: number): void; - export function createReadStream(path: string, options?: { + export function accessSync(path: string | Buffer, mode?: number): void; + export function createReadStream(path: string | Buffer, options?: { flags?: string; encoding?: string; - fd?: string; + fd?: number; mode?: number; - bufferSize?: number; + autoClose?: boolean; + start?: number; + end?: number; }): ReadStream; - export function createReadStream(path: string, options?: { - flags?: string; - encoding?: string; - fd?: string; - mode?: string; - bufferSize?: number; - }): ReadStream; - export function createWriteStream(path: string, options?: { + export function createWriteStream(path: string | Buffer, options?: { flags?: string; encoding?: string; + fd?: number; mode?: number; + autoClose?: boolean; + start?: number; }): WriteStream; + export function fdatasync(fd: number, callback: Function): void; + export function fdatasyncSync(fd: number): void; } declare module "path" { @@ -1444,43 +2555,43 @@ declare module "path" { export function format(pathObject: ParsedPath): string; export module posix { - export function normalize(p: string): string; - export function join(...paths: any[]): string; - export function resolve(...pathSegments: any[]): string; - export function isAbsolute(p: string): boolean; - export function relative(from: string, to: string): string; - export function dirname(p: string): string; - export function basename(p: string, ext?: string): string; - export function extname(p: string): string; - export var sep: string; - export var delimiter: string; - export function parse(p: string): ParsedPath; - export function format(pP: ParsedPath): string; + export function normalize(p: string): string; + export function join(...paths: any[]): string; + export function resolve(...pathSegments: any[]): string; + export function isAbsolute(p: string): boolean; + export function relative(from: string, to: string): string; + export function dirname(p: string): string; + export function basename(p: string, ext?: string): string; + export function extname(p: string): string; + export var sep: string; + export var delimiter: string; + export function parse(p: string): ParsedPath; + export function format(pP: ParsedPath): string; } export module win32 { - export function normalize(p: string): string; - export function join(...paths: any[]): string; - export function resolve(...pathSegments: any[]): string; - export function isAbsolute(p: string): boolean; - export function relative(from: string, to: string): string; - export function dirname(p: string): string; - export function basename(p: string, ext?: string): string; - export function extname(p: string): string; - export var sep: string; - export var delimiter: string; - export function parse(p: string): ParsedPath; - export function format(pP: ParsedPath): string; + export function normalize(p: string): string; + export function join(...paths: any[]): string; + export function resolve(...pathSegments: any[]): string; + export function isAbsolute(p: string): boolean; + export function relative(from: string, to: string): string; + export function dirname(p: string): string; + export function basename(p: string, ext?: string): string; + export function extname(p: string): string; + export var sep: string; + export var delimiter: string; + export function parse(p: string): ParsedPath; + export function format(pP: ParsedPath): string; } } declare module "string_decoder" { export interface NodeStringDecoder { write(buffer: Buffer): string; - detectIncompleteChar(buffer: Buffer): number; + end(buffer?: Buffer): string; } export var StringDecoder: { - new (encoding: string): NodeStringDecoder; + new (encoding?: string): NodeStringDecoder; }; } @@ -1492,42 +2603,222 @@ declare module "tls" { var CLIENT_RENEG_LIMIT: number; var CLIENT_RENEG_WINDOW: number; + export interface Certificate { + /** + * Country code. + */ + C: string; + /** + * Street. + */ + ST: string; + /** + * Locality. + */ + L: string; + /** + * Organization. + */ + O: string; + /** + * Organizational unit. + */ + OU: string; + /** + * Common name. + */ + CN: string; + } + + export interface CipherNameAndProtocol { + /** + * The cipher name. + */ + name: string; + /** + * SSL/TLS protocol version. + */ + version: string; + } + + export class TLSSocket extends stream.Duplex { + /** + * Returns the bound address, the address family name and port of the underlying socket as reported by + * the operating system. + * @returns {any} - An object with three properties, e.g. { port: 12346, family: 'IPv4', address: '127.0.0.1' }. + */ + address(): { port: number; family: string; address: string }; + /** + * A boolean that is true if the peer certificate was signed by one of the specified CAs, otherwise false. + */ + authorized: boolean; + /** + * The reason why the peer's certificate has not been verified. + * This property becomes available only when tlsSocket.authorized === false. + */ + authorizationError: Error; + /** + * Static boolean value, always true. + * May be used to distinguish TLS sockets from regular ones. + */ + encrypted: boolean; + /** + * Returns an object representing the cipher name and the SSL/TLS protocol version of the current connection. + * @returns {CipherNameAndProtocol} - Returns an object representing the cipher name + * and the SSL/TLS protocol version of the current connection. + */ + getCipher(): CipherNameAndProtocol; + /** + * Returns an object representing the peer's certificate. + * The returned object has some properties corresponding to the field of the certificate. + * If detailed argument is true the full chain with issuer property will be returned, + * if false only the top certificate without issuer property. + * If the peer does not provide a certificate, it returns null or an empty object. + * @param {boolean} detailed - If true; the full chain with issuer property will be returned. + * @returns {any} - An object representing the peer's certificate. + */ + getPeerCertificate(detailed?: boolean): { + subject: Certificate; + issuerInfo: Certificate; + issuer: Certificate; + raw: any; + valid_from: string; + valid_to: string; + fingerprint: string; + serialNumber: string; + }; + /** + * Could be used to speed up handshake establishment when reconnecting to the server. + * @returns {any} - ASN.1 encoded TLS session or undefined if none was negotiated. + */ + getSession(): any; + /** + * NOTE: Works only with client TLS sockets. + * Useful only for debugging, for session reuse provide session option to tls.connect(). + * @returns {any} - TLS session ticket or undefined if none was negotiated. + */ + getTLSTicket(): any; + /** + * The string representation of the local IP address. + */ + localAddress: string; + /** + * The numeric representation of the local port. + */ + localPort: string; + /** + * The string representation of the remote IP address. + * For example, '74.125.127.100' or '2001:4860:a005::68'. + */ + remoteAddress: string; + /** + * The string representation of the remote IP family. 'IPv4' or 'IPv6'. + */ + remoteFamily: string; + /** + * The numeric representation of the remote port. For example, 443. + */ + remotePort: number; + /** + * Initiate TLS renegotiation process. + * + * NOTE: Can be used to request peer's certificate after the secure connection has been established. + * ANOTHER NOTE: When running as the server, socket will be destroyed with an error after handshakeTimeout timeout. + * @param {TlsOptions} options - The options may contain the following fields: rejectUnauthorized, + * requestCert (See tls.createServer() for details). + * @param {Function} callback - callback(err) will be executed with null as err, once the renegotiation + * is successfully completed. + */ + renegotiate(options: TlsOptions, callback: (err: Error) => any): any; + /** + * Set maximum TLS fragment size (default and maximum value is: 16384, minimum is: 512). + * Smaller fragment size decreases buffering latency on the client: large fragments are buffered by + * the TLS layer until the entire fragment is received and its integrity is verified; + * large fragments can span multiple roundtrips, and their processing can be delayed due to packet + * loss or reordering. However, smaller fragments add extra TLS framing bytes and CPU overhead, + * which may decrease overall server throughput. + * @param {number} size - TLS fragment size (default and maximum value is: 16384, minimum is: 512). + * @returns {boolean} - Returns true on success, false otherwise. + */ + setMaxSendFragment(size: number): boolean; + + /** + * events.EventEmitter + * 1. OCSPResponse + * 2. secureConnect + **/ + addListener(event: string, listener: Function): this; + addListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + addListener(event: "secureConnect", listener: () => void): this; + + emit(event: string, ...args: any[]): boolean; + emit(event: "OCSPResponse", response: Buffer): boolean; + emit(event: "secureConnect"): boolean; + + on(event: string, listener: Function): this; + on(event: "OCSPResponse", listener: (response: Buffer) => void): this; + on(event: "secureConnect", listener: () => void): this; + + once(event: string, listener: Function): this; + once(event: "OCSPResponse", listener: (response: Buffer) => void): this; + once(event: "secureConnect", listener: () => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + prependListener(event: "secureConnect", listener: () => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; + prependOnceListener(event: "secureConnect", listener: () => void): this; + } + export interface TlsOptions { - pfx?: any; //string or buffer - key?: any; //string or buffer + host?: string; + port?: number; + pfx?: string | Buffer[]; + key?: string | string[] | Buffer | any[]; passphrase?: string; - cert?: any; - ca?: any; //string or buffer - crl?: any; //string or string array + cert?: string | string[] | Buffer | Buffer[]; + ca?: string | string[] | Buffer | Buffer[]; + crl?: string | string[]; ciphers?: string; - honorCipherOrder?: any; + honorCipherOrder?: boolean; requestCert?: boolean; rejectUnauthorized?: boolean; - NPNProtocols?: any; //array or Buffer; - SNICallback?: (servername: string) => any; + NPNProtocols?: string[] | Buffer; + SNICallback?: (servername: string, cb: (err: Error, ctx: SecureContext) => any) => any; + ecdhCurve?: string; + dhparam?: string | Buffer; + handshakeTimeout?: number; + ALPNProtocols?: string[] | Buffer; + sessionTimeout?: number; + ticketKeys?: any; + sessionIdContext?: string; + secureProtocol?: string; } export interface ConnectionOptions { host?: string; port?: number; socket?: net.Socket; - pfx?: any; //string | Buffer - key?: any; //string | Buffer + pfx?: string | Buffer + key?: string | string[] | Buffer | Buffer[]; passphrase?: string; - cert?: any; //string | Buffer - ca?: any; //Array of string | Buffer + cert?: string | string[] | Buffer | Buffer[]; + ca?: string | Buffer | (string | Buffer)[]; rejectUnauthorized?: boolean; - NPNProtocols?: any; //Array of string | Buffer + NPNProtocols?: (string | Buffer)[]; servername?: string; + path?: string; + ALPNProtocols?: (string | Buffer)[]; + checkServerIdentity?: (servername: string, cert: string | Buffer | (string | Buffer)[]) => any; + secureProtocol?: string; + secureContext?: Object; + session?: Buffer; + minDHSize?: number; } export interface Server extends net.Server { - // Extended base methods - listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; - listen(path: string, listeningListener?: Function): Server; - listen(handle: any, listeningListener?: Function): Server; - - listen(port: number, host?: string, callback?: Function): Server; close(): Server; address(): { port: number; family: string; address: string; }; addContext(hostName: string, credentials: { @@ -1537,6 +2828,56 @@ declare module "tls" { }): void; maxConnections: number; connections: number; + + /** + * events.EventEmitter + * 1. tlsClientError + * 2. newSession + * 3. OCSPRequest + * 4. resumeSession + * 5. secureConnection + **/ + addListener(event: string, listener: Function): this; + addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; + addListener(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this; + addListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this; + addListener(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this; + addListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; + + emit(event: string, ...args: any[]): boolean; + emit(event: "tlsClientError", err: Error, tlsSocket: TLSSocket): boolean; + emit(event: "newSession", sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void): boolean; + emit(event: "OCSPRequest", certificate: Buffer, issuer: Buffer, callback: Function): boolean; + emit(event: "resumeSession", sessionId: any, callback: (err: Error, sessionData: any) => void): boolean; + emit(event: "secureConnection", tlsSocket: TLSSocket): boolean; + + on(event: string, listener: Function): this; + on(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; + on(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this; + on(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this; + on(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this; + on(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; + + once(event: string, listener: Function): this; + once(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; + once(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this; + once(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this; + once(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this; + once(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; + prependListener(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this; + prependListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this; + prependListener(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this; + prependListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; + prependOnceListener(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this; + prependOnceListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this; + prependOnceListener(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this; + prependOnceListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; } export interface ClearTextStream extends stream.Duplex { @@ -1562,12 +2903,12 @@ declare module "tls" { } export interface SecureContextOptions { - pfx?: any; //string | buffer - key?: any; //string | buffer + pfx?: string | Buffer; + key?: string | Buffer; passphrase?: string; - cert?: any; // string | buffer - ca?: any; // string | buffer - crl?: any; // string | string[] + cert?: string | Buffer; + ca?: string | Buffer; + crl?: string | string[] ciphers?: string; honorCipherOrder?: boolean; } @@ -1576,178 +2917,397 @@ declare module "tls" { context: any; } - export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; - export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; - export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; - export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; + export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) => void): Server; + export function connect(options: ConnectionOptions, secureConnectionListener?: () => void): ClearTextStream; + export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () => void): ClearTextStream; + export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () => void): ClearTextStream; export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; export function createSecureContext(details: SecureContextOptions): SecureContext; } declare module "crypto" { + export interface Certificate { + exportChallenge(spkac: string | Buffer): Buffer; + exportPublicKey(spkac: string | Buffer): Buffer; + verifySpkac(spkac: Buffer): boolean; + } + export var Certificate: { + new (): Certificate; + (): Certificate; + } + + export var fips: boolean; + export interface CredentialDetails { pfx: string; key: string; passphrase: string; cert: string; - ca: any; //string | string array - crl: any; //string | string array + ca: string | string[]; + crl: string | string[]; ciphers: string; } export interface Credentials { context?: any; } export function createCredentials(details: CredentialDetails): Credentials; export function createHash(algorithm: string): Hash; - export function createHmac(algorithm: string, key: string): Hmac; - export function createHmac(algorithm: string, key: Buffer): Hmac; - interface Hash { - update(data: any, input_encoding?: string): Hash; - digest(encoding: 'buffer'): Buffer; - digest(encoding: string): any; + export function createHmac(algorithm: string, key: string | Buffer): Hmac; + + type Utf8AsciiLatin1Encoding = "utf8" | "ascii" | "latin1"; + type HexBase64Latin1Encoding = "latin1" | "hex" | "base64"; + type Utf8AsciiBinaryEncoding = "utf8" | "ascii" | "binary"; + type HexBase64BinaryEncoding = "binary" | "base64" | "hex"; + type ECDHKeyFormat = "compressed" | "uncompressed" | "hybrid"; + + export interface Hash extends NodeJS.ReadWriteStream { + update(data: string | Buffer): Hash; + update(data: string | Buffer, input_encoding: Utf8AsciiLatin1Encoding): Hash; digest(): Buffer; + digest(encoding: HexBase64Latin1Encoding): string; } - interface Hmac { - update(data: any, input_encoding?: string): Hmac; - digest(encoding: 'buffer'): Buffer; - digest(encoding: string): any; + export interface Hmac extends NodeJS.ReadWriteStream { + update(data: string | Buffer): Hmac; + update(data: string | Buffer, input_encoding: Utf8AsciiLatin1Encoding): Hmac; digest(): Buffer; + digest(encoding: HexBase64Latin1Encoding): string; } export function createCipher(algorithm: string, password: any): Cipher; export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; - interface Cipher { + export interface Cipher extends NodeJS.ReadWriteStream { update(data: Buffer): Buffer; - update(data: string, input_encoding?: string, output_encoding?: string): string; + update(data: string, input_encoding: Utf8AsciiBinaryEncoding): Buffer; + update(data: Buffer, input_encoding: any, output_encoding: HexBase64BinaryEncoding): string; + update(data: string, input_encoding: Utf8AsciiBinaryEncoding, output_encoding: HexBase64BinaryEncoding): string; final(): Buffer; final(output_encoding: string): string; - setAutoPadding(auto_padding: boolean): void; + setAutoPadding(auto_padding?: boolean): void; + getAuthTag(): Buffer; + setAAD(buffer: Buffer): void; } export function createDecipher(algorithm: string, password: any): Decipher; export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; - interface Decipher { + export interface Decipher extends NodeJS.ReadWriteStream { update(data: Buffer): Buffer; - update(data: string, input_encoding?: string, output_encoding?: string): string; + update(data: string, input_encoding: HexBase64BinaryEncoding): Buffer; + update(data: Buffer, input_encoding: any, output_encoding: Utf8AsciiBinaryEncoding): string; + update(data: string, input_encoding: HexBase64BinaryEncoding, output_encoding: Utf8AsciiBinaryEncoding): string; final(): Buffer; final(output_encoding: string): string; - setAutoPadding(auto_padding: boolean): void; + setAutoPadding(auto_padding?: boolean): void; + setAuthTag(tag: Buffer): void; + setAAD(buffer: Buffer): void; } export function createSign(algorithm: string): Signer; - interface Signer extends NodeJS.WritableStream { - update(data: any): void; - sign(private_key: string, output_format: string): string; + export interface Signer extends NodeJS.WritableStream { + update(data: string | Buffer): Signer; + update(data: string | Buffer, input_encoding: Utf8AsciiLatin1Encoding): Signer; + sign(private_key: string | { key: string; passphrase: string }): Buffer; + sign(private_key: string | { key: string; passphrase: string }, output_format: HexBase64Latin1Encoding): string; } export function createVerify(algorith: string): Verify; - interface Verify extends NodeJS.WritableStream { - update(data: any): void; - verify(object: string, signature: string, signature_format?: string): boolean; - } - export function createDiffieHellman(prime_length: number): DiffieHellman; - export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; - interface DiffieHellman { - generateKeys(encoding?: string): string; - computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; - getPrime(encoding?: string): string; - getGenerator(encoding: string): string; - getPublicKey(encoding?: string): string; - getPrivateKey(encoding?: string): string; - setPublicKey(public_key: string, encoding?: string): void; - setPrivateKey(public_key: string, encoding?: string): void; + export interface Verify extends NodeJS.WritableStream { + update(data: string | Buffer): Verify; + update(data: string | Buffer, input_encoding: Utf8AsciiLatin1Encoding): Verify; + verify(object: string, signature: Buffer): boolean; + verify(object: string, signature: string, signature_format: HexBase64Latin1Encoding): boolean; + } + export function createDiffieHellman(prime_length: number, generator?: number): DiffieHellman; + export function createDiffieHellman(prime: Buffer): DiffieHellman; + export function createDiffieHellman(prime: string, prime_encoding: HexBase64Latin1Encoding): DiffieHellman; + export function createDiffieHellman(prime: string, prime_encoding: HexBase64Latin1Encoding, generator: number | Buffer): DiffieHellman; + export function createDiffieHellman(prime: string, prime_encoding: HexBase64Latin1Encoding, generator: string, generator_encoding: HexBase64Latin1Encoding): DiffieHellman; + export interface DiffieHellman { + generateKeys(): Buffer; + generateKeys(encoding: HexBase64Latin1Encoding): string; + computeSecret(other_public_key: Buffer): Buffer; + computeSecret(other_public_key: string, input_encoding: HexBase64Latin1Encoding): Buffer; + computeSecret(other_public_key: string, input_encoding: HexBase64Latin1Encoding, output_encoding: HexBase64Latin1Encoding): string; + getPrime(): Buffer; + getPrime(encoding: HexBase64Latin1Encoding): string; + getGenerator(): Buffer; + getGenerator(encoding: HexBase64Latin1Encoding): string; + getPublicKey(): Buffer; + getPublicKey(encoding: HexBase64Latin1Encoding): string; + getPrivateKey(): Buffer; + getPrivateKey(encoding: HexBase64Latin1Encoding): string; + setPublicKey(public_key: Buffer): void; + setPublicKey(public_key: string, encoding: string): void; + setPrivateKey(private_key: Buffer): void; + setPrivateKey(private_key: string, encoding: string): void; + verifyError: number; } export function getDiffieHellman(group_name: string): DiffieHellman; - export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; - export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, digest: string, callback: (err: Error, derivedKey: Buffer) => any): void; - export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number) : Buffer; - export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number, digest: string) : Buffer; + export function pbkdf2(password: string | Buffer, salt: string | Buffer, iterations: number, keylen: number, digest: string, callback: (err: Error, derivedKey: Buffer) => any): void; + export function pbkdf2Sync(password: string | Buffer, salt: string | Buffer, iterations: number, keylen: number, digest: string): Buffer; export function randomBytes(size: number): Buffer; - export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; + export function randomBytes(size: number, callback: (err: Error, buf: Buffer) => void): void; export function pseudoRandomBytes(size: number): Buffer; - export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; + export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) => void): void; + export interface RsaPublicKey { + key: string; + padding?: number; + } + export interface RsaPrivateKey { + key: string; + passphrase?: string, + padding?: number; + } + export function publicEncrypt(public_key: string | RsaPublicKey, buffer: Buffer): Buffer + export function privateDecrypt(private_key: string | RsaPrivateKey, buffer: Buffer): Buffer + export function privateEncrypt(private_key: string | RsaPrivateKey, buffer: Buffer): Buffer + export function publicDecrypt(public_key: string | RsaPublicKey, buffer: Buffer): Buffer + export function getCiphers(): string[]; + export function getCurves(): string[]; + export function getHashes(): string[]; + export interface ECDH { + generateKeys(): Buffer; + generateKeys(encoding: HexBase64Latin1Encoding): string; + generateKeys(encoding: HexBase64Latin1Encoding, format: ECDHKeyFormat): string; + computeSecret(other_public_key: Buffer): Buffer; + computeSecret(other_public_key: string, input_encoding: HexBase64Latin1Encoding): Buffer; + computeSecret(other_public_key: string, input_encoding: HexBase64Latin1Encoding, output_encoding: HexBase64Latin1Encoding): string; + getPrivateKey(): Buffer; + getPrivateKey(encoding: HexBase64Latin1Encoding): string; + getPublicKey(): Buffer; + getPublicKey(encoding: HexBase64Latin1Encoding): string; + getPublicKey(encoding: HexBase64Latin1Encoding, format: ECDHKeyFormat): string; + setPrivateKey(private_key: Buffer): void; + setPrivateKey(private_key: string, encoding: HexBase64Latin1Encoding): void; + } + export function createECDH(curve_name: string): ECDH; + export function timingSafeEqual(a: Buffer, b: Buffer): boolean; + export var DEFAULT_ENCODING: string; } declare module "stream" { import * as events from "events"; - export interface Stream extends events.EventEmitter { + class internal extends events.EventEmitter { pipe(destination: T, options?: { end?: boolean; }): T; } + namespace internal { - export interface ReadableOptions { - highWaterMark?: number; - encoding?: string; - objectMode?: boolean; - } + export class Stream extends internal { } - export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { - readable: boolean; - constructor(opts?: ReadableOptions); - _read(size: number): void; - read(size?: number): any; - setEncoding(encoding: string): void; - pause(): void; - resume(): void; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; - unshift(chunk: any): void; - wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; - push(chunk: any, encoding?: string): boolean; - } + export interface ReadableOptions { + highWaterMark?: number; + encoding?: string; + objectMode?: boolean; + read?: (size?: number) => any; + } - export interface WritableOptions { - highWaterMark?: number; - decodeStrings?: boolean; - } + export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { + readable: boolean; + constructor(opts?: ReadableOptions); + _read(size: number): void; + read(size?: number): any; + setEncoding(encoding: string): void; + pause(): Readable; + resume(): Readable; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; + unshift(chunk: any): void; + wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; + push(chunk: any, encoding?: string): boolean; + + /** + * Event emitter + * The defined events on documents including: + * 1. close + * 2. data + * 3. end + * 4. readable + * 5. error + **/ + addListener(event: string, listener: Function): this; + addListener(event: string, listener: Function): this; + addListener(event: "close", listener: () => void): this; + addListener(event: "data", listener: (chunk: Buffer | string) => void): this; + addListener(event: "end", listener: () => void): this; + addListener(event: "readable", listener: () => void): this; + addListener(event: "error", listener: (err: Error) => void): this; + + emit(event: string, ...args: any[]): boolean; + emit(event: "close"): boolean; + emit(event: "data", chunk: Buffer | string): boolean; + emit(event: "end"): boolean; + emit(event: "readable"): boolean; + emit(event: "error", err: Error): boolean; + + on(event: string, listener: Function): this; + on(event: "close", listener: () => void): this; + on(event: "data", listener: (chunk: Buffer | string) => void): this; + on(event: "end", listener: () => void): this; + on(event: "readable", listener: () => void): this; + on(event: "error", listener: (err: Error) => void): this; + + once(event: string, listener: Function): this; + once(event: "close", listener: () => void): this; + once(event: "data", listener: (chunk: Buffer | string) => void): this; + once(event: "end", listener: () => void): this; + once(event: "readable", listener: () => void): this; + once(event: "error", listener: (err: Error) => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "close", listener: () => void): this; + prependListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependListener(event: "end", listener: () => void): this; + prependListener(event: "readable", listener: () => void): this; + prependListener(event: "error", listener: (err: Error) => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "close", listener: () => void): this; + prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this; + prependOnceListener(event: "end", listener: () => void): this; + prependOnceListener(event: "readable", listener: () => void): this; + prependOnceListener(event: "error", listener: (err: Error) => void): this; + + removeListener(event: string, listener: Function): this; + removeListener(event: "close", listener: () => void): this; + removeListener(event: "data", listener: (chunk: Buffer | string) => void): this; + removeListener(event: "end", listener: () => void): this; + removeListener(event: "readable", listener: () => void): this; + removeListener(event: "error", listener: (err: Error) => void): this; + } - export class Writable extends events.EventEmitter implements NodeJS.WritableStream { - writable: boolean; - constructor(opts?: WritableOptions); - _write(chunk: any, encoding: string, callback: Function): void; - write(chunk: any, cb?: Function): boolean; - write(chunk: any, encoding?: string, cb?: Function): boolean; - end(): void; - end(chunk: any, cb?: Function): void; - end(chunk: any, encoding?: string, cb?: Function): void; - } + export interface WritableOptions { + highWaterMark?: number; + decodeStrings?: boolean; + objectMode?: boolean; + write?: (chunk: string | Buffer, encoding: string, callback: Function) => any; + writev?: (chunks: { chunk: string | Buffer, encoding: string }[], callback: Function) => any; + } - export interface DuplexOptions extends ReadableOptions, WritableOptions { - allowHalfOpen?: boolean; - } + export class Writable extends events.EventEmitter implements NodeJS.WritableStream { + writable: boolean; + constructor(opts?: WritableOptions); + _write(chunk: any, encoding: string, callback: Function): void; + write(chunk: any, cb?: Function): boolean; + write(chunk: any, encoding?: string, cb?: Function): boolean; + end(): void; + end(chunk: any, cb?: Function): void; + end(chunk: any, encoding?: string, cb?: Function): void; + + /** + * Event emitter + * The defined events on documents including: + * 1. close + * 2. drain + * 3. error + * 4. finish + * 5. pipe + * 6. unpipe + **/ + addListener(event: string, listener: Function): this; + addListener(event: "close", listener: () => void): this; + addListener(event: "drain", listener: () => void): this; + addListener(event: "error", listener: (err: Error) => void): this; + addListener(event: "finish", listener: () => void): this; + addListener(event: "pipe", listener: (src: Readable) => void): this; + addListener(event: "unpipe", listener: (src: Readable) => void): this; + + emit(event: string, ...args: any[]): boolean; + emit(event: "close"): boolean; + emit(event: "drain", chunk: Buffer | string): boolean; + emit(event: "error", err: Error): boolean; + emit(event: "finish"): boolean; + emit(event: "pipe", src: Readable): boolean; + emit(event: "unpipe", src: Readable): boolean; + + on(event: string, listener: Function): this; + on(event: "close", listener: () => void): this; + on(event: "drain", listener: () => void): this; + on(event: "error", listener: (err: Error) => void): this; + on(event: "finish", listener: () => void): this; + on(event: "pipe", listener: (src: Readable) => void): this; + on(event: "unpipe", listener: (src: Readable) => void): this; + + once(event: string, listener: Function): this; + once(event: "close", listener: () => void): this; + once(event: "drain", listener: () => void): this; + once(event: "error", listener: (err: Error) => void): this; + once(event: "finish", listener: () => void): this; + once(event: "pipe", listener: (src: Readable) => void): this; + once(event: "unpipe", listener: (src: Readable) => void): this; + + prependListener(event: string, listener: Function): this; + prependListener(event: "close", listener: () => void): this; + prependListener(event: "drain", listener: () => void): this; + prependListener(event: "error", listener: (err: Error) => void): this; + prependListener(event: "finish", listener: () => void): this; + prependListener(event: "pipe", listener: (src: Readable) => void): this; + prependListener(event: "unpipe", listener: (src: Readable) => void): this; + + prependOnceListener(event: string, listener: Function): this; + prependOnceListener(event: "close", listener: () => void): this; + prependOnceListener(event: "drain", listener: () => void): this; + prependOnceListener(event: "error", listener: (err: Error) => void): this; + prependOnceListener(event: "finish", listener: () => void): this; + prependOnceListener(event: "pipe", listener: (src: Readable) => void): this; + prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this; + + removeListener(event: string, listener: Function): this; + removeListener(event: "close", listener: () => void): this; + removeListener(event: "drain", listener: () => void): this; + removeListener(event: "error", listener: (err: Error) => void): this; + removeListener(event: "finish", listener: () => void): this; + removeListener(event: "pipe", listener: (src: Readable) => void): this; + removeListener(event: "unpipe", listener: (src: Readable) => void): this; + } - // Note: Duplex extends both Readable and Writable. - export class Duplex extends Readable implements NodeJS.ReadWriteStream { - writable: boolean; - constructor(opts?: DuplexOptions); - _write(chunk: any, encoding: string, callback: Function): void; - write(chunk: any, cb?: Function): boolean; - write(chunk: any, encoding?: string, cb?: Function): boolean; - end(): void; - end(chunk: any, cb?: Function): void; - end(chunk: any, encoding?: string, cb?: Function): void; - } + export interface DuplexOptions extends ReadableOptions, WritableOptions { + allowHalfOpen?: boolean; + readableObjectMode?: boolean; + writableObjectMode?: boolean; + } - export interface TransformOptions extends ReadableOptions, WritableOptions {} + // Note: Duplex extends both Readable and Writable. + export class Duplex extends Readable implements NodeJS.ReadWriteStream { + // Readable + pause(): Duplex; + resume(): Duplex; + // Writeable + writable: boolean; + constructor(opts?: DuplexOptions); + _write(chunk: any, encoding: string, callback: Function): void; + write(chunk: any, cb?: Function): boolean; + write(chunk: any, encoding?: string, cb?: Function): boolean; + end(): void; + end(chunk: any, cb?: Function): void; + end(chunk: any, encoding?: string, cb?: Function): void; + } - // Note: Transform lacks the _read and _write methods of Readable/Writable. - export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { - readable: boolean; - writable: boolean; - constructor(opts?: TransformOptions); - _transform(chunk: any, encoding: string, callback: Function): void; - _flush(callback: Function): void; - read(size?: number): any; - setEncoding(encoding: string): void; - pause(): void; - resume(): void; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; - unshift(chunk: any): void; - wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; - push(chunk: any, encoding?: string): boolean; - write(chunk: any, cb?: Function): boolean; - write(chunk: any, encoding?: string, cb?: Function): boolean; - end(): void; - end(chunk: any, cb?: Function): void; - end(chunk: any, encoding?: string, cb?: Function): void; + export interface TransformOptions extends DuplexOptions { + transform?: (chunk: string | Buffer, encoding: string, callback: Function) => any; + flush?: (callback: Function) => any; + } + + // Note: Transform lacks the _read and _write methods of Readable/Writable. + export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { + readable: boolean; + writable: boolean; + constructor(opts?: TransformOptions); + _transform(chunk: any, encoding: string, callback: Function): void; + _flush(callback: Function): void; + read(size?: number): any; + setEncoding(encoding: string): void; + pause(): Transform; + resume(): Transform; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; + unshift(chunk: any): void; + wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; + push(chunk: any, encoding?: string): boolean; + write(chunk: any, cb?: Function): boolean; + write(chunk: any, encoding?: string, cb?: Function): boolean; + end(): void; + end(chunk: any, cb?: Function): void; + end(chunk: any, encoding?: string, cb?: Function): void; + } + + export class PassThrough extends Transform { } } - export class PassThrough extends Transform {} + export = internal; } declare module "util" { @@ -1771,12 +3331,24 @@ declare module "util" { export function isDate(object: any): boolean; export function isError(object: any): boolean; export function inherits(constructor: any, superConstructor: any): void; - export function debuglog(key:string): (msg:string,...param: any[])=>void; + export function debuglog(key: string): (msg: string, ...param: any[]) => void; + export function isBoolean(object: any): boolean; + export function isBuffer(object: any): boolean; + export function isFunction(object: any): boolean; + export function isNull(object: any): boolean; + export function isNullOrUndefined(object: any): boolean; + export function isNumber(object: any): boolean; + export function isObject(object: any): boolean; + export function isPrimitive(object: any): boolean; + export function isString(object: any): boolean; + export function isSymbol(object: any): boolean; + export function isUndefined(object: any): boolean; + export function deprecate(fn: Function, message: string): Function; } declare module "assert" { - function internal (value: any, message?: string): void; - module internal { + function internal(value: any, message?: string): void; + namespace internal { export class AssertionError implements Error { name: string; message: string; @@ -1785,11 +3357,13 @@ declare module "assert" { operator: string; generatedMessage: boolean; - constructor(options?: {message?: string; actual?: any; expected?: any; - operator?: string; stackStartFunction?: Function}); + constructor(options?: { + message?: string; actual?: any; expected?: any; + operator?: string; stackStartFunction?: Function + }); } - export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; + export function fail(actual: any, expected: any, message: string, operator: string): void; export function ok(value: any, message?: string): void; export function equal(actual: any, expected: any, message?: string): void; export function notEqual(actual: any, expected: any, message?: string): void; @@ -1797,6 +3371,8 @@ declare module "assert" { export function notDeepEqual(acutal: any, expected: any, message?: string): void; export function strictEqual(actual: any, expected: any, message?: string): void; export function notStrictEqual(actual: any, expected: any, message?: string): void; + export function deepStrictEqual(actual: any, expected: any, message?: string): void; + export function notDeepStrictEqual(actual: any, expected: any, message?: string): void; export var throws: { (block: Function, message?: string): void; (block: Function, error: Function, message?: string): void; @@ -1824,29 +3400,28 @@ declare module "tty" { export interface ReadStream extends net.Socket { isRaw: boolean; setRawMode(mode: boolean): void; + isTTY: boolean; } export interface WriteStream extends net.Socket { columns: number; rows: number; + isTTY: boolean; } } declare module "domain" { import * as events from "events"; - export class Domain extends events.EventEmitter { + export class Domain extends events.EventEmitter implements NodeJS.Domain { run(fn: Function): void; add(emitter: events.EventEmitter): void; remove(emitter: events.EventEmitter): void; bind(cb: (err: Error, data: any) => any): any; intercept(cb: (data: any) => any): any; dispose(): void; - - addListener(event: string, listener: Function): Domain; - on(event: string, listener: Function): Domain; - once(event: string, listener: Function): Domain; - removeListener(event: string, listener: Function): Domain; - removeAllListeners(event?: string): Domain; + members: any[]; + enter(): void; + exit(): void; } export function create(): Domain; @@ -2064,9 +3639,32 @@ declare module "constants" { export var S_IFREG: number; export var S_IFDIR: number; export var S_IFCHR: number; + export var S_IFBLK: number; + export var S_IFIFO: number; + export var S_IFSOCK: number; + export var S_IRWXU: number; + export var S_IRUSR: number; + export var S_IWUSR: number; + export var S_IXUSR: number; + export var S_IRWXG: number; + export var S_IRGRP: number; + export var S_IWGRP: number; + export var S_IXGRP: number; + export var S_IRWXO: number; + export var S_IROTH: number; + export var S_IWOTH: number; + export var S_IXOTH: number; export var S_IFLNK: number; export var O_CREAT: number; export var O_EXCL: number; + export var O_NOCTTY: number; + export var O_DIRECTORY: number; + export var O_NOATIME: number; + export var O_NOFOLLOW: number; + export var O_SYNC: number; + export var O_SYMLINK: number; + export var O_DIRECT: number; + export var O_NONBLOCK: number; export var O_TRUNC: number; export var O_APPEND: number; export var F_OK: number; @@ -2074,4 +3672,63 @@ declare module "constants" { export var W_OK: number; export var X_OK: number; export var UV_UDP_REUSEADDR: number; + export var SIGQUIT: number; + export var SIGTRAP: number; + export var SIGIOT: number; + export var SIGBUS: number; + export var SIGUSR1: number; + export var SIGUSR2: number; + export var SIGPIPE: number; + export var SIGALRM: number; + export var SIGCHLD: number; + export var SIGSTKFLT: number; + export var SIGCONT: number; + export var SIGSTOP: number; + export var SIGTSTP: number; + export var SIGTTIN: number; + export var SIGTTOU: number; + export var SIGURG: number; + export var SIGXCPU: number; + export var SIGXFSZ: number; + export var SIGVTALRM: number; + export var SIGPROF: number; + export var SIGIO: number; + export var SIGPOLL: number; + export var SIGPWR: number; + export var SIGSYS: number; + export var SIGUNUSED: number; + export var defaultCoreCipherList: string; + export var defaultCipherList: string; + export var ENGINE_METHOD_RSA: number; + export var ALPN_ENABLED: number; +} + +declare module "process" { + export = process; +} + +declare module "v8" { + interface HeapSpaceInfo { + space_name: string; + space_size: number; + space_used_size: number; + space_available_size: number; + physical_space_size: number; + } + export function getHeapStatistics(): { total_heap_size: number, total_heap_size_executable: number, total_physical_size: number, total_avaialble_size: number, used_heap_size: number, heap_size_limit: number }; + export function getHeapSpaceStatistics(): HeapSpaceInfo[]; + export function setFlagsFromString(flags: string): void; +} + +declare module "timers" { + export function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; + export function clearTimeout(timeoutId: NodeJS.Timer): void; + export function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; + export function clearInterval(intervalId: NodeJS.Timer): void; + export function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; + export function clearImmediate(immediateId: any): void; +} + +declare module "console" { + export = console; } diff --git a/typings/tsd.d.ts b/typings/tsd.d.ts new file mode 100644 index 00000000000..2781e558d17 --- /dev/null +++ b/typings/tsd.d.ts @@ -0,0 +1,10 @@ +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// diff --git a/typings/underscore.string/underscore.string.d.ts b/typings/underscore.string/underscore.string.d.ts index 1b08dcf852d..ef4033d6836 100644 --- a/typings/underscore.string/underscore.string.d.ts +++ b/typings/underscore.string/underscore.string.d.ts @@ -1,7 +1,7 @@ // Type definitions for underscore.string // Project: https://github.com/epeli/underscore.string // Definitions by: Ry Racherbaumer -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -66,6 +66,13 @@ interface UnderscoreStringStaticExports { * @param str */ capitalize(str: string): string; + + /** + * Converts first letter of the string to lowercase. + * ('Foo Bar') => 'foo Bar' + * @param str + */ + decapitalize(str: string): string; /** * Chop a string into pieces. @@ -300,7 +307,7 @@ interface UnderscoreStringStaticExports { * @param delimiter */ words(str: string): string[]; - + /** * Split string by delimiter (String or RegExp). * /\s+/ by default. diff --git a/typings/underscore/underscore.d.ts b/typings/underscore/underscore.d.ts index 7dea66a84ac..d8d08a3b756 100644 --- a/typings/underscore/underscore.d.ts +++ b/typings/underscore/underscore.d.ts @@ -1,7 +1,7 @@ -// Type definitions for Underscore 1.7.0 +// Type definitions for Underscore 1.8.3 // Project: http://underscorejs.org/ -// Definitions by: Boris Yankov , Josh Baldwin -// Definitions: https://github.com/borisyankov/DefinitelyTyped +// Definitions by: Boris Yankov , Josh Baldwin , Christopher Currens +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare module _ { /** @@ -39,6 +39,12 @@ declare module _ { * Default value is '/<%-([\s\S]+?)%>/g'. **/ escape?: RegExp; + + /** + * By default, 'template()' places the values from your data in the local scope via the 'with' statement. + * However, you can specify a single variable name with this setting. + **/ + variable?: string; } interface Collection { } @@ -68,6 +74,10 @@ declare module _ { interface MemoObjectIterator { (prev: TResult, curr: T, key: string, list: Dictionary): TResult; } + + interface Cancelable { + cancel() : void; + } } interface UnderscoreStatic { @@ -76,6 +86,7 @@ interface UnderscoreStatic { * as the first parameter can be invoked through this function. * @param key First argument to Underscore object functions. **/ + (value: _.Dictionary): Underscore; (value: Array): Underscore; (value: T): Underscore; @@ -254,6 +265,20 @@ interface UnderscoreStatic { iterator: _.ObjectIterator, context?: any): T; + /** + * @see _.find + **/ + find( + object: _.List|_.Dictionary, + iterator: U): T; + + /** + * @see _.find + **/ + find( + object: _.List|_.Dictionary, + iterator: string): T; + /** * @see _.find **/ @@ -268,22 +293,21 @@ interface UnderscoreStatic { detect( object: _.Dictionary, iterator: _.ObjectIterator, - context?: any): T; + context?: any): T; - /** - * Looks through each value in the list, returning the index of the first one that passes a truth - * test (iterator). The function returns as soon as it finds an acceptable element, - * and doesn't traverse the entire list. - * @param list Searches for a value in this list. - * @param iterator Search iterator function for each element in `list`. - * @param context `this` object in `iterator`, optional. - * @return The index of the first acceptable found element in `list`, if nothing is found -1 is returned. + /** + * @see _.find **/ - findIndex( - list: _.List, - iterator: _.ListIterator, - context?: any): number; + detect( + object: _.List|_.Dictionary, + iterator: U): T; + /** + * @see _.find + **/ + detect( + object: _.List|_.Dictionary, + iterator: string): T; /** * Looks through each value in the list, returning an array of all the values that pass a truth @@ -439,6 +463,10 @@ interface UnderscoreStatic { iterator?: _.ObjectIterator, context?: any): boolean; + any( + list: _.List, + value: T): boolean; + /** * Returns true if the value is present in the list. Uses indexOf internally, * if list is an Array. @@ -448,7 +476,8 @@ interface UnderscoreStatic { **/ contains( list: _.List, - value: T): boolean; + value: T, + fromIndex?: number): boolean; /** * @see _.contains @@ -462,7 +491,8 @@ interface UnderscoreStatic { **/ include( list: _.Collection, - value: T): boolean; + value: T, + fromIndex?: number): boolean; /** * @see _.contains @@ -471,6 +501,21 @@ interface UnderscoreStatic { object: _.Dictionary, value: T): boolean; + /** + * @see _.contains + **/ + includes( + list: _.Collection, + value: T, + fromIndex?: number): boolean; + + /** + * @see _.contains + **/ + includes( + object: _.Dictionary, + value: T): boolean; + /** * Calls the method named by methodName on each value in the list. Any extra arguments passed to * invoke will be forwarded on to the method invocation. @@ -501,6 +546,11 @@ interface UnderscoreStatic { **/ max(list: _.List): number; + /** + * @see _.max + */ + max(object: _.Dictionary): number; + /** * Returns the maximum value in list. If iterator is passed, it will be used on each value to generate * the criterion by which the value is ranked. @@ -514,6 +564,14 @@ interface UnderscoreStatic { iterator?: _.ListIterator, context?: any): T; + /** + * @see _.max + */ + max( + list: _.Dictionary, + iterator?: _.ObjectIterator, + context?: any): T; + /** * Returns the minimum value in list. * @param list Finds the minimum value in this list. @@ -521,6 +579,11 @@ interface UnderscoreStatic { **/ min(list: _.List): number; + /** + * @see _.min + */ + min(o: _.Dictionary): number; + /** * Returns the minimum value in list. If iterator is passed, it will be used on each value to generate * the criterion by which the value is ranked. @@ -534,6 +597,14 @@ interface UnderscoreStatic { iterator?: _.ListIterator, context?: any): T; + /** + * @see _.min + */ + min( + list: _.Dictionary, + iterator?: _.ObjectIterator, + context?: any): T; + /** * Returns a sorted copy of list, ranked in ascending order by the results of running each value * through iterator. Iterator may also be the string name of the property to sort by (eg. length). @@ -655,7 +726,7 @@ interface UnderscoreStatic { size(list: _.Collection): number; /** - * Split array into two arrays: + * Split array into two arrays: * one whose elements all satisfy predicate and one whose elements all do not satisfy predicate. * @param array Array to split in two. * @param iterator Filter iterator function for each element in `array`. @@ -872,6 +943,16 @@ interface UnderscoreStatic { **/ zip(...arrays: any[]): any[]; + /** + * The opposite of zip. Given a number of arrays, returns a series of new arrays, the first + * of which contains all of the first elements in the input arrays, the second of which + * contains all of the second elements, and so on. Use with apply to pass in an array + * of arrays + * @param arrays The arrays to unzip. + * @return Unzipped version of `arrays`. + **/ + unzip(...arrays: any[][]): any[][]; + /** * Converts arrays into objects. Pass either a single list of [key, value] pairs, or a * list of keys, and a list of values. @@ -934,6 +1015,30 @@ interface UnderscoreStatic { value: T, from?: number): number; + /** + * Returns the first index of an element in `array` where the predicate truth test passes + * @param array The array to search for the index of the first element where the predicate truth test passes. + * @param predicate Predicate function. + * @param context `this` object in `predicate`, optional. + * @return Returns the index of an element in `array` where the predicate truth test passes or -1.` + **/ + findIndex( + array: _.List, + predicate: _.ListIterator | {}, + context?: any): number; + + /** + * Returns the last index of an element in `array` where the predicate truth test passes + * @param array The array to search for the index of the last element where the predicate truth test passes. + * @param predicate Predicate function. + * @param context `this` object in `predicate`, optional. + * @return Returns the index of an element in `array` where the predicate truth test passes or -1.` + **/ + findLastIndex( + array: _.List, + predicate: _.ListIterator | {}, + context?: any): number; + /** * Uses a binary search to determine the index at which the value should be inserted into the list in order * to maintain the list's sorted order. If an iterator is passed, it will be used to compute the sort ranking @@ -971,6 +1076,14 @@ interface UnderscoreStatic { **/ range(stop: number): number[]; + /** + * Split an **array** into several arrays containing **count** or less elements + * of initial array. + * @param array The array to split + * @param count The maximum size of the inner arrays. + */ + chunk(array: _.Collection, count: number): (_.Collection)[] + /************* * Functions * *************/ @@ -1003,15 +1116,2291 @@ interface UnderscoreStatic { /** * Partially apply a function by filling in any number of its arguments, without changing its dynamic this value. - * A close cousin of bind. You may pass _ in your list of arguments to specify an argument that should not be - * pre-filled, but left open to supply at call-time. + * A close cousin of bind. You may pass _ in your list of arguments to specify an argument that should not be + * pre-filled, but left open to supply at call-time. * @param fn Function to partially fill in arguments. * @param arguments The partial arguments. * @return `fn` with partially filled in arguments. **/ - partial( - fn: Function, - ...arguments: any[]): Function; + + partial( + fn: { (p1: T1):T2 }, + p1: T1 + ): { (): T2 }; + + partial( + fn: { (p1: T1, p2: T2):T3 }, + p1: T1 + ): { (p2: T2): T3 }; + + partial( + fn: { (p1: T1, p2: T2):T3 }, + p1: T1, + p2: T2 + ): { (): T3 }; + + partial( + fn: { (p1: T1, p2: T2):T3 }, + stub1: UnderscoreStatic, + p2: T2 + ): { (p1: T1): T3 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3):T4 }, + p1: T1 + ): { (p2: T2, p3: T3): T4 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3):T4 }, + p1: T1, + p2: T2 + ): { (p3: T3): T4 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3):T4 }, + stub1: UnderscoreStatic, + p2: T2 + ): { (p1: T1, p3: T3): T4 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3):T4 }, + p1: T1, + p2: T2, + p3: T3 + ): { (): T4 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3):T4 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3 + ): { (p1: T1): T4 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3):T4 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3 + ): { (p2: T2): T4 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3):T4 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3 + ): { (p1: T1, p2: T2): T4 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + p1: T1 + ): { (p2: T2, p3: T3, p4: T4): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + p1: T1, + p2: T2 + ): { (p3: T3, p4: T4): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + stub1: UnderscoreStatic, + p2: T2 + ): { (p1: T1, p3: T3, p4: T4): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + p1: T1, + p2: T2, + p3: T3 + ): { (p4: T4): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3 + ): { (p1: T1, p4: T4): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3 + ): { (p2: T2, p4: T4): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3 + ): { (p1: T1, p2: T2, p4: T4): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4 + ): { (): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4 + ): { (p1: T1): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4 + ): { (p2: T2): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4 + ): { (p1: T1, p2: T2): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4 + ): { (p3: T3): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4 + ): { (p1: T1, p3: T3): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4 + ): { (p2: T2, p3: T3): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4 + ): { (p1: T1, p2: T2, p3: T3): T5 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1 + ): { (p2: T2, p3: T3, p4: T4, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + p2: T2 + ): { (p3: T3, p4: T4, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + p2: T2 + ): { (p1: T1, p3: T3, p4: T4, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + p2: T2, + p3: T3 + ): { (p4: T4, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3 + ): { (p1: T1, p4: T4, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3 + ): { (p2: T2, p4: T4, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3 + ): { (p1: T1, p2: T2, p4: T4, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4 + ): { (p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4 + ): { (p1: T1, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4 + ): { (p2: T2, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4 + ): { (p1: T1, p2: T2, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4 + ): { (p3: T3, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4 + ): { (p1: T1, p3: T3, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4 + ): { (p2: T2, p3: T3, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4 + ): { (p1: T1, p2: T2, p3: T3, p5: T5): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4, + p5: T5 + ): { (): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4, + p5: T5 + ): { (p1: T1): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5 + ): { (p2: T2): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5 + ): { (p1: T1, p2: T2): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p3: T3): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p1: T1, p3: T3): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p2: T2, p3: T3): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p1: T1, p2: T2, p3: T3): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p4: T4): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p4: T4): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p2: T2, p4: T4): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p2: T2, p4: T4): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p3: T3, p4: T4): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p3: T3, p4: T4): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p2: T2, p3: T3, p4: T4): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p2: T2, p3: T3, p4: T4): T6 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1 + ): { (p2: T2, p3: T3, p4: T4, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2 + ): { (p3: T3, p4: T4, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2 + ): { (p1: T1, p3: T3, p4: T4, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + p3: T3 + ): { (p4: T4, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3 + ): { (p1: T1, p4: T4, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3 + ): { (p2: T2, p4: T4, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3 + ): { (p1: T1, p2: T2, p4: T4, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4 + ): { (p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4 + ): { (p1: T1, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4 + ): { (p2: T2, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4 + ): { (p1: T1, p2: T2, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4 + ): { (p3: T3, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4 + ): { (p1: T1, p3: T3, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4 + ): { (p2: T2, p3: T3, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4 + ): { (p1: T1, p2: T2, p3: T3, p5: T5, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4, + p5: T5 + ): { (p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4, + p5: T5 + ): { (p1: T1, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5 + ): { (p2: T2, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5 + ): { (p1: T1, p2: T2, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p3: T3, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p1: T1, p3: T3, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p2: T2, p3: T3, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p1: T1, p2: T2, p3: T3, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p4: T4, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p4: T4, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p2: T2, p4: T4, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p2: T2, p4: T4, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p3: T3, p4: T4, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p3: T3, p4: T4, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p2: T2, p3: T3, p4: T4, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p2: T2, p3: T3, p4: T4, p6: T6): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4, + p5: T5, + p6: T6 + ): { (): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4, + p5: T5, + p6: T6 + ): { (p1: T1): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5, + p6: T6 + ): { (p2: T2): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5, + p6: T6 + ): { (p1: T1, p2: T2): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6 + ): { (p3: T3): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6 + ): { (p1: T1, p3: T3): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6 + ): { (p2: T2, p3: T3): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6 + ): { (p1: T1, p2: T2, p3: T3): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p4: T4): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p1: T1, p4: T4): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p2: T2, p4: T4): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p1: T1, p2: T2, p4: T4): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p3: T3, p4: T4): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p1: T1, p3: T3, p4: T4): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p2: T2, p3: T3, p4: T4): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p1: T1, p2: T2, p3: T3, p4: T4): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p2: T2, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p2: T2, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p3: T3, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p3: T3, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p2: T2, p3: T3, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p2: T2, p3: T3, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p4: T4, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p4: T4, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p2: T2, p4: T4, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p2: T2, p4: T4, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p3: T3, p4: T4, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p3: T3, p4: T4, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p2: T2, p3: T3, p4: T4, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5): T7 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1 + ): { (p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2 + ): { (p3: T3, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2 + ): { (p1: T1, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3 + ): { (p4: T4, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3 + ): { (p1: T1, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3 + ): { (p2: T2, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3 + ): { (p1: T1, p2: T2, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4 + ): { (p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4 + ): { (p1: T1, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4 + ): { (p2: T2, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4 + ): { (p1: T1, p2: T2, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4 + ): { (p3: T3, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4 + ): { (p1: T1, p3: T3, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4 + ): { (p2: T2, p3: T3, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4 + ): { (p1: T1, p2: T2, p3: T3, p5: T5, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4, + p5: T5 + ): { (p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4, + p5: T5 + ): { (p1: T1, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5 + ): { (p2: T2, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5 + ): { (p1: T1, p2: T2, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p3: T3, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p1: T1, p3: T3, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p2: T2, p3: T3, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5 + ): { (p1: T1, p2: T2, p3: T3, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p4: T4, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p4: T4, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p2: T2, p4: T4, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p2: T2, p4: T4, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p3: T3, p4: T4, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p3: T3, p4: T4, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p2: T2, p3: T3, p4: T4, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5 + ): { (p1: T1, p2: T2, p3: T3, p4: T4, p6: T6, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4, + p5: T5, + p6: T6 + ): { (p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4, + p5: T5, + p6: T6 + ): { (p1: T1, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5, + p6: T6 + ): { (p2: T2, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5, + p6: T6 + ): { (p1: T1, p2: T2, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6 + ): { (p3: T3, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6 + ): { (p1: T1, p3: T3, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6 + ): { (p2: T2, p3: T3, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6 + ): { (p1: T1, p2: T2, p3: T3, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p4: T4, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p1: T1, p4: T4, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p2: T2, p4: T4, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p1: T1, p2: T2, p4: T4, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p3: T3, p4: T4, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p1: T1, p3: T3, p4: T4, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p2: T2, p3: T3, p4: T4, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6 + ): { (p1: T1, p2: T2, p3: T3, p4: T4, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p2: T2, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p2: T2, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p3: T3, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p3: T3, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p2: T2, p3: T3, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p2: T2, p3: T3, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p4: T4, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p4: T4, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p2: T2, p4: T4, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p2: T2, p4: T4, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p3: T3, p4: T4, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p3: T3, p4: T4, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p2: T2, p3: T3, p4: T4, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6 + ): { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p7: T7): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4, + p5: T5, + p6: T6, + p7: T7 + ): { (): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4, + p5: T5, + p6: T6, + p7: T7 + ): { (p1: T1): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5, + p6: T6, + p7: T7 + ): { (p2: T2): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5, + p6: T6, + p7: T7 + ): { (p1: T1, p2: T2): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6, + p7: T7 + ): { (p3: T3): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6, + p7: T7 + ): { (p1: T1, p3: T3): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6, + p7: T7 + ): { (p2: T2, p3: T3): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + p6: T6, + p7: T7 + ): { (p1: T1, p2: T2, p3: T3): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6, + p7: T7 + ): { (p4: T4): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6, + p7: T7 + ): { (p1: T1, p4: T4): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6, + p7: T7 + ): { (p2: T2, p4: T4): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + p6: T6, + p7: T7 + ): { (p1: T1, p2: T2, p4: T4): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6, + p7: T7 + ): { (p3: T3, p4: T4): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6, + p7: T7 + ): { (p1: T1, p3: T3, p4: T4): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6, + p7: T7 + ): { (p2: T2, p3: T3, p4: T4): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + p6: T6, + p7: T7 + ): { (p1: T1, p2: T2, p3: T3, p4: T4): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p1: T1, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p2: T2, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p1: T1, p2: T2, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p3: T3, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p1: T1, p3: T3, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p2: T2, p3: T3, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p1: T1, p2: T2, p3: T3, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p4: T4, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p1: T1, p4: T4, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p2: T2, p4: T4, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p1: T1, p2: T2, p4: T4, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p3: T3, p4: T4, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p1: T1, p3: T3, p4: T4, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p2: T2, p3: T3, p4: T4, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + p6: T6, + p7: T7 + ): { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p2: T2, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p2: T2, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p3: T3, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p3: T3, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p2: T2, p3: T3, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p2: T2, p3: T3, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p4: T4, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p4: T4, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p2: T2, p4: T4, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p2: T2, p4: T4, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p3: T3, p4: T4, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p3: T3, p4: T4, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p2: T2, p3: T3, p4: T4, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + p5: T5, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p2: T2, p3: T3, p4: T4, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p2: T2, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + p4: T4, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p2: T2, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p3: T3, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p3: T3, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p2: T2, p3: T3, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + p4: T4, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p2: T2, p3: T3, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p4: T4, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p4: T4, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p2: T2, p4: T4, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + p3: T3, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p2: T2, p4: T4, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p3: T3, p4: T4, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + p2: T2, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p3: T3, p4: T4, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + p1: T1, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p2: T2, p3: T3, p4: T4, p5: T5, p6: T6): T8 }; + + partial( + fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, + stub1: UnderscoreStatic, + stub2: UnderscoreStatic, + stub3: UnderscoreStatic, + stub4: UnderscoreStatic, + stub5: UnderscoreStatic, + stub6: UnderscoreStatic, + p7: T7 + ): { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6): T8 }; /** * Memoizes a given function by caching the computed result. Useful for speeding up slow-running computations. @@ -1073,7 +3462,7 @@ interface UnderscoreStatic { throttle( func: T, wait: number, - options?: _.ThrottleSettings): T; + options?: _.ThrottleSettings): T & _.Cancelable; /** * Creates and returns a new debounced version of the passed function that will postpone its execution @@ -1092,7 +3481,7 @@ interface UnderscoreStatic { debounce( fn: T, wait: number, - immediate?: boolean): T; + immediate?: boolean): T & _.Cancelable; /** * Creates a version of the function that can only be called one time. Repeated calls to the modified @@ -1103,6 +3492,12 @@ interface UnderscoreStatic { **/ once(fn: T): T; + /** + * Similar to ES6's rest param (http://ariya.ofilabs.com/2013/03/es6-and-rest-parameter.html) + * This accumulates the arguments passed into an array, after a given index. + **/ + restArgs(func: Function, starIndex?: number) : Function; + /** * Creates a version of the function that will only be run after first being called count times. Useful * for grouping asynchronous responses, where you want to be sure that all the async calls have finished, @@ -1140,10 +3535,10 @@ interface UnderscoreStatic { /** * Returns a negated version of the pass-in predicate. - * @param Function predicate - * @return boolean + * @param (...args: any[]) => boolean predicate + * @return (...args: any[]) => boolean **/ - negate(predicate: Function): boolean; + negate(predicate: (...args: any[]) => boolean): (...args: any[]) => boolean; /** * Returns the composition of a list of functions, where each function consumes the return value of the @@ -1164,37 +3559,51 @@ interface UnderscoreStatic { **/ keys(object: any): string[]; + /** + * Retrieve all the names of object's own and inherited properties. + * @param object Retrieve the key or property names from this object. + * @return List of all the property names on `object`. + **/ + allKeys(object: any): string[]; + + /** + * Return all of the values of the object's properties. + * @param object Retrieve the values of all the properties on this object. + * @return List of all the values on `object`. + **/ + values(object: _.Dictionary): T[]; + /** * Return all of the values of the object's properties. * @param object Retrieve the values of all the properties on this object. * @return List of all the values on `object`. **/ values(object: any): any[]; - - /** - * Like map, but for objects. Transform the value of each property in turn. - * @param object The object to transform - * @param iteratee The function that transforms property values - * @param context The optional context (value of `this`) to bind to - * @return a new _.Dictionary of property values - */ - mapObject(object: _.Dictionary, iteratee: (val: T, key: string, object: _.Dictionary) => U, context?: any): _.Dictionary; - - /** - * Like map, but for objects. Transform the value of each property in turn. - * @param object The object to transform - * @param iteratee The function that tranforms property values - * @param context The optional context (value of `this`) to bind to - */ - mapObject(object: any, iteratee: (val: any, key: string, object: any) => T, context?: any): _.Dictionary; - - /** - * Like map, but for objects. Retrieves a property from each entry in the object, as if by _.property - * @param object The object to transform - * @param iteratee The property name to retrieve - * @param context The optional context (value of `this`) to bind to - */ - mapObject(object: any, iteratee: string, context?: any): _.Dictionary; + + /** + * Like map, but for objects. Transform the value of each property in turn. + * @param object The object to transform + * @param iteratee The function that transforms property values + * @param context The optional context (value of `this`) to bind to + * @return a new _.Dictionary of property values + */ + mapObject(object: _.Dictionary, iteratee: (val: T, key: string, object: _.Dictionary) => U, context?: any): _.Dictionary; + + /** + * Like map, but for objects. Transform the value of each property in turn. + * @param object The object to transform + * @param iteratee The function that tranforms property values + * @param context The optional context (value of `this`) to bind to + */ + mapObject(object: any, iteratee: (val: any, key: string, object: any) => T, context?: any): _.Dictionary; + + /** + * Like map, but for objects. Retrieves a property from each entry in the object, as if by _.property + * @param object The object to transform + * @param iteratee The property name to retrieve + * @param context The optional context (value of `this`) to bind to + */ + mapObject(object: any, iteratee: string, context?: any): _.Dictionary; /** * Convert an object into a list of [key, value] pairs. @@ -1242,7 +3651,7 @@ interface UnderscoreStatic { extendOwn( destination: any, ...source: any[]): any; - + /** * Like extend, but only copies own properties over to the destination object. (alias: extendOwn) */ @@ -1250,6 +3659,14 @@ interface UnderscoreStatic { destination: any, ...source: any[]): any; + /** + * Returns the first key on an object that passes a predicate test. + * @param obj the object to search in + * @param predicate Predicate function. + * @param context `this` object in `iterator`, optional. + */ + findKey(obj: _.Dictionary, predicate: _.ObjectIterator, context? : any): T + /** * Return a copy of the object, filtered to only have values for the whitelisted keys * (or array of valid keys). @@ -1303,6 +3720,16 @@ interface UnderscoreStatic { object: any, ...defaults: any[]): any; + + /** + * Creates an object that inherits from the given prototype object. + * If additional properties are provided then they will be added to the + * created object. + * @param prototype The prototype that the returned object will inherit from. + * @param props Additional props added to the returned object. + **/ + create(prototype: any, props?: Object): any; + /** * Create a shallow-copied clone of the object. * Any nested objects or arrays will be copied by reference, not duplicated. @@ -1336,6 +3763,14 @@ interface UnderscoreStatic { **/ matches(attrs: T): _.ListIterator; + /** + * Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs. + * @see _.matches + * @param attrs Object with key values pair + * @return Predicate function + **/ + matcher(attrs: T): _.ListIterator; + /** * Returns a function that will itself return the key property of any passed-in object. * @param key Property of the object. @@ -1343,6 +3778,13 @@ interface UnderscoreStatic { **/ property(key: string): (object: Object) => any; + /** + * Returns a function that will itself return the value of a object key property. + * @param key The object to get the property value from. + * @return Function which accept a key property in `object` and returns its value. + **/ + propertyOf(object: Object): (key: string) => any; + /** * Performs an optimized deep comparison between the two objects, * to determine if they should be considered equal. @@ -1359,19 +3801,41 @@ interface UnderscoreStatic { **/ isEmpty(object: any): boolean; + /** + * Returns true if the keys and values in `properties` matches with the `object` properties. + * @param object Object to be compared with `properties`. + * @param properties Properties be compared with `object` + * @return True if `object` has matching keys and values, otherwise false. + **/ + isMatch(object:any, properties:any): boolean; + /** * Returns true if object is a DOM element. * @param object Check if this object is a DOM element. * @return True if `object` is a DOM element, otherwise false. **/ - isElement(object: any): boolean; + isElement(object: any): object is Element; + + /** + * Returns true if object is an Array. + * @param object Check if this object is an Array. + * @return True if `object` is an Array, otherwise false. + **/ + isArray(object: any): object is any[]; /** * Returns true if object is an Array. * @param object Check if this object is an Array. * @return True if `object` is an Array, otherwise false. **/ - isArray(object: any): boolean; + isArray(object: any): object is T[]; + + /** + * Returns true if object is a Symbol. + * @param object Check if this object is a Symbol. + * @return True if `object` is a Symbol, otherwise false. + **/ + isSymbol(object: any): object is symbol; /** * Returns true if value is an Object. Note that JavaScript arrays and functions are objects, @@ -1386,28 +3850,35 @@ interface UnderscoreStatic { * @param object Check if this object is an Arguments object. * @return True if `object` is an Arguments object, otherwise false. **/ - isArguments(object: any): boolean; + isArguments(object: any): object is IArguments; /** * Returns true if object is a Function. * @param object Check if this object is a Function. * @return True if `object` is a Function, otherwise false. **/ - isFunction(object: any): boolean; + isFunction(object: any): object is Function; + + /** + * Returns true if object inherits from an Error. + * @param object Check if this object is an Error. + * @return True if `object` is a Error, otherwise false. + **/ + isError(object:any): object is Error; /** * Returns true if object is a String. * @param object Check if this object is a String. * @return True if `object` is a String, otherwise false. **/ - isString(object: any): boolean; + isString(object: any): object is string; /** * Returns true if object is a Number (including NaN). * @param object Check if this object is a Number. * @return True if `object` is a Number, otherwise false. **/ - isNumber(object: any): boolean; + isNumber(object: any): object is number; /** * Returns true if object is a finite Number. @@ -1421,21 +3892,21 @@ interface UnderscoreStatic { * @param object Check if this object is a bool. * @return True if `object` is a bool, otherwise false. **/ - isBoolean(object: any): boolean; + isBoolean(object: any): object is boolean; /** * Returns true if object is a Date. * @param object Check if this object is a Date. * @return True if `object` is a Date, otherwise false. **/ - isDate(object: any): boolean; + isDate(object: any): object is Date; /** * Returns true if object is a RegExp. * @param object Check if this object is a RegExp. * @return True if `object` is a RegExp, otherwise false. **/ - isRegExp(object: any): boolean; + isRegExp(object: any): object is RegExp; /** * Returns true if object is NaN. @@ -1487,7 +3958,7 @@ interface UnderscoreStatic { constant(value: T): () => T; /** - * Returns undefined irrespective of the arguments passed to it. Useful as the default + * Returns undefined irrespective of the arguments passed to it. Useful as the default * for optional callback arguments. * Note there is no way to indicate a 'undefined' return, so it is currently typed as void. * @return undefined @@ -1532,11 +4003,10 @@ interface UnderscoreStatic { * a property matcher, or a propetery accessor. * @param string|Function|Object value The value to iterate over, usually the key. * @param any context - * @param number argCount * @return Callback that can be applied to each element in a collection. **/ iteratee(value: string): Function; - iteratee(value: Function, context?: any, argCount?: number): Function; + iteratee(value: Function, context?: any): Function; iteratee(value: Object): Function; /** @@ -1545,12 +4015,7 @@ interface UnderscoreStatic { * @param prefix A prefix string to start the unique ID with. * @return Unique string ID beginning with `prefix`. **/ - uniqueId(prefix: string): string; - - /** - * @see _.uniqueId - **/ - uniqueId(): number; + uniqueId(prefix?: string): string; /** * Escapes a string for insertion into HTML, replacing &, <, >, ", ', and / characters. @@ -1570,9 +4035,10 @@ interface UnderscoreStatic { * If the value of the named property is a function then invoke it; otherwise, return it. * @param object Object to maybe invoke function `property` on. * @param property The function by name to invoke on `object`. + * @param defaultValue The value to be returned in case `property` doesn't exist or is undefined. * @return The result of invoking the function `property` on `object. **/ - result(object: any, property: string): any; + result(object: any, property: string, defaultValue?:any): any; /** * Compiles JavaScript templates into functions that can be evaluated for rendering. Useful @@ -1590,7 +4056,7 @@ interface UnderscoreStatic { * @return Returns the compiled Underscore HTML template. **/ template(templateString: string, settings?: _.TemplateSettings): (...data: any[]) => string; - + /** * By default, Underscore uses ERB-style template delimiters, change the * following template settings to use alternative delimiters. @@ -1613,6 +4079,7 @@ interface UnderscoreStatic { * @return Wrapped `obj`. **/ chain(obj: T[]): _Chain; + chain(obj: _.Dictionary): _Chain; chain(obj: T): _Chain; } @@ -1696,12 +4163,32 @@ interface Underscore { * Wrapped type `any[]`. * @see _.find **/ - find(iterator: _.ListIterator, context?: any): T; + find(iterator: _.ListIterator|_.ObjectIterator, context?: any): T; + + /** + * @see _.find + **/ + find(interator: U): T; + + /** + * @see _.find + **/ + find(interator: string): T; + + /** + * @see _.find + **/ + detect(iterator: _.ListIterator|_.ObjectIterator, context?: any): T; /** * @see _.find **/ - detect(iterator: _.ListIterator, context?: any): T; + detect(interator?: U): T; + + /** + * @see _.find + **/ + detect(interator?: string): T; /** * Wrapped type `any[]`. @@ -1758,13 +4245,19 @@ interface Underscore { * Wrapped type `any[]`. * @see _.contains **/ - contains(value: T): boolean; + contains(value: T, fromIndex? : number): boolean; /** * Alias for 'contains'. * @see contains **/ - include(value: T): boolean; + include(value: T, fromIndex? : number): boolean; + + /** + * Alias for 'contains'. + * @see contains + **/ + includes(value: T, fromIndex? : number): boolean; /** * Wrapped type `any[]`. @@ -2031,6 +4524,12 @@ interface Underscore { **/ zip(...arrays: any[][]): any[][]; + /** + * Wrapped type `any[][]`. + * @see _.unzip + **/ + unzip(...arrays: any[][]): any[][]; + /** * Wrapped type `any[][]`. * @see _.object @@ -2059,6 +4558,16 @@ interface Underscore { **/ lastIndexOf(value: T, from?: number): number; + /** + * @see _.findIndex + **/ + findIndex(array: _.List, predicate: _.ListIterator | {}, context?: any): number; + + /** + * @see _.findLastIndex + **/ + findLastIndex(array: _.List, predicate: _.ListIterator | {}, context?: any): number; + /** * Wrapped type `any[]`. * @see _.sortedIndex @@ -2077,6 +4586,12 @@ interface Underscore { **/ range(): number[]; + /** + * Wrapped type any[][]. + * @see _.chunk + **/ + chunk(): any[][]; + /* *********** * Functions * ************ */ @@ -2126,13 +4641,13 @@ interface Underscore { * Wrapped type `Function`. * @see _.throttle **/ - throttle(wait: number, options?: _.ThrottleSettings): Function; + throttle(wait: number, options?: _.ThrottleSettings): Function & _.Cancelable; /** * Wrapped type `Function`. * @see _.debounce **/ - debounce(wait: number, immediate?: boolean): Function; + debounce(wait: number, immediate?: boolean): Function & _.Cancelable; /** * Wrapped type `Function`. @@ -2140,6 +4655,12 @@ interface Underscore { **/ once(): Function; + /** + * Wrapped type `Function`. + * @see _.once + **/ + restArgs(starIndex?: number) : Function; + /** * Wrapped type `number`. * @see _.after @@ -2180,6 +4701,12 @@ interface Underscore { **/ keys(): string[]; + /** + * Wrapped type `object`. + * @see _.allKeys + **/ + allKeys(): string[]; + /** * Wrapped type `object`. * @see _.values @@ -2215,6 +4742,12 @@ interface Underscore { **/ extend(...sources: any[]): any; + /** + * Wrapped type `object`. + * @see _.extend + **/ + findKey(predicate: _.ObjectIterator, context? : any): any + /** * Wrapped type `object`. * @see _.pick @@ -2237,6 +4770,12 @@ interface Underscore { **/ defaults(...defaults: any[]): any; + /** + * Wrapped type `any`. + * @see _.create + **/ + create(props?: Object): any; + /** * Wrapped type `any[]`. * @see _.clone @@ -2261,12 +4800,24 @@ interface Underscore { **/ matches(): _.ListIterator; + /** + * Wrapped type `any[]`. + * @see _.matcher + **/ + matcher(): _.ListIterator; + /** * Wrapped type `string`. * @see _.property **/ property(): (object: Object) => any; + /** + * Wrapped type `object`. + * @see _.propertyOf + **/ + propertyOf(): (key: string) => any; + /** * Wrapped type `object`. * @see _.isEqual @@ -2279,6 +4830,12 @@ interface Underscore { **/ isEmpty(): boolean; + /** + * Wrapped type `object`. + * @see _.isMatch + **/ + isMatch(): boolean; + /** * Wrapped type `object`. * @see _.isElement @@ -2291,6 +4848,12 @@ interface Underscore { **/ isArray(): boolean; + /** + * Wrapped type `object`. + * @see _.isSymbol + **/ + isSymbol(): boolean; + /** * Wrapped type `object`. * @see _.isObject @@ -2309,6 +4872,12 @@ interface Underscore { **/ isFunction(): boolean; + /** + * Wrapped type `object`. + * @see _.isError + **/ + isError(): boolean; + /** * Wrapped type `object`. * @see _.isString @@ -2412,7 +4981,7 @@ interface Underscore { * Wrapped type `string|Function|Object`. * @see _.iteratee **/ - iteratee(context?: any, argCount?: number): Function; + iteratee(context?: any): Function; /** * Wrapped type `string`. @@ -2436,7 +5005,7 @@ interface Underscore { * Wrapped type `object`. * @see _.result **/ - result(property: string): any; + result(property: string, defaultValue?:any): any; /** * Wrapped type `string`. @@ -2554,12 +5123,32 @@ interface _Chain { * Wrapped type `any[]`. * @see _.find **/ - find(iterator: _.ListIterator, context?: any): _ChainSingle; + find(iterator: _.ListIterator|_.ObjectIterator, context?: any): _ChainSingle; /** * @see _.find **/ - detect(iterator: _.ListIterator, context?: any): _Chain; + find(interator: U): _ChainSingle; + + /** + * @see _.find + **/ + find(interator: string): _ChainSingle; + + /** + * @see _.find + **/ + detect(iterator: _.ListIterator|_.ObjectIterator, context?: any): _ChainSingle; + + /** + * @see _.find + **/ + detect(interator: U): _ChainSingle; + + /** + * @see _.find + **/ + detect(interator: string): _ChainSingle; /** * Wrapped type `any[]`. @@ -2594,35 +5183,41 @@ interface _Chain { * Wrapped type `any[]`. * @see _.all **/ - all(iterator?: _.ListIterator, context?: any): _Chain; + all(iterator?: _.ListIterator, context?: any): _ChainSingle; /** * @see _.all **/ - every(iterator?: _.ListIterator, context?: any): _Chain; + every(iterator?: _.ListIterator, context?: any): _ChainSingle; /** * Wrapped type `any[]`. * @see _.any **/ - any(iterator?: _.ListIterator, context?: any): _Chain; + any(iterator?: _.ListIterator, context?: any): _ChainSingle; /** * @see _.any **/ - some(iterator?: _.ListIterator, context?: any): _Chain; + some(iterator?: _.ListIterator, context?: any): _ChainSingle; /** * Wrapped type `any[]`. * @see _.contains **/ - contains(value: T): _Chain; + contains(value: T, fromIndex?: number): _ChainSingle; /** * Alias for 'contains'. * @see contains **/ - include(value: T): _Chain; + include(value: T, fromIndex?: number): _ChainSingle; + + /** + * Alias for 'contains'. + * @see contains + **/ + includes(value: T, fromIndex?: number): _ChainSingle; /** * Wrapped type `any[]`. @@ -2747,7 +5342,7 @@ interface _Chain { * Wrapped type `any`. * @see _.size **/ - size(): _Chain; + size(): _ChainSingle; /********* * Arrays * @@ -2889,6 +5484,12 @@ interface _Chain { **/ zip(...arrays: any[][]): _Chain; + /** + * Wrapped type `any[][]`. + * @see _.unzip + **/ + unzip(...arrays: any[][]): _Chain; + /** * Wrapped type `any[][]`. * @see _.object @@ -2904,24 +5505,34 @@ interface _Chain { * Wrapped type `any[]`. * @see _.indexOf **/ - indexOf(value: T, isSorted?: boolean): _ChainSingle; + indexOf(value: T, isSorted?: boolean): _ChainSingle; /** * @see _.indexOf **/ - indexOf(value: T, startFrom: number): _ChainSingle; + indexOf(value: T, startFrom: number): _ChainSingle; /** * Wrapped type `any[]`. * @see _.lastIndexOf **/ - lastIndexOf(value: T, from?: number): _ChainSingle; + lastIndexOf(value: T, from?: number): _ChainSingle; + + /** + * @see _.findIndex + **/ + findIndex(predicate: _.ListIterator | {}, context?: any): _ChainSingle; + + /** + * @see _.findLastIndex + **/ + findLastIndex(predicate: _.ListIterator | {}, context?: any): _ChainSingle; /** * Wrapped type `any[]`. * @see _.sortedIndex **/ - sortedIndex(value: T, iterator?: (x: T) => any, context?: any): _Chain; + sortedIndex(value: T, iterator?: (x: T) => any, context?: any): _ChainSingle; /** * Wrapped type `number`. @@ -2935,6 +5546,12 @@ interface _Chain { **/ range(): _Chain; + /** + * Wrapped type `any[][]`. + * @see _.chunk + **/ + chunk(): _Chain; + /* *********** * Functions * ************ */ @@ -2998,6 +5615,12 @@ interface _Chain { **/ once(): _Chain; + /** + * Wrapped type `Function`. + * @see _.once + **/ + restArgs(startIndex? : number): _Chain; + /** * Wrapped type `number`. * @see _.after @@ -3038,6 +5661,12 @@ interface _Chain { **/ keys(): _Chain; + /** + * Wrapped type `object`. + * @see _.allKeys + **/ + allKeys(): _Chain; + /** * Wrapped type `object`. * @see _.values @@ -3073,6 +5702,12 @@ interface _Chain { **/ extend(...sources: any[]): _Chain; + /** + * Wrapped type `object`. + * @see _.extend + **/ + findKey(predicate: _.ObjectIterator, context? : any): _Chain + /** * Wrapped type `object`. * @see _.pick @@ -3095,6 +5730,12 @@ interface _Chain { **/ defaults(...defaults: any[]): _Chain; + /** + * Wrapped type `any`. + * @see _.create + **/ + create(props?: Object): _Chain; + /** * Wrapped type `any[]`. * @see _.clone @@ -3119,12 +5760,24 @@ interface _Chain { **/ matches(): _Chain; + /** + * Wrapped type `any[]`. + * @see _.matcher + **/ + matcher(): _Chain; + /** * Wrapped type `string`. * @see _.property **/ property(): _Chain; + /** + * Wrapped type `object`. + * @see _.propertyOf + **/ + propertyOf(): _Chain; + /** * Wrapped type `object`. * @see _.isEqual @@ -3137,6 +5790,12 @@ interface _Chain { **/ isEmpty(): _Chain; + /** + * Wrapped type `object`. + * @see _.isMatch + **/ + isMatch(): _Chain; + /** * Wrapped type `object`. * @see _.isElement @@ -3149,6 +5808,12 @@ interface _Chain { **/ isArray(): _Chain; + /** + * Wrapped type `object`. + * @see _.isSymbol + **/ + isSymbol(): _Chain; + /** * Wrapped type `object`. * @see _.isObject @@ -3167,6 +5832,12 @@ interface _Chain { **/ isFunction(): _Chain; + /** + * Wrapped type `object`. + * @see _.isError + **/ + isError(): _Chain; + /** * Wrapped type `object`. * @see _.isString @@ -3270,7 +5941,7 @@ interface _Chain { * Wrapped type `string|Function|Object`. * @see _.iteratee **/ - iteratee(context?: any, argCount?: number): _Chain; + iteratee(context?: any): _Chain; /** * Wrapped type `string`. @@ -3294,7 +5965,7 @@ interface _Chain { * Wrapped type `object`. * @see _.result **/ - result(property: string): _Chain; + result(property: string, defaultValue?:any): _Chain; /** * Wrapped type `string`. @@ -3305,7 +5976,7 @@ interface _Chain { /************* * * Array proxy * ************** */ - + /** * Returns a new array comprised of the array on which it is called * joined with the array(s) and/or value(s) provided as arguments. @@ -3403,7 +6074,8 @@ interface _ChainSingle { value(): T; } interface _ChainOfArrays extends _Chain { - flatten(): _Chain; + flatten(shallow?: boolean): _Chain; + mapObject(fn: _.ListIterator): _ChainOfArrays; } declare var _: UnderscoreStatic; From b0f5ff1e435191350d696c06f4bd5ee4957e8e51 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 16:01:57 -0400 Subject: [PATCH 004/111] Use Object.assign available in Node v4+ --- scripts/buildDocs.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/scripts/buildDocs.ts b/scripts/buildDocs.ts index 17ae7b80fa5..79cfee250f0 100644 --- a/scripts/buildDocs.ts +++ b/scripts/buildDocs.ts @@ -148,14 +148,10 @@ function buildDocumentationDataFile(documentation: IDocumentation, metadataJson: * Generates Jekyll data from any item's metadata. */ function generateJekyllData(metadata: any, type: string, name: string): any { - const jekyllData: any = {}; - // TODO: Use Object.assign when Node 0.12 support is dropped (#1181) - for (const key of Object.keys(metadata)) { - jekyllData[key] = ( metadata)[key]; - } - jekyllData.layout = type.toLowerCase(); - jekyllData.title = `${type}: ${name}`; - return jekyllData; + return Object.assign({}, metadata, { + layout: type.toLowerCase(), + title: `${type}: ${name}`, + }); } /** @@ -163,7 +159,7 @@ function generateJekyllData(metadata: any, type: string, name: string): any { * that only consists of a YAML front matter block. */ function generateRuleFile(metadata: IRuleMetadata): string { - const yamlData: any = generateJekyllData(metadata, "Rule", metadata.ruleName); + const yamlData = generateJekyllData(metadata, "Rule", metadata.ruleName); yamlData.optionsJSON = JSON.stringify(metadata.options, undefined, 2); return `---\n${yaml.safeDump(yamlData, {lineWidth: 140})}---`; } @@ -173,7 +169,7 @@ function generateRuleFile(metadata: IRuleMetadata): string { * that only consists of a YAML front matter block. */ function generateFormatterFile(metadata: IFormatterMetadata): string { - const yamlData: any = generateJekyllData(metadata, "Formatter", metadata.formatterName); + const yamlData = generateJekyllData(metadata, "Formatter", metadata.formatterName); return `---\n${yaml.safeDump(yamlData, {lineWidth: 140})}---`; } From 83757825bb9415a78ea0919fa9107dd1878d106e Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 16:48:18 -0400 Subject: [PATCH 005/111] Update NPM dependencies, compile with typescript v2.0.3 (#1612) --- package.json | 16 ++++++++-------- src/language/utils.ts | 3 +-- src/test.ts | 3 +-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 91e9fb2a455..d06da7c24c9 100644 --- a/package.json +++ b/package.json @@ -21,9 +21,9 @@ }, "dependencies": { "colors": "^1.1.2", - "diff": "^2.2.1", + "diff": "^3.0.1", "findup-sync": "~0.3.0", - "glob": "^7.0.3", + "glob": "^7.1.1", "optimist": "~0.6.0", "resolve": "^1.1.7", "underscore.string": "^3.3.4" @@ -33,17 +33,17 @@ "grunt": "^1.0.1", "grunt-cli": "^1.2.0", "grunt-contrib-clean": "^1.0.0", - "grunt-eslint": "^18.1.0", - "grunt-mocha-test": "^0.12.7", + "grunt-eslint": "^19.0.0", + "grunt-mocha-test": "^0.13.2", "grunt-npm-command": "^0.1.2", "grunt-run": "~0.6.0", - "grunt-ts": "^5.1.0", + "grunt-ts": "^5.5.1", "grunt-tslint": "latest", - "js-yaml": "^3.4.6", - "mocha": "^2.2.5", + "js-yaml": "^3.6.1", + "mocha": "^3.1.0", "tslint": "latest", "tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative", - "typescript": "1.8.10" + "typescript": "2.0.3" }, "peerDependencies": { "typescript": ">=1.7.3" diff --git a/src/language/utils.ts b/src/language/utils.ts index 90d9715ccba..5982866821a 100644 --- a/src/language/utils.ts +++ b/src/language/utils.ts @@ -29,8 +29,7 @@ export function getSourceFile(fileName: string, source: string): ts.SourceFile { getCanonicalFileName: (filename: string) => filename, getCurrentDirectory: () => "", getDefaultLibFileName: () => "lib.d.ts", - // TODO: include this field when compiling with TS 2.0 - // getDirectories: (path: string) => [], + getDirectories: (path: string) => [], getNewLine: () => "\n", getSourceFile: (filenameToGet: string) => { if (filenameToGet === normalizedName) { diff --git a/src/test.ts b/src/test.ts index 936a6959e1a..71f75c142cf 100644 --- a/src/test.ts +++ b/src/test.ts @@ -65,8 +65,7 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[ getCanonicalFileName: (filename: string) => filename, getCurrentDirectory: () => "", getDefaultLibFileName: () => ts.getDefaultLibFileName(compilerOptions), - // TODO: include this field when compiling with TS 2.0 - // getDirectories: (path: string) => [], + getDirectories: (path: string) => [], getNewLine: () => "\n", getSourceFile(filenameToGet: string) { if (filenameToGet === this.getDefaultLibFileName()) { From cbe88c3a4eb2c3b05c2e3edb0dbbd6e4445ad32e Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 17:00:07 -0400 Subject: [PATCH 006/111] Remove label-undefined rule (#1614) Resolves #877. This rule is already covered by compiler checks. --- docs/_data/rules.json | 14 +---- docs/rules/label-undefined/index.html | 14 ----- src/configs/recommended.ts | 1 - src/rules/labelUndefinedRule.ts | 75 ------------------------- src/tsconfig.json | 1 - test/rules/label-undefined/test.ts.lint | 55 ------------------ test/rules/label-undefined/tslint.json | 5 -- test/tsconfig.json | 1 - 8 files changed, 1 insertion(+), 165 deletions(-) delete mode 100644 docs/rules/label-undefined/index.html delete mode 100644 src/rules/labelUndefinedRule.ts delete mode 100644 test/rules/label-undefined/test.ts.lint delete mode 100644 test/rules/label-undefined/tslint.json diff --git a/docs/_data/rules.json b/docs/_data/rules.json index e67982e42a4..311d7c1e058 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -208,18 +208,6 @@ ], "type": "functionality" }, - { - "ruleName": "label-undefined", - "description": "Checks that labels are defined before usage.", - "descriptionDetails": "This rule is now implemented in the TypeScript compiler and does not need to be used.", - "rationale": "Using `break` or `continue` to go to an out-of-scope label is an error in JS.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality" - }, { "ruleName": "linebreak-style", "description": "Enforces a consistent linebreak style.", @@ -1312,4 +1300,4 @@ ], "type": "style" } -] \ No newline at end of file +] diff --git a/docs/rules/label-undefined/index.html b/docs/rules/label-undefined/index.html deleted file mode 100644 index 4876b9c2486..00000000000 --- a/docs/rules/label-undefined/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -ruleName: label-undefined -description: Checks that labels are defined before usage. -descriptionDetails: This rule is now implemented in the TypeScript compiler and does not need to be used. -rationale: Using `break` or `continue` to go to an out-of-scope label is an error in JS. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -optionsJSON: 'null' -layout: rule -title: 'Rule: label-undefined' ---- \ No newline at end of file diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index d0195bd59da..99b52e95cb7 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -32,7 +32,6 @@ export const rules = { "interface-name": [true, "always-prefix"], "jsdoc-format": true, "label-position": true, - "label-undefined": true, "max-line-length": [true, 120], "member-access": true, "member-ordering": [true, diff --git a/src/rules/labelUndefinedRule.ts b/src/rules/labelUndefinedRule.ts deleted file mode 100644 index 54df05d9c33..00000000000 --- a/src/rules/labelUndefinedRule.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @license - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as ts from "typescript"; - -import * as Lint from "../lint"; - -export class Rule extends Lint.Rules.AbstractRule { - /* tslint:disable:object-literal-sort-keys */ - public static metadata: Lint.IRuleMetadata = { - ruleName: "label-undefined", - description: "Checks that labels are defined before usage.", - descriptionDetails: "This rule is now implemented in the TypeScript compiler and does not need to be used.", - rationale: "Using `break` or `continue` to go to an out-of-scope label is an error in JS.", - optionsDescription: "Not configurable.", - options: null, - optionExamples: ["true"], - type: "functionality", - }; - /* tslint:enable:object-literal-sort-keys */ - - public static FAILURE_STRING = "undefined label: '"; - - public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new LabelUndefinedWalker(sourceFile, this.getOptions())); - } -} - -class LabelUndefinedWalker extends Lint.ScopeAwareRuleWalker<{[key: string]: any}> { - public createScope(): {[key: string]: any} { - return {}; - } - - public visitLabeledStatement(node: ts.LabeledStatement) { - const label = node.label.text; - const currentScope = this.getCurrentScope(); - - currentScope[label] = true; - super.visitLabeledStatement(node); - } - - public visitBreakStatement(node: ts.BreakOrContinueStatement) { - this.validateLabelAt(node.label, node.getStart(), node.getChildAt(0).getWidth()); - super.visitBreakStatement(node); - } - - public visitContinueStatement(node: ts.BreakOrContinueStatement) { - this.validateLabelAt(node.label, node.getStart(), node.getChildAt(0).getWidth()); - super.visitContinueStatement(node); - } - - private validateLabelAt(label: ts.Identifier, position: number, width: number) { - const currentScope = this.getCurrentScope(); - - if (label != null && !currentScope[label.text]) { - const failureString = Rule.FAILURE_STRING + label.text + "'"; - const failure = this.createFailure(position, width, failureString); - this.addFailure(failure); - } - } -} diff --git a/src/tsconfig.json b/src/tsconfig.json index 55607a2a7c7..5a55ca1ce33 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -90,7 +90,6 @@ "rules/interfaceNameRule.ts", "rules/jsdocFormatRule.ts", "rules/labelPositionRule.ts", - "rules/labelUndefinedRule.ts", "rules/linebreakStyleRule.ts", "rules/maxFileLineCountRule.ts", "rules/maxLineLengthRule.ts", diff --git a/test/rules/label-undefined/test.ts.lint b/test/rules/label-undefined/test.ts.lint deleted file mode 100644 index d9988de8916..00000000000 --- a/test/rules/label-undefined/test.ts.lint +++ /dev/null @@ -1,55 +0,0 @@ -// invalid code - -function f() { - lab3: - for (var i = 0; i < 10; ++i) { - break lab1; - ~~~~~ [undefined label: 'lab1'] - } -} - -var x = function() { - lab4: - while (i < 10) { - continue lab2; - ~~~~~~~~ [undefined label: 'lab2'] - } -}; - -var y = () => { - lab3: - while (i < 10) { - continue lab3; - } - - (function() { - lab2: - switch (j) { - case 1: - break lab3; - ~~~~~ [undefined label: 'lab3'] - } - })(); -}; - -var z = x => { - lab1: - do { - x++; - continue lab4; - ~~~~~~~~ [undefined label: 'lab4'] - } while (x < 10); -}; - -// valid code - -lab5: -for (var i = 0; i < 10; ++i) { - var w = () => { - lab2: - while (i < 10) { - continue lab2; - } - }; - break lab5; -} diff --git a/test/rules/label-undefined/tslint.json b/test/rules/label-undefined/tslint.json deleted file mode 100644 index 74a9a3d5886..00000000000 --- a/test/rules/label-undefined/tslint.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "label-undefined": true - } -} diff --git a/test/tsconfig.json b/test/tsconfig.json index 4d8f1f8a7a9..d64527e9e25 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -85,7 +85,6 @@ "../src/rules/interfaceNameRule.ts", "../src/rules/jsdocFormatRule.ts", "../src/rules/labelPositionRule.ts", - "../src/rules/labelUndefinedRule.ts", "../src/rules/linebreakStyleRule.ts", "../src/rules/maxFileLineCountRule.ts", "../src/rules/maxLineLengthRule.ts", From 2534fc959c33985b64067b6ec927328fd76ef74c Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 17:03:09 -0400 Subject: [PATCH 007/111] Remove use-strict rule (#1615) Resolves #678. This rule is obsolete as of TypeScript v1.8. --- docs/_data/rules.json | 21 ----- docs/rules/use-strict/index.html | 37 --------- src/rules/useStrictRule.ts | 121 ----------------------------- src/tsconfig.json | 1 - test/rules/use-strict/test.ts.lint | 62 --------------- test/rules/use-strict/tslint.json | 5 -- test/tsconfig.json | 1 - 7 files changed, 248 deletions(-) delete mode 100644 docs/rules/use-strict/index.html delete mode 100644 src/rules/useStrictRule.ts delete mode 100644 test/rules/use-strict/test.ts.lint delete mode 100644 test/rules/use-strict/tslint.json diff --git a/docs/_data/rules.json b/docs/_data/rules.json index 311d7c1e058..f98b7f7ddd6 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -1228,27 +1228,6 @@ ], "type": "functionality" }, - { - "ruleName": "use-strict", - "description": "Requires using ECMAScript 5's strict mode.", - "optionsDescription": "\nTwo arguments may be optionally provided:\n\n* `check-module` checks that all top-level modules are using strict mode.\n* `check-function` checks that all top-level functions are using strict mode.", - "options": { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-module", - "check-function" - ] - }, - "minLength": 0, - "maxLength": 2 - }, - "optionExamples": [ - "[true, \"check-module\"]" - ], - "type": "functionality" - }, { "ruleName": "variable-name", "description": "Checks variable names for various errors.", diff --git a/docs/rules/use-strict/index.html b/docs/rules/use-strict/index.html deleted file mode 100644 index a90611acb6b..00000000000 --- a/docs/rules/use-strict/index.html +++ /dev/null @@ -1,37 +0,0 @@ ---- -ruleName: use-strict -description: Requires using ECMAScript 5's strict mode. -optionsDescription: |- - - Two arguments may be optionally provided: - - * `check-module` checks that all top-level modules are using strict mode. - * `check-function` checks that all top-level functions are using strict mode. -options: - type: array - items: - type: string - enum: - - check-module - - check-function - minLength: 0 - maxLength: 2 -optionExamples: - - '[true, "check-module"]' -type: functionality -optionsJSON: |- - { - "type": "array", - "items": { - "type": "string", - "enum": [ - "check-module", - "check-function" - ] - }, - "minLength": 0, - "maxLength": 2 - } -layout: rule -title: 'Rule: use-strict' ---- \ No newline at end of file diff --git a/src/rules/useStrictRule.ts b/src/rules/useStrictRule.ts deleted file mode 100644 index d7aa8335c74..00000000000 --- a/src/rules/useStrictRule.ts +++ /dev/null @@ -1,121 +0,0 @@ -/** - * @license - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as ts from "typescript"; - -import * as Lint from "../lint"; - -export class Rule extends Lint.Rules.AbstractRule { - /* tslint:disable:object-literal-sort-keys */ - public static metadata: Lint.IRuleMetadata = { - ruleName: "use-strict", - description: "Requires using ECMAScript 5's strict mode.", - optionsDescription: Lint.Utils.dedent` - Two arguments may be optionally provided: - - * \`check-module\` checks that all top-level modules are using strict mode. - * \`check-function\` checks that all top-level functions are using strict mode.`, - options: { - type: "array", - items: { - type: "string", - enum: ["check-module", "check-function"], - }, - minLength: 0, - maxLength: 2, - }, - optionExamples: ['[true, "check-module"]'], - type: "functionality", - }; - /* tslint:enable:object-literal-sort-keys */ - - public static FAILURE_STRING = "missing 'use strict'"; - - public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - const useStrictWalker = new UseStrictWalker(sourceFile, this.getOptions()); - return this.applyWithWalker(useStrictWalker); - } -} - -class UseStrictWalker extends Lint.ScopeAwareRuleWalker<{}> { - private static OPTION_CHECK_FUNCTION = "check-function"; - private static OPTION_CHECK_MODULE = "check-module"; - - private static USE_STRICT_STRING = "use strict"; - - public createScope(): {} { - return {}; - } - - public visitModuleDeclaration(node: ts.ModuleDeclaration) { - if (!Lint.hasModifier(node.modifiers, ts.SyntaxKind.DeclareKeyword) - && this.hasOption(UseStrictWalker.OPTION_CHECK_MODULE) - && node.body != null - && node.body.kind === ts.SyntaxKind.ModuleBlock) { - let firstModuleDeclaration = getFirstInModuleDeclarationsChain(node); - let hasOnlyModuleDeclarationParents = firstModuleDeclaration.parent.kind === ts.SyntaxKind.SourceFile; - - if (hasOnlyModuleDeclarationParents) { - this.handleBlock(firstModuleDeclaration, node.body); - } - } - - super.visitModuleDeclaration(node); - } - - public visitFunctionDeclaration(node: ts.FunctionDeclaration) { - // current depth is 2: global scope and the scope created by this function - if (this.getCurrentDepth() === 2 && - this.hasOption(UseStrictWalker.OPTION_CHECK_FUNCTION) && - node.body != null) { - this.handleBlock(node, node.body); - } - - super.visitFunctionDeclaration(node); - } - - private handleBlock(node: ts.Declaration, block: ts.Block | ts.ModuleBlock) { - let isFailure = true; - - if (block.statements != null && block.statements.length > 0) { - const firstStatement = block.statements[0]; - - if (firstStatement.kind === ts.SyntaxKind.ExpressionStatement) { - const firstChild = firstStatement.getChildAt(0); - - if (firstChild.kind === ts.SyntaxKind.StringLiteral - && ( firstChild).text === UseStrictWalker.USE_STRICT_STRING) { - isFailure = false; - } - } - } - - if (isFailure) { - this.addFailure(this.createFailure(node.getStart(), node.getFirstToken().getWidth(), Rule.FAILURE_STRING)); - } - } -} - -function getFirstInModuleDeclarationsChain(node: ts.ModuleDeclaration): ts.ModuleDeclaration { - let current = node; - - while (current.parent.kind === ts.SyntaxKind.ModuleDeclaration) { - current = current.parent; - } - - return current; -} diff --git a/src/tsconfig.json b/src/tsconfig.json index 5a55ca1ce33..a4db5f9f864 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -150,7 +150,6 @@ "rules/typedefRule.ts", "rules/typedefWhitespaceRule.ts", "rules/useIsnanRule.ts", - "rules/useStrictRule.ts", "rules/variableNameRule.ts", "rules/whitespaceRule.ts", "test/lines.ts", diff --git a/test/rules/use-strict/test.ts.lint b/test/rules/use-strict/test.ts.lint deleted file mode 100644 index e80f0664713..00000000000 --- a/test/rules/use-strict/test.ts.lint +++ /dev/null @@ -1,62 +0,0 @@ -declare function foo(): void; - -function testDoubleQuotes() { - // hello - "use strict"; // bye - - var i = 3; -} - -function testSingleQuotes() { - 'use strict'; -} - -function testNoUseStrict() { -~~~~~~~~ [missing 'use strict'] -} - -module TestModule { - // hello - "use strict"; // bye - - var i = 3; -} - -module TestNoUseStrictModule { -~~~~~~ [missing 'use strict'] - // hello - var i = 3; -} - -module TestNoUseStrictModule.Namespaced.AndAgain { -~~~~~~ [missing 'use strict'] - // hello - var i = 3; -} - -function checkDepth() { - "use strict"; - - function innerFunction() { - - } -} - -module TestModuleWithFunction { - "use strict"; - - function hello() { - // there shouldn't be a failure here since it isn't top level - } -} - -declare module foo { - // shouldn't error because of the declare - export class bar { - } -} - -function shouldPassUseStrictRule(): string { - "use strict" - return "This is a test" -} diff --git a/test/rules/use-strict/tslint.json b/test/rules/use-strict/tslint.json deleted file mode 100644 index 3784cf991b7..00000000000 --- a/test/rules/use-strict/tslint.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "use-strict": [true, "check-function", "check-module"] - } -} diff --git a/test/tsconfig.json b/test/tsconfig.json index d64527e9e25..1643ad32432 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -145,7 +145,6 @@ "../src/rules/typedefRule.ts", "../src/rules/typedefWhitespaceRule.ts", "../src/rules/useIsnanRule.ts", - "../src/rules/useStrictRule.ts", "../src/rules/variableNameRule.ts", "../src/rules/whitespaceRule.ts", "../src/test.ts", From 01e9e3c540f9c9e59152f4fa18f4dd3705873690 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 17:31:52 -0400 Subject: [PATCH 008/111] Rename no-constructor-vars to no-parameter-properties (#1616) Resolves #1296. --- README.md | 2 +- docs/_data/rules.json | 22 +++++++++---------- .../index.html | 0 src/configs/recommended.ts | 2 +- ...rsRule.ts => noParameterPropertiesRule.ts} | 8 +++---- src/tsconfig.json | 4 ++-- test/rules/no-constructor-vars/tslint.json | 5 ----- .../test.ts.lint | 0 .../rules/no-parameter-properties/tslint.json | 5 +++++ test/tsconfig.json | 4 ++-- 10 files changed, 26 insertions(+), 26 deletions(-) rename docs/rules/{no-constructor-vars => no-parameter-properties}/index.html (100%) rename src/rules/{noConstructorVarsRule.ts => noParameterPropertiesRule.ts} (88%) delete mode 100644 test/rules/no-constructor-vars/tslint.json rename test/rules/{no-constructor-vars => no-parameter-properties}/test.ts.lint (100%) create mode 100644 test/rules/no-parameter-properties/tslint.json diff --git a/README.md b/README.md index 6a8c8323968..9c77ceae6ff 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ The configuration file specifies which rules are enabled and their options. Thes /* * Any rules specified here will override those from the base config we are extending */ - "no-constructor-vars": true + "no-parameter-properties": true }, "rulesDirectory": [ /* diff --git a/docs/_data/rules.json b/docs/_data/rules.json index f98b7f7ddd6..cf2f09bccb1 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -421,17 +421,6 @@ ], "type": "functionality" }, - { - "ruleName": "no-constructor-vars", - "description": "Disallows parameter properties.", - "rationale": "\nParameter properties can be confusing to those new to TS as they are less explicit\nthan other ways of declaring and initializing class members.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "style" - }, { "ruleName": "no-construct", "description": "Disallows access to the constructors of `String`, `Number`, and `Boolean`.", @@ -624,6 +613,17 @@ ], "type": "functionality" }, + { + "ruleName": "no-parameter-properties", + "description": "Disallows parameter properties.", + "rationale": "\nParameter properties can be confusing to those new to TS as they are less explicit\nthan other ways of declaring and initializing class members.", + "optionsDescription": "Not configurable.", + "options": null, + "optionExamples": [ + "true" + ], + "type": "style" + }, { "ruleName": "no-reference", "description": "Disallows `/// ` imports (use ES6-style imports instead).", diff --git a/docs/rules/no-constructor-vars/index.html b/docs/rules/no-parameter-properties/index.html similarity index 100% rename from docs/rules/no-constructor-vars/index.html rename to docs/rules/no-parameter-properties/index.html diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index 99b52e95cb7..2f4992afa3b 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -52,7 +52,6 @@ export const rules = { "trace", ], "no-construct": true, - "no-constructor-vars": false, "no-debugger": true, "no-duplicate-key": true, "no-duplicate-variable": true, @@ -60,6 +59,7 @@ export const rules = { "no-eval": true, "no-internal-module": true, "no-namespace": true, + "no-parameter-properties": false, "no-reference": true, "no-shadowed-variable": true, "no-string-literal": true, diff --git a/src/rules/noConstructorVarsRule.ts b/src/rules/noParameterPropertiesRule.ts similarity index 88% rename from src/rules/noConstructorVarsRule.ts rename to src/rules/noParameterPropertiesRule.ts index 446bb1e1138..eba4b6e8c4f 100644 --- a/src/rules/noConstructorVarsRule.ts +++ b/src/rules/noParameterPropertiesRule.ts @@ -22,8 +22,8 @@ import * as Lint from "../lint"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ public static metadata: Lint.IRuleMetadata = { - ruleName: "no-constructor-vars", - description: "Disallows parameter properties.", + ruleName: "no-parameter-properties", + description: "Disallows parameter properties in class constructors.", rationale: Lint.Utils.dedent` Parameter properties can be confusing to those new to TS as they are less explicit than other ways of declaring and initializing class members.`, @@ -37,11 +37,11 @@ export class Rule extends Lint.Rules.AbstractRule { public static FAILURE_STRING_FACTORY = (ident: string) => `Property '${ident}' cannot be declared in the constructor`; public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new NoConstructorVarsWalker(sourceFile, this.getOptions())); + return this.applyWithWalker(new NoParameterPropertiesWalker(sourceFile, this.getOptions())); } } -export class NoConstructorVarsWalker extends Lint.RuleWalker { +export class NoParameterPropertiesWalker extends Lint.RuleWalker { public visitConstructorDeclaration(node: ts.ConstructorDeclaration) { const parameters = node.parameters; for (let parameter of parameters) { diff --git a/src/tsconfig.json b/src/tsconfig.json index a4db5f9f864..9e3da7de7fa 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -103,7 +103,6 @@ "rules/noConditionalAssignmentRule.ts", "rules/noConsecutiveBlankLinesRule.ts", "rules/noConsoleRule.ts", - "rules/noConstructorVarsRule.ts", "rules/noConstructRule.ts", "rules/noDebuggerRule.ts", "rules/noDefaultExportRule.ts", @@ -118,6 +117,7 @@ "rules/noMergeableNamespaceRule.ts", "rules/noNamespaceRule.ts", "rules/noNullKeywordRule.ts", + "rules/noParameterPropertiesRule.ts", "rules/noReferenceRule.ts", "rules/noRequireImportsRule.ts", "rules/noShadowedVariableRule.ts", @@ -157,4 +157,4 @@ "test/parse.ts", "test/utils.ts" ] -} +} \ No newline at end of file diff --git a/test/rules/no-constructor-vars/tslint.json b/test/rules/no-constructor-vars/tslint.json deleted file mode 100644 index 6a614c47fcf..00000000000 --- a/test/rules/no-constructor-vars/tslint.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "no-constructor-vars": true - } -} diff --git a/test/rules/no-constructor-vars/test.ts.lint b/test/rules/no-parameter-properties/test.ts.lint similarity index 100% rename from test/rules/no-constructor-vars/test.ts.lint rename to test/rules/no-parameter-properties/test.ts.lint diff --git a/test/rules/no-parameter-properties/tslint.json b/test/rules/no-parameter-properties/tslint.json new file mode 100644 index 00000000000..c65a294034b --- /dev/null +++ b/test/rules/no-parameter-properties/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-parameter-properties": true + } +} diff --git a/test/tsconfig.json b/test/tsconfig.json index 1643ad32432..f95a9ac9338 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -98,7 +98,6 @@ "../src/rules/noConditionalAssignmentRule.ts", "../src/rules/noConsecutiveBlankLinesRule.ts", "../src/rules/noConsoleRule.ts", - "../src/rules/noConstructorVarsRule.ts", "../src/rules/noConstructRule.ts", "../src/rules/noDebuggerRule.ts", "../src/rules/noDefaultExportRule.ts", @@ -113,6 +112,7 @@ "../src/rules/noMergeableNamespaceRule.ts", "../src/rules/noNamespaceRule.ts", "../src/rules/noNullKeywordRule.ts", + "../src/rules/noParameterPropertiesRule.ts", "../src/rules/noReferenceRule.ts", "../src/rules/noRequireImportsRule.ts", "../src/rules/noShadowedVariableRule.ts", @@ -179,4 +179,4 @@ "rule-tester/testData.ts", "rule-tester/utilsTests.ts" ] -} +} \ No newline at end of file From 670672e56c996c016235d82e7eb062feaff7b1f0 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 20:02:51 -0400 Subject: [PATCH 009/111] Build system enhancements (#1619) - Remove `typings/` and TSD, install ambient types from NPM - Remove grunt, use NPM scripts instead - Enable new compiler options `--noUnusedParameters` and `--noUnusedLocals` --- .eslintrc.json | 9 - .gitignore | 3 + Gruntfile.js | 127 - appveyor.yml | 4 +- circle.yml | 3 + custom-typings/resolve.d.ts | 29 - package.json | 40 +- scripts/buildDocs.ts | 2 + .../custom-typings.d.ts | 0 scripts/tsconfig.json | 35 +- src/language/rule/typedRule.ts | 2 +- src/language/utils.ts | 2 +- src/rules/memberOrderingRule.ts | 8 +- src/rules/noDuplicateVariableRule.ts | 4 +- src/rules/noShadowedVariableRule.ts | 12 +- src/test.ts | 4 +- src/tsconfig.json | 157 +- src/utils.ts | 2 +- test/tsconfig.json | 181 +- test/tsd.json | 14 - test/typings/chai/chai.d.ts | 283 - test/typings/mocha/mocha.d.ts | 166 - tsd.json | 39 - tslint.json | 7 + typings/colors/colors.d.ts | 137 - typings/diff/diff.d.ts | 88 - typings/findup-sync/findup-sync.d.ts | 18 - typings/glob/glob.d.ts | 112 - typings/js-yaml/js-yaml.d.ts | 85 - typings/minimatch/minimatch.d.ts | 64 - typings/node/node.d.ts | 3734 ---------- typings/optimist/optimist.d.ts | 89 - typings/tsd.d.ts | 10 - .../underscore.string/underscore.string.d.ts | 580 -- typings/underscore/underscore.d.ts | 6085 ----------------- 35 files changed, 83 insertions(+), 12052 deletions(-) delete mode 100644 .eslintrc.json delete mode 100644 Gruntfile.js delete mode 100644 custom-typings/resolve.d.ts rename custom-typings/object.d.ts => scripts/custom-typings.d.ts (100%) delete mode 100644 test/tsd.json delete mode 100644 test/typings/chai/chai.d.ts delete mode 100644 test/typings/mocha/mocha.d.ts delete mode 100644 tsd.json delete mode 100644 typings/colors/colors.d.ts delete mode 100644 typings/diff/diff.d.ts delete mode 100644 typings/findup-sync/findup-sync.d.ts delete mode 100644 typings/glob/glob.d.ts delete mode 100644 typings/js-yaml/js-yaml.d.ts delete mode 100644 typings/minimatch/minimatch.d.ts delete mode 100644 typings/node/node.d.ts delete mode 100644 typings/optimist/optimist.d.ts delete mode 100644 typings/tsd.d.ts delete mode 100644 typings/underscore.string/underscore.string.d.ts delete mode 100644 typings/underscore/underscore.d.ts diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 6179039e4b1..00000000000 --- a/.eslintrc.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "extends": "eslint:recommended", - "env": { - "node": true - }, - "rules": { - "comma-dangle": ["error", "always-multiline"] - } -} diff --git a/.gitignore b/.gitignore index 6cebaca4f5b..e631b300bcf 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ typings/.basedir.ts # vim swap files *.swo *.swp + +# grunt-ts, see See https://github.com/grunt-ts/grunt-ts/issues/77 +.baseDir.ts diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index e8acf9fa740..00000000000 --- a/Gruntfile.js +++ /dev/null @@ -1,127 +0,0 @@ -"use strict"; - -var checkBinTest; -if (process.platform === "win32") { - checkBinTest = []; -} else { - checkBinTest = ["run:testBin"]; -} - -module.exports = function (grunt) { - grunt.initConfig({ - pkg: grunt.file.readJSON("package.json"), - - eslint: { - target: [ - "Gruntfile.js", - "test/files/formatters/*.js", - ], - }, - - clean: { - core: ["lib/**/*.js", "lib/**/*.d.ts"], - scripts: ["scripts/*.js"], - test: ["build/", "test/config/node_modules/"], - }, - - mochaTest: { - test: { - options: { - reporter: "spec", - }, - src: ["build/test/**/*Tests.js", "build/test/assert.js"], - }, - }, - - run: { - testBin: { - cmd: "./test/check-bin.sh", - options: {quiet: Infinity}, - }, - testRules: { - args: ["./build/test/ruleTestRunner.js"], - }, - docs: { - cmd: "node", - args: ["buildDocs.js"], - options: {cwd: "./scripts/"}, - }, - }, - - tslint: { - src: [ - "src/*.ts", - "src/configs/**/*.ts", - "src/formatters/**/*.ts", - "src/language/**/*.ts", - "src/rules/**/*.ts", - "src/test/**/*.ts", - ], - scripts: [ - "scripts/**/*.ts", - ], - test: [ - "test/**/*.ts", - "!test/**/*.test.ts", - "!test/typings/**/*.ts", - ], - }, - - ts: { - core: { - tsconfig: "src/tsconfig.json", - }, - scripts: { - tsconfig: "scripts/tsconfig.json", - }, - test: { - tsconfig: "test/tsconfig.json", - }, - }, - - "npm-command": { - test: { - options: { - cwd: "./test/config", - }, - }, - }, - }); - - // load NPM tasks - grunt.loadNpmTasks("grunt-contrib-clean"); - grunt.loadNpmTasks("grunt-eslint"); - grunt.loadNpmTasks("grunt-mocha-test"); - grunt.loadNpmTasks("grunt-run"); - grunt.loadNpmTasks("grunt-tslint"); - grunt.loadNpmTasks("grunt-ts"); - grunt.loadNpmTasks("grunt-npm-command"); - - // register custom tasks - grunt.registerTask("core", [ - "clean:core", - "ts:core", - "tslint:src", - ]); - grunt.registerTask("scripts", [ - "clean:scripts", - "ts:scripts", - "tslint:scripts", - ]); - grunt.registerTask("test", [ - "clean:test", - "npm-command:test", - "ts:test", - "tslint:test", - "mochaTest", - "run:testRules", - ].concat(checkBinTest)); - // generates new docs metadata files - grunt.registerTask("docs", [ - "default", - "run:docs", - ]); - - // create default task - grunt.registerTask("default", ["eslint", "core", "scripts", "test"]); -}; diff --git a/appveyor.yml b/appveyor.yml index 345574d588c..7cfb2bbfa21 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,12 +7,10 @@ environment: install: - ps: Install-Product node $env:nodejs_version - npm install - - npm install -g grunt-cli test_script: - node --version - npm --version - - grunt --version - - grunt + - npm run verify build: off diff --git a/circle.yml b/circle.yml index 6530894cdfb..1387283aaff 100644 --- a/circle.yml +++ b/circle.yml @@ -5,6 +5,9 @@ general: dependencies: pre: - case $CIRCLE_NODE_INDEX in 0) nvm use 4.2 ;; 1) nvm use 5.7 ;; 2) nvm use 6.1 ;; esac +test: + override: + - npm run verify deployment: npm-latest: # match semver tag (e.g. 3.12.7) diff --git a/custom-typings/resolve.d.ts b/custom-typings/resolve.d.ts deleted file mode 100644 index 31ab1a0d164..00000000000 --- a/custom-typings/resolve.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -declare module "resolve" { - interface ResolveOptions { - basedir?: string; - extensions?: string[]; - paths?: string[]; - moduleDirectory?: string | string[]; - } - interface AsyncResolveOptions extends ResolveOptions { - package?: any; - readFile?: Function; - isFile?: (file: string, cb: Function) => void; - packageFilter?: Function; - pathFilter?: Function; - } - interface SyncResolveOptions extends ResolveOptions { - readFile?: Function; - isFile?: (file: string) => boolean; - packageFilter?: Function; - } - interface ResolveFunction { - (id: string, cb: (err: any, res: string, pkg: any) => void): void; - (id: string, opts: AsyncResolveOptions, cb: (err: any, res: string, pkg: any) => void): void; - sync(id: string, opts?: SyncResolveOptions): string; - isCore(pkg: any): any; - } - - const resolve: ResolveFunction; - export = resolve; -} diff --git a/package.json b/package.json index d06da7c24c9..3907b35d8fb 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,23 @@ "linter" ], "scripts": { - "test": "grunt" + "clean": "npm-run-all -p clean:core clean:test", + "clean:core": "rm -rf lib", + "clean:test": "rm -rf build && rm -rf test/config/node_modules", + "docs": "node scripts/buildDocs.js", + "compile": "npm-run-all -p compile:core compile:test -s compile:scripts", + "compile:core": "tsc -p src", + "compile:scripts": "tsc -p scripts", + "compile:test": "tsc -p test", + "lint": "npm-run-all -p lint:core lint:test", + "lint:core": "tslint src/**/*.ts", + "lint:test": "tslint test/**/*.ts -e test/**/*.test.ts", + "test": "npm-run-all test:pre -p test:bin test:mocha test:rules", + "test:pre": "cd ./test/config && npm install", + "test:bin": "./test/check-bin.sh &> /dev/null", + "test:mocha": "mocha --reporter spec --colors build/test/**/*Tests.js build/test/assert.js", + "test:rules": "node ./build/test/ruleTestRunner.js", + "verify": "npm-run-all clean compile lint test docs" }, "dependencies": { "colors": "^1.1.2", @@ -29,18 +45,22 @@ "underscore.string": "^3.3.4" }, "devDependencies": { + "@types/chai": "^3.4.34", + "@types/colors": "^0.6.33", + "@types/diff": "0.0.31", + "@types/findup-sync": "^0.3.29", + "@types/glob": "^5.0.30", + "@types/js-yaml": "^3.5.28", + "@types/mocha": "^2.2.32", + "@types/node": "^6.0.45", + "@types/optimist": "0.0.29", + "@types/resolve": "0.0.4", + "@types/underscore": "^1.7.33", + "@types/underscore.string": "0.0.30", "chai": "^3.0.0", - "grunt": "^1.0.1", - "grunt-cli": "^1.2.0", - "grunt-contrib-clean": "^1.0.0", - "grunt-eslint": "^19.0.0", - "grunt-mocha-test": "^0.13.2", - "grunt-npm-command": "^0.1.2", - "grunt-run": "~0.6.0", - "grunt-ts": "^5.5.1", - "grunt-tslint": "latest", "js-yaml": "^3.6.1", "mocha": "^3.1.0", + "npm-run-all": "^3.1.0", "tslint": "latest", "tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative", "typescript": "2.0.3" diff --git a/scripts/buildDocs.ts b/scripts/buildDocs.ts index 79cfee250f0..937928927b5 100644 --- a/scripts/buildDocs.ts +++ b/scripts/buildDocs.ts @@ -76,6 +76,8 @@ interface IDocumentation { const DOCS_DIR = "../docs"; +process.chdir("./scripts"); + /** * Documentation definition for rule modules. */ diff --git a/custom-typings/object.d.ts b/scripts/custom-typings.d.ts similarity index 100% rename from custom-typings/object.d.ts rename to scripts/custom-typings.d.ts diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index f48ffa18db7..a289747f09e 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -1,35 +1,12 @@ { - "version": "1.8.0", + "version": "2.0.3", "compilerOptions": { "module": "commonjs", "noImplicitAny": true, + "noUnusedParameters": true, + "noUnusedLocals": true, "declaration": false, "sourceMap": false, - "target": "es5", - "outDir": "." - }, - "atom": { - "rewriteTsconfig": false - }, - "filesGlob": [ - "../custom-typings/**/*.d.ts", - "../typings/**/*.d.ts", - "./*.ts" - ], - "files": [ - "../custom-typings/object.d.ts", - "../custom-typings/resolve.d.ts", - "../typings/colors/colors.d.ts", - "../typings/diff/diff.d.ts", - "../typings/findup-sync/findup-sync.d.ts", - "../typings/glob/glob.d.ts", - "../typings/js-yaml/js-yaml.d.ts", - "../typings/minimatch/minimatch.d.ts", - "../typings/node/node.d.ts", - "../typings/optimist/optimist.d.ts", - "../typings/tsd.d.ts", - "../typings/underscore.string/underscore.string.d.ts", - "../typings/underscore/underscore.d.ts", - "buildDocs.ts" - ] -} \ No newline at end of file + "target": "es5" + } +} diff --git a/src/language/rule/typedRule.ts b/src/language/rule/typedRule.ts index 05b5797bb45..1489165bd55 100644 --- a/src/language/rule/typedRule.ts +++ b/src/language/rule/typedRule.ts @@ -21,7 +21,7 @@ import {AbstractRule} from "./abstractRule"; import {RuleFailure} from "./rule"; export abstract class TypedRule extends AbstractRule { - public apply(sourceFile: ts.SourceFile): RuleFailure[] { + public apply(_sourceFile: ts.SourceFile): RuleFailure[] { // if no program is given to the linter, throw an error throw new Error(`${this.getOptions().ruleName} requires type checking`); } diff --git a/src/language/utils.ts b/src/language/utils.ts index 5982866821a..5e1ecb8241c 100644 --- a/src/language/utils.ts +++ b/src/language/utils.ts @@ -29,7 +29,7 @@ export function getSourceFile(fileName: string, source: string): ts.SourceFile { getCanonicalFileName: (filename: string) => filename, getCurrentDirectory: () => "", getDefaultLibFileName: () => "lib.d.ts", - getDirectories: (path: string) => [], + getDirectories: (_path: string) => [], getNewLine: () => "\n", getSourceFile: (filenameToGet: string) => { if (filenameToGet === normalizedName) { diff --git a/src/rules/memberOrderingRule.ts b/src/rules/memberOrderingRule.ts index 614070f4f5b..648f705fb42 100644 --- a/src/rules/memberOrderingRule.ts +++ b/src/rules/memberOrderingRule.ts @@ -275,11 +275,11 @@ export class MemberOrderingWalker extends Lint.RuleWalker { super.visitPropertySignature(node); } - public visitTypeLiteral(node: ts.TypeLiteralNode) { + public visitTypeLiteral(_node: ts.TypeLiteralNode) { // don't call super from here -- we want to skip the property declarations in type literals } - public visitObjectLiteralExpression(node: ts.ObjectLiteralExpression) { + public visitObjectLiteralExpression(_node: ts.ObjectLiteralExpression) { // again, don't call super here - object literals can have methods, // and we don't wan't to check these } @@ -298,7 +298,7 @@ export class MemberOrderingWalker extends Lint.RuleWalker { const failure = this.createFailure( node.getStart(), node.getWidth(), - `Declaration of ${toString(currentMember)} not allowed to appear after declaration of ${toString(this.previousMember)}` + `Declaration of ${toString(currentMember)} not allowed to appear after declaration of ${toString(this.previousMember)}`, ); this.addFailure(failure); } @@ -367,7 +367,7 @@ export class MemberOrderingWalker extends Lint.RuleWalker { this.addFailure(this.createFailure( node.getStart(), node.getWidth(), - errorLine1 + errorLine1, )); } else { // keep track of last good node diff --git a/src/rules/noDuplicateVariableRule.ts b/src/rules/noDuplicateVariableRule.ts index 17c7694d625..264adaf7e02 100644 --- a/src/rules/noDuplicateVariableRule.ts +++ b/src/rules/noDuplicateVariableRule.ts @@ -71,11 +71,11 @@ class NoDuplicateVariableWalker extends Lint.BlockScopeAwareRuleWalker<{}, Scope this.visitBlock(node.block); } - public visitMethodSignature(node: ts.SignatureDeclaration) { + public visitMethodSignature(_node: ts.SignatureDeclaration) { // don't call super, we don't want to walk method signatures either } - public visitTypeLiteral(node: ts.TypeLiteralNode) { + public visitTypeLiteral(_node: ts.TypeLiteralNode) { // don't call super, we don't want to walk the inside of type nodes } diff --git a/src/rules/noShadowedVariableRule.ts b/src/rules/noShadowedVariableRule.ts index 8d32fd53705..c6fd5b261dd 100644 --- a/src/rules/noShadowedVariableRule.ts +++ b/src/rules/noShadowedVariableRule.ts @@ -71,23 +71,23 @@ class NoShadowedVariableWalker extends Lint.BlockScopeAwareRuleWalker filename, getCurrentDirectory: () => "", getDefaultLibFileName: () => ts.getDefaultLibFileName(compilerOptions), - getDirectories: (path: string) => [], + getDirectories: (_path: string) => [], getNewLine: () => "\n", getSourceFile(filenameToGet: string) { if (filenameToGet === this.getDefaultLibFileName()) { diff --git a/src/tsconfig.json b/src/tsconfig.json index 9e3da7de7fa..797e7d67879 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,160 +1,13 @@ { - "version": "1.8.10", + "version": "2.0.3", "compilerOptions": { "module": "commonjs", "noImplicitAny": true, + "noUnusedParameters": true, + "noUnusedLocals": true, "declaration": true, "sourceMap": false, "target": "es5", "outDir": "../lib" - }, - "atom": { - "rewriteTsconfig": false - }, - "filesGlob": [ - "../custom-typings/**/*.d.ts", - "../typings/**/*.d.ts", - "./*.ts", - "./configs/**/*.ts", - "./formatters/**/*.ts", - "./language/**/*.ts", - "./rules/**/*.ts", - "./test/**/*.ts" - ], - "files": [ - "../custom-typings/object.d.ts", - "../custom-typings/resolve.d.ts", - "../typings/colors/colors.d.ts", - "../typings/diff/diff.d.ts", - "../typings/findup-sync/findup-sync.d.ts", - "../typings/glob/glob.d.ts", - "../typings/js-yaml/js-yaml.d.ts", - "../typings/minimatch/minimatch.d.ts", - "../typings/node/node.d.ts", - "../typings/optimist/optimist.d.ts", - "../typings/tsd.d.ts", - "../typings/underscore.string/underscore.string.d.ts", - "../typings/underscore/underscore.d.ts", - "configuration.ts", - "enableDisableRules.ts", - "formatterLoader.ts", - "formatters.ts", - "lint.ts", - "ruleLoader.ts", - "rules.ts", - "test.ts", - "tslint-cli.ts", - "tslint.ts", - "tslintMulti.ts", - "utils.ts", - "configs/latest.ts", - "configs/recommended.ts", - "formatters/applyFixesFormatter.ts", - "formatters/checkstyleFormatter.ts", - "formatters/fileslistFormatter.ts", - "formatters/index.ts", - "formatters/jsonFormatter.ts", - "formatters/msbuildFormatter.ts", - "formatters/pmdFormatter.ts", - "formatters/proseFormatter.ts", - "formatters/stylishFormatter.ts", - "formatters/verboseFormatter.ts", - "formatters/vsoFormatter.ts", - "language/formatter/abstractFormatter.ts", - "language/formatter/formatter.ts", - "language/languageServiceHost.ts", - "language/rule/abstractRule.ts", - "language/rule/rule.ts", - "language/rule/typedRule.ts", - "language/utils.ts", - "language/walker/blockScopeAwareRuleWalker.ts", - "language/walker/index.ts", - "language/walker/programAwareRuleWalker.ts", - "language/walker/ruleWalker.ts", - "language/walker/scopeAwareRuleWalker.ts", - "language/walker/skippableTokenAwareRuleWalker.ts", - "language/walker/syntaxWalker.ts", - "rules/adjacentOverloadSignaturesRule.ts", - "rules/alignRule.ts", - "rules/arrayTypeRule.ts", - "rules/arrowParensRule.ts", - "rules/banRule.ts", - "rules/classNameRule.ts", - "rules/commentFormatRule.ts", - "rules/curlyRule.ts", - "rules/cyclomaticComplexityRule.ts", - "rules/eoflineRule.ts", - "rules/fileHeaderRule.ts", - "rules/forinRule.ts", - "rules/indentRule.ts", - "rules/interfaceNameRule.ts", - "rules/jsdocFormatRule.ts", - "rules/labelPositionRule.ts", - "rules/linebreakStyleRule.ts", - "rules/maxFileLineCountRule.ts", - "rules/maxLineLengthRule.ts", - "rules/memberAccessRule.ts", - "rules/memberOrderingRule.ts", - "rules/newParensRule.ts", - "rules/noAngleBracketTypeAssertionRule.ts", - "rules/noAnyRule.ts", - "rules/noArgRule.ts", - "rules/noBitwiseRule.ts", - "rules/noConditionalAssignmentRule.ts", - "rules/noConsecutiveBlankLinesRule.ts", - "rules/noConsoleRule.ts", - "rules/noConstructRule.ts", - "rules/noDebuggerRule.ts", - "rules/noDefaultExportRule.ts", - "rules/noDuplicateKeyRule.ts", - "rules/noDuplicateVariableRule.ts", - "rules/noEmptyRule.ts", - "rules/noEvalRule.ts", - "rules/noForInArrayRule.ts", - "rules/noInferrableTypesRule.ts", - "rules/noInternalModuleRule.ts", - "rules/noInvalidThisRule.ts", - "rules/noMergeableNamespaceRule.ts", - "rules/noNamespaceRule.ts", - "rules/noNullKeywordRule.ts", - "rules/noParameterPropertiesRule.ts", - "rules/noReferenceRule.ts", - "rules/noRequireImportsRule.ts", - "rules/noShadowedVariableRule.ts", - "rules/noStringLiteralRule.ts", - "rules/noSwitchCaseFallThroughRule.ts", - "rules/noTrailingWhitespaceRule.ts", - "rules/noUnreachableRule.ts", - "rules/noUnsafeFinallyRule.ts", - "rules/noUnusedExpressionRule.ts", - "rules/noUnusedNewRule.ts", - "rules/noUnusedVariableRule.ts", - "rules/noUseBeforeDeclareRule.ts", - "rules/noVarKeywordRule.ts", - "rules/noVarRequiresRule.ts", - "rules/objectLiteralKeyQuotesRule.ts", - "rules/objectLiteralShorthandRule.ts", - "rules/objectLiteralSortKeysRule.ts", - "rules/oneLineRule.ts", - "rules/oneVariablePerDeclarationRule.ts", - "rules/onlyArrowFunctionsRule.ts", - "rules/orderedImportsRule.ts", - "rules/preferForOfRule.ts", - "rules/quotemarkRule.ts", - "rules/radixRule.ts", - "rules/restrictPlusOperandsRule.ts", - "rules/semicolonRule.ts", - "rules/switchDefaultRule.ts", - "rules/trailingCommaRule.ts", - "rules/tripleEqualsRule.ts", - "rules/typedefRule.ts", - "rules/typedefWhitespaceRule.ts", - "rules/useIsnanRule.ts", - "rules/variableNameRule.ts", - "rules/whitespaceRule.ts", - "test/lines.ts", - "test/lintError.ts", - "test/parse.ts", - "test/utils.ts" - ] -} \ No newline at end of file + } +} diff --git a/src/utils.ts b/src/utils.ts index a288c59199f..20743afd41a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -66,7 +66,7 @@ export function stripComments(content: string): string { * Fourth matches line comments */ const regexp: RegExp = /("(?:[^\\\"]*(?:\\.)?)*")|('(?:[^\\\']*(?:\\.)?)*')|(\/\*(?:\r?\n|.)*?\*\/)|(\/{2,}.*?(?:(?:\r?\n)|$))/g; - let result = content.replace(regexp, (match, m1, m2, m3, m4) => { + let result = content.replace(regexp, (match, _m1, _m2, m3, m4) => { // Only one of m1, m2, m3, m4 matches if (m3) { // A block comment. Replace with nothing diff --git a/test/tsconfig.json b/test/tsconfig.json index f95a9ac9338..d672d8b5146 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,182 +1,19 @@ { - "version": "1.8.10", + "version": "2.0.3", "compilerOptions": { "module": "commonjs", "noImplicitAny": true, + "noUnusedParameters": true, + "noUnusedLocals": true, "sourceMap": false, "target": "es5", "outDir": "../build" }, - "atom": { - "rewriteTsconfig": false - }, - "filesGlob": [ - "../custom-typings/**/*.d.ts", - "../typings/**/*.d.ts", - "./typings/**/*.d.ts", - "../src/**/*.ts", - "./*.ts", - "./formatters/*.ts", - "./rule-tester/*.ts" + "include": [ + "../src/**/*", + "**/*" ], - "files": [ - "../custom-typings/object.d.ts", - "../custom-typings/resolve.d.ts", - "../typings/colors/colors.d.ts", - "../typings/diff/diff.d.ts", - "../typings/findup-sync/findup-sync.d.ts", - "../typings/glob/glob.d.ts", - "../typings/js-yaml/js-yaml.d.ts", - "../typings/minimatch/minimatch.d.ts", - "../typings/node/node.d.ts", - "../typings/optimist/optimist.d.ts", - "../typings/tsd.d.ts", - "../typings/underscore.string/underscore.string.d.ts", - "../typings/underscore/underscore.d.ts", - "typings/chai/chai.d.ts", - "typings/mocha/mocha.d.ts", - "../src/configs/latest.ts", - "../src/configs/recommended.ts", - "../src/configuration.ts", - "../src/enableDisableRules.ts", - "../src/formatterLoader.ts", - "../src/formatters.ts", - "../src/formatters/applyFixesFormatter.ts", - "../src/formatters/checkstyleFormatter.ts", - "../src/formatters/fileslistFormatter.ts", - "../src/formatters/index.ts", - "../src/formatters/jsonFormatter.ts", - "../src/formatters/msbuildFormatter.ts", - "../src/formatters/pmdFormatter.ts", - "../src/formatters/proseFormatter.ts", - "../src/formatters/stylishFormatter.ts", - "../src/formatters/verboseFormatter.ts", - "../src/formatters/vsoFormatter.ts", - "../src/language/formatter/abstractFormatter.ts", - "../src/language/formatter/formatter.ts", - "../src/language/languageServiceHost.ts", - "../src/language/rule/abstractRule.ts", - "../src/language/rule/rule.ts", - "../src/language/rule/typedRule.ts", - "../src/language/utils.ts", - "../src/language/walker/blockScopeAwareRuleWalker.ts", - "../src/language/walker/index.ts", - "../src/language/walker/programAwareRuleWalker.ts", - "../src/language/walker/ruleWalker.ts", - "../src/language/walker/scopeAwareRuleWalker.ts", - "../src/language/walker/skippableTokenAwareRuleWalker.ts", - "../src/language/walker/syntaxWalker.ts", - "../src/lint.ts", - "../src/ruleLoader.ts", - "../src/rules.ts", - "../src/rules/adjacentOverloadSignaturesRule.ts", - "../src/rules/alignRule.ts", - "../src/rules/arrayTypeRule.ts", - "../src/rules/arrowParensRule.ts", - "../src/rules/banRule.ts", - "../src/rules/classNameRule.ts", - "../src/rules/commentFormatRule.ts", - "../src/rules/curlyRule.ts", - "../src/rules/cyclomaticComplexityRule.ts", - "../src/rules/eoflineRule.ts", - "../src/rules/fileHeaderRule.ts", - "../src/rules/forinRule.ts", - "../src/rules/indentRule.ts", - "../src/rules/interfaceNameRule.ts", - "../src/rules/jsdocFormatRule.ts", - "../src/rules/labelPositionRule.ts", - "../src/rules/linebreakStyleRule.ts", - "../src/rules/maxFileLineCountRule.ts", - "../src/rules/maxLineLengthRule.ts", - "../src/rules/memberAccessRule.ts", - "../src/rules/memberOrderingRule.ts", - "../src/rules/newParensRule.ts", - "../src/rules/noAngleBracketTypeAssertionRule.ts", - "../src/rules/noAnyRule.ts", - "../src/rules/noArgRule.ts", - "../src/rules/noBitwiseRule.ts", - "../src/rules/noConditionalAssignmentRule.ts", - "../src/rules/noConsecutiveBlankLinesRule.ts", - "../src/rules/noConsoleRule.ts", - "../src/rules/noConstructRule.ts", - "../src/rules/noDebuggerRule.ts", - "../src/rules/noDefaultExportRule.ts", - "../src/rules/noDuplicateKeyRule.ts", - "../src/rules/noDuplicateVariableRule.ts", - "../src/rules/noEmptyRule.ts", - "../src/rules/noEvalRule.ts", - "../src/rules/noForInArrayRule.ts", - "../src/rules/noInferrableTypesRule.ts", - "../src/rules/noInternalModuleRule.ts", - "../src/rules/noInvalidThisRule.ts", - "../src/rules/noMergeableNamespaceRule.ts", - "../src/rules/noNamespaceRule.ts", - "../src/rules/noNullKeywordRule.ts", - "../src/rules/noParameterPropertiesRule.ts", - "../src/rules/noReferenceRule.ts", - "../src/rules/noRequireImportsRule.ts", - "../src/rules/noShadowedVariableRule.ts", - "../src/rules/noStringLiteralRule.ts", - "../src/rules/noSwitchCaseFallThroughRule.ts", - "../src/rules/noTrailingWhitespaceRule.ts", - "../src/rules/noUnreachableRule.ts", - "../src/rules/noUnsafeFinallyRule.ts", - "../src/rules/noUnusedExpressionRule.ts", - "../src/rules/noUnusedNewRule.ts", - "../src/rules/noUnusedVariableRule.ts", - "../src/rules/noUseBeforeDeclareRule.ts", - "../src/rules/noVarKeywordRule.ts", - "../src/rules/noVarRequiresRule.ts", - "../src/rules/objectLiteralKeyQuotesRule.ts", - "../src/rules/objectLiteralShorthandRule.ts", - "../src/rules/objectLiteralSortKeysRule.ts", - "../src/rules/oneLineRule.ts", - "../src/rules/oneVariablePerDeclarationRule.ts", - "../src/rules/onlyArrowFunctionsRule.ts", - "../src/rules/orderedImportsRule.ts", - "../src/rules/preferForOfRule.ts", - "../src/rules/quotemarkRule.ts", - "../src/rules/radixRule.ts", - "../src/rules/restrictPlusOperandsRule.ts", - "../src/rules/semicolonRule.ts", - "../src/rules/switchDefaultRule.ts", - "../src/rules/trailingCommaRule.ts", - "../src/rules/tripleEqualsRule.ts", - "../src/rules/typedefRule.ts", - "../src/rules/typedefWhitespaceRule.ts", - "../src/rules/useIsnanRule.ts", - "../src/rules/variableNameRule.ts", - "../src/rules/whitespaceRule.ts", - "../src/test.ts", - "../src/test/lines.ts", - "../src/test/lintError.ts", - "../src/test/parse.ts", - "../src/test/utils.ts", - "../src/tslint-cli.ts", - "../src/tslint.ts", - "../src/tslintMulti.ts", - "../src/utils.ts", - "assert.ts", - "configurationTests.ts", - "eofLineRuleTests.ts", - "lint.ts", - "ruleLoaderTests.ts", - "ruleTestRunner.ts", - "utils.ts", - "utilsTests.ts", - "formatters/checkstyleFormatterTests.ts", - "formatters/externalFormatterTests.ts", - "formatters/fileslistFormatterTests.ts", - "formatters/jsonFormatterTests.ts", - "formatters/msbuildFormatterTests.ts", - "formatters/pmdFormatterTests.ts", - "formatters/proseFormatterTests.ts", - "formatters/stylishFormatterTests.ts", - "formatters/verboseFormatterTests.ts", - "formatters/vsoFormatterTests.ts", - "rule-tester/linesTests.ts", - "rule-tester/parseTests.ts", - "rule-tester/testData.ts", - "rule-tester/utilsTests.ts" + "exclude": [ + "./files" ] -} \ No newline at end of file +} diff --git a/test/tsd.json b/test/tsd.json deleted file mode 100644 index 7266793fd1c..00000000000 --- a/test/tsd.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "version": "v4", - "repo": "borisyankov/DefinitelyTyped", - "ref": "master", - "path": "typings", - "installed": { - "chai/chai.d.ts": { - "commit": "aadd63ecae3feb76ea2d4be80511e266b5c2c4a7" - }, - "mocha/mocha.d.ts": { - "commit": "aadd63ecae3feb76ea2d4be80511e266b5c2c4a7" - } - } -} diff --git a/test/typings/chai/chai.d.ts b/test/typings/chai/chai.d.ts deleted file mode 100644 index 1134b137daa..00000000000 --- a/test/typings/chai/chai.d.ts +++ /dev/null @@ -1,283 +0,0 @@ -// Type definitions for chai 2.0.0 -// Project: http://chaijs.com/ -// Definitions by: Jed Mao , Bart van der Schoor -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -declare module Chai { - - interface ChaiStatic { - expect: ExpectStatic; - /** - * Provides a way to extend the internals of Chai - */ - use(fn: (chai: any, utils: any) => void): any; - assert: AssertStatic; - config: Config; - } - - export interface ExpectStatic extends AssertionStatic { - } - - export interface AssertStatic extends Assert { - } - - export interface AssertionStatic { - (target: any, message?: string): Assertion; - } - - interface Assertion extends LanguageChains, NumericComparison, TypeComparison { - not: Assertion; - deep: Deep; - a: TypeComparison; - an: TypeComparison; - include: Include; - contain: Include; - ok: Assertion; - true: Assertion; - false: Assertion; - null: Assertion; - undefined: Assertion; - exist: Assertion; - empty: Assertion; - arguments: Assertion; - Arguments: Assertion; - equal: Equal; - equals: Equal; - eq: Equal; - eql: Equal; - eqls: Equal; - property: Property; - ownProperty: OwnProperty; - haveOwnProperty: OwnProperty; - length: Length; - lengthOf: Length; - match(regexp: RegExp|string, message?: string): Assertion; - string(string: string, message?: string): Assertion; - keys: Keys; - key(string: string): Assertion; - throw: Throw; - throws: Throw; - Throw: Throw; - respondTo(method: string, message?: string): Assertion; - itself: Assertion; - satisfy(matcher: Function, message?: string): Assertion; - closeTo(expected: number, delta: number, message?: string): Assertion; - members: Members; - } - - interface LanguageChains { - to: Assertion; - be: Assertion; - been: Assertion; - is: Assertion; - that: Assertion; - which: Assertion; - and: Assertion; - has: Assertion; - have: Assertion; - with: Assertion; - at: Assertion; - of: Assertion; - same: Assertion; - } - - interface NumericComparison { - above: NumberComparer; - gt: NumberComparer; - greaterThan: NumberComparer; - least: NumberComparer; - gte: NumberComparer; - below: NumberComparer; - lt: NumberComparer; - lessThan: NumberComparer; - most: NumberComparer; - lte: NumberComparer; - within(start: number, finish: number, message?: string): Assertion; - } - - interface NumberComparer { - (value: number, message?: string): Assertion; - } - - interface TypeComparison { - (type: string, message?: string): Assertion; - instanceof: InstanceOf; - instanceOf: InstanceOf; - } - - interface InstanceOf { - (constructor: Object, message?: string): Assertion; - } - - interface Deep { - equal: Equal; - include: Include; - property: Property; - } - - interface Equal { - (value: any, message?: string): Assertion; - } - - interface Property { - (name: string, value?: any, message?: string): Assertion; - } - - interface OwnProperty { - (name: string, message?: string): Assertion; - } - - interface Length extends LanguageChains, NumericComparison { - (length: number, message?: string): Assertion; - } - - interface Include { - (value: Object, message?: string): Assertion; - (value: string, message?: string): Assertion; - (value: number, message?: string): Assertion; - keys: Keys; - members: Members; - } - - interface Keys { - (...keys: string[]): Assertion; - (keys: any[]): Assertion; - } - - interface Throw { - (): Assertion; - (expected: string, message?: string): Assertion; - (expected: RegExp, message?: string): Assertion; - (constructor: Error, expected?: string, message?: string): Assertion; - (constructor: Error, expected?: RegExp, message?: string): Assertion; - (constructor: Function, expected?: string, message?: string): Assertion; - (constructor: Function, expected?: RegExp, message?: string): Assertion; - } - - interface Members { - (set: any[], message?: string): Assertion; - } - - export interface Assert { - /** - * @param expression Expression to test for truthiness. - * @param message Message to display on error. - */ - (expression: any, message?: string): void; - - fail(actual?: any, expected?: any, msg?: string, operator?: string): void; - - ok(val: any, msg?: string): void; - notOk(val: any, msg?: string): void; - - equal(act: any, exp: any, msg?: string): void; - notEqual(act: any, exp: any, msg?: string): void; - - strictEqual(act: any, exp: any, msg?: string): void; - notStrictEqual(act: any, exp: any, msg?: string): void; - - deepEqual(act: any, exp: any, msg?: string): void; - notDeepEqual(act: any, exp: any, msg?: string): void; - - isTrue(val: any, msg?: string): void; - isFalse(val: any, msg?: string): void; - - isNull(val: any, msg?: string): void; - isNotNull(val: any, msg?: string): void; - - isUndefined(val: any, msg?: string): void; - isDefined(val: any, msg?: string): void; - - isFunction(val: any, msg?: string): void; - isNotFunction(val: any, msg?: string): void; - - isObject(val: any, msg?: string): void; - isNotObject(val: any, msg?: string): void; - - isArray(val: any, msg?: string): void; - isNotArray(val: any, msg?: string): void; - - isString(val: any, msg?: string): void; - isNotString(val: any, msg?: string): void; - - isNumber(val: any, msg?: string): void; - isNotNumber(val: any, msg?: string): void; - - isBoolean(val: any, msg?: string): void; - isNotBoolean(val: any, msg?: string): void; - - typeOf(val: any, type: string, msg?: string): void; - notTypeOf(val: any, type: string, msg?: string): void; - - instanceOf(val: any, type: Function, msg?: string): void; - notInstanceOf(val: any, type: Function, msg?: string): void; - - include(exp: string, inc: any, msg?: string): void; - include(exp: any[], inc: any, msg?: string): void; - - notInclude(exp: string, inc: any, msg?: string): void; - notInclude(exp: any[], inc: any, msg?: string): void; - - match(exp: any, re: RegExp, msg?: string): void; - notMatch(exp: any, re: RegExp, msg?: string): void; - - property(obj: Object, prop: string, msg?: string): void; - notProperty(obj: Object, prop: string, msg?: string): void; - deepProperty(obj: Object, prop: string, msg?: string): void; - notDeepProperty(obj: Object, prop: string, msg?: string): void; - - propertyVal(obj: Object, prop: string, val: any, msg?: string): void; - propertyNotVal(obj: Object, prop: string, val: any, msg?: string): void; - - deepPropertyVal(obj: Object, prop: string, val: any, msg?: string): void; - deepPropertyNotVal(obj: Object, prop: string, val: any, msg?: string): void; - - lengthOf(exp: any, len: number, msg?: string): void; - //alias frenzy - throw(fn: Function, msg?: string): void; - throw(fn: Function, regExp: RegExp): void; - throw(fn: Function, errType: Function, msg?: string): void; - throw(fn: Function, errType: Function, regExp: RegExp): void; - - throws(fn: Function, msg?: string): void; - throws(fn: Function, regExp: RegExp): void; - throws(fn: Function, errType: Function, msg?: string): void; - throws(fn: Function, errType: Function, regExp: RegExp): void; - - Throw(fn: Function, msg?: string): void; - Throw(fn: Function, regExp: RegExp): void; - Throw(fn: Function, errType: Function, msg?: string): void; - Throw(fn: Function, errType: Function, regExp: RegExp): void; - - doesNotThrow(fn: Function, msg?: string): void; - doesNotThrow(fn: Function, regExp: RegExp): void; - doesNotThrow(fn: Function, errType: Function, msg?: string): void; - doesNotThrow(fn: Function, errType: Function, regExp: RegExp): void; - - operator(val: any, operator: string, val2: any, msg?: string): void; - closeTo(act: number, exp: number, delta: number, msg?: string): void; - - sameMembers(set1: any[], set2: any[], msg?: string): void; - includeMembers(set1: any[], set2: any[], msg?: string): void; - - ifError(val: any, msg?: string): void; - } - - export interface Config { - includeStack: boolean; - } - - export class AssertionError { - constructor(message: string, _props?: any, ssf?: Function); - name: string; - message: string; - showDiff: boolean; - stack: string; - } -} - -declare var chai: Chai.ChaiStatic; - -declare module "chai" { - export = chai; -} diff --git a/test/typings/mocha/mocha.d.ts b/test/typings/mocha/mocha.d.ts deleted file mode 100644 index 63ad66014a2..00000000000 --- a/test/typings/mocha/mocha.d.ts +++ /dev/null @@ -1,166 +0,0 @@ -// Type definitions for mocha 2.0.1 -// Project: http://mochajs.org/ -// Definitions by: Kazi Manzur Rashid , otiai10 , jt000 -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -interface Mocha { - // Setup mocha with the given setting options. - setup(options: MochaSetupOptions): Mocha; - - //Run tests and invoke `fn()` when complete. - run(callback?: () => void): void; - - // Set reporter as function - reporter(reporter: () => void): Mocha; - - // Set reporter, defaults to "dot" - reporter(reporter: string): Mocha; - - // Enable growl support. - growl(): Mocha -} - -interface MochaSetupOptions { - //milliseconds to wait before considering a test slow - slow?: number; - - // timeout in milliseconds - timeout?: number; - - // ui name "bdd", "tdd", "exports" etc - ui?: string; - - //array of accepted globals - globals?: any[]; - - // reporter instance (function or string), defaults to `mocha.reporters.Dot` - reporter?: any; - - // bail on the first test failure - bail?: boolean; - - // ignore global leaks - ignoreLeaks?: boolean; - - // grep string or regexp to filter tests with - grep?: any; -} - -interface MochaDone { - (error?: Error): void; -} - -declare var mocha: Mocha; - -declare var describe: { - (description: string, spec: () => void): void; - only(description: string, spec: () => void): void; - skip(description: string, spec: () => void): void; - timeout(ms: number): void; -} - -// alias for `describe` -declare var context: { - (contextTitle: string, spec: () => void): void; - only(contextTitle: string, spec: () => void): void; - skip(contextTitle: string, spec: () => void): void; - timeout(ms: number): void; -}; - -// alias for `describe` -declare var suite: { - (suiteTitle: string, spec: () => void): void; - only(suiteTitle: string, spec: () => void): void; - skip(suiteTitle: string, spec: () => void): void; - timeout(ms: number): void; -}; - -declare var it: { - (expectation: string, assertion?: () => void): void; - (expectation: string, assertion?: (done: MochaDone) => void): void; - only(expectation: string, assertion?: () => void): void; - only(expectation: string, assertion?: (done: MochaDone) => void): void; - skip(expectation: string, assertion?: () => void): void; - skip(expectation: string, assertion?: (done: MochaDone) => void): void; - timeout(ms: number): void; -}; - -// alias for `it` -declare var test: { - (expectation: string, assertion?: () => void): void; - (expectation: string, assertion?: (done: MochaDone) => void): void; - only(expectation: string, assertion?: () => void): void; - only(expectation: string, assertion?: (done: MochaDone) => void): void; - skip(expectation: string, assertion?: () => void): void; - skip(expectation: string, assertion?: (done: MochaDone) => void): void; - timeout(ms: number): void; -}; - -declare function before(action: () => void): void; - -declare function before(action: (done: MochaDone) => void): void; - -declare function setup(action: () => void): void; - -declare function setup(action: (done: MochaDone) => void): void; - -declare function after(action: () => void): void; - -declare function after(action: (done: MochaDone) => void): void; - -declare function teardown(action: () => void): void; - -declare function teardown(action: (done: MochaDone) => void): void; - -declare function beforeEach(action: () => void): void; - -declare function beforeEach(action: (done: MochaDone) => void): void; - -declare function suiteSetup(action: () => void): void; - -declare function suiteSetup(action: (done: MochaDone) => void): void; - -declare function afterEach(action: () => void): void; - -declare function afterEach(action: (done: MochaDone) => void): void; - -declare function suiteTeardown(action: () => void): void; - -declare function suiteTeardown(action: (done: MochaDone) => void): void; - -declare module "mocha" { - - class Mocha { - constructor(options?: { - grep?: RegExp; - ui?: string; - reporter?: string; - timeout?: number; - bail?: boolean; - }); - - bail(value?: boolean): Mocha; - addFile(file: string): Mocha; - reporter(value: string): Mocha; - ui(value: string): Mocha; - grep(value: string): Mocha; - grep(value: RegExp): Mocha; - invert(): Mocha; - ignoreLeaks(value: boolean): Mocha; - checkLeaks(): Mocha; - growl(): Mocha; - globals(value: string): Mocha; - globals(values: string[]): Mocha; - useColors(value: boolean): Mocha; - useInlineDiffs(value: boolean): Mocha; - timeout(value: number): Mocha; - slow(value: number): Mocha; - enableTimeouts(value: boolean): Mocha; - asyncOnly(value: boolean): Mocha; - noHighlighting(value: boolean): Mocha; - - run(onComplete?: (failures: number) => void): void; - } - - export = Mocha; -} diff --git a/tsd.json b/tsd.json deleted file mode 100644 index 5e2c7dcdbb9..00000000000 --- a/tsd.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "version": "v4", - "repo": "borisyankov/DefinitelyTyped", - "ref": "master", - "path": "typings", - "bundle": "typings/tsd.d.ts", - "installed": { - "colors/colors.d.ts": { - "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" - }, - "diff/diff.d.ts": { - "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" - }, - "findup-sync/findup-sync.d.ts": { - "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" - }, - "glob/glob.d.ts": { - "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" - }, - "js-yaml/js-yaml.d.ts": { - "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" - }, - "minimatch/minimatch.d.ts": { - "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" - }, - "node/node.d.ts": { - "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" - }, - "optimist/optimist.d.ts": { - "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" - }, - "underscore.string/underscore.string.d.ts": { - "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" - }, - "underscore/underscore.d.ts": { - "commit": "e623c6b3164bb8c6da508f84f7865eaaa97e1a0f" - } - } -} diff --git a/tslint.json b/tslint.json index 998acb59a2e..f0eae7a1393 100644 --- a/tslint.json +++ b/tslint.json @@ -7,6 +7,13 @@ "public-before-private", "static-before-instance", "variables-before-functions" + ], + "no-unused-variable": false, + "variable-name": [true, + "ban-keywords", + "check-format", + "allow-leading-underscore", + "allow-pascal-case" ] } } diff --git a/typings/colors/colors.d.ts b/typings/colors/colors.d.ts deleted file mode 100644 index 50e960c4167..00000000000 --- a/typings/colors/colors.d.ts +++ /dev/null @@ -1,137 +0,0 @@ -// Type definitions for Colors.js 0.6.0-1 -// Project: https://github.com/Marak/colors.js -// Definitions by: Bart van der Schoor -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare module "colors" { - interface Color { - (text: string): string; - - strip: Color; - stripColors: Color; - - black: Color; - red: Color; - green: Color; - yellow: Color; - blue: Color; - magenta: Color; - cyan: Color; - white: Color; - gray: Color; - grey: Color; - - bgBlack: Color; - bgRed: Color; - bgGreen: Color; - bgYellow: Color; - bgBlue: Color; - bgMagenta: Color; - bgCyan: Color; - bgWhite: Color; - - reset: Color; - bold: Color; - dim: Color; - italic: Color; - underline: Color; - inverse: Color; - hidden: Color; - strikethrough: Color; - - rainbow: Color; - zebra: Color; - america: Color; - trap: Color; - random: Color; - zalgo: Color; - } - - namespace e { - export function setTheme(theme:any): void; - - export var enabled: boolean; - - export var strip: Color; - export var stripColors: Color; - - export var black: Color; - export var red: Color; - export var green: Color; - export var yellow: Color; - export var blue: Color; - export var magenta: Color; - export var cyan: Color; - export var white: Color; - export var gray: Color; - export var grey: Color; - - export var bgBlack: Color; - export var bgRed: Color; - export var bgGreen: Color; - export var bgYellow: Color; - export var bgBlue: Color; - export var bgMagenta: Color; - export var bgCyan: Color; - export var bgWhite: Color; - - export var reset: Color; - export var bold: Color; - export var dim: Color; - export var italic: Color; - export var underline: Color; - export var inverse: Color; - export var hidden: Color; - export var strikethrough: Color; - - export var rainbow: Color; - export var zebra: Color; - export var america: Color; - export var trap: Color; - export var random: Color; - export var zalgo: Color; - } - - export = e; -} - -interface String { - strip: string; - stripColors: string; - - black: string; - red: string; - green: string; - yellow: string; - blue: string; - magenta: string; - cyan: string; - white: string; - gray: string; - grey: string; - - bgBlack: string; - bgRed: string; - bgGreen: string; - bgYellow: string; - bgBlue: string; - bgMagenta: string; - bgCyan: string; - bgWhite: string; - - reset: string; - bold: string; - dim: string; - italic: string; - underline: string; - inverse: string; - hidden: string; - strikethrough: string; - - rainbow: string; - zebra: string; - america: string; - trap: string; - random: string; - zalgo: string; -} diff --git a/typings/diff/diff.d.ts b/typings/diff/diff.d.ts deleted file mode 100644 index fc4708c2a1f..00000000000 --- a/typings/diff/diff.d.ts +++ /dev/null @@ -1,88 +0,0 @@ -// Type definitions for diff -// Project: https://github.com/kpdecker/jsdiff -// Definitions by: vvakame -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare namespace JsDiff { - interface IDiffResult { - value: string; - count?: number; - added?: boolean; - removed?: boolean; - } - - interface IBestPath { - newPos: number; - componenets: IDiffResult[]; - } - - interface IHunk { - oldStart: number; - oldLines: number; - newStart: number; - newLines: number; - lines: string[]; - } - - interface IUniDiff { - oldFileName: string; - newFileName: string; - oldHeader: string; - newHeader: string; - hunks: IHunk[]; - } - - class Diff { - ignoreWhitespace:boolean; - - constructor(ignoreWhitespace?:boolean); - - diff(oldString:string, newString:string):IDiffResult[]; - - pushComponent(components:IDiffResult[], value:string, added:boolean, removed:boolean):void; - - extractCommon(basePath:IBestPath, newString:string, oldString:string, diagonalPath:number):number; - - equals(left:string, right:string):boolean; - - join(left:string, right:string):string; - - tokenize(value:string):any; // return types are string or string[] - } - - function diffChars(oldStr:string, newStr:string):IDiffResult[]; - - function diffWords(oldStr:string, newStr:string):IDiffResult[]; - - function diffWordsWithSpace(oldStr:string, newStr:string):IDiffResult[]; - - function diffJson(oldObj: Object, newObj: Object): IDiffResult[]; - - function diffLines(oldStr:string, newStr:string):IDiffResult[]; - - function diffCss(oldStr:string, newStr:string):IDiffResult[]; - - function createPatch(fileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string; - - function createTwoFilesPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): string; - - function structuredPatch(oldFileName: string, newFileName: string, oldStr: string, newStr: string, oldHeader: string, newHeader: string, options?: {context: number}): IUniDiff; - - function applyPatch(oldStr: string, uniDiff: string | IUniDiff | IUniDiff[]): string; - - function applyPatches(uniDiff: IUniDiff[], options: { - loadFile: (index: number, callback: (err: Error, data: string) => void) => void, - patched: (index: number, content: string) => void, - complete: (err?: Error) => void - }): void; - - function parsePatch(diffStr: string, options?: {strict: boolean}): IUniDiff[]; - - function convertChangesToXML(changes:IDiffResult[]):string; - - function convertChangesToDMP(changes:IDiffResult[]):{0: number; 1:string;}[]; -} - -declare module "diff" { - export = JsDiff; -} diff --git a/typings/findup-sync/findup-sync.d.ts b/typings/findup-sync/findup-sync.d.ts deleted file mode 100644 index 71ff2672cdc..00000000000 --- a/typings/findup-sync/findup-sync.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -// Type definitions for findup-sync v0.3.0 -// Project: https://github.com/cowboy/node-findup-sync -// Definitions by: Bart van der Schoor , Nathan Brown -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - -declare module 'findup-sync' { - import minimatch = require('minimatch'); - - interface IOptions extends minimatch.IOptions { - cwd?: string; - } - - function mod(pattern: string[] | string, opts?: IOptions): string; - - export = mod; -} diff --git a/typings/glob/glob.d.ts b/typings/glob/glob.d.ts deleted file mode 100644 index 2957204f2c5..00000000000 --- a/typings/glob/glob.d.ts +++ /dev/null @@ -1,112 +0,0 @@ -// Type definitions for Glob 5.0.10 -// Project: https://github.com/isaacs/node-glob -// Definitions by: vvakame -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// -/// - -declare module "glob" { - - import events = require("events"); - import fs = require('fs'); - import minimatch = require("minimatch"); - - function G(pattern: string, cb: (err: Error, matches: string[]) => void): void; - function G(pattern: string, options: G.IOptions, cb: (err: Error, matches: string[]) => void): void; - - namespace G { - function sync(pattern: string, options?: IOptions): string[]; - - function hasMagic(pattern: string, options?: IOptions): boolean; - - var Glob: IGlobStatic; - var GlobSync: IGlobSyncStatic; - - interface IOptions extends minimatch.IOptions { - cwd?: string; - root?: string; - dot?: boolean; - nomount?: boolean; - mark?: boolean; - nosort?: boolean; - stat?: boolean; - silent?: boolean; - strict?: boolean; - cache?: { [path: string]: any /* boolean | string | string[] */ }; - statCache?: { [path: string]: fs.Stats }; - symlinks?: any; - sync?: boolean; - nounique?: boolean; - nonull?: boolean; - debug?: boolean; - nobrace?: boolean; - noglobstar?: boolean; - noext?: boolean; - nocase?: boolean; - matchBase?: any; - nodir?: boolean; - ignore?: any; /* string | string[] */ - follow?: boolean; - realpath?: boolean; - nonegate?: boolean; - nocomment?: boolean; - - /** Deprecated. */ - globDebug?: boolean; - } - - interface IGlobStatic extends events.EventEmitter { - new (pattern: string, cb?: (err: Error, matches: string[]) => void): IGlob; - new (pattern: string, options: IOptions, cb?: (err: Error, matches: string[]) => void): IGlob; - prototype: IGlob; - } - - interface IGlobSyncStatic { - new (pattern: string, options?: IOptions): IGlobBase - prototype: IGlobBase; - } - - interface IGlobBase { - minimatch: minimatch.IMinimatch; - options: IOptions; - aborted: boolean; - cache: { [path: string]: any /* boolean | string | string[] */ }; - statCache: { [path: string]: fs.Stats }; - symlinks: { [path: string]: boolean }; - realpathCache: { [path: string]: string }; - found: string[]; - } - - interface IGlob extends IGlobBase, events.EventEmitter { - pause(): void; - resume(): void; - abort(): void; - - /** Deprecated. */ - EOF: any; - /** Deprecated. */ - paused: boolean; - /** Deprecated. */ - maxDepth: number; - /** Deprecated. */ - maxLength: number; - /** Deprecated. */ - changedCwd: boolean; - /** Deprecated. */ - cwd: string; - /** Deprecated. */ - root: string; - /** Deprecated. */ - error: any; - /** Deprecated. */ - matches: string[]; - /** Deprecated. */ - log(...args: any[]): void; - /** Deprecated. */ - emitMatch(m: any): void; - } - } - - export = G; -} diff --git a/typings/js-yaml/js-yaml.d.ts b/typings/js-yaml/js-yaml.d.ts deleted file mode 100644 index dca80dc228c..00000000000 --- a/typings/js-yaml/js-yaml.d.ts +++ /dev/null @@ -1,85 +0,0 @@ -// Type definitions for js-yaml 3.5.2 -// Project: https://github.com/nodeca/js-yaml -// Definitions by: Bart van der Schoor , Sebastian Clausen -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare namespace jsyaml { - export function safeLoad(str: string, opts?: LoadOptions): any; - export function load(str: string, opts?: LoadOptions): any; - - export class Type implements TypeConstructorOptions { - constructor(tag: string, opts?: TypeConstructorOptions); - tag: string; - } - export class Schema { - constructor(definition: SchemaDefinition); - public static create(args: any[]): Schema; - } - - export function safeLoadAll(str: string, iterator: (doc: any) => void, opts?: LoadOptions): any; - export function loadAll(str: string, iterator: (doc: any) => void, opts?: LoadOptions): any; - - export function safeDump(obj: any, opts?: DumpOptions): string; - export function dump(obj: any, opts?: DumpOptions): string; - - export interface LoadOptions { - // string to be used as a file path in error/warning messages. - filename?: string; - // makes the loader to throw errors instead of warnings. - strict?: boolean; - // specifies a schema to use. - schema?: any; - } - - export interface DumpOptions { - // indentation width to use (in spaces). - indent?: number; - // do not throw on invalid types (like function in the safe schema) and skip pairs and single values with such types. - skipInvalid?: boolean; - // specifies level of nesting, when to switch from block to flow style for collections. -1 means block style everwhere - flowLevel?: number; - // Each tag may have own set of styles. - "tag" => "style" map. - styles?: Object; - // specifies a schema to use. - schema?: any; - } - - export interface TypeConstructorOptions { - kind?: string; - resolve?: Function; - construct?: Function; - instanceOf?: Object; - predicate?: string; - represent?: Function; - defaultStyle?: string; - styleAliases?: Object; - } - - export interface SchemaDefinition { - implicit?: any[]; - explicit?: any[]; - include?: any[]; - } - - // only strings, arrays and plain objects: http://www.yaml.org/spec/1.2/spec.html#id2802346 - export var FAILSAFE_SCHEMA: any; - // only strings, arrays and plain objects: http://www.yaml.org/spec/1.2/spec.html#id2802346 - export var JSON_SCHEMA: any; - // same as JSON_SCHEMA: http://www.yaml.org/spec/1.2/spec.html#id2804923 - export var CORE_SCHEMA: any; - // all supported YAML types, without unsafe ones (!!js/undefined, !!js/regexp and !!js/function): http://yaml.org/type/ - export var DEFAULT_SAFE_SCHEMA: any; - // all supported YAML types. - export var DEFAULT_FULL_SCHEMA: any; - export var MINIMAL_SCHEMA: any; - export var SAFE_SCHEMA: any; - - export class YAMLException extends Error { - constructor(reason?: any, mark?: any); - toString(compact?: boolean): string; - } -} - -declare module 'js-yaml' { - export = jsyaml; -} diff --git a/typings/minimatch/minimatch.d.ts b/typings/minimatch/minimatch.d.ts deleted file mode 100644 index 5a6c7215ae1..00000000000 --- a/typings/minimatch/minimatch.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -// Type definitions for Minimatch 2.0.8 -// Project: https://github.com/isaacs/minimatch -// Definitions by: vvakame -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare module "minimatch" { - - function M(target: string, pattern: string, options?: M.IOptions): boolean; - - namespace M { - function match(list: string[], pattern: string, options?: IOptions): string[]; - function filter(pattern: string, options?: IOptions): (element: string, indexed: number, array: string[]) => boolean; - function makeRe(pattern: string, options?: IOptions): RegExp; - - var Minimatch: IMinimatchStatic; - - interface IOptions { - debug?: boolean; - nobrace?: boolean; - noglobstar?: boolean; - dot?: boolean; - noext?: boolean; - nocase?: boolean; - nonull?: boolean; - matchBase?: boolean; - nocomment?: boolean; - nonegate?: boolean; - flipNegate?: boolean; - } - - interface IMinimatchStatic { - new (pattern: string, options?: IOptions): IMinimatch; - prototype: IMinimatch; - } - - interface IMinimatch { - pattern: string; - options: IOptions; - /** 2-dimensional array of regexp or string expressions. */ - set: any[][]; // (RegExp | string)[][] - regexp: RegExp; - negate: boolean; - comment: boolean; - empty: boolean; - - makeRe(): RegExp; // regexp or boolean - match(fname: string): boolean; - matchOne(files: string[], pattern: string[], partial: boolean): boolean; - - /** Deprecated. For internal use. */ - debug(): void; - /** Deprecated. For internal use. */ - make(): void; - /** Deprecated. For internal use. */ - parseNegate(): void; - /** Deprecated. For internal use. */ - braceExpand(pattern: string, options: IOptions): void; - /** Deprecated. For internal use. */ - parse(pattern: string, isSub?: boolean): void; - } - } - - export = M; -} diff --git a/typings/node/node.d.ts b/typings/node/node.d.ts deleted file mode 100644 index 0b91d8095ca..00000000000 --- a/typings/node/node.d.ts +++ /dev/null @@ -1,3734 +0,0 @@ -// Type definitions for Node.js v6.x -// Project: http://nodejs.org/ -// Definitions by: Microsoft TypeScript , DefinitelyTyped -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/************************************************ -* * -* Node.js v6.x API * -* * -************************************************/ - -interface Error { - stack?: string; -} - -interface ErrorConstructor { - captureStackTrace(targetObject: Object, constructorOpt?: Function): void; - stackTraceLimit: number; -} - -// compat for TypeScript 1.8 -// if you use with --target es3 or --target es5 and use below definitions, -// use the lib.es6.d.ts that is bundled with TypeScript 1.8. -interface MapConstructor { } -interface WeakMapConstructor { } -interface SetConstructor { } -interface WeakSetConstructor { } - -/************************************************ -* * -* GLOBAL * -* * -************************************************/ -declare var process: NodeJS.Process; -declare var global: NodeJS.Global; - -declare var __filename: string; -declare var __dirname: string; - -declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; -declare function clearTimeout(timeoutId: NodeJS.Timer): void; -declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; -declare function clearInterval(intervalId: NodeJS.Timer): void; -declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; -declare function clearImmediate(immediateId: any): void; - -interface NodeRequireFunction { - (id: string): any; -} - -interface NodeRequire extends NodeRequireFunction { - resolve(id: string): string; - cache: any; - extensions: any; - main: any; -} - -declare var require: NodeRequire; - -interface NodeModule { - exports: any; - require: NodeRequireFunction; - id: string; - filename: string; - loaded: boolean; - parent: any; - children: any[]; -} - -declare var module: NodeModule; - -// Same as module.exports -declare var exports: any; -declare var SlowBuffer: { - new (str: string, encoding?: string): Buffer; - new (size: number): Buffer; - new (size: Uint8Array): Buffer; - new (array: any[]): Buffer; - prototype: Buffer; - isBuffer(obj: any): boolean; - byteLength(string: string, encoding?: string): number; - concat(list: Buffer[], totalLength?: number): Buffer; -}; - - -// Buffer class -type BufferEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "binary" | "hex"; -interface Buffer extends NodeBuffer { } - -/** - * Raw data is stored in instances of the Buffer class. - * A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. - * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' - */ -declare var Buffer: { - /** - * Allocates a new buffer containing the given {str}. - * - * @param str String to store in buffer. - * @param encoding encoding to use, optional. Default is 'utf8' - */ - new (str: string, encoding?: string): Buffer; - /** - * Allocates a new buffer of {size} octets. - * - * @param size count of octets to allocate. - */ - new (size: number): Buffer; - /** - * Allocates a new buffer containing the given {array} of octets. - * - * @param array The octets to store. - */ - new (array: Uint8Array): Buffer; - /** - * Produces a Buffer backed by the same allocated memory as - * the given {ArrayBuffer}. - * - * - * @param arrayBuffer The ArrayBuffer with which to share memory. - */ - new (arrayBuffer: ArrayBuffer): Buffer; - /** - * Allocates a new buffer containing the given {array} of octets. - * - * @param array The octets to store. - */ - new (array: any[]): Buffer; - /** - * Copies the passed {buffer} data onto a new {Buffer} instance. - * - * @param buffer The buffer to copy. - */ - new (buffer: Buffer): Buffer; - prototype: Buffer; - /** - * Allocates a new Buffer using an {array} of octets. - * - * @param array - */ - from(array: any[]): Buffer; - /** - * When passed a reference to the .buffer property of a TypedArray instance, - * the newly created Buffer will share the same allocated memory as the TypedArray. - * The optional {byteOffset} and {length} arguments specify a memory range - * within the {arrayBuffer} that will be shared by the Buffer. - * - * @param arrayBuffer The .buffer property of a TypedArray or a new ArrayBuffer() - * @param byteOffset - * @param length - */ - from(arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer; - /** - * Copies the passed {buffer} data onto a new Buffer instance. - * - * @param buffer - */ - from(buffer: Buffer): Buffer; - /** - * Creates a new Buffer containing the given JavaScript string {str}. - * If provided, the {encoding} parameter identifies the character encoding. - * If not provided, {encoding} defaults to 'utf8'. - * - * @param str - */ - from(str: string, encoding?: string): Buffer; - /** - * Returns true if {obj} is a Buffer - * - * @param obj object to test. - */ - isBuffer(obj: any): obj is Buffer; - /** - * Returns true if {encoding} is a valid encoding argument. - * Valid string encodings in Node 0.12: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'binary'(deprecated)|'hex' - * - * @param encoding string to test. - */ - isEncoding(encoding: string): boolean; - /** - * Gives the actual byte length of a string. encoding defaults to 'utf8'. - * This is not the same as String.prototype.length since that returns the number of characters in a string. - * - * @param string string to test. - * @param encoding encoding used to evaluate (defaults to 'utf8') - */ - byteLength(string: string, encoding?: string): number; - /** - * Returns a buffer which is the result of concatenating all the buffers in the list together. - * - * If the list has no items, or if the totalLength is 0, then it returns a zero-length buffer. - * If the list has exactly one item, then the first item of the list is returned. - * If the list has more than one item, then a new Buffer is created. - * - * @param list An array of Buffer objects to concatenate - * @param totalLength Total length of the buffers when concatenated. - * If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly. - */ - concat(list: Buffer[], totalLength?: number): Buffer; - /** - * The same as buf1.compare(buf2). - */ - compare(buf1: Buffer, buf2: Buffer): number; - /** - * Allocates a new buffer of {size} octets. - * - * @param size count of octets to allocate. - * @param fill if specified, buffer will be initialized by calling buf.fill(fill). - * If parameter is omitted, buffer will be filled with zeros. - * @param encoding encoding used for call to buf.fill while initalizing - */ - alloc(size: number, fill?: string | Buffer | number, encoding?: string): Buffer; - /** - * Allocates a new buffer of {size} octets, leaving memory not initialized, so the contents - * of the newly created Buffer are unknown and may contain sensitive data. - * - * @param size count of octets to allocate - */ - allocUnsafe(size: number): Buffer; - /** - * Allocates a new non-pooled buffer of {size} octets, leaving memory not initialized, so the contents - * of the newly created Buffer are unknown and may contain sensitive data. - * - * @param size count of octets to allocate - */ - allocUnsafeSlow(size: number): Buffer; -}; - -/************************************************ -* * -* GLOBAL INTERFACES * -* * -************************************************/ -declare namespace NodeJS { - export interface ErrnoException extends Error { - errno?: string; - code?: string; - path?: string; - syscall?: string; - stack?: string; - } - - export class EventEmitter { - addListener(event: string | symbol, listener: Function): this; - on(event: string | symbol, listener: Function): this; - once(event: string | symbol, listener: Function): this; - removeListener(event: string | symbol, listener: Function): this; - removeAllListeners(event?: string | symbol): this; - setMaxListeners(n: number): this; - getMaxListeners(): number; - listeners(event: string | symbol): Function[]; - emit(event: string | symbol, ...args: any[]): boolean; - listenerCount(type: string | symbol): number; - // Added in Node 6... - prependListener(event: string | symbol, listener: Function): this; - prependOnceListener(event: string | symbol, listener: Function): this; - eventNames(): (string | symbol)[]; - } - - export interface ReadableStream extends EventEmitter { - readable: boolean; - read(size?: number): string | Buffer; - setEncoding(encoding: string): void; - pause(): ReadableStream; - resume(): ReadableStream; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; - unshift(chunk: string): void; - unshift(chunk: Buffer): void; - wrap(oldStream: ReadableStream): ReadableStream; - } - - export interface WritableStream extends EventEmitter { - writable: boolean; - write(buffer: Buffer | string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - } - - export interface ReadWriteStream extends ReadableStream, WritableStream { - pause(): ReadWriteStream; - resume(): ReadWriteStream; - } - - export interface Events extends EventEmitter { } - - export interface Domain extends Events { - run(fn: Function): void; - add(emitter: Events): void; - remove(emitter: Events): void; - bind(cb: (err: Error, data: any) => any): any; - intercept(cb: (data: any) => any): any; - dispose(): void; - - addListener(event: string, listener: Function): this; - on(event: string, listener: Function): this; - once(event: string, listener: Function): this; - removeListener(event: string, listener: Function): this; - removeAllListeners(event?: string): this; - } - - export interface MemoryUsage { - rss: number; - heapTotal: number; - heapUsed: number; - } - - export interface ProcessVersions { - http_parser: string; - node: string; - v8: string; - ares: string; - uv: string; - zlib: string; - modules: string; - openssl: string; - } - - export interface Process extends EventEmitter { - stdout: WritableStream; - stderr: WritableStream; - stdin: ReadableStream; - argv: string[]; - execArgv: string[]; - execPath: string; - abort(): void; - chdir(directory: string): void; - cwd(): string; - env: any; - exit(code?: number): void; - exitCode: number; - getgid(): number; - setgid(id: number): void; - setgid(id: string): void; - getuid(): number; - setuid(id: number): void; - setuid(id: string): void; - version: string; - versions: ProcessVersions; - config: { - target_defaults: { - cflags: any[]; - default_configuration: string; - defines: string[]; - include_dirs: string[]; - libraries: string[]; - }; - variables: { - clang: number; - host_arch: string; - node_install_npm: boolean; - node_install_waf: boolean; - node_prefix: string; - node_shared_openssl: boolean; - node_shared_v8: boolean; - node_shared_zlib: boolean; - node_use_dtrace: boolean; - node_use_etw: boolean; - node_use_openssl: boolean; - target_arch: string; - v8_no_strict_aliasing: number; - v8_use_snapshot: boolean; - visibility: string; - }; - }; - kill(pid: number, signal?: string | number): void; - pid: number; - title: string; - arch: string; - platform: string; - memoryUsage(): MemoryUsage; - nextTick(callback: Function, ...args: any[]): void; - umask(mask?: number): number; - uptime(): number; - hrtime(time?: number[]): number[]; - domain: Domain; - - // Worker - send?(message: any, sendHandle?: any): void; - disconnect(): void; - connected: boolean; - } - - export interface Global { - Array: typeof Array; - ArrayBuffer: typeof ArrayBuffer; - Boolean: typeof Boolean; - Buffer: typeof Buffer; - DataView: typeof DataView; - Date: typeof Date; - Error: typeof Error; - EvalError: typeof EvalError; - Float32Array: typeof Float32Array; - Float64Array: typeof Float64Array; - Function: typeof Function; - GLOBAL: Global; - Infinity: typeof Infinity; - Int16Array: typeof Int16Array; - Int32Array: typeof Int32Array; - Int8Array: typeof Int8Array; - Intl: typeof Intl; - JSON: typeof JSON; - Map: MapConstructor; - Math: typeof Math; - NaN: typeof NaN; - Number: typeof Number; - Object: typeof Object; - Promise: Function; - RangeError: typeof RangeError; - ReferenceError: typeof ReferenceError; - RegExp: typeof RegExp; - Set: SetConstructor; - String: typeof String; - Symbol: Function; - SyntaxError: typeof SyntaxError; - TypeError: typeof TypeError; - URIError: typeof URIError; - Uint16Array: typeof Uint16Array; - Uint32Array: typeof Uint32Array; - Uint8Array: typeof Uint8Array; - Uint8ClampedArray: Function; - WeakMap: WeakMapConstructor; - WeakSet: WeakSetConstructor; - clearImmediate: (immediateId: any) => void; - clearInterval: (intervalId: NodeJS.Timer) => void; - clearTimeout: (timeoutId: NodeJS.Timer) => void; - console: typeof console; - decodeURI: typeof decodeURI; - decodeURIComponent: typeof decodeURIComponent; - encodeURI: typeof encodeURI; - encodeURIComponent: typeof encodeURIComponent; - escape: (str: string) => string; - eval: typeof eval; - global: Global; - isFinite: typeof isFinite; - isNaN: typeof isNaN; - parseFloat: typeof parseFloat; - parseInt: typeof parseInt; - process: Process; - root: Global; - setImmediate: (callback: (...args: any[]) => void, ...args: any[]) => any; - setInterval: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; - setTimeout: (callback: (...args: any[]) => void, ms: number, ...args: any[]) => NodeJS.Timer; - undefined: typeof undefined; - unescape: (str: string) => string; - gc: () => void; - v8debug?: any; - } - - export interface Timer { - ref(): void; - unref(): void; - } -} - -interface IterableIterator { } - -/** - * @deprecated - */ -interface NodeBuffer extends Uint8Array { - write(string: string, offset?: number, length?: number, encoding?: string): number; - toString(encoding?: string, start?: number, end?: number): string; - toJSON(): { type: 'Buffer', data: any[] }; - equals(otherBuffer: Buffer): boolean; - compare(otherBuffer: Buffer, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number; - copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; - slice(start?: number, end?: number): Buffer; - writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; - writeUIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; - writeIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; - writeIntBE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; - readUIntLE(offset: number, byteLength: number, noAssert?: boolean): number; - readUIntBE(offset: number, byteLength: number, noAssert?: boolean): number; - readIntLE(offset: number, byteLength: number, noAssert?: boolean): number; - readIntBE(offset: number, byteLength: number, noAssert?: boolean): number; - readUInt8(offset: number, noAssert?: boolean): number; - readUInt16LE(offset: number, noAssert?: boolean): number; - readUInt16BE(offset: number, noAssert?: boolean): number; - readUInt32LE(offset: number, noAssert?: boolean): number; - readUInt32BE(offset: number, noAssert?: boolean): number; - readInt8(offset: number, noAssert?: boolean): number; - readInt16LE(offset: number, noAssert?: boolean): number; - readInt16BE(offset: number, noAssert?: boolean): number; - readInt32LE(offset: number, noAssert?: boolean): number; - readInt32BE(offset: number, noAssert?: boolean): number; - readFloatLE(offset: number, noAssert?: boolean): number; - readFloatBE(offset: number, noAssert?: boolean): number; - readDoubleLE(offset: number, noAssert?: boolean): number; - readDoubleBE(offset: number, noAssert?: boolean): number; - swap16(): Buffer; - swap32(): Buffer; - swap64(): Buffer; - writeUInt8(value: number, offset: number, noAssert?: boolean): number; - writeUInt16LE(value: number, offset: number, noAssert?: boolean): number; - writeUInt16BE(value: number, offset: number, noAssert?: boolean): number; - writeUInt32LE(value: number, offset: number, noAssert?: boolean): number; - writeUInt32BE(value: number, offset: number, noAssert?: boolean): number; - writeInt8(value: number, offset: number, noAssert?: boolean): number; - writeInt16LE(value: number, offset: number, noAssert?: boolean): number; - writeInt16BE(value: number, offset: number, noAssert?: boolean): number; - writeInt32LE(value: number, offset: number, noAssert?: boolean): number; - writeInt32BE(value: number, offset: number, noAssert?: boolean): number; - writeFloatLE(value: number, offset: number, noAssert?: boolean): number; - writeFloatBE(value: number, offset: number, noAssert?: boolean): number; - writeDoubleLE(value: number, offset: number, noAssert?: boolean): number; - writeDoubleBE(value: number, offset: number, noAssert?: boolean): number; - fill(value: any, offset?: number, end?: number): this; - indexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number; - lastIndexOf(value: string | number | Buffer, byteOffset?: number, encoding?: string): number; - entries(): IterableIterator<[number, number]>; - includes(value: string | number | Buffer, byteOffset?: number, encoding?: string): boolean; - keys(): IterableIterator; - values(): IterableIterator; -} - -/************************************************ -* * -* MODULES * -* * -************************************************/ -declare module "buffer" { - export var INSPECT_MAX_BYTES: number; - var BuffType: typeof Buffer; - var SlowBuffType: typeof SlowBuffer; - export { BuffType as Buffer, SlowBuffType as SlowBuffer }; -} - -declare module "querystring" { - export interface StringifyOptions { - encodeURIComponent?: Function; - } - - export interface ParseOptions { - maxKeys?: number; - decodeURIComponent?: Function; - } - - export function stringify(obj: T, sep?: string, eq?: string, options?: StringifyOptions): string; - export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): any; - export function parse(str: string, sep?: string, eq?: string, options?: ParseOptions): T; - export function escape(str: string): string; - export function unescape(str: string): string; -} - -declare module "events" { - export class EventEmitter extends NodeJS.EventEmitter { - static EventEmitter: EventEmitter; - static listenerCount(emitter: EventEmitter, event: string | symbol): number; // deprecated - static defaultMaxListeners: number; - - addListener(event: string | symbol, listener: Function): this; - on(event: string | symbol, listener: Function): this; - once(event: string | symbol, listener: Function): this; - prependListener(event: string | symbol, listener: Function): this; - prependOnceListener(event: string | symbol, listener: Function): this; - removeListener(event: string | symbol, listener: Function): this; - removeAllListeners(event?: string | symbol): this; - setMaxListeners(n: number): this; - getMaxListeners(): number; - listeners(event: string | symbol): Function[]; - emit(event: string | symbol, ...args: any[]): boolean; - eventNames(): (string | symbol)[]; - listenerCount(type: string | symbol): number; - } -} - -declare module "http" { - import * as events from "events"; - import * as net from "net"; - import * as stream from "stream"; - - export interface RequestOptions { - protocol?: string; - host?: string; - hostname?: string; - family?: number; - port?: number; - localAddress?: string; - socketPath?: string; - method?: string; - path?: string; - headers?: { [key: string]: any }; - auth?: string; - agent?: Agent | boolean; - } - - export interface Server extends net.Server { - setTimeout(msecs: number, callback: Function): void; - maxHeadersCount: number; - timeout: number; - listening: boolean; - } - /** - * @deprecated Use IncomingMessage - */ - export interface ServerRequest extends IncomingMessage { - connection: net.Socket; - } - export interface ServerResponse extends stream.Writable { - // Extended base methods - write(buffer: Buffer): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - write(str: string, encoding?: string, fd?: string): boolean; - - writeContinue(): void; - writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; - writeHead(statusCode: number, headers?: any): void; - statusCode: number; - statusMessage: string; - headersSent: boolean; - setHeader(name: string, value: string | string[]): void; - setTimeout(msecs: number, callback: Function): ServerResponse; - sendDate: boolean; - getHeader(name: string): string; - removeHeader(name: string): void; - write(chunk: any, encoding?: string): any; - addTrailers(headers: any): void; - finished: boolean; - - // Extended base methods - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - end(data?: any, encoding?: string): void; - } - export interface ClientRequest extends stream.Writable { - // Extended base methods - write(buffer: Buffer): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - write(str: string, encoding?: string, fd?: string): boolean; - - write(chunk: any, encoding?: string): void; - abort(): void; - setTimeout(timeout: number, callback?: Function): void; - setNoDelay(noDelay?: boolean): void; - setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; - - setHeader(name: string, value: string | string[]): void; - getHeader(name: string): string; - removeHeader(name: string): void; - addTrailers(headers: any): void; - - // Extended base methods - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - end(data?: any, encoding?: string): void; - } - export interface IncomingMessage extends stream.Readable { - httpVersion: string; - httpVersionMajor: number; - httpVersionMinor: number; - connection: net.Socket; - headers: any; - rawHeaders: string[]; - trailers: any; - rawTrailers: any; - setTimeout(msecs: number, callback: Function): NodeJS.Timer; - /** - * Only valid for request obtained from http.Server. - */ - method?: string; - /** - * Only valid for request obtained from http.Server. - */ - url?: string; - /** - * Only valid for response obtained from http.ClientRequest. - */ - statusCode?: number; - /** - * Only valid for response obtained from http.ClientRequest. - */ - statusMessage?: string; - socket: net.Socket; - destroy(error?: Error): void; - } - /** - * @deprecated Use IncomingMessage - */ - export interface ClientResponse extends IncomingMessage { } - - export interface AgentOptions { - /** - * Keep sockets around in a pool to be used by other requests in the future. Default = false - */ - keepAlive?: boolean; - /** - * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000. - * Only relevant if keepAlive is set to true. - */ - keepAliveMsecs?: number; - /** - * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity - */ - maxSockets?: number; - /** - * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256. - */ - maxFreeSockets?: number; - } - - export class Agent { - maxSockets: number; - sockets: any; - requests: any; - - constructor(opts?: AgentOptions); - - /** - * Destroy any sockets that are currently in use by the agent. - * It is usually not necessary to do this. However, if you are using an agent with KeepAlive enabled, - * then it is best to explicitly shut down the agent when you know that it will no longer be used. Otherwise, - * sockets may hang open for quite a long time before the server terminates them. - */ - destroy(): void; - } - - export var METHODS: string[]; - - export var STATUS_CODES: { - [errorCode: number]: string; - [errorCode: string]: string; - }; - export function createServer(requestListener?: (request: IncomingMessage, response: ServerResponse) => void): Server; - export function createClient(port?: number, host?: string): any; - export function request(options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest; - export function get(options: any, callback?: (res: IncomingMessage) => void): ClientRequest; - export var globalAgent: Agent; -} - -declare module "cluster" { - import * as child from "child_process"; - import * as events from "events"; - import * as net from "net"; - - // interfaces - export interface ClusterSettings { - execArgv?: string[]; // default: process.execArgv - exec?: string; - args?: string[]; - silent?: boolean; - stdio?: any[]; - uid?: number; - gid?: number; - } - - export interface ClusterSetupMasterSettings { - exec?: string; // default: process.argv[1] - args?: string[]; // default: process.argv.slice(2) - silent?: boolean; // default: false - stdio?: any[]; - } - - export interface Address { - address: string; - port: number; - addressType: number | "udp4" | "udp6"; // 4, 6, -1, "udp4", "udp6" - } - - export class Worker extends events.EventEmitter { - id: string; - process: child.ChildProcess; - suicide: boolean; - send(message: any, sendHandle?: any): boolean; - kill(signal?: string): void; - destroy(signal?: string): void; - disconnect(): void; - isConnected(): boolean; - isDead(): boolean; - exitedAfterDisconnect: boolean; - - /** - * events.EventEmitter - * 1. disconnect - * 2. error - * 3. exit - * 4. listening - * 5. message - * 6. online - */ - addListener(event: string, listener: Function): this; - addListener(event: "disconnect", listener: () => void): this; - addListener(event: "error", listener: (code: number, signal: string) => void): this; - addListener(event: "exit", listener: (code: number, signal: string) => void): this; - addListener(event: "listening", listener: (address: Address) => void): this; - addListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. - addListener(event: "online", listener: () => void): this; - - emit(event: string, listener: Function): boolean - emit(event: "disconnect", listener: () => void): boolean - emit(event: "error", listener: (code: number, signal: string) => void): boolean - emit(event: "exit", listener: (code: number, signal: string) => void): boolean - emit(event: "listening", listener: (address: Address) => void): boolean - emit(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): boolean - emit(event: "online", listener: () => void): boolean - - on(event: string, listener: Function): this; - on(event: "disconnect", listener: () => void): this; - on(event: "error", listener: (code: number, signal: string) => void): this; - on(event: "exit", listener: (code: number, signal: string) => void): this; - on(event: "listening", listener: (address: Address) => void): this; - on(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. - on(event: "online", listener: () => void): this; - - once(event: string, listener: Function): this; - once(event: "disconnect", listener: () => void): this; - once(event: "error", listener: (code: number, signal: string) => void): this; - once(event: "exit", listener: (code: number, signal: string) => void): this; - once(event: "listening", listener: (address: Address) => void): this; - once(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. - once(event: "online", listener: () => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "disconnect", listener: () => void): this; - prependListener(event: "error", listener: (code: number, signal: string) => void): this; - prependListener(event: "exit", listener: (code: number, signal: string) => void): this; - prependListener(event: "listening", listener: (address: Address) => void): this; - prependListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. - prependListener(event: "online", listener: () => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "disconnect", listener: () => void): this; - prependOnceListener(event: "error", listener: (code: number, signal: string) => void): this; - prependOnceListener(event: "exit", listener: (code: number, signal: string) => void): this; - prependOnceListener(event: "listening", listener: (address: Address) => void): this; - prependOnceListener(event: "message", listener: (message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. - prependOnceListener(event: "online", listener: () => void): this; - } - - export interface Cluster extends events.EventEmitter { - Worker: Worker; - disconnect(callback?: Function): void; - fork(env?: any): Worker; - isMaster: boolean; - isWorker: boolean; - // TODO: cluster.schedulingPolicy - settings: ClusterSettings; - setupMaster(settings?: ClusterSetupMasterSettings): void; - worker: Worker; - workers: { - [index: string]: Worker - }; - - /** - * events.EventEmitter - * 1. disconnect - * 2. exit - * 3. fork - * 4. listening - * 5. message - * 6. online - * 7. setup - */ - addListener(event: string, listener: Function): this; - addListener(event: "disconnect", listener: (worker: Worker) => void): this; - addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; - addListener(event: "fork", listener: (worker: Worker) => void): this; - addListener(event: "listening", listener: (worker: Worker, address: Address) => void): this; - addListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. - addListener(event: "online", listener: (worker: Worker) => void): this; - addListener(event: "setup", listener: (settings: any) => void): this; - - emit(event: string, listener: Function): boolean; - emit(event: "disconnect", listener: (worker: Worker) => void): boolean; - emit(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): boolean; - emit(event: "fork", listener: (worker: Worker) => void): boolean; - emit(event: "listening", listener: (worker: Worker, address: Address) => void): boolean; - emit(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): boolean; - emit(event: "online", listener: (worker: Worker) => void): boolean; - emit(event: "setup", listener: (settings: any) => void): boolean; - - on(event: string, listener: Function): this; - on(event: "disconnect", listener: (worker: Worker) => void): this; - on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; - on(event: "fork", listener: (worker: Worker) => void): this; - on(event: "listening", listener: (worker: Worker, address: Address) => void): this; - on(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. - on(event: "online", listener: (worker: Worker) => void): this; - on(event: "setup", listener: (settings: any) => void): this; - - once(event: string, listener: Function): this; - once(event: "disconnect", listener: (worker: Worker) => void): this; - once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; - once(event: "fork", listener: (worker: Worker) => void): this; - once(event: "listening", listener: (worker: Worker, address: Address) => void): this; - once(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. - once(event: "online", listener: (worker: Worker) => void): this; - once(event: "setup", listener: (settings: any) => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "disconnect", listener: (worker: Worker) => void): this; - prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; - prependListener(event: "fork", listener: (worker: Worker) => void): this; - prependListener(event: "listening", listener: (worker: Worker, address: Address) => void): this; - prependListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. - prependListener(event: "online", listener: (worker: Worker) => void): this; - prependListener(event: "setup", listener: (settings: any) => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): this; - prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): this; - prependOnceListener(event: "fork", listener: (worker: Worker) => void): this; - prependOnceListener(event: "listening", listener: (worker: Worker, address: Address) => void): this; - prependOnceListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): this; // the handle is a net.Socket or net.Server object, or undefined. - prependOnceListener(event: "online", listener: (worker: Worker) => void): this; - prependOnceListener(event: "setup", listener: (settings: any) => void): this; - - } - - export function disconnect(callback?: Function): void; - export function fork(env?: any): Worker; - export var isMaster: boolean; - export var isWorker: boolean; - // TODO: cluster.schedulingPolicy - export var settings: ClusterSettings; - export function setupMaster(settings?: ClusterSetupMasterSettings): void; - export var worker: Worker; - export var workers: { - [index: string]: Worker - }; - - /** - * events.EventEmitter - * 1. disconnect - * 2. exit - * 3. fork - * 4. listening - * 5. message - * 6. online - * 7. setup - */ - export function addListener(event: string, listener: Function): Cluster; - export function addListener(event: "disconnect", listener: (worker: Worker) => void): Cluster; - export function addListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster; - export function addListener(event: "fork", listener: (worker: Worker) => void): Cluster; - export function addListener(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster; - export function addListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined. - export function addListener(event: "online", listener: (worker: Worker) => void): Cluster; - export function addListener(event: "setup", listener: (settings: any) => void): Cluster; - - export function emit(event: string, listener: Function): boolean; - export function emit(event: "disconnect", listener: (worker: Worker) => void): boolean; - export function emit(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): boolean; - export function emit(event: "fork", listener: (worker: Worker) => void): boolean; - export function emit(event: "listening", listener: (worker: Worker, address: Address) => void): boolean; - export function emit(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): boolean; - export function emit(event: "online", listener: (worker: Worker) => void): boolean; - export function emit(event: "setup", listener: (settings: any) => void): boolean; - - export function on(event: string, listener: Function): Cluster; - export function on(event: "disconnect", listener: (worker: Worker) => void): Cluster; - export function on(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster; - export function on(event: "fork", listener: (worker: Worker) => void): Cluster; - export function on(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster; - export function on(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined. - export function on(event: "online", listener: (worker: Worker) => void): Cluster; - export function on(event: "setup", listener: (settings: any) => void): Cluster; - - export function once(event: string, listener: Function): Cluster; - export function once(event: "disconnect", listener: (worker: Worker) => void): Cluster; - export function once(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster; - export function once(event: "fork", listener: (worker: Worker) => void): Cluster; - export function once(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster; - export function once(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined. - export function once(event: "online", listener: (worker: Worker) => void): Cluster; - export function once(event: "setup", listener: (settings: any) => void): Cluster; - - export function removeListener(event: string, listener: Function): Cluster; - export function removeAllListeners(event?: string): Cluster; - export function setMaxListeners(n: number): Cluster; - export function getMaxListeners(): number; - export function listeners(event: string): Function[]; - export function listenerCount(type: string): number; - - export function prependListener(event: string, listener: Function): Cluster; - export function prependListener(event: "disconnect", listener: (worker: Worker) => void): Cluster; - export function prependListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster; - export function prependListener(event: "fork", listener: (worker: Worker) => void): Cluster; - export function prependListener(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster; - export function prependListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined. - export function prependListener(event: "online", listener: (worker: Worker) => void): Cluster; - export function prependListener(event: "setup", listener: (settings: any) => void): Cluster; - - export function prependOnceListener(event: string, listener: Function): Cluster; - export function prependOnceListener(event: "disconnect", listener: (worker: Worker) => void): Cluster; - export function prependOnceListener(event: "exit", listener: (worker: Worker, code: number, signal: string) => void): Cluster; - export function prependOnceListener(event: "fork", listener: (worker: Worker) => void): Cluster; - export function prependOnceListener(event: "listening", listener: (worker: Worker, address: Address) => void): Cluster; - export function prependOnceListener(event: "message", listener: (worker: Worker, message: any, handle: net.Socket | net.Server) => void): Cluster; // the handle is a net.Socket or net.Server object, or undefined. - export function prependOnceListener(event: "online", listener: (worker: Worker) => void): Cluster; - export function prependOnceListener(event: "setup", listener: (settings: any) => void): Cluster; - - export function eventNames(): string[]; -} - -declare module "zlib" { - import * as stream from "stream"; - export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } - - export interface Gzip extends stream.Transform { } - export interface Gunzip extends stream.Transform { } - export interface Deflate extends stream.Transform { } - export interface Inflate extends stream.Transform { } - export interface DeflateRaw extends stream.Transform { } - export interface InflateRaw extends stream.Transform { } - export interface Unzip extends stream.Transform { } - - export function createGzip(options?: ZlibOptions): Gzip; - export function createGunzip(options?: ZlibOptions): Gunzip; - export function createDeflate(options?: ZlibOptions): Deflate; - export function createInflate(options?: ZlibOptions): Inflate; - export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; - export function createInflateRaw(options?: ZlibOptions): InflateRaw; - export function createUnzip(options?: ZlibOptions): Unzip; - - export function deflate(buf: Buffer, callback: (error: Error, result: any) => void): void; - export function deflateSync(buf: Buffer, options?: ZlibOptions): any; - export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) => void): void; - export function deflateRawSync(buf: Buffer, options?: ZlibOptions): any; - export function gzip(buf: Buffer, callback: (error: Error, result: any) => void): void; - export function gzipSync(buf: Buffer, options?: ZlibOptions): any; - export function gunzip(buf: Buffer, callback: (error: Error, result: any) => void): void; - export function gunzipSync(buf: Buffer, options?: ZlibOptions): any; - export function inflate(buf: Buffer, callback: (error: Error, result: any) => void): void; - export function inflateSync(buf: Buffer, options?: ZlibOptions): any; - export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) => void): void; - export function inflateRawSync(buf: Buffer, options?: ZlibOptions): any; - export function unzip(buf: Buffer, callback: (error: Error, result: any) => void): void; - export function unzipSync(buf: Buffer, options?: ZlibOptions): any; - - // Constants - export var Z_NO_FLUSH: number; - export var Z_PARTIAL_FLUSH: number; - export var Z_SYNC_FLUSH: number; - export var Z_FULL_FLUSH: number; - export var Z_FINISH: number; - export var Z_BLOCK: number; - export var Z_TREES: number; - export var Z_OK: number; - export var Z_STREAM_END: number; - export var Z_NEED_DICT: number; - export var Z_ERRNO: number; - export var Z_STREAM_ERROR: number; - export var Z_DATA_ERROR: number; - export var Z_MEM_ERROR: number; - export var Z_BUF_ERROR: number; - export var Z_VERSION_ERROR: number; - export var Z_NO_COMPRESSION: number; - export var Z_BEST_SPEED: number; - export var Z_BEST_COMPRESSION: number; - export var Z_DEFAULT_COMPRESSION: number; - export var Z_FILTERED: number; - export var Z_HUFFMAN_ONLY: number; - export var Z_RLE: number; - export var Z_FIXED: number; - export var Z_DEFAULT_STRATEGY: number; - export var Z_BINARY: number; - export var Z_TEXT: number; - export var Z_ASCII: number; - export var Z_UNKNOWN: number; - export var Z_DEFLATED: number; - export var Z_NULL: number; -} - -declare module "os" { - export interface CpuInfo { - model: string; - speed: number; - times: { - user: number; - nice: number; - sys: number; - idle: number; - irq: number; - }; - } - - export interface NetworkInterfaceInfo { - address: string; - netmask: string; - family: string; - mac: string; - internal: boolean; - } - - export function hostname(): string; - export function loadavg(): number[]; - export function uptime(): number; - export function freemem(): number; - export function totalmem(): number; - export function cpus(): CpuInfo[]; - export function type(): string; - export function release(): string; - export function networkInterfaces(): { [index: string]: NetworkInterfaceInfo[] }; - export function homedir(): string; - export function userInfo(options?: { encoding: string }): { username: string, uid: number, gid: number, shell: any, homedir: string } - export var constants: { - UV_UDP_REUSEADDR: number, - errno: { - SIGHUP: number; - SIGINT: number; - SIGQUIT: number; - SIGILL: number; - SIGTRAP: number; - SIGABRT: number; - SIGIOT: number; - SIGBUS: number; - SIGFPE: number; - SIGKILL: number; - SIGUSR1: number; - SIGSEGV: number; - SIGUSR2: number; - SIGPIPE: number; - SIGALRM: number; - SIGTERM: number; - SIGCHLD: number; - SIGSTKFLT: number; - SIGCONT: number; - SIGSTOP: number; - SIGTSTP: number; - SIGTTIN: number; - SIGTTOU: number; - SIGURG: number; - SIGXCPU: number; - SIGXFSZ: number; - SIGVTALRM: number; - SIGPROF: number; - SIGWINCH: number; - SIGIO: number; - SIGPOLL: number; - SIGPWR: number; - SIGSYS: number; - SIGUNUSED: number; - }, - signals: { - E2BIG: number; - EACCES: number; - EADDRINUSE: number; - EADDRNOTAVAIL: number; - EAFNOSUPPORT: number; - EAGAIN: number; - EALREADY: number; - EBADF: number; - EBADMSG: number; - EBUSY: number; - ECANCELED: number; - ECHILD: number; - ECONNABORTED: number; - ECONNREFUSED: number; - ECONNRESET: number; - EDEADLK: number; - EDESTADDRREQ: number; - EDOM: number; - EDQUOT: number; - EEXIST: number; - EFAULT: number; - EFBIG: number; - EHOSTUNREACH: number; - EIDRM: number; - EILSEQ: number; - EINPROGRESS: number; - EINTR: number; - EINVAL: number; - EIO: number; - EISCONN: number; - EISDIR: number; - ELOOP: number; - EMFILE: number; - EMLINK: number; - EMSGSIZE: number; - EMULTIHOP: number; - ENAMETOOLONG: number; - ENETDOWN: number; - ENETRESET: number; - ENETUNREACH: number; - ENFILE: number; - ENOBUFS: number; - ENODATA: number; - ENODEV: number; - ENOENT: number; - ENOEXEC: number; - ENOLCK: number; - ENOLINK: number; - ENOMEM: number; - ENOMSG: number; - ENOPROTOOPT: number; - ENOSPC: number; - ENOSR: number; - ENOSTR: number; - ENOSYS: number; - ENOTCONN: number; - ENOTDIR: number; - ENOTEMPTY: number; - ENOTSOCK: number; - ENOTSUP: number; - ENOTTY: number; - ENXIO: number; - EOPNOTSUPP: number; - EOVERFLOW: number; - EPERM: number; - EPIPE: number; - EPROTO: number; - EPROTONOSUPPORT: number; - EPROTOTYPE: number; - ERANGE: number; - EROFS: number; - ESPIPE: number; - ESRCH: number; - ESTALE: number; - ETIME: number; - ETIMEDOUT: number; - ETXTBSY: number; - EWOULDBLOCK: number; - EXDEV: number; - }, - }; - export function arch(): string; - export function platform(): string; - export function tmpdir(): string; - export var EOL: string; - export function endianness(): "BE" | "LE"; -} - -declare module "https" { - import * as tls from "tls"; - import * as events from "events"; - import * as http from "http"; - - export interface ServerOptions { - pfx?: any; - key?: any; - passphrase?: string; - cert?: any; - ca?: any; - crl?: any; - ciphers?: string; - honorCipherOrder?: boolean; - requestCert?: boolean; - rejectUnauthorized?: boolean; - NPNProtocols?: any; - SNICallback?: (servername: string, cb: (err: Error, ctx: tls.SecureContext) => any) => any; - } - - export interface RequestOptions extends http.RequestOptions { - pfx?: any; - key?: any; - passphrase?: string; - cert?: any; - ca?: any; - ciphers?: string; - rejectUnauthorized?: boolean; - secureProtocol?: string; - } - - export interface Agent extends http.Agent { } - - export interface AgentOptions extends http.AgentOptions { - pfx?: any; - key?: any; - passphrase?: string; - cert?: any; - ca?: any; - ciphers?: string; - rejectUnauthorized?: boolean; - secureProtocol?: string; - maxCachedSessions?: number; - } - - export var Agent: { - new (options?: AgentOptions): Agent; - }; - export interface Server extends tls.Server { } - export function createServer(options: ServerOptions, requestListener?: Function): Server; - export function request(options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest; - export function get(options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest; - export var globalAgent: Agent; -} - -declare module "punycode" { - export function decode(string: string): string; - export function encode(string: string): string; - export function toUnicode(domain: string): string; - export function toASCII(domain: string): string; - export var ucs2: ucs2; - interface ucs2 { - decode(string: string): number[]; - encode(codePoints: number[]): string; - } - export var version: any; -} - -declare module "repl" { - import * as stream from "stream"; - import * as readline from "readline"; - - export interface ReplOptions { - prompt?: string; - input?: NodeJS.ReadableStream; - output?: NodeJS.WritableStream; - terminal?: boolean; - eval?: Function; - useColors?: boolean; - useGlobal?: boolean; - ignoreUndefined?: boolean; - writer?: Function; - completer?: Function; - replMode?: any; - breakEvalOnSigint?: any; - } - - export interface REPLServer extends readline.ReadLine { - defineCommand(keyword: string, cmd: Function | { help: string, action: Function }): void; - displayPrompt(preserveCursor?: boolean): void - } - - export function start(options: ReplOptions): REPLServer; -} - -declare module "readline" { - import * as events from "events"; - import * as stream from "stream"; - - export interface Key { - sequence?: string; - name?: string; - ctrl?: boolean; - meta?: boolean; - shift?: boolean; - } - - export interface ReadLine extends events.EventEmitter { - setPrompt(prompt: string): void; - prompt(preserveCursor?: boolean): void; - question(query: string, callback: (answer: string) => void): void; - pause(): ReadLine; - resume(): ReadLine; - close(): void; - write(data: string | Buffer, key?: Key): void; - } - - export interface Completer { - (line: string): CompleterResult; - (line: string, callback: (err: any, result: CompleterResult) => void): any; - } - - export interface CompleterResult { - completions: string[]; - line: string; - } - - export interface ReadLineOptions { - input: NodeJS.ReadableStream; - output?: NodeJS.WritableStream; - completer?: Completer; - terminal?: boolean; - historySize?: number; - } - - export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer, terminal?: boolean): ReadLine; - export function createInterface(options: ReadLineOptions): ReadLine; - - export function cursorTo(stream: NodeJS.WritableStream, x: number, y: number): void; - export function moveCursor(stream: NodeJS.WritableStream, dx: number | string, dy: number | string): void; - export function clearLine(stream: NodeJS.WritableStream, dir: number): void; - export function clearScreenDown(stream: NodeJS.WritableStream): void; -} - -declare module "vm" { - export interface Context { } - export interface ScriptOptions { - filename?: string; - lineOffset?: number; - columnOffset?: number; - displayErrors?: boolean; - timeout?: number; - cachedData?: Buffer; - produceCachedData?: boolean; - } - export interface RunningScriptOptions { - filename?: string; - lineOffset?: number; - columnOffset?: number; - displayErrors?: boolean; - timeout?: number; - } - export class Script { - constructor(code: string, options?: ScriptOptions); - runInContext(contextifiedSandbox: Context, options?: RunningScriptOptions): any; - runInNewContext(sandbox?: Context, options?: RunningScriptOptions): any; - runInThisContext(options?: RunningScriptOptions): any; - } - export function createContext(sandbox?: Context): Context; - export function isContext(sandbox: Context): boolean; - export function runInContext(code: string, contextifiedSandbox: Context, options?: RunningScriptOptions): any; - export function runInDebugContext(code: string): any; - export function runInNewContext(code: string, sandbox?: Context, options?: RunningScriptOptions): any; - export function runInThisContext(code: string, options?: RunningScriptOptions): any; -} - -declare module "child_process" { - import * as events from "events"; - import * as stream from "stream"; - - export interface ChildProcess extends events.EventEmitter { - stdin: stream.Writable; - stdout: stream.Readable; - stderr: stream.Readable; - stdio: [stream.Writable, stream.Readable, stream.Readable]; - pid: number; - kill(signal?: string): void; - send(message: any, sendHandle?: any): boolean; - connected: boolean; - disconnect(): void; - unref(): void; - ref(): void; - } - - export interface SpawnOptions { - cwd?: string; - env?: any; - stdio?: any; - detached?: boolean; - uid?: number; - gid?: number; - shell?: boolean | string; - } - export function spawn(command: string, args?: string[], options?: SpawnOptions): ChildProcess; - - export interface ExecOptions { - cwd?: string; - env?: any; - shell?: string; - timeout?: number; - maxBuffer?: number; - killSignal?: string; - uid?: number; - gid?: number; - } - export interface ExecOptionsWithStringEncoding extends ExecOptions { - encoding: BufferEncoding; - } - export interface ExecOptionsWithBufferEncoding extends ExecOptions { - encoding: string; // specify `null`. - } - export function exec(command: string, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; - export function exec(command: string, options: ExecOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; - // usage. child_process.exec("tsc", {encoding: null as string}, (err, stdout, stderr) => {}); - export function exec(command: string, options: ExecOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess; - export function exec(command: string, options: ExecOptions, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; - - export interface ExecFileOptions { - cwd?: string; - env?: any; - timeout?: number; - maxBuffer?: number; - killSignal?: string; - uid?: number; - gid?: number; - } - export interface ExecFileOptionsWithStringEncoding extends ExecFileOptions { - encoding: BufferEncoding; - } - export interface ExecFileOptionsWithBufferEncoding extends ExecFileOptions { - encoding: string; // specify `null`. - } - export function execFile(file: string, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; - export function execFile(file: string, options?: ExecFileOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; - // usage. child_process.execFile("file.sh", {encoding: null as string}, (err, stdout, stderr) => {}); - export function execFile(file: string, options?: ExecFileOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess; - export function execFile(file: string, options?: ExecFileOptions, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; - export function execFile(file: string, args?: string[], callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; - export function execFile(file: string, args?: string[], options?: ExecFileOptionsWithStringEncoding, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; - // usage. child_process.execFile("file.sh", ["foo"], {encoding: null as string}, (err, stdout, stderr) => {}); - export function execFile(file: string, args?: string[], options?: ExecFileOptionsWithBufferEncoding, callback?: (error: Error, stdout: Buffer, stderr: Buffer) => void): ChildProcess; - export function execFile(file: string, args?: string[], options?: ExecFileOptions, callback?: (error: Error, stdout: string, stderr: string) => void): ChildProcess; - - export interface ForkOptions { - cwd?: string; - env?: any; - execPath?: string; - execArgv?: string[]; - silent?: boolean; - uid?: number; - gid?: number; - } - export function fork(modulePath: string, args?: string[], options?: ForkOptions): ChildProcess; - - export interface SpawnSyncOptions { - cwd?: string; - input?: string | Buffer; - stdio?: any; - env?: any; - uid?: number; - gid?: number; - timeout?: number; - killSignal?: string; - maxBuffer?: number; - encoding?: string; - shell?: boolean | string; - } - export interface SpawnSyncOptionsWithStringEncoding extends SpawnSyncOptions { - encoding: BufferEncoding; - } - export interface SpawnSyncOptionsWithBufferEncoding extends SpawnSyncOptions { - encoding: string; // specify `null`. - } - export interface SpawnSyncReturns { - pid: number; - output: string[]; - stdout: T; - stderr: T; - status: number; - signal: string; - error: Error; - } - export function spawnSync(command: string): SpawnSyncReturns; - export function spawnSync(command: string, options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns; - export function spawnSync(command: string, options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; - export function spawnSync(command: string, options?: SpawnSyncOptions): SpawnSyncReturns; - export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptionsWithStringEncoding): SpawnSyncReturns; - export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptionsWithBufferEncoding): SpawnSyncReturns; - export function spawnSync(command: string, args?: string[], options?: SpawnSyncOptions): SpawnSyncReturns; - - export interface ExecSyncOptions { - cwd?: string; - input?: string | Buffer; - stdio?: any; - env?: any; - shell?: string; - uid?: number; - gid?: number; - timeout?: number; - killSignal?: string; - maxBuffer?: number; - encoding?: string; - } - export interface ExecSyncOptionsWithStringEncoding extends ExecSyncOptions { - encoding: BufferEncoding; - } - export interface ExecSyncOptionsWithBufferEncoding extends ExecSyncOptions { - encoding: string; // specify `null`. - } - export function execSync(command: string): Buffer; - export function execSync(command: string, options?: ExecSyncOptionsWithStringEncoding): string; - export function execSync(command: string, options?: ExecSyncOptionsWithBufferEncoding): Buffer; - export function execSync(command: string, options?: ExecSyncOptions): Buffer; - - export interface ExecFileSyncOptions { - cwd?: string; - input?: string | Buffer; - stdio?: any; - env?: any; - uid?: number; - gid?: number; - timeout?: number; - killSignal?: string; - maxBuffer?: number; - encoding?: string; - } - export interface ExecFileSyncOptionsWithStringEncoding extends ExecFileSyncOptions { - encoding: BufferEncoding; - } - export interface ExecFileSyncOptionsWithBufferEncoding extends ExecFileSyncOptions { - encoding: string; // specify `null`. - } - export function execFileSync(command: string): Buffer; - export function execFileSync(command: string, options?: ExecFileSyncOptionsWithStringEncoding): string; - export function execFileSync(command: string, options?: ExecFileSyncOptionsWithBufferEncoding): Buffer; - export function execFileSync(command: string, options?: ExecFileSyncOptions): Buffer; - export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptionsWithStringEncoding): string; - export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptionsWithBufferEncoding): Buffer; - export function execFileSync(command: string, args?: string[], options?: ExecFileSyncOptions): Buffer; -} - -declare module "url" { - export interface Url { - href?: string; - protocol?: string; - auth?: string; - hostname?: string; - port?: string; - host?: string; - pathname?: string; - search?: string; - query?: string | any; - slashes?: boolean; - hash?: string; - path?: string; - } - - export function parse(urlStr: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): Url; - export function format(url: Url): string; - export function resolve(from: string, to: string): string; -} - -declare module "dns" { - export interface MxRecord { - exchange: string, - priority: number - } - - export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) => void): string; - export function lookup(domain: string, callback: (err: Error, address: string, family: number) => void): string; - export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) => void): string[]; - export function resolve(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; - export function resolve4(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; - export function resolve6(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; - export function resolveMx(domain: string, callback: (err: Error, addresses: MxRecord[]) => void): string[]; - export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; - export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; - export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; - export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) => void): string[]; - export function reverse(ip: string, callback: (err: Error, domains: string[]) => void): string[]; - export function setServers(servers: string[]): void; - - //Error codes - export var NODATA: string; - export var FORMERR: string; - export var SERVFAIL: string; - export var NOTFOUND: string; - export var NOTIMP: string; - export var REFUSED: string; - export var BADQUERY: string; - export var BADNAME: string; - export var BADFAMILY: string; - export var BADRESP: string; - export var CONNREFUSED: string; - export var TIMEOUT: string; - export var EOF: string; - export var FILE: string; - export var NOMEM: string; - export var DESTRUCTION: string; - export var BADSTR: string; - export var BADFLAGS: string; - export var NONAME: string; - export var BADHINTS: string; - export var NOTINITIALIZED: string; - export var LOADIPHLPAPI: string; - export var ADDRGETNETWORKPARAMS: string; - export var CANCELLED: string; -} - -declare module "net" { - import * as stream from "stream"; - - export interface Socket extends stream.Duplex { - // Extended base methods - write(buffer: Buffer): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - write(str: string, encoding?: string, fd?: string): boolean; - - connect(port: number, host?: string, connectionListener?: Function): void; - connect(path: string, connectionListener?: Function): void; - bufferSize: number; - setEncoding(encoding?: string): void; - write(data: any, encoding?: string, callback?: Function): void; - destroy(): void; - pause(): Socket; - resume(): Socket; - setTimeout(timeout: number, callback?: Function): void; - setNoDelay(noDelay?: boolean): void; - setKeepAlive(enable?: boolean, initialDelay?: number): void; - address(): { port: number; family: string; address: string; }; - unref(): void; - ref(): void; - - remoteAddress: string; - remoteFamily: string; - remotePort: number; - localAddress: string; - localPort: number; - bytesRead: number; - bytesWritten: number; - - // Extended base methods - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - end(data?: any, encoding?: string): void; - - /** - * events.EventEmitter - * 1. close - * 2. connect - * 3. data - * 4. drain - * 5. end - * 6. error - * 7. lookup - * 8. timeout - */ - addListener(event: string, listener: Function): this; - addListener(event: "close", listener: (had_error: boolean) => void): this; - addListener(event: "connect", listener: () => void): this; - addListener(event: "data", listener: (data: Buffer) => void): this; - addListener(event: "drain", listener: () => void): this; - addListener(event: "end", listener: () => void): this; - addListener(event: "error", listener: (err: Error) => void): this; - addListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; - addListener(event: "timeout", listener: () => void): this; - - emit(event: string, ...args: any[]): boolean; - emit(event: "close", had_error: boolean): boolean; - emit(event: "connect"): boolean; - emit(event: "data", data: Buffer): boolean; - emit(event: "drain"): boolean; - emit(event: "end"): boolean; - emit(event: "error", err: Error): boolean; - emit(event: "lookup", err: Error, address: string, family: string | number, host: string): boolean; - emit(event: "timeout"): boolean; - - on(event: string, listener: Function): this; - on(event: "close", listener: (had_error: boolean) => void): this; - on(event: "connect", listener: () => void): this; - on(event: "data", listener: (data: Buffer) => void): this; - on(event: "drain", listener: () => void): this; - on(event: "end", listener: () => void): this; - on(event: "error", listener: (err: Error) => void): this; - on(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; - on(event: "timeout", listener: () => void): this; - - once(event: string, listener: Function): this; - once(event: "close", listener: (had_error: boolean) => void): this; - once(event: "connect", listener: () => void): this; - once(event: "data", listener: (data: Buffer) => void): this; - once(event: "drain", listener: () => void): this; - once(event: "end", listener: () => void): this; - once(event: "error", listener: (err: Error) => void): this; - once(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; - once(event: "timeout", listener: () => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "close", listener: (had_error: boolean) => void): this; - prependListener(event: "connect", listener: () => void): this; - prependListener(event: "data", listener: (data: Buffer) => void): this; - prependListener(event: "drain", listener: () => void): this; - prependListener(event: "end", listener: () => void): this; - prependListener(event: "error", listener: (err: Error) => void): this; - prependListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; - prependListener(event: "timeout", listener: () => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "close", listener: (had_error: boolean) => void): this; - prependOnceListener(event: "connect", listener: () => void): this; - prependOnceListener(event: "data", listener: (data: Buffer) => void): this; - prependOnceListener(event: "drain", listener: () => void): this; - prependOnceListener(event: "end", listener: () => void): this; - prependOnceListener(event: "error", listener: (err: Error) => void): this; - prependOnceListener(event: "lookup", listener: (err: Error, address: string, family: string | number, host: string) => void): this; - prependOnceListener(event: "timeout", listener: () => void): this; - } - - export var Socket: { - new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; - }; - - export interface ListenOptions { - port?: number; - host?: string; - backlog?: number; - path?: string; - exclusive?: boolean; - } - - export interface Server extends Socket { - listen(port: number, hostname?: string, backlog?: number, listeningListener?: Function): Server; - listen(port: number, hostname?: string, listeningListener?: Function): Server; - listen(port: number, backlog?: number, listeningListener?: Function): Server; - listen(port: number, listeningListener?: Function): Server; - listen(path: string, backlog?: number, listeningListener?: Function): Server; - listen(path: string, listeningListener?: Function): Server; - listen(handle: any, backlog?: number, listeningListener?: Function): Server; - listen(handle: any, listeningListener?: Function): Server; - listen(options: ListenOptions, listeningListener?: Function): Server; - close(callback?: Function): Server; - address(): { port: number; family: string; address: string; }; - getConnections(cb: (error: Error, count: number) => void): void; - ref(): Server; - unref(): Server; - maxConnections: number; - connections: number; - - /** - * events.EventEmitter - * 1. close - * 2. connection - * 3. error - * 4. listening - */ - addListener(event: string, listener: Function): this; - addListener(event: "close", listener: () => void): this; - addListener(event: "connection", listener: (socket: Socket) => void): this; - addListener(event: "error", listener: (err: Error) => void): this; - addListener(event: "listening", listener: () => void): this; - - emit(event: string, ...args: any[]): boolean; - emit(event: "close"): boolean; - emit(event: "connection", socket: Socket): boolean; - emit(event: "error", err: Error): boolean; - emit(event: "listening"): boolean; - - on(event: string, listener: Function): this; - on(event: "close", listener: () => void): this; - on(event: "connection", listener: (socket: Socket) => void): this; - on(event: "error", listener: (err: Error) => void): this; - on(event: "listening", listener: () => void): this; - - once(event: string, listener: Function): this; - once(event: "close", listener: () => void): this; - once(event: "connection", listener: (socket: Socket) => void): this; - once(event: "error", listener: (err: Error) => void): this; - once(event: "listening", listener: () => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "close", listener: () => void): this; - prependListener(event: "connection", listener: (socket: Socket) => void): this; - prependListener(event: "error", listener: (err: Error) => void): this; - prependListener(event: "listening", listener: () => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "close", listener: () => void): this; - prependOnceListener(event: "connection", listener: (socket: Socket) => void): this; - prependOnceListener(event: "error", listener: (err: Error) => void): this; - prependOnceListener(event: "listening", listener: () => void): this; - } - export function createServer(connectionListener?: (socket: Socket) => void): Server; - export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) => void): Server; - export function connect(options: { port: number, host?: string, localAddress?: string, localPort?: string, family?: number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; - export function connect(port: number, host?: string, connectionListener?: Function): Socket; - export function connect(path: string, connectionListener?: Function): Socket; - export function createConnection(options: { port: number, host?: string, localAddress?: string, localPort?: string, family?: number, allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; - export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; - export function createConnection(path: string, connectionListener?: Function): Socket; - export function isIP(input: string): number; - export function isIPv4(input: string): boolean; - export function isIPv6(input: string): boolean; -} - -declare module "dgram" { - import * as events from "events"; - - interface RemoteInfo { - address: string; - family: string; - port: number; - } - - interface AddressInfo { - address: string; - family: string; - port: number; - } - - interface BindOptions { - port: number; - address?: string; - exclusive?: boolean; - } - - interface SocketOptions { - type: "udp4" | "udp6"; - reuseAddr?: boolean; - } - - export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; - export function createSocket(options: SocketOptions, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; - - export interface Socket extends events.EventEmitter { - send(msg: Buffer | String | any[], port: number, address: string, callback?: (error: Error, bytes: number) => void): void; - send(msg: Buffer | String | any[], offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; - bind(port?: number, address?: string, callback?: () => void): void; - bind(options: BindOptions, callback?: Function): void; - close(callback?: any): void; - address(): AddressInfo; - setBroadcast(flag: boolean): void; - setTTL(ttl: number): void; - setMulticastTTL(ttl: number): void; - setMulticastLoopback(flag: boolean): void; - addMembership(multicastAddress: string, multicastInterface?: string): void; - dropMembership(multicastAddress: string, multicastInterface?: string): void; - ref(): void; - unref(): void; - - /** - * events.EventEmitter - * 1. close - * 2. error - * 3. listening - * 4. message - **/ - addListener(event: string, listener: Function): this; - addListener(event: "close", listener: () => void): this; - addListener(event: "error", listener: (err: Error) => void): this; - addListener(event: "listening", listener: () => void): this; - addListener(event: "message", listener: (msg: string, rinfo: AddressInfo) => void): this; - - emit(event: string, ...args: any[]): boolean; - emit(event: "close"): boolean; - emit(event: "error", err: Error): boolean; - emit(event: "listening"): boolean; - emit(event: "message", msg: string, rinfo: AddressInfo): boolean; - - on(event: string, listener: Function): this; - on(event: "close", listener: () => void): this; - on(event: "error", listener: (err: Error) => void): this; - on(event: "listening", listener: () => void): this; - on(event: "message", listener: (msg: string, rinfo: AddressInfo) => void): this; - - once(event: string, listener: Function): this; - once(event: "close", listener: () => void): this; - once(event: "error", listener: (err: Error) => void): this; - once(event: "listening", listener: () => void): this; - once(event: "message", listener: (msg: string, rinfo: AddressInfo) => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "close", listener: () => void): this; - prependListener(event: "error", listener: (err: Error) => void): this; - prependListener(event: "listening", listener: () => void): this; - prependListener(event: "message", listener: (msg: string, rinfo: AddressInfo) => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "close", listener: () => void): this; - prependOnceListener(event: "error", listener: (err: Error) => void): this; - prependOnceListener(event: "listening", listener: () => void): this; - prependOnceListener(event: "message", listener: (msg: string, rinfo: AddressInfo) => void): this; - } -} - -declare module "fs" { - import * as stream from "stream"; - import * as events from "events"; - - interface Stats { - isFile(): boolean; - isDirectory(): boolean; - isBlockDevice(): boolean; - isCharacterDevice(): boolean; - isSymbolicLink(): boolean; - isFIFO(): boolean; - isSocket(): boolean; - dev: number; - ino: number; - mode: number; - nlink: number; - uid: number; - gid: number; - rdev: number; - size: number; - blksize: number; - blocks: number; - atime: Date; - mtime: Date; - ctime: Date; - birthtime: Date; - } - - interface FSWatcher extends events.EventEmitter { - close(): void; - - /** - * events.EventEmitter - * 1. change - * 2. error - */ - addListener(event: string, listener: Function): this; - addListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; - addListener(event: "error", listener: (code: number, signal: string) => void): this; - - on(event: string, listener: Function): this; - on(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; - on(event: "error", listener: (code: number, signal: string) => void): this; - - once(event: string, listener: Function): this; - once(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; - once(event: "error", listener: (code: number, signal: string) => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; - prependListener(event: "error", listener: (code: number, signal: string) => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "change", listener: (eventType: string, filename: string | Buffer) => void): this; - prependOnceListener(event: "error", listener: (code: number, signal: string) => void): this; - } - - export interface ReadStream extends stream.Readable { - close(): void; - destroy(): void; - - /** - * events.EventEmitter - * 1. open - * 2. close - */ - addListener(event: string, listener: Function): this; - addListener(event: "open", listener: (fd: number) => void): this; - addListener(event: "close", listener: () => void): this; - - on(event: string, listener: Function): this; - on(event: "open", listener: (fd: number) => void): this; - on(event: "close", listener: () => void): this; - - once(event: string, listener: Function): this; - once(event: "open", listener: (fd: number) => void): this; - once(event: "close", listener: () => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "open", listener: (fd: number) => void): this; - prependListener(event: "close", listener: () => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "open", listener: (fd: number) => void): this; - prependOnceListener(event: "close", listener: () => void): this; - } - - export interface WriteStream extends stream.Writable { - close(): void; - bytesWritten: number; - path: string | Buffer; - - /** - * events.EventEmitter - * 1. open - * 2. close - */ - addListener(event: string, listener: Function): this; - addListener(event: "open", listener: (fd: number) => void): this; - addListener(event: "close", listener: () => void): this; - - on(event: string, listener: Function): this; - on(event: "open", listener: (fd: number) => void): this; - on(event: "close", listener: () => void): this; - - once(event: string, listener: Function): this; - once(event: "open", listener: (fd: number) => void): this; - once(event: "close", listener: () => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "open", listener: (fd: number) => void): this; - prependListener(event: "close", listener: () => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "open", listener: (fd: number) => void): this; - prependOnceListener(event: "close", listener: () => void): this; - } - - /** - * Asynchronous rename. - * @param oldPath - * @param newPath - * @param callback No arguments other than a possible exception are given to the completion callback. - */ - export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - /** - * Synchronous rename - * @param oldPath - * @param newPath - */ - export function renameSync(oldPath: string, newPath: string): void; - export function truncate(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function truncate(path: string | Buffer, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function truncateSync(path: string | Buffer, len?: number): void; - export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function ftruncateSync(fd: number, len?: number): void; - export function chown(path: string | Buffer, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chownSync(path: string | Buffer, uid: number, gid: number): void; - export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fchownSync(fd: number, uid: number, gid: number): void; - export function lchown(path: string | Buffer, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchownSync(path: string | Buffer, uid: number, gid: number): void; - export function chmod(path: string | Buffer, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chmod(path: string | Buffer, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chmodSync(path: string | Buffer, mode: number): void; - export function chmodSync(path: string | Buffer, mode: string): void; - export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fchmodSync(fd: number, mode: number): void; - export function fchmodSync(fd: number, mode: string): void; - export function lchmod(path: string | Buffer, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchmod(path: string | Buffer, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchmodSync(path: string | Buffer, mode: number): void; - export function lchmodSync(path: string | Buffer, mode: string): void; - export function stat(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; - export function lstat(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; - export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; - export function statSync(path: string | Buffer): Stats; - export function lstatSync(path: string | Buffer): Stats; - export function fstatSync(fd: number): Stats; - export function link(srcpath: string | Buffer, dstpath: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function linkSync(srcpath: string | Buffer, dstpath: string | Buffer): void; - export function symlink(srcpath: string | Buffer, dstpath: string | Buffer, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function symlinkSync(srcpath: string | Buffer, dstpath: string | Buffer, type?: string): void; - export function readlink(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; - export function readlinkSync(path: string | Buffer): string; - export function realpath(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; - export function realpath(path: string | Buffer, cache: { [path: string]: string }, callback: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; - export function realpathSync(path: string | Buffer, cache?: { [path: string]: string }): string; - /* - * Asynchronous unlink - deletes the file specified in {path} - * - * @param path - * @param callback No arguments other than a possible exception are given to the completion callback. - */ - export function unlink(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void; - /* - * Synchronous unlink - deletes the file specified in {path} - * - * @param path - */ - export function unlinkSync(path: string | Buffer): void; - /* - * Asynchronous rmdir - removes the directory specified in {path} - * - * @param path - * @param callback No arguments other than a possible exception are given to the completion callback. - */ - export function rmdir(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void; - /* - * Synchronous rmdir - removes the directory specified in {path} - * - * @param path - */ - export function rmdirSync(path: string | Buffer): void; - /* - * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. - * - * @param path - * @param callback No arguments other than a possible exception are given to the completion callback. - */ - export function mkdir(path: string | Buffer, callback?: (err?: NodeJS.ErrnoException) => void): void; - /* - * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. - * - * @param path - * @param mode - * @param callback No arguments other than a possible exception are given to the completion callback. - */ - export function mkdir(path: string | Buffer, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - /* - * Asynchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. - * - * @param path - * @param mode - * @param callback No arguments other than a possible exception are given to the completion callback. - */ - export function mkdir(path: string | Buffer, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - /* - * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. - * - * @param path - * @param mode - * @param callback No arguments other than a possible exception are given to the completion callback. - */ - export function mkdirSync(path: string | Buffer, mode?: number): void; - /* - * Synchronous mkdir - creates the directory specified in {path}. Parameter {mode} defaults to 0777. - * - * @param path - * @param mode - * @param callback No arguments other than a possible exception are given to the completion callback. - */ - export function mkdirSync(path: string | Buffer, mode?: string): void; - /* - * Asynchronous mkdtemp - Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory. - * - * @param prefix - * @param callback The created folder path is passed as a string to the callback's second parameter. - */ - export function mkdtemp(prefix: string, callback?: (err: NodeJS.ErrnoException, folder: string) => void): void; - /* - * Synchronous mkdtemp - Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory. - * - * @param prefix - * @returns Returns the created folder path. - */ - export function mkdtempSync(prefix: string): string; - export function readdir(path: string | Buffer, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; - export function readdirSync(path: string | Buffer): string[]; - export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function closeSync(fd: number): void; - export function open(path: string | Buffer, flags: string | number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void; - export function open(path: string | Buffer, flags: string | number, mode: number, callback: (err: NodeJS.ErrnoException, fd: number) => void): void; - export function openSync(path: string | Buffer, flags: string | number, mode?: number): number; - export function utimes(path: string | Buffer, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function utimes(path: string | Buffer, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function utimesSync(path: string | Buffer, atime: number, mtime: number): void; - export function utimesSync(path: string | Buffer, atime: Date, mtime: Date): void; - export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function futimesSync(fd: number, atime: number, mtime: number): void; - export function futimesSync(fd: number, atime: Date, mtime: Date): void; - export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fsyncSync(fd: number): void; - export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; - export function write(fd: number, buffer: Buffer, offset: number, length: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; - export function write(fd: number, data: any, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; - export function write(fd: number, data: any, offset: number, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; - export function write(fd: number, data: any, offset: number, encoding: string, callback?: (err: NodeJS.ErrnoException, written: number, str: string) => void): void; - export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position?: number): number; - export function writeSync(fd: number, data: any, position?: number, enconding?: string): number; - export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; - export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; - /* - * Asynchronous readFile - Asynchronously reads the entire contents of a file. - * - * @param fileName - * @param encoding - * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. - */ - export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; - /* - * Asynchronous readFile - Asynchronously reads the entire contents of a file. - * - * @param fileName - * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. - * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. - */ - export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; - /* - * Asynchronous readFile - Asynchronously reads the entire contents of a file. - * - * @param fileName - * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFile returns a string; otherwise it returns a Buffer. - * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. - */ - export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; - /* - * Asynchronous readFile - Asynchronously reads the entire contents of a file. - * - * @param fileName - * @param callback - The callback is passed two arguments (err, data), where data is the contents of the file. - */ - export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; - /* - * Synchronous readFile - Synchronously reads the entire contents of a file. - * - * @param fileName - * @param encoding - */ - export function readFileSync(filename: string, encoding: string): string; - /* - * Synchronous readFile - Synchronously reads the entire contents of a file. - * - * @param fileName - * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. - */ - export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; - /* - * Synchronous readFile - Synchronously reads the entire contents of a file. - * - * @param fileName - * @param options An object with optional {encoding} and {flag} properties. If {encoding} is specified, readFileSync returns a string; otherwise it returns a Buffer. - */ - export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; - export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; - export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; - export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; - export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; - export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; - export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; - export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; - export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; - export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; - export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; - export function watch(filename: string, encoding: string, listener?: (event: string, filename: string | Buffer) => any): FSWatcher; - export function watch(filename: string, options: { persistent?: boolean; recursive?: boolean; encoding?: string }, listener?: (event: string, filename: string | Buffer) => any): FSWatcher; - export function exists(path: string | Buffer, callback?: (exists: boolean) => void): void; - export function existsSync(path: string | Buffer): boolean; - - export namespace constants { - // File Access Constants - - /** Constant for fs.access(). File is visible to the calling process. */ - export const F_OK: number; - - /** Constant for fs.access(). File can be read by the calling process. */ - export const R_OK: number; - - /** Constant for fs.access(). File can be written by the calling process. */ - export const W_OK: number; - - /** Constant for fs.access(). File can be executed by the calling process. */ - export const X_OK: number; - - // File Open Constants - - /** Constant for fs.open(). Flag indicating to open a file for read-only access. */ - export const O_RDONLY: number; - - /** Constant for fs.open(). Flag indicating to open a file for write-only access. */ - export const O_WRONLY: number; - - /** Constant for fs.open(). Flag indicating to open a file for read-write access. */ - export const O_RDWR: number; - - /** Constant for fs.open(). Flag indicating to create the file if it does not already exist. */ - export const O_CREAT: number; - - /** Constant for fs.open(). Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists. */ - export const O_EXCL: number; - - /** Constant for fs.open(). Flag indicating that if path identifies a terminal device, opening the path shall not cause that terminal to become the controlling terminal for the process (if the process does not already have one). */ - export const O_NOCTTY: number; - - /** Constant for fs.open(). Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero. */ - export const O_TRUNC: number; - - /** Constant for fs.open(). Flag indicating that data will be appended to the end of the file. */ - export const O_APPEND: number; - - /** Constant for fs.open(). Flag indicating that the open should fail if the path is not a directory. */ - export const O_DIRECTORY: number; - - /** Constant for fs.open(). Flag indicating reading accesses to the file system will no longer result in an update to the atime information associated with the file. This flag is available on Linux operating systems only. */ - export const O_NOATIME: number; - - /** Constant for fs.open(). Flag indicating that the open should fail if the path is a symbolic link. */ - export const O_NOFOLLOW: number; - - /** Constant for fs.open(). Flag indicating that the file is opened for synchronous I/O. */ - export const O_SYNC: number; - - /** Constant for fs.open(). Flag indicating to open the symbolic link itself rather than the resource it is pointing to. */ - export const O_SYMLINK: number; - - /** Constant for fs.open(). When set, an attempt will be made to minimize caching effects of file I/O. */ - export const O_DIRECT: number; - - /** Constant for fs.open(). Flag indicating to open the file in nonblocking mode when possible. */ - export const O_NONBLOCK: number; - - // File Type Constants - - /** Constant for fs.Stats mode property for determining a file's type. Bit mask used to extract the file type code. */ - export const S_IFMT: number; - - /** Constant for fs.Stats mode property for determining a file's type. File type constant for a regular file. */ - export const S_IFREG: number; - - /** Constant for fs.Stats mode property for determining a file's type. File type constant for a directory. */ - export const S_IFDIR: number; - - /** Constant for fs.Stats mode property for determining a file's type. File type constant for a character-oriented device file. */ - export const S_IFCHR: number; - - /** Constant for fs.Stats mode property for determining a file's type. File type constant for a block-oriented device file. */ - export const S_IFBLK: number; - - /** Constant for fs.Stats mode property for determining a file's type. File type constant for a FIFO/pipe. */ - export const S_IFIFO: number; - - /** Constant for fs.Stats mode property for determining a file's type. File type constant for a symbolic link. */ - export const S_IFLNK: number; - - /** Constant for fs.Stats mode property for determining a file's type. File type constant for a socket. */ - export const S_IFSOCK: number; - - // File Mode Constants - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by owner. */ - export const S_IRWXU: number; - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by owner. */ - export const S_IRUSR: number; - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by owner. */ - export const S_IWUSR: number; - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by owner. */ - export const S_IXUSR: number; - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by group. */ - export const S_IRWXG: number; - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by group. */ - export const S_IRGRP: number; - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by group. */ - export const S_IWGRP: number; - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by group. */ - export const S_IXGRP: number; - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable, writable and executable by others. */ - export const S_IRWXO: number; - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating readable by others. */ - export const S_IROTH: number; - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating writable by others. */ - export const S_IWOTH: number; - - /** Constant for fs.Stats mode property for determining access permissions for a file. File mode indicating executable by others. */ - export const S_IXOTH: number; - } - - /** Tests a user's permissions for the file specified by path. */ - export function access(path: string | Buffer, callback: (err: NodeJS.ErrnoException) => void): void; - export function access(path: string | Buffer, mode: number, callback: (err: NodeJS.ErrnoException) => void): void; - /** Synchronous version of fs.access. This throws if any accessibility checks fail, and does nothing otherwise. */ - export function accessSync(path: string | Buffer, mode?: number): void; - export function createReadStream(path: string | Buffer, options?: { - flags?: string; - encoding?: string; - fd?: number; - mode?: number; - autoClose?: boolean; - start?: number; - end?: number; - }): ReadStream; - export function createWriteStream(path: string | Buffer, options?: { - flags?: string; - encoding?: string; - fd?: number; - mode?: number; - autoClose?: boolean; - start?: number; - }): WriteStream; - export function fdatasync(fd: number, callback: Function): void; - export function fdatasyncSync(fd: number): void; -} - -declare module "path" { - - /** - * A parsed path object generated by path.parse() or consumed by path.format(). - */ - export interface ParsedPath { - /** - * The root of the path such as '/' or 'c:\' - */ - root: string; - /** - * The full directory path such as '/home/user/dir' or 'c:\path\dir' - */ - dir: string; - /** - * The file name including extension (if any) such as 'index.html' - */ - base: string; - /** - * The file extension (if any) such as '.html' - */ - ext: string; - /** - * The file name without extension (if any) such as 'index' - */ - name: string; - } - - /** - * Normalize a string path, reducing '..' and '.' parts. - * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used. - * - * @param p string path to normalize. - */ - export function normalize(p: string): string; - /** - * Join all arguments together and normalize the resulting path. - * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. - * - * @param paths string paths to join. - */ - export function join(...paths: any[]): string; - /** - * Join all arguments together and normalize the resulting path. - * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown. - * - * @param paths string paths to join. - */ - export function join(...paths: string[]): string; - /** - * The right-most parameter is considered {to}. Other parameters are considered an array of {from}. - * - * Starting from leftmost {from} paramter, resolves {to} to an absolute path. - * - * If {to} isn't already absolute, {from} arguments are prepended in right to left order, until an absolute path is found. If after using all {from} paths still no absolute path is found, the current working directory is used as well. The resulting path is normalized, and trailing slashes are removed unless the path gets resolved to the root directory. - * - * @param pathSegments string paths to join. Non-string arguments are ignored. - */ - export function resolve(...pathSegments: any[]): string; - /** - * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory. - * - * @param path path to test. - */ - export function isAbsolute(path: string): boolean; - /** - * Solve the relative path from {from} to {to}. - * At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve. - * - * @param from - * @param to - */ - export function relative(from: string, to: string): string; - /** - * Return the directory name of a path. Similar to the Unix dirname command. - * - * @param p the path to evaluate. - */ - export function dirname(p: string): string; - /** - * Return the last portion of a path. Similar to the Unix basename command. - * Often used to extract the file name from a fully qualified path. - * - * @param p the path to evaluate. - * @param ext optionally, an extension to remove from the result. - */ - export function basename(p: string, ext?: string): string; - /** - * Return the extension of the path, from the last '.' to end of string in the last portion of the path. - * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string - * - * @param p the path to evaluate. - */ - export function extname(p: string): string; - /** - * The platform-specific file separator. '\\' or '/'. - */ - export var sep: string; - /** - * The platform-specific file delimiter. ';' or ':'. - */ - export var delimiter: string; - /** - * Returns an object from a path string - the opposite of format(). - * - * @param pathString path to evaluate. - */ - export function parse(pathString: string): ParsedPath; - /** - * Returns a path string from an object - the opposite of parse(). - * - * @param pathString path to evaluate. - */ - export function format(pathObject: ParsedPath): string; - - export module posix { - export function normalize(p: string): string; - export function join(...paths: any[]): string; - export function resolve(...pathSegments: any[]): string; - export function isAbsolute(p: string): boolean; - export function relative(from: string, to: string): string; - export function dirname(p: string): string; - export function basename(p: string, ext?: string): string; - export function extname(p: string): string; - export var sep: string; - export var delimiter: string; - export function parse(p: string): ParsedPath; - export function format(pP: ParsedPath): string; - } - - export module win32 { - export function normalize(p: string): string; - export function join(...paths: any[]): string; - export function resolve(...pathSegments: any[]): string; - export function isAbsolute(p: string): boolean; - export function relative(from: string, to: string): string; - export function dirname(p: string): string; - export function basename(p: string, ext?: string): string; - export function extname(p: string): string; - export var sep: string; - export var delimiter: string; - export function parse(p: string): ParsedPath; - export function format(pP: ParsedPath): string; - } -} - -declare module "string_decoder" { - export interface NodeStringDecoder { - write(buffer: Buffer): string; - end(buffer?: Buffer): string; - } - export var StringDecoder: { - new (encoding?: string): NodeStringDecoder; - }; -} - -declare module "tls" { - import * as crypto from "crypto"; - import * as net from "net"; - import * as stream from "stream"; - - var CLIENT_RENEG_LIMIT: number; - var CLIENT_RENEG_WINDOW: number; - - export interface Certificate { - /** - * Country code. - */ - C: string; - /** - * Street. - */ - ST: string; - /** - * Locality. - */ - L: string; - /** - * Organization. - */ - O: string; - /** - * Organizational unit. - */ - OU: string; - /** - * Common name. - */ - CN: string; - } - - export interface CipherNameAndProtocol { - /** - * The cipher name. - */ - name: string; - /** - * SSL/TLS protocol version. - */ - version: string; - } - - export class TLSSocket extends stream.Duplex { - /** - * Returns the bound address, the address family name and port of the underlying socket as reported by - * the operating system. - * @returns {any} - An object with three properties, e.g. { port: 12346, family: 'IPv4', address: '127.0.0.1' }. - */ - address(): { port: number; family: string; address: string }; - /** - * A boolean that is true if the peer certificate was signed by one of the specified CAs, otherwise false. - */ - authorized: boolean; - /** - * The reason why the peer's certificate has not been verified. - * This property becomes available only when tlsSocket.authorized === false. - */ - authorizationError: Error; - /** - * Static boolean value, always true. - * May be used to distinguish TLS sockets from regular ones. - */ - encrypted: boolean; - /** - * Returns an object representing the cipher name and the SSL/TLS protocol version of the current connection. - * @returns {CipherNameAndProtocol} - Returns an object representing the cipher name - * and the SSL/TLS protocol version of the current connection. - */ - getCipher(): CipherNameAndProtocol; - /** - * Returns an object representing the peer's certificate. - * The returned object has some properties corresponding to the field of the certificate. - * If detailed argument is true the full chain with issuer property will be returned, - * if false only the top certificate without issuer property. - * If the peer does not provide a certificate, it returns null or an empty object. - * @param {boolean} detailed - If true; the full chain with issuer property will be returned. - * @returns {any} - An object representing the peer's certificate. - */ - getPeerCertificate(detailed?: boolean): { - subject: Certificate; - issuerInfo: Certificate; - issuer: Certificate; - raw: any; - valid_from: string; - valid_to: string; - fingerprint: string; - serialNumber: string; - }; - /** - * Could be used to speed up handshake establishment when reconnecting to the server. - * @returns {any} - ASN.1 encoded TLS session or undefined if none was negotiated. - */ - getSession(): any; - /** - * NOTE: Works only with client TLS sockets. - * Useful only for debugging, for session reuse provide session option to tls.connect(). - * @returns {any} - TLS session ticket or undefined if none was negotiated. - */ - getTLSTicket(): any; - /** - * The string representation of the local IP address. - */ - localAddress: string; - /** - * The numeric representation of the local port. - */ - localPort: string; - /** - * The string representation of the remote IP address. - * For example, '74.125.127.100' or '2001:4860:a005::68'. - */ - remoteAddress: string; - /** - * The string representation of the remote IP family. 'IPv4' or 'IPv6'. - */ - remoteFamily: string; - /** - * The numeric representation of the remote port. For example, 443. - */ - remotePort: number; - /** - * Initiate TLS renegotiation process. - * - * NOTE: Can be used to request peer's certificate after the secure connection has been established. - * ANOTHER NOTE: When running as the server, socket will be destroyed with an error after handshakeTimeout timeout. - * @param {TlsOptions} options - The options may contain the following fields: rejectUnauthorized, - * requestCert (See tls.createServer() for details). - * @param {Function} callback - callback(err) will be executed with null as err, once the renegotiation - * is successfully completed. - */ - renegotiate(options: TlsOptions, callback: (err: Error) => any): any; - /** - * Set maximum TLS fragment size (default and maximum value is: 16384, minimum is: 512). - * Smaller fragment size decreases buffering latency on the client: large fragments are buffered by - * the TLS layer until the entire fragment is received and its integrity is verified; - * large fragments can span multiple roundtrips, and their processing can be delayed due to packet - * loss or reordering. However, smaller fragments add extra TLS framing bytes and CPU overhead, - * which may decrease overall server throughput. - * @param {number} size - TLS fragment size (default and maximum value is: 16384, minimum is: 512). - * @returns {boolean} - Returns true on success, false otherwise. - */ - setMaxSendFragment(size: number): boolean; - - /** - * events.EventEmitter - * 1. OCSPResponse - * 2. secureConnect - **/ - addListener(event: string, listener: Function): this; - addListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; - addListener(event: "secureConnect", listener: () => void): this; - - emit(event: string, ...args: any[]): boolean; - emit(event: "OCSPResponse", response: Buffer): boolean; - emit(event: "secureConnect"): boolean; - - on(event: string, listener: Function): this; - on(event: "OCSPResponse", listener: (response: Buffer) => void): this; - on(event: "secureConnect", listener: () => void): this; - - once(event: string, listener: Function): this; - once(event: "OCSPResponse", listener: (response: Buffer) => void): this; - once(event: "secureConnect", listener: () => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; - prependListener(event: "secureConnect", listener: () => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "OCSPResponse", listener: (response: Buffer) => void): this; - prependOnceListener(event: "secureConnect", listener: () => void): this; - } - - export interface TlsOptions { - host?: string; - port?: number; - pfx?: string | Buffer[]; - key?: string | string[] | Buffer | any[]; - passphrase?: string; - cert?: string | string[] | Buffer | Buffer[]; - ca?: string | string[] | Buffer | Buffer[]; - crl?: string | string[]; - ciphers?: string; - honorCipherOrder?: boolean; - requestCert?: boolean; - rejectUnauthorized?: boolean; - NPNProtocols?: string[] | Buffer; - SNICallback?: (servername: string, cb: (err: Error, ctx: SecureContext) => any) => any; - ecdhCurve?: string; - dhparam?: string | Buffer; - handshakeTimeout?: number; - ALPNProtocols?: string[] | Buffer; - sessionTimeout?: number; - ticketKeys?: any; - sessionIdContext?: string; - secureProtocol?: string; - } - - export interface ConnectionOptions { - host?: string; - port?: number; - socket?: net.Socket; - pfx?: string | Buffer - key?: string | string[] | Buffer | Buffer[]; - passphrase?: string; - cert?: string | string[] | Buffer | Buffer[]; - ca?: string | Buffer | (string | Buffer)[]; - rejectUnauthorized?: boolean; - NPNProtocols?: (string | Buffer)[]; - servername?: string; - path?: string; - ALPNProtocols?: (string | Buffer)[]; - checkServerIdentity?: (servername: string, cert: string | Buffer | (string | Buffer)[]) => any; - secureProtocol?: string; - secureContext?: Object; - session?: Buffer; - minDHSize?: number; - } - - export interface Server extends net.Server { - close(): Server; - address(): { port: number; family: string; address: string; }; - addContext(hostName: string, credentials: { - key: string; - cert: string; - ca: string; - }): void; - maxConnections: number; - connections: number; - - /** - * events.EventEmitter - * 1. tlsClientError - * 2. newSession - * 3. OCSPRequest - * 4. resumeSession - * 5. secureConnection - **/ - addListener(event: string, listener: Function): this; - addListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; - addListener(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this; - addListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this; - addListener(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this; - addListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - - emit(event: string, ...args: any[]): boolean; - emit(event: "tlsClientError", err: Error, tlsSocket: TLSSocket): boolean; - emit(event: "newSession", sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void): boolean; - emit(event: "OCSPRequest", certificate: Buffer, issuer: Buffer, callback: Function): boolean; - emit(event: "resumeSession", sessionId: any, callback: (err: Error, sessionData: any) => void): boolean; - emit(event: "secureConnection", tlsSocket: TLSSocket): boolean; - - on(event: string, listener: Function): this; - on(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; - on(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this; - on(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this; - on(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this; - on(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - - once(event: string, listener: Function): this; - once(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; - once(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this; - once(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this; - once(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this; - once(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; - prependListener(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this; - prependListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this; - prependListener(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this; - prependListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "tlsClientError", listener: (err: Error, tlsSocket: TLSSocket) => void): this; - prependOnceListener(event: "newSession", listener: (sessionId: any, sessionData: any, callback: (err: Error, resp: Buffer) => void) => void): this; - prependOnceListener(event: "OCSPRequest", listener: (certificate: Buffer, issuer: Buffer, callback: Function) => void): this; - prependOnceListener(event: "resumeSession", listener: (sessionId: any, callback: (err: Error, sessionData: any) => void) => void): this; - prependOnceListener(event: "secureConnection", listener: (tlsSocket: TLSSocket) => void): this; - } - - export interface ClearTextStream extends stream.Duplex { - authorized: boolean; - authorizationError: Error; - getPeerCertificate(): any; - getCipher: { - name: string; - version: string; - }; - address: { - port: number; - family: string; - address: string; - }; - remoteAddress: string; - remotePort: number; - } - - export interface SecurePair { - encrypted: any; - cleartext: any; - } - - export interface SecureContextOptions { - pfx?: string | Buffer; - key?: string | Buffer; - passphrase?: string; - cert?: string | Buffer; - ca?: string | Buffer; - crl?: string | string[] - ciphers?: string; - honorCipherOrder?: boolean; - } - - export interface SecureContext { - context: any; - } - - export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) => void): Server; - export function connect(options: ConnectionOptions, secureConnectionListener?: () => void): ClearTextStream; - export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () => void): ClearTextStream; - export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () => void): ClearTextStream; - export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; - export function createSecureContext(details: SecureContextOptions): SecureContext; -} - -declare module "crypto" { - export interface Certificate { - exportChallenge(spkac: string | Buffer): Buffer; - exportPublicKey(spkac: string | Buffer): Buffer; - verifySpkac(spkac: Buffer): boolean; - } - export var Certificate: { - new (): Certificate; - (): Certificate; - } - - export var fips: boolean; - - export interface CredentialDetails { - pfx: string; - key: string; - passphrase: string; - cert: string; - ca: string | string[]; - crl: string | string[]; - ciphers: string; - } - export interface Credentials { context?: any; } - export function createCredentials(details: CredentialDetails): Credentials; - export function createHash(algorithm: string): Hash; - export function createHmac(algorithm: string, key: string | Buffer): Hmac; - - type Utf8AsciiLatin1Encoding = "utf8" | "ascii" | "latin1"; - type HexBase64Latin1Encoding = "latin1" | "hex" | "base64"; - type Utf8AsciiBinaryEncoding = "utf8" | "ascii" | "binary"; - type HexBase64BinaryEncoding = "binary" | "base64" | "hex"; - type ECDHKeyFormat = "compressed" | "uncompressed" | "hybrid"; - - export interface Hash extends NodeJS.ReadWriteStream { - update(data: string | Buffer): Hash; - update(data: string | Buffer, input_encoding: Utf8AsciiLatin1Encoding): Hash; - digest(): Buffer; - digest(encoding: HexBase64Latin1Encoding): string; - } - export interface Hmac extends NodeJS.ReadWriteStream { - update(data: string | Buffer): Hmac; - update(data: string | Buffer, input_encoding: Utf8AsciiLatin1Encoding): Hmac; - digest(): Buffer; - digest(encoding: HexBase64Latin1Encoding): string; - } - export function createCipher(algorithm: string, password: any): Cipher; - export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; - export interface Cipher extends NodeJS.ReadWriteStream { - update(data: Buffer): Buffer; - update(data: string, input_encoding: Utf8AsciiBinaryEncoding): Buffer; - update(data: Buffer, input_encoding: any, output_encoding: HexBase64BinaryEncoding): string; - update(data: string, input_encoding: Utf8AsciiBinaryEncoding, output_encoding: HexBase64BinaryEncoding): string; - final(): Buffer; - final(output_encoding: string): string; - setAutoPadding(auto_padding?: boolean): void; - getAuthTag(): Buffer; - setAAD(buffer: Buffer): void; - } - export function createDecipher(algorithm: string, password: any): Decipher; - export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; - export interface Decipher extends NodeJS.ReadWriteStream { - update(data: Buffer): Buffer; - update(data: string, input_encoding: HexBase64BinaryEncoding): Buffer; - update(data: Buffer, input_encoding: any, output_encoding: Utf8AsciiBinaryEncoding): string; - update(data: string, input_encoding: HexBase64BinaryEncoding, output_encoding: Utf8AsciiBinaryEncoding): string; - final(): Buffer; - final(output_encoding: string): string; - setAutoPadding(auto_padding?: boolean): void; - setAuthTag(tag: Buffer): void; - setAAD(buffer: Buffer): void; - } - export function createSign(algorithm: string): Signer; - export interface Signer extends NodeJS.WritableStream { - update(data: string | Buffer): Signer; - update(data: string | Buffer, input_encoding: Utf8AsciiLatin1Encoding): Signer; - sign(private_key: string | { key: string; passphrase: string }): Buffer; - sign(private_key: string | { key: string; passphrase: string }, output_format: HexBase64Latin1Encoding): string; - } - export function createVerify(algorith: string): Verify; - export interface Verify extends NodeJS.WritableStream { - update(data: string | Buffer): Verify; - update(data: string | Buffer, input_encoding: Utf8AsciiLatin1Encoding): Verify; - verify(object: string, signature: Buffer): boolean; - verify(object: string, signature: string, signature_format: HexBase64Latin1Encoding): boolean; - } - export function createDiffieHellman(prime_length: number, generator?: number): DiffieHellman; - export function createDiffieHellman(prime: Buffer): DiffieHellman; - export function createDiffieHellman(prime: string, prime_encoding: HexBase64Latin1Encoding): DiffieHellman; - export function createDiffieHellman(prime: string, prime_encoding: HexBase64Latin1Encoding, generator: number | Buffer): DiffieHellman; - export function createDiffieHellman(prime: string, prime_encoding: HexBase64Latin1Encoding, generator: string, generator_encoding: HexBase64Latin1Encoding): DiffieHellman; - export interface DiffieHellman { - generateKeys(): Buffer; - generateKeys(encoding: HexBase64Latin1Encoding): string; - computeSecret(other_public_key: Buffer): Buffer; - computeSecret(other_public_key: string, input_encoding: HexBase64Latin1Encoding): Buffer; - computeSecret(other_public_key: string, input_encoding: HexBase64Latin1Encoding, output_encoding: HexBase64Latin1Encoding): string; - getPrime(): Buffer; - getPrime(encoding: HexBase64Latin1Encoding): string; - getGenerator(): Buffer; - getGenerator(encoding: HexBase64Latin1Encoding): string; - getPublicKey(): Buffer; - getPublicKey(encoding: HexBase64Latin1Encoding): string; - getPrivateKey(): Buffer; - getPrivateKey(encoding: HexBase64Latin1Encoding): string; - setPublicKey(public_key: Buffer): void; - setPublicKey(public_key: string, encoding: string): void; - setPrivateKey(private_key: Buffer): void; - setPrivateKey(private_key: string, encoding: string): void; - verifyError: number; - } - export function getDiffieHellman(group_name: string): DiffieHellman; - export function pbkdf2(password: string | Buffer, salt: string | Buffer, iterations: number, keylen: number, digest: string, callback: (err: Error, derivedKey: Buffer) => any): void; - export function pbkdf2Sync(password: string | Buffer, salt: string | Buffer, iterations: number, keylen: number, digest: string): Buffer; - export function randomBytes(size: number): Buffer; - export function randomBytes(size: number, callback: (err: Error, buf: Buffer) => void): void; - export function pseudoRandomBytes(size: number): Buffer; - export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) => void): void; - export interface RsaPublicKey { - key: string; - padding?: number; - } - export interface RsaPrivateKey { - key: string; - passphrase?: string, - padding?: number; - } - export function publicEncrypt(public_key: string | RsaPublicKey, buffer: Buffer): Buffer - export function privateDecrypt(private_key: string | RsaPrivateKey, buffer: Buffer): Buffer - export function privateEncrypt(private_key: string | RsaPrivateKey, buffer: Buffer): Buffer - export function publicDecrypt(public_key: string | RsaPublicKey, buffer: Buffer): Buffer - export function getCiphers(): string[]; - export function getCurves(): string[]; - export function getHashes(): string[]; - export interface ECDH { - generateKeys(): Buffer; - generateKeys(encoding: HexBase64Latin1Encoding): string; - generateKeys(encoding: HexBase64Latin1Encoding, format: ECDHKeyFormat): string; - computeSecret(other_public_key: Buffer): Buffer; - computeSecret(other_public_key: string, input_encoding: HexBase64Latin1Encoding): Buffer; - computeSecret(other_public_key: string, input_encoding: HexBase64Latin1Encoding, output_encoding: HexBase64Latin1Encoding): string; - getPrivateKey(): Buffer; - getPrivateKey(encoding: HexBase64Latin1Encoding): string; - getPublicKey(): Buffer; - getPublicKey(encoding: HexBase64Latin1Encoding): string; - getPublicKey(encoding: HexBase64Latin1Encoding, format: ECDHKeyFormat): string; - setPrivateKey(private_key: Buffer): void; - setPrivateKey(private_key: string, encoding: HexBase64Latin1Encoding): void; - } - export function createECDH(curve_name: string): ECDH; - export function timingSafeEqual(a: Buffer, b: Buffer): boolean; - export var DEFAULT_ENCODING: string; -} - -declare module "stream" { - import * as events from "events"; - - class internal extends events.EventEmitter { - pipe(destination: T, options?: { end?: boolean; }): T; - } - namespace internal { - - export class Stream extends internal { } - - export interface ReadableOptions { - highWaterMark?: number; - encoding?: string; - objectMode?: boolean; - read?: (size?: number) => any; - } - - export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { - readable: boolean; - constructor(opts?: ReadableOptions); - _read(size: number): void; - read(size?: number): any; - setEncoding(encoding: string): void; - pause(): Readable; - resume(): Readable; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; - unshift(chunk: any): void; - wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; - push(chunk: any, encoding?: string): boolean; - - /** - * Event emitter - * The defined events on documents including: - * 1. close - * 2. data - * 3. end - * 4. readable - * 5. error - **/ - addListener(event: string, listener: Function): this; - addListener(event: string, listener: Function): this; - addListener(event: "close", listener: () => void): this; - addListener(event: "data", listener: (chunk: Buffer | string) => void): this; - addListener(event: "end", listener: () => void): this; - addListener(event: "readable", listener: () => void): this; - addListener(event: "error", listener: (err: Error) => void): this; - - emit(event: string, ...args: any[]): boolean; - emit(event: "close"): boolean; - emit(event: "data", chunk: Buffer | string): boolean; - emit(event: "end"): boolean; - emit(event: "readable"): boolean; - emit(event: "error", err: Error): boolean; - - on(event: string, listener: Function): this; - on(event: "close", listener: () => void): this; - on(event: "data", listener: (chunk: Buffer | string) => void): this; - on(event: "end", listener: () => void): this; - on(event: "readable", listener: () => void): this; - on(event: "error", listener: (err: Error) => void): this; - - once(event: string, listener: Function): this; - once(event: "close", listener: () => void): this; - once(event: "data", listener: (chunk: Buffer | string) => void): this; - once(event: "end", listener: () => void): this; - once(event: "readable", listener: () => void): this; - once(event: "error", listener: (err: Error) => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "close", listener: () => void): this; - prependListener(event: "data", listener: (chunk: Buffer | string) => void): this; - prependListener(event: "end", listener: () => void): this; - prependListener(event: "readable", listener: () => void): this; - prependListener(event: "error", listener: (err: Error) => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "close", listener: () => void): this; - prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this; - prependOnceListener(event: "end", listener: () => void): this; - prependOnceListener(event: "readable", listener: () => void): this; - prependOnceListener(event: "error", listener: (err: Error) => void): this; - - removeListener(event: string, listener: Function): this; - removeListener(event: "close", listener: () => void): this; - removeListener(event: "data", listener: (chunk: Buffer | string) => void): this; - removeListener(event: "end", listener: () => void): this; - removeListener(event: "readable", listener: () => void): this; - removeListener(event: "error", listener: (err: Error) => void): this; - } - - export interface WritableOptions { - highWaterMark?: number; - decodeStrings?: boolean; - objectMode?: boolean; - write?: (chunk: string | Buffer, encoding: string, callback: Function) => any; - writev?: (chunks: { chunk: string | Buffer, encoding: string }[], callback: Function) => any; - } - - export class Writable extends events.EventEmitter implements NodeJS.WritableStream { - writable: boolean; - constructor(opts?: WritableOptions); - _write(chunk: any, encoding: string, callback: Function): void; - write(chunk: any, cb?: Function): boolean; - write(chunk: any, encoding?: string, cb?: Function): boolean; - end(): void; - end(chunk: any, cb?: Function): void; - end(chunk: any, encoding?: string, cb?: Function): void; - - /** - * Event emitter - * The defined events on documents including: - * 1. close - * 2. drain - * 3. error - * 4. finish - * 5. pipe - * 6. unpipe - **/ - addListener(event: string, listener: Function): this; - addListener(event: "close", listener: () => void): this; - addListener(event: "drain", listener: () => void): this; - addListener(event: "error", listener: (err: Error) => void): this; - addListener(event: "finish", listener: () => void): this; - addListener(event: "pipe", listener: (src: Readable) => void): this; - addListener(event: "unpipe", listener: (src: Readable) => void): this; - - emit(event: string, ...args: any[]): boolean; - emit(event: "close"): boolean; - emit(event: "drain", chunk: Buffer | string): boolean; - emit(event: "error", err: Error): boolean; - emit(event: "finish"): boolean; - emit(event: "pipe", src: Readable): boolean; - emit(event: "unpipe", src: Readable): boolean; - - on(event: string, listener: Function): this; - on(event: "close", listener: () => void): this; - on(event: "drain", listener: () => void): this; - on(event: "error", listener: (err: Error) => void): this; - on(event: "finish", listener: () => void): this; - on(event: "pipe", listener: (src: Readable) => void): this; - on(event: "unpipe", listener: (src: Readable) => void): this; - - once(event: string, listener: Function): this; - once(event: "close", listener: () => void): this; - once(event: "drain", listener: () => void): this; - once(event: "error", listener: (err: Error) => void): this; - once(event: "finish", listener: () => void): this; - once(event: "pipe", listener: (src: Readable) => void): this; - once(event: "unpipe", listener: (src: Readable) => void): this; - - prependListener(event: string, listener: Function): this; - prependListener(event: "close", listener: () => void): this; - prependListener(event: "drain", listener: () => void): this; - prependListener(event: "error", listener: (err: Error) => void): this; - prependListener(event: "finish", listener: () => void): this; - prependListener(event: "pipe", listener: (src: Readable) => void): this; - prependListener(event: "unpipe", listener: (src: Readable) => void): this; - - prependOnceListener(event: string, listener: Function): this; - prependOnceListener(event: "close", listener: () => void): this; - prependOnceListener(event: "drain", listener: () => void): this; - prependOnceListener(event: "error", listener: (err: Error) => void): this; - prependOnceListener(event: "finish", listener: () => void): this; - prependOnceListener(event: "pipe", listener: (src: Readable) => void): this; - prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this; - - removeListener(event: string, listener: Function): this; - removeListener(event: "close", listener: () => void): this; - removeListener(event: "drain", listener: () => void): this; - removeListener(event: "error", listener: (err: Error) => void): this; - removeListener(event: "finish", listener: () => void): this; - removeListener(event: "pipe", listener: (src: Readable) => void): this; - removeListener(event: "unpipe", listener: (src: Readable) => void): this; - } - - export interface DuplexOptions extends ReadableOptions, WritableOptions { - allowHalfOpen?: boolean; - readableObjectMode?: boolean; - writableObjectMode?: boolean; - } - - // Note: Duplex extends both Readable and Writable. - export class Duplex extends Readable implements NodeJS.ReadWriteStream { - // Readable - pause(): Duplex; - resume(): Duplex; - // Writeable - writable: boolean; - constructor(opts?: DuplexOptions); - _write(chunk: any, encoding: string, callback: Function): void; - write(chunk: any, cb?: Function): boolean; - write(chunk: any, encoding?: string, cb?: Function): boolean; - end(): void; - end(chunk: any, cb?: Function): void; - end(chunk: any, encoding?: string, cb?: Function): void; - } - - export interface TransformOptions extends DuplexOptions { - transform?: (chunk: string | Buffer, encoding: string, callback: Function) => any; - flush?: (callback: Function) => any; - } - - // Note: Transform lacks the _read and _write methods of Readable/Writable. - export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { - readable: boolean; - writable: boolean; - constructor(opts?: TransformOptions); - _transform(chunk: any, encoding: string, callback: Function): void; - _flush(callback: Function): void; - read(size?: number): any; - setEncoding(encoding: string): void; - pause(): Transform; - resume(): Transform; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; - unshift(chunk: any): void; - wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; - push(chunk: any, encoding?: string): boolean; - write(chunk: any, cb?: Function): boolean; - write(chunk: any, encoding?: string, cb?: Function): boolean; - end(): void; - end(chunk: any, cb?: Function): void; - end(chunk: any, encoding?: string, cb?: Function): void; - } - - export class PassThrough extends Transform { } - } - - export = internal; -} - -declare module "util" { - export interface InspectOptions { - showHidden?: boolean; - depth?: number; - colors?: boolean; - customInspect?: boolean; - } - - export function format(format: any, ...param: any[]): string; - export function debug(string: string): void; - export function error(...param: any[]): void; - export function puts(...param: any[]): void; - export function print(...param: any[]): void; - export function log(string: string): void; - export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; - export function inspect(object: any, options: InspectOptions): string; - export function isArray(object: any): boolean; - export function isRegExp(object: any): boolean; - export function isDate(object: any): boolean; - export function isError(object: any): boolean; - export function inherits(constructor: any, superConstructor: any): void; - export function debuglog(key: string): (msg: string, ...param: any[]) => void; - export function isBoolean(object: any): boolean; - export function isBuffer(object: any): boolean; - export function isFunction(object: any): boolean; - export function isNull(object: any): boolean; - export function isNullOrUndefined(object: any): boolean; - export function isNumber(object: any): boolean; - export function isObject(object: any): boolean; - export function isPrimitive(object: any): boolean; - export function isString(object: any): boolean; - export function isSymbol(object: any): boolean; - export function isUndefined(object: any): boolean; - export function deprecate(fn: Function, message: string): Function; -} - -declare module "assert" { - function internal(value: any, message?: string): void; - namespace internal { - export class AssertionError implements Error { - name: string; - message: string; - actual: any; - expected: any; - operator: string; - generatedMessage: boolean; - - constructor(options?: { - message?: string; actual?: any; expected?: any; - operator?: string; stackStartFunction?: Function - }); - } - - export function fail(actual: any, expected: any, message: string, operator: string): void; - export function ok(value: any, message?: string): void; - export function equal(actual: any, expected: any, message?: string): void; - export function notEqual(actual: any, expected: any, message?: string): void; - export function deepEqual(actual: any, expected: any, message?: string): void; - export function notDeepEqual(acutal: any, expected: any, message?: string): void; - export function strictEqual(actual: any, expected: any, message?: string): void; - export function notStrictEqual(actual: any, expected: any, message?: string): void; - export function deepStrictEqual(actual: any, expected: any, message?: string): void; - export function notDeepStrictEqual(actual: any, expected: any, message?: string): void; - export var throws: { - (block: Function, message?: string): void; - (block: Function, error: Function, message?: string): void; - (block: Function, error: RegExp, message?: string): void; - (block: Function, error: (err: any) => boolean, message?: string): void; - }; - - export var doesNotThrow: { - (block: Function, message?: string): void; - (block: Function, error: Function, message?: string): void; - (block: Function, error: RegExp, message?: string): void; - (block: Function, error: (err: any) => boolean, message?: string): void; - }; - - export function ifError(value: any): void; - } - - export = internal; -} - -declare module "tty" { - import * as net from "net"; - - export function isatty(fd: number): boolean; - export interface ReadStream extends net.Socket { - isRaw: boolean; - setRawMode(mode: boolean): void; - isTTY: boolean; - } - export interface WriteStream extends net.Socket { - columns: number; - rows: number; - isTTY: boolean; - } -} - -declare module "domain" { - import * as events from "events"; - - export class Domain extends events.EventEmitter implements NodeJS.Domain { - run(fn: Function): void; - add(emitter: events.EventEmitter): void; - remove(emitter: events.EventEmitter): void; - bind(cb: (err: Error, data: any) => any): any; - intercept(cb: (data: any) => any): any; - dispose(): void; - members: any[]; - enter(): void; - exit(): void; - } - - export function create(): Domain; -} - -declare module "constants" { - export var E2BIG: number; - export var EACCES: number; - export var EADDRINUSE: number; - export var EADDRNOTAVAIL: number; - export var EAFNOSUPPORT: number; - export var EAGAIN: number; - export var EALREADY: number; - export var EBADF: number; - export var EBADMSG: number; - export var EBUSY: number; - export var ECANCELED: number; - export var ECHILD: number; - export var ECONNABORTED: number; - export var ECONNREFUSED: number; - export var ECONNRESET: number; - export var EDEADLK: number; - export var EDESTADDRREQ: number; - export var EDOM: number; - export var EEXIST: number; - export var EFAULT: number; - export var EFBIG: number; - export var EHOSTUNREACH: number; - export var EIDRM: number; - export var EILSEQ: number; - export var EINPROGRESS: number; - export var EINTR: number; - export var EINVAL: number; - export var EIO: number; - export var EISCONN: number; - export var EISDIR: number; - export var ELOOP: number; - export var EMFILE: number; - export var EMLINK: number; - export var EMSGSIZE: number; - export var ENAMETOOLONG: number; - export var ENETDOWN: number; - export var ENETRESET: number; - export var ENETUNREACH: number; - export var ENFILE: number; - export var ENOBUFS: number; - export var ENODATA: number; - export var ENODEV: number; - export var ENOENT: number; - export var ENOEXEC: number; - export var ENOLCK: number; - export var ENOLINK: number; - export var ENOMEM: number; - export var ENOMSG: number; - export var ENOPROTOOPT: number; - export var ENOSPC: number; - export var ENOSR: number; - export var ENOSTR: number; - export var ENOSYS: number; - export var ENOTCONN: number; - export var ENOTDIR: number; - export var ENOTEMPTY: number; - export var ENOTSOCK: number; - export var ENOTSUP: number; - export var ENOTTY: number; - export var ENXIO: number; - export var EOPNOTSUPP: number; - export var EOVERFLOW: number; - export var EPERM: number; - export var EPIPE: number; - export var EPROTO: number; - export var EPROTONOSUPPORT: number; - export var EPROTOTYPE: number; - export var ERANGE: number; - export var EROFS: number; - export var ESPIPE: number; - export var ESRCH: number; - export var ETIME: number; - export var ETIMEDOUT: number; - export var ETXTBSY: number; - export var EWOULDBLOCK: number; - export var EXDEV: number; - export var WSAEINTR: number; - export var WSAEBADF: number; - export var WSAEACCES: number; - export var WSAEFAULT: number; - export var WSAEINVAL: number; - export var WSAEMFILE: number; - export var WSAEWOULDBLOCK: number; - export var WSAEINPROGRESS: number; - export var WSAEALREADY: number; - export var WSAENOTSOCK: number; - export var WSAEDESTADDRREQ: number; - export var WSAEMSGSIZE: number; - export var WSAEPROTOTYPE: number; - export var WSAENOPROTOOPT: number; - export var WSAEPROTONOSUPPORT: number; - export var WSAESOCKTNOSUPPORT: number; - export var WSAEOPNOTSUPP: number; - export var WSAEPFNOSUPPORT: number; - export var WSAEAFNOSUPPORT: number; - export var WSAEADDRINUSE: number; - export var WSAEADDRNOTAVAIL: number; - export var WSAENETDOWN: number; - export var WSAENETUNREACH: number; - export var WSAENETRESET: number; - export var WSAECONNABORTED: number; - export var WSAECONNRESET: number; - export var WSAENOBUFS: number; - export var WSAEISCONN: number; - export var WSAENOTCONN: number; - export var WSAESHUTDOWN: number; - export var WSAETOOMANYREFS: number; - export var WSAETIMEDOUT: number; - export var WSAECONNREFUSED: number; - export var WSAELOOP: number; - export var WSAENAMETOOLONG: number; - export var WSAEHOSTDOWN: number; - export var WSAEHOSTUNREACH: number; - export var WSAENOTEMPTY: number; - export var WSAEPROCLIM: number; - export var WSAEUSERS: number; - export var WSAEDQUOT: number; - export var WSAESTALE: number; - export var WSAEREMOTE: number; - export var WSASYSNOTREADY: number; - export var WSAVERNOTSUPPORTED: number; - export var WSANOTINITIALISED: number; - export var WSAEDISCON: number; - export var WSAENOMORE: number; - export var WSAECANCELLED: number; - export var WSAEINVALIDPROCTABLE: number; - export var WSAEINVALIDPROVIDER: number; - export var WSAEPROVIDERFAILEDINIT: number; - export var WSASYSCALLFAILURE: number; - export var WSASERVICE_NOT_FOUND: number; - export var WSATYPE_NOT_FOUND: number; - export var WSA_E_NO_MORE: number; - export var WSA_E_CANCELLED: number; - export var WSAEREFUSED: number; - export var SIGHUP: number; - export var SIGINT: number; - export var SIGILL: number; - export var SIGABRT: number; - export var SIGFPE: number; - export var SIGKILL: number; - export var SIGSEGV: number; - export var SIGTERM: number; - export var SIGBREAK: number; - export var SIGWINCH: number; - export var SSL_OP_ALL: number; - export var SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: number; - export var SSL_OP_CIPHER_SERVER_PREFERENCE: number; - export var SSL_OP_CISCO_ANYCONNECT: number; - export var SSL_OP_COOKIE_EXCHANGE: number; - export var SSL_OP_CRYPTOPRO_TLSEXT_BUG: number; - export var SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: number; - export var SSL_OP_EPHEMERAL_RSA: number; - export var SSL_OP_LEGACY_SERVER_CONNECT: number; - export var SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: number; - export var SSL_OP_MICROSOFT_SESS_ID_BUG: number; - export var SSL_OP_MSIE_SSLV2_RSA_PADDING: number; - export var SSL_OP_NETSCAPE_CA_DN_BUG: number; - export var SSL_OP_NETSCAPE_CHALLENGE_BUG: number; - export var SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG: number; - export var SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: number; - export var SSL_OP_NO_COMPRESSION: number; - export var SSL_OP_NO_QUERY_MTU: number; - export var SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: number; - export var SSL_OP_NO_SSLv2: number; - export var SSL_OP_NO_SSLv3: number; - export var SSL_OP_NO_TICKET: number; - export var SSL_OP_NO_TLSv1: number; - export var SSL_OP_NO_TLSv1_1: number; - export var SSL_OP_NO_TLSv1_2: number; - export var SSL_OP_PKCS1_CHECK_1: number; - export var SSL_OP_PKCS1_CHECK_2: number; - export var SSL_OP_SINGLE_DH_USE: number; - export var SSL_OP_SINGLE_ECDH_USE: number; - export var SSL_OP_SSLEAY_080_CLIENT_DH_BUG: number; - export var SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG: number; - export var SSL_OP_TLS_BLOCK_PADDING_BUG: number; - export var SSL_OP_TLS_D5_BUG: number; - export var SSL_OP_TLS_ROLLBACK_BUG: number; - export var ENGINE_METHOD_DSA: number; - export var ENGINE_METHOD_DH: number; - export var ENGINE_METHOD_RAND: number; - export var ENGINE_METHOD_ECDH: number; - export var ENGINE_METHOD_ECDSA: number; - export var ENGINE_METHOD_CIPHERS: number; - export var ENGINE_METHOD_DIGESTS: number; - export var ENGINE_METHOD_STORE: number; - export var ENGINE_METHOD_PKEY_METHS: number; - export var ENGINE_METHOD_PKEY_ASN1_METHS: number; - export var ENGINE_METHOD_ALL: number; - export var ENGINE_METHOD_NONE: number; - export var DH_CHECK_P_NOT_SAFE_PRIME: number; - export var DH_CHECK_P_NOT_PRIME: number; - export var DH_UNABLE_TO_CHECK_GENERATOR: number; - export var DH_NOT_SUITABLE_GENERATOR: number; - export var NPN_ENABLED: number; - export var RSA_PKCS1_PADDING: number; - export var RSA_SSLV23_PADDING: number; - export var RSA_NO_PADDING: number; - export var RSA_PKCS1_OAEP_PADDING: number; - export var RSA_X931_PADDING: number; - export var RSA_PKCS1_PSS_PADDING: number; - export var POINT_CONVERSION_COMPRESSED: number; - export var POINT_CONVERSION_UNCOMPRESSED: number; - export var POINT_CONVERSION_HYBRID: number; - export var O_RDONLY: number; - export var O_WRONLY: number; - export var O_RDWR: number; - export var S_IFMT: number; - export var S_IFREG: number; - export var S_IFDIR: number; - export var S_IFCHR: number; - export var S_IFBLK: number; - export var S_IFIFO: number; - export var S_IFSOCK: number; - export var S_IRWXU: number; - export var S_IRUSR: number; - export var S_IWUSR: number; - export var S_IXUSR: number; - export var S_IRWXG: number; - export var S_IRGRP: number; - export var S_IWGRP: number; - export var S_IXGRP: number; - export var S_IRWXO: number; - export var S_IROTH: number; - export var S_IWOTH: number; - export var S_IXOTH: number; - export var S_IFLNK: number; - export var O_CREAT: number; - export var O_EXCL: number; - export var O_NOCTTY: number; - export var O_DIRECTORY: number; - export var O_NOATIME: number; - export var O_NOFOLLOW: number; - export var O_SYNC: number; - export var O_SYMLINK: number; - export var O_DIRECT: number; - export var O_NONBLOCK: number; - export var O_TRUNC: number; - export var O_APPEND: number; - export var F_OK: number; - export var R_OK: number; - export var W_OK: number; - export var X_OK: number; - export var UV_UDP_REUSEADDR: number; - export var SIGQUIT: number; - export var SIGTRAP: number; - export var SIGIOT: number; - export var SIGBUS: number; - export var SIGUSR1: number; - export var SIGUSR2: number; - export var SIGPIPE: number; - export var SIGALRM: number; - export var SIGCHLD: number; - export var SIGSTKFLT: number; - export var SIGCONT: number; - export var SIGSTOP: number; - export var SIGTSTP: number; - export var SIGTTIN: number; - export var SIGTTOU: number; - export var SIGURG: number; - export var SIGXCPU: number; - export var SIGXFSZ: number; - export var SIGVTALRM: number; - export var SIGPROF: number; - export var SIGIO: number; - export var SIGPOLL: number; - export var SIGPWR: number; - export var SIGSYS: number; - export var SIGUNUSED: number; - export var defaultCoreCipherList: string; - export var defaultCipherList: string; - export var ENGINE_METHOD_RSA: number; - export var ALPN_ENABLED: number; -} - -declare module "process" { - export = process; -} - -declare module "v8" { - interface HeapSpaceInfo { - space_name: string; - space_size: number; - space_used_size: number; - space_available_size: number; - physical_space_size: number; - } - export function getHeapStatistics(): { total_heap_size: number, total_heap_size_executable: number, total_physical_size: number, total_avaialble_size: number, used_heap_size: number, heap_size_limit: number }; - export function getHeapSpaceStatistics(): HeapSpaceInfo[]; - export function setFlagsFromString(flags: string): void; -} - -declare module "timers" { - export function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; - export function clearTimeout(timeoutId: NodeJS.Timer): void; - export function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; - export function clearInterval(intervalId: NodeJS.Timer): void; - export function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; - export function clearImmediate(immediateId: any): void; -} - -declare module "console" { - export = console; -} diff --git a/typings/optimist/optimist.d.ts b/typings/optimist/optimist.d.ts deleted file mode 100644 index 12a51be1d6f..00000000000 --- a/typings/optimist/optimist.d.ts +++ /dev/null @@ -1,89 +0,0 @@ -// Type definitions for optimist -// Project: https://github.com/substack/node-optimist -// Definitions by: Carlos Ballesteros Velasco , Christopher Brown -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare module "optimist" { - - namespace optimist { - interface Opt { - alias?: string | string[]; - default?: any; - demand?: string | number | string[]; - describe?: string; - type?: string; - } - - interface Parser { - /** Implicitly use process.argv array to construct the argv object */ - argv: any; - /** Pass in the process.argv yourself */ - (args: string[]): any; - /** Use .parse() to do the same thing as treating optimist as a function */ - parse(args: string[]): any; - - // The types below follow the order and documentation of https://github.com/substack/node-optimist - - /** Set key names as equivalent such that updates to a key will propagate to aliases and vice-versa. */ - alias(key: string, alias: string | string[]): Parser; - /** Take an object that maps keys to aliases. */ - alias(aliases: {[index: string]: string | string[]}): Parser; - - /** Set argv[key] to value if no option was specified on process.argv */ - default(key: string, value: any): Parser; - /** Take an object that maps keys to default values */ - default(defaults: {[index: string]: any}): Parser; - - /** Show the usage information and exit if key wasn't specified in process.argv */ - demand(key: string): Parser; - /** Demand at least as many non-option arguments, which show up in argv._ */ - demand(key: number): Parser; - /** Demand each element in key */ - demand(key: string[]): Parser; - - /** Describe a key for the generated usage information */ - describe(key: string, desc: string): Parser; - /** Take an object that maps keys to descriptions */ - describe(descriptions: {[index: string]: string}): Parser; - - /** Instead of chaining together, e.g. optimist.alias().demand().default()..., - you can specify keys in opt for each of the chainable methods. */ - options(key: string, opt: Opt): Parser; - /** Take an object that maps keys to opt parameters */ - options(options: {[index: string]: Opt}): Parser; - - /** Set a usage message to show which commands to use. Inside message, - the string $0 will get interpolated to the current script name or node - command for the present script similar to how $0 works in bash or perl. */ - usage(message: string): Parser; - - /** Check that certain conditions are met in the provided arguments. If fn - throws or returns false, show the thrown error, usage information, and exit. - */ - check(fn: (argv: any) => any): Parser; - - /** Interpret key as a boolean. If a non-flag option follows key in process.argv, - that string won't get set as the value of key. If key never shows up as a - flag in process.arguments, argv[key] will be false. */ - boolean(key: string): Parser; - /** Interpret all the elements as booleans. */ - boolean(key: string[]): Parser; - - /** Tell the parser logic not to interpret key as a number or boolean. This can be useful if you need to preserve leading zeros in an input. */ - string(key: string): Parser; - /** Interpret all the elements as strings */ - string(key: string[]): Parser; - - /** Format usage output to wrap at columns many columns. */ - wrap(columns: number): Parser; - - /** Return the generated usage string. */ - help(): string; - /** Print the usage data using fn for printing (defaults to console.error). */ - showHelp(fn?: (message: string) => void): void; - } - } - - var optimist: optimist.Parser; - export = optimist; -} diff --git a/typings/tsd.d.ts b/typings/tsd.d.ts deleted file mode 100644 index 2781e558d17..00000000000 --- a/typings/tsd.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// -/// -/// -/// diff --git a/typings/underscore.string/underscore.string.d.ts b/typings/underscore.string/underscore.string.d.ts deleted file mode 100644 index ef4033d6836..00000000000 --- a/typings/underscore.string/underscore.string.d.ts +++ /dev/null @@ -1,580 +0,0 @@ -// Type definitions for underscore.string -// Project: https://github.com/epeli/underscore.string -// Definitions by: Ry Racherbaumer -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - -interface UnderscoreStatic { - str: UnderscoreStringStatic; - string: UnderscoreStringStatic; -} - -declare var s : UnderscoreStringStatic; - -interface UnderscoreStringStatic extends UnderscoreStringStaticExports { - /** - * Tests if string contains a substring. - * ('foobar', 'ob') => true - * @param str - * @param needle - */ - include(str: string, needle: string): boolean; - - /** - * Tests if string contains a substring. - * ('foobar', 'ob') => true - * @param str - * @param needle - */ - contains(str: string, needle: string): boolean; - - /** - * Return reversed string. - * ('foobar') => 'raboof' - * @param str - */ - reverse(str: string): string; -} - -/** - * Functions exported for mixing with underscore object. - * - * Usage: - * _.mixin(_.string.exports()); - * interface UnderscoreStatic extends UnderscoreStringStaticExports { } - */ -interface UnderscoreStringStaticExports { - - exports(): UnderscoreStringStaticExports; - - /** - * Determine if a string is 'blank.' - * @param str - */ - isBlank(str: string): boolean; - - /** - * Removes all html tags from string. - * @param str - */ - stripTags(str: string): string; - - /** - * Converts first letter of the string to uppercase. - * ('foo Bar') => 'Foo Bar' - * @param str - */ - capitalize(str: string): string; - - /** - * Converts first letter of the string to lowercase. - * ('Foo Bar') => 'foo Bar' - * @param str - */ - decapitalize(str: string): string; - - /** - * Chop a string into pieces. - * ('whitespace', 3) => ['whi','tes','pac','e'] - * @param str String to chop - * @param step Size of the pieces - */ - chop(str: string, step: number): any[]; - - /** - * Compress some whitespaces to one. - * (' foo bar ') => 'foo bar' - * @param str - */ - clean(str: string): string; - - /** - * Count occurences of a sub string. - * ('Hello world', 'l') => 3 - * @param str - * @param substr - */ - count(str: string, substr: string): number; - - /** - * Convert string to an array of characters. - * ('Hello') => ['H','e','l','l','o'] - * @param str - */ - chars(str: string): any[]; - - /** - * Returns a copy of the string in which all the case-based characters have had their case swapped. - * ('hELLO') => 'Hello' - * @param str - */ - swapCase(str: string): string; - - /** - * Converts HTML special characters to their entity equivalents. - * ('
Blah blah blah
') => '<div>Blah blah blah</div>' - * @param str - */ - escapeHTML(str: string): string; - - /** - * Converts entity characters to HTML equivalents. - * ('<div>Blah blah blah</div>') => '
Blah blah blah
' - * @param str - */ - unescapeHTML(str: string): string; - - /** - * Escape a string for use in a regular expression. - * @param str - */ - escapeRegExp(str: string): string; - - /** - * Splice a string like an array. - * @param str - * @param i - * @param howmany - * @param substr - */ - splice(str: string, i: number, howmany: number, substr?: string): string; - - /** - * Insert a string at index. - * @param str - * @param i - * @param substr - */ - insert(str: string, i: number, substr: string): string; - - /** - * Joins strings together with given separator. - * (' ', 'foo', 'bar') => 'foo bar' - * @param separator - * @param args - */ - join(separator: string, ...args: string[]): string; - - /** - * Split string by newlines character. - * ('Hello\nWorld') => ['Hello', 'World'] - * @param str - */ - lines(str: string): any[]; - - /** - * Checks if string starts with another string. - * ('image.gif', 'image') => true - * @param str - * @param starts - */ - startsWith(str: string, starts: string): boolean; - - /** - * Checks if string ends with another string. - * ('image.gif', 'gif') => true - * @param value - * @param starts - */ - endsWith(value: string, starts: string): boolean; - - /** - * Returns the successor to passed string. - * ('a') => 'b' - * @param str - */ - succ(str: string): string; - - /** - * Capitalize first letter of every word in the string. - * ('my name is epeli') => 'My Name Is Epeli' - * @param str - */ - titleize(str: string): string; - - /** - * Converts underscored or dasherized string to a camelized one. - * ('-moz-transform') => 'MozTransform' - * @param str - */ - camelize(str: string): string; - - /** - * Converts a camelized or dasherized string into an underscored one. - * ('MozTransform') => 'moz_transform' - * @param str - */ - underscored(str: string): string; - - /** - * Converts a underscored or camelized string into an dasherized one. - * ('MozTransform') => '-moz-transform' - * @param str - */ - dasherize(str: string): string; - - /** - * Converts string to camelized class name. - * ('some_class_name') => 'SomeClassName' - * @param str - */ - classify(str: string): string; - - /** - * Converts an underscored, camelized, or dasherized string into a humanized one. - * Also removes beginning and ending whitespace, and removes the postfix '_id'. - * (' capitalize dash-CamelCase_underscore trim ') => 'Capitalize dash camel case underscore trim' - * @param str - */ - humanize(str: string): string; - - /** - * Trims defined characters from begining and ending of the string. - * Defaults to whitespace characters. - * (' foobar ') => 'foobar' - * ('_-foobar-_', '_-') => 'foobar' - * @param str - * @param characters - */ - trim(str: string, characters?: string): string; - - /** - * Trims defined characters from begining and ending of the string. - * Defaults to whitespace characters. - * (' foobar ') => 'foobar' - * ('_-foobar-_', '_-') => 'foobar' - * @param str - * @param characters - */ - strip(str: string, characters?: string): string; - - /** - * Left trim. Similar to trim, but only for left side. - * @param str - * @param characters - */ - ltrim(str: string, characters?: string): string; - - /** - * Left trim. Similar to trim, but only for left side. - * @param str - * @param characters - */ - lstrip(str: string, characters?: string): string; - - /** - * Right trim. Similar to trim, but only for right side. - * @param str - * @param characters - */ - rtrim(str: string, characters?: string): string; - - /** - * Right trim. Similar to trim, but only for right side. - * @param str - * @param characters - */ - rstrip(str: string, characters?: string): string; - - /** - * Truncate string to specified length. - * ('Hello world').truncate(5) => 'Hello...' - * ('Hello').truncate(10) => 'Hello' - * @param str - * @param length - * @param truncateStr - */ - truncate(str: string, length: number, truncateStr?: string): string; - - /** - * Elegant version of truncate. - * Makes sure the pruned string does not exceed the original length. - * Avoid half-chopped words when truncating. - * ('Hello, cruel world', 15) => 'Hello, cruel...' - * @param str - * @param length - * @param pruneStr - */ - prune(str: string, length: number, pruneStr?: string): string; - - /** - * Split string by delimiter (String or RegExp). - * /\s+/ by default. - * (' I love you ') => ['I','love','you'] - * ('I_love_you', '_') => ['I','love','you'] - * @param str - * @param delimiter - */ - words(str: string): string[]; - - /** - * Split string by delimiter (String or RegExp). - * /\s+/ by default. - * (' I love you ') => ['I','love','you'] - * ('I_love_you', '_') => ['I','love','you'] - * @param str - * @param delimiter - */ - words(str: string, delimiter: string): string[]; - - /** - * Split string by delimiter (String or RegExp). - * /\s+/ by default. - * (' I love you ') => ['I','love','you'] - * ('I_love_you', '_') => ['I','love','you'] - * @param str - * @param delimiter - */ - words(str: string, delimiter: RegExp): string[]; - - /** - * Pads a string with characters until the total string length is equal to the passed length parameter. - * By default, pads on the left with the space char (' '). - * padStr is truncated to a single character if necessary. - * ('1', 8) => ' 1' - * ('1', 8, '0') => '00000001' - * ('1', 8, '0', 'right') => '10000000' - * ('1', 8, '0', 'both') => '00001000' - * ('1', 8, 'bleepblorp', 'both') => 'bbbb1bbb' - * @param str - * @param length - * @param padStr - * @param type - */ - pad(str: string, length: number, padStr?:string, type?: string): string; - - /** - * Left-pad a string. - * Alias for pad(str, length, padStr, 'left') - * ('1', 8, '0') => '00000001' - * @param str - * @param length - * @param padStr - */ - lpad(str: string, length: number, padStr?: string): string; - - /** - * Left-pad a string. - * Alias for pad(str, length, padStr, 'left') - * ('1', 8, '0') => '00000001' - * @param str - * @param length - * @param padStr - */ - rjust(str: string, length: number, padStr?: string): string; - - /** - * Right-pad a string. - * Alias for pad(str, length, padStr, 'right') - * ('1', 8, '0') => '10000000' - * @param str - * @param length - * @param padStr - */ - rpad(str: string, length: number, padStr?: string): string; - - /** - * Right-pad a string. - * Alias for pad(str, length, padStr, 'right') - * ('1', 8, '0') => '10000000' - * @param str - * @param length - * @param padStr - */ - ljust(str: string, length: number, padStr?: string): string; - - /** - * Left/right-pad a string. - * Alias for pad(str, length, padStr, 'both') - * ('1', 8, '0') => '00001000' - * @param str - * @param length - * @param padStr - */ - lrpad(str: string, length: number, padStr?: string): string; - - /** - * Left/right-pad a string. - * Alias for pad(str, length, padStr, 'both') - * ('1', 8, '0') => '00001000' - * @param str - * @param length - * @param padStr - */ - center(str: string, length: number, padStr?: string): string; - - /** - * C like string formatting. - * _.sprintf('%.1f', 1.17) => '1.2' - * @param format - * @param args - */ - sprintf(format: string, ...args: any[]): string; - - /** - * Parse string to number. - * Returns NaN if string can't be parsed to number. - * ('2.556').toNumber() => 3 - * ('2.556').toNumber(1) => 2.6 - * @param str - * @param decimals - */ - toNumber(str: string, decimals?: number): number; - - /** - * Formats the numbers. - * (1000, 2) => '1,000.00' - * (123456789.123, 5, '.', ',') => '123,456,789.12300' - * @param number - * @param dec - * @param dsep - * @param tsep - */ - numberFormat(number: number, dec?: number, dsep?: string, tsep?: string): string; - - /** - * Searches a string from left to right for a pattern. - * Returns a substring consisting of the characters in the string that are to the right of the pattern. - * If no match found, returns entire string. - * ('This_is_a_test_string').strRight('_') => 'is_a_test_string' - * @param str - * @param sep - */ - strRight(str: string, sep: string): string; - - /** - * Searches a string from right to left for a pattern. - * Returns a substring consisting of the characters in the string that are to the right of the pattern. - * If no match found, returns entire string. - * ('This_is_a_test_string').strRightBack('_') => 'string' - * @param str - * @param sep - */ - strRightBack(str: string, sep: string): string; - - /** - * Searches a string from left to right for a pattern. - * Returns a substring consisting of the characters in the string that are to the left of the pattern. - * If no match found, returns entire string. - * ('This_is_a_test_string').strLeft('_') => 'This' - * @param str - * @param sep - */ - strLeft(str: string, sep: string): string; - - /** - * Searches a string from right to left for a pattern. - * Returns a substring consisting of the characters in the string that are to the left of the pattern. - * If no match found, returns entire string. - * ('This_is_a_test_string').strLeftBack('_') => 'This_is_a_test' - * @param str - * @param sep - */ - strLeftBack(str: string, sep: string): string; - - /** - * Join an array into a human readable sentence. - * (['jQuery', 'Mootools', 'Prototype']) => 'jQuery, Mootools and Prototype' - * (['jQuery', 'Mootools', 'Prototype'], ', ', ' unt ') => 'jQuery, Mootools unt Prototype' - * @param array - * @param separator - * @param lastSeparator - * @param serial - */ - toSentence(array: any[], separator?: string, lastSeparator?: string, serial?: boolean): string; - - /** - * The same as toSentence, but uses ', ' as default for lastSeparator. - * @param array - * @param separator - * @param lastSeparator - */ - toSentenceSerial(array: any[], separator?: string, lastSeparator?: string): string; - - /** - * Transform text into a URL slug. Replaces whitespaces, accentuated, and special characters with a dash. - * ('Un éléphant à l'orée du bois') => 'un-elephant-a-loree-du-bois' - * @param str - */ - slugify(str: string): string; - - /** - * Surround a string with another string. - * ('foo', 'ab') => 'abfooab' - * @param str - * @param wrapper - */ - surround(str: string, wrapper: string): string; - - /** - * Quotes a string. - * quoteChar defaults to " - * ('foo') => '"foo"' - * @param str - */ - quote(str: string, quoteChar?: string): string; - - /** - * Quotes a string. - * quoteChar defaults to " - * ('foo') => '"foo"' - * @param str - */ - q(str: string, quoteChar?: string): string; - - /** - * Unquotes a string. - * quoteChar defaults to " - * ('"foo"') => 'foo' - * ("'foo'", "'") => 'foo' - * @param str - */ - unquote(str: string, quoteChar?: string): string; - - /** - * Repeat a string with an optional separator. - * ('foo', 3) => 'foofoofoo' - * ('foo', 3, 'bar') => 'foobarfoobarfoo' - * @param value - * @param count - * @param separator - */ - repeat(value: string, count: number, separator?:string): string; - - /** - * Naturally sort strings like humans would do. - * Caution: this function is charset dependent. - * @param str1 - * @param str2 - */ - naturalCmp(str1: string, str2: string): number; - - /** - * Calculates Levenshtein distance between two strings. - * ('kitten', 'kittah') => 2 - * @param str1 - * @param str2 - */ - levenshtein(str1: string, str2: string): number; - - /** - * Turn strings that can be commonly considered as booleans to real booleans. - * Such as "true", "false", "1" and "0". This function is case insensitive. - * ('true') => true - * ('FALSE') => false - * ('random') => undefined - * ('truthy', ['truthy'], ['falsy']) => true - * ('true only at start', [/^true/]) => true - * @param str - * @param trueValues - * @param falseValues - */ - toBoolean(str: string, trueValues?: any[], falseValues?: any[]): boolean; - -} -declare module 'underscore.string' { - var underscoreString: UnderscoreStringStatic; - export = underscoreString; -} -// TODO interface UnderscoreString extends Underscore diff --git a/typings/underscore/underscore.d.ts b/typings/underscore/underscore.d.ts deleted file mode 100644 index d8d08a3b756..00000000000 --- a/typings/underscore/underscore.d.ts +++ /dev/null @@ -1,6085 +0,0 @@ -// Type definitions for Underscore 1.8.3 -// Project: http://underscorejs.org/ -// Definitions by: Boris Yankov , Josh Baldwin , Christopher Currens -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -declare module _ { - /** - * underscore.js _.throttle options. - **/ - interface ThrottleSettings { - - /** - * If you'd like to disable the leading-edge call, pass this as false. - **/ - leading?: boolean; - - /** - * If you'd like to disable the execution on the trailing-edge, pass false. - **/ - trailing?: boolean; - } - - /** - * underscore.js template settings, set templateSettings or pass as an argument - * to 'template()' to override defaults. - **/ - interface TemplateSettings { - /** - * Default value is '/<%([\s\S]+?)%>/g'. - **/ - evaluate?: RegExp; - - /** - * Default value is '/<%=([\s\S]+?)%>/g'. - **/ - interpolate?: RegExp; - - /** - * Default value is '/<%-([\s\S]+?)%>/g'. - **/ - escape?: RegExp; - - /** - * By default, 'template()' places the values from your data in the local scope via the 'with' statement. - * However, you can specify a single variable name with this setting. - **/ - variable?: string; - } - - interface Collection { } - - // Common interface between Arrays and jQuery objects - interface List extends Collection { - [index: number]: T; - length: number; - } - - interface Dictionary extends Collection { - [index: string]: T; - } - - interface ListIterator { - (value: T, index: number, list: List): TResult; - } - - interface ObjectIterator { - (element: T, key: string, list: Dictionary): TResult; - } - - interface MemoIterator { - (prev: TResult, curr: T, index: number, list: List): TResult; - } - - interface MemoObjectIterator { - (prev: TResult, curr: T, key: string, list: Dictionary): TResult; - } - - interface Cancelable { - cancel() : void; - } -} - -interface UnderscoreStatic { - /** - * Underscore OOP Wrapper, all Underscore functions that take an object - * as the first parameter can be invoked through this function. - * @param key First argument to Underscore object functions. - **/ - (value: _.Dictionary): Underscore; - (value: Array): Underscore; - (value: T): Underscore; - - /* ************* - * Collections * - ************* */ - - /** - * Iterates over a list of elements, yielding each in turn to an iterator function. The iterator is - * bound to the context object, if one is passed. Each invocation of iterator is called with three - * arguments: (element, index, list). If list is a JavaScript object, iterator's arguments will be - * (value, key, object). Delegates to the native forEach function if it exists. - * @param list Iterates over this list of elements. - * @param iterator Iterator function for each element `list`. - * @param context 'this' object in `iterator`, optional. - **/ - each( - list: _.List, - iterator: _.ListIterator, - context?: any): _.List; - - /** - * @see _.each - * @param object Iterates over properties of this object. - * @param iterator Iterator function for each property on `object`. - * @param context 'this' object in `iterator`, optional. - **/ - each( - object: _.Dictionary, - iterator: _.ObjectIterator, - context?: any): _.Dictionary; - - /** - * @see _.each - **/ - forEach( - list: _.List, - iterator: _.ListIterator, - context?: any): _.List; - - /** - * @see _.each - **/ - forEach( - object: _.Dictionary, - iterator: _.ObjectIterator, - context?: any): _.Dictionary; - - /** - * Produces a new array of values by mapping each value in list through a transformation function - * (iterator). If the native map method exists, it will be used instead. If list is a JavaScript - * object, iterator's arguments will be (value, key, object). - * @param list Maps the elements of this array. - * @param iterator Map iterator function for each element in `list`. - * @param context `this` object in `iterator`, optional. - * @return The mapped array result. - **/ - map( - list: _.List, - iterator: _.ListIterator, - context?: any): TResult[]; - - /** - * @see _.map - * @param object Maps the properties of this object. - * @param iterator Map iterator function for each property on `object`. - * @param context `this` object in `iterator`, optional. - * @return The mapped object result. - **/ - map( - object: _.Dictionary, - iterator: _.ObjectIterator, - context?: any): TResult[]; - - /** - * @see _.map - **/ - collect( - list: _.List, - iterator: _.ListIterator, - context?: any): TResult[]; - - /** - * @see _.map - **/ - collect( - object: _.Dictionary, - iterator: _.ObjectIterator, - context?: any): TResult[]; - - /** - * Also known as inject and foldl, reduce boils down a list of values into a single value. - * Memo is the initial state of the reduction, and each successive step of it should be - * returned by iterator. The iterator is passed four arguments: the memo, then the value - * and index (or key) of the iteration, and finally a reference to the entire list. - * @param list Reduces the elements of this array. - * @param iterator Reduce iterator function for each element in `list`. - * @param memo Initial reduce state. - * @param context `this` object in `iterator`, optional. - * @return Reduced object result. - **/ - reduce( - list: _.Collection, - iterator: _.MemoIterator, - memo?: TResult, - context?: any): TResult; - - reduce( - list: _.Dictionary, - iterator: _.MemoObjectIterator, - memo?: TResult, - context?: any): TResult; - - /** - * @see _.reduce - **/ - inject( - list: _.Collection, - iterator: _.MemoIterator, - memo?: TResult, - context?: any): TResult; - - /** - * @see _.reduce - **/ - foldl( - list: _.Collection, - iterator: _.MemoIterator, - memo?: TResult, - context?: any): TResult; - - /** - * The right-associative version of reduce. Delegates to the JavaScript 1.8 version of - * reduceRight, if it exists. `foldr` is not as useful in JavaScript as it would be in a - * language with lazy evaluation. - * @param list Reduces the elements of this array. - * @param iterator Reduce iterator function for each element in `list`. - * @param memo Initial reduce state. - * @param context `this` object in `iterator`, optional. - * @return Reduced object result. - **/ - reduceRight( - list: _.Collection, - iterator: _.MemoIterator, - memo?: TResult, - context?: any): TResult; - - /** - * @see _.reduceRight - **/ - foldr( - list: _.Collection, - iterator: _.MemoIterator, - memo?: TResult, - context?: any): TResult; - - /** - * Looks through each value in the list, returning the first one that passes a truth - * test (iterator). The function returns as soon as it finds an acceptable element, - * and doesn't traverse the entire list. - * @param list Searches for a value in this list. - * @param iterator Search iterator function for each element in `list`. - * @param context `this` object in `iterator`, optional. - * @return The first acceptable found element in `list`, if nothing is found undefined/null is returned. - **/ - find( - list: _.List, - iterator: _.ListIterator, - context?: any): T; - - /** - * @see _.find - **/ - find( - object: _.Dictionary, - iterator: _.ObjectIterator, - context?: any): T; - - /** - * @see _.find - **/ - find( - object: _.List|_.Dictionary, - iterator: U): T; - - /** - * @see _.find - **/ - find( - object: _.List|_.Dictionary, - iterator: string): T; - - /** - * @see _.find - **/ - detect( - list: _.List, - iterator: _.ListIterator, - context?: any): T; - - /** - * @see _.find - **/ - detect( - object: _.Dictionary, - iterator: _.ObjectIterator, - context?: any): T; - - /** - * @see _.find - **/ - detect( - object: _.List|_.Dictionary, - iterator: U): T; - - /** - * @see _.find - **/ - detect( - object: _.List|_.Dictionary, - iterator: string): T; - - /** - * Looks through each value in the list, returning an array of all the values that pass a truth - * test (iterator). Delegates to the native filter method, if it exists. - * @param list Filter elements out of this list. - * @param iterator Filter iterator function for each element in `list`. - * @param context `this` object in `iterator`, optional. - * @return The filtered list of elements. - **/ - filter( - list: _.List, - iterator: _.ListIterator, - context?: any): T[]; - - /** - * @see _.filter - **/ - filter( - object: _.Dictionary, - iterator: _.ObjectIterator, - context?: any): T[]; - - /** - * @see _.filter - **/ - select( - list: _.List, - iterator: _.ListIterator, - context?: any): T[]; - - /** - * @see _.filter - **/ - select( - object: _.Dictionary, - iterator: _.ObjectIterator, - context?: any): T[]; - - /** - * Looks through each value in the list, returning an array of all the values that contain all - * of the key-value pairs listed in properties. - * @param list List to match elements again `properties`. - * @param properties The properties to check for on each element within `list`. - * @return The elements within `list` that contain the required `properties`. - **/ - where( - list: _.List, - properties: U): T[]; - - /** - * Looks through the list and returns the first value that matches all of the key-value pairs listed in properties. - * @param list Search through this list's elements for the first object with all `properties`. - * @param properties Properties to look for on the elements within `list`. - * @return The first element in `list` that has all `properties`. - **/ - findWhere( - list: _.List, - properties: U): T; - - /** - * Returns the values in list without the elements that the truth test (iterator) passes. - * The opposite of filter. - * Return all the elements for which a truth test fails. - * @param list Reject elements within this list. - * @param iterator Reject iterator function for each element in `list`. - * @param context `this` object in `iterator`, optional. - * @return The rejected list of elements. - **/ - reject( - list: _.List, - iterator: _.ListIterator, - context?: any): T[]; - - /** - * @see _.reject - **/ - reject( - object: _.Dictionary, - iterator: _.ObjectIterator, - context?: any): T[]; - - /** - * Returns true if all of the values in the list pass the iterator truth test. Delegates to the - * native method every, if present. - * @param list Truth test against all elements within this list. - * @param iterator Trust test iterator function for each element in `list`. - * @param context `this` object in `iterator`, optional. - * @return True if all elements passed the truth test, otherwise false. - **/ - every( - list: _.List, - iterator?: _.ListIterator, - context?: any): boolean; - - /** - * @see _.every - **/ - every( - list: _.Dictionary, - iterator?: _.ObjectIterator, - context?: any): boolean; - - /** - * @see _.every - **/ - all( - list: _.List, - iterator?: _.ListIterator, - context?: any): boolean; - - /** - * @see _.every - **/ - all( - list: _.Dictionary, - iterator?: _.ObjectIterator, - context?: any): boolean; - - /** - * Returns true if any of the values in the list pass the iterator truth test. Short-circuits and - * stops traversing the list if a true element is found. Delegates to the native method some, if present. - * @param list Truth test against all elements within this list. - * @param iterator Trust test iterator function for each element in `list`. - * @param context `this` object in `iterator`, optional. - * @return True if any elements passed the truth test, otherwise false. - **/ - some( - list: _.List, - iterator?: _.ListIterator, - context?: any): boolean; - - /** - * @see _.some - **/ - some( - object: _.Dictionary, - iterator?: _.ObjectIterator, - context?: any): boolean; - - /** - * @see _.some - **/ - any( - list: _.List, - iterator?: _.ListIterator, - context?: any): boolean; - - /** - * @see _.some - **/ - any( - object: _.Dictionary, - iterator?: _.ObjectIterator, - context?: any): boolean; - - any( - list: _.List, - value: T): boolean; - - /** - * Returns true if the value is present in the list. Uses indexOf internally, - * if list is an Array. - * @param list Checks each element to see if `value` is present. - * @param value The value to check for within `list`. - * @return True if `value` is present in `list`, otherwise false. - **/ - contains( - list: _.List, - value: T, - fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - contains( - object: _.Dictionary, - value: T): boolean; - - /** - * @see _.contains - **/ - include( - list: _.Collection, - value: T, - fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - include( - object: _.Dictionary, - value: T): boolean; - - /** - * @see _.contains - **/ - includes( - list: _.Collection, - value: T, - fromIndex?: number): boolean; - - /** - * @see _.contains - **/ - includes( - object: _.Dictionary, - value: T): boolean; - - /** - * Calls the method named by methodName on each value in the list. Any extra arguments passed to - * invoke will be forwarded on to the method invocation. - * @param list The element's in this list will each have the method `methodName` invoked. - * @param methodName The method's name to call on each element within `list`. - * @param arguments Additional arguments to pass to the method `methodName`. - **/ - invoke( - list: _.List, - methodName: string, - ...arguments: any[]): any; - - /** - * A convenient version of what is perhaps the most common use-case for map: extracting a list of - * property values. - * @param list The list to pluck elements out of that have the property `propertyName`. - * @param propertyName The property to look for on each element within `list`. - * @return The list of elements within `list` that have the property `propertyName`. - **/ - pluck( - list: _.List, - propertyName: string): any[]; - - /** - * Returns the maximum value in list. - * @param list Finds the maximum value in this list. - * @return Maximum value in `list`. - **/ - max(list: _.List): number; - - /** - * @see _.max - */ - max(object: _.Dictionary): number; - - /** - * Returns the maximum value in list. If iterator is passed, it will be used on each value to generate - * the criterion by which the value is ranked. - * @param list Finds the maximum value in this list. - * @param iterator Compares each element in `list` to find the maximum value. - * @param context `this` object in `iterator`, optional. - * @return The maximum element within `list`. - **/ - max( - list: _.List, - iterator?: _.ListIterator, - context?: any): T; - - /** - * @see _.max - */ - max( - list: _.Dictionary, - iterator?: _.ObjectIterator, - context?: any): T; - - /** - * Returns the minimum value in list. - * @param list Finds the minimum value in this list. - * @return Minimum value in `list`. - **/ - min(list: _.List): number; - - /** - * @see _.min - */ - min(o: _.Dictionary): number; - - /** - * Returns the minimum value in list. If iterator is passed, it will be used on each value to generate - * the criterion by which the value is ranked. - * @param list Finds the minimum value in this list. - * @param iterator Compares each element in `list` to find the minimum value. - * @param context `this` object in `iterator`, optional. - * @return The minimum element within `list`. - **/ - min( - list: _.List, - iterator?: _.ListIterator, - context?: any): T; - - /** - * @see _.min - */ - min( - list: _.Dictionary, - iterator?: _.ObjectIterator, - context?: any): T; - - /** - * Returns a sorted copy of list, ranked in ascending order by the results of running each value - * through iterator. Iterator may also be the string name of the property to sort by (eg. length). - * @param list Sorts this list. - * @param iterator Sort iterator for each element within `list`. - * @param context `this` object in `iterator`, optional. - * @return A sorted copy of `list`. - **/ - sortBy( - list: _.List, - iterator?: _.ListIterator, - context?: any): T[]; - - /** - * @see _.sortBy - * @param iterator Sort iterator for each element within `list`. - **/ - sortBy( - list: _.List, - iterator: string, - context?: any): T[]; - - /** - * Splits a collection into sets, grouped by the result of running each value through iterator. - * If iterator is a string instead of a function, groups by the property named by iterator on - * each of the values. - * @param list Groups this list. - * @param iterator Group iterator for each element within `list`, return the key to group the element by. - * @param context `this` object in `iterator`, optional. - * @return An object with the group names as properties where each property contains the grouped elements from `list`. - **/ - groupBy( - list: _.List, - iterator?: _.ListIterator, - context?: any): _.Dictionary; - - /** - * @see _.groupBy - * @param iterator Property on each object to group them by. - **/ - groupBy( - list: _.List, - iterator: string, - context?: any): _.Dictionary; - - /** - * Given a `list`, and an `iterator` function that returns a key for each element in the list (or a property name), - * returns an object with an index of each item. Just like _.groupBy, but for when you know your keys are unique. - **/ - indexBy( - list: _.List, - iterator: _.ListIterator, - context?: any): _.Dictionary; - - /** - * @see _.indexBy - * @param iterator Property on each object to index them by. - **/ - indexBy( - list: _.List, - iterator: string, - context?: any): _.Dictionary; - - /** - * Sorts a list into groups and returns a count for the number of objects in each group. Similar - * to groupBy, but instead of returning a list of values, returns a count for the number of values - * in that group. - * @param list Group elements in this list and then count the number of elements in each group. - * @param iterator Group iterator for each element within `list`, return the key to group the element by. - * @param context `this` object in `iterator`, optional. - * @return An object with the group names as properties where each property contains the number of elements in that group. - **/ - countBy( - list: _.List, - iterator?: _.ListIterator, - context?: any): _.Dictionary; - - /** - * @see _.countBy - * @param iterator Function name - **/ - countBy( - list: _.List, - iterator: string, - context?: any): _.Dictionary; - - /** - * Returns a shuffled copy of the list, using a version of the Fisher-Yates shuffle. - * @param list List to shuffle. - * @return Shuffled copy of `list`. - **/ - shuffle(list: _.Collection): T[]; - - /** - * Produce a random sample from the `list`. Pass a number to return `n` random elements from the list. Otherwise a single random item will be returned. - * @param list List to sample. - * @return Random sample of `n` elements in `list`. - **/ - sample(list: _.Collection, n: number): T[]; - - /** - * @see _.sample - **/ - sample(list: _.Collection): T; - - /** - * Converts the list (anything that can be iterated over), into a real Array. Useful for transmuting - * the arguments object. - * @param list object to transform into an array. - * @return `list` as an array. - **/ - toArray(list: _.Collection): T[]; - - /** - * Return the number of values in the list. - * @param list Count the number of values/elements in this list. - * @return Number of values in `list`. - **/ - size(list: _.Collection): number; - - /** - * Split array into two arrays: - * one whose elements all satisfy predicate and one whose elements all do not satisfy predicate. - * @param array Array to split in two. - * @param iterator Filter iterator function for each element in `array`. - * @param context `this` object in `iterator`, optional. - * @return Array where Array[0] are the elements in `array` that satisfies the predicate, and Array[1] the elements that did not. - **/ - partition( - array: Array, - iterator: _.ListIterator, - context?: any): T[][]; - - /********* - * Arrays * - **********/ - - /** - * Returns the first element of an array. Passing n will return the first n elements of the array. - * @param array Retrieves the first element of this array. - * @return Returns the first element of `array`. - **/ - first(array: _.List): T; - - /** - * @see _.first - * @param n Return more than one element from `array`. - **/ - first( - array: _.List, - n: number): T[]; - - /** - * @see _.first - **/ - head(array: _.List): T; - - /** - * @see _.first - **/ - head( - array: _.List, - n: number): T[]; - - /** - * @see _.first - **/ - take(array: _.List): T; - - /** - * @see _.first - **/ - take( - array: _.List, - n: number): T[]; - - /** - * Returns everything but the last entry of the array. Especially useful on the arguments object. - * Pass n to exclude the last n elements from the result. - * @param array Retrieve all elements except the last `n`. - * @param n Leaves this many elements behind, optional. - * @return Returns everything but the last `n` elements of `array`. - **/ - initial( - array: _.List, - n?: number): T[]; - - /** - * Returns the last element of an array. Passing n will return the last n elements of the array. - * @param array Retrieves the last element of this array. - * @return Returns the last element of `array`. - **/ - last(array: _.List): T; - - /** - * @see _.last - * @param n Return more than one element from `array`. - **/ - last( - array: _.List, - n: number): T[]; - - /** - * Returns the rest of the elements in an array. Pass an index to return the values of the array - * from that index onward. - * @param array The array to retrieve all but the first `index` elements. - * @param n The index to start retrieving elements forward from, optional, default = 1. - * @return Returns the elements of `array` from `index` to the end of `array`. - **/ - rest( - array: _.List, - n?: number): T[]; - - /** - * @see _.rest - **/ - tail( - array: _.List, - n?: number): T[]; - - /** - * @see _.rest - **/ - drop( - array: _.List, - n?: number): T[]; - - /** - * Returns a copy of the array with all falsy values removed. In JavaScript, false, null, 0, "", - * undefined and NaN are all falsy. - * @param array Array to compact. - * @return Copy of `array` without false values. - **/ - compact(array: _.List): T[]; - - /** - * Flattens a nested array (the nesting can be to any depth). If you pass shallow, the array will - * only be flattened a single level. - * @param array The array to flatten. - * @param shallow If true then only flatten one level, optional, default = false. - * @return `array` flattened. - **/ - flatten( - array: _.List, - shallow?: boolean): any[]; - - /** - * Returns a copy of the array with all instances of the values removed. - * @param array The array to remove `values` from. - * @param values The values to remove from `array`. - * @return Copy of `array` without `values`. - **/ - without( - array: _.List, - ...values: T[]): T[]; - - /** - * Computes the union of the passed-in arrays: the list of unique items, in order, that are - * present in one or more of the arrays. - * @param arrays Array of arrays to compute the union of. - * @return The union of elements within `arrays`. - **/ - union(...arrays: _.List[]): T[]; - - /** - * Computes the list of values that are the intersection of all the arrays. Each value in the result - * is present in each of the arrays. - * @param arrays Array of arrays to compute the intersection of. - * @return The intersection of elements within `arrays`. - **/ - intersection(...arrays: _.List[]): T[]; - - /** - * Similar to without, but returns the values from array that are not present in the other arrays. - * @param array Keeps values that are within `others`. - * @param others The values to keep within `array`. - * @return Copy of `array` with only `others` values. - **/ - difference( - array: _.List, - ...others: _.List[]): T[]; - - /** - * Produces a duplicate-free version of the array, using === to test object equality. If you know in - * advance that the array is sorted, passing true for isSorted will run a much faster algorithm. If - * you want to compute unique items based on a transformation, pass an iterator function. - * @param array Array to remove duplicates from. - * @param isSorted True if `array` is already sorted, optional, default = false. - * @param iterator Transform the elements of `array` before comparisons for uniqueness. - * @param context 'this' object in `iterator`, optional. - * @return Copy of `array` where all elements are unique. - **/ - uniq( - array: _.List, - isSorted?: boolean, - iterator?: _.ListIterator, - context?: any): T[]; - - /** - * @see _.uniq - **/ - uniq( - array: _.List, - iterator?: _.ListIterator, - context?: any): T[]; - - /** - * @see _.uniq - **/ - unique( - array: _.List, - iterator?: _.ListIterator, - context?: any): T[]; - - /** - * @see _.uniq - **/ - unique( - array: _.List, - isSorted?: boolean, - iterator?: _.ListIterator, - context?: any): T[]; - - - /** - * Merges together the values of each of the arrays with the values at the corresponding position. - * Useful when you have separate data sources that are coordinated through matching array indexes. - * If you're working with a matrix of nested arrays, zip.apply can transpose the matrix in a similar fashion. - * @param arrays The arrays to merge/zip. - * @return Zipped version of `arrays`. - **/ - zip(...arrays: any[][]): any[][]; - - /** - * @see _.zip - **/ - zip(...arrays: any[]): any[]; - - /** - * The opposite of zip. Given a number of arrays, returns a series of new arrays, the first - * of which contains all of the first elements in the input arrays, the second of which - * contains all of the second elements, and so on. Use with apply to pass in an array - * of arrays - * @param arrays The arrays to unzip. - * @return Unzipped version of `arrays`. - **/ - unzip(...arrays: any[][]): any[][]; - - /** - * Converts arrays into objects. Pass either a single list of [key, value] pairs, or a - * list of keys, and a list of values. - * @param keys Key array. - * @param values Value array. - * @return An object containing the `keys` as properties and `values` as the property values. - **/ - object( - keys: _.List, - values: _.List): TResult; - - /** - * Converts arrays into objects. Pass either a single list of [key, value] pairs, or a - * list of keys, and a list of values. - * @param keyValuePairs Array of [key, value] pairs. - * @return An object containing the `keys` as properties and `values` as the property values. - **/ - object(...keyValuePairs: any[][]): TResult; - - /** - * @see _.object - **/ - object( - list: _.List, - values?: any): TResult; - - /** - * Returns the index at which value can be found in the array, or -1 if value is not present in the array. - * Uses the native indexOf function unless it's missing. If you're working with a large array, and you know - * that the array is already sorted, pass true for isSorted to use a faster binary search ... or, pass a number - * as the third argument in order to look for the first matching value in the array after the given index. - * @param array The array to search for the index of `value`. - * @param value The value to search for within `array`. - * @param isSorted True if the array is already sorted, optional, default = false. - * @return The index of `value` within `array`. - **/ - indexOf( - array: _.List, - value: T, - isSorted?: boolean): number; - - /** - * @see _indexof - **/ - indexOf( - array: _.List, - value: T, - startFrom: number): number; - - /** - * Returns the index of the last occurrence of value in the array, or -1 if value is not present. Uses the - * native lastIndexOf function if possible. Pass fromIndex to start your search at a given index. - * @param array The array to search for the last index of `value`. - * @param value The value to search for within `array`. - * @param from The starting index for the search, optional. - * @return The index of the last occurrence of `value` within `array`. - **/ - lastIndexOf( - array: _.List, - value: T, - from?: number): number; - - /** - * Returns the first index of an element in `array` where the predicate truth test passes - * @param array The array to search for the index of the first element where the predicate truth test passes. - * @param predicate Predicate function. - * @param context `this` object in `predicate`, optional. - * @return Returns the index of an element in `array` where the predicate truth test passes or -1.` - **/ - findIndex( - array: _.List, - predicate: _.ListIterator | {}, - context?: any): number; - - /** - * Returns the last index of an element in `array` where the predicate truth test passes - * @param array The array to search for the index of the last element where the predicate truth test passes. - * @param predicate Predicate function. - * @param context `this` object in `predicate`, optional. - * @return Returns the index of an element in `array` where the predicate truth test passes or -1.` - **/ - findLastIndex( - array: _.List, - predicate: _.ListIterator | {}, - context?: any): number; - - /** - * Uses a binary search to determine the index at which the value should be inserted into the list in order - * to maintain the list's sorted order. If an iterator is passed, it will be used to compute the sort ranking - * of each value, including the value you pass. - * @param list The sorted list. - * @param value The value to determine its index within `list`. - * @param iterator Iterator to compute the sort ranking of each value, optional. - * @return The index where `value` should be inserted into `list`. - **/ - sortedIndex( - list: _.List, - value: T, - iterator?: (x: T) => TSort, context?: any): number; - - /** - * A function to create flexibly-numbered lists of integers, handy for each and map loops. start, if omitted, - * defaults to 0; step defaults to 1. Returns a list of integers from start to stop, incremented (or decremented) - * by step, exclusive. - * @param start Start here. - * @param stop Stop here. - * @param step The number to count up by each iteration, optional, default = 1. - * @return Array of numbers from `start` to `stop` with increments of `step`. - **/ - - range( - start: number, - stop: number, - step?: number): number[]; - - /** - * @see _.range - * @param stop Stop here. - * @return Array of numbers from 0 to `stop` with increments of 1. - * @note If start is not specified the implementation will never pull the step (step = arguments[2] || 0) - **/ - range(stop: number): number[]; - - /** - * Split an **array** into several arrays containing **count** or less elements - * of initial array. - * @param array The array to split - * @param count The maximum size of the inner arrays. - */ - chunk(array: _.Collection, count: number): (_.Collection)[] - - /************* - * Functions * - *************/ - - /** - * Bind a function to an object, meaning that whenever the function is called, the value of this will - * be the object. Optionally, bind arguments to the function to pre-fill them, also known as partial application. - * @param func The function to bind `this` to `object`. - * @param context The `this` pointer whenever `fn` is called. - * @param arguments Additional arguments to pass to `fn` when called. - * @return `fn` with `this` bound to `object`. - **/ - bind( - func: Function, - context: any, - ...arguments: any[]): () => any; - - /** - * Binds a number of methods on the object, specified by methodNames, to be run in the context of that object - * whenever they are invoked. Very handy for binding functions that are going to be used as event handlers, - * which would otherwise be invoked with a fairly useless this. If no methodNames are provided, all of the - * object's function properties will be bound to it. - * @param object The object to bind the methods `methodName` to. - * @param methodNames The methods to bind to `object`, optional and if not provided all of `object`'s - * methods are bound. - **/ - bindAll( - object: any, - ...methodNames: string[]): any; - - /** - * Partially apply a function by filling in any number of its arguments, without changing its dynamic this value. - * A close cousin of bind. You may pass _ in your list of arguments to specify an argument that should not be - * pre-filled, but left open to supply at call-time. - * @param fn Function to partially fill in arguments. - * @param arguments The partial arguments. - * @return `fn` with partially filled in arguments. - **/ - - partial( - fn: { (p1: T1):T2 }, - p1: T1 - ): { (): T2 }; - - partial( - fn: { (p1: T1, p2: T2):T3 }, - p1: T1 - ): { (p2: T2): T3 }; - - partial( - fn: { (p1: T1, p2: T2):T3 }, - p1: T1, - p2: T2 - ): { (): T3 }; - - partial( - fn: { (p1: T1, p2: T2):T3 }, - stub1: UnderscoreStatic, - p2: T2 - ): { (p1: T1): T3 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3):T4 }, - p1: T1 - ): { (p2: T2, p3: T3): T4 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3):T4 }, - p1: T1, - p2: T2 - ): { (p3: T3): T4 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3):T4 }, - stub1: UnderscoreStatic, - p2: T2 - ): { (p1: T1, p3: T3): T4 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3):T4 }, - p1: T1, - p2: T2, - p3: T3 - ): { (): T4 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3):T4 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3 - ): { (p1: T1): T4 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3):T4 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3 - ): { (p2: T2): T4 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3):T4 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3 - ): { (p1: T1, p2: T2): T4 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - p1: T1 - ): { (p2: T2, p3: T3, p4: T4): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - p1: T1, - p2: T2 - ): { (p3: T3, p4: T4): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - stub1: UnderscoreStatic, - p2: T2 - ): { (p1: T1, p3: T3, p4: T4): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - p1: T1, - p2: T2, - p3: T3 - ): { (p4: T4): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3 - ): { (p1: T1, p4: T4): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3 - ): { (p2: T2, p4: T4): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3 - ): { (p1: T1, p2: T2, p4: T4): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4 - ): { (): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4 - ): { (p1: T1): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4 - ): { (p2: T2): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4 - ): { (p1: T1, p2: T2): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4 - ): { (p3: T3): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4 - ): { (p1: T1, p3: T3): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4 - ): { (p2: T2, p3: T3): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4):T5 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4 - ): { (p1: T1, p2: T2, p3: T3): T5 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1 - ): { (p2: T2, p3: T3, p4: T4, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - p2: T2 - ): { (p3: T3, p4: T4, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - p2: T2 - ): { (p1: T1, p3: T3, p4: T4, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - p2: T2, - p3: T3 - ): { (p4: T4, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3 - ): { (p1: T1, p4: T4, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3 - ): { (p2: T2, p4: T4, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3 - ): { (p1: T1, p2: T2, p4: T4, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4 - ): { (p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4 - ): { (p1: T1, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4 - ): { (p2: T2, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4 - ): { (p1: T1, p2: T2, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4 - ): { (p3: T3, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4 - ): { (p1: T1, p3: T3, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4 - ): { (p2: T2, p3: T3, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4 - ): { (p1: T1, p2: T2, p3: T3, p5: T5): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4, - p5: T5 - ): { (): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4, - p5: T5 - ): { (p1: T1): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5 - ): { (p2: T2): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5 - ): { (p1: T1, p2: T2): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p3: T3): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p1: T1, p3: T3): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p2: T2, p3: T3): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p1: T1, p2: T2, p3: T3): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p4: T4): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p4: T4): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p2: T2, p4: T4): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p2: T2, p4: T4): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p3: T3, p4: T4): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p3: T3, p4: T4): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p2: T2, p3: T3, p4: T4): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5):T6 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p2: T2, p3: T3, p4: T4): T6 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1 - ): { (p2: T2, p3: T3, p4: T4, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2 - ): { (p3: T3, p4: T4, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2 - ): { (p1: T1, p3: T3, p4: T4, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - p3: T3 - ): { (p4: T4, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3 - ): { (p1: T1, p4: T4, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3 - ): { (p2: T2, p4: T4, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3 - ): { (p1: T1, p2: T2, p4: T4, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4 - ): { (p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4 - ): { (p1: T1, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4 - ): { (p2: T2, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4 - ): { (p1: T1, p2: T2, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4 - ): { (p3: T3, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4 - ): { (p1: T1, p3: T3, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4 - ): { (p2: T2, p3: T3, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4 - ): { (p1: T1, p2: T2, p3: T3, p5: T5, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4, - p5: T5 - ): { (p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4, - p5: T5 - ): { (p1: T1, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5 - ): { (p2: T2, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5 - ): { (p1: T1, p2: T2, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p3: T3, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p1: T1, p3: T3, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p2: T2, p3: T3, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p1: T1, p2: T2, p3: T3, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p4: T4, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p4: T4, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p2: T2, p4: T4, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p2: T2, p4: T4, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p3: T3, p4: T4, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p3: T3, p4: T4, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p2: T2, p3: T3, p4: T4, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p2: T2, p3: T3, p4: T4, p6: T6): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4, - p5: T5, - p6: T6 - ): { (): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4, - p5: T5, - p6: T6 - ): { (p1: T1): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5, - p6: T6 - ): { (p2: T2): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5, - p6: T6 - ): { (p1: T1, p2: T2): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6 - ): { (p3: T3): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6 - ): { (p1: T1, p3: T3): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6 - ): { (p2: T2, p3: T3): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6 - ): { (p1: T1, p2: T2, p3: T3): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p4: T4): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p1: T1, p4: T4): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p2: T2, p4: T4): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p1: T1, p2: T2, p4: T4): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p3: T3, p4: T4): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p1: T1, p3: T3, p4: T4): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p2: T2, p3: T3, p4: T4): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p1: T1, p2: T2, p3: T3, p4: T4): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p2: T2, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p2: T2, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p3: T3, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p3: T3, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p2: T2, p3: T3, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p2: T2, p3: T3, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p4: T4, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p4: T4, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p2: T2, p4: T4, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p2: T2, p4: T4, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p3: T3, p4: T4, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p3: T3, p4: T4, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p2: T2, p3: T3, p4: T4, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6):T7 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5): T7 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1 - ): { (p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2 - ): { (p3: T3, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2 - ): { (p1: T1, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3 - ): { (p4: T4, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3 - ): { (p1: T1, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3 - ): { (p2: T2, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3 - ): { (p1: T1, p2: T2, p4: T4, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4 - ): { (p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4 - ): { (p1: T1, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4 - ): { (p2: T2, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4 - ): { (p1: T1, p2: T2, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4 - ): { (p3: T3, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4 - ): { (p1: T1, p3: T3, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4 - ): { (p2: T2, p3: T3, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4 - ): { (p1: T1, p2: T2, p3: T3, p5: T5, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4, - p5: T5 - ): { (p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4, - p5: T5 - ): { (p1: T1, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5 - ): { (p2: T2, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5 - ): { (p1: T1, p2: T2, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p3: T3, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p1: T1, p3: T3, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p2: T2, p3: T3, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5 - ): { (p1: T1, p2: T2, p3: T3, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p4: T4, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p4: T4, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p2: T2, p4: T4, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p2: T2, p4: T4, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p3: T3, p4: T4, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p3: T3, p4: T4, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p2: T2, p3: T3, p4: T4, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5 - ): { (p1: T1, p2: T2, p3: T3, p4: T4, p6: T6, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4, - p5: T5, - p6: T6 - ): { (p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4, - p5: T5, - p6: T6 - ): { (p1: T1, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5, - p6: T6 - ): { (p2: T2, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5, - p6: T6 - ): { (p1: T1, p2: T2, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6 - ): { (p3: T3, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6 - ): { (p1: T1, p3: T3, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6 - ): { (p2: T2, p3: T3, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6 - ): { (p1: T1, p2: T2, p3: T3, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p4: T4, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p1: T1, p4: T4, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p2: T2, p4: T4, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p1: T1, p2: T2, p4: T4, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p3: T3, p4: T4, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p1: T1, p3: T3, p4: T4, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p2: T2, p3: T3, p4: T4, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6 - ): { (p1: T1, p2: T2, p3: T3, p4: T4, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p2: T2, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p2: T2, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p3: T3, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p3: T3, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p2: T2, p3: T3, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p2: T2, p3: T3, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p4: T4, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p4: T4, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p2: T2, p4: T4, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p2: T2, p4: T4, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p3: T3, p4: T4, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p3: T3, p4: T4, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p2: T2, p3: T3, p4: T4, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6 - ): { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p7: T7): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4, - p5: T5, - p6: T6, - p7: T7 - ): { (): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4, - p5: T5, - p6: T6, - p7: T7 - ): { (p1: T1): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5, - p6: T6, - p7: T7 - ): { (p2: T2): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5, - p6: T6, - p7: T7 - ): { (p1: T1, p2: T2): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6, - p7: T7 - ): { (p3: T3): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6, - p7: T7 - ): { (p1: T1, p3: T3): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6, - p7: T7 - ): { (p2: T2, p3: T3): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - p6: T6, - p7: T7 - ): { (p1: T1, p2: T2, p3: T3): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6, - p7: T7 - ): { (p4: T4): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6, - p7: T7 - ): { (p1: T1, p4: T4): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6, - p7: T7 - ): { (p2: T2, p4: T4): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - p6: T6, - p7: T7 - ): { (p1: T1, p2: T2, p4: T4): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6, - p7: T7 - ): { (p3: T3, p4: T4): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6, - p7: T7 - ): { (p1: T1, p3: T3, p4: T4): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6, - p7: T7 - ): { (p2: T2, p3: T3, p4: T4): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - p6: T6, - p7: T7 - ): { (p1: T1, p2: T2, p3: T3, p4: T4): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p1: T1, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p2: T2, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p1: T1, p2: T2, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p3: T3, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p1: T1, p3: T3, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p2: T2, p3: T3, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p1: T1, p2: T2, p3: T3, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p4: T4, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p1: T1, p4: T4, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p2: T2, p4: T4, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p1: T1, p2: T2, p4: T4, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p3: T3, p4: T4, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p1: T1, p3: T3, p4: T4, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p2: T2, p3: T3, p4: T4, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - p6: T6, - p7: T7 - ): { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p2: T2, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p2: T2, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p3: T3, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p3: T3, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p2: T2, p3: T3, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p2: T2, p3: T3, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p4: T4, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p4: T4, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p2: T2, p4: T4, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p2: T2, p4: T4, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p3: T3, p4: T4, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p3: T3, p4: T4, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p2: T2, p3: T3, p4: T4, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - p5: T5, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p2: T2, p3: T3, p4: T4, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p2: T2, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - p4: T4, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p2: T2, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p3: T3, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p3: T3, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p2: T2, p3: T3, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - p4: T4, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p2: T2, p3: T3, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p4: T4, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p4: T4, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p2: T2, p4: T4, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - p3: T3, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p2: T2, p4: T4, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p3: T3, p4: T4, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - p2: T2, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p3: T3, p4: T4, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - p1: T1, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p2: T2, p3: T3, p4: T4, p5: T5, p6: T6): T8 }; - - partial( - fn: { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6, p7: T7):T8 }, - stub1: UnderscoreStatic, - stub2: UnderscoreStatic, - stub3: UnderscoreStatic, - stub4: UnderscoreStatic, - stub5: UnderscoreStatic, - stub6: UnderscoreStatic, - p7: T7 - ): { (p1: T1, p2: T2, p3: T3, p4: T4, p5: T5, p6: T6): T8 }; - - /** - * Memoizes a given function by caching the computed result. Useful for speeding up slow-running computations. - * If passed an optional hashFunction, it will be used to compute the hash key for storing the result, based - * on the arguments to the original function. The default hashFunction just uses the first argument to the - * memoized function as the key. - * @param fn Computationally expensive function that will now memoized results. - * @param hashFn Hash function for storing the result of `fn`. - * @return Memoized version of `fn`. - **/ - memoize( - fn: Function, - hashFn?: (...args: any[]) => string): Function; - - /** - * Much like setTimeout, invokes function after wait milliseconds. If you pass the optional arguments, - * they will be forwarded on to the function when it is invoked. - * @param func Function to delay `waitMS` amount of ms. - * @param wait The amount of milliseconds to delay `fn`. - * @arguments Additional arguments to pass to `fn`. - **/ - delay( - func: Function, - wait: number, - ...arguments: any[]): any; - - /** - * @see _delay - **/ - delay( - func: Function, - ...arguments: any[]): any; - - /** - * Defers invoking the function until the current call stack has cleared, similar to using setTimeout - * with a delay of 0. Useful for performing expensive computations or HTML rendering in chunks without - * blocking the UI thread from updating. If you pass the optional arguments, they will be forwarded on - * to the function when it is invoked. - * @param fn The function to defer. - * @param arguments Additional arguments to pass to `fn`. - **/ - defer( - fn: Function, - ...arguments: any[]): void; - - /** - * Creates and returns a new, throttled version of the passed function, that, when invoked repeatedly, - * will only actually call the original function at most once per every wait milliseconds. Useful for - * rate-limiting events that occur faster than you can keep up with. - * By default, throttle will execute the function as soon as you call it for the first time, and, - * if you call it again any number of times during the wait period, as soon as that period is over. - * If you'd like to disable the leading-edge call, pass {leading: false}, and if you'd like to disable - * the execution on the trailing-edge, pass {trailing: false}. - * @param func Function to throttle `waitMS` ms. - * @param wait The number of milliseconds to wait before `fn` can be invoked again. - * @param options Allows for disabling execution of the throttled function on either the leading or trailing edge. - * @return `fn` with a throttle of `wait`. - **/ - throttle( - func: T, - wait: number, - options?: _.ThrottleSettings): T & _.Cancelable; - - /** - * Creates and returns a new debounced version of the passed function that will postpone its execution - * until after wait milliseconds have elapsed since the last time it was invoked. Useful for implementing - * behavior that should only happen after the input has stopped arriving. For example: rendering a preview - * of a Markdown comment, recalculating a layout after the window has stopped being resized, and so on. - * - * Pass true for the immediate parameter to cause debounce to trigger the function on the leading instead - * of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double - *-clicks on a "submit" button from firing a second time. - * @param fn Function to debounce `waitMS` ms. - * @param wait The number of milliseconds to wait before `fn` can be invoked again. - * @param immediate True if `fn` should be invoked on the leading edge of `waitMS` instead of the trailing edge. - * @return Debounced version of `fn` that waits `wait` ms when invoked. - **/ - debounce( - fn: T, - wait: number, - immediate?: boolean): T & _.Cancelable; - - /** - * Creates a version of the function that can only be called one time. Repeated calls to the modified - * function will have no effect, returning the value from the original call. Useful for initialization - * functions, instead of having to set a boolean flag and then check it later. - * @param fn Function to only execute once. - * @return Copy of `fn` that can only be invoked once. - **/ - once(fn: T): T; - - /** - * Similar to ES6's rest param (http://ariya.ofilabs.com/2013/03/es6-and-rest-parameter.html) - * This accumulates the arguments passed into an array, after a given index. - **/ - restArgs(func: Function, starIndex?: number) : Function; - - /** - * Creates a version of the function that will only be run after first being called count times. Useful - * for grouping asynchronous responses, where you want to be sure that all the async calls have finished, - * before proceeding. - * @param number count Number of times to be called before actually executing. - * @param Function fn The function to defer execution `count` times. - * @return Copy of `fn` that will not execute until it is invoked `count` times. - **/ - after( - count: number, - fn: Function): Function; - - /** - * Creates a version of the function that can be called no more than count times. The result of - * the last function call is memoized and returned when count has been reached. - * @param number count The maxmimum number of times the function can be called. - * @param Function fn The function to limit the number of times it can be called. - * @return Copy of `fn` that can only be called `count` times. - **/ - before( - count: number, - fn: Function): Function; - - /** - * Wraps the first function inside of the wrapper function, passing it as the first argument. This allows - * the wrapper to execute code before and after the function runs, adjust the arguments, and execute it - * conditionally. - * @param fn Function to wrap. - * @param wrapper The function that will wrap `fn`. - * @return Wrapped version of `fn. - **/ - wrap( - fn: Function, - wrapper: (fn: Function, ...args: any[]) => any): Function; - - /** - * Returns a negated version of the pass-in predicate. - * @param (...args: any[]) => boolean predicate - * @return (...args: any[]) => boolean - **/ - negate(predicate: (...args: any[]) => boolean): (...args: any[]) => boolean; - - /** - * Returns the composition of a list of functions, where each function consumes the return value of the - * function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())). - * @param functions List of functions to compose. - * @return Composition of `functions`. - **/ - compose(...functions: Function[]): Function; - - /********** - * Objects * - ***********/ - - /** - * Retrieve all the names of the object's properties. - * @param object Retrieve the key or property names from this object. - * @return List of all the property names on `object`. - **/ - keys(object: any): string[]; - - /** - * Retrieve all the names of object's own and inherited properties. - * @param object Retrieve the key or property names from this object. - * @return List of all the property names on `object`. - **/ - allKeys(object: any): string[]; - - /** - * Return all of the values of the object's properties. - * @param object Retrieve the values of all the properties on this object. - * @return List of all the values on `object`. - **/ - values(object: _.Dictionary): T[]; - - /** - * Return all of the values of the object's properties. - * @param object Retrieve the values of all the properties on this object. - * @return List of all the values on `object`. - **/ - values(object: any): any[]; - - /** - * Like map, but for objects. Transform the value of each property in turn. - * @param object The object to transform - * @param iteratee The function that transforms property values - * @param context The optional context (value of `this`) to bind to - * @return a new _.Dictionary of property values - */ - mapObject(object: _.Dictionary, iteratee: (val: T, key: string, object: _.Dictionary) => U, context?: any): _.Dictionary; - - /** - * Like map, but for objects. Transform the value of each property in turn. - * @param object The object to transform - * @param iteratee The function that tranforms property values - * @param context The optional context (value of `this`) to bind to - */ - mapObject(object: any, iteratee: (val: any, key: string, object: any) => T, context?: any): _.Dictionary; - - /** - * Like map, but for objects. Retrieves a property from each entry in the object, as if by _.property - * @param object The object to transform - * @param iteratee The property name to retrieve - * @param context The optional context (value of `this`) to bind to - */ - mapObject(object: any, iteratee: string, context?: any): _.Dictionary; - - /** - * Convert an object into a list of [key, value] pairs. - * @param object Convert this object to a list of [key, value] pairs. - * @return List of [key, value] pairs on `object`. - **/ - pairs(object: any): any[][]; - - /** - * Returns a copy of the object where the keys have become the values and the values the keys. - * For this to work, all of your object's values should be unique and string serializable. - * @param object Object to invert key/value pairs. - * @return An inverted key/value paired version of `object`. - **/ - invert(object: any): any; - - /** - * Returns a sorted list of the names of every method in an object - that is to say, - * the name of every function property of the object. - * @param object Object to pluck all function property names from. - * @return List of all the function names on `object`. - **/ - functions(object: any): string[]; - - /** - * @see _functions - **/ - methods(object: any): string[]; - - /** - * Copy all of the properties in the source objects over to the destination object, and return - * the destination object. It's in-order, so the last source will override properties of the - * same name in previous arguments. - * @param destination Object to extend all the properties from `sources`. - * @param sources Extends `destination` with all properties from these source objects. - * @return `destination` extended with all the properties from the `sources` objects. - **/ - extend( - destination: any, - ...sources: any[]): any; - - /** - * Like extend, but only copies own properties over to the destination object. (alias: assign) - */ - extendOwn( - destination: any, - ...source: any[]): any; - - /** - * Like extend, but only copies own properties over to the destination object. (alias: extendOwn) - */ - assign( - destination: any, - ...source: any[]): any; - - /** - * Returns the first key on an object that passes a predicate test. - * @param obj the object to search in - * @param predicate Predicate function. - * @param context `this` object in `iterator`, optional. - */ - findKey(obj: _.Dictionary, predicate: _.ObjectIterator, context? : any): T - - /** - * Return a copy of the object, filtered to only have values for the whitelisted keys - * (or array of valid keys). - * @param object Object to strip unwanted key/value pairs. - * @keys The key/value pairs to keep on `object`. - * @return Copy of `object` with only the `keys` properties. - **/ - pick( - object: any, - ...keys: any[]): any; - - /** - * @see _.pick - **/ - pick( - object: any, - fn: (value: any, key: any, object: any) => any): any; - - /** - * Return a copy of the object, filtered to omit the blacklisted keys (or array of keys). - * @param object Object to strip unwanted key/value pairs. - * @param keys The key/value pairs to remove on `object`. - * @return Copy of `object` without the `keys` properties. - **/ - omit( - object: any, - ...keys: string[]): any; - - /** - * @see _.omit - **/ - omit( - object: any, - keys: string[]): any; - - /** - * @see _.omit - **/ - omit( - object: any, - iteratee: Function): any; - - /** - * Fill in null and undefined properties in object with values from the defaults objects, - * and return the object. As soon as the property is filled, further defaults will have no effect. - * @param object Fill this object with default values. - * @param defaults The default values to add to `object`. - * @return `object` with added `defaults` values. - **/ - defaults( - object: any, - ...defaults: any[]): any; - - - /** - * Creates an object that inherits from the given prototype object. - * If additional properties are provided then they will be added to the - * created object. - * @param prototype The prototype that the returned object will inherit from. - * @param props Additional props added to the returned object. - **/ - create(prototype: any, props?: Object): any; - - /** - * Create a shallow-copied clone of the object. - * Any nested objects or arrays will be copied by reference, not duplicated. - * @param object Object to clone. - * @return Copy of `object`. - **/ - clone(object: T): T; - - /** - * Invokes interceptor with the object, and then returns object. The primary purpose of this method - * is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. - * @param object Argument to `interceptor`. - * @param intercepter The function to modify `object` before continuing the method chain. - * @return Modified `object`. - **/ - tap(object: T, intercepter: Function): T; - - /** - * Does the object contain the given key? Identical to object.hasOwnProperty(key), but uses a safe - * reference to the hasOwnProperty function, in case it's been overridden accidentally. - * @param object Object to check for `key`. - * @param key The key to check for on `object`. - * @return True if `key` is a property on `object`, otherwise false. - **/ - has(object: any, key: string): boolean; - - /** - * Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs. - * @param attrs Object with key values pair - * @return Predicate function - **/ - matches(attrs: T): _.ListIterator; - - /** - * Returns a predicate function that will tell you if a passed in object contains all of the key/value properties present in attrs. - * @see _.matches - * @param attrs Object with key values pair - * @return Predicate function - **/ - matcher(attrs: T): _.ListIterator; - - /** - * Returns a function that will itself return the key property of any passed-in object. - * @param key Property of the object. - * @return Function which accept an object an returns the value of key in that object. - **/ - property(key: string): (object: Object) => any; - - /** - * Returns a function that will itself return the value of a object key property. - * @param key The object to get the property value from. - * @return Function which accept a key property in `object` and returns its value. - **/ - propertyOf(object: Object): (key: string) => any; - - /** - * Performs an optimized deep comparison between the two objects, - * to determine if they should be considered equal. - * @param object Compare to `other`. - * @param other Compare to `object`. - * @return True if `object` is equal to `other`. - **/ - isEqual(object: any, other: any): boolean; - - /** - * Returns true if object contains no values. - * @param object Check if this object has no properties or values. - * @return True if `object` is empty. - **/ - isEmpty(object: any): boolean; - - /** - * Returns true if the keys and values in `properties` matches with the `object` properties. - * @param object Object to be compared with `properties`. - * @param properties Properties be compared with `object` - * @return True if `object` has matching keys and values, otherwise false. - **/ - isMatch(object:any, properties:any): boolean; - - /** - * Returns true if object is a DOM element. - * @param object Check if this object is a DOM element. - * @return True if `object` is a DOM element, otherwise false. - **/ - isElement(object: any): object is Element; - - /** - * Returns true if object is an Array. - * @param object Check if this object is an Array. - * @return True if `object` is an Array, otherwise false. - **/ - isArray(object: any): object is any[]; - - /** - * Returns true if object is an Array. - * @param object Check if this object is an Array. - * @return True if `object` is an Array, otherwise false. - **/ - isArray(object: any): object is T[]; - - /** - * Returns true if object is a Symbol. - * @param object Check if this object is a Symbol. - * @return True if `object` is a Symbol, otherwise false. - **/ - isSymbol(object: any): object is symbol; - - /** - * Returns true if value is an Object. Note that JavaScript arrays and functions are objects, - * while (normal) strings and numbers are not. - * @param object Check if this object is an Object. - * @return True of `object` is an Object, otherwise false. - **/ - isObject(object: any): boolean; - - /** - * Returns true if object is an Arguments object. - * @param object Check if this object is an Arguments object. - * @return True if `object` is an Arguments object, otherwise false. - **/ - isArguments(object: any): object is IArguments; - - /** - * Returns true if object is a Function. - * @param object Check if this object is a Function. - * @return True if `object` is a Function, otherwise false. - **/ - isFunction(object: any): object is Function; - - /** - * Returns true if object inherits from an Error. - * @param object Check if this object is an Error. - * @return True if `object` is a Error, otherwise false. - **/ - isError(object:any): object is Error; - - /** - * Returns true if object is a String. - * @param object Check if this object is a String. - * @return True if `object` is a String, otherwise false. - **/ - isString(object: any): object is string; - - /** - * Returns true if object is a Number (including NaN). - * @param object Check if this object is a Number. - * @return True if `object` is a Number, otherwise false. - **/ - isNumber(object: any): object is number; - - /** - * Returns true if object is a finite Number. - * @param object Check if this object is a finite Number. - * @return True if `object` is a finite Number. - **/ - isFinite(object: any): boolean; - - /** - * Returns true if object is either true or false. - * @param object Check if this object is a bool. - * @return True if `object` is a bool, otherwise false. - **/ - isBoolean(object: any): object is boolean; - - /** - * Returns true if object is a Date. - * @param object Check if this object is a Date. - * @return True if `object` is a Date, otherwise false. - **/ - isDate(object: any): object is Date; - - /** - * Returns true if object is a RegExp. - * @param object Check if this object is a RegExp. - * @return True if `object` is a RegExp, otherwise false. - **/ - isRegExp(object: any): object is RegExp; - - /** - * Returns true if object is NaN. - * Note: this is not the same as the native isNaN function, - * which will also return true if the variable is undefined. - * @param object Check if this object is NaN. - * @return True if `object` is NaN, otherwise false. - **/ - isNaN(object: any): boolean; - - /** - * Returns true if the value of object is null. - * @param object Check if this object is null. - * @return True if `object` is null, otherwise false. - **/ - isNull(object: any): boolean; - - /** - * Returns true if value is undefined. - * @param object Check if this object is undefined. - * @return True if `object` is undefined, otherwise false. - **/ - isUndefined(value: any): boolean; - - /* ********* - * Utility * - ********** */ - - /** - * Give control of the "_" variable back to its previous owner. - * Returns a reference to the Underscore object. - * @return Underscore object reference. - **/ - noConflict(): any; - - /** - * Returns the same value that is used as the argument. In math: f(x) = x - * This function looks useless, but is used throughout Underscore as a default iterator. - * @param value Identity of this object. - * @return `value`. - **/ - identity(value: T): T; - - /** - * Creates a function that returns the same value that is used as the argument of _.constant - * @param value Identity of this object. - * @return Function that return value. - **/ - constant(value: T): () => T; - - /** - * Returns undefined irrespective of the arguments passed to it. Useful as the default - * for optional callback arguments. - * Note there is no way to indicate a 'undefined' return, so it is currently typed as void. - * @return undefined - **/ - noop(): void; - - /** - * Invokes the given iterator function n times. - * Each invocation of iterator is called with an index argument - * @param n Number of times to invoke `iterator`. - * @param iterator Function iterator to invoke `n` times. - * @param context `this` object in `iterator`, optional. - **/ - times(n: number, iterator: (n: number) => TResult, context?: any): TResult[]; - - /** - * Returns a random integer between min and max, inclusive. If you only pass one argument, - * it will return a number between 0 and that number. - * @param max The maximum random number. - * @return A random number between 0 and `max`. - **/ - random(max: number): number; - - /** - * @see _.random - * @param min The minimum random number. - * @return A random number between `min` and `max`. - **/ - random(min: number, max: number): number; - - /** - * Allows you to extend Underscore with your own utility functions. Pass a hash of - * {name: function} definitions to have your functions added to the Underscore object, - * as well as the OOP wrapper. - * @param object Mixin object containing key/function pairs to add to the Underscore object. - **/ - mixin(object: any): void; - - /** - * A mostly-internal function to generate callbacks that can be applied to each element - * in a collection, returning the desired result -- either identity, an arbitrary callback, - * a property matcher, or a propetery accessor. - * @param string|Function|Object value The value to iterate over, usually the key. - * @param any context - * @return Callback that can be applied to each element in a collection. - **/ - iteratee(value: string): Function; - iteratee(value: Function, context?: any): Function; - iteratee(value: Object): Function; - - /** - * Generate a globally-unique id for client-side models or DOM elements that need one. - * If prefix is passed, the id will be appended to it. Without prefix, returns an integer. - * @param prefix A prefix string to start the unique ID with. - * @return Unique string ID beginning with `prefix`. - **/ - uniqueId(prefix?: string): string; - - /** - * Escapes a string for insertion into HTML, replacing &, <, >, ", ', and / characters. - * @param str Raw string to escape. - * @return `str` HTML escaped. - **/ - escape(str: string): string; - - /** - * The opposite of escape, replaces &, <, >, ", and ' with their unescaped counterparts. - * @param str HTML escaped string. - * @return `str` Raw string. - **/ - unescape(str: string): string; - - /** - * If the value of the named property is a function then invoke it; otherwise, return it. - * @param object Object to maybe invoke function `property` on. - * @param property The function by name to invoke on `object`. - * @param defaultValue The value to be returned in case `property` doesn't exist or is undefined. - * @return The result of invoking the function `property` on `object. - **/ - result(object: any, property: string, defaultValue?:any): any; - - /** - * Compiles JavaScript templates into functions that can be evaluated for rendering. Useful - * for rendering complicated bits of HTML from JSON data sources. Template functions can both - * interpolate variables, using <%= ... %>, as well as execute arbitrary JavaScript code, with - * <% ... %>. If you wish to interpolate a value, and have it be HTML-escaped, use <%- ... %> When - * you evaluate a template function, pass in a data object that has properties corresponding to - * the template's free variables. If you're writing a one-off, you can pass the data object as - * the second parameter to template in order to render immediately instead of returning a template - * function. The settings argument should be a hash containing any _.templateSettings that should - * be overridden. - * @param templateString Underscore HTML template. - * @param data Data to use when compiling `templateString`. - * @param settings Settings to use while compiling. - * @return Returns the compiled Underscore HTML template. - **/ - template(templateString: string, settings?: _.TemplateSettings): (...data: any[]) => string; - - /** - * By default, Underscore uses ERB-style template delimiters, change the - * following template settings to use alternative delimiters. - **/ - templateSettings: _.TemplateSettings; - - /** - * Returns an integer timestamp for the current time, using the fastest method available in the runtime. Useful for implementing timing/animation functions. - **/ - now(): number; - - /* ********** - * Chaining * - *********** */ - - /** - * Returns a wrapped object. Calling methods on this object will continue to return wrapped objects - * until value() is used. - * @param obj Object to chain. - * @return Wrapped `obj`. - **/ - chain(obj: T[]): _Chain; - chain(obj: _.Dictionary): _Chain; - chain(obj: T): _Chain; -} - -interface Underscore { - - /* ************* - * Collections * - ************* */ - - /** - * Wrapped type `any[]`. - * @see _.each - **/ - each(iterator: _.ListIterator, context?: any): T[]; - - /** - * @see _.each - **/ - each(iterator: _.ObjectIterator, context?: any): T[]; - - /** - * @see _.each - **/ - forEach(iterator: _.ListIterator, context?: any): T[]; - - /** - * @see _.each - **/ - forEach(iterator: _.ObjectIterator, context?: any): T[]; - - /** - * Wrapped type `any[]`. - * @see _.map - **/ - map(iterator: _.ListIterator, context?: any): TResult[]; - - /** - * Wrapped type `any[]`. - * @see _.map - **/ - map(iterator: _.ObjectIterator, context?: any): TResult[]; - - /** - * @see _.map - **/ - collect(iterator: _.ListIterator, context?: any): TResult[]; - - /** - * @see _.map - **/ - collect(iterator: _.ObjectIterator, context?: any): TResult[]; - - /** - * Wrapped type `any[]`. - * @see _.reduce - **/ - reduce(iterator: _.MemoIterator, memo?: TResult, context?: any): TResult; - - /** - * @see _.reduce - **/ - inject(iterator: _.MemoIterator, memo?: TResult, context?: any): TResult; - - /** - * @see _.reduce - **/ - foldl(iterator: _.MemoIterator, memo?: TResult, context?: any): TResult; - - /** - * Wrapped type `any[]`. - * @see _.reduceRight - **/ - reduceRight(iterator: _.MemoIterator, memo?: TResult, context?: any): TResult; - - /** - * @see _.reduceRight - **/ - foldr(iterator: _.MemoIterator, memo?: TResult, context?: any): TResult; - - /** - * Wrapped type `any[]`. - * @see _.find - **/ - find(iterator: _.ListIterator|_.ObjectIterator, context?: any): T; - - /** - * @see _.find - **/ - find(interator: U): T; - - /** - * @see _.find - **/ - find(interator: string): T; - - /** - * @see _.find - **/ - detect(iterator: _.ListIterator|_.ObjectIterator, context?: any): T; - - /** - * @see _.find - **/ - detect(interator?: U): T; - - /** - * @see _.find - **/ - detect(interator?: string): T; - - /** - * Wrapped type `any[]`. - * @see _.filter - **/ - filter(iterator: _.ListIterator, context?: any): T[]; - - /** - * @see _.filter - **/ - select(iterator: _.ListIterator, context?: any): T[]; - - /** - * Wrapped type `any[]`. - * @see _.where - **/ - where(properties: U): T[]; - - /** - * Wrapped type `any[]`. - * @see _.findWhere - **/ - findWhere(properties: U): T; - - /** - * Wrapped type `any[]`. - * @see _.reject - **/ - reject(iterator: _.ListIterator, context?: any): T[]; - - /** - * Wrapped type `any[]`. - * @see _.all - **/ - all(iterator?: _.ListIterator, context?: any): boolean; - - /** - * @see _.all - **/ - every(iterator?: _.ListIterator, context?: any): boolean; - - /** - * Wrapped type `any[]`. - * @see _.any - **/ - any(iterator?: _.ListIterator, context?: any): boolean; - - /** - * @see _.any - **/ - some(iterator?: _.ListIterator, context?: any): boolean; - - /** - * Wrapped type `any[]`. - * @see _.contains - **/ - contains(value: T, fromIndex? : number): boolean; - - /** - * Alias for 'contains'. - * @see contains - **/ - include(value: T, fromIndex? : number): boolean; - - /** - * Alias for 'contains'. - * @see contains - **/ - includes(value: T, fromIndex? : number): boolean; - - /** - * Wrapped type `any[]`. - * @see _.invoke - **/ - invoke(methodName: string, ...arguments: any[]): any; - - /** - * Wrapped type `any[]`. - * @see _.pluck - **/ - pluck(propertyName: string): any[]; - - /** - * Wrapped type `number[]`. - * @see _.max - **/ - max(): number; - - /** - * Wrapped type `any[]`. - * @see _.max - **/ - max(iterator: _.ListIterator, context?: any): T; - - /** - * Wrapped type `any[]`. - * @see _.max - **/ - max(iterator?: _.ListIterator, context?: any): T; - - /** - * Wrapped type `number[]`. - * @see _.min - **/ - min(): number; - - /** - * Wrapped type `any[]`. - * @see _.min - **/ - min(iterator: _.ListIterator, context?: any): T; - - /** - * Wrapped type `any[]`. - * @see _.min - **/ - min(iterator?: _.ListIterator, context?: any): T; - - /** - * Wrapped type `any[]`. - * @see _.sortBy - **/ - sortBy(iterator?: _.ListIterator, context?: any): T[]; - - /** - * Wrapped type `any[]`. - * @see _.sortBy - **/ - sortBy(iterator: string, context?: any): T[]; - - /** - * Wrapped type `any[]`. - * @see _.groupBy - **/ - groupBy(iterator?: _.ListIterator, context?: any): _.Dictionary<_.List>; - - /** - * Wrapped type `any[]`. - * @see _.groupBy - **/ - groupBy(iterator: string, context?: any): _.Dictionary; - - /** - * Wrapped type `any[]`. - * @see _.indexBy - **/ - indexBy(iterator: _.ListIterator, context?: any): _.Dictionary; - - /** - * Wrapped type `any[]`. - * @see _.indexBy - **/ - indexBy(iterator: string, context?: any): _.Dictionary; - - /** - * Wrapped type `any[]`. - * @see _.countBy - **/ - countBy(iterator?: _.ListIterator, context?: any): _.Dictionary; - - /** - * Wrapped type `any[]`. - * @see _.countBy - **/ - countBy(iterator: string, context?: any): _.Dictionary; - - /** - * Wrapped type `any[]`. - * @see _.shuffle - **/ - shuffle(): T[]; - - /** - * Wrapped type `any[]`. - * @see _.sample - **/ - sample(n: number): T[]; - - /** - * @see _.sample - **/ - sample(): T; - - /** - * Wrapped type `any`. - * @see _.toArray - **/ - toArray(): T[]; - - /** - * Wrapped type `any`. - * @see _.size - **/ - size(): number; - - /********* - * Arrays * - **********/ - - /** - * Wrapped type `any[]`. - * @see _.first - **/ - first(): T; - - /** - * Wrapped type `any[]`. - * @see _.first - **/ - first(n: number): T[]; - - /** - * @see _.first - **/ - head(): T; - - /** - * @see _.first - **/ - head(n: number): T[]; - - /** - * @see _.first - **/ - take(): T; - - /** - * @see _.first - **/ - take(n: number): T[]; - - /** - * Wrapped type `any[]`. - * @see _.initial - **/ - initial(n?: number): T[]; - - /** - * Wrapped type `any[]`. - * @see _.last - **/ - last(): T; - - /** - * Wrapped type `any[]`. - * @see _.last - **/ - last(n: number): T[]; - - /** - * Wrapped type `any[]`. - * @see _.rest - **/ - rest(n?: number): T[]; - - /** - * @see _.rest - **/ - tail(n?: number): T[]; - - /** - * @see _.rest - **/ - drop(n?: number): T[]; - - /** - * Wrapped type `any[]`. - * @see _.compact - **/ - compact(): T[]; - - /** - * Wrapped type `any`. - * @see _.flatten - **/ - flatten(shallow?: boolean): any[]; - - /** - * Wrapped type `any[]`. - * @see _.without - **/ - without(...values: T[]): T[]; - - /** - * Wrapped type `any[]`. - * @see _.partition - **/ - partition(iterator: _.ListIterator, context?: any): T[][]; - - /** - * Wrapped type `any[][]`. - * @see _.union - **/ - union(...arrays: _.List[]): T[]; - - /** - * Wrapped type `any[][]`. - * @see _.intersection - **/ - intersection(...arrays: _.List[]): T[]; - - /** - * Wrapped type `any[]`. - * @see _.difference - **/ - difference(...others: _.List[]): T[]; - - /** - * Wrapped type `any[]`. - * @see _.uniq - **/ - uniq(isSorted?: boolean, iterator?: _.ListIterator): T[]; - - /** - * Wrapped type `any[]`. - * @see _.uniq - **/ - uniq(iterator?: _.ListIterator, context?: any): T[]; - - /** - * @see _.uniq - **/ - unique(isSorted?: boolean, iterator?: _.ListIterator): T[]; - - /** - * @see _.uniq - **/ - unique(iterator?: _.ListIterator, context?: any): T[]; - - /** - * Wrapped type `any[][]`. - * @see _.zip - **/ - zip(...arrays: any[][]): any[][]; - - /** - * Wrapped type `any[][]`. - * @see _.unzip - **/ - unzip(...arrays: any[][]): any[][]; - - /** - * Wrapped type `any[][]`. - * @see _.object - **/ - object(...keyValuePairs: any[][]): any; - - /** - * @see _.object - **/ - object(values?: any): any; - - /** - * Wrapped type `any[]`. - * @see _.indexOf - **/ - indexOf(value: T, isSorted?: boolean): number; - - /** - * @see _.indexOf - **/ - indexOf(value: T, startFrom: number): number; - - /** - * Wrapped type `any[]`. - * @see _.lastIndexOf - **/ - lastIndexOf(value: T, from?: number): number; - - /** - * @see _.findIndex - **/ - findIndex(array: _.List, predicate: _.ListIterator | {}, context?: any): number; - - /** - * @see _.findLastIndex - **/ - findLastIndex(array: _.List, predicate: _.ListIterator | {}, context?: any): number; - - /** - * Wrapped type `any[]`. - * @see _.sortedIndex - **/ - sortedIndex(value: T, iterator?: (x: T) => any, context?: any): number; - - /** - * Wrapped type `number`. - * @see _.range - **/ - range(stop: number, step?: number): number[]; - - /** - * Wrapped type `number`. - * @see _.range - **/ - range(): number[]; - - /** - * Wrapped type any[][]. - * @see _.chunk - **/ - chunk(): any[][]; - - /* *********** - * Functions * - ************ */ - - /** - * Wrapped type `Function`. - * @see _.bind - **/ - bind(object: any, ...arguments: any[]): Function; - - /** - * Wrapped type `object`. - * @see _.bindAll - **/ - bindAll(...methodNames: string[]): any; - - /** - * Wrapped type `Function`. - * @see _.partial - **/ - partial(...arguments: any[]): Function; - - /** - * Wrapped type `Function`. - * @see _.memoize - **/ - memoize(hashFn?: (n: any) => string): Function; - - /** - * Wrapped type `Function`. - * @see _.defer - **/ - defer(...arguments: any[]): void; - - /** - * Wrapped type `Function`. - * @see _.delay - **/ - delay(wait: number, ...arguments: any[]): any; - - /** - * @see _.delay - **/ - delay(...arguments: any[]): any; - - /** - * Wrapped type `Function`. - * @see _.throttle - **/ - throttle(wait: number, options?: _.ThrottleSettings): Function & _.Cancelable; - - /** - * Wrapped type `Function`. - * @see _.debounce - **/ - debounce(wait: number, immediate?: boolean): Function & _.Cancelable; - - /** - * Wrapped type `Function`. - * @see _.once - **/ - once(): Function; - - /** - * Wrapped type `Function`. - * @see _.once - **/ - restArgs(starIndex?: number) : Function; - - /** - * Wrapped type `number`. - * @see _.after - **/ - after(fn: Function): Function; - - /** - * Wrapped type `number`. - * @see _.before - **/ - before(fn: Function): Function; - - /** - * Wrapped type `Function`. - * @see _.wrap - **/ - wrap(wrapper: Function): () => Function; - - /** - * Wrapped type `Function`. - * @see _.negate - **/ - negate(): boolean; - - /** - * Wrapped type `Function[]`. - * @see _.compose - **/ - compose(...functions: Function[]): Function; - - /********* * - * Objects * - ********** */ - - /** - * Wrapped type `object`. - * @see _.keys - **/ - keys(): string[]; - - /** - * Wrapped type `object`. - * @see _.allKeys - **/ - allKeys(): string[]; - - /** - * Wrapped type `object`. - * @see _.values - **/ - values(): T[]; - - /** - * Wrapped type `object`. - * @see _.pairs - **/ - pairs(): any[][]; - - /** - * Wrapped type `object`. - * @see _.invert - **/ - invert(): any; - - /** - * Wrapped type `object`. - * @see _.functions - **/ - functions(): string[]; - - /** - * @see _.functions - **/ - methods(): string[]; - - /** - * Wrapped type `object`. - * @see _.extend - **/ - extend(...sources: any[]): any; - - /** - * Wrapped type `object`. - * @see _.extend - **/ - findKey(predicate: _.ObjectIterator, context? : any): any - - /** - * Wrapped type `object`. - * @see _.pick - **/ - pick(...keys: any[]): any; - pick(keys: any[]): any; - pick(fn: (value: any, key: any, object: any) => any): any; - - /** - * Wrapped type `object`. - * @see _.omit - **/ - omit(...keys: string[]): any; - omit(keys: string[]): any; - omit(fn: Function): any; - - /** - * Wrapped type `object`. - * @see _.defaults - **/ - defaults(...defaults: any[]): any; - - /** - * Wrapped type `any`. - * @see _.create - **/ - create(props?: Object): any; - - /** - * Wrapped type `any[]`. - * @see _.clone - **/ - clone(): T; - - /** - * Wrapped type `object`. - * @see _.tap - **/ - tap(interceptor: (...as: any[]) => any): any; - - /** - * Wrapped type `object`. - * @see _.has - **/ - has(key: string): boolean; - - /** - * Wrapped type `any[]`. - * @see _.matches - **/ - matches(): _.ListIterator; - - /** - * Wrapped type `any[]`. - * @see _.matcher - **/ - matcher(): _.ListIterator; - - /** - * Wrapped type `string`. - * @see _.property - **/ - property(): (object: Object) => any; - - /** - * Wrapped type `object`. - * @see _.propertyOf - **/ - propertyOf(): (key: string) => any; - - /** - * Wrapped type `object`. - * @see _.isEqual - **/ - isEqual(other: any): boolean; - - /** - * Wrapped type `object`. - * @see _.isEmpty - **/ - isEmpty(): boolean; - - /** - * Wrapped type `object`. - * @see _.isMatch - **/ - isMatch(): boolean; - - /** - * Wrapped type `object`. - * @see _.isElement - **/ - isElement(): boolean; - - /** - * Wrapped type `object`. - * @see _.isArray - **/ - isArray(): boolean; - - /** - * Wrapped type `object`. - * @see _.isSymbol - **/ - isSymbol(): boolean; - - /** - * Wrapped type `object`. - * @see _.isObject - **/ - isObject(): boolean; - - /** - * Wrapped type `object`. - * @see _.isArguments - **/ - isArguments(): boolean; - - /** - * Wrapped type `object`. - * @see _.isFunction - **/ - isFunction(): boolean; - - /** - * Wrapped type `object`. - * @see _.isError - **/ - isError(): boolean; - - /** - * Wrapped type `object`. - * @see _.isString - **/ - isString(): boolean; - - /** - * Wrapped type `object`. - * @see _.isNumber - **/ - isNumber(): boolean; - - /** - * Wrapped type `object`. - * @see _.isFinite - **/ - isFinite(): boolean; - - /** - * Wrapped type `object`. - * @see _.isBoolean - **/ - isBoolean(): boolean; - - /** - * Wrapped type `object`. - * @see _.isDate - **/ - isDate(): boolean; - - /** - * Wrapped type `object`. - * @see _.isRegExp - **/ - isRegExp(): boolean; - - /** - * Wrapped type `object`. - * @see _.isNaN - **/ - isNaN(): boolean; - - /** - * Wrapped type `object`. - * @see _.isNull - **/ - isNull(): boolean; - - /** - * Wrapped type `object`. - * @see _.isUndefined - **/ - isUndefined(): boolean; - - /********* * - * Utility * - ********** */ - - /** - * Wrapped type `any`. - * @see _.identity - **/ - identity(): any; - - /** - * Wrapped type `any`. - * @see _.constant - **/ - constant(): () => T; - - /** - * Wrapped type `any`. - * @see _.noop - **/ - noop(): void; - - /** - * Wrapped type `number`. - * @see _.times - **/ - times(iterator: (n: number) => TResult, context?: any): TResult[]; - - /** - * Wrapped type `number`. - * @see _.random - **/ - random(): number; - /** - * Wrapped type `number`. - * @see _.random - **/ - random(max: number): number; - - /** - * Wrapped type `object`. - * @see _.mixin - **/ - mixin(): void; - - /** - * Wrapped type `string|Function|Object`. - * @see _.iteratee - **/ - iteratee(context?: any): Function; - - /** - * Wrapped type `string`. - * @see _.uniqueId - **/ - uniqueId(): string; - - /** - * Wrapped type `string`. - * @see _.escape - **/ - escape(): string; - - /** - * Wrapped type `string`. - * @see _.unescape - **/ - unescape(): string; - - /** - * Wrapped type `object`. - * @see _.result - **/ - result(property: string, defaultValue?:any): any; - - /** - * Wrapped type `string`. - * @see _.template - **/ - template(settings?: _.TemplateSettings): (...data: any[]) => string; - - /********** * - * Chaining * - *********** */ - - /** - * Wrapped type `any`. - * @see _.chain - **/ - chain(): _Chain; - - /** - * Wrapped type `any`. - * Extracts the value of a wrapped object. - * @return Value of the wrapped object. - **/ - value(): TResult; -} - -interface _Chain { - - /* ************* - * Collections * - ************* */ - - /** - * Wrapped type `any[]`. - * @see _.each - **/ - each(iterator: _.ListIterator, context?: any): _Chain; - - /** - * @see _.each - **/ - each(iterator: _.ObjectIterator, context?: any): _Chain; - - /** - * @see _.each - **/ - forEach(iterator: _.ListIterator, context?: any): _Chain; - - /** - * @see _.each - **/ - forEach(iterator: _.ObjectIterator, context?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.map - **/ - map(iterator: _.ListIterator, context?: any): _ChainOfArrays; - - /** - * Wrapped type `any[]`. - * @see _.map - **/ - map(iterator: _.ListIterator, context?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.map - **/ - map(iterator: _.ObjectIterator, context?: any): _ChainOfArrays; - - /** - * Wrapped type `any[]`. - * @see _.map - **/ - map(iterator: _.ObjectIterator, context?: any): _Chain; - - /** - * @see _.map - **/ - collect(iterator: _.ListIterator, context?: any): _Chain; - - /** - * @see _.map - **/ - collect(iterator: _.ObjectIterator, context?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.reduce - **/ - reduce(iterator: _.MemoIterator, memo?: TResult, context?: any): _ChainSingle; - - /** - * @see _.reduce - **/ - inject(iterator: _.MemoIterator, memo?: TResult, context?: any): _ChainSingle; - - /** - * @see _.reduce - **/ - foldl(iterator: _.MemoIterator, memo?: TResult, context?: any): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.reduceRight - **/ - reduceRight(iterator: _.MemoIterator, memo?: TResult, context?: any): _ChainSingle; - - /** - * @see _.reduceRight - **/ - foldr(iterator: _.MemoIterator, memo?: TResult, context?: any): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.find - **/ - find(iterator: _.ListIterator|_.ObjectIterator, context?: any): _ChainSingle; - - /** - * @see _.find - **/ - find(interator: U): _ChainSingle; - - /** - * @see _.find - **/ - find(interator: string): _ChainSingle; - - /** - * @see _.find - **/ - detect(iterator: _.ListIterator|_.ObjectIterator, context?: any): _ChainSingle; - - /** - * @see _.find - **/ - detect(interator: U): _ChainSingle; - - /** - * @see _.find - **/ - detect(interator: string): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.filter - **/ - filter(iterator: _.ListIterator, context?: any): _Chain; - - /** - * @see _.filter - **/ - select(iterator: _.ListIterator, context?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.where - **/ - where(properties: U): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.findWhere - **/ - findWhere(properties: U): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.reject - **/ - reject(iterator: _.ListIterator, context?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.all - **/ - all(iterator?: _.ListIterator, context?: any): _ChainSingle; - - /** - * @see _.all - **/ - every(iterator?: _.ListIterator, context?: any): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.any - **/ - any(iterator?: _.ListIterator, context?: any): _ChainSingle; - - /** - * @see _.any - **/ - some(iterator?: _.ListIterator, context?: any): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.contains - **/ - contains(value: T, fromIndex?: number): _ChainSingle; - - /** - * Alias for 'contains'. - * @see contains - **/ - include(value: T, fromIndex?: number): _ChainSingle; - - /** - * Alias for 'contains'. - * @see contains - **/ - includes(value: T, fromIndex?: number): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.invoke - **/ - invoke(methodName: string, ...arguments: any[]): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.pluck - **/ - pluck(propertyName: string): _Chain; - - /** - * Wrapped type `number[]`. - * @see _.max - **/ - max(): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.max - **/ - max(iterator: _.ListIterator, context?: any): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.max - **/ - max(iterator?: _.ListIterator, context?: any): _ChainSingle; - - /** - * Wrapped type `number[]`. - * @see _.min - **/ - min(): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.min - **/ - min(iterator: _.ListIterator, context?: any): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.min - **/ - min(iterator?: _.ListIterator, context?: any): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.sortBy - **/ - sortBy(iterator?: _.ListIterator, context?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.sortBy - **/ - sortBy(iterator: string, context?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.groupBy - **/ - groupBy(iterator?: _.ListIterator, context?: any): _ChainOfArrays; - - /** - * Wrapped type `any[]`. - * @see _.groupBy - **/ - groupBy(iterator: string, context?: any): _ChainOfArrays; - - /** - * Wrapped type `any[]`. - * @see _.indexBy - **/ - indexBy(iterator: _.ListIterator, context?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.indexBy - **/ - indexBy(iterator: string, context?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.countBy - **/ - countBy(iterator?: _.ListIterator, context?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.countBy - **/ - countBy(iterator: string, context?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.shuffle - **/ - shuffle(): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.sample - **/ - sample(n: number): _Chain; - - /** - * @see _.sample - **/ - sample(): _Chain; - - /** - * Wrapped type `any`. - * @see _.toArray - **/ - toArray(): _Chain; - - /** - * Wrapped type `any`. - * @see _.size - **/ - size(): _ChainSingle; - - /********* - * Arrays * - **********/ - - /** - * Wrapped type `any[]`. - * @see _.first - **/ - first(): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.first - **/ - first(n: number): _Chain; - - /** - * @see _.first - **/ - head(): _Chain; - - /** - * @see _.first - **/ - head(n: number): _Chain; - - /** - * @see _.first - **/ - take(): _Chain; - - /** - * @see _.first - **/ - take(n: number): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.initial - **/ - initial(n?: number): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.last - **/ - last(): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.last - **/ - last(n: number): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.rest - **/ - rest(n?: number): _Chain; - - /** - * @see _.rest - **/ - tail(n?: number): _Chain; - - /** - * @see _.rest - **/ - drop(n?: number): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.compact - **/ - compact(): _Chain; - - /** - * Wrapped type `any`. - * @see _.flatten - **/ - flatten(shallow?: boolean): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.without - **/ - without(...values: T[]): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.partition - **/ - partition(iterator: _.ListIterator, context?: any): _Chain; - - /** - * Wrapped type `any[][]`. - * @see _.union - **/ - union(...arrays: _.List[]): _Chain; - - /** - * Wrapped type `any[][]`. - * @see _.intersection - **/ - intersection(...arrays: _.List[]): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.difference - **/ - difference(...others: _.List[]): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.uniq - **/ - uniq(isSorted?: boolean, iterator?: _.ListIterator): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.uniq - **/ - uniq(iterator?: _.ListIterator, context?: any): _Chain; - - /** - * @see _.uniq - **/ - unique(isSorted?: boolean, iterator?: _.ListIterator): _Chain; - - /** - * @see _.uniq - **/ - unique(iterator?: _.ListIterator, context?: any): _Chain; - - /** - * Wrapped type `any[][]`. - * @see _.zip - **/ - zip(...arrays: any[][]): _Chain; - - /** - * Wrapped type `any[][]`. - * @see _.unzip - **/ - unzip(...arrays: any[][]): _Chain; - - /** - * Wrapped type `any[][]`. - * @see _.object - **/ - object(...keyValuePairs: any[][]): _Chain; - - /** - * @see _.object - **/ - object(values?: any): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.indexOf - **/ - indexOf(value: T, isSorted?: boolean): _ChainSingle; - - /** - * @see _.indexOf - **/ - indexOf(value: T, startFrom: number): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.lastIndexOf - **/ - lastIndexOf(value: T, from?: number): _ChainSingle; - - /** - * @see _.findIndex - **/ - findIndex(predicate: _.ListIterator | {}, context?: any): _ChainSingle; - - /** - * @see _.findLastIndex - **/ - findLastIndex(predicate: _.ListIterator | {}, context?: any): _ChainSingle; - - /** - * Wrapped type `any[]`. - * @see _.sortedIndex - **/ - sortedIndex(value: T, iterator?: (x: T) => any, context?: any): _ChainSingle; - - /** - * Wrapped type `number`. - * @see _.range - **/ - range(stop: number, step?: number): _Chain; - - /** - * Wrapped type `number`. - * @see _.range - **/ - range(): _Chain; - - /** - * Wrapped type `any[][]`. - * @see _.chunk - **/ - chunk(): _Chain; - - /* *********** - * Functions * - ************ */ - - /** - * Wrapped type `Function`. - * @see _.bind - **/ - bind(object: any, ...arguments: any[]): _Chain; - - /** - * Wrapped type `object`. - * @see _.bindAll - **/ - bindAll(...methodNames: string[]): _Chain; - - /** - * Wrapped type `Function`. - * @see _.partial - **/ - partial(...arguments: any[]): _Chain; - - /** - * Wrapped type `Function`. - * @see _.memoize - **/ - memoize(hashFn?: (n: any) => string): _Chain; - - /** - * Wrapped type `Function`. - * @see _.defer - **/ - defer(...arguments: any[]): _Chain; - - /** - * Wrapped type `Function`. - * @see _.delay - **/ - delay(wait: number, ...arguments: any[]): _Chain; - - /** - * @see _.delay - **/ - delay(...arguments: any[]): _Chain; - - /** - * Wrapped type `Function`. - * @see _.throttle - **/ - throttle(wait: number, options?: _.ThrottleSettings): _Chain; - - /** - * Wrapped type `Function`. - * @see _.debounce - **/ - debounce(wait: number, immediate?: boolean): _Chain; - - /** - * Wrapped type `Function`. - * @see _.once - **/ - once(): _Chain; - - /** - * Wrapped type `Function`. - * @see _.once - **/ - restArgs(startIndex? : number): _Chain; - - /** - * Wrapped type `number`. - * @see _.after - **/ - after(func: Function): _Chain; - - /** - * Wrapped type `number`. - * @see _.before - **/ - before(fn: Function): _Chain; - - /** - * Wrapped type `Function`. - * @see _.wrap - **/ - wrap(wrapper: Function): () => _Chain; - - /** - * Wrapped type `Function`. - * @see _.negate - **/ - negate(): _Chain; - - /** - * Wrapped type `Function[]`. - * @see _.compose - **/ - compose(...functions: Function[]): _Chain; - - /********* * - * Objects * - ********** */ - - /** - * Wrapped type `object`. - * @see _.keys - **/ - keys(): _Chain; - - /** - * Wrapped type `object`. - * @see _.allKeys - **/ - allKeys(): _Chain; - - /** - * Wrapped type `object`. - * @see _.values - **/ - values(): _Chain; - - /** - * Wrapped type `object`. - * @see _.pairs - **/ - pairs(): _Chain; - - /** - * Wrapped type `object`. - * @see _.invert - **/ - invert(): _Chain; - - /** - * Wrapped type `object`. - * @see _.functions - **/ - functions(): _Chain; - - /** - * @see _.functions - **/ - methods(): _Chain; - - /** - * Wrapped type `object`. - * @see _.extend - **/ - extend(...sources: any[]): _Chain; - - /** - * Wrapped type `object`. - * @see _.extend - **/ - findKey(predicate: _.ObjectIterator, context? : any): _Chain - - /** - * Wrapped type `object`. - * @see _.pick - **/ - pick(...keys: any[]): _Chain; - pick(keys: any[]): _Chain; - pick(fn: (value: any, key: any, object: any) => any): _Chain; - - /** - * Wrapped type `object`. - * @see _.omit - **/ - omit(...keys: string[]): _Chain; - omit(keys: string[]): _Chain; - omit(iteratee: Function): _Chain; - - /** - * Wrapped type `object`. - * @see _.defaults - **/ - defaults(...defaults: any[]): _Chain; - - /** - * Wrapped type `any`. - * @see _.create - **/ - create(props?: Object): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.clone - **/ - clone(): _Chain; - - /** - * Wrapped type `object`. - * @see _.tap - **/ - tap(interceptor: (...as: any[]) => any): _Chain; - - /** - * Wrapped type `object`. - * @see _.has - **/ - has(key: string): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.matches - **/ - matches(): _Chain; - - /** - * Wrapped type `any[]`. - * @see _.matcher - **/ - matcher(): _Chain; - - /** - * Wrapped type `string`. - * @see _.property - **/ - property(): _Chain; - - /** - * Wrapped type `object`. - * @see _.propertyOf - **/ - propertyOf(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isEqual - **/ - isEqual(other: any): _Chain; - - /** - * Wrapped type `object`. - * @see _.isEmpty - **/ - isEmpty(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isMatch - **/ - isMatch(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isElement - **/ - isElement(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isArray - **/ - isArray(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isSymbol - **/ - isSymbol(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isObject - **/ - isObject(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isArguments - **/ - isArguments(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isFunction - **/ - isFunction(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isError - **/ - isError(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isString - **/ - isString(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isNumber - **/ - isNumber(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isFinite - **/ - isFinite(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isBoolean - **/ - isBoolean(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isDate - **/ - isDate(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isRegExp - **/ - isRegExp(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isNaN - **/ - isNaN(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isNull - **/ - isNull(): _Chain; - - /** - * Wrapped type `object`. - * @see _.isUndefined - **/ - isUndefined(): _Chain; - - /********* * - * Utility * - ********** */ - - /** - * Wrapped type `any`. - * @see _.identity - **/ - identity(): _Chain; - - /** - * Wrapped type `any`. - * @see _.constant - **/ - constant(): _Chain; - - /** - * Wrapped type `any`. - * @see _.noop - **/ - noop(): _Chain; - - /** - * Wrapped type `number`. - * @see _.times - **/ - times(iterator: (n: number) => TResult, context?: any): _Chain; - - /** - * Wrapped type `number`. - * @see _.random - **/ - random(): _Chain; - /** - * Wrapped type `number`. - * @see _.random - **/ - random(max: number): _Chain; - - /** - * Wrapped type `object`. - * @see _.mixin - **/ - mixin(): _Chain; - - /** - * Wrapped type `string|Function|Object`. - * @see _.iteratee - **/ - iteratee(context?: any): _Chain; - - /** - * Wrapped type `string`. - * @see _.uniqueId - **/ - uniqueId(): _Chain; - - /** - * Wrapped type `string`. - * @see _.escape - **/ - escape(): _Chain; - - /** - * Wrapped type `string`. - * @see _.unescape - **/ - unescape(): _Chain; - - /** - * Wrapped type `object`. - * @see _.result - **/ - result(property: string, defaultValue?:any): _Chain; - - /** - * Wrapped type `string`. - * @see _.template - **/ - template(settings?: _.TemplateSettings): (...data: any[]) => _Chain; - - /************* * - * Array proxy * - ************** */ - - /** - * Returns a new array comprised of the array on which it is called - * joined with the array(s) and/or value(s) provided as arguments. - * @param arr Arrays and/or values to concatenate into a new array. See the discussion below for details. - * @return A new array comprised of the array on which it is called - **/ - concat(...arr: Array): _Chain; - - /** - * Join all elements of an array into a string. - * @param separator Optional. Specifies a string to separate each element of the array. The separator is converted to a string if necessary. If omitted, the array elements are separated with a comma. - * @return The string conversions of all array elements joined into one string. - **/ - join(separator?: any): _ChainSingle; - - /** - * Removes the last element from an array and returns that element. - * @return Returns the popped element. - **/ - pop(): _ChainSingle; - - /** - * Adds one or more elements to the end of an array and returns the new length of the array. - * @param item The elements to add to the end of the array. - * @return The array with the element added to the end. - **/ - push(...item: Array): _Chain; - - /** - * Reverses an array in place. The first array element becomes the last and the last becomes the first. - * @return The reversed array. - **/ - reverse(): _Chain; - - /** - * Removes the first element from an array and returns that element. This method changes the length of the array. - * @return The shifted element. - **/ - shift(): _ChainSingle; - - /** - * Returns a shallow copy of a portion of an array into a new array object. - * @param start Zero-based index at which to begin extraction. - * @param end Optional. Zero-based index at which to end extraction. slice extracts up to but not including end. - * @return A shallow copy of a portion of an array into a new array object. - **/ - slice(start: number, end?: number): _Chain; - - /** - * Sorts the elements of an array in place and returns the array. The sort is not necessarily stable. The default sort order is according to string Unicode code points. - * @param compareFn Optional. Specifies a function that defines the sort order. If omitted, the array is sorted according to each character's Unicode code point value, according to the string conversion of each element. - * @return The sorted array. - **/ - sort(compareFn: (a: T, b: T) => boolean): _Chain; - - /** - * Changes the content of an array by removing existing elements and/or adding new elements. - * @param index Index at which to start changing the array. If greater than the length of the array, actual starting index will be set to the length of the array. If negative, will begin that many elements from the end. - * @param quantity An integer indicating the number of old array elements to remove. If deleteCount is 0, no elements are removed. In this case, you should specify at least one new element. If deleteCount is greater than the number of elements left in the array starting at index, then all of the elements through the end of the array will be deleted. - * @param items The element to add to the array. If you don't specify any elements, splice will only remove elements from the array. - * @return An array containing the deleted elements. If only one element is removed, an array of one element is returned. If no elements are removed, an empty array is returned. - **/ - splice(index: number, quantity: number, ...items: Array): _Chain; - - /** - * A string representing the specified array and its elements. - * @return A string representing the specified array and its elements. - **/ - toString(): _ChainSingle; - - /** - * Adds one or more elements to the beginning of an array and returns the new length of the array. - * @param items The elements to add to the front of the array. - * @return The array with the element added to the beginning. - **/ - unshift(...items: Array): _Chain; - - /********** * - * Chaining * - *********** */ - - /** - * Wrapped type `any`. - * @see _.chain - **/ - chain(): _Chain; - - /** - * Wrapped type `any`. - * @see _.value - **/ - value(): T[]; -} -interface _ChainSingle { - value(): T; -} -interface _ChainOfArrays extends _Chain { - flatten(shallow?: boolean): _Chain; - mapObject(fn: _.ListIterator): _ChainOfArrays; -} - -declare var _: UnderscoreStatic; - -declare module "underscore" { - export = _; -} From 7a7c62e92381279e6b5aefb052b7d702df00a438 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 20:04:15 -0400 Subject: [PATCH 010/111] Remove unused line from .gitignore --- .gitignore | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitignore b/.gitignore index e631b300bcf..6cebaca4f5b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,3 @@ typings/.basedir.ts # vim swap files *.swo *.swp - -# grunt-ts, see See https://github.com/grunt-ts/grunt-ts/issues/77 -.baseDir.ts From db0e417436fd09917de03becdb99a171486a373f Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 20:09:53 -0400 Subject: [PATCH 011/111] Remove TypeScript copyright notice now that we no longer bundle the compiler source --- TypeScriptNotice.txt | 172 ------------------------------------------- 1 file changed, 172 deletions(-) delete mode 100644 TypeScriptNotice.txt diff --git a/TypeScriptNotice.txt b/TypeScriptNotice.txt deleted file mode 100644 index 3707ec2b970..00000000000 --- a/TypeScriptNotice.txt +++ /dev/null @@ -1,172 +0,0 @@ -/****************************************************************************** -This project incorporates material and code from the Microsoft TypeScript project: -http://www.typescriptlang.org/ licensed under the Apache Version 2.0 License - -Relevant notice and copyright provisions for TypeScript are below. - -**************************************************************/ - - - -/* ***************************************************************************** -Copyright (c) Microsoft Corporation. All rights reserved. -Licensed under the Apache License, Version 2.0 (the "License"); you may not use -this file except in compliance with the License. You may obtain a copy of the -License at http://www.apache.org/licenses/LICENSE-2.0 - -THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED -WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, -MERCHANTABLITY OR NON-INFRINGEMENT. - -See the Apache Version 2.0 License for specific language governing permissions -and limitations under the License. -***************************************************************************** */ - - -/*----------------- TypeScript ThirdPartyNotices ------------------------------------------------------- - -The TypeScript software is based on or incorporates material and code from the projects listed below -(collectively "Third Party Code"). Microsoft is not the original author of the -Third Party Code. The original copyright notice and the license, under which -Microsoft received such Third Party Code, are set forth below. Such license and -notices are provided for informational purposes only. Microsoft licenses the Third -Party Code to you under the terms of the Apache 2.0 License. -All Third Party Code licensed by Microsoft under the Apache License, Version 2.0 (the "License"); you -may not use this file except in compliance with the License. You may obtain a copy -of the License at http://www.apache.org/licenses/LICENSE-2.0 - -THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, -EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR -CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. - -See the Apache Version 2.0 License for specific language governing permissions and -limitations under the License. ---------------------------------------------- -Third Party Code Components --------------------------------------------- ----- Mozilla Developer Code--------- -The following Mozilla Developer Code is under Public Domain as updated after Aug. 20, 2012, see, https://developer.mozilla.org/en-US/docs/Project:Copyrights -1. Array filter Compatibility Method, -Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter -Any copyright is dedicated to the Public Domain. - -2. Array forEach Compatibility Method, -Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach -Any copyright is dedicated to the Public Domain. - -3. Array indexOf Compatibility Method, -Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/indexOf -Any copyright is dedicated to the Public Domain. - -4. Array map Compatibility Method, -Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map -Any copyright is dedicated to the Public Domain. - -5. Array Reduce Compatibility Method, -Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/Reduce -Any copyright is dedicated to the Public Domain. - -6. String Trim Compatibility Method, -Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/Trim -Any copyright is dedicated to the Public Domain. - -7. Date now Compatibility Method, -Available at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/now -Any copyright is dedicated to the Public Domain. - -------------JSON2 Script------------------------ -json2.js 2012-10-08 -Public Domain. -NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. -See, http://www.JSON.org/js.html - ---------------r.js---------------------- -Copyright (c) 2010-2011 Dojo Foundation. All Rights Reserved. -Originally License under MIT License -------------------------------------------------------------------------- -Provided for Informational Purposes Only -MIT License - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --------------------------------------------------------------------------------------- - -------------- End of ThirdPartyNotices --------------------------------------------------- */ - - - - - - -Apache License - -Version 2.0, January 2004 - -http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - -"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. - -"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. - -"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - -"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. - -"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. - -"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. - -"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). - -"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. - -"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." - -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: - -You must give any other recipients of the Work or Derivative Works a copy of this License; and - -You must cause any modified files to carry prominent notices stating that You changed the files; and - -You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and - -If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS From 5cd9757b747a9cac4d5f19bb057242344c51bf10 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 20:37:42 -0400 Subject: [PATCH 012/111] Deprecate no-unused-variable rule (#1618) Resolves #1481. Adds a `deprecationMessage` field to rule metadata. --- src/configs/recommended.ts | 3 ++- src/language/rule/rule.ts | 5 ++++ src/ruleLoader.ts | 4 ++++ src/rules/noUnusedVariableRule.ts | 3 ++- src/tslintMulti.ts | 38 +++++++++++++++---------------- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index 2f4992afa3b..690a5092caa 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -68,7 +68,8 @@ export const rules = { "no-unreachable": true, "no-unused-expression": true, "no-unused-new": true, - "no-unused-variable": [true, "react"], + // deprecated as of v4.0 + "no-unused-variable": false, // disable this rule as it is very heavy performance-wise and not that useful "no-use-before-declare": false, "no-var-keyword": true, diff --git a/src/language/rule/rule.ts b/src/language/rule/rule.ts index a4311e425b7..01e257a29bf 100644 --- a/src/language/rule/rule.ts +++ b/src/language/rule/rule.ts @@ -30,6 +30,11 @@ export interface IRuleMetadata { */ type: RuleType; + /** + * A rule deprecation message, if applicable. + */ + deprecationMessage?: string; + /** * A short, one line description of what the rule does. */ diff --git a/src/ruleLoader.ts b/src/ruleLoader.ts index de2634c4849..63689f8f20b 100644 --- a/src/ruleLoader.ts +++ b/src/ruleLoader.ts @@ -48,6 +48,10 @@ export function loadRules(ruleConfiguration: {[name: string]: any}, const ruleSpecificList = (ruleName in enableDisableRuleMap ? enableDisableRuleMap[ruleName] : []); const disabledIntervals = buildDisabledIntervalsFromSwitches(ruleSpecificList, allList); rules.push(new Rule(ruleName, ruleValue, disabledIntervals)); + + if (Rule.metadata && Rule.metadata.deprecationMessage) { + console.warn(`${Rule.metadata.ruleName} is deprecated. ${Rule.metadata.deprecationMessage}`); + } } } } diff --git a/src/rules/noUnusedVariableRule.ts b/src/rules/noUnusedVariableRule.ts index 886ed620b0a..a20b24b625d 100644 --- a/src/rules/noUnusedVariableRule.ts +++ b/src/rules/noUnusedVariableRule.ts @@ -31,6 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ public static metadata: Lint.IRuleMetadata = { ruleName: "no-unused-variable", + deprecationMessage: "Use the compiler options --noUnusedParameters and --noUnusedLocals instead.", description: "Disallows unused imports, variables, functions and private class members.", optionsDescription: Lint.Utils.dedent` Three optional arguments may be optionally provided: @@ -331,7 +332,7 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker { node.modifiers, ts.SyntaxKind.PublicKeyword, ts.SyntaxKind.PrivateKeyword, - ts.SyntaxKind.ProtectedKeyword + ts.SyntaxKind.ProtectedKeyword, ); if (!isSingleVariable && isPropertyParameter) { diff --git a/src/tslintMulti.ts b/src/tslintMulti.ts index 471fd636e37..7ef35aa9435 100644 --- a/src/tslintMulti.ts +++ b/src/tslintMulti.ts @@ -132,25 +132,25 @@ class MultiLinter { } public getResult(): LintResult { - let formatter: IFormatter; - const formattersDirectory = getRelativePath(this.options.formattersDirectory); - - const formatterName = this.options.formatter || "prose"; - const Formatter = findFormatter(formatterName, formattersDirectory); - if (Formatter) { - formatter = new Formatter(); - } else { - throw new Error(`formatter '${formatterName}' not found`); - } - - const output = formatter.format(this.failures); - - return { - failureCount: this.failures.length, - failures: this.failures, - format: formatterName, - output, - }; + let formatter: IFormatter; + const formattersDirectory = getRelativePath(this.options.formattersDirectory); + + const formatterName = this.options.formatter || "prose"; + const Formatter = findFormatter(formatterName, formattersDirectory); + if (Formatter) { + formatter = new Formatter(); + } else { + throw new Error(`formatter '${formatterName}' not found`); + } + + const output = formatter.format(this.failures); + + return { + failureCount: this.failures.length, + failures: this.failures, + format: formatterName, + output, + }; } private containsRule(rules: RuleFailure[], rule: RuleFailure) { From 39ba6ade68a4a5d35332acb09e40d9546ce0eba8 Mon Sep 17 00:00:00 2001 From: Jay Anslow Date: Mon, 10 Oct 2016 04:32:19 +0100 Subject: [PATCH 013/111] Add "any" order options for "ordered-imports" rule (#1602) --- src/rules/orderedImportsRule.ts | 7 +++-- .../import-sources-any/test.ts.lint | 31 +++++++++++++++++++ .../import-sources-any/tslint.json | 5 +++ .../named-imports-any/test.ts.lint | 30 ++++++++++++++++++ .../named-imports-any/tslint.json | 5 +++ 5 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 test/rules/ordered-imports/import-sources-any/test.ts.lint create mode 100644 test/rules/ordered-imports/import-sources-any/tslint.json create mode 100644 test/rules/ordered-imports/named-imports-any/test.ts.lint create mode 100644 test/rules/ordered-imports/named-imports-any/tslint.json diff --git a/src/rules/orderedImportsRule.ts b/src/rules/orderedImportsRule.ts index d90e636fa1e..7c222611821 100644 --- a/src/rules/orderedImportsRule.ts +++ b/src/rules/orderedImportsRule.ts @@ -42,6 +42,7 @@ export class Rule extends Lint.Rules.AbstractRule { * \`"case-insensitive'\`: Correct order is \`"Bar"\`, \`"baz"\`, \`"Foo"\`. (This is the default.) * \`"lowercase-first"\`: Correct order is \`"baz"\`, \`"Bar"\`, \`"Foo"\`. * \`"lowercase-last"\`: Correct order is \`"Bar"\`, \`"Foo"\`, \`"baz"\`. + * \`"any"\`: Allow any order. You may set the \`"named-imports-order"\` option to control the ordering of named imports (the \`{A, B, C}\` in \`import {A, B, C} from "foo"\`). @@ -51,6 +52,7 @@ export class Rule extends Lint.Rules.AbstractRule { * \`"case-insensitive'\`: Correct order is \`{A, b, C}\`. (This is the default.) * \`"lowercase-first"\`: Correct order is \`{b, A, C}\`. * \`"lowercase-last"\`: Correct order is \`{A, C, b}\`. + * \`"any"\`: Allow any order. `, options: { @@ -58,11 +60,11 @@ export class Rule extends Lint.Rules.AbstractRule { properties: { "import-sources-order": { type: "string", - enum: ["case-insensitive", "lowercase-first", "lowercase-last"], + enum: ["case-insensitive", "lowercase-first", "lowercase-last", "any"], }, "named-imports-order": { type: "string", - enum: ["case-insensitive", "lowercase-first", "lowercase-last"], + enum: ["case-insensitive", "lowercase-first", "lowercase-last", "any"], }, }, additionalProperties: false, @@ -110,6 +112,7 @@ function findUnsortedPair(xs: ts.Node[], transform: (x: string) => string): [ts. // Transformations to apply to produce the desired ordering of imports. // The imports must be lexicographically sorted after applying the transform. const TRANSFORMS: {[ordering: string]: (x: string) => string} = { + any: () => "", "case-insensitive": (x: string) => x.toLowerCase(), "lowercase-first": flipCase, "lowercase-last": (x: string) => x, diff --git a/test/rules/ordered-imports/import-sources-any/test.ts.lint b/test/rules/ordered-imports/import-sources-any/test.ts.lint new file mode 100644 index 00000000000..ab21388c54c --- /dev/null +++ b/test/rules/ordered-imports/import-sources-any/test.ts.lint @@ -0,0 +1,31 @@ +// Named imports should be alphabetized. +import {A, B} from 'foo'; +import {B, A} from 'foo'; // failure + ~~~~ [ordered-imports] + +// Case is irrelevant for named import ordering. +import {A, b, C} from 'foo'; +import {b, A, C} from 'foo'; // failure + ~~~~ [ordered-imports] + + +// Import sources don't need to be alphabetized. +import * as bar from 'bar'; +import * as foo from 'foo'; + +import * as abc from 'abc'; +import * as foo from 'foo'; +import * as bar from 'bar'; // should not fail + +// Case is irrelevant for source import ordering. +import {A, B} from 'Bar'; +import {A, B} from 'baz'; +import {A, B} from 'Foo'; // should not fail + +// Other styles of import statements. +import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; +import someDefault from "module"; +import "something"; + +[ordered-imports]: Named imports must be alphabetized. +[ordered-sources]: Import sources within a group must be alphabetized. diff --git a/test/rules/ordered-imports/import-sources-any/tslint.json b/test/rules/ordered-imports/import-sources-any/tslint.json new file mode 100644 index 00000000000..a88bcb08b5d --- /dev/null +++ b/test/rules/ordered-imports/import-sources-any/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "ordered-imports": [true, {"import-sources-order": "any"}] + } +} diff --git a/test/rules/ordered-imports/named-imports-any/test.ts.lint b/test/rules/ordered-imports/named-imports-any/test.ts.lint new file mode 100644 index 00000000000..2e55118821b --- /dev/null +++ b/test/rules/ordered-imports/named-imports-any/test.ts.lint @@ -0,0 +1,30 @@ +// Named imports do not need to be alphabetized. +import {A, B} from 'foo'; +import {B, A} from 'foo'; // should not fail + +// Case is irrelevant for named import ordering. +import {A, b, C} from 'foo'; +import {b, A, C} from 'foo'; // should not fail + + +// Import sources should be alphabetized. +import * as bar from 'bar'; +import * as foo from 'foo'; + +import * as abc from 'abc'; +import * as foo from 'foo'; +import * as bar from 'bar'; // failure +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [ordered-sources] + +// Case is irrelevant for source import ordering. +import {A, B} from 'Bar'; +import {A, B} from 'baz'; +import {A, B} from 'Foo'; // should not fail + +// Other styles of import statements. +import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; +import someDefault from "module"; +import "something"; + +[ordered-imports]: Named imports must be alphabetized. +[ordered-sources]: Import sources within a group must be alphabetized. diff --git a/test/rules/ordered-imports/named-imports-any/tslint.json b/test/rules/ordered-imports/named-imports-any/tslint.json new file mode 100644 index 00000000000..89be91b2528 --- /dev/null +++ b/test/rules/ordered-imports/named-imports-any/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "ordered-imports": [true, {"named-imports-order": "any"}] + } +} From 82cd3ac92f30ac8204b63bcff339f709565dab94 Mon Sep 17 00:00:00 2001 From: Raghav Katyal Date: Sun, 9 Oct 2016 20:35:47 -0700 Subject: [PATCH 014/111] Fix object enumeration bug in adjacent-overload-signatures (#1454) --- src/rules/adjacentOverloadSignaturesRule.ts | 3 ++- test/rules/adjacent-overload-signatures/test.ts.lint | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/rules/adjacentOverloadSignaturesRule.ts b/src/rules/adjacentOverloadSignaturesRule.ts index 2c5b711d467..e3959157a97 100644 --- a/src/rules/adjacentOverloadSignaturesRule.ts +++ b/src/rules/adjacentOverloadSignaturesRule.ts @@ -58,7 +58,7 @@ class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker { if (member.name !== undefined) { const methodName = getTextOfPropertyName(member.name); if (methodName !== undefined) { - if (seen[methodName] && last !== methodName) { + if (seen.hasOwnProperty(methodName) && last !== methodName) { this.addFailure(this.createFailure(member.getStart(), member.getWidth(), Rule.FAILURE_STRING_FACTORY(methodName))); } @@ -85,6 +85,7 @@ function getTextOfPropertyName(name: ts.PropertyName): string { if (isLiteralExpression(expression)) { return expression.text; } + break; default: if (isLiteralExpression(name)) { return name.text; diff --git a/test/rules/adjacent-overload-signatures/test.ts.lint b/test/rules/adjacent-overload-signatures/test.ts.lint index 7379405b1b8..92087ae57ea 100644 --- a/test/rules/adjacent-overload-signatures/test.ts.lint +++ b/test/rules/adjacent-overload-signatures/test.ts.lint @@ -32,6 +32,10 @@ interface i5 { } } +interface i6 { + toString(): string; +} + // bad From 3de891013c008f5953fe1d8a4ce904a7653ca04d Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sun, 9 Oct 2016 23:38:01 -0400 Subject: [PATCH 015/111] Add explanatory comment for #1454 --- test/rules/adjacent-overload-signatures/test.ts.lint | 1 + 1 file changed, 1 insertion(+) diff --git a/test/rules/adjacent-overload-signatures/test.ts.lint b/test/rules/adjacent-overload-signatures/test.ts.lint index 92087ae57ea..c7e10afcb2e 100644 --- a/test/rules/adjacent-overload-signatures/test.ts.lint +++ b/test/rules/adjacent-overload-signatures/test.ts.lint @@ -33,6 +33,7 @@ interface i5 { } interface i6 { + // ensure no false positives for properties/methods available from prototype chain toString(): string; } From 67ecb54ff791903be750350ac2fc1a6afc76defa Mon Sep 17 00:00:00 2001 From: Ben Coveney Date: Mon, 10 Oct 2016 15:17:39 +0100 Subject: [PATCH 016/111] Updated README Formatters (#1621) --- README.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9c77ceae6ff..fca9b0316e5 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Table of Contents - [Installation](#installation) - [Usage](#usage) - [Core Rules](#core-rules) +- [Core Formatters](#core-formatters) - [Rule Flags](#rule-flags) - [Custom Rules](#custom-rules) - [Development](#development) @@ -251,17 +252,10 @@ Core Rules Core Formatters ----- +[back to ToC ↑](#table-of-contents) -Formatters are used to format the results of the linter before outputting it to stdout or -the configured output file. The core formatters are: - -- __prose__: human readable (default) -- __json__: machine readable -- __verbose__: human readable (includes rule names) -- __pmd__ -- __msbuild__ -- __checkstyle__ -- __vso__ +[See the TSLint website for a list of core formatters included in the `tslint` package.] +(http://palantir.github.io/tslint/formatters/) Rule Flags ----- From 231a6a9335cde1ed754571bb6f124cc1197a5aa3 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 10 Oct 2016 10:20:42 -0400 Subject: [PATCH 017/111] One-liner descriptions for rules & formatters in README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index fca9b0316e5..eb297d9b95d 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,8 @@ Core Rules ----- [back to ToC ↑](#table-of-contents) +_Rules_ encode logic for syntactic & semantic checks of TypeScript source code. + [See the TSLint website for a list of core rules included in the `tslint` package.] (http://palantir.github.io/tslint/rules/) @@ -254,6 +256,8 @@ Core Formatters ----- [back to ToC ↑](#table-of-contents) +_Formatters_ allow for transformation of lint results into various forms before outputting to stdout or a file. + [See the TSLint website for a list of core formatters included in the `tslint` package.] (http://palantir.github.io/tslint/formatters/) From eadbca9389439ab8685ebe0a50fd63a3fe340930 Mon Sep 17 00:00:00 2001 From: Jason Killian Date: Tue, 11 Oct 2016 22:05:57 -0400 Subject: [PATCH 018/111] fix test script by executing it with the right shell (#1625) --- test/check-bin.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/check-bin.sh b/test/check-bin.sh index 7b87e33a548..ac468dc115d 100755 --- a/test/check-bin.sh +++ b/test/check-bin.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Palantir Technologies, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); From a960938e4cbda8c608652821cd62e09f4e14bffb Mon Sep 17 00:00:00 2001 From: Mingye Wang Date: Thu, 13 Oct 2016 11:12:28 -0400 Subject: [PATCH 019/111] use some bash arithmetics (#1627) ... to replace expr command and [ (string eq) --- test/check-bin.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/check-bin.sh b/test/check-bin.sh index ac468dc115d..26fb0de9dc9 100755 --- a/test/check-bin.sh +++ b/test/check-bin.sh @@ -26,7 +26,7 @@ expectOut () { # if Node 0.10.*, node will sometimes exit with status 8 when an error is thrown if [[ $expect != $actual || $nodeV == v0.10.* && $expect == 1 && $actual == 8 ]] ; then echo "$msg: expected $expect got $actual" - num_failures=$(expr $num_failures + 1) + ((num_failures += 1)) fi } @@ -85,7 +85,7 @@ fi ./tslint --init if [ ! -f tslint.json ]; then echo "--init failed, tslint.json not created" - num_failures=$(expr $num_failures + 1) + ((num_failures += 1)) fi expectOut $? 0 "tslint with --init flag did not exit correctly" @@ -125,7 +125,7 @@ expectOut $? 0 "tslint with tsconfig did not exit correctly" ./bin/tslint -c test/files/tsconfig-test/tslint.json --project test/files/tsconfig-test/tsconfig.json test/files/tsconfig-test/other.test.ts expectOut $? 2 "tslint with tsconfig and files did not find lint failures from given files" -if [ $num_failures != 0 ]; then +if (( num_failures != 0 )); then echo "Failed $num_failures tests" exit 1 else From 0c0e0e8d7641db4e127870f3a0794ee606d93ac3 Mon Sep 17 00:00:00 2001 From: Cyril Gandon Date: Fri, 14 Oct 2016 20:00:36 +0200 Subject: [PATCH 020/111] Fix no-empty rule on readonly modifier on parameters (#1630) Fixes #1629. --- src/rules/noEmptyRule.ts | 3 ++- test/rules/no-empty/test.ts.lint | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rules/noEmptyRule.ts b/src/rules/noEmptyRule.ts index d3a3e20e536..8b95bc9e61b 100644 --- a/src/rules/noEmptyRule.ts +++ b/src/rules/noEmptyRule.ts @@ -67,7 +67,8 @@ class BlockWalker extends Lint.RuleWalker { param.modifiers, ts.SyntaxKind.PrivateKeyword, ts.SyntaxKind.ProtectedKeyword, - ts.SyntaxKind.PublicKeyword + ts.SyntaxKind.PublicKeyword, + ts.SyntaxKind.ReadonlyKeyword ); if (hasPropertyAccessModifier) { diff --git a/test/rules/no-empty/test.ts.lint b/test/rules/no-empty/test.ts.lint index 0bbc38c017a..9abc44e9d88 100644 --- a/test/rules/no-empty/test.ts.lint +++ b/test/rules/no-empty/test.ts.lint @@ -40,3 +40,8 @@ class testClass3 { } ~~~~~ [block is empty] } + +class testClass4 { + constructor(readonly allowed: any) { + } +} From 3b466ca6a7651a0524c66f19e4646ec59e1620bd Mon Sep 17 00:00:00 2001 From: Andrii Dieiev Date: Mon, 17 Oct 2016 02:36:19 +0300 Subject: [PATCH 021/111] Use rimraf to make clean task work on Windows (#1633) --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3907b35d8fb..4d7aad8681b 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,8 @@ ], "scripts": { "clean": "npm-run-all -p clean:core clean:test", - "clean:core": "rm -rf lib", - "clean:test": "rm -rf build && rm -rf test/config/node_modules", + "clean:core": "rimraf lib", + "clean:test": "rimraf build && rimraf test/config/node_modules", "docs": "node scripts/buildDocs.js", "compile": "npm-run-all -p compile:core compile:test -s compile:scripts", "compile:core": "tsc -p src", @@ -42,6 +42,7 @@ "glob": "^7.1.1", "optimist": "~0.6.0", "resolve": "^1.1.7", + "rimraf": "^2.5.4", "underscore.string": "^3.3.4" }, "devDependencies": { From a1f23e49a73eac15cfbab9fdbd2e70b870256b90 Mon Sep 17 00:00:00 2001 From: Kunal Marwaha Date: Thu, 20 Oct 2016 14:38:38 -0400 Subject: [PATCH 022/111] Fix docs typo controled -> controlled (#1648) --- docs/_data/rules.json | 2 +- docs/rules/ordered-imports/index.html | 2 +- src/rules/orderedImportsRule.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/_data/rules.json b/docs/_data/rules.json index cf2f09bccb1..fc235ccf2c9 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -914,7 +914,7 @@ { "ruleName": "ordered-imports", "description": "Requires that import statements be alphabetized.", - "descriptionDetails": "\nEnforce a consistent ordering for ES6 imports:\n- Named imports must be alphabetized (i.e. \"import {A, B, C} from \"foo\";\")\n - The exact ordering can be controled by the named-imports-order option.\n - \"longName as name\" imports are ordered by \"longName\".\n- Import sources must be alphabetized within groups, i.e.:\n import * as foo from \"a\";\n import * as bar from \"b\";\n- Groups of imports are delineated by blank lines. You can use these to group imports\n however you like, e.g. by first- vs. third-party or thematically.", + "descriptionDetails": "\nEnforce a consistent ordering for ES6 imports:\n- Named imports must be alphabetized (i.e. \"import {A, B, C} from \"foo\";\")\n - The exact ordering can be controlled by the named-imports-order option.\n - \"longName as name\" imports are ordered by \"longName\".\n- Import sources must be alphabetized within groups, i.e.:\n import * as foo from \"a\";\n import * as bar from \"b\";\n- Groups of imports are delineated by blank lines. You can use these to group imports\n however you like, e.g. by first- vs. third-party or thematically.", "optionsDescription": "\nYou may set the `\"import-sources-order\"` option to control the ordering of source\nimports (the `\"foo\"` in `import {A, B, C} from \"foo\"`).\n\nPossible values for `\"import-sources-order\"` are:\n* `\"case-insensitive'`: Correct order is `\"Bar\"`, `\"baz\"`, `\"Foo\"`. (This is the default.)\n* `\"lowercase-first\"`: Correct order is `\"baz\"`, `\"Bar\"`, `\"Foo\"`.\n* `\"lowercase-last\"`: Correct order is `\"Bar\"`, `\"Foo\"`, `\"baz\"`.\n\nYou may set the `\"named-imports-order\"` option to control the ordering of named\nimports (the `{A, B, C}` in `import {A, B, C} from \"foo\"`).\n\nPossible values for `\"named-imports-order\"` are:\n\n* `\"case-insensitive'`: Correct order is `{A, b, C}`. (This is the default.)\n* `\"lowercase-first\"`: Correct order is `{b, A, C}`.\n* `\"lowercase-last\"`: Correct order is `{A, C, b}`.\n\n ", "options": { "type": "object", diff --git a/docs/rules/ordered-imports/index.html b/docs/rules/ordered-imports/index.html index 8a87a1b21b2..64691a23f70 100644 --- a/docs/rules/ordered-imports/index.html +++ b/docs/rules/ordered-imports/index.html @@ -5,7 +5,7 @@ Enforce a consistent ordering for ES6 imports: - Named imports must be alphabetized (i.e. "import {A, B, C} from "foo";") - - The exact ordering can be controled by the named-imports-order option. + - The exact ordering can be controlled by the named-imports-order option. - "longName as name" imports are ordered by "longName". - Import sources must be alphabetized within groups, i.e.: import * as foo from "a"; diff --git a/src/rules/orderedImportsRule.ts b/src/rules/orderedImportsRule.ts index 7c222611821..8bef8a180b2 100644 --- a/src/rules/orderedImportsRule.ts +++ b/src/rules/orderedImportsRule.ts @@ -27,7 +27,7 @@ export class Rule extends Lint.Rules.AbstractRule { descriptionDetails: Lint.Utils.dedent` Enforce a consistent ordering for ES6 imports: - Named imports must be alphabetized (i.e. "import {A, B, C} from "foo";") - - The exact ordering can be controled by the named-imports-order option. + - The exact ordering can be controlled by the named-imports-order option. - "longName as name" imports are ordered by "longName". - Import sources must be alphabetized within groups, i.e.: import * as foo from "a"; From 7ddaee6cb4828c34e847c913e8af0fe093a2e2d0 Mon Sep 17 00:00:00 2001 From: Boris Aranovich Date: Sat, 22 Oct 2016 23:19:16 +0300 Subject: [PATCH 023/111] npm-debug.log in .gitignore (#1649) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6cebaca4f5b..5d9f8ee71ff 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ /lib/ node_modules/ tscommand*.txt +npm-debug.log # created by grunt-ts for faster compiling typings/.basedir.ts From 761553a307bed54b3cd3123438512038ad2e2a57 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sat, 22 Oct 2016 19:18:41 -0400 Subject: [PATCH 024/111] Create PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 00000000000..d21f050c4e8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,14 @@ +#### PR checklist + +- [ ] Addresses an existing issue: #0000 +- [ ] New feature, bugfix, or enhancement + - [ ] Includes tests +- [ ] Documentation update + +#### What changes did you make? + +(give an overview) + +#### Is there anything you'd like reviewers to focus on? + +(optional) From 028000523c0422cb756c9a0a41d5ab99d18be2c3 Mon Sep 17 00:00:00 2001 From: Boris Aranovich Date: Fri, 28 Oct 2016 23:02:10 +0300 Subject: [PATCH 025/111] Make sure vscode uses locally provided Typescript (#1659) --- .vscode/settings.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 214c37a251d..aa07ee373b5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,5 +17,8 @@ "build", "lib", "node_modules" - ] + ], + + // Always use project's provided typescript compiler version + "typescript.tsdk": "node_modules/typescript/lib" } From 255a657186d3966c851c70fd909715a912777335 Mon Sep 17 00:00:00 2001 From: Boris Aranovich Date: Sat, 29 Oct 2016 02:24:53 +0300 Subject: [PATCH 026/111] Option added to no-consecutive-blank-lines (#1650) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Option added to no-consecutive-blank-lines Added an optional argument to no-consecutive-blank-lines rule to allow specifying maximum number of allowed blank lines instead of only allowing 1. By default, if no option is specified, the old value of 1 is used, thus the rule is fully backwards compatible. Similar to ESLint’s no-multiple-empty-lines rule “Max” option: http://eslint.org/docs/rules/no-multiple-empty-lines * Added another test case: invalid option value --- src/rules/noConsecutiveBlankLinesRule.ts | 42 +++++++++++++++---- .../{ => default}/test.ts.lint | 0 .../{ => default}/tslint.json | 0 .../invalid-option/test.ts.lint | 30 +++++++++++++ .../invalid-option/tslint.json | 5 +++ .../multiple/test.ts.lint | 40 ++++++++++++++++++ .../multiple/tslint.json | 5 +++ 7 files changed, 115 insertions(+), 7 deletions(-) rename test/rules/no-consecutive-blank-lines/{ => default}/test.ts.lint (100%) rename test/rules/no-consecutive-blank-lines/{ => default}/tslint.json (100%) create mode 100644 test/rules/no-consecutive-blank-lines/invalid-option/test.ts.lint create mode 100644 test/rules/no-consecutive-blank-lines/invalid-option/tslint.json create mode 100644 test/rules/no-consecutive-blank-lines/multiple/test.ts.lint create mode 100644 test/rules/no-consecutive-blank-lines/multiple/tslint.json diff --git a/src/rules/noConsecutiveBlankLinesRule.ts b/src/rules/noConsecutiveBlankLinesRule.ts index b3208e117ab..111c47db574 100644 --- a/src/rules/noConsecutiveBlankLinesRule.ts +++ b/src/rules/noConsecutiveBlankLinesRule.ts @@ -20,19 +20,43 @@ import * as ts from "typescript"; import * as Lint from "../lint"; export class Rule extends Lint.Rules.AbstractRule { + public static DEFAULT_ALLOWED_BLANKS = 1; + public static MINIMUM_ALLOWED_BLANKS = 1; + /* tslint:disable:object-literal-sort-keys */ public static metadata: Lint.IRuleMetadata = { ruleName: "no-consecutive-blank-lines", - description: "Disallows more than one blank line in a row.", + description: "Disallows one or more blank lines in a row.", rationale: "Helps maintain a readable style in your codebase.", - optionsDescription: "Not configurable.", - options: {}, - optionExamples: ["true"], + optionsDescription: Lint.Utils.dedent` + An optional number of maximum allowed sequential blanks can be specified. If no value + is provided, a default of $(Rule.DEFAULT_ALLOWED_BLANKS) will be used.`, + options: { + type: "number", + minimum: "$(Rule.MINIMUM_ALLOWED_BLANKS)", + }, + optionExamples: ["true", "[true, 2]"], type: "style", }; /* tslint:enable:object-literal-sort-keys */ - public static FAILURE_STRING = "Consecutive blank lines are forbidden"; + public static FAILURE_STRING_FACTORY(allowed: number) { + return allowed === 1 + ? "Consecutive blank lines are forbidden" + : `Exceeds the ${allowed} allowed consecutive blank lines`; + }; + + /** + * Disable the rule if the option is provided but non-numeric or less than the minimum. + */ + public isEnabled(): boolean { + if (!super.isEnabled()) { + return false; + } + const options = this.getOptions(); + const allowedBlanks = options.ruleArguments && options.ruleArguments[0] || Rule.DEFAULT_ALLOWED_BLANKS; + return typeof allowedBlanks === "number" && allowedBlanks >= Rule.MINIMUM_ALLOWED_BLANKS; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new NoConsecutiveBlankLinesWalker(sourceFile, this.getOptions())); @@ -43,6 +67,9 @@ class NoConsecutiveBlankLinesWalker extends Lint.SkippableTokenAwareRuleWalker { public visitSourceFile(node: ts.SourceFile) { super.visitSourceFile(node); + const options = this.getOptions(); + const allowedBlanks = options && options[0] || Rule.DEFAULT_ALLOWED_BLANKS; + const failureMessage = Rule.FAILURE_STRING_FACTORY(allowedBlanks); const sourceFileText = node.getFullText(); const soureFileLines = sourceFileText.split(/\n/); @@ -62,10 +89,11 @@ class NoConsecutiveBlankLinesWalker extends Lint.SkippableTokenAwareRuleWalker { lastVal = line; } sequences - .filter((arr) => arr.length > 1).map((arr) => arr[0]) + .filter((arr) => arr.length > allowedBlanks) + .map((arr) => arr[0]) .forEach((startLineNum: number) => { let startCharPos = node.getPositionOfLineAndCharacter(startLineNum + 1, 0); - this.addFailure(this.createFailure(startCharPos, 1, Rule.FAILURE_STRING)); + this.addFailure(this.createFailure(startCharPos, 1, failureMessage)); }); } } diff --git a/test/rules/no-consecutive-blank-lines/test.ts.lint b/test/rules/no-consecutive-blank-lines/default/test.ts.lint similarity index 100% rename from test/rules/no-consecutive-blank-lines/test.ts.lint rename to test/rules/no-consecutive-blank-lines/default/test.ts.lint diff --git a/test/rules/no-consecutive-blank-lines/tslint.json b/test/rules/no-consecutive-blank-lines/default/tslint.json similarity index 100% rename from test/rules/no-consecutive-blank-lines/tslint.json rename to test/rules/no-consecutive-blank-lines/default/tslint.json diff --git a/test/rules/no-consecutive-blank-lines/invalid-option/test.ts.lint b/test/rules/no-consecutive-blank-lines/invalid-option/test.ts.lint new file mode 100644 index 00000000000..6bc6eb7fc90 --- /dev/null +++ b/test/rules/no-consecutive-blank-lines/invalid-option/test.ts.lint @@ -0,0 +1,30 @@ +// This rule will always pass since the arguments value in tslint.json is a string, +// while it should be a valid integer and > 1. +// In such a case, the rule is not enabled. + +class Clazz { // comment + + public funcxion() { + + + // also comment + + + + // still allowed since 2 lines only + + + + + + // this one won't be allowed anymore + + console.log("test"); + + } + + +} + + + diff --git a/test/rules/no-consecutive-blank-lines/invalid-option/tslint.json b/test/rules/no-consecutive-blank-lines/invalid-option/tslint.json new file mode 100644 index 00000000000..11f06b692b3 --- /dev/null +++ b/test/rules/no-consecutive-blank-lines/invalid-option/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-consecutive-blank-lines": [true, "three"] + } +} diff --git a/test/rules/no-consecutive-blank-lines/multiple/test.ts.lint b/test/rules/no-consecutive-blank-lines/multiple/test.ts.lint new file mode 100644 index 00000000000..b81bc3c41d7 --- /dev/null +++ b/test/rules/no-consecutive-blank-lines/multiple/test.ts.lint @@ -0,0 +1,40 @@ +// the markup for this test is a little bit weird +// tslint, for the first error below, says it goes from +// [5, 1] to [6, 1], and thus the markup appears to be off (but it's not) + +class Clazz { // comment + + +~nil + +~nil [Exceeds the 2 allowed consecutive blank lines] + + public funcxion() { + + // also comment + + + // still allowed since 2 lines only + + +~nil + +~nil [Exceeds the 2 allowed consecutive blank lines] + + + // this one won't be allowed anymore + + console.log("test"); + + } + + +} + +//Begin whitespace +// The next lines contain only tabs or spaces, they are also considered "blank" lines + + +~ [Exceeds the 2 allowed consecutive blank lines] + + diff --git a/test/rules/no-consecutive-blank-lines/multiple/tslint.json b/test/rules/no-consecutive-blank-lines/multiple/tslint.json new file mode 100644 index 00000000000..b9a168a7960 --- /dev/null +++ b/test/rules/no-consecutive-blank-lines/multiple/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-consecutive-blank-lines": [true, 2] + } +} From 591d39f69a5714494e7a08be6f6ef54da87d701f Mon Sep 17 00:00:00 2001 From: Andrii Dieiev Date: Sun, 30 Oct 2016 18:22:57 +0200 Subject: [PATCH 027/111] Show rule deprecation warning only once (#1660) --- src/ruleLoader.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ruleLoader.ts b/src/ruleLoader.ts index 63689f8f20b..73a30ab216a 100644 --- a/src/ruleLoader.ts +++ b/src/ruleLoader.ts @@ -24,6 +24,7 @@ import {IDisabledInterval, IRule} from "./language/rule/rule"; const moduleDirectory = path.dirname(module.filename); const CORE_RULES_DIRECTORY = path.resolve(moduleDirectory, ".", "rules"); +const shownDeprecations: string[] = []; export interface IEnableDisablePosition { isEnabled: boolean; @@ -49,8 +50,9 @@ export function loadRules(ruleConfiguration: {[name: string]: any}, const disabledIntervals = buildDisabledIntervalsFromSwitches(ruleSpecificList, allList); rules.push(new Rule(ruleName, ruleValue, disabledIntervals)); - if (Rule.metadata && Rule.metadata.deprecationMessage) { + if (Rule.metadata && Rule.metadata.deprecationMessage && shownDeprecations.indexOf(Rule.metadata.ruleName) === -1) { console.warn(`${Rule.metadata.ruleName} is deprecated. ${Rule.metadata.deprecationMessage}`); + shownDeprecations.push(Rule.metadata.ruleName); } } } From b93eefa5cb7d7a122f1754c979c1ceaad6d56155 Mon Sep 17 00:00:00 2001 From: Andrii Dieiev Date: Sun, 30 Oct 2016 18:23:52 +0200 Subject: [PATCH 028/111] Move rimraf to devDependencies (#1661) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4d7aad8681b..1bc58cc38c7 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "glob": "^7.1.1", "optimist": "~0.6.0", "resolve": "^1.1.7", - "rimraf": "^2.5.4", "underscore.string": "^3.3.4" }, "devDependencies": { @@ -62,6 +61,7 @@ "js-yaml": "^3.6.1", "mocha": "^3.1.0", "npm-run-all": "^3.1.0", + "rimraf": "^2.5.4", "tslint": "latest", "tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative", "typescript": "2.0.3" From d24c33189dbc9a1da67fa4702523d174b62777eb Mon Sep 17 00:00:00 2001 From: Evgeniy Zhukovskiy Date: Tue, 1 Nov 2016 17:46:55 +0300 Subject: [PATCH 029/111] Skip single line objects in object-literal-sort-keys rule (#1646) --- src/rules/objectLiteralSortKeysRule.ts | 14 ++++++++++++-- .../rules/object-literal-sort-keys/test.ts.lint | 17 +++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/rules/objectLiteralSortKeysRule.ts b/src/rules/objectLiteralSortKeysRule.ts index ccebcbe8167..dd6122a4b92 100644 --- a/src/rules/objectLiteralSortKeysRule.ts +++ b/src/rules/objectLiteralSortKeysRule.ts @@ -42,6 +42,7 @@ export class Rule extends Lint.Rules.AbstractRule { class ObjectLiteralSortKeysWalker extends Lint.RuleWalker { // stacks are used to maintain state while recursing through nested object literals private lastSortedKeyStack: string[] = []; + private multilineFlagStack: boolean[] = []; private sortedStateStack: boolean[] = []; public visitObjectLiteralExpression(node: ts.ObjectLiteralExpression) { @@ -49,18 +50,21 @@ class ObjectLiteralSortKeysWalker extends Lint.RuleWalker { this.lastSortedKeyStack.push(""); // sorted state is always initially true this.sortedStateStack.push(true); + this.multilineFlagStack.push(this.isMultilineListNode(node)); super.visitObjectLiteralExpression(node); + this.multilineFlagStack.pop(); this.lastSortedKeyStack.pop(); this.sortedStateStack.pop(); } public visitPropertyAssignment(node: ts.PropertyAssignment) { const sortedState = this.sortedStateStack[this.sortedStateStack.length - 1]; + const isMultiline = this.multilineFlagStack[this.multilineFlagStack.length - 1]; // skip remainder of object literal scan if a previous key was found // in an unsorted position. This ensures only one error is thrown at - // a time and keeps error output clean. - if (sortedState) { + // a time and keeps error output clean. Skip also single line objects. + if (sortedState && isMultiline) { const lastSortedKey = this.lastSortedKeyStack[this.lastSortedKeyStack.length - 1]; const keyNode = node.name; if (isIdentifierOrStringLiteral(keyNode)) { @@ -76,6 +80,12 @@ class ObjectLiteralSortKeysWalker extends Lint.RuleWalker { } super.visitPropertyAssignment(node); } + + private isMultilineListNode(node: ts.ObjectLiteralExpression) { + const startLineOfNode = this.getSourceFile().getLineAndCharacterOfPosition(node.getStart()).line; + const endLineOfNode = this.getSourceFile().getLineAndCharacterOfPosition(node.getEnd()).line; + return endLineOfNode !== startLineOfNode; + } } function isIdentifierOrStringLiteral(node: ts.Node): node is (ts.Identifier | ts.StringLiteral) { diff --git a/test/rules/object-literal-sort-keys/test.ts.lint b/test/rules/object-literal-sort-keys/test.ts.lint index 5e8c9fccb10..5668b48773e 100644 --- a/test/rules/object-literal-sort-keys/test.ts.lint +++ b/test/rules/object-literal-sort-keys/test.ts.lint @@ -144,3 +144,20 @@ var failK = { ~ [The key 'a' is not sorted alphabetically] c: 3 } + +var passL = {z: 1, y: '1', x: [1, 2]}; + +var failL = {x: 1, y: { + b: 1, + a: 2 + ~ [The key 'a' is not sorted alphabetically] +}, z: [1, 2]}; + +var passM = { + x: 1, + y: { + a: 1, + b: 2 + }, + z: {z: 1, y: '1', x: [1, 2]} +}; From 45312fd02d48d67a00a6deb7b42711a425f9e5d4 Mon Sep 17 00:00:00 2001 From: Chris Barr Date: Tue, 1 Nov 2016 15:01:42 -0400 Subject: [PATCH 030/111] New Rule: max-classes-per-file (#1656) --- src/rules/maxClassesPerFileRule.ts | 64 +++++++++++++++++++ .../max-classes-per-file/one/test.ts.lint | 12 ++++ .../max-classes-per-file/one/tslint.json | 5 ++ .../max-classes-per-file/two/test.ts.lint | 23 +++++++ .../max-classes-per-file/two/tslint.json | 5 ++ 5 files changed, 109 insertions(+) create mode 100644 src/rules/maxClassesPerFileRule.ts create mode 100644 test/rules/max-classes-per-file/one/test.ts.lint create mode 100644 test/rules/max-classes-per-file/one/tslint.json create mode 100644 test/rules/max-classes-per-file/two/test.ts.lint create mode 100644 test/rules/max-classes-per-file/two/tslint.json diff --git a/src/rules/maxClassesPerFileRule.ts b/src/rules/maxClassesPerFileRule.ts new file mode 100644 index 00000000000..d266c92cf6e --- /dev/null +++ b/src/rules/maxClassesPerFileRule.ts @@ -0,0 +1,64 @@ +import * as Lint from "../lint"; +import * as ts from "typescript"; + +export class Rule extends Lint.Rules.AbstractRule { + + /* tslint:disable:object-literal-sort-keys */ + public static metadata: Lint.IRuleMetadata = { + ruleName: "max-classes-per-file", + description: Lint.Utils.dedent` + A file may not contain more than the specified number of classes + if the file name does not match the "ignore-filename-pattern" option`, + rationale: Lint.Utils.dedent` + Ensures that files have a single responsibility so that that classes each exist in their own files`, + optionsDescription: Lint.Utils.dedent` + The one required argument is an integer indicating the maximum number of classes that can appear in a file.`, + options: { + type: "array", + items: [ + { + type: "number", + minimum: 1, + }, + ], + additionalItems: false, + minLength: 1, + maxLength: 2, + }, + optionExamples: ["[true, 1]", "[true, 5]"], + type: "maintainability", + }; + /* tslint:enable:object-literal-sort-keys */ + + public static FAILURE_STRING_FACTORY = (maxCount: number): string => { + const maxClassWord = maxCount === 1 ? "class per file is" : "classes per file are"; + return `A maximum of ${maxCount} ${maxClassWord} allowed`; + } + + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { + return this.applyWithWalker(new MaxClassesPerFileWalker(sourceFile, this.getOptions())); + } +} + +class MaxClassesPerFileWalker extends Lint.RuleWalker { + private classCount = 0; + private maxClassCount: number; + + constructor(sourceFile: ts.SourceFile, options: Lint.IOptions) { + super(sourceFile, options); + + this.maxClassCount = options.ruleArguments[0]; + if (isNaN(this.maxClassCount) || this.maxClassCount < 1) { + this.maxClassCount = 1; + } + } + + public visitClassDeclaration(node: ts.ClassDeclaration) { + this.classCount++; + if (this.classCount > this.maxClassCount) { + const msg = Rule.FAILURE_STRING_FACTORY(this.maxClassCount); + this.addFailure(this.createFailure(node.getStart(), node.getWidth(), msg)); + } + super.visitClassDeclaration(node); + } +} diff --git a/test/rules/max-classes-per-file/one/test.ts.lint b/test/rules/max-classes-per-file/one/test.ts.lint new file mode 100644 index 00000000000..ed0372cec7e --- /dev/null +++ b/test/rules/max-classes-per-file/one/test.ts.lint @@ -0,0 +1,12 @@ +class one { + public foo = "bar"; +} + +class two { +~~~~~~~~~~~ + public banana = "apple"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + public theAbovePropertyMakesSense = false; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +} +~ [A maximum of 1 class per file is allowed] \ No newline at end of file diff --git a/test/rules/max-classes-per-file/one/tslint.json b/test/rules/max-classes-per-file/one/tslint.json new file mode 100644 index 00000000000..d4df2d8e491 --- /dev/null +++ b/test/rules/max-classes-per-file/one/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "max-classes-per-file": [true, 1] + } +} diff --git a/test/rules/max-classes-per-file/two/test.ts.lint b/test/rules/max-classes-per-file/two/test.ts.lint new file mode 100644 index 00000000000..5e6e1932969 --- /dev/null +++ b/test/rules/max-classes-per-file/two/test.ts.lint @@ -0,0 +1,23 @@ +class one { + public foo = "bar"; +} + +class two { + public foo = "bar"; +} + +class three { +~~~~~~~~~~~~ + public foo = "bar"; +~~~~~~~~~~~~~~~~~~~~~~~ +} +~ [0] + +class four { +~~~~~~~~~~~~ + public foo = "bar"; +~~~~~~~~~~~~~~~~~~~~~~~ +} +~ [0] + +[0]: A maximum of 2 classes per file are allowed \ No newline at end of file diff --git a/test/rules/max-classes-per-file/two/tslint.json b/test/rules/max-classes-per-file/two/tslint.json new file mode 100644 index 00000000000..2064f81ad82 --- /dev/null +++ b/test/rules/max-classes-per-file/two/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "max-classes-per-file": [true, 2] + } +} From 276c6e4587e914ee5b59120f5b0aa04cdeccfb08 Mon Sep 17 00:00:00 2001 From: Chris Barr Date: Wed, 2 Nov 2016 12:36:05 -0400 Subject: [PATCH 031/111] Adding class expression checks (#1666) --- src/rules/maxClassesPerFileRule.ts | 11 ++++++++++- test/rules/max-classes-per-file/one/test.ts.lint | 7 +++++++ test/rules/max-classes-per-file/two/test.ts.lint | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/rules/maxClassesPerFileRule.ts b/src/rules/maxClassesPerFileRule.ts index d266c92cf6e..0076fbc9311 100644 --- a/src/rules/maxClassesPerFileRule.ts +++ b/src/rules/maxClassesPerFileRule.ts @@ -54,11 +54,20 @@ class MaxClassesPerFileWalker extends Lint.RuleWalker { } public visitClassDeclaration(node: ts.ClassDeclaration) { + this.increaseClassCount(node); + super.visitClassDeclaration(node); + } + + public visitClassExpression(node: ts.ClassExpression) { + this.increaseClassCount(node); + super.visitClassExpression(node); + } + + private increaseClassCount(node: ts.ClassExpression | ts.ClassDeclaration) { this.classCount++; if (this.classCount > this.maxClassCount) { const msg = Rule.FAILURE_STRING_FACTORY(this.maxClassCount); this.addFailure(this.createFailure(node.getStart(), node.getWidth(), msg)); } - super.visitClassDeclaration(node); } } diff --git a/test/rules/max-classes-per-file/one/test.ts.lint b/test/rules/max-classes-per-file/one/test.ts.lint index ed0372cec7e..aa012bfc086 100644 --- a/test/rules/max-classes-per-file/one/test.ts.lint +++ b/test/rules/max-classes-per-file/one/test.ts.lint @@ -9,4 +9,11 @@ class two { public theAbovePropertyMakesSense = false; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } +~ [A maximum of 1 class per file is allowed] + +let three = class { + ~~~~~~~ + public foo = "bar"; +~~~~~~~~~~~~~~~~~~~~~~~ +} ~ [A maximum of 1 class per file is allowed] \ No newline at end of file diff --git a/test/rules/max-classes-per-file/two/test.ts.lint b/test/rules/max-classes-per-file/two/test.ts.lint index 5e6e1932969..3ce15cdd61f 100644 --- a/test/rules/max-classes-per-file/two/test.ts.lint +++ b/test/rules/max-classes-per-file/two/test.ts.lint @@ -6,8 +6,8 @@ class two { public foo = "bar"; } -class three { -~~~~~~~~~~~~ +let three = class { + ~~~~~~~ public foo = "bar"; ~~~~~~~~~~~~~~~~~~~~~~~ } From 56948f887ad17ad98911e61ff160529ea3b98508 Mon Sep 17 00:00:00 2001 From: jakpaw Date: Wed, 2 Nov 2016 20:14:50 +0100 Subject: [PATCH 032/111] Add rule name to msbuild formatter output (#1658) --- src/formatters/msbuildFormatter.ts | 5 ++++- test/formatters/msbuildFormatterTests.ts | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/formatters/msbuildFormatter.ts b/src/formatters/msbuildFormatter.ts index 1239093cfd7..2457d1d82b9 100644 --- a/src/formatters/msbuildFormatter.ts +++ b/src/formatters/msbuildFormatter.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import {camelize} from "underscore.string"; + import {AbstractFormatter} from "../language/formatter/abstractFormatter"; import {IFormatterMetadata} from "../language/formatter/formatter"; import {RuleFailure} from "../language/rule/rule"; @@ -37,11 +39,12 @@ export class Formatter extends AbstractFormatter { const outputLines = failures.map((failure: RuleFailure) => { const fileName = failure.getFileName(); const failureString = failure.getFailure(); + const camelizedRule = camelize(failure.getRuleName()); const lineAndCharacter = failure.getStartPosition().getLineAndCharacter(); const positionTuple = `(${lineAndCharacter.line + 1},${lineAndCharacter.character + 1})`; - return `${fileName}${positionTuple}: warning: ${failureString}`; + return `${fileName}${positionTuple}: warning ${camelizedRule}: ${failureString}`; }); return outputLines.join("\n") + "\n"; diff --git a/test/formatters/msbuildFormatterTests.ts b/test/formatters/msbuildFormatterTests.ts index 2560f8fb473..ef2fd8f4344 100644 --- a/test/formatters/msbuildFormatterTests.ts +++ b/test/formatters/msbuildFormatterTests.ts @@ -39,9 +39,9 @@ describe("MSBuild Formatter", () => { ]; const expectedResult = - getFailureString(TEST_FILE, 1, 1, "first failure") + - getFailureString(TEST_FILE, 2, 12, "mid failure") + - getFailureString(TEST_FILE, 9, 2, "last failure"); + getFailureString(TEST_FILE, 1, 1, "first failure", "firstName") + + getFailureString(TEST_FILE, 2, 12, "mid failure", "midName") + + getFailureString(TEST_FILE, 9, 2, "last failure", "lastName"); const actualResult = formatter.format(failures); assert.equal(actualResult, expectedResult); @@ -52,7 +52,7 @@ describe("MSBuild Formatter", () => { assert.equal(result, "\n"); }); - function getFailureString(file: string, line: number, character: number, reason: string) { - return `${file}(${line},${character}): warning: ${reason}\n`; + function getFailureString(file: string, line: number, character: number, reason: string, ruleCamelCase: string) { + return `${file}(${line},${character}): warning ${ruleCamelCase}: ${reason}\n`; } }); From 5ada6a533fefaa8605e79b1a5d985ccaf28ce303 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 2 Nov 2016 18:43:49 -0400 Subject: [PATCH 033/111] Adds semicolon option `allow-bound-class-methods` (#1643) --- src/rules/semicolonRule.ts | 19 ++-- test/rules/semicolon/always/test.ts.fix | 1 + test/rules/semicolon/always/test.ts.lint | 4 +- test/rules/semicolon/enabled/test.ts.fix | 1 + test/rules/semicolon/enabled/test.ts.lint | 4 +- .../ignore-bound-class-methods/test.ts.fix | 73 ++++++++++++++ .../ignore-bound-class-methods/test.ts.lint | 99 +++++++++++++++++++ .../ignore-bound-class-methods/tslint.json | 5 + .../semicolon/ignore-interfaces/test.ts.fix | 1 + .../semicolon/ignore-interfaces/test.ts.lint | 4 +- 10 files changed, 202 insertions(+), 9 deletions(-) create mode 100644 test/rules/semicolon/ignore-bound-class-methods/test.ts.fix create mode 100644 test/rules/semicolon/ignore-bound-class-methods/test.ts.lint create mode 100644 test/rules/semicolon/ignore-bound-class-methods/tslint.json diff --git a/src/rules/semicolonRule.ts b/src/rules/semicolonRule.ts index 6ae0d810303..0b296e5ec6d 100644 --- a/src/rules/semicolonRule.ts +++ b/src/rules/semicolonRule.ts @@ -21,6 +21,7 @@ import * as Lint from "../lint"; const OPTION_ALWAYS = "always"; const OPTION_NEVER = "never"; +const OPTION_IGNORE_BOUND_CLASS_METHODS = "ignore-bound-class-methods"; const OPTION_IGNORE_INTERFACES = "ignore-interfaces"; export class Rule extends Lint.Rules.AbstractRule { @@ -35,7 +36,8 @@ export class Rule extends Lint.Rules.AbstractRule { * \`"${OPTION_NEVER}"\` disallows semicolons at the end of every statement except for when they are necessary. The following arguments may be optionaly provided: - * \`"${OPTION_IGNORE_INTERFACES}"\` skips checking semicolons at the end of interface members.`, + * \`"${OPTION_IGNORE_INTERFACES}"\` skips checking semicolons at the end of interface members. + * \`"${OPTION_IGNORE_BOUND_CLASS_METHODS}"\` skips checking semicolons at the end of bound class methods.`, options: { type: "array", items: [{ @@ -51,6 +53,7 @@ export class Rule extends Lint.Rules.AbstractRule { `[true, "${OPTION_ALWAYS}"]`, `[true, "${OPTION_NEVER}"]`, `[true, "${OPTION_ALWAYS}", "${OPTION_IGNORE_INTERFACES}"]`, + `[true, "${OPTION_ALWAYS}", "${OPTION_IGNORE_BOUND_CLASS_METHODS}"]`, ], type: "style", }; @@ -117,8 +120,11 @@ class SemicolonWalker extends Lint.RuleWalker { public visitPropertyDeclaration(node: ts.PropertyDeclaration) { const initializer = node.initializer; - /* ALWAYS === "enabled" for this rule. */ - if (this.hasOption(OPTION_NEVER) || !(initializer && initializer.kind === ts.SyntaxKind.ArrowFunction)) { + if (initializer && initializer.kind === ts.SyntaxKind.ArrowFunction) { + if (!this.hasOption(OPTION_IGNORE_BOUND_CLASS_METHODS)) { + this.checkSemicolonAt(node, "never"); + } + } else { this.checkSemicolonAt(node); } super.visitPropertyDeclaration(node); @@ -152,13 +158,14 @@ class SemicolonWalker extends Lint.RuleWalker { super.visitTypeAliasDeclaration(node); } - private checkSemicolonAt(node: ts.Node) { + private checkSemicolonAt(node: ts.Node, override?: "never") { const sourceFile = this.getSourceFile(); const children = node.getChildren(sourceFile); const hasSemicolon = children.some((child) => child.kind === ts.SyntaxKind.SemicolonToken); const position = node.getStart(sourceFile) + node.getWidth(sourceFile); + const never = override === "never" || this.hasOption(OPTION_NEVER); // Backwards compatible with plain {"semicolon": true} - const always = this.hasOption(OPTION_ALWAYS) || (this.getOptions() && this.getOptions().length === 0); + const always = !never && (this.hasOption(OPTION_ALWAYS) || (this.getOptions() && this.getOptions().length === 0)); if (always && !hasSemicolon) { const failureStart = Math.min(position, this.getLimit()); @@ -166,7 +173,7 @@ class SemicolonWalker extends Lint.RuleWalker { this.appendText(failureStart, ";"), ]); this.addFailure(this.createFailure(failureStart, 0, Rule.FAILURE_STRING_MISSING, fix)); - } else if (this.hasOption(OPTION_NEVER) && hasSemicolon) { + } else if (never && hasSemicolon) { const scanner = ts.createScanner(ts.ScriptTarget.ES5, false, ts.LanguageVariant.Standard, sourceFile.text); scanner.setTextPos(position); diff --git a/test/rules/semicolon/always/test.ts.fix b/test/rules/semicolon/always/test.ts.fix index 87f1de6d87f..2789b578e7e 100644 --- a/test/rules/semicolon/always/test.ts.fix +++ b/test/rules/semicolon/always/test.ts.fix @@ -52,6 +52,7 @@ class MyClass { public initializedProperty = 6; public initializedMethodProperty = () => { return "hi"; } + public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } } interface ITest { diff --git a/test/rules/semicolon/always/test.ts.lint b/test/rules/semicolon/always/test.ts.lint index 5794f22dbf0..464f70bf905 100644 --- a/test/rules/semicolon/always/test.ts.lint +++ b/test/rules/semicolon/always/test.ts.lint @@ -71,7 +71,9 @@ class MyClass { public initializedProperty = 6 ~nil [Missing semicolon] - public initializedMethodProperty = () => { return "hi"; } + public initializedMethodProperty = () => { return "hi"; }; + ~ [Unnecessary semicolon] + public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } } interface ITest { diff --git a/test/rules/semicolon/enabled/test.ts.fix b/test/rules/semicolon/enabled/test.ts.fix index 87f1de6d87f..2789b578e7e 100644 --- a/test/rules/semicolon/enabled/test.ts.fix +++ b/test/rules/semicolon/enabled/test.ts.fix @@ -52,6 +52,7 @@ class MyClass { public initializedProperty = 6; public initializedMethodProperty = () => { return "hi"; } + public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } } interface ITest { diff --git a/test/rules/semicolon/enabled/test.ts.lint b/test/rules/semicolon/enabled/test.ts.lint index 5794f22dbf0..464f70bf905 100644 --- a/test/rules/semicolon/enabled/test.ts.lint +++ b/test/rules/semicolon/enabled/test.ts.lint @@ -71,7 +71,9 @@ class MyClass { public initializedProperty = 6 ~nil [Missing semicolon] - public initializedMethodProperty = () => { return "hi"; } + public initializedMethodProperty = () => { return "hi"; }; + ~ [Unnecessary semicolon] + public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } } interface ITest { diff --git a/test/rules/semicolon/ignore-bound-class-methods/test.ts.fix b/test/rules/semicolon/ignore-bound-class-methods/test.ts.fix new file mode 100644 index 00000000000..6c7c6e551d6 --- /dev/null +++ b/test/rules/semicolon/ignore-bound-class-methods/test.ts.fix @@ -0,0 +1,73 @@ +var x = 3; +a += b; + +c = () => { +}; + +d = function() { }; + +console.log("i am adam, am i?"); + +function xyz() { + return; +} + +switch(xyz) { + case 1: + break; + case 2: + continue; +} + +throw new Error("some error"); + +do { + var a = 4; +} while(x == 3); + +debugger; + +import v = require("i"); +module M { + export var x; + export function f(s: string): string; + export function f(n: number): number; + export function f(x: any) { return x; } +} + +declare module "M" { + function f(): number; + function g(): number; +} + +function useStrictMissingSemicolon() { + "use strict"; + return null; +} + +class MyClass { + public name : string; + private index : number; + private email : string; + + public initializedProperty = 6; + public initializedMethodProperty = () => { return "hi"; }; + public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } +} + +interface ITest { + foo?: string; + bar: number; + baz: boolean; +} + +import {Router} from 'aurelia-router'; + +import {Controller} from 'my-lib'; + +export default LoginPage; +export default LoginPage; +export = Date; +export = Date; +type t = number; +type t = number; diff --git a/test/rules/semicolon/ignore-bound-class-methods/test.ts.lint b/test/rules/semicolon/ignore-bound-class-methods/test.ts.lint new file mode 100644 index 00000000000..574b2275734 --- /dev/null +++ b/test/rules/semicolon/ignore-bound-class-methods/test.ts.lint @@ -0,0 +1,99 @@ +var x = 3 + ~nil [Missing semicolon] +a += b + ~nil [Missing semicolon] + +c = () => { +} + ~nil [Missing semicolon] + +d = function() { } + ~nil [Missing semicolon] + +console.log("i am adam, am i?") + ~nil [Missing semicolon] + +function xyz() { + return + ~nil [Missing semicolon] +} + +switch(xyz) { + case 1: + break + ~nil [Missing semicolon] + case 2: + continue + ~nil [Missing semicolon] +} + +throw new Error("some error") + ~nil [Missing semicolon] + +do { + var a = 4 + ~nil [Missing semicolon] +} while(x == 3) + ~nil [Missing semicolon] + +debugger + ~nil [Missing semicolon] + +import v = require("i") + ~nil [Missing semicolon] +module M { + export var x + ~nil [Missing semicolon] + export function f(s: string): string; + export function f(n: number): number + ~nil [Missing semicolon] + export function f(x: any) { return x; } +} + +declare module "M" { + function f(): number; + function g(): number + ~nil [Missing semicolon] +} + +function useStrictMissingSemicolon() { + "use strict" + ~nil [Missing semicolon] + return null; +} + +class MyClass { + public name : string + ~nil [Missing semicolon] + private index : number + ~nil [Missing semicolon] + private email : string; + + public initializedProperty = 6 + ~nil [Missing semicolon] + public initializedMethodProperty = () => { return "hi"; }; + public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } +} + +interface ITest { + foo?: string + ~nil [Missing semicolon] + bar: number + ~nil [Missing semicolon] + baz: boolean; +} + +import {Router} from 'aurelia-router'; + +import {Controller} from 'my-lib' + ~nil [Missing semicolon] + +export default LoginPage; +export default LoginPage + ~nil [Missing semicolon] +export = Date; +export = Date + ~nil [Missing semicolon] +type t = number; +type t = number + ~nil [Missing semicolon] diff --git a/test/rules/semicolon/ignore-bound-class-methods/tslint.json b/test/rules/semicolon/ignore-bound-class-methods/tslint.json new file mode 100644 index 00000000000..52bef362d4b --- /dev/null +++ b/test/rules/semicolon/ignore-bound-class-methods/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "semicolon": [true, "always", "ignore-bound-class-methods"] + } +} diff --git a/test/rules/semicolon/ignore-interfaces/test.ts.fix b/test/rules/semicolon/ignore-interfaces/test.ts.fix index 1bb2d36cedf..6420c714d03 100644 --- a/test/rules/semicolon/ignore-interfaces/test.ts.fix +++ b/test/rules/semicolon/ignore-interfaces/test.ts.fix @@ -52,6 +52,7 @@ class MyClass { public initializedProperty = 6; public initializedMethodProperty = () => { return "hi"; } + public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } } interface ITest { diff --git a/test/rules/semicolon/ignore-interfaces/test.ts.lint b/test/rules/semicolon/ignore-interfaces/test.ts.lint index e2251344f0c..4edd267c806 100644 --- a/test/rules/semicolon/ignore-interfaces/test.ts.lint +++ b/test/rules/semicolon/ignore-interfaces/test.ts.lint @@ -71,7 +71,9 @@ class MyClass { public initializedProperty = 6 ~nil [Missing semicolon] - public initializedMethodProperty = () => { return "hi"; } + public initializedMethodProperty = () => { return "hi"; }; + ~ [Unnecessary semicolon] + public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } } interface ITest { From c0e470add73191b80bed2b3f060c45be3c643e8d Mon Sep 17 00:00:00 2001 From: Andrii Dieiev Date: Thu, 3 Nov 2016 04:57:56 +0200 Subject: [PATCH 034/111] Reimplement tests for TSLint bin file as Mocha tests (fixes #1635) (#1667) --- .gitignore | 1 + package.json | 3 +- test/check-bin.sh | 134 ------------- test/executable/executableTests.ts | 251 ++++++++++++++++++++++++ test/executable/npm-like-executable | 15 ++ test/executable/npm-like-executable.cmd | 7 + 6 files changed, 275 insertions(+), 136 deletions(-) delete mode 100755 test/check-bin.sh create mode 100644 test/executable/executableTests.ts create mode 100755 test/executable/npm-like-executable create mode 100644 test/executable/npm-like-executable.cmd diff --git a/.gitignore b/.gitignore index 5d9f8ee71ff..60b5c5e8d98 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /docs/site/ /scripts/*.js /lib/ +/test/executable/tslint.json node_modules/ tscommand*.txt npm-debug.log diff --git a/package.json b/package.json index 1bc58cc38c7..77cbd9c7955 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,8 @@ "lint": "npm-run-all -p lint:core lint:test", "lint:core": "tslint src/**/*.ts", "lint:test": "tslint test/**/*.ts -e test/**/*.test.ts", - "test": "npm-run-all test:pre -p test:bin test:mocha test:rules", + "test": "npm-run-all test:pre -p test:mocha test:rules", "test:pre": "cd ./test/config && npm install", - "test:bin": "./test/check-bin.sh &> /dev/null", "test:mocha": "mocha --reporter spec --colors build/test/**/*Tests.js build/test/assert.js", "test:rules": "node ./build/test/ruleTestRunner.js", "verify": "npm-run-all clean compile lint test docs" diff --git a/test/check-bin.sh b/test/check-bin.sh deleted file mode 100755 index 26fb0de9dc9..00000000000 --- a/test/check-bin.sh +++ /dev/null @@ -1,134 +0,0 @@ -#!/bin/bash - -# Copyright 2014 Palantir Technologies, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -num_failures=0 - -expectOut () { - actual=$1 - expect=$2 - msg=$3 - - nodeV=`node -v` - - # if Node 0.10.*, node will sometimes exit with status 8 when an error is thrown - if [[ $expect != $actual || $nodeV == v0.10.* && $expect == 1 && $actual == 8 ]] ; then - echo "$msg: expected $expect got $actual" - ((num_failures += 1)) - fi -} - -echo "Checking tslint binary" -# make sure calling tslint with no args exits correctly. -./bin/tslint -expectOut $? 1 "tslint with no args did not exit correctly" - -# make sure calling tslint with a good file exits correctly. -./bin/tslint src/configuration.ts -expectOut $? 0 "tslint with a good file did not exit correctly" - -# make sure calling tslint without the -f flag exits correctly -./bin/tslint src/configuration.ts src/formatterLoader.ts -expectOut $? 0 "tslint with valid arguments did not exit correctly" - -# make sure calling tslint with the -f flag exits correctly -./bin/tslint src/configuration.ts -f src/formatterLoader.ts -expectOut $? 1 "tslint with -f flag did not exit correctly" - -# make sure calling tslint with a CLI custom rules directory that doesn't exist fails -# (redirect stderr because it's confusing to see a stack trace during the build) -./bin/tslint -c ./test/config/tslint-custom-rules.json -r ./someRandomDir src/tslint.ts -expectOut $? 1 "tslint with -r pointing to a nonexistent directory did not fail" - -# make sure calling tslint with a CLI custom rules directory that does exist finds the errors it should -./bin/tslint -c ./test/config/tslint-custom-rules.json -r ./test/files/custom-rules src/tslint.ts -expectOut $? 2 "tslint with with -r pointing to custom rules did not find lint failures" - -# make sure calling tslint with a rulesDirectory in a config file works -./bin/tslint -c ./test/config/tslint-custom-rules-with-dir.json src/tslint.ts -expectOut $? 2 "tslint with with JSON pointing to custom rules did not find lint failures" - -# make sure calling tslint with an array as rulesDirectory in a config file works -./bin/tslint -c ./test/config/tslint-custom-rules-with-two-dirs.json src/tslint.ts -expectOut $? 2 "tslint with with JSON pointing to two custom rules did not find lint failures from second directory" - -# make sure --force option makes TSLint return a status code of 0 when there are lint errors -./bin/tslint -c ./test/config/tslint-custom-rules.json -r ./test/files/custom-rules --force src/tslint.ts -expectOut $? 0 "tslint with with -r pointing to custom rules did not find lint failures" - -# make sure path to config without a preceding "./" works on the CLI -./bin/tslint -c test/config/tslint-almost-empty.json src/tslint.ts -expectOut $? 0 "-c relative path without ./ did not work" - -# make sure calling tslint with a config file which extends a package relative to the config file works -./bin/tslint -c test/config/tslint-extends-package-no-mod.json src/tslint.ts -expectOut $? 0 "tslint (with config file extending relative package) did not work" - -# make sure tslint --init generates a file -cd ./bin -if [ -f tslint.json ]; then - rm tslint.json -fi - -./tslint --init -if [ ! -f tslint.json ]; then - echo "--init failed, tslint.json not created" - ((num_failures += 1)) -fi -expectOut $? 0 "tslint with --init flag did not exit correctly" - -# should fail since tslint.json already exists -./tslint --init -expectOut $? 1 "tslint with --init flag did not exit correctly when tslint.json already exists" - -rm tslint.json -cd .. - -# ensure --test command works correctly -./bin/tslint --test test/rules/no-eval -expectOut $? 0 "tslint --test did not exit correctly for a passing test" - -./bin/tslint --test test/files/incorrect-rule-test -expectOut $? 1 "tslint --test did not exit correctly for a failing test" - -# ensure --test command works correctly with custom rules -./bin/tslint --test test/files/custom-rule-rule-test -expectOut $? 0 "tslint --test did not exit correctly for a passing test with custom rules" - -./bin/tslint -r test/files/custom-rules-2 --test test/files/custom-rule-cli-rule-test -expectOut $? 0 "tslint --test did not exit correctly for a passing test with custom rules from the CLI" - -# ensure --test command works correctly with fixes -./bin/tslint --test test/files/fixes-test -expectOut $? 0 "tslint --test did not exit correctly for a passing test with fixes" - -./bin/tslint --test test/files/incorrect-fixes-test -expectOut $? 1 "tslint --test did not exit correctly for a failing test with fixes" - -# make sure tslint exits correctly when tsconfig is specified but no files are given -./bin/tslint -c test/files/tsconfig-test/tslint.json --project test/files/tsconfig-test/tsconfig.json -expectOut $? 0 "tslint with tsconfig did not exit correctly" - -# make sure tslint only lints files given if tsconfig is also specified -./bin/tslint -c test/files/tsconfig-test/tslint.json --project test/files/tsconfig-test/tsconfig.json test/files/tsconfig-test/other.test.ts -expectOut $? 2 "tslint with tsconfig and files did not find lint failures from given files" - -if (( num_failures != 0 )); then - echo "Failed $num_failures tests" - exit 1 -else - echo "Done!" - exit 0 -fi diff --git a/test/executable/executableTests.ts b/test/executable/executableTests.ts new file mode 100644 index 00000000000..61e24ce8ff8 --- /dev/null +++ b/test/executable/executableTests.ts @@ -0,0 +1,251 @@ +/* + * Copyright 2016 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as cp from "child_process"; +import * as fs from "fs"; +import * as os from "os"; +import * as path from "path"; + +// when tests are run with mocha from npm scripts CWD points to project root +const EXECUTABLE_DIR = path.resolve(process.cwd(), "test", "executable"); +const EXECUTABLE_PATH = path.resolve(EXECUTABLE_DIR, "npm-like-executable"); +const TEMP_JSON_PATH = path.resolve(EXECUTABLE_DIR, "tslint.json"); + +describe("Executable", () => { + + describe("Files", () => { + it("exits with code 1 if no arguments passed", (done) => { + execCli([], (err, stdout, stderr) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 1, "error code should be 1"); + + assert.include(stderr, "Missing files", "stderr should contain notification about missing files"); + assert.strictEqual(stdout, "", "shouldn't contain any output in stdout"); + done(); + }); + }); + + it("exits with code 0 if correct file is passed", (done) => { + execCli(["src/configuration.ts"], (err) => { + assert.isNull(err, "process should exit without an error"); + done(); + }); + }); + + it("exits with code 0 if several files passed without `-f` flag", (done) => { + execCli(["src/configuration.ts", "src/formatterLoader.ts"], (err) => { + assert.isNull(err, "process should exit without an error"); + done(); + }); + }); + + it("exits with code 1 if removed `-f` flag is passed", (done) => { + execCli(["src/configuration.ts", "-f", "src/formatterLoader.ts"], (err, stdout, stderr) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 1, "error code should be 1"); + + assert.include(stderr, "-f option is no longer available", "stderr should contain notification about removed flag"); + assert.strictEqual(stdout, "", "shouldn't contain any output in stdout"); + done(); + }); + }); + }); + + describe("Configuration file", () => { + it("exits with code 0 if relative path is passed without `./`", (done) => { + execCli(["-c", "test/config/tslint-almost-empty.json", "src/tslint.ts"], (err) => { + assert.isNull(err, "process should exit without an error"); + done(); + }); + }); + + it("exits with code 0 if config file that extends relative config file", (done) => { + execCli(["-c", "test/config/tslint-extends-package-no-mod.json", "src/tslint.ts"], (err) => { + assert.isNull(err, "process should exit without an error"); + done(); + }); + }); + }); + + describe("Custom rules", () => { + it("exits with code 1 if nonexisting custom rules directory is passed", (done) => { + execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./someRandomDir", "src/tslint.ts"], (err) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 1, "error code should be 1"); + done(); + }); + }); + + it("exits with code 2 if custom rules directory is passed and file contains lint errors", (done) => { + execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "src/tslint.ts"], (err) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 2, "error code should be 2"); + done(); + }); + }); + + it("exits with code 2 if custom rules directory is specified in config file and file contains lint errors", (done) => { + execCli(["-c", "./test/config/tslint-custom-rules-with-dir.json", "src/tslint.ts"], (err) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 2, "error code should be 2"); + done(); + }); + }); + + it("exits with code 2 if several custom rules directories are specified in config file and file contains lint errors", (done) => { + execCli(["-c", "./test/config/tslint-custom-rules-with-two-dirs.json", "src/tslint.ts"], (err) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 2, "error code should be 2"); + done(); + }); + }); + }); + + describe("--force flag", () => { + it("exits with code 0 if `--force` flag is passed", (done) => { + execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "--force", "src/tslint.ts"], + (err, stdout) => { + assert.isNull(err, "process should exit without an error"); + assert.include(stdout, "failure", "errors should be reported"); + done(); + }); + }); + }); + + describe("--test flag", () => { + it("exits with code 0 if `--test` flag is used", (done) => { + execCli(["--test", "test/rules/no-eval"], (err) => { + assert.isNull(err, "process should exit without an error"); + done(); + }); + }); + + it("exits with code 1 if `--test` flag is used with incorrect rule", (done) => { + execCli(["--test", "test/files/incorrect-rule-test"], (err) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 1, "error code should be 1"); + done(); + }); + }); + + it("exits with code 0 if `--test` flag is used with custom rule", (done) => { + execCli(["--test", "test/files/custom-rule-rule-test"], (err) => { + assert.isNull(err, "process should exit without an error"); + done(); + }); + }); + + it("exits with code 0 if `--test` and `-r` flags are used with custom rule", (done) => { + execCli(["-r", "test/files/custom-rules-2", "--test", "test/files/custom-rule-rule-test"], (err) => { + assert.isNull(err, "process should exit without an error"); + done(); + }); + }); + + it("exits with code 0 if `--test` flag is used with fixes", (done) => { + execCli(["--test", "test/files/fixes-test"], (err) => { + assert.isNull(err, "process should exit without an error"); + done(); + }); + }); + + it("exits with code 1 if `--test` flag is used with incorrect fixes", (done) => { + execCli(["--test", "test/files/incorrect-fixes-test"], (err) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 1, "error code should be 1"); + done(); + }); + }); + }); + + describe("tsconfig.json", () => { + it("exits with code 0 if `tsconfig.json` is passed and it specifies files without errors", (done) => { + execCli(["-c", "test/files/tsconfig-test/tslint.json", "--project", "test/files/tsconfig-test/tsconfig.json"], (err) => { + assert.isNull(err, "process should exit without an error"); + done(); + }); + }); + + it("exits with code 2 if both `tsconfig.json` and files arguments are passed and files contain lint errors", (done) => { + execCli(["-c", "test/files/tsconfig-test/tslint.json", "--project", "test/files/tsconfig-test/tsconfig.json", + "test/files/tsconfig-test/other.test.ts"], (err) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 2, "error code should be 2"); + done(); + }); + }); + }); + + describe("--init flag", () => { + // remove temp file before calling tslint --init + beforeEach(cleanTempInitFile); + // clean up temp file after tests + afterEach(cleanTempInitFile); + + it("exits with code 0 if `--init` flag is used in folder without tslint.json", (done) => { + + execCli(["--init"], { cwd: EXECUTABLE_DIR }, (err) => { + assert.isNull(err, "process should exit without an error"); + assert.strictEqual(fs.existsSync(TEMP_JSON_PATH), true, "file should be created"); + done(); + }); + }); + + it("exits with code 1 if `--init` flag is used in folder with tslint.json", (done) => { + // make sure that file exists before test + fs.writeFileSync(TEMP_JSON_PATH, "{}"); + + execCli(["--init"], { cwd: EXECUTABLE_DIR }, (err) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 1, "error code should be 1"); + done(); + }); + + }); + }); +}); + +type ExecFileCallback = (error: any, stdout: string, stderr: string) => void; + +function execCli(args: string[], cb: ExecFileCallback): cp.ChildProcess; +function execCli(args: string[], options: cp.ExecFileOptions, cb: ExecFileCallback): cp.ChildProcess; +function execCli(args: string[], options: cp.ExecFileOptions | ExecFileCallback, cb?: ExecFileCallback): cp.ChildProcess { + let filePath = EXECUTABLE_PATH; + + // Specify extension for Windows executable to avoid ENOENT errors + if (os.platform() === "win32") { + filePath += ".cmd"; + } + + if (isFunction(options)) { + cb = options as ExecFileCallback; + options = {}; + } + + return cp.execFile(filePath, args, options, (error, stdout, stderr) => { + cb(error, stdout.trim(), stderr.trim()); + }); +} + +function isFunction(fn: any): boolean { + return ({}).toString.call(fn) === "[object Function]"; +} + +function cleanTempInitFile(): void { + if (fs.existsSync(TEMP_JSON_PATH)) { + fs.unlinkSync(TEMP_JSON_PATH); + } +} diff --git a/test/executable/npm-like-executable b/test/executable/npm-like-executable new file mode 100755 index 00000000000..bb1ea78083f --- /dev/null +++ b/test/executable/npm-like-executable @@ -0,0 +1,15 @@ +#!/bin/sh +basedir=`dirname "$0"` + +case `uname` in + *CYGWIN*) basedir=`cygpath -w "$basedir"`;; +esac + +if [ -x "$basedir/node" ]; then + "$basedir/node" "$basedir/../../bin/tslint" "$@" + ret=$? +else + node "$basedir/../../bin/tslint" "$@" + ret=$? +fi +exit $ret diff --git a/test/executable/npm-like-executable.cmd b/test/executable/npm-like-executable.cmd new file mode 100644 index 00000000000..f0072bb4523 --- /dev/null +++ b/test/executable/npm-like-executable.cmd @@ -0,0 +1,7 @@ +@IF EXIST "%~dp0\node.exe" ( + "%~dp0\node.exe" "%~dp0\..\..\bin\tslint" %* +) ELSE ( + @SETLOCAL + @SET PATHEXT=%PATHEXT:;.JS;=;% + node "%~dp0\..\..\bin\tslint" %* +) \ No newline at end of file From fd5ae5a23e173da569a17719f63911a7c54f74d2 Mon Sep 17 00:00:00 2001 From: Yuichi Nukiyama Date: Thu, 3 Nov 2016 12:55:09 +0900 Subject: [PATCH 035/111] New feature: lint js files (#1515) * New feature: linting js files * use metadata.typscriptonly * test all rules --- src/configs/recommended.ts | 79 ++++ src/configuration.ts | 31 ++ src/language/rule/rule.ts | 5 + src/language/utils.ts | 1 + src/ruleLoader.ts | 33 +- src/rules/adjacentOverloadSignaturesRule.ts | 1 + src/rules/alignRule.ts | 1 + src/rules/arrayTypeRule.ts | 1 + src/rules/arrowParensRule.ts | 1 + src/rules/banRule.ts | 1 + src/rules/classNameRule.ts | 1 + src/rules/commentFormatRule.ts | 1 + src/rules/curlyRule.ts | 1 + src/rules/eoflineRule.ts | 1 + src/rules/fileHeaderRule.ts | 1 + src/rules/forinRule.ts | 1 + src/rules/indentRule.ts | 1 + src/rules/interfaceNameRule.ts | 1 + src/rules/jsdocFormatRule.ts | 1 + src/rules/labelPositionRule.ts | 1 + src/rules/linebreakStyleRule.ts | 1 + src/rules/maxFileLineCountRule.ts | 1 + src/rules/maxLineLengthRule.ts | 1 + src/rules/memberAccessRule.ts | 1 + src/rules/memberOrderingRule.ts | 1 + src/rules/newParensRule.ts | 1 + src/rules/noAngleBracketTypeAssertionRule.ts | 1 + src/rules/noAnyRule.ts | 1 + src/rules/noArgRule.ts | 1 + src/rules/noBitwiseRule.ts | 1 + src/rules/noConditionalAssignmentRule.ts | 1 + src/rules/noConsecutiveBlankLinesRule.ts | 1 + src/rules/noConsoleRule.ts | 1 + src/rules/noConstructRule.ts | 1 + src/rules/noDebuggerRule.ts | 1 + src/rules/noDefaultExportRule.ts | 1 + src/rules/noDuplicateKeyRule.ts | 1 + src/rules/noDuplicateVariableRule.ts | 1 + src/rules/noEmptyRule.ts | 1 + src/rules/noEvalRule.ts | 1 + src/rules/noForInArrayRule.ts | 1 + src/rules/noInferrableTypesRule.ts | 1 + src/rules/noInternalModuleRule.ts | 1 + src/rules/noInvalidThisRule.ts | 1 + src/rules/noMergeableNamespaceRule.ts | 1 + src/rules/noNamespaceRule.ts | 1 + src/rules/noNullKeywordRule.ts | 1 + src/rules/noParameterPropertiesRule.ts | 1 + src/rules/noReferenceRule.ts | 1 + src/rules/noRequireImportsRule.ts | 1 + src/rules/noShadowedVariableRule.ts | 1 + src/rules/noStringLiteralRule.ts | 1 + src/rules/noSwitchCaseFallThroughRule.ts | 1 + src/rules/noTrailingWhitespaceRule.ts | 1 + src/rules/noUnreachableRule.ts | 1 + src/rules/noUnsafeFinallyRule.ts | 1 + src/rules/noUnusedExpressionRule.ts | 1 + src/rules/noUnusedNewRule.ts | 1 + src/rules/noUnusedVariableRule.ts | 1 + src/rules/noUseBeforeDeclareRule.ts | 1 + src/rules/noVarKeywordRule.ts | 1 + src/rules/noVarRequiresRule.ts | 1 + src/rules/objectLiteralKeyQuotesRule.ts | 1 + src/rules/objectLiteralShorthandRule.ts | 1 + src/rules/objectLiteralSortKeysRule.ts | 1 + src/rules/oneLineRule.ts | 1 + src/rules/oneVariablePerDeclarationRule.ts | 1 + src/rules/onlyArrowFunctionsRule.ts | 1 + src/rules/orderedImportsRule.ts | 1 + src/rules/quotemarkRule.ts | 1 + src/rules/radixRule.ts | 1 + src/rules/restrictPlusOperandsRule.ts | 1 + src/rules/semicolonRule.ts | 1 + src/rules/switchDefaultRule.ts | 1 + src/rules/trailingCommaRule.ts | 1 + src/rules/tripleEqualsRule.ts | 1 + src/rules/typedefRule.ts | 1 + src/rules/typedefWhitespaceRule.ts | 1 + src/rules/useIsnanRule.ts | 1 + src/rules/variableNameRule.ts | 1 + src/rules/whitespaceRule.ts | 1 + src/tslintMulti.ts | 16 +- test/config/tslint-extends-builtin.json | 3 + test/config/tslint-extends-package-array.json | 3 + .../tslint-extends-package-two-levels.json | 3 + test/config/tslint-extends-package.json | 4 + test/config/tslint-extends-relative.json | 3 + test/config/tslint-with-jsrules.json | 5 + test/configurationTests.ts | 48 ++- test/ruleLoaderTests.ts | 20 + test/rules/align/arguments/test.js.lint | 152 ++++++++ test/rules/align/arguments/tslint.json | 3 + test/rules/align/parameters/test.js.lint | 38 ++ test/rules/align/parameters/tslint.json | 3 + test/rules/align/statements/test.js.lint | 151 ++++++++ test/rules/align/statements/tslint.json | 3 + test/rules/arrow-parens/test.js.lint | 15 + test/rules/arrow-parens/tslint.json | 3 + test/rules/ban/test.js.lint | 15 + test/rules/ban/tslint.json | 8 + test/rules/class-name/test.js.lint | 17 + test/rules/class-name/tslint.json | 3 + test/rules/comment-format/lower/test.js.lint | 25 ++ test/rules/comment-format/lower/tslint.json | 3 + test/rules/curly/test.js.lint | 81 ++++ test/rules/curly/tslint.json | 3 + .../file-header/bad-shebang/test.js.lint | 18 + .../rules/file-header/bad-shebang/tslint.json | 3 + .../file-header/bad-use-strict/test.js.lint | 18 + .../file-header/bad-use-strict/tslint.json | 3 + test/rules/file-header/bad/test.js.lint | 16 + test/rules/file-header/bad/tslint.json | 3 + .../file-header/good-shebang/test.js.lint | 14 + .../file-header/good-shebang/tslint.json | 3 + .../file-header/good-use-strict/test.js.lint | 13 + .../file-header/good-use-strict/tslint.json | 3 + test/rules/file-header/good/test.js.lint | 12 + test/rules/file-header/good/tslint.json | 3 + test/rules/forin/test.js.lint | 41 ++ test/rules/forin/tslint.json | 3 + test/rules/indent/spaces/test.js.lint | 136 +++++++ test/rules/indent/spaces/tslint.json | 3 + test/rules/indent/tabs/test.js.lint | 134 +++++++ test/rules/indent/tabs/tslint.json | 3 + test/rules/jsdoc-format/jsdoc-windows.js.lint | 10 + test/rules/jsdoc-format/jsdoc.js.lint | 79 ++++ test/rules/jsdoc-format/tslint.json | 3 + test/rules/label-position/test.js.lint | 38 ++ test/rules/label-position/tslint.json | 3 + .../linebreak-style/emptyFile/test.js.lint | 0 .../linebreak-style/emptyFile/tslint.json | 3 + .../linebreak-style/failure/CRLF/test.js.lint | 8 + .../linebreak-style/failure/CRLF/tslint.json | 3 + .../linebreak-style/failure/LF/test.js.lint | 8 + .../linebreak-style/failure/LF/tslint.json | 3 + .../linebreak-style/success/CRLF/test.js.lint | 4 + .../linebreak-style/success/CRLF/tslint.json | 3 + .../linebreak-style/success/LF/test.js.lint | 4 + .../linebreak-style/success/LF/tslint.json | 3 + .../max-file-line-count/default/test.js.lint | 23 ++ .../max-file-line-count/default/tslint.json | 3 + .../max-file-line-count/disabled/test.js.lint | 23 ++ .../max-file-line-count/disabled/tslint.json | 3 + test/rules/max-line-length/test.js.lint | 5 + test/rules/max-line-length/tslint.json | 3 + test/rules/new-parens/test.js.lint | 14 + test/rules/new-parens/tslint.json | 3 + test/rules/no-arg/test.js.lint | 12 + test/rules/no-arg/tslint.json | 3 + test/rules/no-bitwise/test.js.lint | 6 + test/rules/no-bitwise/tslint.json | 3 + .../no-conditional-assignment/test.js.lint | 50 +++ .../no-conditional-assignment/tslint.json | 3 + .../default/tslint.json | 3 + .../no-consecutive-blank-lines/test.js.lint | 32 ++ test/rules/no-console/test.js.lint | 13 + test/rules/no-console/tslint.json | 3 + test/rules/no-construct/test.js.lint | 13 + test/rules/no-construct/tslint.json | 3 + test/rules/no-debugger/test.js.lint | 8 + test/rules/no-debugger/tslint.json | 3 + test/rules/no-default-export/test.js.lint | 38 ++ test/rules/no-default-export/tslint.json | 3 + test/rules/no-duplicate-key/test.js.lint | 46 +++ test/rules/no-duplicate-key/tslint.json | 3 + test/rules/no-duplicate-variable/test.js.lint | 155 ++++++++ test/rules/no-duplicate-variable/tslint.json | 3 + test/rules/no-empty/test.js.lint | 42 ++ test/rules/no-empty/tslint.json | 3 + test/rules/no-eval/test.js.lint | 10 + test/rules/no-eval/tslint.json | 3 + test/rules/no-for-in-array/test.js.lint | 41 ++ test/rules/no-for-in-array/tslint.json | 3 + .../no-invalid-this/enabled/test.js.lint | 60 +++ .../rules/no-invalid-this/enabled/tslint.json | 6 + test/rules/no-null-keyword/test.js.lint | 4 + test/rules/no-null-keyword/tslint.json | 3 + test/rules/no-reference/test.js.lint | 2 + test/rules/no-reference/tslint.json | 3 + test/rules/no-require-imports/test.js.lint | 24 ++ test/rules/no-require-imports/tslint.json | 3 + test/rules/no-shadowed-variable/test.js.lint | 156 ++++++++ test/rules/no-shadowed-variable/tslint.json | 3 + test/rules/no-string-literal/tslint.json | 3 + .../no-switch-case-fall-through/test.js.lint | 87 +++++ .../no-switch-case-fall-through/tslint.json | 3 + .../rules/no-trailing-whitespace/test.js.lint | 16 + test/rules/no-trailing-whitespace/tslint.json | 3 + test/rules/no-unreachable/test.js.lint | 104 +++++ test/rules/no-unreachable/tslint.json | 3 + test/rules/no-unsafe-finally/test.js.lint | 361 ++++++++++++++++++ test/rules/no-unsafe-finally/tslint.json | 3 + test/rules/no-unused-expression/test.js.lint | 112 ++++++ test/rules/no-unused-expression/tslint.json | 3 + test/rules/no-unused-new/test.js.lint | 99 +++++ test/rules/no-unused-new/tslint.json | 3 + test/rules/no-use-before-declare/test.js.lint | 74 ++++ test/rules/no-use-before-declare/tslint.json | 3 + test/rules/no-var-keyword/test.js.lint | 49 +++ test/rules/no-var-keyword/tslint.json | 3 + .../always/test.js.lint | 23 ++ .../always/tslint.json | 3 + .../as-needed/test.js.lint | 22 ++ .../as-needed/tslint.json | 3 + .../object-literal-shorthand/test.js.lint | 46 +++ .../object-literal-shorthand/tslint.json | 3 + .../object-literal-sort-keys/test.js.lint | 85 +++++ .../object-literal-sort-keys/tslint.json | 3 + test/rules/one-line/all/test.js.lint | 110 ++++++ test/rules/one-line/all/tslint.json | 3 + test/rules/one-line/none/test.js.lint | 92 +++++ test/rules/one-line/none/tslint.json | 3 + .../default/test.js.lint | 40 ++ .../default/tslint.json | 3 + .../ignore-for-loop/test.js.lint | 25 ++ .../ignore-for-loop/tslint.json | 5 + .../allow-declarations/test.js.lint | 16 + .../allow-declarations/tslint.json | 3 + .../only-arrow-functions/default/test.js.lint | 18 + .../only-arrow-functions/default/tslint.json | 3 + .../case-insensitive/test.js.lint | 32 ++ .../case-insensitive/tslint.json | 3 + .../lowercase-first/test.js.lint | 32 ++ .../lowercase-first/tslint.json | 3 + .../double-avoid-escape/test.js.lint | 5 + .../quotemark/double-avoid-escape/tslint.json | 3 + test/rules/quotemark/double/test.js.lint | 6 + test/rules/quotemark/double/tslint.json | 3 + .../single-avoid-escape/test.js.lint | 5 + .../quotemark/single-avoid-escape/tslint.json | 3 + test/rules/quotemark/single/test.js.lint | 6 + test/rules/quotemark/single/tslint.json | 3 + test/rules/radix/test.js.lint | 4 + test/rules/radix/tslint.json | 3 + .../rules/restrict-plus-operands/test.js.lint | 51 +++ test/rules/restrict-plus-operands/tslint.json | 3 + test/rules/semicolon/always/test.js.lint | 67 ++++ test/rules/semicolon/always/tslint.json | 3 + test/rules/switch-default/test.js.lint | 74 ++++ test/rules/switch-default/tslint.json | 3 + .../multiline-always/test.js.lint | 138 +++++++ .../multiline-always/tslint.json | 3 + .../allow-null-check/test.js.lint | 19 + .../allow-null-check/tslint.json | 3 + .../allow-undefined-check/test.js.lint | 19 + .../allow-undefined-check/tslint.json | 3 + test/rules/use-isnan/test.js.lint | 31 ++ test/rules/use-isnan/tslint.json | 3 + .../test.js.lint | 45 +++ .../tslint.json | 3 + test/rules/whitespace/all/test.js.lint | 88 +++++ test/rules/whitespace/all/tslint.json | 11 + 252 files changed, 4402 insertions(+), 14 deletions(-) create mode 100644 test/config/tslint-with-jsrules.json create mode 100644 test/rules/align/arguments/test.js.lint create mode 100644 test/rules/align/parameters/test.js.lint create mode 100644 test/rules/align/statements/test.js.lint create mode 100644 test/rules/arrow-parens/test.js.lint create mode 100644 test/rules/ban/test.js.lint create mode 100644 test/rules/class-name/test.js.lint create mode 100644 test/rules/comment-format/lower/test.js.lint create mode 100644 test/rules/curly/test.js.lint create mode 100644 test/rules/file-header/bad-shebang/test.js.lint create mode 100644 test/rules/file-header/bad-use-strict/test.js.lint create mode 100644 test/rules/file-header/bad/test.js.lint create mode 100644 test/rules/file-header/good-shebang/test.js.lint create mode 100644 test/rules/file-header/good-use-strict/test.js.lint create mode 100644 test/rules/file-header/good/test.js.lint create mode 100644 test/rules/forin/test.js.lint create mode 100644 test/rules/indent/spaces/test.js.lint create mode 100644 test/rules/indent/tabs/test.js.lint create mode 100644 test/rules/jsdoc-format/jsdoc-windows.js.lint create mode 100644 test/rules/jsdoc-format/jsdoc.js.lint create mode 100644 test/rules/label-position/test.js.lint create mode 100644 test/rules/linebreak-style/emptyFile/test.js.lint create mode 100644 test/rules/linebreak-style/failure/CRLF/test.js.lint create mode 100644 test/rules/linebreak-style/failure/LF/test.js.lint create mode 100644 test/rules/linebreak-style/success/CRLF/test.js.lint create mode 100644 test/rules/linebreak-style/success/LF/test.js.lint create mode 100644 test/rules/max-file-line-count/default/test.js.lint create mode 100644 test/rules/max-file-line-count/disabled/test.js.lint create mode 100644 test/rules/max-line-length/test.js.lint create mode 100644 test/rules/new-parens/test.js.lint create mode 100644 test/rules/no-arg/test.js.lint create mode 100644 test/rules/no-bitwise/test.js.lint create mode 100644 test/rules/no-conditional-assignment/test.js.lint create mode 100644 test/rules/no-consecutive-blank-lines/test.js.lint create mode 100644 test/rules/no-console/test.js.lint create mode 100644 test/rules/no-construct/test.js.lint create mode 100644 test/rules/no-debugger/test.js.lint create mode 100644 test/rules/no-default-export/test.js.lint create mode 100644 test/rules/no-duplicate-key/test.js.lint create mode 100644 test/rules/no-duplicate-variable/test.js.lint create mode 100644 test/rules/no-empty/test.js.lint create mode 100644 test/rules/no-eval/test.js.lint create mode 100644 test/rules/no-for-in-array/test.js.lint create mode 100644 test/rules/no-invalid-this/enabled/test.js.lint create mode 100644 test/rules/no-null-keyword/test.js.lint create mode 100644 test/rules/no-reference/test.js.lint create mode 100644 test/rules/no-require-imports/test.js.lint create mode 100644 test/rules/no-shadowed-variable/test.js.lint create mode 100644 test/rules/no-switch-case-fall-through/test.js.lint create mode 100644 test/rules/no-trailing-whitespace/test.js.lint create mode 100644 test/rules/no-unreachable/test.js.lint create mode 100644 test/rules/no-unsafe-finally/test.js.lint create mode 100644 test/rules/no-unused-expression/test.js.lint create mode 100644 test/rules/no-unused-new/test.js.lint create mode 100644 test/rules/no-use-before-declare/test.js.lint create mode 100644 test/rules/no-var-keyword/test.js.lint create mode 100644 test/rules/object-literal-key-quotes/always/test.js.lint create mode 100644 test/rules/object-literal-key-quotes/as-needed/test.js.lint create mode 100644 test/rules/object-literal-shorthand/test.js.lint create mode 100644 test/rules/object-literal-sort-keys/test.js.lint create mode 100644 test/rules/one-line/all/test.js.lint create mode 100644 test/rules/one-line/none/test.js.lint create mode 100644 test/rules/one-variable-per-declaration/default/test.js.lint create mode 100644 test/rules/one-variable-per-declaration/ignore-for-loop/test.js.lint create mode 100644 test/rules/only-arrow-functions/allow-declarations/test.js.lint create mode 100644 test/rules/only-arrow-functions/default/test.js.lint create mode 100644 test/rules/ordered-imports/case-insensitive/test.js.lint create mode 100644 test/rules/ordered-imports/lowercase-first/test.js.lint create mode 100644 test/rules/quotemark/double-avoid-escape/test.js.lint create mode 100644 test/rules/quotemark/double/test.js.lint create mode 100644 test/rules/quotemark/single-avoid-escape/test.js.lint create mode 100644 test/rules/quotemark/single/test.js.lint create mode 100644 test/rules/radix/test.js.lint create mode 100644 test/rules/restrict-plus-operands/test.js.lint create mode 100644 test/rules/semicolon/always/test.js.lint create mode 100644 test/rules/switch-default/test.js.lint create mode 100644 test/rules/trailing-comma/multiline-always/test.js.lint create mode 100644 test/rules/triple-equals/allow-null-check/test.js.lint create mode 100644 test/rules/triple-equals/allow-undefined-check/test.js.lint create mode 100644 test/rules/use-isnan/test.js.lint create mode 100644 test/rules/variable-name/allow-leading-trailing-underscore/test.js.lint create mode 100644 test/rules/whitespace/all/test.js.lint diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index 690a5092caa..5a41449ef63 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -127,4 +127,83 @@ export const rules = { "check-typecast", ], }; +export const jsRules = { + "align": [true, + "parameters", + "statements", + ], + "class-name": true, + "curly": true, + "eofline": true, + "forin": true, + "indent": [true, "spaces"], + "jsdoc-format": true, + "label-position": true, + "max-line-length": [true, 120], + "new-parens": true, + "no-arg": true, + "no-bitwise": true, + "no-conditional-assignment": true, + "no-consecutive-blank-lines": true, + "no-console": [true, + "debug", + "info", + "log", + "time", + "timeEnd", + "trace", + ], + "no-construct": true, + "no-debugger": true, + "no-duplicate-key": true, + "no-duplicate-variable": true, + "no-empty": true, + "no-eval": true, + "no-reference": true, + "no-shadowed-variable": true, + "no-string-literal": true, + "no-switch-case-fall-through": false, + "no-trailing-whitespace": true, + "no-unreachable": true, + "no-unused-expression": true, + "no-unused-new": true, + // disable this rule as it is very heavy performance-wise and not that useful + "no-use-before-declare": false, + "object-literal-sort-keys": true, + "one-line": [true, + "check-catch", + "check-else", + "check-finally", + "check-open-brace", + "check-whitespace", + ], + "one-variable-per-declaration": [true, + "ignore-for-loop", + ], + "quotemark": [true, "double", "avoid-escape"], + "radix": true, + "semicolon": [true, "always"], + "switch-default": true, + "trailing-comma": [true, + { + "multiline": "always", + "singleline": "never", + }, + ], + "triple-equals": [true, "allow-null-check"], + "use-isnan": true, + "variable-name": [true, + "ban-keywords", + "check-format", + "allow-pascal-case", + ], + "whitespace": [true, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type", + "check-typecast", + ], +}; /* tslint:enable:object-literal-key-quotes */ diff --git a/src/configuration.ts b/src/configuration.ts index e9039169c90..4c7241bbf74 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -24,6 +24,7 @@ import {arrayify, objectify, stripComments} from "./utils"; export interface IConfigurationFile { extends?: string | string[]; + jsRules?: any; linterOptions?: { typeCheck?: boolean, }; @@ -34,6 +35,28 @@ export interface IConfigurationFile { export const CONFIG_FILENAME = "tslint.json"; /* tslint:disable:object-literal-key-quotes */ export const DEFAULT_CONFIG = { + "jsRules": { + "class-name": true, + "comment-format": [true, "check-space"], + "indent": [true, "spaces"], + "no-duplicate-variable": true, + "no-eval": true, + "no-trailing-whitespace": true, + "no-unsafe-finally": true, + "no-var-keyword": true, + "one-line": [true, "check-open-brace", "check-whitespace"], + "quotemark": [true, "double"], + "semicolon": [true, "always"], + "triple-equals": [true, "allow-null-check"], + "variable-name": [true, "ban-keywords"], + "whitespace": [true, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type", + ], + }, "rules": { "class-name": true, "comment-format": [true, "check-space"], @@ -204,6 +227,14 @@ export function extendConfigurationFile(config: IConfigurationFile, baseConfig: combinedConfig.rules[name] = config.rules[name]; } + combinedConfig.jsRules = {}; + for (const name of Object.keys(objectify(baseConfig.jsRules))) { + combinedConfig.jsRules[name] = baseConfig.jsRules[name]; + } + for (const name of Object.keys(objectify(config.jsRules))) { + combinedConfig.jsRules[name] = config.jsRules[name]; + } + return combinedConfig; } diff --git a/src/language/rule/rule.ts b/src/language/rule/rule.ts index 01e257a29bf..815cfefaef0 100644 --- a/src/language/rule/rule.ts +++ b/src/language/rule/rule.ts @@ -72,6 +72,11 @@ export interface IRuleMetadata { * Whether or not the rule requires type info to run. */ requiresTypeInfo?: boolean; + + /** + * Whether or not the rule use for TypeScript only. + */ + typescriptOnly?: boolean; } export type RuleType = "functionality" | "maintainability" | "style" | "typescript"; diff --git a/src/language/utils.ts b/src/language/utils.ts index 5e1ecb8241c..62f3b332154 100644 --- a/src/language/utils.ts +++ b/src/language/utils.ts @@ -48,6 +48,7 @@ export function getSourceFile(fileName: string, source: string): ts.SourceFile { export function createCompilerOptions(): ts.CompilerOptions { return { + allowJs: true, noResolve: true, target: ts.ScriptTarget.ES5, }; diff --git a/src/ruleLoader.ts b/src/ruleLoader.ts index 73a30ab216a..9e779072704 100644 --- a/src/ruleLoader.ts +++ b/src/ruleLoader.ts @@ -33,9 +33,11 @@ export interface IEnableDisablePosition { export function loadRules(ruleConfiguration: {[name: string]: any}, enableDisableRuleMap: {[rulename: string]: IEnableDisablePosition[]}, - rulesDirectories?: string | string[]): IRule[] { + rulesDirectories?: string | string[], + isJs?: boolean): IRule[] { const rules: IRule[] = []; const notFoundRules: string[] = []; + const notAllowedInJsRules: string[] = []; for (const ruleName in ruleConfiguration) { if (ruleConfiguration.hasOwnProperty(ruleName)) { @@ -44,15 +46,19 @@ export function loadRules(ruleConfiguration: {[name: string]: any}, if (Rule == null) { notFoundRules.push(ruleName); } else { - const all = "all"; // make the linter happy until we can turn it on and off - const allList = (all in enableDisableRuleMap ? enableDisableRuleMap[all] : []); - const ruleSpecificList = (ruleName in enableDisableRuleMap ? enableDisableRuleMap[ruleName] : []); - const disabledIntervals = buildDisabledIntervalsFromSwitches(ruleSpecificList, allList); - rules.push(new Rule(ruleName, ruleValue, disabledIntervals)); - - if (Rule.metadata && Rule.metadata.deprecationMessage && shownDeprecations.indexOf(Rule.metadata.ruleName) === -1) { - console.warn(`${Rule.metadata.ruleName} is deprecated. ${Rule.metadata.deprecationMessage}`); - shownDeprecations.push(Rule.metadata.ruleName); + if (isJs && Rule.metadata.typescriptOnly != null && Rule.metadata.typescriptOnly) { + notAllowedInJsRules.push(ruleName); + } else { + const all = "all"; // make the linter happy until we can turn it on and off + const allList = (all in enableDisableRuleMap ? enableDisableRuleMap[all] : []); + const ruleSpecificList = (ruleName in enableDisableRuleMap ? enableDisableRuleMap[ruleName] : []); + const disabledIntervals = buildDisabledIntervalsFromSwitches(ruleSpecificList, allList); + rules.push(new Rule(ruleName, ruleValue, disabledIntervals)); + + if (Rule.metadata && Rule.metadata.deprecationMessage && shownDeprecations.indexOf(Rule.metadata.ruleName) === -1) { + console.warn(`${Rule.metadata.ruleName} is deprecated. ${Rule.metadata.deprecationMessage}`); + shownDeprecations.push(Rule.metadata.ruleName); + } } } } @@ -67,6 +73,13 @@ export function loadRules(ruleConfiguration: {[name: string]: any}, `; throw new Error(ERROR_MESSAGE); + } else if (notAllowedInJsRules.length > 0) { + const JS_ERROR_MESSAGE = ` + Could not apply to JavaScript files for the following rules specified in the configuration: + ${notAllowedInJsRules.join("\n")} + `; + + throw new Error(JS_ERROR_MESSAGE); } else { return rules; } diff --git a/src/rules/adjacentOverloadSignaturesRule.ts b/src/rules/adjacentOverloadSignaturesRule.ts index e3959157a97..bbe11db548e 100644 --- a/src/rules/adjacentOverloadSignaturesRule.ts +++ b/src/rules/adjacentOverloadSignaturesRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "typescript", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/alignRule.ts b/src/rules/alignRule.ts index 40327a20731..031392b800b 100644 --- a/src/rules/alignRule.ts +++ b/src/rules/alignRule.ts @@ -42,6 +42,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, "parameters", "statements"]'], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/arrayTypeRule.ts b/src/rules/arrayTypeRule.ts index 256e6cb1098..96918f19d7d 100644 --- a/src/rules/arrayTypeRule.ts +++ b/src/rules/arrayTypeRule.ts @@ -23,6 +23,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: [`[true, ${OPTION_ARRAY}]`, `[true, ${OPTION_GENERIC}]`, `[true, ${OPTION_ARRAY_SIMPLE}]`], type: "style", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/arrowParensRule.ts b/src/rules/arrowParensRule.ts index 01fa2bd5341..39a7bdd8485 100644 --- a/src/rules/arrowParensRule.ts +++ b/src/rules/arrowParensRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/banRule.ts b/src/rules/banRule.ts index c0667ce45d8..99500e3a58a 100644 --- a/src/rules/banRule.ts +++ b/src/rules/banRule.ts @@ -39,6 +39,7 @@ export class Rule extends Lint.Rules.AbstractRule { optionExamples: [`[true, ["someGlobalMethod"], ["someObject", "someFunction"], ["someObject", "otherFunction", "Optional explanation"]]`], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/classNameRule.ts b/src/rules/classNameRule.ts index fb31837c796..cb5c050ac33 100644 --- a/src/rules/classNameRule.ts +++ b/src/rules/classNameRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/commentFormatRule.ts b/src/rules/commentFormatRule.ts index 76c920d53c4..31d02991b96 100644 --- a/src/rules/commentFormatRule.ts +++ b/src/rules/commentFormatRule.ts @@ -47,6 +47,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, "check-space", "check-lowercase"]'], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/curlyRule.ts b/src/rules/curlyRule.ts index 8a053bd149f..e7e3f1698df 100644 --- a/src/rules/curlyRule.ts +++ b/src/rules/curlyRule.ts @@ -38,6 +38,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/eoflineRule.ts b/src/rules/eoflineRule.ts index c835290abb5..3380ebe849f 100644 --- a/src/rules/eoflineRule.ts +++ b/src/rules/eoflineRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ public static FAILURE_STRING = "file should end with a newline"; diff --git a/src/rules/fileHeaderRule.ts b/src/rules/fileHeaderRule.ts index 63d42683770..c7da278ea3d 100644 --- a/src/rules/fileHeaderRule.ts +++ b/src/rules/fileHeaderRule.ts @@ -13,6 +13,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, "Copyright \\\\d{4}"]'], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/forinRule.ts b/src/rules/forinRule.ts index 7c6f6e5f2a4..92c10e53b67 100644 --- a/src/rules/forinRule.ts +++ b/src/rules/forinRule.ts @@ -39,6 +39,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/indentRule.ts b/src/rules/indentRule.ts index 0cda08317de..7d56502b81f 100644 --- a/src/rules/indentRule.ts +++ b/src/rules/indentRule.ts @@ -41,6 +41,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, "spaces"]'], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/interfaceNameRule.ts b/src/rules/interfaceNameRule.ts index c2ac0f54145..431967764e1 100644 --- a/src/rules/interfaceNameRule.ts +++ b/src/rules/interfaceNameRule.ts @@ -39,6 +39,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: [`[true, "${OPTION_ALWAYS}"]`, `[true, "${OPTION_NEVER}"]`], type: "style", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/jsdocFormatRule.ts b/src/rules/jsdocFormatRule.ts index d3b486d4919..f27e38afaab 100644 --- a/src/rules/jsdocFormatRule.ts +++ b/src/rules/jsdocFormatRule.ts @@ -36,6 +36,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/labelPositionRule.ts b/src/rules/labelPositionRule.ts index e55474110fd..1301692f064 100644 --- a/src/rules/labelPositionRule.ts +++ b/src/rules/labelPositionRule.ts @@ -33,6 +33,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/linebreakStyleRule.ts b/src/rules/linebreakStyleRule.ts index 4fcc62ec381..1f033207805 100644 --- a/src/rules/linebreakStyleRule.ts +++ b/src/rules/linebreakStyleRule.ts @@ -38,6 +38,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: [`[true, "${OPTION_LINEBREAK_STYLE_LF}"]`, `[true, "${OPTION_LINEBREAK_STYLE_CRLF}"]`], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/maxFileLineCountRule.ts b/src/rules/maxFileLineCountRule.ts index 3d9982c42bb..249c173728f 100644 --- a/src/rules/maxFileLineCountRule.ts +++ b/src/rules/maxFileLineCountRule.ts @@ -32,6 +32,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["[true, 300]"], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/maxLineLengthRule.ts b/src/rules/maxLineLengthRule.ts index 2fa48b520e8..a029f3938a5 100644 --- a/src/rules/maxLineLengthRule.ts +++ b/src/rules/maxLineLengthRule.ts @@ -35,6 +35,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["[true, 120]"], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/memberAccessRule.ts b/src/rules/memberAccessRule.ts index 61bb205ae23..972bfc182b3 100644 --- a/src/rules/memberAccessRule.ts +++ b/src/rules/memberAccessRule.ts @@ -41,6 +41,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["true", '[true, "check-accessor"]'], type: "typescript", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/memberOrderingRule.ts b/src/rules/memberOrderingRule.ts index 648f705fb42..4c3bbf09712 100644 --- a/src/rules/memberOrderingRule.ts +++ b/src/rules/memberOrderingRule.ts @@ -127,6 +127,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, { "order": "fields-first" }]'], type: "typescript", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { diff --git a/src/rules/newParensRule.ts b/src/rules/newParensRule.ts index a39cb0eda60..9c774347f06 100644 --- a/src/rules/newParensRule.ts +++ b/src/rules/newParensRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noAngleBracketTypeAssertionRule.ts b/src/rules/noAngleBracketTypeAssertionRule.ts index 854467336c7..dbf8a36069e 100644 --- a/src/rules/noAngleBracketTypeAssertionRule.ts +++ b/src/rules/noAngleBracketTypeAssertionRule.ts @@ -32,6 +32,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "style", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noAnyRule.ts b/src/rules/noAnyRule.ts index a0b602dc707..c8e8db534b2 100644 --- a/src/rules/noAnyRule.ts +++ b/src/rules/noAnyRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "typescript", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noArgRule.ts b/src/rules/noArgRule.ts index 8b34f8437ef..e3471baed69 100644 --- a/src/rules/noArgRule.ts +++ b/src/rules/noArgRule.ts @@ -32,6 +32,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noBitwiseRule.ts b/src/rules/noBitwiseRule.ts index 4a5b0a74795..62bcd4b0054 100644 --- a/src/rules/noBitwiseRule.ts +++ b/src/rules/noBitwiseRule.ts @@ -37,6 +37,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noConditionalAssignmentRule.ts b/src/rules/noConditionalAssignmentRule.ts index b59d87fed40..bf92d769190 100644 --- a/src/rules/noConditionalAssignmentRule.ts +++ b/src/rules/noConditionalAssignmentRule.ts @@ -33,6 +33,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noConsecutiveBlankLinesRule.ts b/src/rules/noConsecutiveBlankLinesRule.ts index 111c47db574..00921213c67 100644 --- a/src/rules/noConsecutiveBlankLinesRule.ts +++ b/src/rules/noConsecutiveBlankLinesRule.ts @@ -37,6 +37,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["true", "[true, 2]"], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noConsoleRule.ts b/src/rules/noConsoleRule.ts index 8c9f83fb52c..92df69e1f72 100644 --- a/src/rules/noConsoleRule.ts +++ b/src/rules/noConsoleRule.ts @@ -33,6 +33,7 @@ export class Rule extends BanRule.Rule { }, optionExamples: [`[true, "log", "error"]`], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noConstructRule.ts b/src/rules/noConstructRule.ts index b9fc89a19fa..5ef72fb2fb9 100644 --- a/src/rules/noConstructRule.ts +++ b/src/rules/noConstructRule.ts @@ -33,6 +33,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noDebuggerRule.ts b/src/rules/noDebuggerRule.ts index a4b5a5130ba..f6a531f373a 100644 --- a/src/rules/noDebuggerRule.ts +++ b/src/rules/noDebuggerRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noDefaultExportRule.ts b/src/rules/noDefaultExportRule.ts index be65e9273cb..74fa7f1fa51 100644 --- a/src/rules/noDefaultExportRule.ts +++ b/src/rules/noDefaultExportRule.ts @@ -33,6 +33,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noDuplicateKeyRule.ts b/src/rules/noDuplicateKeyRule.ts index 9f8973f72ab..17e86fcf06c 100644 --- a/src/rules/noDuplicateKeyRule.ts +++ b/src/rules/noDuplicateKeyRule.ts @@ -31,6 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noDuplicateVariableRule.ts b/src/rules/noDuplicateVariableRule.ts index 264adaf7e02..c9ac6d72a8c 100644 --- a/src/rules/noDuplicateVariableRule.ts +++ b/src/rules/noDuplicateVariableRule.ts @@ -34,6 +34,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noEmptyRule.ts b/src/rules/noEmptyRule.ts index 8b95bc9e61b..753755aa1d0 100644 --- a/src/rules/noEmptyRule.ts +++ b/src/rules/noEmptyRule.ts @@ -30,6 +30,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noEvalRule.ts b/src/rules/noEvalRule.ts index 9e6ee898efb..d8e62642bff 100644 --- a/src/rules/noEvalRule.ts +++ b/src/rules/noEvalRule.ts @@ -32,6 +32,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noForInArrayRule.ts b/src/rules/noForInArrayRule.ts index ebccb4e1a96..d9abbde92e0 100644 --- a/src/rules/noForInArrayRule.ts +++ b/src/rules/noForInArrayRule.ts @@ -43,6 +43,7 @@ export class Rule extends Lint.Rules.TypedRule { optionExamples: ["true"], requiresTypeInfo: true, type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noInferrableTypesRule.ts b/src/rules/noInferrableTypesRule.ts index 99ee2f28f9f..252343ae056 100644 --- a/src/rules/noInferrableTypesRule.ts +++ b/src/rules/noInferrableTypesRule.ts @@ -43,6 +43,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["true", `[true, "${OPTION_IGNORE_PARMS}"]`], type: "typescript", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noInternalModuleRule.ts b/src/rules/noInternalModuleRule.ts index 4e890d05ded..bfb4f165a05 100644 --- a/src/rules/noInternalModuleRule.ts +++ b/src/rules/noInternalModuleRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "typescript", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noInvalidThisRule.ts b/src/rules/noInvalidThisRule.ts index c98a22d7d45..d36bc9da871 100644 --- a/src/rules/noInvalidThisRule.ts +++ b/src/rules/noInvalidThisRule.ts @@ -48,6 +48,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["true", `[true, "${OPTION_FUNCTION_IN_METHOD}"]`], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noMergeableNamespaceRule.ts b/src/rules/noMergeableNamespaceRule.ts index d3466c5e286..be9aa32ef9d 100644 --- a/src/rules/noMergeableNamespaceRule.ts +++ b/src/rules/noMergeableNamespaceRule.ts @@ -28,6 +28,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "maintainability", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noNamespaceRule.ts b/src/rules/noNamespaceRule.ts index 980fd1adc47..5f16cf38169 100644 --- a/src/rules/noNamespaceRule.ts +++ b/src/rules/noNamespaceRule.ts @@ -43,6 +43,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["true", '[true, "allow-declarations"]'], type: "typescript", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noNullKeywordRule.ts b/src/rules/noNullKeywordRule.ts index b49ea822c01..aea34aa0377 100644 --- a/src/rules/noNullKeywordRule.ts +++ b/src/rules/noNullKeywordRule.ts @@ -33,6 +33,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noParameterPropertiesRule.ts b/src/rules/noParameterPropertiesRule.ts index eba4b6e8c4f..78e04d0f47e 100644 --- a/src/rules/noParameterPropertiesRule.ts +++ b/src/rules/noParameterPropertiesRule.ts @@ -31,6 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "style", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noReferenceRule.ts b/src/rules/noReferenceRule.ts index fcac6e8d74d..a35b5461957 100644 --- a/src/rules/noReferenceRule.ts +++ b/src/rules/noReferenceRule.ts @@ -31,6 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "typescript", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noRequireImportsRule.ts b/src/rules/noRequireImportsRule.ts index f5aac5109e8..051dc8fe221 100644 --- a/src/rules/noRequireImportsRule.ts +++ b/src/rules/noRequireImportsRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noShadowedVariableRule.ts b/src/rules/noShadowedVariableRule.ts index c6fd5b261dd..d78a8eed1ec 100644 --- a/src/rules/noShadowedVariableRule.ts +++ b/src/rules/noShadowedVariableRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noStringLiteralRule.ts b/src/rules/noStringLiteralRule.ts index e101df69f16..5fb944d8125 100644 --- a/src/rules/noStringLiteralRule.ts +++ b/src/rules/noStringLiteralRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noSwitchCaseFallThroughRule.ts b/src/rules/noSwitchCaseFallThroughRule.ts index afae05f0b48..f0dfc6cdf2c 100644 --- a/src/rules/noSwitchCaseFallThroughRule.ts +++ b/src/rules/noSwitchCaseFallThroughRule.ts @@ -54,6 +54,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noTrailingWhitespaceRule.ts b/src/rules/noTrailingWhitespaceRule.ts index 8998a5a37dc..b102a612388 100644 --- a/src/rules/noTrailingWhitespaceRule.ts +++ b/src/rules/noTrailingWhitespaceRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noUnreachableRule.ts b/src/rules/noUnreachableRule.ts index f36bcc5b24f..2d63de4d65a 100644 --- a/src/rules/noUnreachableRule.ts +++ b/src/rules/noUnreachableRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noUnsafeFinallyRule.ts b/src/rules/noUnsafeFinallyRule.ts index 2fa74b20e4d..9c88031cfff 100644 --- a/src/rules/noUnsafeFinallyRule.ts +++ b/src/rules/noUnsafeFinallyRule.ts @@ -35,6 +35,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noUnusedExpressionRule.ts b/src/rules/noUnusedExpressionRule.ts index 287398c81e1..ae863c0b3af 100644 --- a/src/rules/noUnusedExpressionRule.ts +++ b/src/rules/noUnusedExpressionRule.ts @@ -33,6 +33,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noUnusedNewRule.ts b/src/rules/noUnusedNewRule.ts index 87dc6a7daa6..a5cfba4b5ea 100644 --- a/src/rules/noUnusedNewRule.ts +++ b/src/rules/noUnusedNewRule.ts @@ -34,6 +34,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noUnusedVariableRule.ts b/src/rules/noUnusedVariableRule.ts index a20b24b625d..741e4e3fd46 100644 --- a/src/rules/noUnusedVariableRule.ts +++ b/src/rules/noUnusedVariableRule.ts @@ -64,6 +64,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, "react"]', '[true, {"ignore-pattern": "^_"}]'], type: "functionality", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noUseBeforeDeclareRule.ts b/src/rules/noUseBeforeDeclareRule.ts index 1f126607356..8654658a8ae 100644 --- a/src/rules/noUseBeforeDeclareRule.ts +++ b/src/rules/noUseBeforeDeclareRule.ts @@ -31,6 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noVarKeywordRule.ts b/src/rules/noVarKeywordRule.ts index 2c51ec52756..6b285918cfb 100644 --- a/src/rules/noVarKeywordRule.ts +++ b/src/rules/noVarKeywordRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/noVarRequiresRule.ts b/src/rules/noVarRequiresRule.ts index e6498d03773..b13bc5824da 100644 --- a/src/rules/noVarRequiresRule.ts +++ b/src/rules/noVarRequiresRule.ts @@ -31,6 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "typescript", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/objectLiteralKeyQuotesRule.ts b/src/rules/objectLiteralKeyQuotesRule.ts index 75d4452db23..c63dac4e59a 100644 --- a/src/rules/objectLiteralKeyQuotesRule.ts +++ b/src/rules/objectLiteralKeyQuotesRule.ts @@ -39,6 +39,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["[true, \"as-needed\"]", "[true, \"always\"]"], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/objectLiteralShorthandRule.ts b/src/rules/objectLiteralShorthandRule.ts index d1eca695246..6f58862c687 100644 --- a/src/rules/objectLiteralShorthandRule.ts +++ b/src/rules/objectLiteralShorthandRule.ts @@ -9,6 +9,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/objectLiteralSortKeysRule.ts b/src/rules/objectLiteralSortKeysRule.ts index dd6122a4b92..5ff902585eb 100644 --- a/src/rules/objectLiteralSortKeysRule.ts +++ b/src/rules/objectLiteralSortKeysRule.ts @@ -29,6 +29,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/oneLineRule.ts b/src/rules/oneLineRule.ts index e7bcfc0ef2e..d89cf241708 100644 --- a/src/rules/oneLineRule.ts +++ b/src/rules/oneLineRule.ts @@ -49,6 +49,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, "check-catch", "check-finally", "check-else"]'], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/oneVariablePerDeclarationRule.ts b/src/rules/oneVariablePerDeclarationRule.ts index 3a79c213f24..409ef4286ed 100644 --- a/src/rules/oneVariablePerDeclarationRule.ts +++ b/src/rules/oneVariablePerDeclarationRule.ts @@ -41,6 +41,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["true", `[true, "${OPTION_IGNORE_FOR_LOOP}"]`], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/onlyArrowFunctionsRule.ts b/src/rules/onlyArrowFunctionsRule.ts index f29b191ece7..b2306b990ff 100644 --- a/src/rules/onlyArrowFunctionsRule.ts +++ b/src/rules/onlyArrowFunctionsRule.ts @@ -43,6 +43,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["true", `[true, "${OPTION_ALLOW_DECLARATIONS}"]`], type: "typescript", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/orderedImportsRule.ts b/src/rules/orderedImportsRule.ts index 8bef8a180b2..f10eb5941ac 100644 --- a/src/rules/orderedImportsRule.ts +++ b/src/rules/orderedImportsRule.ts @@ -74,6 +74,7 @@ export class Rule extends Lint.Rules.AbstractRule { '[true, {"import-sources-order": "lowercase-last", "named-imports-order": "lowercase-first"}]', ], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/quotemarkRule.ts b/src/rules/quotemarkRule.ts index aabfd9eaf32..a82237b3610 100644 --- a/src/rules/quotemarkRule.ts +++ b/src/rules/quotemarkRule.ts @@ -49,6 +49,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, "single", "avoid-escape"]', '[true, "single", "jsx-double"]'], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/radixRule.ts b/src/rules/radixRule.ts index 5bfb33b9c49..28174d603f4 100644 --- a/src/rules/radixRule.ts +++ b/src/rules/radixRule.ts @@ -32,6 +32,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/restrictPlusOperandsRule.ts b/src/rules/restrictPlusOperandsRule.ts index 50cea6b81eb..68cd410a967 100644 --- a/src/rules/restrictPlusOperandsRule.ts +++ b/src/rules/restrictPlusOperandsRule.ts @@ -28,6 +28,7 @@ export class Rule extends Lint.Rules.TypedRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, requiresTypeInfo: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/semicolonRule.ts b/src/rules/semicolonRule.ts index 0b296e5ec6d..a175cf7b69a 100644 --- a/src/rules/semicolonRule.ts +++ b/src/rules/semicolonRule.ts @@ -56,6 +56,7 @@ export class Rule extends Lint.Rules.AbstractRule { `[true, "${OPTION_ALWAYS}", "${OPTION_IGNORE_BOUND_CLASS_METHODS}"]`, ], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/switchDefaultRule.ts b/src/rules/switchDefaultRule.ts index a9c3e6b4279..fb9f9d50419 100644 --- a/src/rules/switchDefaultRule.ts +++ b/src/rules/switchDefaultRule.ts @@ -28,6 +28,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/trailingCommaRule.ts b/src/rules/trailingCommaRule.ts index f6ef978a691..42514e14e5f 100644 --- a/src/rules/trailingCommaRule.ts +++ b/src/rules/trailingCommaRule.ts @@ -53,6 +53,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, {"multiline": "always", "singleline": "never"}]'], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/tripleEqualsRule.ts b/src/rules/tripleEqualsRule.ts index 87c4fbdfc00..67d4dc7e62a 100644 --- a/src/rules/tripleEqualsRule.ts +++ b/src/rules/tripleEqualsRule.ts @@ -47,6 +47,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["true", '[true, "allow-null-check"]', '[true, "allow-undefined-check"]'], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/typedefRule.ts b/src/rules/typedefRule.ts index 8155c0eec6f..6c4a7f0c4e6 100644 --- a/src/rules/typedefRule.ts +++ b/src/rules/typedefRule.ts @@ -53,6 +53,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, "call-signature", "parameter", "member-variable-declaration"]'], type: "typescript", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/typedefWhitespaceRule.ts b/src/rules/typedefWhitespaceRule.ts index 53e2aae6651..205c8d41f82 100644 --- a/src/rules/typedefWhitespaceRule.ts +++ b/src/rules/typedefWhitespaceRule.ts @@ -79,6 +79,7 @@ export class Rule extends Lint.Rules.AbstractRule { ]`, ], type: "typescript", + typescriptOnly: true, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/useIsnanRule.ts b/src/rules/useIsnanRule.ts index 5e37d0daf62..d0902c2fa34 100644 --- a/src/rules/useIsnanRule.ts +++ b/src/rules/useIsnanRule.ts @@ -31,6 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "functionality", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/variableNameRule.ts b/src/rules/variableNameRule.ts index 76699ec737f..18028d786f6 100644 --- a/src/rules/variableNameRule.ts +++ b/src/rules/variableNameRule.ts @@ -58,6 +58,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, "ban-keywords", "check-format", "allow-leading-underscore"]'], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/whitespaceRule.ts b/src/rules/whitespaceRule.ts index 06bb678a10e..63465e70912 100644 --- a/src/rules/whitespaceRule.ts +++ b/src/rules/whitespaceRule.ts @@ -55,6 +55,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ['[true, "check-branch", "check-operator", "check-typecast"]'], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/tslintMulti.ts b/src/tslintMulti.ts index 7ef35aa9435..65a8ded8606 100644 --- a/src/tslintMulti.ts +++ b/src/tslintMulti.ts @@ -24,6 +24,7 @@ import { findConfigurationPath, getRelativePath, getRulesDirectories, + IConfigurationFile, loadConfigurationFromPath, } from "./configuration"; import { EnableDisableRulesWalker } from "./enableDisableRules"; @@ -32,7 +33,7 @@ import { IFormatter } from "./language/formatter/formatter"; import { RuleFailure } from "./language/rule/rule"; import { TypedRule } from "./language/rule/typedRule"; import { getSourceFile } from "./language/utils"; -import { IMultiLinterOptions, LintResult } from "./lint"; +import { IMultiLinterOptions, IRule, LintResult } from "./lint"; import { loadRules } from "./ruleLoader"; import { arrayify } from "./utils"; @@ -87,7 +88,7 @@ class MultiLinter { // Empty } - public lint(fileName: string, source?: string, configuration: any = DEFAULT_CONFIG): void { + public lint(fileName: string, source?: string, configuration: IConfigurationFile = DEFAULT_CONFIG): void { let sourceFile: ts.SourceFile; if (this.program) { sourceFile = this.program.getSourceFile(fileName); @@ -114,7 +115,16 @@ class MultiLinter { const rulesDirectories = arrayify(this.options.rulesDirectory) .concat(arrayify(configuration.rulesDirectory)); const configurationRules = configuration.rules; - const configuredRules = loadRules(configurationRules, enableDisableRuleMap, rulesDirectories); + const jsConfiguration = configuration.jsRules; + const isJs = fileName.substr(-3) === ".js"; + let configuredRules: IRule[]; + + if (isJs) { + configuredRules = loadRules(jsConfiguration, enableDisableRuleMap, rulesDirectories, true); + } else { + configuredRules = loadRules(configurationRules, enableDisableRuleMap, rulesDirectories, false); + } + const enabledRules = configuredRules.filter((r) => r.isEnabled()); for (let rule of enabledRules) { let ruleFailures: RuleFailure[] = []; diff --git a/test/config/tslint-extends-builtin.json b/test/config/tslint-extends-builtin.json index 6219cf987a0..4daad33a5c8 100644 --- a/test/config/tslint-extends-builtin.json +++ b/test/config/tslint-extends-builtin.json @@ -1,5 +1,8 @@ { "extends": "tslint:latest", + "jsRules": { + "no-eval": false + }, "rules": { "no-eval": false } diff --git a/test/config/tslint-extends-package-array.json b/test/config/tslint-extends-package-array.json index 2cd7ee1a31b..e52fb098a1d 100644 --- a/test/config/tslint-extends-package-array.json +++ b/test/config/tslint-extends-package-array.json @@ -3,6 +3,9 @@ "tslint-test-custom-rules", "./tslint-custom-rules-with-two-dirs.json" ], + "jsRules": { + "always-fail": false + }, "rules": { "always-fail": false } diff --git a/test/config/tslint-extends-package-two-levels.json b/test/config/tslint-extends-package-two-levels.json index a61c1cb9d2d..2e2a12b63ac 100644 --- a/test/config/tslint-extends-package-two-levels.json +++ b/test/config/tslint-extends-package-two-levels.json @@ -1,6 +1,9 @@ { "extends": "tslint-test-config/tslint.json", "rulesDirectory": "../files/custom-rules", + "jsRules": { + "always-fail": false + }, "rules": { "always-fail": false } diff --git a/test/config/tslint-extends-package.json b/test/config/tslint-extends-package.json index 445ed231aca..ed5eced16c4 100644 --- a/test/config/tslint-extends-package.json +++ b/test/config/tslint-extends-package.json @@ -1,5 +1,9 @@ { "extends": "tslint-test-custom-rules", + "jsRules": { + "rule-two": true, + "rule-three": false + }, "rules": { "rule-two": true, "rule-three": false diff --git a/test/config/tslint-extends-relative.json b/test/config/tslint-extends-relative.json index 006b647d0eb..c53505e38af 100644 --- a/test/config/tslint-extends-relative.json +++ b/test/config/tslint-extends-relative.json @@ -1,5 +1,8 @@ { "extends": "./tslint-custom-rules-with-two-dirs.json", + "jsRules": { + "always-fail": false + }, "rules": { "always-fail": false } diff --git a/test/config/tslint-with-jsrules.json b/test/config/tslint-with-jsrules.json new file mode 100644 index 00000000000..dc4f5463b1c --- /dev/null +++ b/test/config/tslint-with-jsrules.json @@ -0,0 +1,5 @@ +{ + "jsRules": { + "rule": true + } +} \ No newline at end of file diff --git a/test/configurationTests.ts b/test/configurationTests.ts index 9e99caf5433..d7f24d0b201 100644 --- a/test/configurationTests.ts +++ b/test/configurationTests.ts @@ -23,6 +23,7 @@ import {IConfigurationFile, extendConfigurationFile, loadConfigurationFromPath} describe("Configuration", () => { it("extendConfigurationFile", () => { const EMPTY_CONFIG: IConfigurationFile = { + jsRules: {}, rules: {}, rulesDirectory: [], }; @@ -30,23 +31,34 @@ describe("Configuration", () => { assert.deepEqual(extendConfigurationFile({}, {}), EMPTY_CONFIG); assert.deepEqual(extendConfigurationFile({}, EMPTY_CONFIG), EMPTY_CONFIG); assert.deepEqual(extendConfigurationFile(EMPTY_CONFIG, {}), EMPTY_CONFIG); - assert.deepEqual(extendConfigurationFile({}, {rules: {foo: "bar"}, rulesDirectory: "foo"}), { + assert.deepEqual(extendConfigurationFile({}, { + jsRules: { row: "oar" }, + rules: { foo: "bar" }, + rulesDirectory: "foo", + }), { + jsRules: { row: "oar" }, rules: {foo: "bar"}, rulesDirectory: ["foo"], }); assert.deepEqual(extendConfigurationFile({ + jsRules: { row: "oar" }, rules: { a: 1, b: 2, }, rulesDirectory: ["foo", "bar"], }, { + jsRules: { fly: "wings" }, rules: { b: 1, c: 3, }, rulesDirectory: "baz", }), { + jsRules: { + fly: "wings", + row: "oar", + }, rules: { a: 1, b: 2, @@ -63,6 +75,8 @@ describe("Configuration", () => { assert.isArray(config.rulesDirectory); assert.isTrue(config.rules["no-fail"]); assert.isFalse(config.rules["always-fail"]); + assert.isTrue(config.jsRules["no-fail"]); + assert.isFalse(config.jsRules["always-fail"]); }); it("extends with package", () => { @@ -70,6 +84,11 @@ describe("Configuration", () => { assert.isArray(config.rulesDirectory); /* tslint:disable:object-literal-sort-keys */ + assert.deepEqual(config.jsRules, { + "rule-one": true, + "rule-two": true, + "rule-three": false, + }); assert.deepEqual(config.rules, { "rule-one": true, "rule-two": true, @@ -82,6 +101,10 @@ describe("Configuration", () => { let config = loadConfigurationFromPath("./test/config/tslint-extends-package-no-mod.json"); assert.isArray(config.rulesDirectory); + assert.deepEqual(config.jsRules, { + "rule-one": true, + "rule-two": false, + }); assert.deepEqual(config.rules, { "rule-one": true, "rule-two": false, @@ -90,6 +113,8 @@ describe("Configuration", () => { it("extends with builtin", () => { const config = loadConfigurationFromPath("./test/config/tslint-extends-builtin.json"); + assert.isTrue(config.jsRules["no-var-keyword"]); + assert.isFalse(config.jsRules["no-eval"]); assert.isTrue(config.rules["no-var-keyword"]); assert.isFalse(config.rules["no-eval"]); }); @@ -119,6 +144,9 @@ describe("Configuration", () => { it("extends with package installed relative to tslint", () => { fs.writeFileSync(tmpfile, JSON.stringify({ extends: "tslint-test-config-non-relative" })); let config = loadConfigurationFromPath(tmpfile); + assert.deepEqual(config.jsRules, { + "class-name": true, + }); assert.deepEqual(config.rules, { "class-name": true, }); @@ -133,6 +161,12 @@ describe("Configuration", () => { assert.isTrue(fs.existsSync(config.rulesDirectory[0])); assert.isTrue(fs.existsSync(config.rulesDirectory[1])); /* tslint:disable:object-literal-sort-keys */ + assert.deepEqual(config.jsRules, { + "always-fail": false, + "rule-one": true, + "rule-two": true, + "rule-four": true, + }); assert.deepEqual(config.rules, { "always-fail": false, "rule-one": true, @@ -146,6 +180,12 @@ describe("Configuration", () => { let config = loadConfigurationFromPath("./test/config/tslint-extends-package-array.json"); assert.isArray(config.rulesDirectory); + assert.deepEqual(config.jsRules, { + "always-fail": false, + "no-fail": true, + "rule-one": true, + "rule-two": false, + }); assert.deepEqual(config.rules, { "always-fail": false, "no-fail": true, @@ -158,6 +198,11 @@ describe("Configuration", () => { const config = loadConfigurationFromPath("./test/config/tslint-with-comments.json"); /* tslint:disable:object-literal-sort-keys */ + assert.deepEqual(config.jsRules, { + "rule-two": true, + "rule-three": "//not a comment", + "rule-four": "/*also not a comment*/", + }); assert.deepEqual(config.rules, { "rule-two": true, "rule-three": "//not a comment", @@ -172,6 +217,7 @@ describe("Configuration", () => { it("can load a built-in configuration", () => { const config = loadConfigurationFromPath("tslint:recommended"); + assert.isTrue(config.jsRules["no-eval"]); assert.isTrue(config.rules["no-eval"]); }); diff --git a/test/ruleLoaderTests.ts b/test/ruleLoaderTests.ts index 064cc642f93..70324afd3bb 100644 --- a/test/ruleLoaderTests.ts +++ b/test/ruleLoaderTests.ts @@ -72,4 +72,24 @@ describe("Rule Loader", () => { const rules = loadRules(validConfiguration, {}, [RULES_DIRECTORY]); assert.equal(rules.length, 5); }); + + it("loads js rules", () => { + const validConfiguration: {[name: string]: any} = { + "class-name": true, + }; + + const rules = loadRules(validConfiguration, {}, RULES_DIRECTORY, true); + assert.equal(rules.length, 1); + }); + + it("throws if an invalid rule is adopted", () => { + const invalidConfiguration: {[name: string]: any} = { + "array-type": [true, "array"], + }; + + assert.throws( + () => loadRules(invalidConfiguration, {}, RULES_DIRECTORY, true), + /array-type/ + ); + }); }); diff --git a/test/rules/align/arguments/test.js.lint b/test/rules/align/arguments/test.js.lint new file mode 100644 index 00000000000..3ecef0a198f --- /dev/null +++ b/test/rules/align/arguments/test.js.lint @@ -0,0 +1,152 @@ +function invalidParametersAlignment1(a, +b) { + var i = 0; +} + +function invalidParametersAlignment2(a, b, +c) { + var i = 0; +} + +function invalidParametersAlignment3(a, + b, + c) { + var i = 0; +} + +class C1 { + invalidParametersAlignment(a, + b) + { + } +} + +class InvalidAlignmentInConstructor { + constructor(a, + str) + { + } +} + +var invalidParametersAlignment4 = function(xxx, + yyy) { return true; } + +function validParametersAlignment1(a, b) { + var i = 0; +} + +function validParametersAlignment2(a, b, + c) { + var i = 0; +} + +function validParametersAlignment3(a, + b, + c) { + var i = 0; +} + +function validParametersAlignment4( + a, + b, + c) { + var i = 0; +} + +var validParametersAlignment6 = function(xxx, + yyy) { return true; } + +/////// + +function invalidArgumentsAlignment1() +{ + f(10, + 'abcd', 0); + ~~~~~~ [arguments are not aligned] +} + +function invalidArgumentsAlignment2() +{ + f(10, + 'abcd', + 0); + ~ [arguments are not aligned] + +} + +class Foo { + constructor(a, + str) + { + } +} + +var invalidConstructorArgsAlignment = new foo(10, + "abcd"); + ~~~~~~ [arguments are not aligned] + +function validArgumentsAlignment1() +{ + f(101, 'xyz', 'abc'); +} + +function validArgumentsAlignment2() +{ + f(1, + 2, + 3, + 4); +} + +function validArgumentsAlignment3() +{ + f( + 1, + 2, + 3, + 4); +} + +function validArgumentsAlignment3() +{ + f(1, 2, + 3, 4); +} + +//////// + +function invalidStatementsAlignment1() +{ + var i = 0; + var j = 0; + var k = 1; +} + +function invalidStatementsAlignment1() +{ + var i = 0; + { + var j = 0; + var k = 1; + } +} + +function validStatementsAlignment1() +{ + var i = 0; + var j = 0; + var k = 1; +} + +function validStatementsAlignment2() +{ + var i = 0; + { + var j = 0; + var k = 1; + } +} + +function shouldntCrash() { + let f = new Foo; +} diff --git a/test/rules/align/arguments/tslint.json b/test/rules/align/arguments/tslint.json index 642cc953dcf..22ccf5037b3 100644 --- a/test/rules/align/arguments/tslint.json +++ b/test/rules/align/arguments/tslint.json @@ -1,5 +1,8 @@ { "rules": { "align": [true, "arguments"] + }, + "jsRules": { + "align": [true, "arguments"] } } diff --git a/test/rules/align/parameters/test.js.lint b/test/rules/align/parameters/test.js.lint new file mode 100644 index 00000000000..2822562e3b3 --- /dev/null +++ b/test/rules/align/parameters/test.js.lint @@ -0,0 +1,38 @@ +function invalidParametersAlignment1(a, +b) { +~ [parameters are not aligned] + var i = 0; +} + +function invalidParametersAlignment2(a, b, +c) { +~ [parameters are not aligned] + var i = 0; +} + +function invalidParametersAlignment3(a, + b, + ~ [parameters are not aligned] + c) { + var i = 0; +} + +class C1 { + invalidParametersAlignment(a, + b) + ~ [parameters are not aligned] + { + } +} + +class InvalidAlignmentInConstructor { + constructor(a, + str) + ~~~ [parameters are not aligned] + { + } +} + +var invalidParametersAlignment4 = function(xxx, + yyy) { return true; } + ~~~ [parameters are not aligned] diff --git a/test/rules/align/parameters/tslint.json b/test/rules/align/parameters/tslint.json index b9360403062..5c0c0f8c3d6 100644 --- a/test/rules/align/parameters/tslint.json +++ b/test/rules/align/parameters/tslint.json @@ -1,5 +1,8 @@ { "rules": { "align": [true, "parameters"] + }, + "jsRules": { + "align": [true, "parameters"] } } diff --git a/test/rules/align/statements/test.js.lint b/test/rules/align/statements/test.js.lint new file mode 100644 index 00000000000..576e767a2e1 --- /dev/null +++ b/test/rules/align/statements/test.js.lint @@ -0,0 +1,151 @@ +function invalidParametersAlignment1(a, +b) { + var i = 0; +} + +function invalidParametersAlignment2(a, b, +c) { + var i = 0; +} + +function invalidParametersAlignment3(a, + b, + c) { + var i = 0; +} + +class C1 { + invalidParametersAlignment(a, + b) + { + } +} + +class InvalidAlignmentInConstructor { + constructor(a, + str) + { + } +} + +var invalidParametersAlignment4 = function(xxx, + yyy) { return true; } + +function validParametersAlignment1(a, b) { + var i = 0; +} + +function validParametersAlignment2(a, b, + c) { + var i = 0; +} + +function validParametersAlignment3(a, + b, + c) { + var i = 0; +} + +function validParametersAlignment4( + a, + b, + c) { + var i = 0; +} + +var validParametersAlignment6 = function(xxx, + yyy) { return true; } + + +/////// + +function invalidArgumentsAlignment1() +{ + f(10, + 'abcd', 0); +} + +function invalidArgumentsAlignment2() +{ + f(10, + 'abcd', + 0); +} + +class Foo { + constructor(a, + str) + { + } +} + +var invalidConstructorArgsAlignment = new foo(10, + "abcd"); + +function validArgumentsAlignment1() +{ + f(101, 'xyz', 'abc'); +} + +function validArgumentsAlignment2() +{ + f(1, + 2, + 3, + 4); +} + +function validArgumentsAlignment3() +{ + f( + 1, + 2, + 3, + 4); +} + +function validArgumentsAlignment3() +{ + f(1, 2, + 3, 4); +} + +//////// + +function invalidStatementsAlignment1() +{ + var i = 0; + var j = 0; + var k = 1; + ~~~~~~~~~~ [statements are not aligned] +} + +function invalidStatementsAlignment1() +{ + var i = 0; + { + var j = 0; + var k = 1; + ~~~~~~~~~~ [statements are not aligned] + } +} + +function validStatementsAlignment1() +{ + var i = 0; + var j = 0; + var k = 1; +} + +function validStatementsAlignment2() +{ + var i = 0; + { + var j = 0; + var k = 1; + } +} + +function shouldntCrash() { + let f = new Foo; +} diff --git a/test/rules/align/statements/tslint.json b/test/rules/align/statements/tslint.json index 3bd25ec81d8..b03bdca923a 100644 --- a/test/rules/align/statements/tslint.json +++ b/test/rules/align/statements/tslint.json @@ -1,5 +1,8 @@ { "rules": { "align": [true, "statements"] + }, + "jsRules": { + "align": [true, "statements"] } } diff --git a/test/rules/arrow-parens/test.js.lint b/test/rules/arrow-parens/test.js.lint new file mode 100644 index 00000000000..852f9b29d7e --- /dev/null +++ b/test/rules/arrow-parens/test.js.lint @@ -0,0 +1,15 @@ +// valid case +var a = (a) => {}; +var b = (a: number) => {}; +var c = (a, b) => {}; +var f = (...rest) => {}; +var f = a: number => {}; // TSLint don't warn. But syntax is wrong. +class Foo { + a: (a) =>{} +} + +// invalid case +var e = (a => {})(1); + ~ [Parentheses are required around the parameters of an arrow function definition] +var f = a => {}; + ~ [Parentheses are required around the parameters of an arrow function definition] diff --git a/test/rules/arrow-parens/tslint.json b/test/rules/arrow-parens/tslint.json index f2bb606a314..bce07ce14c4 100644 --- a/test/rules/arrow-parens/tslint.json +++ b/test/rules/arrow-parens/tslint.json @@ -1,5 +1,8 @@ { "rules": { "arrow-parens": true + }, + "jsRules": { + "arrow-parens": true } } diff --git a/test/rules/ban/test.js.lint b/test/rules/ban/test.js.lint new file mode 100644 index 00000000000..3ac20772ce8 --- /dev/null +++ b/test/rules/ban/test.js.lint @@ -0,0 +1,15 @@ +console.time(); +window.toString(); +~~~~~~~~~~~~~~~ [Calls to 'window.toString' are not allowed.] +console.log(); +document.window.toString(); +~~~~~~~~~~~~~~~~~~~~~~~~ [Calls to 'window.toString' are not allowed.] +reference.randomContainer.window.toString(); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Calls to 'window.toString' are not allowed.] +globals.getDocument().window.toString(); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Calls to 'window.toString' are not allowed.] +_.keys(obj).forEach(fun); +_.forEach(fun); +~~~~~~~~~ [Calls to '_.forEach' are not allowed.] +_.filter(array); +~~~~~~~~ [Calls to '_.filter' are not allowed. Use the native JavaScript 'myArray.filter' instead.] \ No newline at end of file diff --git a/test/rules/ban/tslint.json b/test/rules/ban/tslint.json index ca4c09b14f7..877d1ae7f3c 100644 --- a/test/rules/ban/tslint.json +++ b/test/rules/ban/tslint.json @@ -10,5 +10,13 @@ ["_", "forEach"], ["_", "filter", "Use the native JavaScript 'myArray.filter' instead."] ] + }, + "jsRules": { + "ban": [ + true, + ["window", "toString"], + ["_", "forEach"], + ["_", "filter", "Use the native JavaScript 'myArray.filter' instead."] + ] } } diff --git a/test/rules/class-name/test.js.lint b/test/rules/class-name/test.js.lint new file mode 100644 index 00000000000..d8333276abd --- /dev/null +++ b/test/rules/class-name/test.js.lint @@ -0,0 +1,17 @@ +class ValidClassName { + +} + +class invalidClassName { + ~~~~~~~~~~~~~~~~ [0] +} + +class Another_Invalid_Class_Name { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] +} + +export default class { + // should not fail +} + +[0]: Class name must be in pascal case diff --git a/test/rules/class-name/tslint.json b/test/rules/class-name/tslint.json index fcaed86a61e..675b68c2947 100644 --- a/test/rules/class-name/tslint.json +++ b/test/rules/class-name/tslint.json @@ -1,5 +1,8 @@ { "rules": { "class-name": true + }, + "jsRules": { + "class-name": true } } diff --git a/test/rules/comment-format/lower/test.js.lint b/test/rules/comment-format/lower/test.js.lint new file mode 100644 index 00000000000..6b0f7e4cfb2 --- /dev/null +++ b/test/rules/comment-format/lower/test.js.lint @@ -0,0 +1,25 @@ +class Clazz { // this comment is correct + /* block comment + * adada + */ + public funcxion() { // This comment has a capital letter starting it + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [lower] + //This comment is on its own line, and starts with a capital _and_ no space + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [lower] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [space] + console.log("test"); //this comment has no space + ~~~~~~~~~~~~~~~~~~~~~~~~~ [space] + } + /// +} + +//#region test +//#endregion + +`${location.protocol}//${location.hostname}` + +//noinspection JSUnusedGlobalSymbols +const unusedVar = 'unneeded value'; + +[lower]: comment must start with lowercase letter +[space]: comment must start with a space diff --git a/test/rules/comment-format/lower/tslint.json b/test/rules/comment-format/lower/tslint.json index b5c3658ef21..6e48863e1c2 100644 --- a/test/rules/comment-format/lower/tslint.json +++ b/test/rules/comment-format/lower/tslint.json @@ -1,5 +1,8 @@ { "rules": { "comment-format": [true, "check-space", "check-lowercase"] + }, + "jsRules": { + "comment-format": [true, "check-space", "check-lowercase"] } } diff --git a/test/rules/curly/test.js.lint b/test/rules/curly/test.js.lint new file mode 100644 index 00000000000..54a6099cc81 --- /dev/null +++ b/test/rules/curly/test.js.lint @@ -0,0 +1,81 @@ +if (x == 3) { + console.log("x"); +} + +if (y == 4) +{ + console.log("y"); +} + + if (z == 5) // failure + ~~~~~~~~~~~~~~~~~~~~~~ + console.log("z"); +~~~~~~~~~~~~~~~~~~~~~~~~~ [if statements must be braced] + +for (i = 0; i < 1; ++i) { + console.log("i"); +} + +for (j = 0; j < 1; ++j) +{ + console.log("j"); +} + + for (k = 0; k < 1; ++k) // failure + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + console.log("k"); +~~~~~~~~~~~~~~~~~~~~~~~ [for statements must be braced] + +for (k in l) // failure +~~~~~~~~~~~~~~~~~~~~~~~ + console.log("l"); +~~~~~~~~~~~~~~~~~~~~~ [for statements must be braced] + +while (m < 0) { + console.log("q"); +} + +while (n < 0) +{ + console.log("r"); +} + +while (n < 0) // failure +~~~~~~~~~~~~~~~~~~~~~~~~ + console.log("s"); +~~~~~~~~~~~~~~~~~~~~~ [while statements must be braced] + +do { + console.log("m"); +} while (i == 1); + +do +{ + console.log("n"); +} +while (j == 1); + +do // failure +~~~~~~~~~~~~~ + console.log("o"); +~~~~~~~~~~~~~~~~~~~~~ +while (k == 1); +~~~~~~~~~~~~~~~ [do statements must be braced] + +if (true) { + console.log("x"); +} else console.log("y"); // failure + ~~~~~~~~~~~~~~~~~~~~~~ [else statements must be braced] + +if (true) { + console.log("x"); +} else if (true) {console.log("y")}; + +for (let x of [1, 2, 3]) { + console.log(x); +} + +for (let y of [1, 2, 3]) // failure +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + console.log(y); +~~~~~~~~~~~~~~~~~~~ [for statements must be braced] diff --git a/test/rules/curly/tslint.json b/test/rules/curly/tslint.json index c0855ef9fd0..26d7c42bf48 100644 --- a/test/rules/curly/tslint.json +++ b/test/rules/curly/tslint.json @@ -1,5 +1,8 @@ { "rules": { "curly": true + }, + "jsRules": { + "curly": true } } diff --git a/test/rules/file-header/bad-shebang/test.js.lint b/test/rules/file-header/bad-shebang/test.js.lint new file mode 100644 index 00000000000..c55e4ad5604 --- /dev/null +++ b/test/rules/file-header/bad-shebang/test.js.lint @@ -0,0 +1,18 @@ +#!/usr/bin/env node + +~nil [missing file header] +/* + * Bad header 3 + */ + +export class A { + x = 1; + + B() { + return 2; + } +} + +/* + * Good header 4 + */ diff --git a/test/rules/file-header/bad-shebang/tslint.json b/test/rules/file-header/bad-shebang/tslint.json index 79f26da8b41..d995363715f 100644 --- a/test/rules/file-header/bad-shebang/tslint.json +++ b/test/rules/file-header/bad-shebang/tslint.json @@ -1,5 +1,8 @@ { "rules": { "file-header": [true, "Good header \\d"] + }, + "jsRules": { + "file-header": [true, "Good header \\d"] } } diff --git a/test/rules/file-header/bad-use-strict/test.js.lint b/test/rules/file-header/bad-use-strict/test.js.lint new file mode 100644 index 00000000000..b46dceac795 --- /dev/null +++ b/test/rules/file-header/bad-use-strict/test.js.lint @@ -0,0 +1,18 @@ +"use strict"; +~nil [missing file header] + +/* + * Bad header 5 + */ + +export class A { + x = 1; + + B() { + return 2; + } +} + +/* + * Good header 6 + */ diff --git a/test/rules/file-header/bad-use-strict/tslint.json b/test/rules/file-header/bad-use-strict/tslint.json index 79f26da8b41..d995363715f 100644 --- a/test/rules/file-header/bad-use-strict/tslint.json +++ b/test/rules/file-header/bad-use-strict/tslint.json @@ -1,5 +1,8 @@ { "rules": { "file-header": [true, "Good header \\d"] + }, + "jsRules": { + "file-header": [true, "Good header \\d"] } } diff --git a/test/rules/file-header/bad/test.js.lint b/test/rules/file-header/bad/test.js.lint new file mode 100644 index 00000000000..f26963fcabf --- /dev/null +++ b/test/rules/file-header/bad/test.js.lint @@ -0,0 +1,16 @@ +/* +~nil [missing file header] + * Bad header 1 + */ + +export class A { + public x = 1; + + public B() { + return 2; + } +} + +/* + * Good header 2 + */ diff --git a/test/rules/file-header/bad/tslint.json b/test/rules/file-header/bad/tslint.json index 79f26da8b41..d995363715f 100644 --- a/test/rules/file-header/bad/tslint.json +++ b/test/rules/file-header/bad/tslint.json @@ -1,5 +1,8 @@ { "rules": { "file-header": [true, "Good header \\d"] + }, + "jsRules": { + "file-header": [true, "Good header \\d"] } } diff --git a/test/rules/file-header/good-shebang/test.js.lint b/test/rules/file-header/good-shebang/test.js.lint new file mode 100644 index 00000000000..7bf31c076c2 --- /dev/null +++ b/test/rules/file-header/good-shebang/test.js.lint @@ -0,0 +1,14 @@ +#!/usr/bin/env node + + +/* + * Good header 2 + */ + +export class A { + x = 1; + + B() { + return 2; + } +} diff --git a/test/rules/file-header/good-shebang/tslint.json b/test/rules/file-header/good-shebang/tslint.json index 79f26da8b41..d995363715f 100644 --- a/test/rules/file-header/good-shebang/tslint.json +++ b/test/rules/file-header/good-shebang/tslint.json @@ -1,5 +1,8 @@ { "rules": { "file-header": [true, "Good header \\d"] + }, + "jsRules": { + "file-header": [true, "Good header \\d"] } } diff --git a/test/rules/file-header/good-use-strict/test.js.lint b/test/rules/file-header/good-use-strict/test.js.lint new file mode 100644 index 00000000000..3e469beb3a1 --- /dev/null +++ b/test/rules/file-header/good-use-strict/test.js.lint @@ -0,0 +1,13 @@ +/* + * Good header 3 + */ + +"use strict"; + +export class A { + x = 1; + + B() { + return 2; + } +} diff --git a/test/rules/file-header/good-use-strict/tslint.json b/test/rules/file-header/good-use-strict/tslint.json index 79f26da8b41..d995363715f 100644 --- a/test/rules/file-header/good-use-strict/tslint.json +++ b/test/rules/file-header/good-use-strict/tslint.json @@ -1,5 +1,8 @@ { "rules": { "file-header": [true, "Good header \\d"] + }, + "jsRules": { + "file-header": [true, "Good header \\d"] } } diff --git a/test/rules/file-header/good/test.js.lint b/test/rules/file-header/good/test.js.lint new file mode 100644 index 00000000000..f480e249138 --- /dev/null +++ b/test/rules/file-header/good/test.js.lint @@ -0,0 +1,12 @@ + +/* + * Good header 1 + */ + +export class A { + x = 1; + + B() { + return 2; + } +} diff --git a/test/rules/file-header/good/tslint.json b/test/rules/file-header/good/tslint.json index 79f26da8b41..d995363715f 100644 --- a/test/rules/file-header/good/tslint.json +++ b/test/rules/file-header/good/tslint.json @@ -1,5 +1,8 @@ { "rules": { "file-header": [true, "Good header \\d"] + }, + "jsRules": { + "file-header": [true, "Good header \\d"] } } diff --git a/test/rules/forin/test.js.lint b/test/rules/forin/test.js.lint new file mode 100644 index 00000000000..a621922b16b --- /dev/null +++ b/test/rules/forin/test.js.lint @@ -0,0 +1,41 @@ +function a() { + for (var i in obj) { + ~~~~~~~~~~~~~~~~~~~~ + console.log("i"); +~~~~~~~~~~~~~~~~~~~~~~~~~ + } +~~~~~ [0] + + for (var j in obj) { + ~~~~~~~~~~~~~~~~~~~~ + if (j === 3) { +~~~~~~~~~~~~~~~~~~~~~~ + console.log("j"); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } +~~~~~~~~~ + console.log("j"); +~~~~~~~~~~~~~~~~~~~~~~~~~ + } +~~~~~ [0] + + for (var k in obj) { + if (obj.hasOwnProperty(k)) { + console.log("k"); + } + } + + for (var m in obj) { + if (!obj.hasOwnProperty(m)) { + continue; + } + console.log("m"); + } + + for (var n in obj) { + if (!obj.hasOwnProperty(n)) continue; + console.log("m"); + } +} + +[0]: for (... in ...) statements must be filtered with an if statement diff --git a/test/rules/forin/tslint.json b/test/rules/forin/tslint.json index c7c10b4b899..f42f3151de7 100644 --- a/test/rules/forin/tslint.json +++ b/test/rules/forin/tslint.json @@ -1,5 +1,8 @@ { "rules": { "forin": true + }, + "jsRules": { + "forin": true } } diff --git a/test/rules/indent/spaces/test.js.lint b/test/rules/indent/spaces/test.js.lint new file mode 100644 index 00000000000..f119a9cd0ef --- /dev/null +++ b/test/rules/indent/spaces/test.js.lint @@ -0,0 +1,136 @@ +// valid code + + var func = () => { + console.warn("hi"); + }; + + class TestClass1 { + variable; + + testFunction() { + this.variable = 3; + } + } + + var obj = { + a: 1, + b: 2, + c: 3 + }; + + switch (integerValue) { + case 1: + console.warn("1"); + break; + default: + console.warn("default"); + break; + } + + function loops() { + for (var i = 0; i < 1; ++i) { + console.warn(i); + } + + while (i < 1) { + console.warn(i); + } + + do { + console.warn(i); + } while (i < 1); + + if (i < 1) { + console.warn(i); + } else { + console.warn(i + 1); + } + } + + +// invalid code +// we get a weird scenario here where our ~~ underlines don't quite line up with the line above +// this is because tabs are only one character and thus only one ~ goes beneath them. + +function name() { + var test = 123; +~~ [0] +} + +class TestClass { + variable; +~ [0] + + testFunction() { +~ [0] + this.variable = 3; +~~ [0] + } +~ [0] +} + +var obj = { + a: 1, +~ [0] + b: 2, + c: 3 +}; + +switch (integerValue) { + case 0: +~ [0] + console.warn("1"); +~~ [0] + break; +~~ [0] + case 1: + console.warn("1"); + break; + default: +~ [0] + console.warn("default"); +~~ [0] + break; +~~ [0] +} + +for (var i = 0; i < 1; ++i) { + console.warn("123"); +~ [0] +} + +while (i < 1) { + console.warn("123"); +~ [0] +} + +do { + console.warn("123"); +~ [0] +} while (i < 1); + +if (i < 1) { + console.warn("123"); +~ [0] +} + +var arr = [ + 1, +~ [0] + 2 +]; + +var arr2 = [ + { + a: 1, +~~ [0] + b: 2 + }, +~ [0] + { + a: 3, + b: 4 + } +]; + +[0]: space indentation expected diff --git a/test/rules/indent/spaces/tslint.json b/test/rules/indent/spaces/tslint.json index 98c8abd97e1..05594054308 100644 --- a/test/rules/indent/spaces/tslint.json +++ b/test/rules/indent/spaces/tslint.json @@ -1,5 +1,8 @@ { "rules": { "indent": [true, "spaces"] + }, + "jsRules": { + "indent": [true, "spaces"] } } diff --git a/test/rules/indent/tabs/test.js.lint b/test/rules/indent/tabs/test.js.lint new file mode 100644 index 00000000000..c06841aad1f --- /dev/null +++ b/test/rules/indent/tabs/test.js.lint @@ -0,0 +1,134 @@ +// valid code + /** + * Some documentation + */ + var func = () => { + console.warn("hi"); + }; + + class TestClass1 { + variable; + + testFunction() { + this.variable = 3; + } + } + + var obj = { + a: 1, + b: 2, + c: 3 + }; + + switch (integerValue) { + case 1: + console.warn("1"); + break; + default: + console.warn("default"); + break; + } + + function loops() { + for (var i = 0; i < 1; ++i) { + console.warn(i); + } + + while (i < 1) { + console.warn(i); + } + + do { + console.warn(i); + } while (i < 1); + + if (i < 1) { + console.warn(i); + } else { + console.warn(i + 1); + } + } + +// invalid code +function name() { + var test = 123; +~~~~~~~~ [0] +} + +class TestClass { + variable; +~~~~ [0] + + testFunction() { +~~~~ [0] + this.variable = 3; +~~~~~~~ [0] + } +~~~~ [0] +} + +var obj = { + a: 1, +~~~~ [0] + b: 2, + c: 3 +}; + +switch (integerValue) { + case 0: + console.warn("1"); + break; + case 1: +~~~~ [0] + console.warn("1"); +~~~~~~~~ [0] + break; +~~~~~~~~ [0] + default: +~~~~ [0] + console.warn("default"); +~~~~~~~~ [0] + break; +~~~~~~~~ [0] +} + +for (var i = 0; i < 1; ++i) { + console.warn("123"); +~~~~ [0] +} + +while (i < 1) { + console.warn("123"); +~~~~ [0] +} + +do { + console.warn("123"); +~~~~ [0] +} while (i < 1); + +if (i < 1) { + console.warn("123"); +~~~~ [0] +} + +var arr = [ + 1, +~~~~ [0] + 2 +]; + +var arr2 = [ + { + a: 1, +~~~~~~~~ [0] + b: 2 + }, +~~~~ [0] + { + a: 3, + b: 4 + } +]; + +[0]: tab indentation expected diff --git a/test/rules/indent/tabs/tslint.json b/test/rules/indent/tabs/tslint.json index 61b62f2a381..8facc3dcf8f 100644 --- a/test/rules/indent/tabs/tslint.json +++ b/test/rules/indent/tabs/tslint.json @@ -1,5 +1,8 @@ { "rules": { "indent": [true, "tabs"] + }, + "jsRules": { + "indent": [true, "tabs"] } } diff --git a/test/rules/jsdoc-format/jsdoc-windows.js.lint b/test/rules/jsdoc-format/jsdoc-windows.js.lint new file mode 100644 index 00000000000..ffe987ccb6c --- /dev/null +++ b/test/rules/jsdoc-format/jsdoc-windows.js.lint @@ -0,0 +1,10 @@ +/** + * MyClass + * + * Does classy things and impresses everyone. Quite a debonair class indeed. + * + * This file has all windows line endings "\r\n" and valid jsdoc. + */ +class MyClass { + +} \ No newline at end of file diff --git a/test/rules/jsdoc-format/jsdoc.js.lint b/test/rules/jsdoc-format/jsdoc.js.lint new file mode 100644 index 00000000000..52444146974 --- /dev/null +++ b/test/rules/jsdoc-format/jsdoc.js.lint @@ -0,0 +1,79 @@ +function makeHeader(pkg: Package) { + return [ + `\t/**`, + `\t * ${pkg.name} v${pkg.version}`, + `\t */` + ].join("\r\n"); +} + +class Clazz { //this is not a block comment + /* block comment + *Not a jsdoc and not subject to the rules lalala + * oh look I'm over here and you can't do anything about me + *and now I'm here, wheeee +I've even got characters where I shouldn't. How fun! * + You can't stop me! */ + public funcxion() { + /** + * This is jsdoc + * and it is correct + * so should be no errors here + * + * not on the above line either + */ + } + + /** + * this is also jsdoc + *and it has a problem on this line +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [format] + */ + + /** + * this jsoc is fine + * up until the last line when it isn't + */ +~~~~~ [asterisks] + + /** + * this jsdoc has characters where it really should +not */ +~~~~~~~ [format] + + /** + * same thing with this +one * +~~~~~~ [format] + */ + + /** + * what else can go wrong? + * oh right this +~~~~~~~~~~~~~~~~~~ [asterisks] + */ + + /**a bad one liner */ + ~~~~~~~~~~~~~~~~~~~~~ [format] + + /** another bad one liner*/ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ [format] + + /** */ + + /** */ + + /** a good one */ + +} + +// Regression test: jsdoc rule shouldn't look inside template strings (https://github.com/palantir/tslint/issues/332) +function makeHeader(pkg: Package) { + return [ + `\t/**`, + `\t * ${pkg.name} v${pkg.version}`, + `\t */` + ].join("\r\n"); +} + +[format]: jsdoc is not formatted correctly on this line +[asterisks]: asterisks in jsdoc must be aligned diff --git a/test/rules/jsdoc-format/tslint.json b/test/rules/jsdoc-format/tslint.json index 02b95774ec7..393ecc64ceb 100644 --- a/test/rules/jsdoc-format/tslint.json +++ b/test/rules/jsdoc-format/tslint.json @@ -1,5 +1,8 @@ { "rules": { "jsdoc-format": true + }, + "jsRules": { + "jsdoc-format": true } } diff --git a/test/rules/label-position/test.js.lint b/test/rules/label-position/test.js.lint new file mode 100644 index 00000000000..cd7c95afd2d --- /dev/null +++ b/test/rules/label-position/test.js.lint @@ -0,0 +1,38 @@ +var t = function() { + lab1: + ~~~~ [unexpected label on statement] + var x = 123; + + lab2: + ~~~~ [unexpected label on statement] + console.log("123"); + + lab3: + for (var i = 0; i < 5; ++i) { + break lab3; + } + + lab4: + do { + break lab4; + } while (i < 10); + + lab5: + while (i < 10) { + lab6: + while (j < 20) { + break lab5; + } + } + + lab7: + switch (i) { + case 0: + break lab7; + } + + lab8: + for (let value of [1]) { + break lab8; + } +}; diff --git a/test/rules/label-position/tslint.json b/test/rules/label-position/tslint.json index 82a6a0582e6..7e1d262f623 100644 --- a/test/rules/label-position/tslint.json +++ b/test/rules/label-position/tslint.json @@ -1,5 +1,8 @@ { "rules": { "label-position": true + }, + "jsRules": { + "label-position": true } } diff --git a/test/rules/linebreak-style/emptyFile/test.js.lint b/test/rules/linebreak-style/emptyFile/test.js.lint new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/rules/linebreak-style/emptyFile/tslint.json b/test/rules/linebreak-style/emptyFile/tslint.json index f82a6f4d1df..8b246326003 100644 --- a/test/rules/linebreak-style/emptyFile/tslint.json +++ b/test/rules/linebreak-style/emptyFile/tslint.json @@ -1,5 +1,8 @@ { "rules": { "linebreak-style": [true, "LF"] + }, + "jsRules": { + "linebreak-style": [true, "LF"] } } diff --git a/test/rules/linebreak-style/failure/CRLF/test.js.lint b/test/rules/linebreak-style/failure/CRLF/test.js.lint new file mode 100644 index 00000000000..7d55d0fe1f9 --- /dev/null +++ b/test/rules/linebreak-style/failure/CRLF/test.js.lint @@ -0,0 +1,8 @@ +// this line uses CRLF +~~~~~~~~~~~~~~~~~~~~~~ [Expected linebreak to be 'LF'] +// this line uses CRLF +~~~~~~~~~~~~~~~~~~~~~~ [Expected linebreak to be 'LF'] +// this line uses CRLF +~~~~~~~~~~~~~~~~~~~~~~ [Expected linebreak to be 'LF'] +// this line uses CRLF +~~~~~~~~~~~~~~~~~~~~~~ [Expected linebreak to be 'LF'] diff --git a/test/rules/linebreak-style/failure/CRLF/tslint.json b/test/rules/linebreak-style/failure/CRLF/tslint.json index f82a6f4d1df..8b246326003 100644 --- a/test/rules/linebreak-style/failure/CRLF/tslint.json +++ b/test/rules/linebreak-style/failure/CRLF/tslint.json @@ -1,5 +1,8 @@ { "rules": { "linebreak-style": [true, "LF"] + }, + "jsRules": { + "linebreak-style": [true, "LF"] } } diff --git a/test/rules/linebreak-style/failure/LF/test.js.lint b/test/rules/linebreak-style/failure/LF/test.js.lint new file mode 100644 index 00000000000..fa51e943c77 --- /dev/null +++ b/test/rules/linebreak-style/failure/LF/test.js.lint @@ -0,0 +1,8 @@ +// this line uses LF +~~~~~~~~~~~~~~~~~~~~ [Expected linebreak to be 'CRLF'] +// this line uses LF +~~~~~~~~~~~~~~~~~~~~ [Expected linebreak to be 'CRLF'] +// this line uses LF +~~~~~~~~~~~~~~~~~~~~ [Expected linebreak to be 'CRLF'] +// this line uses LF +~~~~~~~~~~~~~~~~~~~~ [Expected linebreak to be 'CRLF'] diff --git a/test/rules/linebreak-style/failure/LF/tslint.json b/test/rules/linebreak-style/failure/LF/tslint.json index d959e7a49e4..1c18385ac74 100644 --- a/test/rules/linebreak-style/failure/LF/tslint.json +++ b/test/rules/linebreak-style/failure/LF/tslint.json @@ -1,5 +1,8 @@ { "rules": { "linebreak-style": [true, "CRLF"] + }, + "jsRules": { + "linebreak-style": [true, "CRLF"] } } diff --git a/test/rules/linebreak-style/success/CRLF/test.js.lint b/test/rules/linebreak-style/success/CRLF/test.js.lint new file mode 100644 index 00000000000..4a60171c332 --- /dev/null +++ b/test/rules/linebreak-style/success/CRLF/test.js.lint @@ -0,0 +1,4 @@ +// this line uses CRLF +// this line uses CRLF +// this line uses CRLF +// this line uses CRLF diff --git a/test/rules/linebreak-style/success/CRLF/tslint.json b/test/rules/linebreak-style/success/CRLF/tslint.json index d959e7a49e4..1c18385ac74 100644 --- a/test/rules/linebreak-style/success/CRLF/tslint.json +++ b/test/rules/linebreak-style/success/CRLF/tslint.json @@ -1,5 +1,8 @@ { "rules": { "linebreak-style": [true, "CRLF"] + }, + "jsRules": { + "linebreak-style": [true, "CRLF"] } } diff --git a/test/rules/linebreak-style/success/LF/test.js.lint b/test/rules/linebreak-style/success/LF/test.js.lint new file mode 100644 index 00000000000..1f88a5a75a2 --- /dev/null +++ b/test/rules/linebreak-style/success/LF/test.js.lint @@ -0,0 +1,4 @@ +// this line uses LF +// this line uses LF +// this line uses LF +// this line uses LF diff --git a/test/rules/linebreak-style/success/LF/tslint.json b/test/rules/linebreak-style/success/LF/tslint.json index f82a6f4d1df..8b246326003 100644 --- a/test/rules/linebreak-style/success/LF/tslint.json +++ b/test/rules/linebreak-style/success/LF/tslint.json @@ -1,5 +1,8 @@ { "rules": { "linebreak-style": [true, "LF"] + }, + "jsRules": { + "linebreak-style": [true, "LF"] } } diff --git a/test/rules/max-file-line-count/default/test.js.lint b/test/rules/max-file-line-count/default/test.js.lint new file mode 100644 index 00000000000..6dfc34a91e3 --- /dev/null +++ b/test/rules/max-file-line-count/default/test.js.lint @@ -0,0 +1,23 @@ +function App() { +~ [This file has 23 lines, which exceeds the maximum of 10 lines allowed. Consider breaking this file up into smaller parts] + class GiveMeANumber { + + /* tslint:disable:no-any */ + num = 10; + /* tslint:enable:no-any */ + + //This is some kind of comment + constructor(){ + this.giveNumber(); + } + + /* + Here is another comment + It's very helpful. + */ + + giveNumber = () =>{ + alert(this.num); + }; + } +} diff --git a/test/rules/max-file-line-count/default/tslint.json b/test/rules/max-file-line-count/default/tslint.json index 0a612cdcda6..f132ca54701 100644 --- a/test/rules/max-file-line-count/default/tslint.json +++ b/test/rules/max-file-line-count/default/tslint.json @@ -1,5 +1,8 @@ { "rules": { "max-file-line-count": [true, 10] + }, + "jsRules": { + "max-file-line-count": [true, 10] } } diff --git a/test/rules/max-file-line-count/disabled/test.js.lint b/test/rules/max-file-line-count/disabled/test.js.lint new file mode 100644 index 00000000000..5a054246d79 --- /dev/null +++ b/test/rules/max-file-line-count/disabled/test.js.lint @@ -0,0 +1,23 @@ +/* tslint:disable:max-file-line-count */ +//This file NEEDS to be very long, so we've disabled this rule here + +function App() { + class GiveMeANumber { + + //THis is a comment about something + num = 10; + + constructor(){ + this.giveNumber(); + } + + /* + Here is another comment + It's very helpful. + */ + + giveNumber = () =>{ + alert(this.num); + }; + } +} diff --git a/test/rules/max-file-line-count/disabled/tslint.json b/test/rules/max-file-line-count/disabled/tslint.json index 0a612cdcda6..f132ca54701 100644 --- a/test/rules/max-file-line-count/disabled/tslint.json +++ b/test/rules/max-file-line-count/disabled/tslint.json @@ -1,5 +1,8 @@ { "rules": { "max-file-line-count": [true, 10] + }, + "jsRules": { + "max-file-line-count": [true, 10] } } diff --git a/test/rules/max-line-length/test.js.lint b/test/rules/max-line-length/test.js.lint new file mode 100644 index 00000000000..f6a4c466bcc --- /dev/null +++ b/test/rules/max-line-length/test.js.lint @@ -0,0 +1,5 @@ +var simpleName = 1; +var complicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedName; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Exceeds maximum line length of 140] + +var complicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicatedNameIsAcomplicat; diff --git a/test/rules/max-line-length/tslint.json b/test/rules/max-line-length/tslint.json index 26a149d34a0..c3b416d0d96 100644 --- a/test/rules/max-line-length/tslint.json +++ b/test/rules/max-line-length/tslint.json @@ -1,5 +1,8 @@ { "rules": { "max-line-length": [true, 140] + }, + "jsRules": { + "max-line-length": [true, 140] } } diff --git a/test/rules/new-parens/test.js.lint b/test/rules/new-parens/test.js.lint new file mode 100644 index 00000000000..733f48ed974 --- /dev/null +++ b/test/rules/new-parens/test.js.lint @@ -0,0 +1,14 @@ +// correct case +var foo = new Date(); + +// incorrect case +var foge = new Date; + ~~~~~~~~ [0] +class Bar {} +var bar = new Bar; + ~~~~~~~ [0] +var fogefoge = new Bar(new Foo); + ~~~~~~~ [0] + +[0]: Parentheses are required when invoking a constructor + diff --git a/test/rules/new-parens/tslint.json b/test/rules/new-parens/tslint.json index 7cd049d2253..6facdcff9ee 100644 --- a/test/rules/new-parens/tslint.json +++ b/test/rules/new-parens/tslint.json @@ -1,5 +1,8 @@ { "rules": { "new-parens": true + }, + "jsRules": { + "new-parens": true } } diff --git a/test/rules/no-arg/test.js.lint b/test/rules/no-arg/test.js.lint new file mode 100644 index 00000000000..6ac3181430d --- /dev/null +++ b/test/rules/no-arg/test.js.lint @@ -0,0 +1,12 @@ +var testVariable = 123; + +function testFunction(): number { + if(arguments.callee.caller === testFunction) { + ~~~~~~~~~ [Access to arguments.callee is forbidden] + console.log("called"); + } + + argument.callee = testFunction; + + return testVariable; +} diff --git a/test/rules/no-arg/tslint.json b/test/rules/no-arg/tslint.json index 139d0955e11..7724bd2a075 100644 --- a/test/rules/no-arg/tslint.json +++ b/test/rules/no-arg/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-arg": true + }, + "jsRules": { + "no-arg": true } } diff --git a/test/rules/no-bitwise/test.js.lint b/test/rules/no-bitwise/test.js.lint new file mode 100644 index 00000000000..f16f3bcc8b2 --- /dev/null +++ b/test/rules/no-bitwise/test.js.lint @@ -0,0 +1,6 @@ +var z = (x || 3) && (y || 4); +var yy = x | 3; + ~~~~~ [Forbidden bitwise operation] +var zz = (z || y) & (x | y); + ~~~~~~~~~~~~~~~~~~ [Forbidden bitwise operation] + ~~~~~ [Forbidden bitwise operation] diff --git a/test/rules/no-bitwise/tslint.json b/test/rules/no-bitwise/tslint.json index 9dfce74f345..9d62bc3da15 100644 --- a/test/rules/no-bitwise/tslint.json +++ b/test/rules/no-bitwise/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-bitwise": true + }, + "jsRules": { + "no-bitwise": true } } diff --git a/test/rules/no-conditional-assignment/test.js.lint b/test/rules/no-conditional-assignment/test.js.lint new file mode 100644 index 00000000000..d74a168ac97 --- /dev/null +++ b/test/rules/no-conditional-assignment/test.js.lint @@ -0,0 +1,50 @@ +// valid cases +if (x == 5) { } +if (x === 5) { } +else if (y <= 23) { } +else if ((z && a) == 7) { } +else { } + +do { } while (x == 2); +do { } while (x !== 2); + +while (x == 2) { } +while (x !== 2) { } + +for (var x = 8; x == 8; ++x) { } +for (var x = 8; x == 8; x = 12) { } +for (;;) { } + +// invalid cases +if (x = 5) { } + ~~~~~ [0] +if (a && (b = 5)) { } + ~~~~~ [0] +else if (x = 2) { } + ~~~~~ [0] + +do { } while (x = 4); + ~~~~~ [0] + +while (x = 4); + ~~~~~ [0] +while ((x = y - 12)); + ~~~~~~~~~~ [0] + +for (var x = 4; x = 8; x++) { } + ~~~~~ [0] +for (; (y == 2) && (x = 3); ) { } + ~~~~~ [0] + +if (x += 2) { } + ~~~~~~ [0] +else if (h || (x <<= 4)) { } + ~~~~~~~ [0] + +do { } while (x ^= 4) { } + ~~~~~~ [0] +while ((a = 5) && ((b == 4) || (c = 3))) + ~~~~~ [0] + ~~~~~ [0] + +[0]: Assignments in conditional expressions are forbidden diff --git a/test/rules/no-conditional-assignment/tslint.json b/test/rules/no-conditional-assignment/tslint.json index 014f7127c44..0304a5f8ff6 100644 --- a/test/rules/no-conditional-assignment/tslint.json +++ b/test/rules/no-conditional-assignment/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-conditional-assignment": true + }, + "jsRules": { + "no-conditional-assignment": true } } diff --git a/test/rules/no-consecutive-blank-lines/default/tslint.json b/test/rules/no-consecutive-blank-lines/default/tslint.json index 3aa56ee6643..46bc8118965 100644 --- a/test/rules/no-consecutive-blank-lines/default/tslint.json +++ b/test/rules/no-consecutive-blank-lines/default/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-consecutive-blank-lines": true + }, + "jsRules": { + "no-consecutive-blank-lines": true } } diff --git a/test/rules/no-consecutive-blank-lines/test.js.lint b/test/rules/no-consecutive-blank-lines/test.js.lint new file mode 100644 index 00000000000..7fa366bb359 --- /dev/null +++ b/test/rules/no-consecutive-blank-lines/test.js.lint @@ -0,0 +1,32 @@ +// the markup for this test is a little bit weird +// tslint, for the first error below, says it goes from +// [5, 1] to [6, 1], and thus the markup appears to be off (but it's not) + + +~nil +class Clazz { // comment +~nil [Consecutive blank lines are forbidden] + + funcxion() { + + // also comment + + +~nil + console.log("test"); +~nil [Consecutive blank lines are forbidden] + + } + + +~nil +} +~nil [Consecutive blank lines are forbidden] + +//Begin whitespace +// The next two lines of "code" contain only tabs or spaces, they are also considered "blank" lines + + +~ [Consecutive blank lines are forbidden] + + diff --git a/test/rules/no-console/test.js.lint b/test/rules/no-console/test.js.lint new file mode 100644 index 00000000000..2ee294b7d6b --- /dev/null +++ b/test/rules/no-console/test.js.lint @@ -0,0 +1,13 @@ +console.time(); +console.log("log"); +~~~~~~~~~~~ [Calls to 'console.log' are not allowed.] +console.dir(object); +~~~~~~~~~~~ [Calls to 'console.dir' are not allowed.] +console.info("info"); +console.trace("trace"); +console.warn("warn"); +~~~~~~~~~~~~ [Calls to 'console.warn' are not allowed.] +console.error("error"); +~~~~~~~~~~~~~ [Calls to 'console.error' are not allowed.] +console.something(); +console.timeEnd(); diff --git a/test/rules/no-console/tslint.json b/test/rules/no-console/tslint.json index 08a0d1815f8..8f639ef177d 100644 --- a/test/rules/no-console/tslint.json +++ b/test/rules/no-console/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-console": [true, "dir", "error", "log", "warn"] + }, + "jsRules": { + "no-console": [true, "dir", "error", "log", "warn"] } } diff --git a/test/rules/no-construct/test.js.lint b/test/rules/no-construct/test.js.lint new file mode 100644 index 00000000000..b11a12570b8 --- /dev/null +++ b/test/rules/no-construct/test.js.lint @@ -0,0 +1,13 @@ +var s1 = "s"; +var s2 = new String("s"); + ~~~~~~~~~~ [0] + +var n1 = 1; +var n2 = new Number(1); + ~~~~~~~~~~~~~ [0] + +var b1 = true; +var b2 = new Boolean (true); + ~~~~~~~~~~~ [0] + +[0]: Forbidden constructor, use a literal or simple function call instead diff --git a/test/rules/no-construct/tslint.json b/test/rules/no-construct/tslint.json index 9d1db2e04c1..561aacc5772 100644 --- a/test/rules/no-construct/tslint.json +++ b/test/rules/no-construct/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-construct": true + }, + "jsRules": { + "no-construct": true } } diff --git a/test/rules/no-debugger/test.js.lint b/test/rules/no-debugger/test.js.lint new file mode 100644 index 00000000000..ba9cfd1eee9 --- /dev/null +++ b/test/rules/no-debugger/test.js.lint @@ -0,0 +1,8 @@ +var testVariable = "debugger"; + +function testFunction(): number { + if (testVariable === "debugger") { + debugger; + ~~~~~~~~ [Use of debugger statements is forbidden] + } +} diff --git a/test/rules/no-debugger/tslint.json b/test/rules/no-debugger/tslint.json index 53e3193c563..2e8428b0baf 100644 --- a/test/rules/no-debugger/tslint.json +++ b/test/rules/no-debugger/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-debugger": true + }, + "jsRules": { + "no-debugger": true } } diff --git a/test/rules/no-default-export/test.js.lint b/test/rules/no-default-export/test.js.lint new file mode 100644 index 00000000000..9d99f45be62 --- /dev/null +++ b/test/rules/no-default-export/test.js.lint @@ -0,0 +1,38 @@ +switch (value) { + case 1: break; + default: break; +} + +export { SingleItem }; + +export { FirstItem, SecondItem }; + +export { Item as aliasForItem }; + +export { ItemFromImport } from 'module'; + +export * from './relativeModule'; + + +export const default = 'VALID'; + +export default 'INVALID'; + ~~~~~~~ [0] + +export default { } + ~~~~~~~ [0] + +export default class { } + ~~~~~~~ [0] + +export default class Test1 { } + ~~~~~~~ [0] + +export default function() { } + ~~~~~~~ [0] + +export default function Test2() { } + ~~~~~~~ [0] + +[0]: Use of default exports is forbidden + diff --git a/test/rules/no-default-export/tslint.json b/test/rules/no-default-export/tslint.json index ebed5e9e331..ee746473cbf 100644 --- a/test/rules/no-default-export/tslint.json +++ b/test/rules/no-default-export/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-default-export": true + }, + "jsRules": { + "no-default-export": true } } diff --git a/test/rules/no-duplicate-key/test.js.lint b/test/rules/no-duplicate-key/test.js.lint new file mode 100644 index 00000000000..78ce9d297b2 --- /dev/null +++ b/test/rules/no-duplicate-key/test.js.lint @@ -0,0 +1,46 @@ +var a = { + a: 1, + b: 2 +}; + +var x = { + axa: 1, + bd: 2, + c: 3, + axa: 4, + ~~~ [Duplicate key 'axa'] + d: 5, + ba: 3, + bd: 6, + ~~ [Duplicate key 'bd'] + axa: 6 + ~~~ [Duplicate key 'axa'] +}; + +var z = { + c: [1, 2, 3], + d: { + b: "b", + a: 11, + c: [11, 22, 33] + }, + a: 1, + b: "a" +}; + +var interspersed = { + duplicated: 1, + newContext: {}, + duplicated: 2 + ~~~~~~~~~~ [Duplicate key 'duplicated'] +}; + +var n = { + constructor: function () {}, + hasOwnProperty: function () {} +}; + +var foo = { + ["ab" + "cd"]: "efgh", + [x.axa]: "bar" +} diff --git a/test/rules/no-duplicate-key/tslint.json b/test/rules/no-duplicate-key/tslint.json index 69550402f75..d1172199f3c 100644 --- a/test/rules/no-duplicate-key/tslint.json +++ b/test/rules/no-duplicate-key/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-duplicate-key": true + }, + "jsRules": { + "no-duplicate-key": true } } diff --git a/test/rules/no-duplicate-variable/test.js.lint b/test/rules/no-duplicate-variable/test.js.lint new file mode 100644 index 00000000000..bcc2d2e675d --- /dev/null +++ b/test/rules/no-duplicate-variable/test.js.lint @@ -0,0 +1,155 @@ +var duplicated = 1; + +class Test { + myFunc() { + var notDuplicated = 123, + duplicated = 234, + someFunc = () => { + var notDuplicated = 345; + }; + + var duplicated = null; + ~~~~~~~~~~ [Duplicate variable: 'duplicated'] + } +} + +function test() { + var notDuplicated = 123, + duplicated = 234, + someFunc = () => { + var notDuplicated = 345; + }; + + var duplicated = null; + ~~~~~~~~~~ [Duplicate variable: 'duplicated'] +} + +duplicated = 2; +var duplicated = 3; + ~~~~~~~~~~ [Duplicate variable: 'duplicated'] + +// valid code +export function tmp() { + var path = require("path"); + export class MyType { + path; + } +} + +export function foo() { + export class ClassA { + id: string; + } + + export class ClassB { + id: string; + } +} + +var a = { + foo(): void { + var bar = 1; + }, + baz(): void { + var bar = 1; + } +}; + +class AccessorTest { + get accesor1(): number { + var x = 0; + return x; + } + + get accesor2(): number { + var x = 0; + return x; + } + +} + +class NoDupConstructor { + test; + constructor() { + var test = "test"; + this.test = test; + } +} + +// valid/invalid code +function letTesting() { + var a = 1; + let b = 1; + let d = 1; + if (true) { + let a = 2; + let b = 2; + let c = 2; + var d = 2; + var e = 2; + } + else { + let b = 3; + let c = 3; + let e = 3; + let f = 3; + } + var f = 4; +} + +// failure: two arguments have the same name. +function testArguments1(arg, arg): void { +} + +// failure: local var/let declarations shadow arguments. +function testArguments2(x, y): void { + var x = 1; + let y = 2; +} + +try { + // +} catch (e) { + e.blah(); + // +} + +try { + // +} catch (e) { + e.blah(); + // +} + +function testDestructuring() { + function myFunc() { + return [1, 2]; + } + + var [x, y] = myFunc(); + var [z, z] = myFunc(); // failure + ~ [Duplicate variable: 'z'] + + let [x1, y1] = myFunc(); + let [z1, z1] = myFunc(); // tsc error + + const [x2, y2] = myFunc(); + const [z2, z2] = myFunc(); // tsc error + + let [a1, [b1, c1]] = [1, [2, 3]]; + let [{a1, d1}] = [{a1: 1, d1: 4}]; // tsc error + + var [a2, [b2, c2]] = [1, [2, 3]]; + var [{a2, d2}] = [{a2: 1, d2: 4}]; // failure + ~~ [Duplicate variable: 'a2'] + + function myFunc2([a, b]) { + var a; // not a failure; caught by no-shadowed-variable + return b; + } + + var [x, y3] = myFunc(); // failure + ~ [Duplicate variable: 'x'] + var [x3, ...y] = [1, 2, 3, 4]; // failure + ~ [Duplicate variable: 'y'] +} diff --git a/test/rules/no-duplicate-variable/tslint.json b/test/rules/no-duplicate-variable/tslint.json index 9d9b7a7156a..2d1c2f4571e 100644 --- a/test/rules/no-duplicate-variable/tslint.json +++ b/test/rules/no-duplicate-variable/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-duplicate-variable": true + }, + "jsRules": { + "no-duplicate-variable": true } } diff --git a/test/rules/no-empty/test.js.lint b/test/rules/no-empty/test.js.lint new file mode 100644 index 00000000000..0bbc38c017a --- /dev/null +++ b/test/rules/no-empty/test.js.lint @@ -0,0 +1,42 @@ +if (x === 1) {} + ~~ [block is empty] +if (x === 2) { + ~ + +~nil + +~nil +} +~ [block is empty] + +function testFunction() { + ~ + +~nil +} +~ [block is empty] + +for (var x = 0; x < 1; ++x) { } + ~~~ [block is empty] + +// empty blocks with comments should be legal +for (var y = 0; y < 1; ++y) { + // empty here +} + +class testClass { + constructor(private allowed: any, private alsoAllowed: any) { + } +} + +class testClass2 { + constructor(protected allowed: any) { + } +} + +class testClass3 { + constructor(notAllowed: any) { + ~ + } +~~~~~ [block is empty] +} diff --git a/test/rules/no-empty/tslint.json b/test/rules/no-empty/tslint.json index 282eaa1ffa3..6ba025b538a 100644 --- a/test/rules/no-empty/tslint.json +++ b/test/rules/no-empty/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-empty": true + }, + "jsRules": { + "no-empty": true } } diff --git a/test/rules/no-eval/test.js.lint b/test/rules/no-eval/test.js.lint new file mode 100644 index 00000000000..d7ffe5c856c --- /dev/null +++ b/test/rules/no-eval/test.js.lint @@ -0,0 +1,10 @@ +var testVariable = "eval"; + +function a() { + function b() { + function c() { + eval("console.log('hi');"); + ~~~~ [forbidden eval] + } + } +} diff --git a/test/rules/no-eval/tslint.json b/test/rules/no-eval/tslint.json index 1f0ba96f559..9c5f3af5fef 100644 --- a/test/rules/no-eval/tslint.json +++ b/test/rules/no-eval/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-eval": true + }, + "jsRules": { + "no-eval": true } } diff --git a/test/rules/no-for-in-array/test.js.lint b/test/rules/no-for-in-array/test.js.lint new file mode 100644 index 00000000000..87e5530518d --- /dev/null +++ b/test/rules/no-for-in-array/test.js.lint @@ -0,0 +1,41 @@ +const array = [1, 2, 3, 4]; +const strArray = ['a', 'b', 'c']; +const objArray = [{a: 1}, {a: 2, b: 10}, {a: 3}]; +const o = {}; +const numArray = { + 1: "a", + 2: "b" +}; +const d = new Date(); +const str = "abc"; +const map = new Map([['a', 1], ['b', 2]]); +const set = new Set([1, 2, 3]); + +class C { + a; + f() {} + g() {} +} +c = new C(); + +// valid cases +for (var k in o); +for (var k in d); +for (var k in map); +for (var k in numArray); +for (var k in c); +for (var k in refType); + +// invalid cases +for (var k in array); +~~~~~~~~~~~~~~~~~~~~~ [0] +for (var k in str); +~~~~~~~~~~~~~~~~~~~ [0] +for (var k in objArray); +~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +// Ideally these would also be forbidden: +for (var k in map); +for (var k in set); + +[0]: for-in loops over arrays are forbidden. Use for-of or array.forEach instead. diff --git a/test/rules/no-for-in-array/tslint.json b/test/rules/no-for-in-array/tslint.json index 583d5858c71..655b4b171e0 100644 --- a/test/rules/no-for-in-array/tslint.json +++ b/test/rules/no-for-in-array/tslint.json @@ -2,6 +2,9 @@ "rules": { "no-for-in-array": true }, + "jsRules": { + "no-for-in-array": true + }, "linterOptions": { "typeCheck": true } diff --git a/test/rules/no-invalid-this/enabled/test.js.lint b/test/rules/no-invalid-this/enabled/test.js.lint new file mode 100644 index 00000000000..ea9d9abc13a --- /dev/null +++ b/test/rules/no-invalid-this/enabled/test.js.lint @@ -0,0 +1,60 @@ +function foo(x) { + console.log(this.x); + ~~~~ [the "this" keyword is disallowed outside of a class body] + + this.evilMethod(); + ~~~~ [the "this" keyword is disallowed outside of a class body] +} + +class AClass { + x; + + constructor() { + this.x = 2; + } + + aMethod() { + this.x = 5; + } + + bMethod() { + [3,4].forEach(function(nr){ + console.log(this.x === nr); + ~~~~ [the "this" keyword is disallowed in function bodies inside class methods, use arrow functions instead] + }); + } + + Method() { + [3,4].forEach((nr) => { + console.log(this.x === nr); + }); + } + + cMethod = () => { + [3,4].forEach(function(nr){ + console.log(this.x === nr); + ~~~~ [the "this" keyword is disallowed in function bodies inside class methods, use arrow functions instead] + }); + } + + dMethod() { + [3,4].forEach(badFunction); + function badFunction(nr) { + console.log(this.x === nr); + ~~~~ [the "this" keyword is disallowed in function bodies inside class methods, use arrow functions instead] + } + } + + eMethod() { + [3,4].forEach(badFunction); + let badFunction = nr => console.log(this.x === nr); + } +} + +const AClassExpression = class { + x; + + aMethod() { + this.x = 5; + } +} diff --git a/test/rules/no-invalid-this/enabled/tslint.json b/test/rules/no-invalid-this/enabled/tslint.json index 55c5eee2986..9ecceb14846 100644 --- a/test/rules/no-invalid-this/enabled/tslint.json +++ b/test/rules/no-invalid-this/enabled/tslint.json @@ -4,5 +4,11 @@ true, "check-function-in-method" ] + }, + "jsRules": { + "no-invalid-this": [ + true, + "check-function-in-method" + ] } } diff --git a/test/rules/no-null-keyword/test.js.lint b/test/rules/no-null-keyword/test.js.lint new file mode 100644 index 00000000000..1cab307c4a1 --- /dev/null +++ b/test/rules/no-null-keyword/test.js.lint @@ -0,0 +1,4 @@ +var x = null; // error + ~~~~ [Use 'undefined' instead of 'null'] +console.log(null, x); // error + ~~~~ [Use 'undefined' instead of 'null'] diff --git a/test/rules/no-null-keyword/tslint.json b/test/rules/no-null-keyword/tslint.json index 1e4bf06a307..5e51d15a6d3 100644 --- a/test/rules/no-null-keyword/tslint.json +++ b/test/rules/no-null-keyword/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-null-keyword": true + }, + "jsRules": { + "no-null-keyword": true } } diff --git a/test/rules/no-reference/test.js.lint b/test/rules/no-reference/test.js.lint new file mode 100644 index 00000000000..2740b845ba2 --- /dev/null +++ b/test/rules/no-reference/test.js.lint @@ -0,0 +1,2 @@ +/// +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [ is not allowed, use imports] diff --git a/test/rules/no-reference/tslint.json b/test/rules/no-reference/tslint.json index 6a925a49578..392c262938a 100644 --- a/test/rules/no-reference/tslint.json +++ b/test/rules/no-reference/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-reference": true + }, + "jsRules": { + "no-reference": true } } diff --git a/test/rules/no-require-imports/test.js.lint b/test/rules/no-require-imports/test.js.lint new file mode 100644 index 00000000000..b54741ed2b8 --- /dev/null +++ b/test/rules/no-require-imports/test.js.lint @@ -0,0 +1,24 @@ +var lib = require('lib'); // failure + ~~~~~~~~~~~~~~ [no-require] + +let lib2 = require('lib2'); // failure + ~~~~~~~~~~~~~~~ [no-require] + +import {l} from 'lib'; + +var lib3 = load('not_an_import'); + +var lib4 = lib2.subImport; + +var lib5 = require('lib5'), // failure + ~~~~~~~~~~~~~~~ [no-require] + lib6 = require('lib6'), // failure + ~~~~~~~~~~~~~~~ [no-require] + lib7 = 700; + +import lib8 = require('lib8'); // failure + ~~~~~~~~~~~~~~~ [no-require] + +import lib9 = lib2.anotherSubImport; + +[no-require]: require() style import is forbidden diff --git a/test/rules/no-require-imports/tslint.json b/test/rules/no-require-imports/tslint.json index 39bc26f8312..86ac4a05d9a 100644 --- a/test/rules/no-require-imports/tslint.json +++ b/test/rules/no-require-imports/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-require-imports": true + }, + "jsRules": { + "no-require-imports": true } } diff --git a/test/rules/no-shadowed-variable/test.js.lint b/test/rules/no-shadowed-variable/test.js.lint new file mode 100644 index 00000000000..ea5dbdd7673 --- /dev/null +++ b/test/rules/no-shadowed-variable/test.js.lint @@ -0,0 +1,156 @@ +function letTesting() { + var a = 1; + let b = 1; + + if (true) { + let a = 2; // failure + ~ [Shadowed variable: 'a'] + let b = 2; // failure + ~ [Shadowed variable: 'b'] + let c = 2; + var e = 2; + } else { + let b = 3; // failure + ~ [Shadowed variable: 'b'] + let c = 3; + let e = 3; // failure + ~ [Shadowed variable: 'e'] + let f = 3; + } + + var f = 4; +} + +let a = 1; +if (true) { + let a = 2; // failure + ~ [Shadowed variable: 'a'] +} + +var g = 1; +for (var index in [0, 1, 2]) { + var g = 2; // failure + ~ [Shadowed variable: 'g'] +} + +function constTesting() { + var h = 1; + const i = 1; + + if (true) { + const h = 2; // failure + ~ [Shadowed variable: 'h'] + const i = 2; // failure + ~ [Shadowed variable: 'i'] + } +} + +function testArguments(x: number, y: number): void { + var x = 1; // failure + ~ [Shadowed variable: 'x'] + let y = 2; // tsc error + ~ [Shadowed variable: 'y'] +} + +let j = 1; +for (var index in [0, 1, 2]) { // failure + ~~~~~ [Shadowed variable: 'index'] + let j = 2; // failure + ~ [Shadowed variable: 'j'] +} + +function testTryStatement() { + try { + let foo = 1; + throw new Error(); + } catch (e) { + let foo = 2; + var bar = 2; + } finally { + let foo = 3; + let bar = 3; // failure + ~~~ [Shadowed variable: 'bar'] + } +} + +function testWhileStatement() { + let foo = 1; + + while (true) { + let foo = 2; // failure + ~~~ [Shadowed variable: 'foo'] + } +} + +function testDoStatement() { + let foo = 1; + + do { + let foo = 2; // failure + ~~~ [Shadowed variable: 'foo'] + } while (true); +} + +function testDestructuring(x: number) { + var {y, z} = {y: 2, z: 3}; + + function myFunc() { + return [1]; + } + + function innerFunc() { + var [foo] = myFunc(); + var [x] = myFunc(); // failure + ~ [Shadowed variable: 'x'] + let [y] = myFunc(); // failure + ~ [Shadowed variable: 'y'] + const [z] = myFunc(); // failure + ~ [Shadowed variable: 'z'] + } + + function anotherInnerFunc() { + var [{x}] = [{x: 1}]; // failure + ~ [Shadowed variable: 'x'] + let [[y]] = [[2]]; // failure + ~ [Shadowed variable: 'y'] + var [foo, ...bar] = [1, 2, 3, 4]; + var [...z] = [1, 2, 3, 4]; // failure + ~ [Shadowed variable: 'z'] + } +} + +function falsePositive1(bar: (okay1: any) => void) { + let okay1 = 1; +} + +function falsePositive2(okay2: any, done: (okay2: any) => void) { } + +interface FalsePositive3 { + diffuse: (pos: number) => number; + specular: (pos: number) => number; + pos: number; +} + +interface FalsePositive4 { + (parameters: T, runSynchonous: boolean): TResult; + (parameters: T, callback: (error: Error, result: TResult) => void): void; +} + +{ + const simpleBlockVar = 3 +} + +function testSimpleBlockVar() { + const simpleBlockVar = 4 +} + +const external = 1; +interface ExternalIndexSignature1 { + [external: string]: any; +} + +function creatorFunction(constructor, filter) { + const myVariable = 1; + const myParameter = 1; + console.log(myVariable); +} diff --git a/test/rules/no-shadowed-variable/tslint.json b/test/rules/no-shadowed-variable/tslint.json index f9d0b34237a..b286e654896 100644 --- a/test/rules/no-shadowed-variable/tslint.json +++ b/test/rules/no-shadowed-variable/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-shadowed-variable": true + }, + "jsRules": { + "no-shadowed-variable": true } } diff --git a/test/rules/no-string-literal/tslint.json b/test/rules/no-string-literal/tslint.json index ade4197c3d3..ab3e0640502 100644 --- a/test/rules/no-string-literal/tslint.json +++ b/test/rules/no-string-literal/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-string-literal": true + }, + "jsRules": { + "no-string-literal": true } } diff --git a/test/rules/no-switch-case-fall-through/test.js.lint b/test/rules/no-switch-case-fall-through/test.js.lint new file mode 100644 index 00000000000..1dc40e8627b --- /dev/null +++ b/test/rules/no-switch-case-fall-through/test.js.lint @@ -0,0 +1,87 @@ +switch (foo) { + case 1: + bar(); + case 2: + ~~~~ [expected a 'break' before 'case'] + bar(); + bar(); + case 3: + ~~~~ [expected a 'break' before 'case'] + case 4: + default: + ~~~~~~~ [expected a 'break' before 'default'] + break; +} + + +switch (foo) { + case 1: + bar(); + case 2: + ~~~~ [expected a 'break' before 'case'] + bar(); +} + + +switch (foo) { + case 1: + case 2: + default: + ~~~~~~~ [expected a 'break' before 'default'] + bar(); +} + +switch (foo) { + case 1: + switch (bar) { + case "": + default: + ~~~~~~~ [expected a 'break' before 'default'] + break; + } + case 2: + ~~~~ [expected a 'break' before 'case'] +} + +switch (foo) { + case 1: + case 2: + + case 3: + + case 4: + break; + default: + bar(); +} + + +switch (foo) { + case 1: + return; // handle return the same as break + case 2: + case 3: + throw "error"; +} + +switch (foo) { + case 1: + bar(); + /* falls through */ + case 2: + bar(); + /* Testing */ + /* falls through */ + case 3: + break; +} + +// valid +switch (foo) { + case 1: + break; + case 2: + case 3: + break; + default: +} diff --git a/test/rules/no-switch-case-fall-through/tslint.json b/test/rules/no-switch-case-fall-through/tslint.json index 31c7fba4e6e..25ad95f50a3 100644 --- a/test/rules/no-switch-case-fall-through/tslint.json +++ b/test/rules/no-switch-case-fall-through/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-switch-case-fall-through": true + }, + "jsRules": { + "no-switch-case-fall-through": true } } diff --git a/test/rules/no-trailing-whitespace/test.js.lint b/test/rules/no-trailing-whitespace/test.js.lint new file mode 100644 index 00000000000..6ef8b5e18b4 --- /dev/null +++ b/test/rules/no-trailing-whitespace/test.js.lint @@ -0,0 +1,16 @@ +class Clazz { + public funcxion() { + ~~~~ [0] + console.log("test") ; + ~~~~ [0] + } + +~~~~ [0] + +~~~~ [0] + private foobar() { + } +} + ~~~~ [0] + +[0]: trailing whitespace diff --git a/test/rules/no-trailing-whitespace/tslint.json b/test/rules/no-trailing-whitespace/tslint.json index f81bfe73957..b53f885c954 100644 --- a/test/rules/no-trailing-whitespace/tslint.json +++ b/test/rules/no-trailing-whitespace/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-trailing-whitespace": true + }, + "jsRules": { + "no-trailing-whitespace": true } } diff --git a/test/rules/no-unreachable/test.js.lint b/test/rules/no-unreachable/test.js.lint new file mode 100644 index 00000000000..8d6e59e64b4 --- /dev/null +++ b/test/rules/no-unreachable/test.js.lint @@ -0,0 +1,104 @@ +// invalid code + +function f1() { + var x = 3; + return; + var y; + ~~~~~~ [unreachable code] + var z; +} + +var f2 = () => { + if (x === 3) { + throw new Error("error"); + "123"; + ~~~~~~ [unreachable code] + } else { + return y; + } + + return 123; +}; + +lab: +for (var i = 0; i < 10; ++i) { + if (i === 3) { + break; + console.log("hi"); + ~~~~~~~~~~~~~~~~~~ [unreachable code] + } else { + continue lab; + i = 4; + ~~~~~~ [unreachable code] + } +} + +// valid code +var f2 = () => { + if (x === 3) { + throw new Error("error"); + } else { + return y; + } + + return 123; +}; + +switch (x) { + case 1: + i = 2; + break; + case 2: + i = 3; + break; + default: + i = 4; + break; +} + +function f4() { + var x = 3; + if (x === 4) return; + else x = 4; + var y = 7; +} + +function f5() { + var x = 3; + if (x === 4) x = 5; + else return; + var y = 7; +} + +function f6() { + hoisted(); + return 0; + + function hoisted() { + return 0; + } +} + +// more invalid code + +function f7() { + hoisted(); + return 0; + + function hoisted() { + return 0; + } + + var y = 7; + ~~~~~~~~~~ [unreachable code] +} + +// more valid code + +function f8() { + try { + return 0; + } catch (e) { + console.log("here"); + } +} diff --git a/test/rules/no-unreachable/tslint.json b/test/rules/no-unreachable/tslint.json index 8219288f905..80eb8a090fb 100644 --- a/test/rules/no-unreachable/tslint.json +++ b/test/rules/no-unreachable/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-unreachable": true + }, + "jsRules": { + "no-unreachable": true } } diff --git a/test/rules/no-unsafe-finally/test.js.lint b/test/rules/no-unsafe-finally/test.js.lint new file mode 100644 index 00000000000..394d3729689 --- /dev/null +++ b/test/rules/no-unsafe-finally/test.js.lint @@ -0,0 +1,361 @@ +function() { + try { + } finally { + return; + ~~~~~~~ [no-return-in-finally] + } +} + +function() { + try { + } catch { + } finally { + return 1; + ~~~~~~~~~ [no-return-in-finally] + } +} + +function() { + try { + } catch { + } finally { + { + return 1; + ~~~~~~~~~ [no-return-in-finally] + } + } +} + +function() { + try { + } catch { + } finally { + for (let i = 0; i < 5; ++i) { + if (i % 2 === 0) { + return 1; + ~~~~~~~~~ [no-return-in-finally] + } + } + } +} + +function() { + try { + } catch { + } finally { + let i = 1; + while (i < 5) { + if (i % 2 === 0) { + return i; + ~~~~~~~~~ [no-return-in-finally] + } + + ++i; + } + } +} + +function() { + try { + } catch { + } finally { + let i = 1; + do { + if (i % 2 === 0) { + return i; + ~~~~~~~~~ [no-return-in-finally] + } + + ++i; + } while (i < 5); + } +} + +function() { + try { + if (foo()) { + try { + bar(); + } catch { + } finally { + return 2; + ~~~~~~~~~ [no-return-in-finally] + } + } + } catch { + } finally { + for (const i of [1, 2, 3, 4, 5]) { + if (i % 2 === 0) { + return 1; + ~~~~~~~~~ [no-return-in-finally] + } + } + } +} + +function foo() { + try { + try { + } finally { + return 1; + ~~~~~~~~~ [no-return-in-finally] + } + } catch { + } +} + +function foo() { + try { + } finally { + throw "error"; + ~~~~~~~~~~~~~~ [no-throw-in-finally] + } +} + +function foo() { + for (const i of [1, 2, 3, 4, 5]) { + try { + } finally { + continue; + ~~~~~~~~~ [no-continue-in-finally] + } + } +} + +function foo() { + for (const i of [1, 2, 3, 4, 5]) { + try { + } finally { + break; + ~~~~~~ [no-break-in-finally] + } + } +} + +function foo() { + for (let i = 0; i < 5; ++i) { + try { + } finally { + continue; + ~~~~~~~~~ [no-continue-in-finally] + } + } +} + +function foo() { + do { + try { + } finally { + continue; + ~~~~~~~~~ [no-continue-in-finally] + } + } while (i > 0); +} + +function foo() { + while (i > 0) { + try { + } finally { + continue; + ~~~~~~~~~ [no-continue-in-finally] + } + } +} + +function foo() { + do { + try { + } finally { + break; + ~~~~~~ [no-break-in-finally] + } + } while (i > 0); +} + +function foo() { + while (i > 0) { + try { + } finally { + break; + ~~~~~~ [no-break-in-finally] + } + } +} + +function foo() { + switch (a) { + case 1: + try { + return; + } finally { + break; + ~~~~~~ [no-break-in-finally] + } + break; + default: + try { + } finally { + break; + ~~~~~~ [no-break-in-finally] + } + break; + } +} + +function foo() { + label: + try { + } finally { + break label; + ~~~~~~~~~~~~ [no-break-in-finally] + } +} + +function foo() { + label: + for (let i = 0; i < 4; ++i) { + try { + } finally { + break label; + ~~~~~~~~~~~~ [no-break-in-finally] + } + } +} + +function foo() { + outer: + for (let i = 0; i < 4; ++i) { + try { + } finally { + inner: + for (let j = 0; j < 2; ++j) { + break outer; + ~~~~~~~~~~~~ [no-break-in-finally] + } + } + } +} + +function foo() { + label: + for (let i = 0; i < 4; ++i) { + try { + } finally { + continue label; + ~~~~~~~~~~~~~~~ [no-continue-in-finally] + } + } +} + +function foo() { + outer: + for (let i = 0; i < 4; ++i) { + try { + } finally { + inner: + for (let j = 0; j < 2; ++j) { + continue outer; + ~~~~~~~~~~~~~~~ [no-continue-in-finally] + } + } + } +} + +// valid +function() { + try { + } finally { + (function() { + return 1; + })(); + } +} + +// valid +function() { + try { + foo(); + } finally { + class C { + bar() { + return 1; + } + } + } + + return 1; +} + +// valid +function() { + try { + } catch { + } finally { + for (let i = 0; i < 5; ++i) { + if (i % 2 === 0) { + continue; + } + } + } +} + +// valid +function() { + try { + } catch { + } finally { + for (let i = 0; i < 5; ++i) { + if (i % 2 === 0) { + break; + } + } + } +} + +// valid +function() { + try { + } catch { + } finally { + switch (a) { + case 1: + break; + default: + break; + } + } +} + +//valid +function() { + try { + } finally { + label: + break label; + } +} + +//valid +function() { + try { + } finally { + outer: + for (let i = 0; i < 2; ++i) { + if (i % 2 === 0) { + continue outer; + } + + inner: + for (let j = 0; j < 2; ++j) { + if (j % 2 === 0) { + continue outer; + } + } + } + } +} + +[no-return-in-finally]: return statements in finally blocks are forbidden. +[no-throw-in-finally]: throw statements in finally blocks are forbidden. +[no-break-in-finally]: break statements in finally blocks are forbidden. +[no-continue-in-finally]: continue statements in finally blocks are forbidden. diff --git a/test/rules/no-unsafe-finally/tslint.json b/test/rules/no-unsafe-finally/tslint.json index 0b957d11b67..93e37a38d96 100644 --- a/test/rules/no-unsafe-finally/tslint.json +++ b/test/rules/no-unsafe-finally/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-unsafe-finally": true + }, + "jsRules": { + "no-unsafe-finally": true } } \ No newline at end of file diff --git a/test/rules/no-unused-expression/test.js.lint b/test/rules/no-unused-expression/test.js.lint new file mode 100644 index 00000000000..80e8e7bd054 --- /dev/null +++ b/test/rules/no-unused-expression/test.js.lint @@ -0,0 +1,112 @@ +"use strict"; +'use asm'; +"ngInject"; +''; + +function fun1() { + "use strict"; + 'someOtherDirective'; + return 0; +} + +(function() { "directive"; +'foo' +'directive2' +console.log('foo'); +'notdirective'; +~~~~~~~~~~~~~~~ [0] +})(); + +const a = () => { +'use strict'; "use cool"; "use lint"; var a = 1; "notdirective"; } + ~~~~~~~~~~~~~~~ [0] + +function fun2(a) { + return 0; +} + +function fun3(a, b) { + return 0; +} + +class Foo { + constructor() { + "ngInject"; + var a = 1; + 'notdirective'; + ~~~~~~~~~~~~~~~ [0] + } + + bar() { + 'use strict'; + } + + get baz() { + 'use asm'; + } + + set baz(newValue) { + "use asm"; + } +} + +// valid code: + +var i; +var j = 3; +i = 1 + 2; +j = fun1(); +fun1(); +fun2(2); +fun3(2, fun1()); +i++; +i += 2; +--i; +i <<= 2; +i = fun1() + fun1(); +j = (j === 0 ? 5 : 6); +(j === 0 ? fun1() : fun2(j)); +(a => 5)(4); +var obj = {}; +delete obj.key; +function* g() { + for (let i = 0; i < 100; i++) { + yield i; + } +} + +async function f(foo) { + await foo; + return 0; +} + +new Foo(); + +// invalid code: + +5; +~~ [0] +i; +~~ [0] +3 + 5; +~~~~~~ [0] +fun1() + fun1(); +~~~~~~~~~~~~~~~~ [0] +fun2(i) + fun3(4,7); +~~~~~~~~~~~~~~~~~~~~ [0] +fun1() + 4; +~~~~~~~~~~~ [0] +4 + fun2(j); +~~~~~~~~~~~~ [0] +(j === 0 ? fun1() : 5); +~~~~~~~~~~~~~~~~~~~~~~~ [0] +(j === 0 ? i : fun2(j)); +~~~~~~~~~~~~~~~~~~~~~~~~ [0] +a => fun2(a); +~~~~~~~~~~~~~ [0] +() => {return fun1();}; +~~~~~~~~~~~~~~~~~~~~~~~ [0] +"use strct"; +~~~~~~~~~~~~ [0] + +[0]: expected an assignment or function call diff --git a/test/rules/no-unused-expression/tslint.json b/test/rules/no-unused-expression/tslint.json index 042bc2f9ac4..0a5c968e513 100644 --- a/test/rules/no-unused-expression/tslint.json +++ b/test/rules/no-unused-expression/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-unused-expression": true + }, + "jsRules": { + "no-unused-expression": true } } diff --git a/test/rules/no-unused-new/test.js.lint b/test/rules/no-unused-new/test.js.lint new file mode 100644 index 00000000000..b3b1d987b1a --- /dev/null +++ b/test/rules/no-unused-new/test.js.lint @@ -0,0 +1,99 @@ +"use strict"; +'use asm'; +"ngInject"; +''; + +function fun1() { + "use strict"; + 'someOtherDirective'; + return 0; +} + +(function() { "directive"; +'foo' +'directive2' +console.log('foo'); +'notdirective'; +})(); + +const a = () => { +'use strict'; "use cool"; "use lint"; var a = 1; "notdirective"; } + +function fun2(a) { + return 0; +} + +function fun3(a, b) { + return 0; +} + +class Foo { + constructor() { + "ngInject"; + var a = 1; + 'notdirective'; + } + + bar() { + 'use strict'; + } + + get baz() { + 'use asm'; + } + + set baz(newValue) { + "use asm"; + } +} + +// valid code: + +var i; +var j = 3; +i = 1 + 2; +j = fun1(); +fun1(); +fun2(2); +fun3(2, fun1()); +i++; +i += 2; +--i; +i <<= 2; +i = fun1() + fun1(); +j = (j === 0 ? 5 : 6); +(j === 0 ? fun1() : fun2(j)); +(a => 5)(4); +var obj = {}; +delete obj.key; +function* g() { + for (let i = 0; i < 100; i++) { + yield i; + } +} + +async function f(foo) { + await foo; + return 0; +} + +5; +3 + 5; +fun1() + fun1(); +(j === 0 ? fun1() : 5); +() => {return fun1();}; + +// invalid code: + +new Foo(); +~~~~~~~~~~ [0] +5 + new Foo(); +~~~~~~~~~~~~~~ [0] +new Foo() + new Foo(); +~~~~~~~~~~~~~~~~~~~~~~ [0] +fun1() + new Foo(); +~~~~~~~~~~~~~~~~~~~ [0] +(j === 0 ? new Foo() : 5); +~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +[0]: do not use 'new' for side effects diff --git a/test/rules/no-unused-new/tslint.json b/test/rules/no-unused-new/tslint.json index 478e4e1736f..38f26ae9ebf 100644 --- a/test/rules/no-unused-new/tslint.json +++ b/test/rules/no-unused-new/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-unused-new": true + }, + "jsRules": { + "no-unused-new": true } } diff --git a/test/rules/no-use-before-declare/test.js.lint b/test/rules/no-use-before-declare/test.js.lint new file mode 100644 index 00000000000..8c51be3ba61 --- /dev/null +++ b/test/rules/no-use-before-declare/test.js.lint @@ -0,0 +1,74 @@ +$.x = 3; +~ [variable '$' used before declaration] +import $ from "$"; +var vara = varb, varb; + ~~~~ [variable 'varb' used before declaration] + +class Test { + constructor() { + this.a = 3; + } + + a; +} + +var i = j; + ~ [variable 'j' used before declaration] + +class ClassA { + prop; + constructor(object) { + this.prop = object.prop; + } +} + +class ClassB { + prop; +} + +var j; + +if (something) { + var defined = 1; +} else { + var defined; +} + +function testUndeclaredImports() { + console.log(foo1); + ~~~~ [variable 'foo1' used before declaration] + console.log(foo2); + ~~~~ [variable 'foo2' used before declaration] + console.log(foo3); + ~~~~ [variable 'foo3' used before declaration] + map([], (x) => x); + ~~~ [variable 'map' used before declaration] +} + +import { default as foo1 } from "lib"; +import foo2 from "lib"; +import _, { map, foldl } from "underscore"; +import * as foo3 from "lib"; +import "lib"; + +export default function () { + // +}; + +export { + undeclaredA, + ~~~~~~~~~~~ [variable 'undeclaredA' used before declaration] + undeclaredB, // tsc error + undeclaredC, // tsc error + testUndeclaredImports +}; + +var undeclaredA = 42; +let { undeclaredB } = { undeclaredB: 43 }; +const [ undeclaredC, [undeclaredD] ] = [ 1, [2] ]; + +// shouldn't crash tslint +function a() { + var b = ({c: dog}) => { dog++; }; + b({ c: 5 }); +} diff --git a/test/rules/no-use-before-declare/tslint.json b/test/rules/no-use-before-declare/tslint.json index 744ae40f6ff..113653e7cd5 100644 --- a/test/rules/no-use-before-declare/tslint.json +++ b/test/rules/no-use-before-declare/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-use-before-declare": true + }, + "jsRules": { + "no-use-before-declare": true } } diff --git a/test/rules/no-var-keyword/test.js.lint b/test/rules/no-var-keyword/test.js.lint new file mode 100644 index 00000000000..cff272ae817 --- /dev/null +++ b/test/rules/no-var-keyword/test.js.lint @@ -0,0 +1,49 @@ +var foo; +~~~ [Forbidden 'var' keyword, use 'let' or 'const' instead] + +function tmp(t) { + var x = 3; + ~~~ [Forbidden 'var' keyword, use 'let' or 'const' instead] +} + +var i, +~~~ [Forbidden 'var' keyword, use 'let' or 'const' instead] + j; + +var [a, b] = [1, 2]; +~~~ [Forbidden 'var' keyword, use 'let' or 'const' instead] + +for (var n; false;); + ~~~ [Forbidden 'var' keyword, use 'let' or 'const' instead] +for (var n1 in foo); + ~~~ [Forbidden 'var' keyword, use 'let' or 'const' instead] +for (var n2 of foo); + ~~~ [Forbidden 'var' keyword, use 'let' or 'const' instead] + +export var exportVar0 = 0; + ~~~ [Forbidden 'var' keyword, use 'let' or 'const' instead] +export var exportVar1 = 1; + ~~~ [Forbidden 'var' keyword, use 'let' or 'const' instead] +export var exportVar2 = 2, + ~~~ [Forbidden 'var' keyword, use 'let' or 'const' instead] + exportVar21 = 21; +export /* var tst */ var exportVar3 = 3; + ~~~ [Forbidden 'var' keyword, use 'let' or 'const' instead] + +let bar; +const qux; + +let k, + l; + +let [x, y] = [1, 2]; + +for (n; false;); +for (let n; false;); +for (let name in foo); +for (let name of foo); +for (const name in foo); +for (const name of foo); + +export let exportLet = 1; +export const exportConst = 1; diff --git a/test/rules/no-var-keyword/tslint.json b/test/rules/no-var-keyword/tslint.json index 1de4119c014..de411ff36f9 100644 --- a/test/rules/no-var-keyword/tslint.json +++ b/test/rules/no-var-keyword/tslint.json @@ -1,5 +1,8 @@ { "rules": { "no-var-keyword": true + }, + "jsRules": { + "no-var-keyword": true } } diff --git a/test/rules/object-literal-key-quotes/always/test.js.lint b/test/rules/object-literal-key-quotes/always/test.js.lint new file mode 100644 index 00000000000..1f245022bd5 --- /dev/null +++ b/test/rules/object-literal-key-quotes/always/test.js.lint @@ -0,0 +1,23 @@ +const o = { + 'hello': 123, + goodbye: 234, // failure + ~~~~~~~ [Unquoted property 'goodbye' found.] + "quote": 345, + "needs quote": 789, + "hyphens-need-quotes": null, + [computed]: 456, + 123: "hello", // failure + ~~~ [Unquoted property '123' found.] + 1e4: "something", // failure + ~~~ [Unquoted property '1e4' found.] + .123: "float", // failure + ~~~~ [Unquoted property '.123' found.] + '123': 'numbers do not need quotes', + '010': 'but this one does.', + '.123': 'as does this one', + fn() { return }, + true: 0, // failure + ~~~~ [Unquoted property 'true' found.] + "0x0": 0, + "true": 0, +}; diff --git a/test/rules/object-literal-key-quotes/always/tslint.json b/test/rules/object-literal-key-quotes/always/tslint.json index a7927997726..3d2d57e481d 100644 --- a/test/rules/object-literal-key-quotes/always/tslint.json +++ b/test/rules/object-literal-key-quotes/always/tslint.json @@ -1,5 +1,8 @@ { "rules": { "object-literal-key-quotes": [true, "always"] + }, + "jsRules": { + "object-literal-key-quotes": [true, "always"] } } diff --git a/test/rules/object-literal-key-quotes/as-needed/test.js.lint b/test/rules/object-literal-key-quotes/as-needed/test.js.lint new file mode 100644 index 00000000000..e6dc627b5d0 --- /dev/null +++ b/test/rules/object-literal-key-quotes/as-needed/test.js.lint @@ -0,0 +1,22 @@ +const o = { + 'hello': 123, // failure + ~~~~~~~ [Unnecessarily quoted property 'hello' found.] + goodbye: 234, + "quote": 345, // failure + ~~~~~~~ [Unnecessarily quoted property 'quote' found.] + "needs quote": 789, + "hyphens-need-quotes": null, + [computed]: 456, + 123: "hello", + 1e4: "something", + .123: "float", + '123': 'numbers do not need quotes', // failure + ~~~~~ [Unnecessarily quoted property '123' found.] + '010': 'but this one does.', + '.123': 'as does this one', + fn() { return }, + true: 0, + "0x0": 0, + "true": 0, // failure + ~~~~~~ [Unnecessarily quoted property 'true' found.] +}; diff --git a/test/rules/object-literal-key-quotes/as-needed/tslint.json b/test/rules/object-literal-key-quotes/as-needed/tslint.json index a366a23efb2..58ce23cc490 100644 --- a/test/rules/object-literal-key-quotes/as-needed/tslint.json +++ b/test/rules/object-literal-key-quotes/as-needed/tslint.json @@ -1,5 +1,8 @@ { "rules": { "object-literal-key-quotes": [true, "as-needed"] + }, + "jsRules": { + "object-literal-key-quotes": [true, "as-needed"] } } diff --git a/test/rules/object-literal-shorthand/test.js.lint b/test/rules/object-literal-shorthand/test.js.lint new file mode 100644 index 00000000000..91966f41e6b --- /dev/null +++ b/test/rules/object-literal-shorthand/test.js.lint @@ -0,0 +1,46 @@ +const bad = { + w: function() {}, + ~~~~~~~~~~~~~~~~ [method] + x: function *() {}, + ~~~~~~~~~~~~~~~~~~ [method] + [y]: function() {}, + ~~~~~~~~~~~~~~~~~~ [method] + z: z + ~~~~ [property] +}; + +const good = { + w() {}, + *x() {}, + [y]() {}, + z +}; + +const arrows = { + x: (y) => y // this is OK. +}; + +const namedFunctions = { + x: function y() {} // named function expressions are also OK. +}; + +const quotes = { + "foo-bar": function() {}, + ~~~~~~~~~~~~~~~~~~~~~~~~ [method] + "foo-bar"() {} +}; + +const extraCases = { + x, + a: 123, + b: "hello", + c: 'c', + ["a" + "nested"]: { + x: x + ~~~~ [property] + } +}; + + +[property]: Expected property shorthand in object literal. +[method]: Expected method shorthand in object literal. \ No newline at end of file diff --git a/test/rules/object-literal-shorthand/tslint.json b/test/rules/object-literal-shorthand/tslint.json index 3dc26ff61a2..0002634ddd3 100644 --- a/test/rules/object-literal-shorthand/tslint.json +++ b/test/rules/object-literal-shorthand/tslint.json @@ -1,5 +1,8 @@ { "rules": { "object-literal-shorthand": true + }, + "jsRules": { + "object-literal-shorthand": true } } diff --git a/test/rules/object-literal-sort-keys/test.js.lint b/test/rules/object-literal-sort-keys/test.js.lint new file mode 100644 index 00000000000..813815e14dd --- /dev/null +++ b/test/rules/object-literal-sort-keys/test.js.lint @@ -0,0 +1,85 @@ +var passA = { + a: 1, + b: 2 +}; + +var failA = { + b: 1, + a: 2 + ~ [The key 'a' is not sorted alphabetically] +}; + +var passB = { + a: 1, + b: 2, + c: 3, + d: 4 +}; + +var failB = { + c: 3, + a: 1, + ~ [The key 'a' is not sorted alphabetically] + b: 2, + d: 4 +}; + +var passC = { + a: 1, + b: { + aa: 1, + bb: 2 + } +}; + +var failC = { + a: 1, + b: { + bb: 2, + aa: 1 + ~~ [The key 'aa' is not sorted alphabetically] + } +}; + +var passD = { + a: 1, + b: { + aa: 1, + bb: 2 + }, + c: 3 +}; + +var failD = { + a: 1, + c: { + aa: 1, + bb: 2 + }, + b: 3 + ~ [The key 'b' is not sorted alphabetically] +}; + +var passE = {}; + +var passF = { + asdf: [1, 2, 3], + sdfa: {} +}; + +var failF = { + sdfa: {}, + asdf: [1, 2, 3] + ~~~~ [The key 'asdf' is not sorted alphabetically] +}; + +var passG = { + asdfn: function () {}, + sdafn: function () {} +}; + +var failG = { + sdafn: function () {}, + asdfn: function () {} + ~~~~~ [The key 'asdfn' is not sorted alphabetically] +}; diff --git a/test/rules/object-literal-sort-keys/tslint.json b/test/rules/object-literal-sort-keys/tslint.json index 280382fe390..66db23de8d1 100644 --- a/test/rules/object-literal-sort-keys/tslint.json +++ b/test/rules/object-literal-sort-keys/tslint.json @@ -1,5 +1,8 @@ { "rules": { "object-literal-sort-keys": true + }, + "jsRules": { + "object-literal-sort-keys": true } } diff --git a/test/rules/one-line/all/test.js.lint b/test/rules/one-line/all/test.js.lint new file mode 100644 index 00000000000..7dc9c65848d --- /dev/null +++ b/test/rules/one-line/all/test.js.lint @@ -0,0 +1,110 @@ +export function Call() +{ +~ [misplaced opening brace] + if (x == 3) + { + ~ [misplaced opening brace] + x = 4; + } + else { + ~~~~ [misplaced 'else'] + x = 5; + } + return "called"; +} + +var object = +{ +~ [misplaced opening brace] + a: 1, + b: 2 +}; + +for(var x= 0; x < 1; ++x) +{ +~ [misplaced opening brace] + ++i; +} + +switch(y) +{ +~ [misplaced opening brace] + case 0: + x--; + break; + default: + x++; + break; +} + +try +{ +~ [misplaced opening brace] + throw new Error("hi"); +} +catch (e) +~~~~~ [misplaced 'catch'] +{ +~ [misplaced opening brace] + throw(e); +} +finally +~~~~~~~ [misplaced 'finally'] +{ +~ [misplaced opening brace] + // do something +} + +try { + foo(); +} +finally +~~~~~~~ [misplaced 'finally'] +{ +~ [misplaced opening brace] + bar(); +} + +try{ + ~ [missing whitespace] + foo(); +} catch(e){ + ~ [missing whitespace] + bar(); +} finally{ + ~ [missing whitespace] + baz(); +} + +while(x < 10){ + ~ [missing whitespace] + x++; +} + +class BarBooBaz +{ +~ [misplaced opening brace] + +} + +class FooBarBaz { +} + +// Valid multiline declarations +export class LongDescriptiveClassName + extends SomeAbstractBaseClass { +} + +function longFunctionNameWithLotsOfParams( + x, + y, + z, + a) { +} + +let geoConfig += { + maximumAge: 3000, + timeout: 5000, + enableHighAccuracy: false +}; diff --git a/test/rules/one-line/all/tslint.json b/test/rules/one-line/all/tslint.json index d8a064cc2e5..720acee53ac 100644 --- a/test/rules/one-line/all/tslint.json +++ b/test/rules/one-line/all/tslint.json @@ -1,5 +1,8 @@ { "rules": { "one-line": [true, "check-open-brace", "check-catch", "check-else", "check-finally", "check-whitespace"] + }, + "jsRules": { + "one-line": [true, "check-open-brace", "check-catch", "check-else", "check-finally", "check-whitespace"] } } diff --git a/test/rules/one-line/none/test.js.lint b/test/rules/one-line/none/test.js.lint new file mode 100644 index 00000000000..73ddb983470 --- /dev/null +++ b/test/rules/one-line/none/test.js.lint @@ -0,0 +1,92 @@ +export function Call() +{ + if (x == 3) + { + x = 4; + } + else { + x = 5; + } + return "called"; +} + +var object = +{ + a: 1, + b: 2 +}; + +for(var x= 0; x < 1; ++x) +{ + ++i; +} + +switch(y) +{ + case 0: + x--; + break; + default: + x++; + break; +} + +try +{ + throw new Error("hi"); +} +catch (e) +{ + throw(e); +} +finally +{ + // do something +} + +try { + foo(); +} +finally +{ + bar(); +} + +try{ + foo(); +} catch(e){ + bar(); +} finally{ + baz(); +} + +while(x < 10){ + x++; +} + +class BarBooBaz +{ + +} + +class FooBarBaz { +} + +// Valid multiline declarations +export class LongDescriptiveClassName + extends SomeAbstractBaseClass { +} + +function longFunctionNameWithLotsOfParams( + x, + y, + z, + a) { +} + +let geoConfig += { + maximumAge: 3000, + timeout: 5000, + enableHighAccuracy: false +}; diff --git a/test/rules/one-line/none/tslint.json b/test/rules/one-line/none/tslint.json index ea05ac32938..806765d9003 100644 --- a/test/rules/one-line/none/tslint.json +++ b/test/rules/one-line/none/tslint.json @@ -1,5 +1,8 @@ { "rules": { "one-line": true + }, + "jsRules": { + "one-line": true } } diff --git a/test/rules/one-variable-per-declaration/default/test.js.lint b/test/rules/one-variable-per-declaration/default/test.js.lint new file mode 100644 index 00000000000..155ff047a7c --- /dev/null +++ b/test/rules/one-variable-per-declaration/default/test.js.lint @@ -0,0 +1,40 @@ +// valid cases +var foo1; +var foo2; +var foo3 = 1; + +let foo4; +let foo5; +let foo6 = 1; + +const foo7 = 1; +const foo8 = 1; + +for (var i = 0; i > 1; i++) {} +for (let i = 0; i > 1; i++) {} +for (const i = 0; i > 1;) {} + +// invalid cases +var foo9, foo10; +~~~~~~~~~~~~~~~~ [0] + +var foo13 = 1, foo14 = 1; +~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +let foo15, foo16; +~~~~~~~~~~~~~~~~~ [0] +let foo19 = 1, foo20 = 1; +~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +const foo23 = 1, foo24 = 1; +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +for (var i = 0, j = 0; i > 1; i++) {} + ~~~~~~~~~~~~~~~~ [0] +for (let i = 0, j = 0; i > 1; i++) {} + ~~~~~~~~~~~~~~~~ [0] +for (const i = 0, j = 0; i > 1;) {} + ~~~~~~~~~~~~~~~~~~ [0] + +[0]: Multiple variable declarations in the same statement are forbidden + diff --git a/test/rules/one-variable-per-declaration/default/tslint.json b/test/rules/one-variable-per-declaration/default/tslint.json index 3d64c8fa578..20d18dce276 100644 --- a/test/rules/one-variable-per-declaration/default/tslint.json +++ b/test/rules/one-variable-per-declaration/default/tslint.json @@ -1,5 +1,8 @@ { "rules": { "one-variable-per-declaration": true + }, + "jsRules": { + "one-variable-per-declaration": true } } diff --git a/test/rules/one-variable-per-declaration/ignore-for-loop/test.js.lint b/test/rules/one-variable-per-declaration/ignore-for-loop/test.js.lint new file mode 100644 index 00000000000..746d2b87f59 --- /dev/null +++ b/test/rules/one-variable-per-declaration/ignore-for-loop/test.js.lint @@ -0,0 +1,25 @@ +// valid cases +for (var i = 0; i > 1; i++) {} +for (let i = 0; i > 1; i++) {} +for (const i = 0; i > 1;) {} +for (var i = 0, j = 0; i > 1; i++) {} +for (let i = 0, j = 0; i > 1; i++) {} +for (const i = 0, j = 0; i > 1;) {} + +// invalid cases +var foo1, foo2; +~~~~~~~~~~~~~~~ [0] + +var foo5 = 1, foo6 = 1; +~~~~~~~~~~~~~~~~~~~~~~~ [0] + +let foo7, foo8; +~~~~~~~~~~~~~~~ [0] +let foo11 = 1, foo12 = 1; +~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +const foo15 = 1, foo16 = 1; +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +[0]: Multiple variable declarations in the same statement are forbidden + diff --git a/test/rules/one-variable-per-declaration/ignore-for-loop/tslint.json b/test/rules/one-variable-per-declaration/ignore-for-loop/tslint.json index 657afeded5d..6e2204090d1 100644 --- a/test/rules/one-variable-per-declaration/ignore-for-loop/tslint.json +++ b/test/rules/one-variable-per-declaration/ignore-for-loop/tslint.json @@ -3,5 +3,10 @@ "one-variable-per-declaration": [true, "ignore-for-loop" ] + }, + "jsRules": { + "one-variable-per-declaration": [true, + "ignore-for-loop" + ] } } diff --git a/test/rules/only-arrow-functions/allow-declarations/test.js.lint b/test/rules/only-arrow-functions/allow-declarations/test.js.lint new file mode 100644 index 00000000000..d976870301b --- /dev/null +++ b/test/rules/only-arrow-functions/allow-declarations/test.js.lint @@ -0,0 +1,16 @@ +function foo(a) { + return; +} + +let a = () => {}; +let b = function () {}; + ~~~~~~~~ [0] + +function c() {} + +((func) => func())(function e() {}); + ~~~~~~~~ [0] + +((func) => func())(() => {}); + +[0]: non-arrow functions are forbidden diff --git a/test/rules/only-arrow-functions/allow-declarations/tslint.json b/test/rules/only-arrow-functions/allow-declarations/tslint.json index 89262ad4c12..57892e2c824 100644 --- a/test/rules/only-arrow-functions/allow-declarations/tslint.json +++ b/test/rules/only-arrow-functions/allow-declarations/tslint.json @@ -1,5 +1,8 @@ { "rules": { "only-arrow-functions": [true, "allow-declarations"] + }, + "jsRules": { + "only-arrow-functions": [true, "allow-declarations"] } } diff --git a/test/rules/only-arrow-functions/default/test.js.lint b/test/rules/only-arrow-functions/default/test.js.lint new file mode 100644 index 00000000000..c631afef0e8 --- /dev/null +++ b/test/rules/only-arrow-functions/default/test.js.lint @@ -0,0 +1,18 @@ +function foo(a) { +~~~~~~~~ [0] + return; +} + +let a = () => {}; +let b = function () {}; + ~~~~~~~~ [0] + +function c() {} +~~~~~~~~ [0] + +((func) => func())(function e() {}); + ~~~~~~~~ [0] + +((func) => func())(() => {}); + +[0]: non-arrow functions are forbidden diff --git a/test/rules/only-arrow-functions/default/tslint.json b/test/rules/only-arrow-functions/default/tslint.json index 2e69b360a49..42da3aeb813 100644 --- a/test/rules/only-arrow-functions/default/tslint.json +++ b/test/rules/only-arrow-functions/default/tslint.json @@ -1,5 +1,8 @@ { "rules": { "only-arrow-functions": true + }, + "jsRules": { + "only-arrow-functions": true } } diff --git a/test/rules/ordered-imports/case-insensitive/test.js.lint b/test/rules/ordered-imports/case-insensitive/test.js.lint new file mode 100644 index 00000000000..bd7ee497234 --- /dev/null +++ b/test/rules/ordered-imports/case-insensitive/test.js.lint @@ -0,0 +1,32 @@ +// Named imports should be alphabetized. +import {A, B} from 'foo'; +import {B, A} from 'foo'; // failure + ~~~~ [ordered-imports] + +// Case is irrelevant for named import ordering. +import {A, b, C} from 'foo'; +import {b, A, C} from 'foo'; // failure + ~~~~ [ordered-imports] + + +// Import sources should be alphabetized. +import * as bar from 'bar'; +import * as foo from 'foo'; + +import * as abc from 'abc'; +import * as foo from 'foo'; +import * as bar from 'bar'; // failure +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [ordered-sources] + +// Case is irrelevant for source import ordering. +import {A, B} from 'Bar'; +import {A, B} from 'baz'; +import {A, B} from 'Foo'; // should not fail + +// Other styles of import statements. +import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; +import someDefault from "module"; +import "something"; + +[ordered-imports]: Named imports must be alphabetized. +[ordered-sources]: Import sources within a group must be alphabetized. diff --git a/test/rules/ordered-imports/case-insensitive/tslint.json b/test/rules/ordered-imports/case-insensitive/tslint.json index 714e6c81bc9..ddc15fe9f00 100644 --- a/test/rules/ordered-imports/case-insensitive/tslint.json +++ b/test/rules/ordered-imports/case-insensitive/tslint.json @@ -1,5 +1,8 @@ { "rules": { "ordered-imports": true + }, + "jsRules": { + "ordered-imports": true } } diff --git a/test/rules/ordered-imports/lowercase-first/test.js.lint b/test/rules/ordered-imports/lowercase-first/test.js.lint new file mode 100644 index 00000000000..ef8de7ea134 --- /dev/null +++ b/test/rules/ordered-imports/lowercase-first/test.js.lint @@ -0,0 +1,32 @@ +// Named imports should be alphabetized. +import {A, B} from 'foo'; +import {B, A} from 'foo'; // failure + ~~~~ [ordered-imports] + +// Lowercase comes before uppercase. +import {b, A, C} from 'foo'; +import {A, b, C} from 'foo'; // failure + ~~~~ [ordered-imports] + +// Import sources should be alphabetized. +import * as bar from 'bar'; +import * as foo from 'foo'; + +import * as abc from 'abc'; +import * as foo from 'foo'; +import * as bar from 'bar'; // failure +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [ordered-sources] + +// Lowercase comes before uppercase +import {A, B} from 'Bar'; +import {A, B} from 'baz'; +~~~~~~~~~~~~~~~~~~~~~~~~~ [ordered-sources] +import {A, B} from 'Foo'; + +// Other styles of import statements. +import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; +import someDefault from "module"; +import "something"; + +[ordered-imports]: Named imports must be alphabetized. +[ordered-sources]: Import sources within a group must be alphabetized. diff --git a/test/rules/ordered-imports/lowercase-first/tslint.json b/test/rules/ordered-imports/lowercase-first/tslint.json index 62b8787a617..36358521d9a 100644 --- a/test/rules/ordered-imports/lowercase-first/tslint.json +++ b/test/rules/ordered-imports/lowercase-first/tslint.json @@ -1,5 +1,8 @@ { "rules": { "ordered-imports": [true, {"import-sources-order": "lowercase-first", "named-imports-order": "lowercase-first"}] + }, + "jsRules": { + "ordered-imports": [true, {"import-sources-order": "lowercase-first", "named-imports-order": "lowercase-first"}] } } diff --git a/test/rules/quotemark/double-avoid-escape/test.js.lint b/test/rules/quotemark/double-avoid-escape/test.js.lint new file mode 100644 index 00000000000..03f86c4826e --- /dev/null +++ b/test/rules/quotemark/double-avoid-escape/test.js.lint @@ -0,0 +1,5 @@ +var single = 'single'; + ~~~~~~~~ [' should be "] + var doublee = "married"; +var singleWithinDouble = "'singleWithinDouble'"; +var doubleWithinSingle = '"doubleWithinSingle"'; diff --git a/test/rules/quotemark/double-avoid-escape/tslint.json b/test/rules/quotemark/double-avoid-escape/tslint.json index 6c0f14e3051..d49fa4a7e1d 100644 --- a/test/rules/quotemark/double-avoid-escape/tslint.json +++ b/test/rules/quotemark/double-avoid-escape/tslint.json @@ -1,5 +1,8 @@ { "rules": { "quotemark": [true, "double", "avoid-escape"] + }, + "jsRules": { + "quotemark": [true, "double", "avoid-escape"] } } diff --git a/test/rules/quotemark/double/test.js.lint b/test/rules/quotemark/double/test.js.lint new file mode 100644 index 00000000000..2efd3df18b3 --- /dev/null +++ b/test/rules/quotemark/double/test.js.lint @@ -0,0 +1,6 @@ +var single = 'single'; + ~~~~~~~~ [' should be "] + var doublee = "married"; +var singleWithinDouble = "'singleWithinDouble'"; +var doubleWithinSingle = '"doubleWithinSingle"'; + ~~~~~~~~~~~~~~~~~~~~~~ [' should be "] diff --git a/test/rules/quotemark/double/tslint.json b/test/rules/quotemark/double/tslint.json index 9318e0d53e4..4e380ea41bb 100644 --- a/test/rules/quotemark/double/tslint.json +++ b/test/rules/quotemark/double/tslint.json @@ -1,5 +1,8 @@ { "rules": { "quotemark": [true, "double"] + }, + "jsRules": { + "quotemark": [true, "double"] } } diff --git a/test/rules/quotemark/single-avoid-escape/test.js.lint b/test/rules/quotemark/single-avoid-escape/test.js.lint new file mode 100644 index 00000000000..52e21fb78a9 --- /dev/null +++ b/test/rules/quotemark/single-avoid-escape/test.js.lint @@ -0,0 +1,5 @@ +var single = 'single'; + var doublee = "married"; + ~~~~~~~~~ [" should be '] +var singleWithinDouble = "'singleWithinDouble'"; +var doubleWithinSingle = '"doubleWithinSingle"'; diff --git a/test/rules/quotemark/single-avoid-escape/tslint.json b/test/rules/quotemark/single-avoid-escape/tslint.json index c360887f9d7..01b36ddb9fb 100644 --- a/test/rules/quotemark/single-avoid-escape/tslint.json +++ b/test/rules/quotemark/single-avoid-escape/tslint.json @@ -1,5 +1,8 @@ { "rules": { "quotemark": [true, "single", "avoid-escape"] + }, + "jsRules": { + "quotemark": [true, "single", "avoid-escape"] } } diff --git a/test/rules/quotemark/single/test.js.lint b/test/rules/quotemark/single/test.js.lint new file mode 100644 index 00000000000..bba732c703b --- /dev/null +++ b/test/rules/quotemark/single/test.js.lint @@ -0,0 +1,6 @@ +var single = 'single'; + var doublee = "married"; + ~~~~~~~~~ [" should be '] +var singleWithinDouble = "'singleWithinDouble'"; + ~~~~~~~~~~~~~~~~~~~~~~ [" should be '] +var doubleWithinSingle = '"doubleWithinSingle"'; diff --git a/test/rules/quotemark/single/tslint.json b/test/rules/quotemark/single/tslint.json index 4a5f880d8ab..b27e2003874 100644 --- a/test/rules/quotemark/single/tslint.json +++ b/test/rules/quotemark/single/tslint.json @@ -1,5 +1,8 @@ { "rules": { "quotemark": [true, "single"] + }, + "jsRules": { + "quotemark": [true, "single"] } } diff --git a/test/rules/radix/test.js.lint b/test/rules/radix/test.js.lint new file mode 100644 index 00000000000..634a0e9620b --- /dev/null +++ b/test/rules/radix/test.js.lint @@ -0,0 +1,4 @@ +var x = parseInt(3, 10) + + parseInt(4); + ~~~~~~~~~~~ [Missing radix parameter] +var y = parseFloat("2.5"); diff --git a/test/rules/radix/tslint.json b/test/rules/radix/tslint.json index 38441411292..c3e2ba00c22 100644 --- a/test/rules/radix/tslint.json +++ b/test/rules/radix/tslint.json @@ -1,5 +1,8 @@ { "rules": { "radix": true + }, + "jsRules": { + "radix": true } } diff --git a/test/rules/restrict-plus-operands/test.js.lint b/test/rules/restrict-plus-operands/test.js.lint new file mode 100644 index 00000000000..e5e92360603 --- /dev/null +++ b/test/rules/restrict-plus-operands/test.js.lint @@ -0,0 +1,51 @@ + +var x = 5; +var y = "10"; +var z = 8.2; +var w = "6.5"; +var pair = { + first: 5, + second: "10" +}; + +// bad +var bad1 = 5 + "10"; + ~~~~~~~~ [Types of values used in '+' operation must match] +var bad2 = [] + 5; + ~~~~~~ [Types of values used in '+' operation must match] +var bad3 = [] + {}; + ~~~~~~~ [Types of values used in '+' operation must match] +var bad4 = [] + []; + ~~~~~~~ [cannot add type undefined[]] +var bad4 = 5 + []; + ~~~~~~ [Types of values used in '+' operation must match] +var bad5 = "5" + {}; + ~~~~~~~~ [Types of values used in '+' operation must match] +var bad6 = 5.5 + "5"; + ~~~~~~~~~ [Types of values used in '+' operation must match] +var bad7 = "5.5" + 5; + ~~~~~~~~~ [Types of values used in '+' operation must match] +var bad8 = x + y; + ~~~~~ [Types of values used in '+' operation must match] +var bad9 = y + x; + ~~~~~ [Types of values used in '+' operation must match] +var bad10 = x + {}; + ~~~~~~ [Types of values used in '+' operation must match] +var bad11 = [] + y; + ~~~~~~ [Types of values used in '+' operation must match] +var bad12 = pair.first + "10"; + ~~~~~~~~~~~~~~~~~ [Types of values used in '+' operation must match] +var bad13 = 5 + pair.second; + ~~~~~~~~~~~~~~~ [Types of values used in '+' operation must match] +var bad14 = pair + pair; + ~~~~~~~~~~~ [cannot add type { first: number; second: string; }] + +// good +var good1 = 5 + 10; +var good2 = "5.5" + "10"; +var good3 = parseFloat("5.5", 10), + 10; +var good4 = x + z; +var good5 = y + w; + +var good6 = pair.first + 10; +var good8 = "5.5" + pair.second; diff --git a/test/rules/restrict-plus-operands/tslint.json b/test/rules/restrict-plus-operands/tslint.json index 5337f453195..555983b2069 100644 --- a/test/rules/restrict-plus-operands/tslint.json +++ b/test/rules/restrict-plus-operands/tslint.json @@ -4,5 +4,8 @@ }, "rules": { "restrict-plus-operands": true + }, + "jsRules": { + "restrict-plus-operands": true } } diff --git a/test/rules/semicolon/always/test.js.lint b/test/rules/semicolon/always/test.js.lint new file mode 100644 index 00000000000..ee95f663803 --- /dev/null +++ b/test/rules/semicolon/always/test.js.lint @@ -0,0 +1,67 @@ +var x = 3 + ~nil [Missing semicolon] +a += b + ~nil [Missing semicolon] + +c = () => { +} + ~nil [Missing semicolon] + +d = function() { } + ~nil [Missing semicolon] + +console.log("i am adam, am i?") + ~nil [Missing semicolon] + +function xyz() { + return + ~nil [Missing semicolon] +} + +switch(xyz) { + case 1: + break + ~nil [Missing semicolon] + case 2: + continue + ~nil [Missing semicolon] +} + +throw new Error("some error") + ~nil [Missing semicolon] + +do { + var a = 4 + ~nil [Missing semicolon] +} while(x == 3) + ~nil [Missing semicolon] + +debugger + ~nil [Missing semicolon] + +function useStrictMissingSemicolon() { + "use strict" + ~nil [Missing semicolon] + return null; +} + +class MyClass { + name + ~nil [Missing semicolon] + index + ~nil [Missing semicolon] + email; + + initializedProperty = 6 + ~nil [Missing semicolon] + initializedMethodProperty = () => { return "hi"; } +} + +import {Router} from 'aurelia-router'; + +import {Controller} from 'my-lib' + ~nil [Missing semicolon] + +export default LoginPage; +export default LoginPage + ~nil [Missing semicolon] diff --git a/test/rules/semicolon/always/tslint.json b/test/rules/semicolon/always/tslint.json index 3df79679a99..81c96685e08 100644 --- a/test/rules/semicolon/always/tslint.json +++ b/test/rules/semicolon/always/tslint.json @@ -1,5 +1,8 @@ { "rules": { "semicolon": [true, "always"] + }, + "jsRules": { + "semicolon": [true, "always"] } } diff --git a/test/rules/switch-default/test.js.lint b/test/rules/switch-default/test.js.lint new file mode 100644 index 00000000000..2f33aba2eb5 --- /dev/null +++ b/test/rules/switch-default/test.js.lint @@ -0,0 +1,74 @@ +switch (foo) { +~~~~~~~~~~~~~~ +case 1: +~~~~~~~ + bar(); +~~~~~~~~~~ + break; +~~~~~~~~~~ +} +~ [Switch statement should include a 'default' case] + +switch (foo) { +~~~~~~~~~~~~~~ +case 1: +~~~~~~~ + bar(); +~~~~~~~~~~ + break; +~~~~~~~~~~ +case 2: +~~~~~~~ + bar(); +~~~~~~~~~~ + break; +~~~~~~~~~~ +case 3: +~~~~~~~ + bar(); +~~~~~~~~~~ + break; +~~~~~~~~~~ +} +~ [Switch statement should include a 'default' case] + +// valid +switch (foo) { +case 1: + bar(); + break; +default: + break; +} + +// valid +switch (foo) { +default: + bar(); + break; +case 1: + bar(); + break; +} + +// valid +switch (foo) { +case 1: + bar(); + break; +default: + break; +case 2: + break; +} + +// valid +baz: +while (true){ + switch(foo) { + case 1: + bar(); + continue baz; + default: + } +} diff --git a/test/rules/switch-default/tslint.json b/test/rules/switch-default/tslint.json index 05e34955935..55854a35889 100644 --- a/test/rules/switch-default/tslint.json +++ b/test/rules/switch-default/tslint.json @@ -1,5 +1,8 @@ { "rules": { "switch-default": true + }, + "jsRules": { + "switch-default": true } } diff --git a/test/rules/trailing-comma/multiline-always/test.js.lint b/test/rules/trailing-comma/multiline-always/test.js.lint new file mode 100644 index 00000000000..ce112b7c9a5 --- /dev/null +++ b/test/rules/trailing-comma/multiline-always/test.js.lint @@ -0,0 +1,138 @@ +var v = [{ + a: 1, + b: 2, + d: 34, + c: (a + b), +},]; + +var x = [{ + a: 1, + b: 2, + d: 34, + c: (a + b) + ~ [Missing trailing comma] +}]; + +var s = { + sA: 6, +}; + +var t = { + tA: 7 + ~ [Missing trailing comma] +} + +var y = { + yA: 42, + yB: 24, +}; + +var z = { + zOne: 2, + zTwo: 1 + ~ [Missing trailing comma] +}; + +var ss = [ + 6, +]; + +var tt = [ + 7 + ~ [Missing trailing comma] +]; + +var yy = [ + 42, + 24, +]; + +var zz = [ + 2, + 1 + ~ [Missing trailing comma] +]; + +var a = [{a: 1, b: 2, d: 34, c: (a + b),},]; + +var b = [{a: 1, b: 2, d: 34, c: (a + b)}]; + +var c = {cA: 42, cB: 24,}; + +var d = {dOne: 2, dTwo: 1}; + +var cc = [42, 24,]; + +var dd = [2, 1]; + +var { + sA, +} = s; + +var { + tA + ~ [Missing trailing comma] +} = t; + +var { + yA, + yB, +} = y; + +var { + zOne, + zTwo + ~ [Missing trailing comma] +} = z; + +var [ + ssA, +] = ss; + +var [ + ttA + ~ [Missing trailing comma] +] = tt; + +var [ + yyA, + yyB, +] = yy; + +var [ + zzOne, + zzTwo + ~ [Missing trailing comma] +] = zz; + +var {cA, cB,} = c; + +var {dOne, dTwo} = d; + +var [ccA, ccB,] = cc; + +var [ddOne, ddTwo] = dd; + +import { + ClassS, +} from "module"; + +import { + ClassT + ~ [Missing trailing comma] +} from "module"; + +import { + ClassV, + ClassX, +} from "module"; + +import { + ClassY, + ClassZ + ~ [Missing trailing comma] +} from "module"; + +import {ClassA, ClassB,} from "module"; + +import {ClassC, ClassD} from "module"; diff --git a/test/rules/trailing-comma/multiline-always/tslint.json b/test/rules/trailing-comma/multiline-always/tslint.json index b9d77c2ab7c..2f4ac0d2439 100644 --- a/test/rules/trailing-comma/multiline-always/tslint.json +++ b/test/rules/trailing-comma/multiline-always/tslint.json @@ -1,5 +1,8 @@ { "rules": { "trailing-comma": [true, {"multiline": "always"}] + }, + "jsRules": { + "trailing-comma": [true, {"multiline": "always"}] } } diff --git a/test/rules/triple-equals/allow-null-check/test.js.lint b/test/rules/triple-equals/allow-null-check/test.js.lint new file mode 100644 index 00000000000..6fddcf97283 --- /dev/null +++ b/test/rules/triple-equals/allow-null-check/test.js.lint @@ -0,0 +1,19 @@ +var testVariable = 123; + +function testFunction() { + if (x === testFunction && y == 4) { + ~~ [== should be ===] + console.log("called"); + } + + var z = (x + 3) != 5; + ~~ [!= should be !==] + return; +} + +// disallow double-equality undefined checks +var x = (y == undefined) ? 1 : 2; + ~~ [== should be ===] + +// allow double-equality null checks +var x = (y == null) ? 1 : 2; diff --git a/test/rules/triple-equals/allow-null-check/tslint.json b/test/rules/triple-equals/allow-null-check/tslint.json index b60bf169ef6..e3ff478bd69 100644 --- a/test/rules/triple-equals/allow-null-check/tslint.json +++ b/test/rules/triple-equals/allow-null-check/tslint.json @@ -1,5 +1,8 @@ { "rules": { "triple-equals": [true, "allow-null-check"] + }, + "jsRules": { + "triple-equals": [true, "allow-null-check"] } } diff --git a/test/rules/triple-equals/allow-undefined-check/test.js.lint b/test/rules/triple-equals/allow-undefined-check/test.js.lint new file mode 100644 index 00000000000..a3e2136f538 --- /dev/null +++ b/test/rules/triple-equals/allow-undefined-check/test.js.lint @@ -0,0 +1,19 @@ +var testVariable = 123; + +function testFunction() { + if (x === testFunction && y == 4) { + ~~ [== should be ===] + console.log("called"); + } + + var z = (x + 3) != 5; + ~~ [!= should be !==] + return; +} + +// allow double-equality undefined checks +var x = (y == undefined) ? 1 : 2; + +// disallow double-equality null checks +var x = (y == null) ? 1 : 2; + ~~ [== should be ===] diff --git a/test/rules/triple-equals/allow-undefined-check/tslint.json b/test/rules/triple-equals/allow-undefined-check/tslint.json index 1ab9dce6344..3bd1a57fb97 100644 --- a/test/rules/triple-equals/allow-undefined-check/tslint.json +++ b/test/rules/triple-equals/allow-undefined-check/tslint.json @@ -1,5 +1,8 @@ { "rules": { "triple-equals": [true, "allow-undefined-check"] + }, + "jsRules": { + "triple-equals": [true, "allow-undefined-check"] } } diff --git a/test/rules/use-isnan/test.js.lint b/test/rules/use-isnan/test.js.lint new file mode 100644 index 00000000000..6999b049d4c --- /dev/null +++ b/test/rules/use-isnan/test.js.lint @@ -0,0 +1,31 @@ + +// no violation for comparing NaN using isNaN +if (isNaN(NaN)) { +} + +// no violation for correctly checking for isNaN +if (isNaN(something)) { } + +// no violation for assignments +let x = 0; +x = NaN; + +// do not use equality operators to compare for NaN +if (foo == NaN) { } + ~~~~~~~~~~ [Found an invalid comparison for NaN: foo == NaN] +if (NaN === foo) { } + ~~~~~~~~~~~ [Found an invalid comparison for NaN: NaN === foo] +if (foo != NaN) { } + ~~~~~~~~~~ [Found an invalid comparison for NaN: foo != NaN] +if (NaN !== foo) { } + ~~~~~~~~~~~ [Found an invalid comparison for NaN: NaN !== foo] + +// do not use any binary operators to compare for NaN +if (foo > NaN) { } + ~~~~~~~~~ [Found an invalid comparison for NaN: foo > NaN] +if (NaN >= foo) { } + ~~~~~~~~~~ [Found an invalid comparison for NaN: NaN >= foo] +if (foo < NaN) { } + ~~~~~~~~~ [Found an invalid comparison for NaN: foo < NaN] +if (NaN <= foo) { } + ~~~~~~~~~~ [Found an invalid comparison for NaN: NaN <= foo] diff --git a/test/rules/use-isnan/tslint.json b/test/rules/use-isnan/tslint.json index 880adde9812..121d0344d4a 100644 --- a/test/rules/use-isnan/tslint.json +++ b/test/rules/use-isnan/tslint.json @@ -1,5 +1,8 @@ { "rules": { "use-isnan": true + }, + "jsRules": { + "use-isnan": true } } diff --git a/test/rules/variable-name/allow-leading-trailing-underscore/test.js.lint b/test/rules/variable-name/allow-leading-trailing-underscore/test.js.lint new file mode 100644 index 00000000000..27af373c96e --- /dev/null +++ b/test/rules/variable-name/allow-leading-trailing-underscore/test.js.lint @@ -0,0 +1,45 @@ +var validName1 = "hi"; +var VALIDNAME2 = "there"; +var InvalidName1 = ","; // failure + ~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] +var invalid_name2 = " "; // failure + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + +class Test { + Invalid_name3 = "how"; // failure + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + _optionallyValid = "are"; // sometimes a failure +} + +function test() { + () => { + var InVaLiDnAmE4 = "you"; // failure + ~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + }; +} + +export function functionWithInvalidParamNames (bad_name, AnotherOne) { // 2 failures + ~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +let { foo, bar } = { foo: 1, bar: 2 }; +let [ InvalidFoo, invalid_bar, ...invalid_baz ] = [1, 2, 3, 4]; // 3 failures + ~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + +export function anotherFunctionWithInvalidParamNames ([first_element, SecondElement]) { // 2 failures + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + ~~~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +export function functionWithInvalidSpread(invalid_arg: ...number) { // 1 failure + ~~~~~~~~~~~ [variable name must be in camelcase or uppercase] + // +} + +let optionallyValid_ = "bar"; +let _$httpBackend_ = "leading and trailing"; diff --git a/test/rules/variable-name/allow-leading-trailing-underscore/tslint.json b/test/rules/variable-name/allow-leading-trailing-underscore/tslint.json index c5d657add43..7c86f5c9881 100644 --- a/test/rules/variable-name/allow-leading-trailing-underscore/tslint.json +++ b/test/rules/variable-name/allow-leading-trailing-underscore/tslint.json @@ -1,5 +1,8 @@ { "rules": { "variable-name": [true, "allow-leading-underscore", "allow-trailing-underscore"] + }, + "jsRules": { + "variable-name": [true, "allow-leading-underscore", "allow-trailing-underscore"] } } diff --git a/test/rules/whitespace/all/test.js.lint b/test/rules/whitespace/all/test.js.lint new file mode 100644 index 00000000000..314a6cd2fe8 --- /dev/null +++ b/test/rules/whitespace/all/test.js.lint @@ -0,0 +1,88 @@ + export var ast=AST; + ~ [missing whitespace] + ~ [missing whitespace] + + var y = (x === 10)?1:2; + ~ [missing whitespace] + ~ [missing whitespace] + ~ [missing whitespace] + ~ [missing whitespace] + + var zz = (y===4); + ~ [missing whitespace] + ~ [missing whitespace] + + var z=y; + ~ [missing whitespace] + ~ [missing whitespace] + + var a,b; + ~ [missing whitespace] + + switch(x) { + ~ [missing whitespace] + case 1:break; + ~ [missing whitespace] + default:break; + ~ [missing whitespace] + } + + for(x = 1;x <2; ++x) { + ~ [missing whitespace] + ~ [missing whitespace] + ~ [missing whitespace] + goto:console.log("hi"); + ~ [missing whitespace] + } + + while(i < 1) { + ~ [missing whitespace] + ++i; + } + + var q; + q.forEach(()=>3); + ~ [missing whitespace] + ~ [missing whitespace] + q.forEach(()=>{ + ~ [missing whitespace] + ~ [missing whitespace] + return 3; + }); + +var a; + +a.then(() => { + return 1; +}).if(() => { + return 1; +}); + +var name = "something"; +var test = ` + +
Date: Thu, 3 Nov 2016 14:55:22 +0100 Subject: [PATCH 036/111] fix: do not flag nested or .d.ts namespaces. (#1571) --- src/language/utils.ts | 7 +++++++ src/rules/noNamespaceRule.ts | 12 +++++++++++- .../no-namespace/allow-declarations/test.ts.lint | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/language/utils.ts b/src/language/utils.ts index 62f3b332154..232abc63de3 100644 --- a/src/language/utils.ts +++ b/src/language/utils.ts @@ -118,6 +118,13 @@ export function getBindingElementVariableDeclaration(node: ts.BindingElement): t return currentParent; } +/** + * Returns true if some ancestor of `node` satisfies `predicate`, including `node` itself. + */ +export function someAncestor(node: ts.Node, predicate: (n: ts.Node)=>boolean): boolean { + return predicate(node) || (node.parent && someAncestor(node.parent, predicate)); +} + /** * Bitwise check for node flags. */ diff --git a/src/rules/noNamespaceRule.ts b/src/rules/noNamespaceRule.ts index 5f16cf38169..130d351ceaa 100644 --- a/src/rules/noNamespaceRule.ts +++ b/src/rules/noNamespaceRule.ts @@ -55,11 +55,21 @@ export class Rule extends Lint.Rules.AbstractRule { } class NoNamespaceWalker extends Lint.RuleWalker { + public visitSourceFile(node: ts.SourceFile) { + // Ignore all .d.ts files by returning and not walking their ASTs. + // .d.ts declarations do not have the Ambient flag set, but are still declarations. + if (this.hasOption("allow-declarations") && node.fileName.match(/\.d\.ts$/)) { return; } + this.walkChildren(node); + } + public visitModuleDeclaration(decl: ts.ModuleDeclaration) { super.visitModuleDeclaration(decl); // declare module 'foo' {} is an external module, not a namespace. if (decl.name.kind === ts.SyntaxKind.StringLiteral) { return; } - if (Lint.isNodeFlagSet(decl, ts.NodeFlags.Ambient) && this.hasOption("allow-declarations")) { return; } + if (Lint.someAncestor(decl, (n) => Lint.isNodeFlagSet(n, ts.NodeFlags.Ambient)) && + this.hasOption("allow-declarations")) { + return; + } if (Lint.isNestedModuleDeclaration(decl)) { return; } this.addFailure(this.createFailure(decl.getStart(), decl.getWidth(), Rule.FAILURE_STRING)); } diff --git a/test/rules/no-namespace/allow-declarations/test.ts.lint b/test/rules/no-namespace/allow-declarations/test.ts.lint index 8caa74ce5dc..64db872ce3a 100644 --- a/test/rules/no-namespace/allow-declarations/test.ts.lint +++ b/test/rules/no-namespace/allow-declarations/test.ts.lint @@ -1,3 +1,6 @@ declare namespace Foo { + // Allowed because namespaces nested in ambients are implicitly ambient. + namespace Foo { + } } From 350e6145b028b8e06c960c1a6a789169e099cb68 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Thu, 3 Nov 2016 10:03:51 -0400 Subject: [PATCH 037/111] Small code style fixes --- src/language/utils.ts | 6 +++--- src/rules/noNamespaceRule.ts | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/language/utils.ts b/src/language/utils.ts index 232abc63de3..2a33a7a6fe9 100644 --- a/src/language/utils.ts +++ b/src/language/utils.ts @@ -119,9 +119,9 @@ export function getBindingElementVariableDeclaration(node: ts.BindingElement): t } /** - * Returns true if some ancestor of `node` satisfies `predicate`, including `node` itself. + * @returns true if some ancestor of `node` satisfies `predicate`, including `node` itself. */ -export function someAncestor(node: ts.Node, predicate: (n: ts.Node)=>boolean): boolean { +export function someAncestor(node: ts.Node, predicate: (n: ts.Node) => boolean): boolean { return predicate(node) || (node.parent && someAncestor(node.parent, predicate)); } @@ -135,7 +135,7 @@ export function isNodeFlagSet(node: ts.Node, flagToCheck: ts.NodeFlags): boolean } /** - * Returns true if decl is a nested module declaration, i.e. represents a segment of a dotted module path. + * @returns true if decl is a nested module declaration, i.e. represents a segment of a dotted module path. */ export function isNestedModuleDeclaration(decl: ts.ModuleDeclaration) { // in a declaration expression like 'module a.b.c' - 'a' is the top level module declaration node and 'b' and 'c' diff --git a/src/rules/noNamespaceRule.ts b/src/rules/noNamespaceRule.ts index 130d351ceaa..9152f9496c3 100644 --- a/src/rules/noNamespaceRule.ts +++ b/src/rules/noNamespaceRule.ts @@ -58,19 +58,27 @@ class NoNamespaceWalker extends Lint.RuleWalker { public visitSourceFile(node: ts.SourceFile) { // Ignore all .d.ts files by returning and not walking their ASTs. // .d.ts declarations do not have the Ambient flag set, but are still declarations. - if (this.hasOption("allow-declarations") && node.fileName.match(/\.d\.ts$/)) { return; } + if (this.hasOption("allow-declarations") && node.fileName.match(/\.d\.ts$/)) { + return; + } this.walkChildren(node); } public visitModuleDeclaration(decl: ts.ModuleDeclaration) { super.visitModuleDeclaration(decl); + // declare module 'foo' {} is an external module, not a namespace. - if (decl.name.kind === ts.SyntaxKind.StringLiteral) { return; } - if (Lint.someAncestor(decl, (n) => Lint.isNodeFlagSet(n, ts.NodeFlags.Ambient)) && - this.hasOption("allow-declarations")) { + if (decl.name.kind === ts.SyntaxKind.StringLiteral) { + return; + } + if (this.hasOption("allow-declarations") + && Lint.someAncestor(decl, (n) => Lint.isNodeFlagSet(n, ts.NodeFlags.Ambient))) { + return; + } + if (Lint.isNestedModuleDeclaration(decl)) { return; } - if (Lint.isNestedModuleDeclaration(decl)) { return; } + this.addFailure(this.createFailure(decl.getStart(), decl.getWidth(), Rule.FAILURE_STRING)); } } From fb3b6ee4385db2ee786ba6bf1817958dd10ae8d9 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Thu, 3 Nov 2016 10:45:32 -0400 Subject: [PATCH 038/111] Remove no-duplicate-key rule again (#1671) --- docs/_data/rules.json | 11 ---- docs/rules/no-duplicate-key/index.html | 16 ------ src/configs/recommended.ts | 2 - src/rules/noDuplicateKeyRule.ts | 70 ------------------------ test/rules/no-duplicate-key/test.js.lint | 46 ---------------- test/rules/no-duplicate-key/test.ts.lint | 46 ---------------- test/rules/no-duplicate-key/tslint.json | 8 --- 7 files changed, 199 deletions(-) delete mode 100644 docs/rules/no-duplicate-key/index.html delete mode 100644 src/rules/noDuplicateKeyRule.ts delete mode 100644 test/rules/no-duplicate-key/test.js.lint delete mode 100644 test/rules/no-duplicate-key/test.ts.lint delete mode 100644 test/rules/no-duplicate-key/tslint.json diff --git a/docs/_data/rules.json b/docs/_data/rules.json index fc235ccf2c9..a431bba3525 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -456,17 +456,6 @@ ], "type": "maintainability" }, - { - "ruleName": "no-duplicate-key", - "description": "Disallows duplicate keys in object literals.", - "rationale": "\nThere is no good reason to define an object literal with the same key twice.\nThis rule is now implemented in the TypeScript compiler and does not need to be used.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality" - }, { "ruleName": "no-duplicate-variable", "description": "Disallows duplicate variable declarations in the same block scope.", diff --git a/docs/rules/no-duplicate-key/index.html b/docs/rules/no-duplicate-key/index.html deleted file mode 100644 index cae244b5058..00000000000 --- a/docs/rules/no-duplicate-key/index.html +++ /dev/null @@ -1,16 +0,0 @@ ---- -ruleName: no-duplicate-key -description: Disallows duplicate keys in object literals. -rationale: |- - - There is no good reason to define an object literal with the same key twice. - This rule is now implemented in the TypeScript compiler and does not need to be used. -optionsDescription: Not configurable. -options: null -optionExamples: - - 'true' -type: functionality -optionsJSON: 'null' -layout: rule -title: 'Rule: no-duplicate-key' ---- \ No newline at end of file diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index 5a41449ef63..b91df7a259d 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -53,7 +53,6 @@ export const rules = { ], "no-construct": true, "no-debugger": true, - "no-duplicate-key": true, "no-duplicate-variable": true, "no-empty": true, "no-eval": true, @@ -155,7 +154,6 @@ export const jsRules = { ], "no-construct": true, "no-debugger": true, - "no-duplicate-key": true, "no-duplicate-variable": true, "no-empty": true, "no-eval": true, diff --git a/src/rules/noDuplicateKeyRule.ts b/src/rules/noDuplicateKeyRule.ts deleted file mode 100644 index 17e86fcf06c..00000000000 --- a/src/rules/noDuplicateKeyRule.ts +++ /dev/null @@ -1,70 +0,0 @@ -/** - * @license - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as ts from "typescript"; - -import * as Lint from "../lint"; - -export class Rule extends Lint.Rules.AbstractRule { - /* tslint:disable:object-literal-sort-keys */ - public static metadata: Lint.IRuleMetadata = { - ruleName: "no-duplicate-key", - description: "Disallows duplicate keys in object literals.", - rationale: Lint.Utils.dedent` - There is no good reason to define an object literal with the same key twice. - This rule is now implemented in the TypeScript compiler and does not need to be used.`, - optionsDescription: "Not configurable.", - options: null, - optionExamples: ["true"], - type: "functionality", - typescriptOnly: false, - }; - /* tslint:enable:object-literal-sort-keys */ - - public static FAILURE_STRING_FACTORY = (name: string) => `Duplicate key '${name}'`; - - public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new NoDuplicateKeyWalker(sourceFile, this.getOptions())); - } -} - -class NoDuplicateKeyWalker extends Lint.RuleWalker { - private objectKeysStack: {[key: string]: boolean}[] = []; - - public visitObjectLiteralExpression(node: ts.ObjectLiteralExpression) { - this.objectKeysStack.push(Object.create(null)); - super.visitObjectLiteralExpression(node); - this.objectKeysStack.pop(); - } - - public visitPropertyAssignment(node: ts.PropertyAssignment) { - const objectKeys = this.objectKeysStack[this.objectKeysStack.length - 1]; - const keyNode = node.name; - - if (keyNode.kind === ts.SyntaxKind.Identifier) { - const key = ( keyNode).text; - if (objectKeys[key]) { - const failureString = Rule.FAILURE_STRING_FACTORY(key); - this.addFailure(this.createFailure(keyNode.getStart(), keyNode.getWidth(), failureString)); - } else { - objectKeys[key] = true; - } - } - - super.visitPropertyAssignment(node); - } -} diff --git a/test/rules/no-duplicate-key/test.js.lint b/test/rules/no-duplicate-key/test.js.lint deleted file mode 100644 index 78ce9d297b2..00000000000 --- a/test/rules/no-duplicate-key/test.js.lint +++ /dev/null @@ -1,46 +0,0 @@ -var a = { - a: 1, - b: 2 -}; - -var x = { - axa: 1, - bd: 2, - c: 3, - axa: 4, - ~~~ [Duplicate key 'axa'] - d: 5, - ba: 3, - bd: 6, - ~~ [Duplicate key 'bd'] - axa: 6 - ~~~ [Duplicate key 'axa'] -}; - -var z = { - c: [1, 2, 3], - d: { - b: "b", - a: 11, - c: [11, 22, 33] - }, - a: 1, - b: "a" -}; - -var interspersed = { - duplicated: 1, - newContext: {}, - duplicated: 2 - ~~~~~~~~~~ [Duplicate key 'duplicated'] -}; - -var n = { - constructor: function () {}, - hasOwnProperty: function () {} -}; - -var foo = { - ["ab" + "cd"]: "efgh", - [x.axa]: "bar" -} diff --git a/test/rules/no-duplicate-key/test.ts.lint b/test/rules/no-duplicate-key/test.ts.lint deleted file mode 100644 index 78ce9d297b2..00000000000 --- a/test/rules/no-duplicate-key/test.ts.lint +++ /dev/null @@ -1,46 +0,0 @@ -var a = { - a: 1, - b: 2 -}; - -var x = { - axa: 1, - bd: 2, - c: 3, - axa: 4, - ~~~ [Duplicate key 'axa'] - d: 5, - ba: 3, - bd: 6, - ~~ [Duplicate key 'bd'] - axa: 6 - ~~~ [Duplicate key 'axa'] -}; - -var z = { - c: [1, 2, 3], - d: { - b: "b", - a: 11, - c: [11, 22, 33] - }, - a: 1, - b: "a" -}; - -var interspersed = { - duplicated: 1, - newContext: {}, - duplicated: 2 - ~~~~~~~~~~ [Duplicate key 'duplicated'] -}; - -var n = { - constructor: function () {}, - hasOwnProperty: function () {} -}; - -var foo = { - ["ab" + "cd"]: "efgh", - [x.axa]: "bar" -} diff --git a/test/rules/no-duplicate-key/tslint.json b/test/rules/no-duplicate-key/tslint.json deleted file mode 100644 index d1172199f3c..00000000000 --- a/test/rules/no-duplicate-key/tslint.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "rules": { - "no-duplicate-key": true - }, - "jsRules": { - "no-duplicate-key": true - } -} From d7e1cf8a930122ad769472ffdba93f7104454995 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Thu, 3 Nov 2016 13:17:46 -0400 Subject: [PATCH 039/111] Make mocha run all tests, fix broken tests (#1677) --- package.json | 2 +- src/ruleLoader.ts | 2 +- src/tslintMulti.ts | 2 +- test/config/tslint-almost-empty.json | 2 +- test/config/tslint-custom-rules-with-dir.json | 3 +++ test/config/tslint-custom-rules-with-two-dirs.json | 4 ++++ test/config/tslint-custom-rules.json | 3 +++ test/config/tslint-with-bom.json | 2 +- test/config/tslint-with-comments.json | 9 +++++++++ test/configurationTests.ts | 5 +---- test/executable/executableTests.ts | 5 +++-- .../external/tslint-test-config-non-relative/tslint.json | 3 +++ test/external/tslint-test-config/tslint.json | 4 ++++ test/external/tslint-test-custom-rules/tslint.json | 4 ++++ 14 files changed, 39 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 77cbd9c7955..ce7f23d7192 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "lint:test": "tslint test/**/*.ts -e test/**/*.test.ts", "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 build/test/assert.js", + "test:mocha": "mocha --reporter spec --colors \"build/test/**/*Tests.js\" build/test/assert.js", "test:rules": "node ./build/test/ruleTestRunner.js", "verify": "npm-run-all clean compile lint test docs" }, diff --git a/src/ruleLoader.ts b/src/ruleLoader.ts index 9e779072704..01d3ffa3d41 100644 --- a/src/ruleLoader.ts +++ b/src/ruleLoader.ts @@ -46,7 +46,7 @@ export function loadRules(ruleConfiguration: {[name: string]: any}, if (Rule == null) { notFoundRules.push(ruleName); } else { - if (isJs && Rule.metadata.typescriptOnly != null && Rule.metadata.typescriptOnly) { + if (isJs && Rule.metadata && Rule.metadata.typescriptOnly != null && Rule.metadata.typescriptOnly) { notAllowedInJsRules.push(ruleName); } else { const all = "all"; // make the linter happy until we can turn it on and off diff --git a/src/tslintMulti.ts b/src/tslintMulti.ts index 65a8ded8606..99d099c5299 100644 --- a/src/tslintMulti.ts +++ b/src/tslintMulti.ts @@ -101,7 +101,7 @@ class MultiLinter { } if (sourceFile === undefined) { - throw new Error(`Invalid source file: ${fileName}. Ensure that the files supplied to lint have a .ts or .tsx extension.`); + throw new Error(`Invalid source file: ${fileName}. Ensure that the files supplied to lint have a .ts, .tsx, or .js extension.`); } // walk the code first to find all the intervals where rules are disabled diff --git a/test/config/tslint-almost-empty.json b/test/config/tslint-almost-empty.json index 5f229f5ea27..74f5ff48f51 100644 --- a/test/config/tslint-almost-empty.json +++ b/test/config/tslint-almost-empty.json @@ -1 +1 @@ -{ "rules": {} } +{ "jsRules": {}, "rules": {} } diff --git a/test/config/tslint-custom-rules-with-dir.json b/test/config/tslint-custom-rules-with-dir.json index abe7c97a534..8c4ae31b1e5 100644 --- a/test/config/tslint-custom-rules-with-dir.json +++ b/test/config/tslint-custom-rules-with-dir.json @@ -1,5 +1,8 @@ { "rulesDirectory": "../files/custom-rules/", + "jsRules": { + "always-fail": true + }, "rules": { "always-fail": true } diff --git a/test/config/tslint-custom-rules-with-two-dirs.json b/test/config/tslint-custom-rules-with-two-dirs.json index f02d738225e..6cc0107305f 100644 --- a/test/config/tslint-custom-rules-with-two-dirs.json +++ b/test/config/tslint-custom-rules-with-two-dirs.json @@ -1,5 +1,9 @@ { "rulesDirectory": ["../files/custom-rules-2", "../files/custom-rules/"], + "jsRules": { + "always-fail": true, + "no-fail": true + }, "rules": { "always-fail": true, "no-fail": true diff --git a/test/config/tslint-custom-rules.json b/test/config/tslint-custom-rules.json index c6568e1ad90..250eafcd974 100644 --- a/test/config/tslint-custom-rules.json +++ b/test/config/tslint-custom-rules.json @@ -1,4 +1,7 @@ { + "jsRules": { + "always-fail": true + }, "rules": { "always-fail": true } diff --git a/test/config/tslint-with-bom.json b/test/config/tslint-with-bom.json index 767e6c5b7e9..2153257c887 100644 --- a/test/config/tslint-with-bom.json +++ b/test/config/tslint-with-bom.json @@ -1 +1 @@ -{ "rules": { } } \ No newline at end of file +{ "jsRules": { }, "rules": { } } \ No newline at end of file diff --git a/test/config/tslint-with-comments.json b/test/config/tslint-with-comments.json index 0990b5256da..ef12ab77da1 100644 --- a/test/config/tslint-with-comments.json +++ b/test/config/tslint-with-comments.json @@ -1,4 +1,13 @@ { + // a nice comment + "jsRules": { + /* + "rule-one": true, + */ + "rule-two": true, + "rule-three": "//not a comment", + "rule-four": "/*also not a comment*/" + }, // a nice comment "rules": { /* diff --git a/test/configurationTests.ts b/test/configurationTests.ts index d7f24d0b201..2e5ab236c14 100644 --- a/test/configurationTests.ts +++ b/test/configurationTests.ts @@ -113,7 +113,7 @@ describe("Configuration", () => { it("extends with builtin", () => { const config = loadConfigurationFromPath("./test/config/tslint-extends-builtin.json"); - assert.isTrue(config.jsRules["no-var-keyword"]); + assert.isUndefined(config.jsRules["no-var-keyword"]); assert.isFalse(config.jsRules["no-eval"]); assert.isTrue(config.rules["no-var-keyword"]); assert.isFalse(config.rules["no-eval"]); @@ -144,9 +144,6 @@ describe("Configuration", () => { it("extends with package installed relative to tslint", () => { fs.writeFileSync(tmpfile, JSON.stringify({ extends: "tslint-test-config-non-relative" })); let config = loadConfigurationFromPath(tmpfile); - assert.deepEqual(config.jsRules, { - "class-name": true, - }); assert.deepEqual(config.rules, { "class-name": true, }); diff --git a/test/executable/executableTests.ts b/test/executable/executableTests.ts index 61e24ce8ff8..31d281c2958 100644 --- a/test/executable/executableTests.ts +++ b/test/executable/executableTests.ts @@ -24,8 +24,9 @@ const EXECUTABLE_DIR = path.resolve(process.cwd(), "test", "executable"); const EXECUTABLE_PATH = path.resolve(EXECUTABLE_DIR, "npm-like-executable"); const TEMP_JSON_PATH = path.resolve(EXECUTABLE_DIR, "tslint.json"); -describe("Executable", () => { - +/* tslint:disable:only-arrow-functions */ +describe("Executable", function() { + this.slow(3000); // the executable is JIT-ed each time it runs; avoid showing slowness warnings describe("Files", () => { it("exits with code 1 if no arguments passed", (done) => { execCli([], (err, stdout, stderr) => { diff --git a/test/external/tslint-test-config-non-relative/tslint.json b/test/external/tslint-test-config-non-relative/tslint.json index fcaed86a61e..5078a1f987d 100644 --- a/test/external/tslint-test-config-non-relative/tslint.json +++ b/test/external/tslint-test-config-non-relative/tslint.json @@ -1,4 +1,7 @@ { + "jsRules": { + "class-name": true + }, "rules": { "class-name": true } diff --git a/test/external/tslint-test-config/tslint.json b/test/external/tslint-test-config/tslint.json index 2cf73c5a02d..2e3cdcef21a 100644 --- a/test/external/tslint-test-config/tslint.json +++ b/test/external/tslint-test-config/tslint.json @@ -1,5 +1,9 @@ { "extends": "tslint-test-custom-rules", + "jsRules": { + "rule-two": true, + "rule-four": true + }, "rules": { "rule-two": true, "rule-four": true diff --git a/test/external/tslint-test-custom-rules/tslint.json b/test/external/tslint-test-custom-rules/tslint.json index 0f4be5d3c42..16ddc786809 100644 --- a/test/external/tslint-test-custom-rules/tslint.json +++ b/test/external/tslint-test-custom-rules/tslint.json @@ -1,5 +1,9 @@ { "rulesDirectory": ["./rules"], + "jsRules": { + "rule-one": true, + "rule-two": false + }, "rules": { "rule-one": true, "rule-two": false From 3e560451d13b43053065f571a21f9c4bc1ff06d5 Mon Sep 17 00:00:00 2001 From: Andrii Dieiev Date: Fri, 4 Nov 2016 05:43:04 +0200 Subject: [PATCH 040/111] Fix lint task for linux and lint error (#1678) --- package.json | 4 ++-- src/tslintMulti.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ce7f23d7192..de1c4a1a118 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "compile:scripts": "tsc -p scripts", "compile:test": "tsc -p test", "lint": "npm-run-all -p lint:core lint:test", - "lint:core": "tslint src/**/*.ts", - "lint:test": "tslint test/**/*.ts -e test/**/*.test.ts", + "lint:core": "tslint \"src/**/*.ts\"", + "lint:test": "tslint \"test/**/*.ts\" -e \"test/**/*.test.ts\"", "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\" build/test/assert.js", diff --git a/src/tslintMulti.ts b/src/tslintMulti.ts index 99d099c5299..9aca4f95af1 100644 --- a/src/tslintMulti.ts +++ b/src/tslintMulti.ts @@ -20,11 +20,11 @@ import * as ts from "typescript"; import { DEFAULT_CONFIG, + IConfigurationFile, findConfiguration, findConfigurationPath, getRelativePath, getRulesDirectories, - IConfigurationFile, loadConfigurationFromPath, } from "./configuration"; import { EnableDisableRulesWalker } from "./enableDisableRules"; From 81dd64a24d032c846d07307055b8571c09629df1 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 4 Nov 2016 21:03:56 -0400 Subject: [PATCH 041/111] Treat one-line arrow functions like a normal statement regarding semicolons (#1680) --- src/rules/semicolonRule.ts | 4 +++- test/rules/semicolon/always/test.js.lint | 14 ++++++++++++- test/rules/semicolon/always/test.ts.fix | 13 ++++++++++-- test/rules/semicolon/always/test.ts.lint | 16 ++++++++++++--- test/rules/semicolon/enabled/test.ts.fix | 17 ++++++++++++++-- test/rules/semicolon/enabled/test.ts.lint | 20 ++++++++++++++++--- .../ignore-bound-class-methods/test.ts.fix | 13 ++++++++++-- .../ignore-bound-class-methods/test.ts.lint | 14 +++++++++++-- .../semicolon/ignore-interfaces/test.ts.fix | 13 ++++++++++-- .../semicolon/ignore-interfaces/test.ts.lint | 16 ++++++++++++--- test/rules/semicolon/never/test.ts.fix | 11 +++++++++- test/rules/semicolon/never/test.ts.lint | 20 ++++++++++++++++--- 12 files changed, 146 insertions(+), 25 deletions(-) diff --git a/src/rules/semicolonRule.ts b/src/rules/semicolonRule.ts index a175cf7b69a..e8a2bb1149b 100644 --- a/src/rules/semicolonRule.ts +++ b/src/rules/semicolonRule.ts @@ -121,7 +121,9 @@ class SemicolonWalker extends Lint.RuleWalker { public visitPropertyDeclaration(node: ts.PropertyDeclaration) { const initializer = node.initializer; - if (initializer && initializer.kind === ts.SyntaxKind.ArrowFunction) { + + // check if this is a multi-line arrow function (`[^]` in the regex matches all characters including CR & LF) + if (initializer && initializer.kind === ts.SyntaxKind.ArrowFunction && /\{[^]*\n/.test(node.getText())) { if (!this.hasOption(OPTION_IGNORE_BOUND_CLASS_METHODS)) { this.checkSemicolonAt(node, "never"); } diff --git a/test/rules/semicolon/always/test.js.lint b/test/rules/semicolon/always/test.js.lint index ee95f663803..31f9806a350 100644 --- a/test/rules/semicolon/always/test.js.lint +++ b/test/rules/semicolon/always/test.js.lint @@ -54,7 +54,19 @@ class MyClass { initializedProperty = 6 ~nil [Missing semicolon] - initializedMethodProperty = () => { return "hi"; } + public initializedMethodProperty = () => { + return "hi"; + }; + ~ [Unnecessary semicolon] + + public initializedMethodPropertyWithoutSemicolon = () => { + return "hi again"; + } + + public initializedMethodProperty1Line = () => { return "hi"; }; + + public initializedMethodPropertyWithoutSemicolon1Line = () => { return "hi again"; } + ~nil [Missing semicolon] } import {Router} from 'aurelia-router'; diff --git a/test/rules/semicolon/always/test.ts.fix b/test/rules/semicolon/always/test.ts.fix index 2789b578e7e..b4e5a93118d 100644 --- a/test/rules/semicolon/always/test.ts.fix +++ b/test/rules/semicolon/always/test.ts.fix @@ -51,8 +51,17 @@ class MyClass { private email : string; public initializedProperty = 6; - public initializedMethodProperty = () => { return "hi"; } - public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } + public initializedMethodProperty = () => { + return "hi"; + } + + public initializedMethodPropertyWithoutSemicolon = () => { + return "hi again"; + } + + public initializedMethodProperty1Line = () => { return "hi"; }; + + public initializedMethodPropertyWithoutSemicolon1Line = () => { return "hi again"; }; } interface ITest { diff --git a/test/rules/semicolon/always/test.ts.lint b/test/rules/semicolon/always/test.ts.lint index 464f70bf905..ff46b4c6637 100644 --- a/test/rules/semicolon/always/test.ts.lint +++ b/test/rules/semicolon/always/test.ts.lint @@ -71,9 +71,19 @@ class MyClass { public initializedProperty = 6 ~nil [Missing semicolon] - public initializedMethodProperty = () => { return "hi"; }; - ~ [Unnecessary semicolon] - public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } + public initializedMethodProperty = () => { + return "hi"; + }; + ~ [Unnecessary semicolon] + + public initializedMethodPropertyWithoutSemicolon = () => { + return "hi again"; + } + + public initializedMethodProperty1Line = () => { return "hi"; }; + + public initializedMethodPropertyWithoutSemicolon1Line = () => { return "hi again"; } + ~nil [Missing semicolon] } interface ITest { diff --git a/test/rules/semicolon/enabled/test.ts.fix b/test/rules/semicolon/enabled/test.ts.fix index 2789b578e7e..ec4315f624d 100644 --- a/test/rules/semicolon/enabled/test.ts.fix +++ b/test/rules/semicolon/enabled/test.ts.fix @@ -4,6 +4,10 @@ a += b; c = () => { }; +f(() => { + return 1; +}); + d = function() { }; console.log("i am adam, am i?"); @@ -51,8 +55,17 @@ class MyClass { private email : string; public initializedProperty = 6; - public initializedMethodProperty = () => { return "hi"; } - public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } + public initializedMethodProperty: mytype = () => { + return "hi"; + } + + public initializedMethodPropertyWithoutSemicolon = () => { + return "hi again"; + } + + public initializedMethodProperty1Line = () => { return "hi"; }; + + public initializedMethodPropertyWithoutSemicolon1Line = () => { return "hi again"; }; } interface ITest { diff --git a/test/rules/semicolon/enabled/test.ts.lint b/test/rules/semicolon/enabled/test.ts.lint index 464f70bf905..928d3fac49b 100644 --- a/test/rules/semicolon/enabled/test.ts.lint +++ b/test/rules/semicolon/enabled/test.ts.lint @@ -7,6 +7,10 @@ c = () => { } ~nil [Missing semicolon] +f(() => { + return 1; +}); + d = function() { } ~nil [Missing semicolon] @@ -71,9 +75,19 @@ class MyClass { public initializedProperty = 6 ~nil [Missing semicolon] - public initializedMethodProperty = () => { return "hi"; }; - ~ [Unnecessary semicolon] - public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } + public initializedMethodProperty: mytype = () => { + return "hi"; + }; + ~ [Unnecessary semicolon] + + public initializedMethodPropertyWithoutSemicolon = () => { + return "hi again"; + } + + public initializedMethodProperty1Line = () => { return "hi"; }; + + public initializedMethodPropertyWithoutSemicolon1Line = () => { return "hi again"; } + ~nil [Missing semicolon] } interface ITest { diff --git a/test/rules/semicolon/ignore-bound-class-methods/test.ts.fix b/test/rules/semicolon/ignore-bound-class-methods/test.ts.fix index 6c7c6e551d6..3123c4670c0 100644 --- a/test/rules/semicolon/ignore-bound-class-methods/test.ts.fix +++ b/test/rules/semicolon/ignore-bound-class-methods/test.ts.fix @@ -51,8 +51,17 @@ class MyClass { private email : string; public initializedProperty = 6; - public initializedMethodProperty = () => { return "hi"; }; - public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } + public initializedMethodProperty = () => { + return "hi"; + }; + + public initializedMethodPropertyWithoutSemicolon = () => { + return "hi again"; + } + + public initializedMethodProperty1Line = () => { return "hi"; }; + + public initializedMethodPropertyWithoutSemicolon1Line = () => { return "hi again"; }; } interface ITest { diff --git a/test/rules/semicolon/ignore-bound-class-methods/test.ts.lint b/test/rules/semicolon/ignore-bound-class-methods/test.ts.lint index 574b2275734..f324082c60d 100644 --- a/test/rules/semicolon/ignore-bound-class-methods/test.ts.lint +++ b/test/rules/semicolon/ignore-bound-class-methods/test.ts.lint @@ -71,8 +71,18 @@ class MyClass { public initializedProperty = 6 ~nil [Missing semicolon] - public initializedMethodProperty = () => { return "hi"; }; - public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } + public initializedMethodProperty = () => { + return "hi"; + }; + + public initializedMethodPropertyWithoutSemicolon = () => { + return "hi again"; + } + + public initializedMethodProperty1Line = () => { return "hi"; }; + + public initializedMethodPropertyWithoutSemicolon1Line = () => { return "hi again"; } + ~nil [Missing semicolon] } interface ITest { diff --git a/test/rules/semicolon/ignore-interfaces/test.ts.fix b/test/rules/semicolon/ignore-interfaces/test.ts.fix index 6420c714d03..af3c4fe6bc6 100644 --- a/test/rules/semicolon/ignore-interfaces/test.ts.fix +++ b/test/rules/semicolon/ignore-interfaces/test.ts.fix @@ -51,8 +51,17 @@ class MyClass { private email : string; public initializedProperty = 6; - public initializedMethodProperty = () => { return "hi"; } - public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } + public initializedMethodProperty = () => { + return "hi"; + } + + public initializedMethodPropertyWithoutSemicolon = () => { + return "hi again"; + } + + public initializedMethodProperty1Line = () => { return "hi"; }; + + public initializedMethodPropertyWithoutSemicolon1Line = () => { return "hi again"; }; } interface ITest { diff --git a/test/rules/semicolon/ignore-interfaces/test.ts.lint b/test/rules/semicolon/ignore-interfaces/test.ts.lint index 4edd267c806..75259aed020 100644 --- a/test/rules/semicolon/ignore-interfaces/test.ts.lint +++ b/test/rules/semicolon/ignore-interfaces/test.ts.lint @@ -71,9 +71,19 @@ class MyClass { public initializedProperty = 6 ~nil [Missing semicolon] - public initializedMethodProperty = () => { return "hi"; }; - ~ [Unnecessary semicolon] - public initializedMethodPropertyWithoutSemicolon = () => { return "hi again"; } + public initializedMethodProperty = () => { + return "hi"; + }; + ~ [Unnecessary semicolon] + + public initializedMethodPropertyWithoutSemicolon = () => { + return "hi again"; + } + + public initializedMethodProperty1Line = () => { return "hi"; }; + + public initializedMethodPropertyWithoutSemicolon1Line = () => { return "hi again"; } + ~nil [Missing semicolon] } interface ITest { diff --git a/test/rules/semicolon/never/test.ts.fix b/test/rules/semicolon/never/test.ts.fix index a6e29364501..b089d624f0c 100644 --- a/test/rules/semicolon/never/test.ts.fix +++ b/test/rules/semicolon/never/test.ts.fix @@ -50,8 +50,17 @@ class MyClass { private index : number private email : string public initializedProperty = 6 - public initializedMethodProperty = () => { return "hi" } + public initializedMethodProperty = () => { + return "hi" + } + public initializedMethodPropertyWithoutSemicolon = () => { + return "hi again" + } + + public initializedMethodProperty1Line = () => { return "hi" } + + public initializedMethodPropertyWithoutSemicolon1Line = () => { return "hi again" } } interface ITest { diff --git a/test/rules/semicolon/never/test.ts.lint b/test/rules/semicolon/never/test.ts.lint index bb4b4b02450..32fe4a65f6b 100644 --- a/test/rules/semicolon/never/test.ts.lint +++ b/test/rules/semicolon/never/test.ts.lint @@ -70,9 +70,23 @@ class MyClass { ~ [Unnecessary semicolon] private email : string public initializedProperty = 6 - public initializedMethodProperty = () => { return "hi" }; - ~ [Unnecessary semicolon] - + public initializedMethodProperty = () => { + return "hi"; + ~ [Unnecessary semicolon] + }; + ~ [Unnecessary semicolon] + + public initializedMethodPropertyWithoutSemicolon = () => { + return "hi again"; + ~ [Unnecessary semicolon] + } + + public initializedMethodProperty1Line = () => { return "hi"; }; + ~ [Unnecessary semicolon] + ~ [Unnecessary semicolon] + + public initializedMethodPropertyWithoutSemicolon1Line = () => { return "hi again"; } + ~ [Unnecessary semicolon] } interface ITest { From 533ad88d655c88149c3e1df96063b4c74034cc3e Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 4 Nov 2016 21:33:10 -0400 Subject: [PATCH 042/111] Implement fixer for ordering import declarations (#1657) --- src/rules/noUnusedVariableRule.ts | 2 +- src/rules/orderedImportsRule.ts | 177 ++++++++++++++++-- .../case-insensitive/test.ts.fix | 44 +++++ .../case-insensitive/test.ts.lint | 32 +++- .../import-sources-any/test.ts.fix | 26 +++ .../import-sources-any/test.ts.lint | 7 +- .../lowercase-first/test.ts.fix | 26 +++ .../lowercase-first/test.ts.lint | 8 +- .../named-imports-any/test.ts.fix | 26 +++ .../named-imports-any/test.ts.lint | 7 +- 10 files changed, 324 insertions(+), 31 deletions(-) create mode 100644 test/rules/ordered-imports/case-insensitive/test.ts.fix create mode 100644 test/rules/ordered-imports/import-sources-any/test.ts.fix create mode 100644 test/rules/ordered-imports/lowercase-first/test.ts.fix create mode 100644 test/rules/ordered-imports/named-imports-any/test.ts.fix diff --git a/src/rules/noUnusedVariableRule.ts b/src/rules/noUnusedVariableRule.ts index 741e4e3fd46..5e464d69629 100644 --- a/src/rules/noUnusedVariableRule.ts +++ b/src/rules/noUnusedVariableRule.ts @@ -418,7 +418,7 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker { private fail(type: string, name: string, position: number, replacements?: Lint.Replacement[]) { let fix: Lint.Fix; if (replacements && replacements.length) { - fix = new Lint.Fix("no-unused-variable", replacements); + fix = new Lint.Fix(Rule.metadata.ruleName, replacements); } this.addFailure(this.createFailure(position, name.length, Rule.FAILURE_STRING_FACTORY(type, name), fix)); } diff --git a/src/rules/orderedImportsRule.ts b/src/rules/orderedImportsRule.ts index f10eb5941ac..48868edbe2f 100644 --- a/src/rules/orderedImportsRule.ts +++ b/src/rules/orderedImportsRule.ts @@ -110,6 +110,36 @@ function findUnsortedPair(xs: ts.Node[], transform: (x: string) => string): [ts. return null; } +function compare(a: string, b: string) { + const isLow = (value: string) => { + return [".", "/"].some((x) => value[0] === x); + }; + if (isLow(a) && !isLow(b)) { + return 1; + } else if (!isLow(a) && isLow(b)) { + return -1; + } else if (a > b) { + return 1; + } else if (a < b) { + return -1; + } + return 0; +} + +function removeQuotes(value: string) { + // strip out quotes + if (value && value.length > 1 && (value[0] === "'" || value[0] === "\"")) { + value = value.substr(1, value.length - 2); + } + return value; +} + +function sortByKey(xs: T[], getSortKey: (x: T) => string): T[] { + return xs.slice().sort((a, b) => { + return compare(getSortKey(a), getSortKey(b)); + }); +} + // Transformations to apply to produce the desired ordering of imports. // The imports must be lexicographically sorted after applying the transform. const TRANSFORMS: {[ordering: string]: (x: string) => string} = { @@ -120,8 +150,9 @@ const TRANSFORMS: {[ordering: string]: (x: string) => string} = { }; class OrderedImportsWalker extends Lint.RuleWalker { - // This gets reset after every blank line. - private lastImportSource: string = null; + private currentImportsBlock: ImportsBlock = new ImportsBlock(); + // keep a reference to the last Fix object so when the entire block is replaced, the replacement can be added + private lastFix: Lint.Fix; private importSourcesOrderTransform: (x: string) => string = null; private namedImportsOrderTransform: (x: string) => string = null; @@ -137,13 +168,17 @@ class OrderedImportsWalker extends Lint.RuleWalker { // e.g. "import Foo from "./foo";" public visitImportDeclaration(node: ts.ImportDeclaration) { - const source = this.importSourcesOrderTransform(node.moduleSpecifier.getText()); + let source = node.moduleSpecifier.getText(); + source = removeQuotes(source); + source = this.importSourcesOrderTransform(source); + const previousSource = this.currentImportsBlock.getLastImportSource(); + this.currentImportsBlock.addImportDeclaration(node, source); - if (this.lastImportSource && source < this.lastImportSource) { - this.addFailure(this.createFailure(node.getStart(), node.getWidth(), - Rule.IMPORT_SOURCES_UNORDERED)); + if (previousSource && compare(source, previousSource) === -1) { + this.lastFix = new Lint.Fix(Rule.metadata.ruleName, []); + const ruleFailure = this.createFailure(node.getStart(), node.getWidth(), Rule.IMPORT_SOURCES_UNORDERED, this.lastFix); + this.addFailure(ruleFailure); } - this.lastImportSource = source; super.visitImportDeclaration(node); } @@ -156,25 +191,135 @@ class OrderedImportsWalker extends Lint.RuleWalker { const pair = findUnsortedPair(imports, this.namedImportsOrderTransform); if (pair !== null) { const [a, b] = pair; - this.addFailure( - this.createFailure( - a.getStart(), - b.getEnd() - a.getStart(), - Rule.NAMED_IMPORTS_UNORDERED)); + const sortedDeclarations = sortByKey(imports, (x) => this.namedImportsOrderTransform(x.getText())).map((x) => x.getText()); + // replace in reverse order to preserve earlier offsets + for (let i = imports.length - 1; i >= 0; i--) { + const start = imports[i].getStart(); + const length = imports[i].getText().length; + + // replace the named imports one at a time to preserve whitespace + this.currentImportsBlock.replaceNamedImports(start, length, sortedDeclarations[i]); + } + + this.lastFix = new Lint.Fix(Rule.metadata.ruleName, []); + const ruleFailure = this.createFailure( + a.getStart(), + b.getEnd() - a.getStart(), + Rule.NAMED_IMPORTS_UNORDERED, + this.lastFix); + this.addFailure(ruleFailure); } super.visitNamedImports(node); } - // Check for a blank line, in which case we should reset the import ordering. + // keep reading the block of import declarations until the block ends, then replace the entire block + // this allows the reorder of named imports to work well with reordering lines public visitNode(node: ts.Node) { const prefixLength = node.getStart() - node.getFullStart(); const prefix = node.getFullText().slice(0, prefixLength); + const hasBlankLine = prefix.indexOf("\n\n") >= 0 || prefix.indexOf("\r\n\r\n") >= 0; + const notImportDeclaration = node.parent != null + && node.parent.kind === ts.SyntaxKind.SourceFile + && node.kind !== ts.SyntaxKind.ImportDeclaration; - if (prefix.indexOf("\n\n") >= 0 || - prefix.indexOf("\r\n\r\n") >= 0) { - this.lastImportSource = null; + if (hasBlankLine || notImportDeclaration) { + // end of block + if (this.lastFix != null) { + const replacement = this.currentImportsBlock.getReplacement(); + if (replacement != null) { + this.lastFix.replacements.push(replacement); + } + this.lastFix = null; + } + this.currentImportsBlock = new ImportsBlock(); } super.visitNode(node); } } + +interface ImportDeclaration { + node: ts.ImportDeclaration; + nodeEndOffset: number; // end position of node within source file + nodeStartOffset: number; // start position of node within source file + text: string; // initialized with original import text; modified if the named imports are reordered + sourcePath: string; +} + +class ImportsBlock { + private importDeclarations: ImportDeclaration[] = []; + + public addImportDeclaration(node: ts.ImportDeclaration, sourcePath: string) { + const start = this.getStartOffset(node); + const end = this.getEndOffset(node); + const text = node.getSourceFile().text.substring(start, end); + + if (start > node.getStart() || end === 0) { + // skip block if any statements don't end with a newline to simplify implementation + this.importDeclarations = []; + return; + } + + this.importDeclarations.push({ + node, + nodeEndOffset: end, + nodeStartOffset: start, + sourcePath, + text, + }); + } + + // replaces the named imports on the most recent import declaration + public replaceNamedImports(fileOffset: number, length: number, replacement: string) { + const importDeclaration = this.getLastImportDeclaration(); + if (importDeclaration == null) { + // nothing to replace. This can happen if the block is skipped + return; + } + + const start = fileOffset - importDeclaration.nodeStartOffset; + if (start < 0 || start + length > importDeclaration.node.getEnd()) { + throw "Unexpected named import position"; + } + + const initialText = importDeclaration.text; + importDeclaration.text = initialText.substring(0, start) + replacement + initialText.substring(start + length); + } + + public getLastImportSource() { + if (this.importDeclarations.length === 0) { + return null; + } + return this.getLastImportDeclaration().sourcePath; + } + + // creates a Lint.Replacement object with ordering fixes for the entire block + public getReplacement() { + if (this.importDeclarations.length === 0) { + return null; + } + const sortedDeclarations = sortByKey(this.importDeclarations.slice(), (x) => x.sourcePath); + const fixedText = sortedDeclarations.map((x) => x.text).join(""); + const start = this.importDeclarations[0].nodeStartOffset; + const end = this.getLastImportDeclaration().nodeEndOffset; + return new Lint.Replacement(start, end - start, fixedText); + } + + // gets the offset immediately after the end of the previous declaration to include comment above + private getStartOffset(node: ts.ImportDeclaration) { + if (this.importDeclarations.length === 0) { + return node.getStart(); + } + return this.getLastImportDeclaration().nodeEndOffset; + } + + // gets the offset of the end of the import's line, including newline, to include comment to the right + private getEndOffset(node: ts.ImportDeclaration) { + let endLineOffset = node.getSourceFile().text.indexOf("\n", node.end) + 1; + return endLineOffset; + } + + private getLastImportDeclaration() { + return this.importDeclarations[this.importDeclarations.length - 1]; + } +} diff --git a/test/rules/ordered-imports/case-insensitive/test.ts.fix b/test/rules/ordered-imports/case-insensitive/test.ts.fix new file mode 100644 index 00000000000..fe75ec2d0f2 --- /dev/null +++ b/test/rules/ordered-imports/case-insensitive/test.ts.fix @@ -0,0 +1,44 @@ +// Named imports should be alphabetized. +import {A, B} from 'foo'; +import {A, B} from 'foo'; // failure + +// Case is irrelevant for named import ordering. +import {A, bz, C} from 'foo'; // failure +import {A, b, C} from 'zfoo'; + +import {g} from "y"; // failure +import { + a as d, + b as c, +} from "z"; + +// Import sources should be alphabetized. +import * as bar from 'bar'; +import * as foo from 'foo'; + +import * as abc from 'abc'; +import * as bar from 'bar'; // failure +import * as foo from 'foo'; + +// ignore quotes +import * as bar from 'bar'; +import * as foo from "foo"; + +import * as bar from "bar"; +import * as foo from 'foo'; + +// Case is irrelevant for source import ordering. +import {A, B} from 'Bar'; +import {A, B} from 'baz'; +import {A, B} from 'Foo'; // should not fail + +// Other styles of import statements. +import someDefault from "module"; +import "something"; +import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; + +// do not fix cases where a newline is missing +import * as foo from 'foo'; import * as bar from 'bar'; + +import * as foo from 'foo'; +import * as bar from 'bar'; \ No newline at end of file diff --git a/test/rules/ordered-imports/case-insensitive/test.ts.lint b/test/rules/ordered-imports/case-insensitive/test.ts.lint index bd7ee497234..441d926d90d 100644 --- a/test/rules/ordered-imports/case-insensitive/test.ts.lint +++ b/test/rules/ordered-imports/case-insensitive/test.ts.lint @@ -4,10 +4,19 @@ import {B, A} from 'foo'; // failure ~~~~ [ordered-imports] // Case is irrelevant for named import ordering. -import {A, b, C} from 'foo'; -import {b, A, C} from 'foo'; // failure - ~~~~ [ordered-imports] +import {A, b, C} from 'zfoo'; +import {bz, A, C} from 'foo'; // failure +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] + ~~~~~ [Named imports must be alphabetized.] +import { + b as c, + ~~~~~~~ + a as d, +~~~~~~~~~~ [Named imports must be alphabetized.] +} from "z"; +import {g} from "y"; // failure +~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] // Import sources should be alphabetized. import * as bar from 'bar'; @@ -18,6 +27,13 @@ import * as foo from 'foo'; import * as bar from 'bar'; // failure ~~~~~~~~~~~~~~~~~~~~~~~~~~~ [ordered-sources] +// ignore quotes +import * as bar from 'bar'; +import * as foo from "foo"; + +import * as bar from "bar"; +import * as foo from 'foo'; + // Case is irrelevant for source import ordering. import {A, B} from 'Bar'; import {A, B} from 'baz'; @@ -26,7 +42,15 @@ import {A, B} from 'Foo'; // should not fail // Other styles of import statements. import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; import someDefault from "module"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] import "something"; +// do not fix cases where a newline is missing +import * as foo from 'foo'; import * as bar from 'bar'; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] + +import * as foo from 'foo'; +import * as bar from 'bar'; +~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] [ordered-imports]: Named imports must be alphabetized. -[ordered-sources]: Import sources within a group must be alphabetized. +[ordered-sources]: Import sources within a group must be alphabetized. \ No newline at end of file diff --git a/test/rules/ordered-imports/import-sources-any/test.ts.fix b/test/rules/ordered-imports/import-sources-any/test.ts.fix new file mode 100644 index 00000000000..a523be9f420 --- /dev/null +++ b/test/rules/ordered-imports/import-sources-any/test.ts.fix @@ -0,0 +1,26 @@ +// Named imports should be alphabetized. +import {A, B} from 'foo'; +import {A, B} from 'foo'; // failure + +// Case is irrelevant for named import ordering. +import {A, b, C} from 'zfoo'; +import {A, bz, C} from 'foo'; // failure + +// Import sources don't need to be alphabetized. +import * as bar from 'bar'; +import * as foo from 'foo'; + +import * as abc from 'abc'; +import * as foo from 'foo'; +import * as bar from 'bar'; // should not fail + +// Case is irrelevant for source import ordering. +import {A, B} from 'Bar'; +import {A, B} from 'baz'; +import {A, B} from 'Foo'; // should not fail + +// Other styles of import statements. +import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; +import someDefault from "module"; +import "something"; + diff --git a/test/rules/ordered-imports/import-sources-any/test.ts.lint b/test/rules/ordered-imports/import-sources-any/test.ts.lint index ab21388c54c..2e6ab32acad 100644 --- a/test/rules/ordered-imports/import-sources-any/test.ts.lint +++ b/test/rules/ordered-imports/import-sources-any/test.ts.lint @@ -4,10 +4,9 @@ import {B, A} from 'foo'; // failure ~~~~ [ordered-imports] // Case is irrelevant for named import ordering. -import {A, b, C} from 'foo'; -import {b, A, C} from 'foo'; // failure - ~~~~ [ordered-imports] - +import {A, b, C} from 'zfoo'; +import {bz, A, C} from 'foo'; // failure + ~~~~~ [ordered-imports] // Import sources don't need to be alphabetized. import * as bar from 'bar'; diff --git a/test/rules/ordered-imports/lowercase-first/test.ts.fix b/test/rules/ordered-imports/lowercase-first/test.ts.fix new file mode 100644 index 00000000000..324ec13d968 --- /dev/null +++ b/test/rules/ordered-imports/lowercase-first/test.ts.fix @@ -0,0 +1,26 @@ +// Named imports should be alphabetized. +import {A, B} from 'foo'; +import {A, B} from 'foo'; // failure + +// Lowercase comes before uppercase. +import {bz, A, C} from 'foo'; // failure +import {b, A, C} from 'zfoo'; + +// Import sources should be alphabetized. +import * as bar from 'bar'; +import * as foo from 'foo'; + +import * as abc from 'abc'; +import * as bar from 'bar'; // failure +import * as foo from 'foo'; + +// Lowercase comes before uppercase +import {A, B} from 'baz'; +import {A, B} from 'Bar'; +import {A, B} from 'Foo'; + +// Other styles of import statements. +import someDefault from "module"; +import "something"; +import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; + diff --git a/test/rules/ordered-imports/lowercase-first/test.ts.lint b/test/rules/ordered-imports/lowercase-first/test.ts.lint index ef8de7ea134..1ae184b3ba7 100644 --- a/test/rules/ordered-imports/lowercase-first/test.ts.lint +++ b/test/rules/ordered-imports/lowercase-first/test.ts.lint @@ -4,9 +4,10 @@ import {B, A} from 'foo'; // failure ~~~~ [ordered-imports] // Lowercase comes before uppercase. -import {b, A, C} from 'foo'; -import {A, b, C} from 'foo'; // failure - ~~~~ [ordered-imports] +import {A, b, C} from 'zfoo'; + ~~~~ [Named imports must be alphabetized.] +import {bz, A, C} from 'foo'; // failure +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] // Import sources should be alphabetized. import * as bar from 'bar'; @@ -26,6 +27,7 @@ import {A, B} from 'Foo'; // Other styles of import statements. import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; import someDefault from "module"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] import "something"; [ordered-imports]: Named imports must be alphabetized. diff --git a/test/rules/ordered-imports/named-imports-any/test.ts.fix b/test/rules/ordered-imports/named-imports-any/test.ts.fix new file mode 100644 index 00000000000..9e4e0e93811 --- /dev/null +++ b/test/rules/ordered-imports/named-imports-any/test.ts.fix @@ -0,0 +1,26 @@ +// Named imports do not need to be alphabetized. +import {A, B} from 'foo'; +import {B, A} from 'foo'; // should not fail + +// Case is irrelevant for named import ordering. +import {bz, A, C} from 'foo'; // should not fail +import {A, b, C} from 'zfoo'; + +// Import sources should be alphabetized. +import * as bar from 'bar'; +import * as foo from 'foo'; + +import * as abc from 'abc'; +import * as bar from 'bar'; // failure +import * as foo from 'foo'; + +// Case is irrelevant for source import ordering. +import {A, B} from 'Bar'; +import {A, B} from 'baz'; +import {A, B} from 'Foo'; // should not fail + +// Other styles of import statements. +import someDefault from "module"; +import "something"; +import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; + diff --git a/test/rules/ordered-imports/named-imports-any/test.ts.lint b/test/rules/ordered-imports/named-imports-any/test.ts.lint index 2e55118821b..e6707e9d62d 100644 --- a/test/rules/ordered-imports/named-imports-any/test.ts.lint +++ b/test/rules/ordered-imports/named-imports-any/test.ts.lint @@ -3,9 +3,9 @@ import {A, B} from 'foo'; import {B, A} from 'foo'; // should not fail // Case is irrelevant for named import ordering. -import {A, b, C} from 'foo'; -import {b, A, C} from 'foo'; // should not fail - +import {A, b, C} from 'zfoo'; +import {bz, A, C} from 'foo'; // should not fail +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] // Import sources should be alphabetized. import * as bar from 'bar'; @@ -24,6 +24,7 @@ import {A, B} from 'Foo'; // should not fail // Other styles of import statements. import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; import someDefault from "module"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] import "something"; [ordered-imports]: Named imports must be alphabetized. From 7bf4597a34d5e8700e416ad0e6e889144a11c682 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Sat, 5 Nov 2016 20:40:48 -0400 Subject: [PATCH 043/111] Fix js import ordering tests (#1689) --- test/rules/ordered-imports/case-insensitive/test.js.lint | 3 ++- test/rules/ordered-imports/lowercase-first/test.js.lint | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/rules/ordered-imports/case-insensitive/test.js.lint b/test/rules/ordered-imports/case-insensitive/test.js.lint index bd7ee497234..2efabb17c31 100644 --- a/test/rules/ordered-imports/case-insensitive/test.js.lint +++ b/test/rules/ordered-imports/case-insensitive/test.js.lint @@ -25,7 +25,8 @@ import {A, B} from 'Foo'; // should not fail // Other styles of import statements. import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; -import someDefault from "module"; +import someDefault from "module"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] import "something"; [ordered-imports]: Named imports must be alphabetized. diff --git a/test/rules/ordered-imports/lowercase-first/test.js.lint b/test/rules/ordered-imports/lowercase-first/test.js.lint index ef8de7ea134..eff6e21b639 100644 --- a/test/rules/ordered-imports/lowercase-first/test.js.lint +++ b/test/rules/ordered-imports/lowercase-first/test.js.lint @@ -25,7 +25,8 @@ import {A, B} from 'Foo'; // Other styles of import statements. import someDefault, {nameA, nameBReallyLong as anotherName} from "./wherever"; -import someDefault from "module"; +import someDefault from "module"; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Import sources within a group must be alphabetized.] import "something"; [ordered-imports]: Named imports must be alphabetized. From f425858cbab50f919b97185e4207b5d84628fdf3 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Sat, 5 Nov 2016 21:59:42 -0400 Subject: [PATCH 044/111] Update .vscode/tasks.json to use npm scripts (#1691) --- .vscode/tasks.json | 55 ++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 5a7f3b3425a..b88873ff328 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,19 +1,36 @@ -// Available variables which can be used inside of strings. -// ${workspaceRoot}: the root folder of the team -// ${file}: the current opened file -// ${fileBasename}: the current opened file's basename -// ${fileDirname}: the current opened file's dirname -// ${fileExtname}: the current opened file's extension -// ${cwd}: the current working directory of the spawned process - -// A task runner that calls scripts/tsc-wrapper.js. The wrapper script traverses -// up the file system until a valid `tsconfig.json` is found, and runs `tsc` from -// node_modules with that path as the root -{ - "version": "0.1.0", - "command": "${workspaceRoot}/scripts/tsc-wrapper.js", - "isShellCommand": true, - "showOutput": "silent", - "args": ["${workspaceRoot}", "${fileDirname}"], - "problemMatcher": "$tsc" -} +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "0.1.0", + "command": "npm", + "isShellCommand": true, + "showOutput": "always", + "suppressTaskName": true, + "tasks": [ + { + "taskName": "install", + "args": ["install"] + }, + { + "taskName": "update", + "args": ["update"] + }, + { + "taskName": "test", + "args": ["run", "test"] + }, + { + "taskName": "test-rules", + "args": ["run", "test:rules"] + }, + { + "taskName": "compile", + "args": ["run", "compile"] + }, + { + "taskName": "verify", + "args": ["run", "verify"] + } + ] +} + From 1b76b85f17fbda8ffb1f63d2cd7c48d4f3aa1be1 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Sat, 5 Nov 2016 22:00:58 -0400 Subject: [PATCH 045/111] in tsconfig, set sourceMap=true for debugging (#1690) --- .npmignore | 1 + src/tsconfig.json | 2 +- test/tsconfig.json | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.npmignore b/.npmignore index fe6cf8753f5..209a3c532a6 100644 --- a/.npmignore +++ b/.npmignore @@ -18,3 +18,4 @@ tslint.json /src/ /test/ tscommand*.txt +*.js.map diff --git a/src/tsconfig.json b/src/tsconfig.json index 797e7d67879..6e232cb680d 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -6,7 +6,7 @@ "noUnusedParameters": true, "noUnusedLocals": true, "declaration": true, - "sourceMap": false, + "sourceMap": true, "target": "es5", "outDir": "../lib" } diff --git a/test/tsconfig.json b/test/tsconfig.json index d672d8b5146..29f6a5b36b6 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -5,7 +5,7 @@ "noImplicitAny": true, "noUnusedParameters": true, "noUnusedLocals": true, - "sourceMap": false, + "sourceMap": true, "target": "es5", "outDir": "../build" }, From 581339e9bc47bd9a04a551fd454d1f8c6783f7d7 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Sat, 5 Nov 2016 23:49:21 -0400 Subject: [PATCH 046/111] Add .vscode/launch.json for debugging in VS Code (#1692) Undo changes to lib/ and use build/ to debug Use tsc in tasks.json instead of npm scripts because of better integration with VS Code --- .npmignore | 1 - .vscode/launch.json | 68 +++++++++++++++++++++++++++++++++++++++++++++ .vscode/tasks.json | 37 ++++-------------------- src/tsconfig.json | 2 +- 4 files changed, 75 insertions(+), 33 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.npmignore b/.npmignore index 209a3c532a6..fe6cf8753f5 100644 --- a/.npmignore +++ b/.npmignore @@ -18,4 +18,3 @@ tslint.json /src/ /test/ tscommand*.txt -*.js.map diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000000..d1c1650a779 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,68 @@ +{ + "version": "0.1.0", + "configurations": [ + { + "name": "Debug CLI", + "type": "node", + "request": "launch", + "program": "${workspaceRoot}/build/src/tslint-cli.js", + "stopOnEntry": false, + "args": [], + "cwd": "${workspaceRoot}", + "preLaunchTask": "tsc", + "runtimeExecutable": null, + "runtimeArgs": [ + "--nolazy" + ], + "env": { + "NODE_ENV": "development" + }, + "console": "internalConsole", + "sourceMaps": true, + "outFiles": [], + "outDir": "${workspaceRoot}/build" + }, + { + "name": "Debug Mocha Tests", + "type": "node", + "request": "launch", + "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", + "stopOnEntry": false, + "args": ["--reporter", "spec", "--colors", "--no-timeouts", "build/test/**/*Tests.js", "build/test/assert.js"], + "cwd": "${workspaceRoot}", + "preLaunchTask": "tsc", + "runtimeExecutable": null, + "runtimeArgs": [ + "--nolazy" + ], + "env": { + "NODE_ENV": "development" + }, + "console": "internalConsole", + "sourceMaps": true, + "outFiles": [], + "outDir": "${workspaceRoot}/build" + }, + { + "name": "Debug Rule Tests", + "type": "node", + "request": "launch", + "program": "${workspaceRoot}/test/ruleTestRunner.ts", + "stopOnEntry": false, + "args": ["run", "test"], + "cwd": "${workspaceRoot}", + "preLaunchTask": "tsc", + "runtimeExecutable": null, + "runtimeArgs": [ + "--nolazy" + ], + "env": { + "NODE_ENV": "development" + }, + "console": "internalConsole", + "sourceMaps": true, + "outFiles": [], + "outDir": "${workspaceRoot}/build" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b88873ff328..f3aafc3f3d3 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -2,35 +2,10 @@ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "0.1.0", - "command": "npm", + "command": "tsc", "isShellCommand": true, - "showOutput": "always", - "suppressTaskName": true, - "tasks": [ - { - "taskName": "install", - "args": ["install"] - }, - { - "taskName": "update", - "args": ["update"] - }, - { - "taskName": "test", - "args": ["run", "test"] - }, - { - "taskName": "test-rules", - "args": ["run", "test:rules"] - }, - { - "taskName": "compile", - "args": ["run", "compile"] - }, - { - "taskName": "verify", - "args": ["run", "verify"] - } - ] -} - + "args": ["-w", "-p", "test"], + "showOutput": "silent", + "isWatching": true, + "problemMatcher": "$tsc-watch" +} \ No newline at end of file diff --git a/src/tsconfig.json b/src/tsconfig.json index 6e232cb680d..797e7d67879 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -6,7 +6,7 @@ "noUnusedParameters": true, "noUnusedLocals": true, "declaration": true, - "sourceMap": true, + "sourceMap": false, "target": "es5", "outDir": "../lib" } From 1353c9f7c2d5e68b37114915bc8bb3299d31b0b8 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Mon, 7 Nov 2016 06:48:20 -0800 Subject: [PATCH 047/111] Mentioned git --config settings in the README (#1687) Also replaced `grunt` with some new `npm run` commands. --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index eb297d9b95d..af5f00985ac 100644 --- a/README.md +++ b/README.md @@ -373,9 +373,10 @@ Development #### Quick Start ```bash -git clone git@github.com:palantir/tslint.git +git clone git@github.com:palantir/tslint.git --config core.autocrlf=input --config core.eol=lf npm install -grunt +npm run compile +npm run test ``` #### `next` branch From 6b70dda9fca84740679889f58a317501da559be0 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 7 Nov 2016 09:48:58 -0500 Subject: [PATCH 048/111] Remove last mention of grunt in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af5f00985ac..6a78262e40d 100644 --- a/README.md +++ b/README.md @@ -392,7 +392,7 @@ Creating a new release 1. Bump the version number in `package.json` and `src/tslintMulti.ts` 2. Add release notes in `CHANGELOG.md` -3. Run `grunt` to build the latest sources +3. `npm run verify` to build the latest sources 4. Commit with message `Prepare release ` 5. Run `npm publish` 6. Create a git tag for the new release and push it ([see existing tags here](https://github.com/palantir/tslint/tags)) From d8a5dda71f6f4aab910179ba2cf826b09591b6f1 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Tue, 8 Nov 2016 11:52:49 -0500 Subject: [PATCH 049/111] Use --fix instead of -t applyFixes (#1697) --- docs/_data/formatters.json | 7 - docs/formatters/applyFixes/index.html | 14 -- src/formatters/applyFixesFormatter.ts | 35 ----- src/formatters/proseFormatter.ts | 26 +++- src/language/formatter/formatter.ts | 7 +- src/lint.ts | 3 + src/tslint-cli.ts | 7 + src/tslint.ts | 1 + src/tslintMulti.ts | 139 +++++++++++------- test/configurationTests.ts | 16 +- test/executable/executableTests.ts | 17 +++ .../multiple-fixes.test.ts | 2 + test/files/multiple-fixes-test/tslint.json | 6 + test/formatters/proseFormatterTests.ts | 22 +++ test/utils.ts | 16 ++ 15 files changed, 193 insertions(+), 125 deletions(-) delete mode 100644 docs/formatters/applyFixes/index.html delete mode 100644 src/formatters/applyFixesFormatter.ts create mode 100644 test/files/multiple-fixes-test/multiple-fixes.test.ts create mode 100644 test/files/multiple-fixes-test/tslint.json diff --git a/docs/_data/formatters.json b/docs/_data/formatters.json index 83a81e7bf9d..c3541f5d75c 100644 --- a/docs/_data/formatters.json +++ b/docs/_data/formatters.json @@ -1,11 +1,4 @@ [ - { - "formatterName": "applyFixes", - "description": "Automatically fixes lint failures.", - "descriptionDetails": "\nModifies source files and applies fixes for lint failures where possible. Changes\nshould be tested as not all fixes preserve semantics.", - "sample": "\nAll done. Remember to test the changes, as not all fixes preserve semantics.", - "consumer": "machine" - }, { "formatterName": "checkstyle", "description": "Formats errors as through they were Checkstyle output.", diff --git a/docs/formatters/applyFixes/index.html b/docs/formatters/applyFixes/index.html deleted file mode 100644 index b860632660b..00000000000 --- a/docs/formatters/applyFixes/index.html +++ /dev/null @@ -1,14 +0,0 @@ ---- -formatterName: applyFixes -description: Automatically fixes lint failures. -descriptionDetails: |- - - Modifies source files and applies fixes for lint failures where possible. Changes - should be tested as not all fixes preserve semantics. -sample: |- - - All done. Remember to test the changes, as not all fixes preserve semantics. -consumer: machine -layout: formatter -title: 'Formatter: applyFixes' ---- \ No newline at end of file diff --git a/src/formatters/applyFixesFormatter.ts b/src/formatters/applyFixesFormatter.ts deleted file mode 100644 index e012ef40ad4..00000000000 --- a/src/formatters/applyFixesFormatter.ts +++ /dev/null @@ -1,35 +0,0 @@ -import {AbstractFormatter} from "../language/formatter/abstractFormatter"; -import {IFormatterMetadata} from "../language/formatter/formatter"; -import {Fix, RuleFailure} from "../language/rule/rule"; -import * as Utils from "../utils"; -import * as fs from "fs"; - -export class Formatter extends AbstractFormatter { - /* tslint:disable:object-literal-sort-keys */ - public static metadata: IFormatterMetadata = { - formatterName: "applyFixes", - description: "Automatically fixes lint failures.", - descriptionDetails: Utils.dedent` - Modifies source files and applies fixes for lint failures where possible. Changes - should be tested as not all fixes preserve semantics.`, - sample: Utils.dedent` - All done. Remember to test the changes, as not all fixes preserve semantics.`, - consumer: "machine", - }; - /* tslint:enable:object-literal-sort-keys */ - - public format(failures: RuleFailure[]): string { - const files: {[file: string]: boolean} = {}; - failures.map(f => files[f.getFileName()] = true); - const log: string[] = []; - for (const file of Object.keys(files)) { - log.push(`Applying fixes to ${file}`); - let content = fs.readFileSync(file, {encoding: "utf-8"}); - const fixes = failures.filter(f => f.getFileName() === file).map(f => f.getFix()).filter(f => !!f); - content = Fix.applyAll(content, fixes); - fs.writeFileSync(file, content, {encoding: "utf-8"}); - } - log.push("All done. Remember to test the changes, as not all fixes preserve semantics."); - return log.join("\n") + "\n"; - } -} diff --git a/src/formatters/proseFormatter.ts b/src/formatters/proseFormatter.ts index 1331c9248ab..b70024a4fa0 100644 --- a/src/formatters/proseFormatter.ts +++ b/src/formatters/proseFormatter.ts @@ -29,12 +29,30 @@ export class Formatter extends AbstractFormatter { }; /* tslint:enable:object-literal-sort-keys */ - public format(failures: RuleFailure[]): string { - if (failures.length === 0) { + public format(failures: RuleFailure[], fixes?: RuleFailure[]): string { + if (failures.length === 0 && (!fixes || fixes.length === 0)) { return ""; } - const outputLines = failures.map((failure: RuleFailure) => { + let fixLines: string[] = []; + if (fixes) { + let perFileFixes: { [fileName: string]: number } = {}; + for (const fix of fixes) { + if (perFileFixes[fix.getFileName()] == null) { + perFileFixes[fix.getFileName()] = 1; + } else { + perFileFixes[fix.getFileName()]++; + } + } + + Object.keys(perFileFixes).forEach((fixedFile: string) => { + const fixCount = perFileFixes[fixedFile]; + fixLines.push(`Fixed ${fixCount} error(s) in ${fixedFile}`); + }); + fixLines.push(""); // add a blank line between fixes and failures + } + + let errorLines = failures.map((failure: RuleFailure) => { const fileName = failure.getFileName(); const failureString = failure.getFailure(); @@ -44,6 +62,6 @@ export class Formatter extends AbstractFormatter { return `${fileName}${positionTuple}: ${failureString}`; }); - return outputLines.join("\n") + "\n"; + return fixLines.concat(errorLines).join("\n") + "\n"; } } diff --git a/src/language/formatter/formatter.ts b/src/language/formatter/formatter.ts index 50b4de7c9e0..7801a9a510b 100644 --- a/src/language/formatter/formatter.ts +++ b/src/language/formatter/formatter.ts @@ -47,5 +47,10 @@ export interface IFormatterMetadata { export type ConsumerType = "human" | "machine"; export interface IFormatter { - format(failures: RuleFailure[]): string; + /** + * Formats linter results + * @param {RuleFailure[]} failures Linter errors that were not fixed + * @param {RuleFailure[]} fixes Fixed linter errors. Available when the `--fix` argument is used on the command line + */ + format(failures: RuleFailure[], fixes?: RuleFailure[]): string; } diff --git a/src/lint.ts b/src/lint.ts index 35f3a1af219..c96ab319bb5 100644 --- a/src/lint.ts +++ b/src/lint.ts @@ -42,6 +42,7 @@ export var Utils = utils; export interface LintResult { failureCount: number; failures: RuleFailure[]; + fixes?: RuleFailure[]; format: string | Function; output: string; } @@ -55,11 +56,13 @@ export interface ILinterOptionsRaw { export interface ILinterOptions extends ILinterOptionsRaw { configuration: any; + fix: boolean; formatter: string | Function; rulesDirectory: string | string[]; } export interface IMultiLinterOptions { + fix: boolean; formatter?: string | Function; formattersDirectory?: string; rulesDirectory?: string | string[]; diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index f358dc672f3..cf5f07ec296 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -50,6 +50,9 @@ let processed = optimist alias: "exclude", describe: "exclude globs from path expansion", }, + fix: { + describe: "Fixes linting errors for select rules. This may overwrite linted files", + }, force: { describe: "return status code 0 even if there are lint errors", type: "boolean", @@ -152,6 +155,9 @@ tslint accepts the following commandline options: This option can be supplied multiple times if you need multiple globs to indicate which files to exclude. + --fix: + Fixes linting errors for select rules. This may overwrite linted files. + --force: Return status code 0 even if there are any lint errors. Useful while running as npm script. @@ -220,6 +226,7 @@ const possibleConfigAbsolutePath = argv.c != null ? path.resolve(argv.c) : null; const processFiles = (files: string[], program?: ts.Program) => { const linter = new Linter({ + fix: argv.fix, formatter: argv.t, formattersDirectory: argv.s || "", rulesDirectory: argv.r || "", diff --git a/src/tslint.ts b/src/tslint.ts index 075eb51bc75..da9b53b106d 100644 --- a/src/tslint.ts +++ b/src/tslint.ts @@ -75,6 +75,7 @@ class Linter { return { configuration: configuration || DEFAULT_CONFIG, + fix: false, formatter: formatter || "prose", formattersDirectory, rulesDirectory: arrayify(rulesDirectory).concat(arrayify(configuration.rulesDirectory)), diff --git a/src/tslintMulti.ts b/src/tslintMulti.ts index 9aca4f95af1..2f9ef86232e 100644 --- a/src/tslintMulti.ts +++ b/src/tslintMulti.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { existsSync } from "fs"; +import * as fs from "fs"; import * as ts from "typescript"; import { @@ -30,10 +30,10 @@ import { import { EnableDisableRulesWalker } from "./enableDisableRules"; import { findFormatter } from "./formatterLoader"; import { IFormatter } from "./language/formatter/formatter"; -import { RuleFailure } from "./language/rule/rule"; +import {Fix, IRule, RuleFailure} from "./language/rule/rule"; import { TypedRule } from "./language/rule/typedRule"; -import { getSourceFile } from "./language/utils"; -import { IMultiLinterOptions, IRule, LintResult } from "./lint"; +import * as utils from "./language/utils"; +import { IMultiLinterOptions, LintResult } from "./lint"; import { loadRules } from "./ruleLoader"; import { arrayify } from "./utils"; @@ -49,6 +49,7 @@ class MultiLinter { public static loadConfigurationFromPath = loadConfigurationFromPath; private failures: RuleFailure[] = []; + private fixes: RuleFailure[] = []; /** * Creates a TypeScript program object from a tsconfig.json file path and optional project directory. @@ -65,7 +66,7 @@ class MultiLinter { const { config } = ts.readConfigFile(configFile, ts.sys.readFile); const parseConfigHost = { - fileExists: existsSync, + fileExists: fs.existsSync, readDirectory: ts.sys.readDirectory, useCaseSensitiveFileNames: true, }; @@ -89,54 +90,35 @@ class MultiLinter { } public lint(fileName: string, source?: string, configuration: IConfigurationFile = DEFAULT_CONFIG): void { - let sourceFile: ts.SourceFile; - if (this.program) { - sourceFile = this.program.getSourceFile(fileName); - // check if the program has been type checked - if (sourceFile && !("resolvedModules" in sourceFile)) { - throw new Error("Program must be type checked before linting"); + const enabledRules = this.getEnabledRules(fileName, source, configuration); + let sourceFile = this.getSourceFile(fileName, source); + let hasLinterRun = false; + + if (this.options.fix) { + this.fixes = []; + for (let rule of enabledRules) { + let fileFailures = this.applyRule(rule, sourceFile); + const fixes = fileFailures.map(f => f.getFix()).filter(f => !!f); + source = fs.readFileSync(fileName, { encoding: "utf-8" }); + if (fixes.length > 0) { + this.fixes = this.fixes.concat(fileFailures); + source = Fix.applyAll(source, fixes); + fs.writeFileSync(fileName, source, { encoding: "utf-8" }); + + // reload AST if file is modified + sourceFile = this.getSourceFile(fileName, source); + } + this.failures = this.failures.concat(fileFailures); } - } else { - sourceFile = getSourceFile(fileName, source); + hasLinterRun = true; } - if (sourceFile === undefined) { - throw new Error(`Invalid source file: ${fileName}. Ensure that the files supplied to lint have a .ts, .tsx, or .js extension.`); - } - - // walk the code first to find all the intervals where rules are disabled - const rulesWalker = new EnableDisableRulesWalker(sourceFile, { - disabledIntervals: [], - ruleName: "", - }); - rulesWalker.walk(sourceFile); - const enableDisableRuleMap = rulesWalker.enableDisableRuleMap; - - const rulesDirectories = arrayify(this.options.rulesDirectory) - .concat(arrayify(configuration.rulesDirectory)); - const configurationRules = configuration.rules; - const jsConfiguration = configuration.jsRules; - const isJs = fileName.substr(-3) === ".js"; - let configuredRules: IRule[]; - - if (isJs) { - configuredRules = loadRules(jsConfiguration, enableDisableRuleMap, rulesDirectories, true); - } else { - configuredRules = loadRules(configurationRules, enableDisableRuleMap, rulesDirectories, false); - } - - const enabledRules = configuredRules.filter((r) => r.isEnabled()); - for (let rule of enabledRules) { - let ruleFailures: RuleFailure[] = []; - if (this.program && rule instanceof TypedRule) { - ruleFailures = rule.applyWithProgram(sourceFile, this.program); - } else { - ruleFailures = rule.apply(sourceFile); - } - for (let ruleFailure of ruleFailures) { - if (!this.containsRule(this.failures, ruleFailure)) { - this.failures.push(ruleFailure); - } + // make a 1st pass or make a 2nd pass if there were any fixes because the positions may be off + if (!hasLinterRun || this.fixes.length > 0) { + this.failures = []; + for (let rule of enabledRules) { + const fileFailures = this.applyRule(rule, sourceFile); + this.failures = this.failures.concat(fileFailures); } } } @@ -153,16 +135,71 @@ class MultiLinter { throw new Error(`formatter '${formatterName}' not found`); } - const output = formatter.format(this.failures); + const output = formatter.format(this.failures, this.fixes); return { failureCount: this.failures.length, failures: this.failures, + fixes: this.fixes, format: formatterName, output, }; } + private applyRule(rule: IRule, sourceFile: ts.SourceFile) { + let ruleFailures: RuleFailure[] = []; + if (this.program && rule instanceof TypedRule) { + ruleFailures = rule.applyWithProgram(sourceFile, this.program); + } else { + ruleFailures = rule.apply(sourceFile); + } + let fileFailures: RuleFailure[] = []; + for (let ruleFailure of ruleFailures) { + if (!this.containsRule(this.failures, ruleFailure)) { + fileFailures.push(ruleFailure); + } + } + return fileFailures; + } + + private getEnabledRules(fileName: string, source?: string, configuration: IConfigurationFile = DEFAULT_CONFIG): IRule[] { + const sourceFile = this.getSourceFile(fileName, source); + + // walk the code first to find all the intervals where rules are disabled + const rulesWalker = new EnableDisableRulesWalker(sourceFile, { + disabledIntervals: [], + ruleName: "", + }); + rulesWalker.walk(sourceFile); + const enableDisableRuleMap = rulesWalker.enableDisableRuleMap; + + const rulesDirectories = arrayify(this.options.rulesDirectory) + .concat(arrayify(configuration.rulesDirectory)); + const isJs = fileName.substr(-3) === ".js"; + const configurationRules = isJs ? configuration.jsRules : configuration.rules; + let configuredRules = loadRules(configurationRules, enableDisableRuleMap, rulesDirectories, isJs); + + return configuredRules.filter((r) => r.isEnabled()); + } + + private getSourceFile(fileName: string, source?: string) { + let sourceFile: ts.SourceFile; + if (this.program) { + sourceFile = this.program.getSourceFile(fileName); + // check if the program has been type checked + if (sourceFile && !("resolvedModules" in sourceFile)) { + throw new Error("Program must be type checked before linting"); + } + } else { + sourceFile = utils.getSourceFile(fileName, source); + } + + if (sourceFile === undefined) { + throw new Error(`Invalid source file: ${fileName}. Ensure that the files supplied to lint have a .ts, .tsx, or .js extension.`); + } + return sourceFile; + } + private containsRule(rules: RuleFailure[], rule: RuleFailure) { return rules.some((r) => r.equals(rule)); } diff --git a/test/configurationTests.ts b/test/configurationTests.ts index 2e5ab236c14..c73f0b7cdb8 100644 --- a/test/configurationTests.ts +++ b/test/configurationTests.ts @@ -15,10 +15,9 @@ */ import * as fs from "fs"; -import * as os from "os"; -import * as path from "path"; -import {IConfigurationFile, extendConfigurationFile, loadConfigurationFromPath} from "../src/configuration"; +import { IConfigurationFile, extendConfigurationFile, loadConfigurationFromPath } from "../src/configuration"; +import { createTempFile } from "./utils"; describe("Configuration", () => { it("extendConfigurationFile", () => { @@ -123,16 +122,7 @@ describe("Configuration", () => { let tmpfile: string; beforeEach(() => { - for (let i = 0; i < 5; i++) { - const attempt = path.join(os.tmpdir(), `tslint.test${Math.round(Date.now() * Math.random())}.json`); - if (!fs.existsSync(tmpfile)) { - tmpfile = attempt; - break; - } - } - if (tmpfile === undefined) { - throw new Error("Couldn't create temp file"); - } + tmpfile = createTempFile("json"); }); afterEach(() => { diff --git a/test/executable/executableTests.ts b/test/executable/executableTests.ts index 31d281c2958..81180180fa7 100644 --- a/test/executable/executableTests.ts +++ b/test/executable/executableTests.ts @@ -14,6 +14,7 @@ * limitations under the License. */ +import { createTempFile } from "../utils"; import * as cp from "child_process"; import * as fs from "fs"; import * as os from "os"; @@ -115,6 +116,22 @@ describe("Executable", function() { }); }); + describe("--fix flag", () => { + it("fixes multiple rules without overwriting each other", (done) => { + const tempFile = createTempFile("ts"); + fs.createReadStream("test/files/multiple-fixes-test/multiple-fixes.test.ts").pipe(fs.createWriteStream(tempFile)); + execCli(["-c", "test/files/multiple-fixes-test/tslint.json", tempFile, "--fix"], + (err, stdout) => { + const content = fs.readFileSync(tempFile, "utf8"); + fs.unlinkSync(tempFile); + assert.strictEqual(content, "import * as y from \"a_long_module\";\nimport * as x from \"b\";\n"); + assert.isNull(err, "process should exit without an error"); + assert.strictEqual(stdout, `Fixed 2 error(s) in ${tempFile}`); + done(); + }); + }); + }); + describe("--force flag", () => { it("exits with code 0 if `--force` flag is passed", (done) => { execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "--force", "src/tslint.ts"], diff --git a/test/files/multiple-fixes-test/multiple-fixes.test.ts b/test/files/multiple-fixes-test/multiple-fixes.test.ts new file mode 100644 index 00000000000..83849f1a699 --- /dev/null +++ b/test/files/multiple-fixes-test/multiple-fixes.test.ts @@ -0,0 +1,2 @@ +import * as x from "b" +import * as y from "a_long_module"; diff --git a/test/files/multiple-fixes-test/tslint.json b/test/files/multiple-fixes-test/tslint.json new file mode 100644 index 00000000000..d57be419e19 --- /dev/null +++ b/test/files/multiple-fixes-test/tslint.json @@ -0,0 +1,6 @@ +{ + "rules": { + "ordered-imports": [true], + "semicolon": [true, "always"] + } +} diff --git a/test/formatters/proseFormatterTests.ts b/test/formatters/proseFormatterTests.ts index ccf8bc18907..0643e58bfdf 100644 --- a/test/formatters/proseFormatterTests.ts +++ b/test/formatters/proseFormatterTests.ts @@ -47,6 +47,28 @@ describe("Prose Formatter", () => { assert.equal(actualResult, expectedResult); }); + it("formats fixes", () => { + const failures = [ + new RuleFailure(sourceFile, 0, 1, "first failure", "first-name"), + ]; + + const mockFix = { getFileName: () => { return "file2"; } } as any; + + const fixes = [ + new RuleFailure(sourceFile, 0, 1, "first failure", "first-name"), + new RuleFailure(sourceFile, 32, 36, "mid failure", "mid-name"), + mockFix, + ]; + + const expectedResult = + `Fixed 2 error(s) in ${TEST_FILE}\n` + + `Fixed 1 error(s) in file2\n\n` + + `${TEST_FILE}${getPositionString(1, 1)}first failure\n`; + + const actualResult = formatter.format(failures, fixes); + assert.equal(actualResult, expectedResult); + }); + it("handles no failures", () => { const result = formatter.format([]); assert.equal(result, ""); diff --git a/test/utils.ts b/test/utils.ts index f3c80a751ee..81629f064fa 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -15,6 +15,7 @@ */ import * as fs from "fs"; +import * as os from "os"; import * as path from "path"; import * as ts from "typescript"; @@ -82,3 +83,18 @@ export function assertContainsFailure(haystack: Lint.RuleFailure[], needle: Lint assert(false, "expected " + stringifiedNeedle + " within " + stringifiedHaystack); } } + +export function createTempFile(extension: string) { + let tmpfile: string; + for (let i = 0; i < 5; i++) { + const attempt = path.join(os.tmpdir(), `tslint.test${Math.round(Date.now() * Math.random())}.${extension}`); + if (!fs.existsSync(tmpfile)) { + tmpfile = attempt; + break; + } + } + if (tmpfile === undefined) { + throw new Error("Couldn't create temp file"); + } + return tmpfile; +} From a47b9d230a6d48333bae09304ee25ea349fda8fc Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 9 Nov 2016 09:10:52 -0500 Subject: [PATCH 050/111] Update CHANGELOG.md (#1700) --- CHANGELOG.md | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6e000ccc5d..27aaf869da8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,90 @@ Change Log === +v4.0.0-dev.1 +--- +* **BREAKING CHANGES** + * [enhancement] The `semicolon` rule now disallows semicolons in multi-line bound class methods + (to get the v3 behavior, use the `ignore-bound-class-methods` option) (#1643) + * [enhancement] Removed `use-strict` rule (#678) + * [enhancement] Removed `label-undefined` rule; covered by compiler (#1614) + * [enhancement] Renamed `no-constructor-vars` to `no-parameter-properties` (#1296) + * [rule-change] The `orderedImports` rule now sorts relative modules below non-relative modules (#1640) +* **Deprecated** + * [deprecated] `no-unused-variable` rule. This is checked by the TypeScript v2 compiler using the flags [`--noUnusedParameters` and `--noUnusedLocals`](https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#flag-unused-declarations-with---nounusedparameters-and---nounusedlocals). (#1481) +* [enhancement] Lint .js files (#1515) +* [new-fixer] `no-var-keyword` replaces `var` with `let` (#1547) +* [new-fixer] `trailing-comma` auto fixed (#1546) +* [new-fixer] `no-unused-variable` auto fixed for imports (#1568) +* [new-fixer] `semicolon` auto fixed (#1423) +* [new-rule] `max-classes-per-file` rule added (#1666) +* [new-rule-option] `no-consecutive-blank-lines` rule now accepts a number value indicating max blank lines (#1650) +* [new-rule-option] `ordered-inputs` rule option `input-sources-order` accepts value `any` (#1602) +* [bugfix] `no-empty` rule fixed when parameter has readonly modifier +* [bugfix] `no-namespace` rule: do not flag nested or .d.ts namespaces (#1571) + +Thanks to our contributors! + +* Alex Eagle +* Andrii Dieiev +* Ben Coveney +* Boris Aranovich +* Chris Barr +* Cyril Gandon +* Evgeniy Zhukovskiy +* Jay Anslow +* Kunal Marwaha +* Martin Probst +* Mingye Wang +* Raghav Katyal +* Sean Dawson +* Yuichi Nukiyama +* jakpaw + +v4.0.0-dev.0 +--- +* **BREAKING CHANGES** + * [enhancement] Drop support for configuration via package.json (#1579) + * [enhancement] Removed `no-duplicate-key` rule; covered by compiler (#1109) + * [enhancement] Call formatter once for all file results. Format output may be different (#656) + * [rule-change] `trailing-comma` supports function declarations, expressions, and types (#1486) + * [rule-change] `object-literal-sort-keys` now sorts quoted keys (#1529) + * [rule-change] `semicolon` now processes type aliases (#1475) + * [rule-change] `no-var-keyword` now rejects `export var` statements (#1256) + * [rule-change] `semicolon` now requires semicolon for function declaration with no body (#1447) +* [new-formatter] `fileslist` formatter writes a list of files with errors without position or error type specifics (#1558) +* [new-rule] `cyclomaticComplexity`, enforces a threshold of cyclomatic complexity.] (#1464) +* [new-rule] `prefer-for-of`, which errors when `for(var x of y)` can be used instead of `for(var i = 0; i < y.length; i++)` (#1335) +* [new-rule] `array-type`, which can require using either `T[]' or 'Array' for arrays (#1498) +* [rule-change] `object-literal-sort-keys` checks multiline objects only (#1642) +* [rule-change] `ban` rule now can ban global functions (#327) +* [bugfix] always write lint result, even if using formatter (#1353) +* [bugfix] npm run test:bin fails on Windows (#1635) +* [bugfix] Don't enforce trailing spaces on newlines in typedef-whitespace rule (#1531) +* [bugfix] `jsdoc` rule should not match arbitrary comments (#1543) +* [bugfix] `one-line` rule errors when declaring wildcard ambient modules (#1425) + +Thanks to our contributors! + +* Alex Eagle +* Andrii Dieiev +* Andy Hanson +* Ben Coveney +* Boris Aranovich +* Chris Barr +* Christian Dreher +* Claas Augner +* Josh Goldberg +* Martin Probst +* Mike Deverell +* Nina Hartmann +* Satoshi Amemiya +* Scott Wu +* Steve Van Opstal +* Umar Bolatov +* Vladimir Matveev +* Yui + v3.15.1 --- * Enabled additional rules in `tslint:latest` configuration (#1506) From 284144506e44f3eef120a1c55b92685071058621 Mon Sep 17 00:00:00 2001 From: Andrii Dieiev Date: Thu, 10 Nov 2016 06:01:10 +0200 Subject: [PATCH 051/111] Use denormalized path in test (fixes Windows build) (#1701) --- test/executable/executableTests.ts | 6 ++++-- test/utils.ts | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/test/executable/executableTests.ts b/test/executable/executableTests.ts index 81180180fa7..a7017632141 100644 --- a/test/executable/executableTests.ts +++ b/test/executable/executableTests.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { createTempFile } from "../utils"; +import { createTempFile, denormalizeWinPath } from "../utils"; import * as cp from "child_process"; import * as fs from "fs"; import * as os from "os"; @@ -123,10 +123,12 @@ describe("Executable", function() { execCli(["-c", "test/files/multiple-fixes-test/tslint.json", tempFile, "--fix"], (err, stdout) => { const content = fs.readFileSync(tempFile, "utf8"); + // compare against file name which will be returned by formatter (used in TypeScript) + const denormalizedFileName = denormalizeWinPath(tempFile); fs.unlinkSync(tempFile); assert.strictEqual(content, "import * as y from \"a_long_module\";\nimport * as x from \"b\";\n"); assert.isNull(err, "process should exit without an error"); - assert.strictEqual(stdout, `Fixed 2 error(s) in ${tempFile}`); + assert.strictEqual(stdout, `Fixed 2 error(s) in ${denormalizedFileName}`); done(); }); }); diff --git a/test/utils.ts b/test/utils.ts index 81629f064fa..7bf981a040c 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -98,3 +98,8 @@ export function createTempFile(extension: string) { } return tmpfile; } + +// converts Windows normalized paths (with backwards slash `\`) to paths used by TypeScript (with forward slash `/`) +export function denormalizeWinPath(path: string): string { + return path.replace(/\\/g, "/"); +} From ebbce9cc3990f2d9c7a60566ed138cde483f4c18 Mon Sep 17 00:00:00 2001 From: Andrii Dieiev Date: Thu, 10 Nov 2016 06:33:30 +0200 Subject: [PATCH 052/111] Add support for glob patterns in single quotes for files and exclude arguments (#1679) --- src/tslint-cli.ts | 19 ++++++++++++++++--- src/tslintMulti.ts | 2 +- test/executable/executableTests.ts | 29 +++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index cf5f07ec296..12c95e89cab 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -26,7 +26,7 @@ import { DEFAULT_CONFIG, findConfiguration, } from "./configuration"; -import {consoleTestResultHandler, runTest} from "./test"; +import { consoleTestResultHandler, runTest } from "./test"; import * as Linter from "./tslintMulti"; let processed = optimist @@ -49,6 +49,7 @@ let processed = optimist e: { alias: "exclude", describe: "exclude globs from path expansion", + type: "string", }, fix: { describe: "Fixes linting errors for select rules. This may overwrite linted files", @@ -303,7 +304,19 @@ if (argv.project != null) { } } +const trimSingleQuotes = (str: string) => str.replace(/^'|'$/g, ""); + +let ignorePatterns: string[] = []; +if (argv.e) { + const excludeArguments: string[] = Array.isArray(argv.e) ? argv.e : [argv.e]; + + ignorePatterns = excludeArguments.map(trimSingleQuotes); +} + files = files - .map((file: string) => glob.sync(file, { ignore: argv.e, nodir: true })) - .reduce((a: string[], b: string[]) => a.concat(b)); + // remove single quotes which break matching on Windows when glob is passed in single quotes + .map(trimSingleQuotes) + .map((file: string) => glob.sync(file, { ignore: ignorePatterns, nodir: true })) + .reduce((a: string[], b: string[]) => a.concat(b)); + processFiles(files, program); diff --git a/src/tslintMulti.ts b/src/tslintMulti.ts index 2f9ef86232e..3542da962f1 100644 --- a/src/tslintMulti.ts +++ b/src/tslintMulti.ts @@ -206,6 +206,6 @@ class MultiLinter { } // tslint:disable-next-line:no-namespace -namespace MultiLinter {} +namespace MultiLinter { } export = MultiLinter; diff --git a/test/executable/executableTests.ts b/test/executable/executableTests.ts index a7017632141..50431bde133 100644 --- a/test/executable/executableTests.ts +++ b/test/executable/executableTests.ts @@ -236,6 +236,35 @@ describe("Executable", function() { }); }); + + describe("globs and quotes", () => { + // when glob pattern is passed without quotes in npm script `process.env` will contain: + // on Windows - pattern string without any quotes + // on Linux - list of files that matches glob (may differ from `glob` module results) + + it("exits with code 2 if correctly finds file containing lint errors when glob is in double quotes", (done) => { + // when glob pattern is passed in double quotes in npm script `process.env` will contain: + // on Windows - pattern string without any quotes + // on Linux - pattern string without any quotes (glob is not expanded) + execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "src/**/tslint.ts"], (err) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 2, "error code should be 2"); + done(); + }); + }); + + it("exits with code 2 if correctly finds file containing lint errors when glob is in single quotes", (done) => { + // when glob pattern is passed in single quotes in npm script `process.env` will contain: + // on Windows - pattern string wrapped in single quotes + // on Linux - pattern string without any quotes (glob is not expanded) + execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "'src/**/tslint.ts'"], (err) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 2, "error code should be 2"); + done(); + }); + }); + + }); }); type ExecFileCallback = (error: any, stdout: string, stderr: string) => void; From 9167373096ae748b14ad20d524c1482b6e54a5cc Mon Sep 17 00:00:00 2001 From: Yuichi Nukiyama Date: Thu, 10 Nov 2016 23:10:50 +0900 Subject: [PATCH 053/111] remove no-var-rule from DEFAULT_CONFIG (#1703) --- src/configuration.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/configuration.ts b/src/configuration.ts index 4c7241bbf74..3a8454c6a01 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -43,7 +43,6 @@ export const DEFAULT_CONFIG = { "no-eval": true, "no-trailing-whitespace": true, "no-unsafe-finally": true, - "no-var-keyword": true, "one-line": [true, "check-open-brace", "check-whitespace"], "quotemark": [true, "double"], "semicolon": [true, "always"], From f9c49aa89ba74976445a3885c24a12d89b52598b Mon Sep 17 00:00:00 2001 From: Stepan Riha Date: Thu, 10 Nov 2016 08:26:47 -0600 Subject: [PATCH 054/111] Skip over template string when checking indent (#1611) (#1651) --- src/rules/indentRule.ts | 26 ++++++++++++++++++++++++-- test/rules/indent/spaces/test.ts.lint | 10 ++++++++++ test/rules/indent/tabs/test.ts.lint | 10 ++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/rules/indentRule.ts b/src/rules/indentRule.ts index 7d56502b81f..b0ab4942054 100644 --- a/src/rules/indentRule.ts +++ b/src/rules/indentRule.ts @@ -77,10 +77,11 @@ class IndentWalker extends Lint.RuleWalker { } let endOfComment = -1; + let endOfTemplateString = -1; const scanner = ts.createScanner(ts.ScriptTarget.ES5, false, ts.LanguageVariant.Standard, node.text); for (let lineStart of node.getLineStarts()) { - if (lineStart < endOfComment) { - // skip checking lines inside multi-line comments + if (lineStart < endOfComment || lineStart < endOfTemplateString) { + // skip checking lines inside multi-line comments or template strings continue; } @@ -104,6 +105,27 @@ class IndentWalker extends Lint.RuleWalker { const commentRanges = ts.getTrailingCommentRanges(node.text, lineStart); if (commentRanges) { endOfComment = commentRanges[commentRanges.length - 1].end; + } else { + let scanType = currentScannedType; + + // scan until we reach end of line, skipping over template strings + while (scanType !== ts.SyntaxKind.NewLineTrivia && scanType !== ts.SyntaxKind.EndOfFileToken) { + if (scanType === ts.SyntaxKind.NoSubstitutionTemplateLiteral) { + // template string without expressions - skip past it + endOfTemplateString = scanner.getStartPos() + scanner.getTokenText().length; + } else if (scanType === ts.SyntaxKind.TemplateHead) { + // find end of template string containing expressions... + while (scanType !== ts.SyntaxKind.TemplateTail && scanType !== ts.SyntaxKind.EndOfFileToken) { + scanType = scanner.scan(); + if (scanType === ts.SyntaxKind.CloseBraceToken) { + scanType = scanner.reScanTemplateToken(); + } + } + // ... and skip past it + endOfTemplateString = scanner.getStartPos() + scanner.getTokenText().length; + } + scanType = scanner.scan(); + } } if (currentScannedType === ts.SyntaxKind.SingleLineCommentTrivia diff --git a/test/rules/indent/spaces/test.ts.lint b/test/rules/indent/spaces/test.ts.lint index 106b76ece18..0ad97bb449c 100644 --- a/test/rules/indent/spaces/test.ts.lint +++ b/test/rules/indent/spaces/test.ts.lint @@ -18,6 +18,16 @@ module TestModule { c: 3 }; + // ignore leading tabs inside template strings + var s1 = ` + multiline` + ` template + string`; + var s2 = ` + multiline ${ "A" } + template ${ "B" + + "C" } + string`; + export enum TestEnum { VALUE1, VALUE2 diff --git a/test/rules/indent/tabs/test.ts.lint b/test/rules/indent/tabs/test.ts.lint index 1ec440ff490..a8b16546010 100644 --- a/test/rules/indent/tabs/test.ts.lint +++ b/test/rules/indent/tabs/test.ts.lint @@ -21,6 +21,16 @@ module TestModule { c: 3 }; + // ignore leading spaces inside template strings + var s1 = ` + multiline` + ` template + string`; + var s2 = ` + multiline ${ "A" } + template ${ "B" + + "C" } + string`; + export enum TestEnum { VALUE1, VALUE2 From 9c8d9287fa4a55a27355806436789c2c7bcea45a Mon Sep 17 00:00:00 2001 From: Chris Barr Date: Thu, 10 Nov 2016 09:37:38 -0500 Subject: [PATCH 055/111] Improve stylish formatter colors (#1668) * Improve color output for the stylish formatter * Nah, this looks nicer instead --- src/formatters/stylishFormatter.ts | 5 +++-- test/formatters/stylishFormatterTests.ts | 12 +++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/formatters/stylishFormatter.ts b/src/formatters/stylishFormatter.ts index bd65d14e2f1..f9ea5f75ffe 100644 --- a/src/formatters/stylishFormatter.ts +++ b/src/formatters/stylishFormatter.ts @@ -59,12 +59,13 @@ export class Formatter extends AbstractFormatter { currentFile = fileName; } - const failureString = failure.getFailure(); + let failureString = failure.getFailure(); + failureString = colors.yellow(failureString); // Rule let ruleName = failure.getRuleName(); ruleName = this.pad(ruleName, ruleMaxSize); - ruleName = colors.yellow(ruleName); + ruleName = colors.grey(ruleName); // Lines const lineAndCharacter = failure.getStartPosition().getLineAndCharacter(); diff --git a/test/formatters/stylishFormatterTests.ts b/test/formatters/stylishFormatterTests.ts index efa515fc929..a694ccf3e25 100644 --- a/test/formatters/stylishFormatterTests.ts +++ b/test/formatters/stylishFormatterTests.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import * as colors from "colors"; + import * as ts from "typescript"; import {IFormatter, RuleFailure, TestUtils} from "../lint"; @@ -43,12 +45,12 @@ describe("Stylish Formatter", () => { const maxPositionTuple = `${maxPositionObj.line + 1}:${maxPositionObj.character + 1}`; - const expectedResult = (require("colors").supportsColor) ? + const expectedResult = colors.enabled ? "formatters/stylishFormatter.test.ts" + "\n" + - "\u001b[31m1:1\u001b[39m \u001b[33mfirst-name\u001b[39m first failure" + "\n" + - "\u001b[31m1:3\u001b[39m \u001b[33mescape \u001b[39m &<>'\" should be escaped" + "\n" + - `\u001b[31m${maxPositionTuple}\u001b[39m \u001b[33mlast-name \u001b[39m last failure` + "\n" + - "\u001b[31m1:1\u001b[39m \u001b[33mfull-name \u001b[39m full failure" + "\n" + + "\u001b[31m1:1\u001b[39m \u001b[90mfirst-name\u001b[39m \u001b[33mfirst failure\u001b[39m" + "\n" + + "\u001b[31m1:3\u001b[39m \u001b[90mescape \u001b[39m \u001b[33m&<>'\" should be escaped\u001b[39m" + "\n" + + `\u001b[31m${maxPositionTuple}\u001b[39m \u001b[90mlast-name \u001b[39m \u001b[33mlast failure\u001b[39m` + "\n" + + "\u001b[31m1:1\u001b[39m \u001b[90mfull-name \u001b[39m \u001b[33mfull failure\u001b[39m" + "\n" + "\n" : "formatters/stylishFormatter.test.ts" + "\n" + "1:1 first-name first failure" + "\n" + From dd6021bf392e85aed16672f2f3c0cbd530dcaed9 Mon Sep 17 00:00:00 2001 From: Davie Schoots Date: Thu, 10 Nov 2016 21:19:35 +0100 Subject: [PATCH 056/111] Use update-notifier to notify of new versions #990 (#1696) --- package.json | 3 ++- src/tslint-cli.ts | 6 ++++++ src/updateNotifier.ts | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/updateNotifier.ts diff --git a/package.json b/package.json index de1c4a1a118..03af7ac9af6 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "glob": "^7.1.1", "optimist": "~0.6.0", "resolve": "^1.1.7", - "underscore.string": "^3.3.4" + "underscore.string": "^3.3.4", + "update-notifier": "^1.0.2" }, "devDependencies": { "@types/chai": "^3.4.34", diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index 12c95e89cab..6e0f14ced8d 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -28,6 +28,7 @@ import { } from "./configuration"; import { consoleTestResultHandler, runTest } from "./test"; import * as Linter from "./tslintMulti"; +import { updateNotifierCheck } from "./updateNotifier"; let processed = optimist .usage("Usage: $0 [options] file ...") @@ -267,6 +268,11 @@ const processFiles = (files: string[], program?: ts.Program) => { process.exit(argv.force ? 0 : 2); } }); + + if (lintResult.format === "prose") { + // Check to see if there are any updates available + updateNotifierCheck(); + } }; // if both files and tsconfig are present, use files diff --git a/src/updateNotifier.ts b/src/updateNotifier.ts new file mode 100644 index 00000000000..e740a7fb27d --- /dev/null +++ b/src/updateNotifier.ts @@ -0,0 +1,36 @@ +/** + * @license + * Copyright 2016 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// tslint:disable-next-line:no-var-requires +const updateNotifier = require("update-notifier"); +// tslint:disable-next-line:no-var-requires +const pkg = require("../package.json"); + +export function updateNotifierCheck(): void { + // Check every 3 days for a new version + const cacheTime: number = 1000 * 60 * 60 * 24 * 3; + const changeLogUrl: string = "https://github.com/palantir/tslint/blob/master/CHANGELOG.md"; + const notifier = updateNotifier({ + pkg, + updateCheckInterval: cacheTime, + }); + + if (notifier.notify && notifier.update) { + let message: string = `TSLint update available v${notifier.update.current} → v${notifier.update.latest} \n See ${changeLogUrl}`; + notifier.notify({ message }); + } +}; From cbdf7a89c773f57cb980bd5c13db3387544ece68 Mon Sep 17 00:00:00 2001 From: Nick Miyake Date: Thu, 10 Nov 2016 12:23:07 -0800 Subject: [PATCH 057/111] Update LICENSE (#1705) Use default Apache 2.0 LICENSE file provided by GitHub.com --- LICENSE | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index 402690572fd..8dada3edaf5 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,3 @@ - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -179,7 +178,7 @@ APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" + boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a @@ -187,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2014 Palantir Technologies + Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From e736ba9e31acfa2dda5c25c8964b1ed36f514ddd Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Thu, 10 Nov 2016 15:56:56 -0500 Subject: [PATCH 058/111] More intuitive configuration composition (#1622) --- src/configuration.ts | 51 ++++++++++--------- src/utils.ts | 6 +++ .../tslint-custom-rules-with-two-dirs.json | 6 ++- test/configurationTests.ts | 39 ++++++++------ test/executable/executableTests.ts | 8 --- test/ruleLoaderTests.ts | 7 +-- 6 files changed, 64 insertions(+), 53 deletions(-) diff --git a/src/configuration.ts b/src/configuration.ts index 3a8454c6a01..4a7e178ba9f 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -170,14 +170,14 @@ export function loadConfigurationFromPath(configFilePath: string): IConfiguratio const configFileDir = path.dirname(resolvedConfigFilePath); configFile.rulesDirectory = getRulesDirectories(configFile.rulesDirectory, configFileDir); - configFile.extends = arrayify(configFile.extends); + // load configurations, in order, using their identifiers or relative paths + // apply the current configuration last by placing it last in this array + const configs = arrayify(configFile.extends).map((name) => { + const nextConfigFilePath = resolveConfigurationPath(name, configFileDir); + return loadConfigurationFromPath(nextConfigFilePath); + }).concat([configFile]); - for (const name of configFile.extends) { - const baseConfigFilePath = resolveConfigurationPath(name, configFileDir); - const baseConfigFile = loadConfigurationFromPath(baseConfigFilePath); - configFile = extendConfigurationFile(configFile, baseConfigFile); - } - return configFile; + return configs.reduce(extendConfigurationFile, {}); } } @@ -211,28 +211,29 @@ function resolveConfigurationPath(filePath: string, relativeTo?: string) { } } -export function extendConfigurationFile(config: IConfigurationFile, baseConfig: IConfigurationFile): IConfigurationFile { +export function extendConfigurationFile(targetConfig: IConfigurationFile, + nextConfigSource: IConfigurationFile): IConfigurationFile { let combinedConfig: IConfigurationFile = {}; - const baseRulesDirectory = arrayify(baseConfig.rulesDirectory); - const configRulesDirectory = arrayify(config.rulesDirectory); - combinedConfig.rulesDirectory = configRulesDirectory.concat(baseRulesDirectory); + const configRulesDirectory = arrayify(targetConfig.rulesDirectory); + const nextConfigRulesDirectory = arrayify(nextConfigSource.rulesDirectory); + combinedConfig.rulesDirectory = configRulesDirectory.concat(nextConfigRulesDirectory); - combinedConfig.rules = {}; - for (const name of Object.keys(objectify(baseConfig.rules))) { - combinedConfig.rules[name] = baseConfig.rules[name]; - } - for (const name of Object.keys(objectify(config.rules))) { - combinedConfig.rules[name] = config.rules[name]; - } + const combineProperties = (targetProperty: any, nextProperty: any) => { + let combinedProperty: any = {}; + for (const name of Object.keys(objectify(targetProperty))) { + combinedProperty[name] = targetProperty[name]; + } + // next config source overwrites the target config object + for (const name of Object.keys(objectify(nextProperty))) { + combinedProperty[name] = nextProperty[name]; + } + return combinedProperty; + }; - combinedConfig.jsRules = {}; - for (const name of Object.keys(objectify(baseConfig.jsRules))) { - combinedConfig.jsRules[name] = baseConfig.jsRules[name]; - } - for (const name of Object.keys(objectify(config.jsRules))) { - combinedConfig.jsRules[name] = config.jsRules[name]; - } + combinedConfig.rules = combineProperties(targetConfig.rules, nextConfigSource.rules); + combinedConfig.jsRules = combineProperties(targetConfig.jsRules, nextConfigSource.jsRules); + combinedConfig.linterOptions = combineProperties(targetConfig.linterOptions, nextConfigSource.linterOptions); return combinedConfig; } diff --git a/src/utils.ts b/src/utils.ts index 20743afd41a..c8b58e36c79 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -15,6 +15,9 @@ * limitations under the License. */ +/** + * Enforces the invariant that the input is an array. + */ export function arrayify(arg: T | T[]): T[] { if (Array.isArray(arg)) { return arg; @@ -25,6 +28,9 @@ export function arrayify(arg: T | T[]): T[] { } } +/** + * Enforces the invariant that the input is an object. + */ export function objectify(arg: any): any { if (typeof arg === "object" && arg != null) { return arg; diff --git a/test/config/tslint-custom-rules-with-two-dirs.json b/test/config/tslint-custom-rules-with-two-dirs.json index 6cc0107305f..a43cf3db773 100644 --- a/test/config/tslint-custom-rules-with-two-dirs.json +++ b/test/config/tslint-custom-rules-with-two-dirs.json @@ -2,10 +2,12 @@ "rulesDirectory": ["../files/custom-rules-2", "../files/custom-rules/"], "jsRules": { "always-fail": true, - "no-fail": true + "no-fail": true, + "rule-two": true }, "rules": { "always-fail": true, - "no-fail": true + "no-fail": true, + "rule-two": true } } diff --git a/test/configurationTests.ts b/test/configurationTests.ts index c73f0b7cdb8..1a4d28eda2a 100644 --- a/test/configurationTests.ts +++ b/test/configurationTests.ts @@ -23,6 +23,7 @@ describe("Configuration", () => { it("extendConfigurationFile", () => { const EMPTY_CONFIG: IConfigurationFile = { jsRules: {}, + linterOptions: {}, rules: {}, rulesDirectory: [], }; @@ -32,72 +33,80 @@ describe("Configuration", () => { assert.deepEqual(extendConfigurationFile(EMPTY_CONFIG, {}), EMPTY_CONFIG); assert.deepEqual(extendConfigurationFile({}, { jsRules: { row: "oar" }, + linterOptions: {}, rules: { foo: "bar" }, rulesDirectory: "foo", }), { jsRules: { row: "oar" }, + linterOptions: {}, rules: {foo: "bar"}, rulesDirectory: ["foo"], }); - assert.deepEqual(extendConfigurationFile({ + const actualConfig = extendConfigurationFile({ jsRules: { row: "oar" }, + linterOptions: {}, rules: { a: 1, - b: 2, + b: 1, }, rulesDirectory: ["foo", "bar"], }, { jsRules: { fly: "wings" }, + linterOptions: {}, rules: { - b: 1, + b: 2, c: 3, }, rulesDirectory: "baz", - }), { + }); + /* tslint:disable:object-literal-sort-keys */ + const expectedConfig = { jsRules: { - fly: "wings", row: "oar", + fly: "wings", }, + linterOptions: {}, rules: { a: 1, b: 2, c: 3, }, rulesDirectory: ["foo", "bar", "baz"], - }); + }; + assert.deepEqual(actualConfig, expectedConfig); }); describe("loadConfigurationFromPath", () => { it("extends with relative path", () => { - let config = loadConfigurationFromPath("./test/config/tslint-extends-relative.json"); + const config = loadConfigurationFromPath("./test/config/tslint-extends-relative.json"); assert.isArray(config.rulesDirectory); - assert.isTrue(config.rules["no-fail"]); - assert.isFalse(config.rules["always-fail"]); + assert.isTrue(config.rules["no-fail"], "did not pick up 'no-fail' in base config"); + assert.isFalse(config.rules["always-fail"], "did not set 'always-fail' in top config"); assert.isTrue(config.jsRules["no-fail"]); assert.isFalse(config.jsRules["always-fail"]); }); it("extends with package", () => { - let config = loadConfigurationFromPath("./test/config/tslint-extends-package.json"); + const config = loadConfigurationFromPath("./test/config/tslint-extends-package.json"); assert.isArray(config.rulesDirectory); /* tslint:disable:object-literal-sort-keys */ assert.deepEqual(config.jsRules, { "rule-one": true, - "rule-two": true, "rule-three": false, + "rule-two": true, }); assert.deepEqual(config.rules, { "rule-one": true, - "rule-two": true, "rule-three": false, + "rule-two": true, }); /* tslint:enable:object-literal-sort-keys */ }); it("extends with package without customization", () => { - let config = loadConfigurationFromPath("./test/config/tslint-extends-package-no-mod.json"); + const config = loadConfigurationFromPath("./test/config/tslint-extends-package-no-mod.json"); assert.isArray(config.rulesDirectory); assert.deepEqual(config.jsRules, { @@ -171,13 +180,13 @@ describe("Configuration", () => { "always-fail": false, "no-fail": true, "rule-one": true, - "rule-two": false, + "rule-two": true, }); assert.deepEqual(config.rules, { "always-fail": false, "no-fail": true, "rule-one": true, - "rule-two": false, + "rule-two": true, }); }); diff --git a/test/executable/executableTests.ts b/test/executable/executableTests.ts index 50431bde133..258ae2ba50a 100644 --- a/test/executable/executableTests.ts +++ b/test/executable/executableTests.ts @@ -106,14 +106,6 @@ describe("Executable", function() { done(); }); }); - - it("exits with code 2 if several custom rules directories are specified in config file and file contains lint errors", (done) => { - execCli(["-c", "./test/config/tslint-custom-rules-with-two-dirs.json", "src/tslint.ts"], (err) => { - assert.isNotNull(err, "process should exit with error"); - assert.strictEqual(err.code, 2, "error code should be 2"); - done(); - }); - }); }); describe("--fix flag", () => { diff --git a/test/ruleLoaderTests.ts b/test/ruleLoaderTests.ts index 70324afd3bb..daa8b1f6422 100644 --- a/test/ruleLoaderTests.ts +++ b/test/ruleLoaderTests.ts @@ -1,4 +1,5 @@ -/* +/** + * @license * Copyright 2013 Palantir Technologies, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,7 +41,7 @@ describe("Rule Loader", () => { assert.throws( () => loadRules(invalidConfiguration, {}, RULES_DIRECTORY), - /invalidConfig1\ninvalidConfig2/ + /invalidConfig1\ninvalidConfig2/, ); }); @@ -56,7 +57,7 @@ describe("Rule Loader", () => { assert.throws( () => loadRules(invalidConfiguration, {}, RULES_DIRECTORY), - /_indent\nforin_\n-quotemark\neofline-/ + /_indent\nforin_\n-quotemark\neofline-/, ); }); From bf798597b1f36cf1911669568a9c3436ad774b4d Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 11 Nov 2016 14:01:00 -0500 Subject: [PATCH 059/111] Typescript peer dependency >= 2.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 03af7ac9af6..bf2621800d2 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "typescript": "2.0.3" }, "peerDependencies": { - "typescript": ">=1.7.3" + "typescript": ">=2.0.0" }, "license": "Apache-2.0", "typescript": { From 4e94c81166bc28e03290bcd0609c13a126b9e25b Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 11 Nov 2016 21:06:47 -0500 Subject: [PATCH 060/111] Make typescriptOnly and optionsDescription required on IRuleMetadata (#1709) --- src/language/rule/rule.ts | 6 +++--- src/rules/adjacentOverloadSignaturesRule.ts | 1 + src/rules/cyclomaticComplexityRule.ts | 1 + src/rules/maxClassesPerFileRule.ts | 1 + src/rules/objectLiteralShorthandRule.ts | 1 + src/rules/preferForOfRule.ts | 1 + 6 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/language/rule/rule.ts b/src/language/rule/rule.ts index 815cfefaef0..3cdd626cc27 100644 --- a/src/language/rule/rule.ts +++ b/src/language/rule/rule.ts @@ -48,7 +48,7 @@ export interface IRuleMetadata { /** * An explanation of the available options for the rule. */ - optionsDescription?: string; + optionsDescription: string; /** * Schema of the options the rule accepts. @@ -74,9 +74,9 @@ export interface IRuleMetadata { requiresTypeInfo?: boolean; /** - * Whether or not the rule use for TypeScript only. + * Whether or not the rule use for TypeScript only. If `false`, this rule may be used with .js files. */ - typescriptOnly?: boolean; + typescriptOnly: boolean; } export type RuleType = "functionality" | "maintainability" | "style" | "typescript"; diff --git a/src/rules/adjacentOverloadSignaturesRule.ts b/src/rules/adjacentOverloadSignaturesRule.ts index bbe11db548e..2e42d3364ee 100644 --- a/src/rules/adjacentOverloadSignaturesRule.ts +++ b/src/rules/adjacentOverloadSignaturesRule.ts @@ -28,6 +28,7 @@ export class Rule extends Lint.Rules.AbstractRule { optionsDescription: "Not configurable.", options: null, optionExamples: ["true"], + rationale: "Improves readability and organization by grouping naturally related items together.", type: "typescript", typescriptOnly: true, }; diff --git a/src/rules/cyclomaticComplexityRule.ts b/src/rules/cyclomaticComplexityRule.ts index 9e1f89bad7d..f22453389ca 100644 --- a/src/rules/cyclomaticComplexityRule.ts +++ b/src/rules/cyclomaticComplexityRule.ts @@ -50,6 +50,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["true", "[true, 20]"], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/maxClassesPerFileRule.ts b/src/rules/maxClassesPerFileRule.ts index 0076fbc9311..e8af20c192a 100644 --- a/src/rules/maxClassesPerFileRule.ts +++ b/src/rules/maxClassesPerFileRule.ts @@ -27,6 +27,7 @@ export class Rule extends Lint.Rules.AbstractRule { }, optionExamples: ["[true, 1]", "[true, 5]"], type: "maintainability", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ diff --git a/src/rules/objectLiteralShorthandRule.ts b/src/rules/objectLiteralShorthandRule.ts index 6f58862c687..813be2fc97d 100644 --- a/src/rules/objectLiteralShorthandRule.ts +++ b/src/rules/objectLiteralShorthandRule.ts @@ -6,6 +6,7 @@ export class Rule extends Lint.Rules.AbstractRule { public static metadata: Lint.IRuleMetadata = { ruleName: "object-literal-shorthand", description: "Enforces use of ES6 object literal shorthand when possible.", + optionsDescription: "Not configurable.", options: null, optionExamples: ["true"], type: "style", diff --git a/src/rules/preferForOfRule.ts b/src/rules/preferForOfRule.ts index cd1078cfb31..3fe891bfe06 100644 --- a/src/rules/preferForOfRule.ts +++ b/src/rules/preferForOfRule.ts @@ -28,6 +28,7 @@ export class Rule extends Lint.Rules.AbstractRule { options: null, optionExamples: ["true"], type: "typescript", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ From 29180134093bc8bc2107d56b631d08eee3d7bbb3 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 11 Nov 2016 22:42:49 -0500 Subject: [PATCH 061/111] Remove rule `no-unreachable` (#1711) --- CHANGELOG.md | 15 ++- src/configs/recommended.ts | 2 - src/rules/noUnreachableRule.ts | 117 --------------------- test/rules/_integration/react/tslint.json | 1 - test/rules/no-unreachable/test.js.lint | 104 ------------------- test/rules/no-unreachable/test.ts.lint | 118 ---------------------- test/rules/no-unreachable/tslint.json | 8 -- 7 files changed, 11 insertions(+), 354 deletions(-) delete mode 100644 src/rules/noUnreachableRule.ts delete mode 100644 test/rules/no-unreachable/test.js.lint delete mode 100644 test/rules/no-unreachable/test.ts.lint delete mode 100644 test/rules/no-unreachable/tslint.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 27aaf869da8..552676a2477 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,20 @@ Change Log === - + v4.0.0-dev.1 --- * **BREAKING CHANGES** * [enhancement] The `semicolon` rule now disallows semicolons in multi-line bound class methods (to get the v3 behavior, use the `ignore-bound-class-methods` option) (#1643) - * [enhancement] Removed `use-strict` rule (#678) - * [enhancement] Removed `label-undefined` rule; covered by compiler (#1614) + * [removed-rule] Removed `use-strict` rule (#678) + * [removed-rule] Removed `label-undefined` rule; covered by compiler (#1614) * [enhancement] Renamed `no-constructor-vars` to `no-parameter-properties` (#1296) * [rule-change] The `orderedImports` rule now sorts relative modules below non-relative modules (#1640) * **Deprecated** @@ -45,7 +52,7 @@ v4.0.0-dev.0 --- * **BREAKING CHANGES** * [enhancement] Drop support for configuration via package.json (#1579) - * [enhancement] Removed `no-duplicate-key` rule; covered by compiler (#1109) + * [removed-rule] Removed `no-duplicate-key` rule; covered by compiler (#1109) * [enhancement] Call formatter once for all file results. Format output may be different (#656) * [rule-change] `trailing-comma` supports function declarations, expressions, and types (#1486) * [rule-change] `object-literal-sort-keys` now sorts quoted keys (#1529) diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index b91df7a259d..fefef3add69 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -64,7 +64,6 @@ export const rules = { "no-string-literal": true, "no-switch-case-fall-through": false, "no-trailing-whitespace": true, - "no-unreachable": true, "no-unused-expression": true, "no-unused-new": true, // deprecated as of v4.0 @@ -162,7 +161,6 @@ export const jsRules = { "no-string-literal": true, "no-switch-case-fall-through": false, "no-trailing-whitespace": true, - "no-unreachable": true, "no-unused-expression": true, "no-unused-new": true, // disable this rule as it is very heavy performance-wise and not that useful diff --git a/src/rules/noUnreachableRule.ts b/src/rules/noUnreachableRule.ts deleted file mode 100644 index 2d63de4d65a..00000000000 --- a/src/rules/noUnreachableRule.ts +++ /dev/null @@ -1,117 +0,0 @@ -/** - * @license - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as ts from "typescript"; - -import * as Lint from "../lint"; - -export class Rule extends Lint.Rules.AbstractRule { - /* tslint:disable:object-literal-sort-keys */ - public static metadata: Lint.IRuleMetadata = { - ruleName: "no-unreachable", - description: "Disallows unreachable code after `break`, `catch`, `throw`, and `return` statements.", - rationale: "Unreachable code is often indication of a logic error.", - optionsDescription: "Not configurable.", - options: null, - optionExamples: ["true"], - type: "functionality", - typescriptOnly: false, - }; - /* tslint:enable:object-literal-sort-keys */ - - public static FAILURE_STRING = "unreachable code"; - - public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - return this.applyWithWalker(new NoUnreachableWalker(sourceFile, this.getOptions())); - } -} - -class NoUnreachableWalker extends Lint.RuleWalker { - private hasReturned: boolean; - - constructor(sourceFile: ts.SourceFile, options: Lint.IOptions) { - super(sourceFile, options); - this.hasReturned = false; - } - - public visitNode(node: ts.Node) { - const previousReturned = this.hasReturned; - // function declarations and type alias declarations can be hoisted - // -- so set hasReturned to false until we're done with the function - if (node.kind === ts.SyntaxKind.FunctionDeclaration || node.kind === ts.SyntaxKind.TypeAliasDeclaration) { - this.hasReturned = false; - } - - if (this.hasReturned) { - this.hasReturned = false; - this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING)); - } - - super.visitNode(node); - - // if there is further code after the hoisted function and we returned before that code is unreachable - // so reset hasReturned to its previous state to check for that - if (node.kind === ts.SyntaxKind.FunctionDeclaration || node.kind === ts.SyntaxKind.TypeAliasDeclaration) { - this.hasReturned = previousReturned; - } - } - - public visitBlock(node: ts.Block) { - super.visitBlock(node); - this.hasReturned = false; - } - - public visitCaseClause(node: ts.CaseClause) { - super.visitCaseClause(node); - this.hasReturned = false; - } - - public visitDefaultClause(node: ts.DefaultClause) { - super.visitDefaultClause(node); - this.hasReturned = false; - } - - public visitIfStatement(node: ts.IfStatement) { - this.visitNode(node.expression); - this.visitNode(node.thenStatement); - this.hasReturned = false; - if (node.elseStatement != null) { - this.visitNode(node.elseStatement); - this.hasReturned = false; - } - } - - public visitBreakStatement(node: ts.BreakOrContinueStatement) { - super.visitBreakStatement(node); - this.hasReturned = true; - } - - public visitContinueStatement(node: ts.BreakOrContinueStatement) { - super.visitContinueStatement(node); - this.hasReturned = true; - } - - public visitReturnStatement(node: ts.ReturnStatement) { - super.visitReturnStatement(node); - this.hasReturned = true; - } - - public visitThrowStatement(node: ts.ThrowStatement) { - super.visitThrowStatement(node); - this.hasReturned = true; - } -} diff --git a/test/rules/_integration/react/tslint.json b/test/rules/_integration/react/tslint.json index 4cc8c887f8e..2d1dbf4cb13 100644 --- a/test/rules/_integration/react/tslint.json +++ b/test/rules/_integration/react/tslint.json @@ -5,7 +5,6 @@ "indent": [true, "spaces"], "max-line-length": true, "no-bitwise": true, - "no-unreachable": true, "no-unused-expression": true, "no-unused-variable": true, "no-use-before-declare": true, diff --git a/test/rules/no-unreachable/test.js.lint b/test/rules/no-unreachable/test.js.lint deleted file mode 100644 index 8d6e59e64b4..00000000000 --- a/test/rules/no-unreachable/test.js.lint +++ /dev/null @@ -1,104 +0,0 @@ -// invalid code - -function f1() { - var x = 3; - return; - var y; - ~~~~~~ [unreachable code] - var z; -} - -var f2 = () => { - if (x === 3) { - throw new Error("error"); - "123"; - ~~~~~~ [unreachable code] - } else { - return y; - } - - return 123; -}; - -lab: -for (var i = 0; i < 10; ++i) { - if (i === 3) { - break; - console.log("hi"); - ~~~~~~~~~~~~~~~~~~ [unreachable code] - } else { - continue lab; - i = 4; - ~~~~~~ [unreachable code] - } -} - -// valid code -var f2 = () => { - if (x === 3) { - throw new Error("error"); - } else { - return y; - } - - return 123; -}; - -switch (x) { - case 1: - i = 2; - break; - case 2: - i = 3; - break; - default: - i = 4; - break; -} - -function f4() { - var x = 3; - if (x === 4) return; - else x = 4; - var y = 7; -} - -function f5() { - var x = 3; - if (x === 4) x = 5; - else return; - var y = 7; -} - -function f6() { - hoisted(); - return 0; - - function hoisted() { - return 0; - } -} - -// more invalid code - -function f7() { - hoisted(); - return 0; - - function hoisted() { - return 0; - } - - var y = 7; - ~~~~~~~~~~ [unreachable code] -} - -// more valid code - -function f8() { - try { - return 0; - } catch (e) { - console.log("here"); - } -} diff --git a/test/rules/no-unreachable/test.ts.lint b/test/rules/no-unreachable/test.ts.lint deleted file mode 100644 index 15d51b06714..00000000000 --- a/test/rules/no-unreachable/test.ts.lint +++ /dev/null @@ -1,118 +0,0 @@ -// invalid code - -function f1() { - var x = 3; - return; - var y; - ~~~~~~ [unreachable code] - var z; -} - -var f2 = () => { - if (x === 3) { - throw new Error("error"); - "123"; - ~~~~~~ [unreachable code] - } else { - return y; - } - - return 123; -}; - -lab: -for (var i = 0; i < 10; ++i) { - if (i === 3) { - break; - console.log("hi"); - ~~~~~~~~~~~~~~~~~~ [unreachable code] - } else { - continue lab; - i = 4; - ~~~~~~ [unreachable code] - } -} - -// valid code -var f2 = () => { - if (x === 3) { - throw new Error("error"); - } else { - return y; - } - - return 123; -}; - -switch (x) { - case 1: - i = 2; - break; - case 2: - i = 3; - break; - default: - i = 4; - break; -} - -function f4() { - var x = 3; - if (x === 4) return; - else x = 4; - var y = 7; -} - -function f5() { - var x = 3; - if (x === 4) x = 5; - else return; - var y = 7; -} - -function f6() { - hoisted(); - return 0; - - function hoisted() { - return 0; - } -} - -// more invalid code - -function f7() { - hoisted(); - return 0; - - function hoisted() { - return 0; - } - - var y = 7; - ~~~~~~~~~~ [unreachable code] -} - -// more valid code - -function f8() { - try { - return 0; - } catch (e) { - console.log("here"); - } -} - -// valid case - -function f9() { - return 1; - function bar() {} - type Bar = string; -} - -function f10() { - type Bar = string; - return 1; - function bar() {} -} \ No newline at end of file diff --git a/test/rules/no-unreachable/tslint.json b/test/rules/no-unreachable/tslint.json deleted file mode 100644 index 80eb8a090fb..00000000000 --- a/test/rules/no-unreachable/tslint.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "rules": { - "no-unreachable": true - }, - "jsRules": { - "no-unreachable": true - } -} From 1076f8f557bcd2ee583a346c110241b8fa78ee0e Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Fri, 11 Nov 2016 20:10:31 -0800 Subject: [PATCH 062/111] Added a completed-docs rule (#1644) Fixes https://github.com/Microsoft/tslint-microsoft-contrib/issues/162. Enforces non-blank comments for any or all of classes, functions, methods, and/or properties. --- src/rules/completedDocsRule.ts | 120 ++++++++++++++++++ test/rules/completed-docs/all/test.ts.lint | 59 +++++++++ test/rules/completed-docs/all/tslint.json | 8 ++ .../completed-docs/functions/test.ts.lint | 50 ++++++++ .../completed-docs/functions/tslint.json | 8 ++ 5 files changed, 245 insertions(+) create mode 100644 src/rules/completedDocsRule.ts create mode 100644 test/rules/completed-docs/all/test.ts.lint create mode 100644 test/rules/completed-docs/all/tslint.json create mode 100644 test/rules/completed-docs/functions/test.ts.lint create mode 100644 test/rules/completed-docs/functions/tslint.json diff --git a/src/rules/completedDocsRule.ts b/src/rules/completedDocsRule.ts new file mode 100644 index 00000000000..f157f6f7025 --- /dev/null +++ b/src/rules/completedDocsRule.ts @@ -0,0 +1,120 @@ +/** + * @license + * Copyright 2013 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as ts from "typescript"; + +import * as Lint from "../lint"; + +export class Rule extends Lint.Rules.TypedRule { + /* tslint:disable:object-literal-sort-keys */ + public static metadata: Lint.IRuleMetadata = { + ruleName: "completed-docs", + description: "Enforces documentation for important items be filled out.", + optionsDescription: Lint.Utils.dedent` + Either \`true\` to enable for all, or any of + \`["classes", "functions", "methods", "properties"] + to choose individual ones.\``, + options: { + type: "array", + items: { + type: "string", + enum: ["classes", "functions", "methods", "properties"], + }, + }, + optionExamples: ["true", `[true, ["classes", "functions"]`], + type: "style", + }; + /* tslint:enable:object-literal-sort-keys */ + + public static FAILURE_STRING_EXIST = " must have documentation."; + + public static ARGUMENT_CLASSES = "classes"; + public static ARGUMENT_FUNCTIONS = "functions"; + public static ARGUMENT_METHODS = "methods"; + public static ARGUMENT_PROPERTIES = "properties"; + + public static defaultArguments = [ + Rule.ARGUMENT_CLASSES, + Rule.ARGUMENT_FUNCTIONS, + Rule.ARGUMENT_METHODS, + Rule.ARGUMENT_PROPERTIES, + ]; + + public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] { + const options = this.getOptions(); + const completedDocsWalker = new CompletedDocsWalker(sourceFile, options, program); + + const nodesToCheck = this.getNodesToCheck(options.ruleArguments); + completedDocsWalker.setNodesToCheck(nodesToCheck); + + return this.applyWithWalker(completedDocsWalker); + } + + private getNodesToCheck(ruleArguments: string[]) { + return ruleArguments.length === 0 ? Rule.defaultArguments : ruleArguments; + } +} + +export class CompletedDocsWalker extends Lint.ProgramAwareRuleWalker { + private nodesToCheck: { [i: string]: boolean } = {}; + + public setNodesToCheck(nodesToCheck: string[]): void { + for (const nodeType of nodesToCheck) { + this.nodesToCheck[nodeType] = true; + } + } + + public visitClassDeclaration(node: ts.ClassDeclaration): void { + this.checkComments(node, Rule.ARGUMENT_CLASSES); + super.visitClassDeclaration(node); + } + + public visitFunctionDeclaration(node: ts.FunctionDeclaration): void { + this.checkComments(node, Rule.ARGUMENT_FUNCTIONS); + super.visitFunctionDeclaration(node); + } + + public visitPropertyDeclaration(node: ts.PropertyDeclaration): void { + this.checkComments(node, Rule.ARGUMENT_PROPERTIES); + super.visitPropertyDeclaration(node); + } + + public visitMethodDeclaration(node: ts.MethodDeclaration): void { + this.checkComments(node, Rule.ARGUMENT_METHODS); + super.visitMethodDeclaration(node); + } + + private checkComments(node: ts.Declaration, nodeToCheck: string): void { + if (!this.nodesToCheck[nodeToCheck]) { + return; + } + + const comments = this.getTypeChecker().getSymbolAtLocation(node.name).getDocumentationComment(); + + if (comments.map(comment => comment.text).join("").trim() === "") { + this.addFailure(this.createDocumentationFailure(node, nodeToCheck)); + } + } + + private createDocumentationFailure(node: ts.Declaration, nodeToCheck: string): Lint.RuleFailure { + const start = node.getStart(); + const width = node.getText().split(/\r|\n/g)[0].length; + const description = nodeToCheck[0].toUpperCase() + nodeToCheck.substring(1) + Rule.FAILURE_STRING_EXIST; + + return this.createFailure(start, width, description); + } +} diff --git a/test/rules/completed-docs/all/test.ts.lint b/test/rules/completed-docs/all/test.ts.lint new file mode 100644 index 00000000000..0cdc5889ed6 --- /dev/null +++ b/test/rules/completed-docs/all/test.ts.lint @@ -0,0 +1,59 @@ +class BadClass { +~~~~~~~~~~~~~~~~ [0] + badProperty; + ~~~~~~~~~~~~ [1] + badMethod() { } + ~~~~~~~~~~~~~~~ [2] +} + +/** + * + */ +class EmptyClass { +~~~~~~~~~~~~~~~~~~ [0] + /** + * + */ + emptyProperty; + ~~~~~~~~~~~~~~ [1] + + /** + * + */ + emptyMethod() { } + ~~~~~~~~~~~~~~~~~ [2] +} + +/** + * ... + */ +class GoodClass { + /** + * ... + */ + goodProperty; + + /** + * ... + */ + goodMethod() { } +} + +function BadFunction() { } +~~~~~~~~~~~~~~~~~~~~~~~~~~ [3] + +/** + * + */ +function EmptyFunction() { } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [3] + +/** + * ... + */ +function GoodFunction() { } + +[0]: Classes must have documentation. +[1]: Properties must have documentation. +[2]: Methods must have documentation. +[3]: Functions must have documentation. diff --git a/test/rules/completed-docs/all/tslint.json b/test/rules/completed-docs/all/tslint.json new file mode 100644 index 00000000000..8dce9903cd7 --- /dev/null +++ b/test/rules/completed-docs/all/tslint.json @@ -0,0 +1,8 @@ +{ + "linterOptions": { + "typeCheck": true + }, + "rules": { + "completed-docs": true + } +} diff --git a/test/rules/completed-docs/functions/test.ts.lint b/test/rules/completed-docs/functions/test.ts.lint new file mode 100644 index 00000000000..4fbe4304713 --- /dev/null +++ b/test/rules/completed-docs/functions/test.ts.lint @@ -0,0 +1,50 @@ +class BadClass { + badMember; + badFunction() { } +} + +/** + * + */ +class EmptyClass { + /** + * + */ + emptyProperty; + + /** + * + */ + emptyMethod() { } +} + +/** + * ... + */ +class GoodClass { + /** + * ... + */ + goodProperty; + + /** + * ... + */ + goodMethod() { } +} + +function BadFunction() { } +~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +/** + * + */ +function EmptyFunction() { } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + +/** + * ... + */ +function GoodFunction() { } + +[0]: Functions must have documentation. diff --git a/test/rules/completed-docs/functions/tslint.json b/test/rules/completed-docs/functions/tslint.json new file mode 100644 index 00000000000..47a6dcf43f6 --- /dev/null +++ b/test/rules/completed-docs/functions/tslint.json @@ -0,0 +1,8 @@ +{ + "linterOptions": { + "typeCheck": true + }, + "rules": { + "completed-docs": [true, "functions"] + } +} From 3499fcb6bdbe6f660cbb3e440b7fd07d0baf013f Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 11 Nov 2016 23:12:11 -0500 Subject: [PATCH 063/111] Add required property `typescriptOnly` --- src/rules/completedDocsRule.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rules/completedDocsRule.ts b/src/rules/completedDocsRule.ts index f157f6f7025..a35e3ae8d85 100644 --- a/src/rules/completedDocsRule.ts +++ b/src/rules/completedDocsRule.ts @@ -37,6 +37,7 @@ export class Rule extends Lint.Rules.TypedRule { }, optionExamples: ["true", `[true, ["classes", "functions"]`], type: "style", + typescriptOnly: false, }; /* tslint:enable:object-literal-sort-keys */ From 5dff1711f397a7384c373ccba46ded961435a221 Mon Sep 17 00:00:00 2001 From: Josh Goldberg Date: Sat, 12 Nov 2016 05:43:23 -0800 Subject: [PATCH 064/111] Slightly better error for failed tslint.json parses (#1686) --- src/configuration.ts | 22 ++++++++++++++++++---- src/test.ts | 2 +- src/tslint-cli.ts | 10 ++++++++-- test/config/tslint-invalid.json | 2 ++ test/executable/executableTests.ts | 11 +++++++++++ 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 test/config/tslint-invalid.json diff --git a/src/configuration.ts b/src/configuration.ts index 4a7e178ba9f..c31517529a2 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -32,6 +32,12 @@ export interface IConfigurationFile { rules?: any; } +export interface IConfigurationLoadResult { + error?: Error; + path: string; + results?: IConfigurationFile; +} + export const CONFIG_FILENAME = "tslint.json"; /* tslint:disable:object-literal-key-quotes */ export const DEFAULT_CONFIG = { @@ -98,11 +104,19 @@ const BUILT_IN_CONFIG = /^tslint:(.*)$/; * @param configFile A path to a config file, this can be null if the location of a config is not known * @param inputFileLocation A path to the current file being linted. This is the starting location * of the search for a configuration. - * @returns A TSLint configuration object + * @returns Load status for a TSLint configuration object */ -export function findConfiguration(configFile: string, inputFilePath: string): IConfigurationFile { - const configPath = findConfigurationPath(configFile, inputFilePath); - return loadConfigurationFromPath(configPath); +export function findConfiguration(configFile: string, inputFilePath: string): IConfigurationLoadResult { + const path = findConfigurationPath(configFile, inputFilePath); + const loadResult: IConfigurationLoadResult = { path }; + + try { + loadResult.results = loadConfigurationFromPath(path); + } catch (error) { + loadResult.error = error; + } + + return loadResult; } /** diff --git a/src/test.ts b/src/test.ts index 77d060794c4..f43e6900a56 100644 --- a/src/test.ts +++ b/src/test.ts @@ -47,7 +47,7 @@ export interface TestResult { export function runTest(testDirectory: string, rulesDirectory?: string | string[]): TestResult { const filesToLint = glob.sync(path.join(testDirectory, `**/*${MARKUP_FILE_EXTENSION}`)); - const tslintConfig = Linter.findConfiguration(path.join(testDirectory, "tslint.json"), null); + const tslintConfig = Linter.findConfiguration(path.join(testDirectory, "tslint.json"), null).results; const results: TestResult = { directory: testDirectory, results: {} }; for (const fileToLint of filesToLint) { diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index 6e0f14ced8d..31765a06915 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -257,8 +257,14 @@ const processFiles = (files: string[], program?: ts.Program) => { } const contents = fs.readFileSync(file, "utf8"); - const configuration = findConfiguration(possibleConfigAbsolutePath, file); - linter.lint(file, contents, configuration); + const configLoad = findConfiguration(possibleConfigAbsolutePath, file); + + if (configLoad.results) { + linter.lint(file, contents, configLoad.results); + } else { + console.error(`Failed to load ${configLoad.path}: ${configLoad.error.message}`); + process.exit(1); + } } const lintResult = linter.getResult(); diff --git a/test/config/tslint-invalid.json b/test/config/tslint-invalid.json new file mode 100644 index 00000000000..765e0c1d55e --- /dev/null +++ b/test/config/tslint-invalid.json @@ -0,0 +1,2 @@ +{ + \ No newline at end of file diff --git a/test/executable/executableTests.ts b/test/executable/executableTests.ts index 258ae2ba50a..453a4d141e9 100644 --- a/test/executable/executableTests.ts +++ b/test/executable/executableTests.ts @@ -80,6 +80,17 @@ describe("Executable", function() { done(); }); }); + + it("exits with code 1 if config file is invalid", (done) => { + execCli(["-c", "test/config/tslint-invalid.json", "src/tslint.ts"], (err, stdout, stderr) => { + assert.isNotNull(err, "process should exit with error"); + assert.strictEqual(err.code, 1, "error code should be 1"); + + assert.include(stderr, "Failed to load", "stderr should contain notification about failing to load json"); + assert.strictEqual(stdout, "", "shouldn't contain any output in stdout"); + done(); + }); + }); }); describe("Custom rules", () => { From 668fb95e6d3091af9e254c9b0b4f587b3e1dd81c Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 12 Nov 2016 05:53:48 -0800 Subject: [PATCH 065/111] Extend adjacent-overload-signatures to work in classes, source files, modules, and namespaces. (#1707) --- src/rules/adjacentOverloadSignaturesRule.ts | 65 ++++++++++++++----- .../adjacent-overload-signatures/test.ts.lint | 28 ++++++++ 2 files changed, 75 insertions(+), 18 deletions(-) diff --git a/src/rules/adjacentOverloadSignaturesRule.ts b/src/rules/adjacentOverloadSignaturesRule.ts index 2e42d3364ee..a0de8adbfad 100644 --- a/src/rules/adjacentOverloadSignaturesRule.ts +++ b/src/rules/adjacentOverloadSignaturesRule.ts @@ -42,34 +42,63 @@ export class Rule extends Lint.Rules.AbstractRule { } class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker { + public visitSourceFile(node: ts.SourceFile) { + this.visitStatements(node.statements); + super.visitSourceFile(node); + } + + public visitModuleDeclaration(node: ts.ModuleDeclaration) { + const { body } = node; + if (body && body.kind === ts.SyntaxKind.ModuleBlock) { + this.visitStatements((body as ts.ModuleBlock).statements); + } + super.visitModuleDeclaration(node); + } public visitInterfaceDeclaration(node: ts.InterfaceDeclaration): void { - this.checkNode(node); + this.checkOverloadsAdjacent(node.members, member => member.name && getTextOfPropertyName(member.name)); super.visitInterfaceDeclaration(node); } - public visitTypeLiteral(node: ts.TypeLiteralNode): void { - this.checkNode(node); + public visitClassDeclaration(node: ts.ClassDeclaration) { + this.visitMembers(node.members); + super.visitClassDeclaration(node); + } + + public visitTypeLiteral(node: ts.TypeLiteralNode) { + this.visitMembers(node.members); super.visitTypeLiteral(node); } - public checkNode(node: ts.TypeLiteralNode | ts.InterfaceDeclaration) { - let last: string = undefined; - const seen: { [name: string]: boolean } = {}; - for (const member of node.members) { - if (member.name !== undefined) { - const methodName = getTextOfPropertyName(member.name); - if (methodName !== undefined) { - if (seen.hasOwnProperty(methodName) && last !== methodName) { - this.addFailure(this.createFailure(member.getStart(), member.getWidth(), - Rule.FAILURE_STRING_FACTORY(methodName))); - } - last = methodName; - seen[methodName] = true; - } + private visitStatements(statements: ts.Statement[]) { + this.checkOverloadsAdjacent(statements, statement => { + if (statement.kind === ts.SyntaxKind.FunctionDeclaration) { + const name = (statement as ts.FunctionDeclaration).name; + return name && name.text; } else { - last = undefined; + return undefined; + } + }); + } + + private visitMembers(members: (ts.TypeElement | ts.ClassElement)[]) { + this.checkOverloadsAdjacent(members, member => member.name && getTextOfPropertyName(member.name)); + } + + /** 'getOverloadName' may return undefined for nodes that cannot be overloads, e.g. a `const` declaration. */ + private checkOverloadsAdjacent(overloads: T[], getOverloadName: (node: T) => string | undefined) { + let last: string | undefined = undefined; + const seen: { [name: string]: true } = Object.create(null); + for (const node of overloads) { + const name = getOverloadName(node); + if (name !== undefined) { + if (name in seen && last !== name) { + this.addFailure(this.createFailure(node.getStart(), node.getWidth(), + Rule.FAILURE_STRING_FACTORY(name))); + } + seen[name] = true; } + last = name; } } } diff --git a/test/rules/adjacent-overload-signatures/test.ts.lint b/test/rules/adjacent-overload-signatures/test.ts.lint index c7e10afcb2e..9b65ef3d1b2 100644 --- a/test/rules/adjacent-overload-signatures/test.ts.lint +++ b/test/rules/adjacent-overload-signatures/test.ts.lint @@ -83,3 +83,31 @@ interface b5 { ~~~~~~~~~~~~~~~~~~~ [All 'a' signatures should be adjacent] } } + +// Also works in classes, source files, modules, namespaces + +class C { + a(): void; + b(): void; + a(x: number): void; + ~~~~~~~~~~~~~~~~~~~ [All 'a' signatures should be adjacent] +} + +declare function a(): void; +declare function b(): void; +declare function a(x: number): void; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [All 'a' signatures should be adjacent] + +declare module "m" { + export function a(): void; + export function b(): void; + export function a(x: number): void; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [All 'a' signatures should be adjacent] +} + +declare namespace N { + export function a(): void; + export function b(): void; + export function a(x: number): void; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [All 'a' signatures should be adjacent] +} From 97a2e29f1c4e0c10636af0637c0d7018dac77a4d Mon Sep 17 00:00:00 2001 From: Andrii Dieiev Date: Sun, 13 Nov 2016 15:52:02 +0200 Subject: [PATCH 066/111] Use jsRules for JSX files (#1714) --- src/ruleLoader.ts | 6 ++++-- src/tslintMulti.ts | 13 ++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/ruleLoader.ts b/src/ruleLoader.ts index 01d3ffa3d41..5a4e79860c7 100644 --- a/src/ruleLoader.ts +++ b/src/ruleLoader.ts @@ -75,8 +75,10 @@ export function loadRules(ruleConfiguration: {[name: string]: any}, throw new Error(ERROR_MESSAGE); } else if (notAllowedInJsRules.length > 0) { const JS_ERROR_MESSAGE = ` - Could not apply to JavaScript files for the following rules specified in the configuration: - ${notAllowedInJsRules.join("\n")} + Following rules specified in configuration couldn't be applied to .js or .jsx files: + ${notAllowedInJsRules.join("\n")} + + Make sure to exclude them from "jsRules" section of your tslint.json. `; throw new Error(JS_ERROR_MESSAGE); diff --git a/src/tslintMulti.ts b/src/tslintMulti.ts index 3542da962f1..9a53a053024 100644 --- a/src/tslintMulti.ts +++ b/src/tslintMulti.ts @@ -30,12 +30,12 @@ import { import { EnableDisableRulesWalker } from "./enableDisableRules"; import { findFormatter } from "./formatterLoader"; import { IFormatter } from "./language/formatter/formatter"; -import {Fix, IRule, RuleFailure} from "./language/rule/rule"; +import { Fix, IRule, RuleFailure } from "./language/rule/rule"; import { TypedRule } from "./language/rule/typedRule"; import * as utils from "./language/utils"; import { IMultiLinterOptions, LintResult } from "./lint"; import { loadRules } from "./ruleLoader"; -import { arrayify } from "./utils"; +import { arrayify, dedent } from "./utils"; /** * Linter that can lint multiple files in consecutive runs. @@ -113,7 +113,7 @@ class MultiLinter { hasLinterRun = true; } - // make a 1st pass or make a 2nd pass if there were any fixes because the positions may be off + // make a 1st pass or make a 2nd pass if there were any fixes because the positions may be off if (!hasLinterRun || this.fixes.length > 0) { this.failures = []; for (let rule of enabledRules) { @@ -175,7 +175,7 @@ class MultiLinter { const rulesDirectories = arrayify(this.options.rulesDirectory) .concat(arrayify(configuration.rulesDirectory)); - const isJs = fileName.substr(-3) === ".js"; + const isJs = /\.jsx?$/i.test(fileName); const configurationRules = isJs ? configuration.jsRules : configuration.rules; let configuredRules = loadRules(configurationRules, enableDisableRuleMap, rulesDirectories, isJs); @@ -195,7 +195,10 @@ class MultiLinter { } if (sourceFile === undefined) { - throw new Error(`Invalid source file: ${fileName}. Ensure that the files supplied to lint have a .ts, .tsx, or .js extension.`); + const INVALID_SOURCE_ERROR = dedent` + Invalid source file: ${fileName}. Ensure that the files supplied to lint have a .ts, .tsx, .js or .jsx extension. + `; + throw new Error(INVALID_SOURCE_ERROR); } return sourceFile; } From 5a18f31ddffcd1bf86b391418d0aba809fe82e47 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Mon, 14 Nov 2016 17:48:32 -0500 Subject: [PATCH 067/111] Remove tslint.ts and interfaces associated with Linter Rename tslintMulti.ts -> linter.ts Rename lint.ts -> index.ts Remove old ILinterOptions and rename IMultiLinterOptions ILinterOptions Reference index.js/index.d.ts in package.json --- package.json | 4 +- src/{lint.ts => index.ts} | 18 +--- src/language/rule/abstractRule.ts | 3 +- src/language/walker/programAwareRuleWalker.ts | 2 +- src/language/walker/ruleWalker.ts | 3 +- .../walker/skippableTokenAwareRuleWalker.ts | 2 +- src/{tslintMulti.ts => linter.ts} | 18 ++-- src/rules/adjacentOverloadSignaturesRule.ts | 2 +- src/rules/alignRule.ts | 2 +- src/rules/arrayTypeRule.ts | 2 +- src/rules/arrowParensRule.ts | 2 +- src/rules/banRule.ts | 2 +- src/rules/classNameRule.ts | 2 +- src/rules/commentFormatRule.ts | 2 +- src/rules/completedDocsRule.ts | 2 +- src/rules/curlyRule.ts | 2 +- src/rules/cyclomaticComplexityRule.ts | 2 +- src/rules/eoflineRule.ts | 2 +- src/rules/fileHeaderRule.ts | 2 +- src/rules/forinRule.ts | 2 +- src/rules/indentRule.ts | 2 +- src/rules/interfaceNameRule.ts | 2 +- src/rules/jsdocFormatRule.ts | 2 +- src/rules/labelPositionRule.ts | 2 +- src/rules/linebreakStyleRule.ts | 2 +- src/rules/maxClassesPerFileRule.ts | 2 +- src/rules/maxFileLineCountRule.ts | 2 +- src/rules/maxLineLengthRule.ts | 2 +- src/rules/memberAccessRule.ts | 2 +- src/rules/memberOrderingRule.ts | 2 +- src/rules/newParensRule.ts | 2 +- src/rules/noAngleBracketTypeAssertionRule.ts | 2 +- src/rules/noAnyRule.ts | 2 +- src/rules/noArgRule.ts | 2 +- src/rules/noBitwiseRule.ts | 2 +- src/rules/noConditionalAssignmentRule.ts | 2 +- src/rules/noConsecutiveBlankLinesRule.ts | 2 +- src/rules/noConsoleRule.ts | 2 +- src/rules/noConstructRule.ts | 2 +- src/rules/noDebuggerRule.ts | 2 +- src/rules/noDefaultExportRule.ts | 2 +- src/rules/noDuplicateVariableRule.ts | 2 +- src/rules/noEmptyRule.ts | 2 +- src/rules/noEvalRule.ts | 2 +- src/rules/noForInArrayRule.ts | 2 +- src/rules/noInferrableTypesRule.ts | 2 +- src/rules/noInternalModuleRule.ts | 2 +- src/rules/noInvalidThisRule.ts | 2 +- src/rules/noMergeableNamespaceRule.ts | 2 +- src/rules/noNamespaceRule.ts | 2 +- src/rules/noNullKeywordRule.ts | 2 +- src/rules/noParameterPropertiesRule.ts | 2 +- src/rules/noReferenceRule.ts | 2 +- src/rules/noRequireImportsRule.ts | 2 +- src/rules/noShadowedVariableRule.ts | 2 +- src/rules/noStringLiteralRule.ts | 2 +- src/rules/noSwitchCaseFallThroughRule.ts | 2 +- src/rules/noTrailingWhitespaceRule.ts | 2 +- src/rules/noUnsafeFinallyRule.ts | 2 +- src/rules/noUnusedExpressionRule.ts | 2 +- src/rules/noUnusedNewRule.ts | 2 +- src/rules/noUnusedVariableRule.ts | 2 +- src/rules/noUseBeforeDeclareRule.ts | 2 +- src/rules/noVarKeywordRule.ts | 2 +- src/rules/noVarRequiresRule.ts | 2 +- src/rules/objectLiteralKeyQuotesRule.ts | 2 +- src/rules/objectLiteralShorthandRule.ts | 2 +- src/rules/objectLiteralSortKeysRule.ts | 2 +- src/rules/oneLineRule.ts | 2 +- src/rules/oneVariablePerDeclarationRule.ts | 2 +- src/rules/onlyArrowFunctionsRule.ts | 2 +- src/rules/orderedImportsRule.ts | 2 +- src/rules/preferForOfRule.ts | 2 +- src/rules/quotemarkRule.ts | 2 +- src/rules/radixRule.ts | 2 +- src/rules/restrictPlusOperandsRule.ts | 2 +- src/rules/semicolonRule.ts | 2 +- src/rules/switchDefaultRule.ts | 2 +- src/rules/trailingCommaRule.ts | 2 +- src/rules/tripleEqualsRule.ts | 2 +- src/rules/typedefRule.ts | 2 +- src/rules/typedefWhitespaceRule.ts | 2 +- src/rules/useIsnanRule.ts | 2 +- src/rules/variableNameRule.ts | 2 +- src/rules/whitespaceRule.ts | 2 +- src/test.ts | 9 +- src/tslint-cli.ts | 2 +- src/tslint.ts | 89 ------------------- test/executable/executableTests.ts | 21 +++-- test/lint.ts | 2 +- test/rules/_integration/react/tslint.json | 4 +- 91 files changed, 117 insertions(+), 216 deletions(-) rename src/{lint.ts => index.ts} (79%) rename src/{tslintMulti.ts => linter.ts} (93%) delete mode 100644 src/tslint.ts diff --git a/package.json b/package.json index bf2621800d2..0d14d50c4f1 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "bin": { "tslint": "./bin/tslint" }, - "main": "./lib/tslint", - "typings": "./lib/tslint", + "main": "./lib/tslint/index.js", + "typings": "./lib/tslint/index.d.ts", "repository": { "type": "git", "url": "https://github.com/palantir/tslint.git" diff --git a/src/lint.ts b/src/index.ts similarity index 79% rename from src/lint.ts rename to src/index.ts index c96ab319bb5..23daf1af5cb 100644 --- a/src/lint.ts +++ b/src/index.ts @@ -18,9 +18,9 @@ import * as configuration from "./configuration"; import * as formatters from "./formatters"; import {RuleFailure} from "./language/rule/rule"; +import * as linter from "./linter"; import * as rules from "./rules"; import * as test from "./test"; -import * as linter from "./tslint"; import * as utils from "./utils"; export * from "./language/rule/rule"; @@ -47,21 +47,7 @@ export interface LintResult { output: string; } -export interface ILinterOptionsRaw { - configuration?: any; - formatter?: string | Function; - formattersDirectory?: string; - rulesDirectory?: string | string[]; -} - -export interface ILinterOptions extends ILinterOptionsRaw { - configuration: any; - fix: boolean; - formatter: string | Function; - rulesDirectory: string | string[]; -} - -export interface IMultiLinterOptions { +export interface ILinterOptions { fix: boolean; formatter?: string | Function; formattersDirectory?: string; diff --git a/src/language/rule/abstractRule.ts b/src/language/rule/abstractRule.ts index c05c1f25fb4..1859227dd78 100644 --- a/src/language/rule/abstractRule.ts +++ b/src/language/rule/abstractRule.ts @@ -17,9 +17,8 @@ import * as ts from "typescript"; -import {IOptions} from "../../lint"; import {RuleWalker} from "../walker/ruleWalker"; -import {IDisabledInterval, IRule, IRuleMetadata, RuleFailure} from "./rule"; +import {IDisabledInterval, IOptions, IRule, IRuleMetadata, RuleFailure} from "./rule"; export abstract class AbstractRule implements IRule { public static metadata: IRuleMetadata; diff --git a/src/language/walker/programAwareRuleWalker.ts b/src/language/walker/programAwareRuleWalker.ts index 6b29e1fdcd4..9fc9b678ca1 100644 --- a/src/language/walker/programAwareRuleWalker.ts +++ b/src/language/walker/programAwareRuleWalker.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import {IOptions} from "../../lint"; +import {IOptions} from "../rule/rule"; import {RuleWalker} from "./ruleWalker"; export class ProgramAwareRuleWalker extends RuleWalker { diff --git a/src/language/walker/ruleWalker.ts b/src/language/walker/ruleWalker.ts index bd9a9162eb5..7c17dee7602 100644 --- a/src/language/walker/ruleWalker.ts +++ b/src/language/walker/ruleWalker.ts @@ -17,8 +17,7 @@ import * as ts from "typescript"; -import {IOptions} from "../../lint"; -import {Fix, IDisabledInterval, Replacement, RuleFailure} from "../rule/rule"; +import {Fix, IDisabledInterval, IOptions, Replacement, RuleFailure} from "../rule/rule"; import {doesIntersect} from "../utils"; import {SyntaxWalker} from "./syntaxWalker"; diff --git a/src/language/walker/skippableTokenAwareRuleWalker.ts b/src/language/walker/skippableTokenAwareRuleWalker.ts index a374fad746d..e3a6e6857ce 100644 --- a/src/language/walker/skippableTokenAwareRuleWalker.ts +++ b/src/language/walker/skippableTokenAwareRuleWalker.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import {IOptions} from "../../lint"; +import {IOptions} from "../rule/rule"; import {RuleWalker} from "./ruleWalker"; export class SkippableTokenAwareRuleWalker extends RuleWalker { diff --git a/src/tslintMulti.ts b/src/linter.ts similarity index 93% rename from src/tslintMulti.ts rename to src/linter.ts index 9a53a053024..30e50209ddb 100644 --- a/src/tslintMulti.ts +++ b/src/linter.ts @@ -29,18 +29,18 @@ import { } from "./configuration"; import { EnableDisableRulesWalker } from "./enableDisableRules"; import { findFormatter } from "./formatterLoader"; +import { ILinterOptions, LintResult } from "./index"; import { IFormatter } from "./language/formatter/formatter"; import { Fix, IRule, RuleFailure } from "./language/rule/rule"; import { TypedRule } from "./language/rule/typedRule"; import * as utils from "./language/utils"; -import { IMultiLinterOptions, LintResult } from "./lint"; import { loadRules } from "./ruleLoader"; import { arrayify, dedent } from "./utils"; /** * Linter that can lint multiple files in consecutive runs. */ -class MultiLinter { +class Linter { public static VERSION = "4.0.0-dev"; public static findConfiguration = findConfiguration; @@ -85,8 +85,14 @@ class MultiLinter { return program.getSourceFiles().map(s => s.fileName).filter(l => l.substr(-5) !== ".d.ts"); } - constructor(private options: IMultiLinterOptions, private program?: ts.Program) { - // Empty + constructor(private options: ILinterOptions, private program?: ts.Program) { + if (typeof options !== "object") { + throw new Error("Unknown Linter options type: " + typeof options); + } + if (( options).configuration != null) { + throw new Error("ILinterOptions does not contain the property `configuration` as of version 4. " + + "Did you mean to pass the `IConfigurationFile` object to lint() ? "); + } } public lint(fileName: string, source?: string, configuration: IConfigurationFile = DEFAULT_CONFIG): void { @@ -209,6 +215,6 @@ class MultiLinter { } // tslint:disable-next-line:no-namespace -namespace MultiLinter { } +namespace Linter { } -export = MultiLinter; +export = Linter; diff --git a/src/rules/adjacentOverloadSignaturesRule.ts b/src/rules/adjacentOverloadSignaturesRule.ts index a0de8adbfad..65e44933bbf 100644 --- a/src/rules/adjacentOverloadSignaturesRule.ts +++ b/src/rules/adjacentOverloadSignaturesRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/src/rules/alignRule.ts b/src/rules/alignRule.ts index 031392b800b..65141617e21 100644 --- a/src/rules/alignRule.ts +++ b/src/rules/alignRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/arrayTypeRule.ts b/src/rules/arrayTypeRule.ts index 96918f19d7d..7b294c9e1d2 100644 --- a/src/rules/arrayTypeRule.ts +++ b/src/rules/arrayTypeRule.ts @@ -1,6 +1,6 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_ARRAY = "array"; const OPTION_GENERIC = "generic"; diff --git a/src/rules/arrowParensRule.ts b/src/rules/arrowParensRule.ts index 39a7bdd8485..e3816ed0008 100644 --- a/src/rules/arrowParensRule.ts +++ b/src/rules/arrowParensRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/banRule.ts b/src/rules/banRule.ts index 99500e3a58a..a621978f4be 100644 --- a/src/rules/banRule.ts +++ b/src/rules/banRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/classNameRule.ts b/src/rules/classNameRule.ts index cb5c050ac33..802fdbf41a0 100644 --- a/src/rules/classNameRule.ts +++ b/src/rules/classNameRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/commentFormatRule.ts b/src/rules/commentFormatRule.ts index 31d02991b96..5b074c364e9 100644 --- a/src/rules/commentFormatRule.ts +++ b/src/rules/commentFormatRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_SPACE = "check-space"; const OPTION_LOWERCASE = "check-lowercase"; diff --git a/src/rules/completedDocsRule.ts b/src/rules/completedDocsRule.ts index a35e3ae8d85..b5d2b265ebd 100644 --- a/src/rules/completedDocsRule.ts +++ b/src/rules/completedDocsRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.TypedRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/curlyRule.ts b/src/rules/curlyRule.ts index e7e3f1698df..b86b74b7221 100644 --- a/src/rules/curlyRule.ts +++ b/src/rules/curlyRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/cyclomaticComplexityRule.ts b/src/rules/cyclomaticComplexityRule.ts index f22453389ca..8f4ddc430ed 100644 --- a/src/rules/cyclomaticComplexityRule.ts +++ b/src/rules/cyclomaticComplexityRule.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as Lint from "../lint"; +import * as Lint from "../index"; import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/src/rules/eoflineRule.ts b/src/rules/eoflineRule.ts index 3380ebe849f..65753975df1 100644 --- a/src/rules/eoflineRule.ts +++ b/src/rules/eoflineRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/fileHeaderRule.ts b/src/rules/fileHeaderRule.ts index c7da278ea3d..1434482e00c 100644 --- a/src/rules/fileHeaderRule.ts +++ b/src/rules/fileHeaderRule.ts @@ -1,6 +1,6 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/forinRule.ts b/src/rules/forinRule.ts index 92c10e53b67..2459cabf43d 100644 --- a/src/rules/forinRule.ts +++ b/src/rules/forinRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/indentRule.ts b/src/rules/indentRule.ts index b0ab4942054..5cdb939da04 100644 --- a/src/rules/indentRule.ts +++ b/src/rules/indentRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_USE_TABS = "tabs"; const OPTION_USE_SPACES = "spaces"; diff --git a/src/rules/interfaceNameRule.ts b/src/rules/interfaceNameRule.ts index 431967764e1..5cea37f4c65 100644 --- a/src/rules/interfaceNameRule.ts +++ b/src/rules/interfaceNameRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_ALWAYS = "always-prefix"; const OPTION_NEVER = "never-prefix"; diff --git a/src/rules/jsdocFormatRule.ts b/src/rules/jsdocFormatRule.ts index f27e38afaab..40e8f172804 100644 --- a/src/rules/jsdocFormatRule.ts +++ b/src/rules/jsdocFormatRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/labelPositionRule.ts b/src/rules/labelPositionRule.ts index 1301692f064..30650f1af87 100644 --- a/src/rules/labelPositionRule.ts +++ b/src/rules/labelPositionRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/linebreakStyleRule.ts b/src/rules/linebreakStyleRule.ts index 1f033207805..2fc8bf2a999 100644 --- a/src/rules/linebreakStyleRule.ts +++ b/src/rules/linebreakStyleRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_LINEBREAK_STYLE_CRLF = "CRLF"; const OPTION_LINEBREAK_STYLE_LF = "LF"; diff --git a/src/rules/maxClassesPerFileRule.ts b/src/rules/maxClassesPerFileRule.ts index e8af20c192a..cd7d112b10b 100644 --- a/src/rules/maxClassesPerFileRule.ts +++ b/src/rules/maxClassesPerFileRule.ts @@ -1,4 +1,4 @@ -import * as Lint from "../lint"; +import * as Lint from "../index"; import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/src/rules/maxFileLineCountRule.ts b/src/rules/maxFileLineCountRule.ts index 249c173728f..7995c6d28d5 100644 --- a/src/rules/maxFileLineCountRule.ts +++ b/src/rules/maxFileLineCountRule.ts @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as Lint from "../lint"; +import * as Lint from "../index"; import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/src/rules/maxLineLengthRule.ts b/src/rules/maxLineLengthRule.ts index a029f3938a5..bf356a4bf8e 100644 --- a/src/rules/maxLineLengthRule.ts +++ b/src/rules/maxLineLengthRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/memberAccessRule.ts b/src/rules/memberAccessRule.ts index 972bfc182b3..817b38dc2da 100644 --- a/src/rules/memberAccessRule.ts +++ b/src/rules/memberAccessRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/memberOrderingRule.ts b/src/rules/memberOrderingRule.ts index 4c3bbf09712..9b4201f4cce 100644 --- a/src/rules/memberOrderingRule.ts +++ b/src/rules/memberOrderingRule.ts @@ -16,7 +16,7 @@ */ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; /* start old options */ const OPTION_VARIABLES_BEFORE_FUNCTIONS = "variables-before-functions"; diff --git a/src/rules/newParensRule.ts b/src/rules/newParensRule.ts index 9c774347f06..7feae34434f 100644 --- a/src/rules/newParensRule.ts +++ b/src/rules/newParensRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noAngleBracketTypeAssertionRule.ts b/src/rules/noAngleBracketTypeAssertionRule.ts index dbf8a36069e..ebf381c52a3 100644 --- a/src/rules/noAngleBracketTypeAssertionRule.ts +++ b/src/rules/noAngleBracketTypeAssertionRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noAnyRule.ts b/src/rules/noAnyRule.ts index c8e8db534b2..7346f151838 100644 --- a/src/rules/noAnyRule.ts +++ b/src/rules/noAnyRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noArgRule.ts b/src/rules/noArgRule.ts index e3471baed69..4adb5d727db 100644 --- a/src/rules/noArgRule.ts +++ b/src/rules/noArgRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noBitwiseRule.ts b/src/rules/noBitwiseRule.ts index 62bcd4b0054..bb69045394d 100644 --- a/src/rules/noBitwiseRule.ts +++ b/src/rules/noBitwiseRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noConditionalAssignmentRule.ts b/src/rules/noConditionalAssignmentRule.ts index bf92d769190..89ad7ff898e 100644 --- a/src/rules/noConditionalAssignmentRule.ts +++ b/src/rules/noConditionalAssignmentRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noConsecutiveBlankLinesRule.ts b/src/rules/noConsecutiveBlankLinesRule.ts index 00921213c67..fffa18ee7bf 100644 --- a/src/rules/noConsecutiveBlankLinesRule.ts +++ b/src/rules/noConsecutiveBlankLinesRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { public static DEFAULT_ALLOWED_BLANKS = 1; diff --git a/src/rules/noConsoleRule.ts b/src/rules/noConsoleRule.ts index 92df69e1f72..e024123a764 100644 --- a/src/rules/noConsoleRule.ts +++ b/src/rules/noConsoleRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; import * as BanRule from "./banRule"; export class Rule extends BanRule.Rule { diff --git a/src/rules/noConstructRule.ts b/src/rules/noConstructRule.ts index 5ef72fb2fb9..f687688f0e6 100644 --- a/src/rules/noConstructRule.ts +++ b/src/rules/noConstructRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noDebuggerRule.ts b/src/rules/noDebuggerRule.ts index f6a531f373a..85703395895 100644 --- a/src/rules/noDebuggerRule.ts +++ b/src/rules/noDebuggerRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noDefaultExportRule.ts b/src/rules/noDefaultExportRule.ts index 74fa7f1fa51..ae9c7bcdd05 100644 --- a/src/rules/noDefaultExportRule.ts +++ b/src/rules/noDefaultExportRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noDuplicateVariableRule.ts b/src/rules/noDuplicateVariableRule.ts index c9ac6d72a8c..5d636721831 100644 --- a/src/rules/noDuplicateVariableRule.ts +++ b/src/rules/noDuplicateVariableRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noEmptyRule.ts b/src/rules/noEmptyRule.ts index 753755aa1d0..fe3b216665c 100644 --- a/src/rules/noEmptyRule.ts +++ b/src/rules/noEmptyRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noEvalRule.ts b/src/rules/noEvalRule.ts index d8e62642bff..a2c4194dc0f 100644 --- a/src/rules/noEvalRule.ts +++ b/src/rules/noEvalRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noForInArrayRule.ts b/src/rules/noForInArrayRule.ts index d9abbde92e0..d8e7f949e1c 100644 --- a/src/rules/noForInArrayRule.ts +++ b/src/rules/noForInArrayRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.TypedRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noInferrableTypesRule.ts b/src/rules/noInferrableTypesRule.ts index 252343ae056..257030e7565 100644 --- a/src/rules/noInferrableTypesRule.ts +++ b/src/rules/noInferrableTypesRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_IGNORE_PARMS = "ignore-params"; diff --git a/src/rules/noInternalModuleRule.ts b/src/rules/noInternalModuleRule.ts index bfb4f165a05..751a4e8a75f 100644 --- a/src/rules/noInternalModuleRule.ts +++ b/src/rules/noInternalModuleRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noInvalidThisRule.ts b/src/rules/noInvalidThisRule.ts index d36bc9da871..12e8f2c7ea0 100644 --- a/src/rules/noInvalidThisRule.ts +++ b/src/rules/noInvalidThisRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; interface Scope { inClass: boolean; diff --git a/src/rules/noMergeableNamespaceRule.ts b/src/rules/noMergeableNamespaceRule.ts index be9aa32ef9d..0829b8157c2 100644 --- a/src/rules/noMergeableNamespaceRule.ts +++ b/src/rules/noMergeableNamespaceRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noNamespaceRule.ts b/src/rules/noNamespaceRule.ts index 9152f9496c3..0113eb1d8dd 100644 --- a/src/rules/noNamespaceRule.ts +++ b/src/rules/noNamespaceRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noNullKeywordRule.ts b/src/rules/noNullKeywordRule.ts index aea34aa0377..40e2e1af9f6 100644 --- a/src/rules/noNullKeywordRule.ts +++ b/src/rules/noNullKeywordRule.ts @@ -19,7 +19,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noParameterPropertiesRule.ts b/src/rules/noParameterPropertiesRule.ts index 78e04d0f47e..9561d64fb00 100644 --- a/src/rules/noParameterPropertiesRule.ts +++ b/src/rules/noParameterPropertiesRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noReferenceRule.ts b/src/rules/noReferenceRule.ts index a35b5461957..e20e38744c3 100644 --- a/src/rules/noReferenceRule.ts +++ b/src/rules/noReferenceRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noRequireImportsRule.ts b/src/rules/noRequireImportsRule.ts index 051dc8fe221..45031cc4fc8 100644 --- a/src/rules/noRequireImportsRule.ts +++ b/src/rules/noRequireImportsRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noShadowedVariableRule.ts b/src/rules/noShadowedVariableRule.ts index d78a8eed1ec..e50c3b168df 100644 --- a/src/rules/noShadowedVariableRule.ts +++ b/src/rules/noShadowedVariableRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noStringLiteralRule.ts b/src/rules/noStringLiteralRule.ts index 5fb944d8125..237ce27f94a 100644 --- a/src/rules/noStringLiteralRule.ts +++ b/src/rules/noStringLiteralRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noSwitchCaseFallThroughRule.ts b/src/rules/noSwitchCaseFallThroughRule.ts index f0dfc6cdf2c..218a6bd4dc0 100644 --- a/src/rules/noSwitchCaseFallThroughRule.ts +++ b/src/rules/noSwitchCaseFallThroughRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noTrailingWhitespaceRule.ts b/src/rules/noTrailingWhitespaceRule.ts index b102a612388..51cc186c4f2 100644 --- a/src/rules/noTrailingWhitespaceRule.ts +++ b/src/rules/noTrailingWhitespaceRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noUnsafeFinallyRule.ts b/src/rules/noUnsafeFinallyRule.ts index 9c88031cfff..1a5664ba4f1 100644 --- a/src/rules/noUnsafeFinallyRule.ts +++ b/src/rules/noUnsafeFinallyRule.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as Lint from "../lint"; +import * as Lint from "../index"; import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/src/rules/noUnusedExpressionRule.ts b/src/rules/noUnusedExpressionRule.ts index ae863c0b3af..83c51a222c9 100644 --- a/src/rules/noUnusedExpressionRule.ts +++ b/src/rules/noUnusedExpressionRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noUnusedNewRule.ts b/src/rules/noUnusedNewRule.ts index a5cfba4b5ea..283e3ac57bd 100644 --- a/src/rules/noUnusedNewRule.ts +++ b/src/rules/noUnusedNewRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; import { NoUnusedExpressionWalker } from "./noUnusedExpressionRule"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/src/rules/noUnusedVariableRule.ts b/src/rules/noUnusedVariableRule.ts index 5e464d69629..280e0bc2a76 100644 --- a/src/rules/noUnusedVariableRule.ts +++ b/src/rules/noUnusedVariableRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_REACT = "react"; const OPTION_CHECK_PARAMETERS = "check-parameters"; diff --git a/src/rules/noUseBeforeDeclareRule.ts b/src/rules/noUseBeforeDeclareRule.ts index 8654658a8ae..a173360422c 100644 --- a/src/rules/noUseBeforeDeclareRule.ts +++ b/src/rules/noUseBeforeDeclareRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noVarKeywordRule.ts b/src/rules/noVarKeywordRule.ts index 6b285918cfb..d022c85cf96 100644 --- a/src/rules/noVarKeywordRule.ts +++ b/src/rules/noVarKeywordRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/noVarRequiresRule.ts b/src/rules/noVarRequiresRule.ts index b13bc5824da..ac5ada9913a 100644 --- a/src/rules/noVarRequiresRule.ts +++ b/src/rules/noVarRequiresRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/objectLiteralKeyQuotesRule.ts b/src/rules/objectLiteralKeyQuotesRule.ts index c63dac4e59a..d05bea1d79a 100644 --- a/src/rules/objectLiteralKeyQuotesRule.ts +++ b/src/rules/objectLiteralKeyQuotesRule.ts @@ -1,4 +1,4 @@ -import * as Lint from "../lint"; +import * as Lint from "../index"; import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/src/rules/objectLiteralShorthandRule.ts b/src/rules/objectLiteralShorthandRule.ts index 813be2fc97d..ed59daa3828 100644 --- a/src/rules/objectLiteralShorthandRule.ts +++ b/src/rules/objectLiteralShorthandRule.ts @@ -1,4 +1,4 @@ -import * as Lint from "../lint"; +import * as Lint from "../index"; import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/src/rules/objectLiteralSortKeysRule.ts b/src/rules/objectLiteralSortKeysRule.ts index 5ff902585eb..48b9567e3ec 100644 --- a/src/rules/objectLiteralSortKeysRule.ts +++ b/src/rules/objectLiteralSortKeysRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/oneLineRule.ts b/src/rules/oneLineRule.ts index d89cf241708..561c31d78c7 100644 --- a/src/rules/oneLineRule.ts +++ b/src/rules/oneLineRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_BRACE = "check-open-brace"; const OPTION_CATCH = "check-catch"; diff --git a/src/rules/oneVariablePerDeclarationRule.ts b/src/rules/oneVariablePerDeclarationRule.ts index 409ef4286ed..f8c056ba4e9 100644 --- a/src/rules/oneVariablePerDeclarationRule.ts +++ b/src/rules/oneVariablePerDeclarationRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_IGNORE_FOR_LOOP = "ignore-for-loop"; diff --git a/src/rules/onlyArrowFunctionsRule.ts b/src/rules/onlyArrowFunctionsRule.ts index b2306b990ff..5d144558884 100644 --- a/src/rules/onlyArrowFunctionsRule.ts +++ b/src/rules/onlyArrowFunctionsRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_ALLOW_DECLARATIONS = "allow-declarations"; diff --git a/src/rules/orderedImportsRule.ts b/src/rules/orderedImportsRule.ts index 48868edbe2f..b241f212e21 100644 --- a/src/rules/orderedImportsRule.ts +++ b/src/rules/orderedImportsRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/preferForOfRule.ts b/src/rules/preferForOfRule.ts index 3fe891bfe06..68183ea3c49 100644 --- a/src/rules/preferForOfRule.ts +++ b/src/rules/preferForOfRule.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import * as Lint from "../lint"; +import * as Lint from "../index"; import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/src/rules/quotemarkRule.ts b/src/rules/quotemarkRule.ts index a82237b3610..ab159c96be5 100644 --- a/src/rules/quotemarkRule.ts +++ b/src/rules/quotemarkRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; enum QuoteMark { SINGLE_QUOTES, diff --git a/src/rules/radixRule.ts b/src/rules/radixRule.ts index 28174d603f4..e35521fc226 100644 --- a/src/rules/radixRule.ts +++ b/src/rules/radixRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/restrictPlusOperandsRule.ts b/src/rules/restrictPlusOperandsRule.ts index 68cd410a967..d5fe764fad6 100644 --- a/src/rules/restrictPlusOperandsRule.ts +++ b/src/rules/restrictPlusOperandsRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.TypedRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/semicolonRule.ts b/src/rules/semicolonRule.ts index e8a2bb1149b..b9be0599be4 100644 --- a/src/rules/semicolonRule.ts +++ b/src/rules/semicolonRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_ALWAYS = "always"; const OPTION_NEVER = "never"; diff --git a/src/rules/switchDefaultRule.ts b/src/rules/switchDefaultRule.ts index fb9f9d50419..0d8524c9c61 100644 --- a/src/rules/switchDefaultRule.ts +++ b/src/rules/switchDefaultRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/trailingCommaRule.ts b/src/rules/trailingCommaRule.ts index 42514e14e5f..35d50dd61bd 100644 --- a/src/rules/trailingCommaRule.ts +++ b/src/rules/trailingCommaRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/tripleEqualsRule.ts b/src/rules/tripleEqualsRule.ts index 67d4dc7e62a..24b04cd9622 100644 --- a/src/rules/tripleEqualsRule.ts +++ b/src/rules/tripleEqualsRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_ALLOW_NULL_CHECK = "allow-null-check"; const OPTION_ALLOW_UNDEFINED_CHECK = "allow-undefined-check"; diff --git a/src/rules/typedefRule.ts b/src/rules/typedefRule.ts index 6c4a7f0c4e6..7e0f5b7dce0 100644 --- a/src/rules/typedefRule.ts +++ b/src/rules/typedefRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/typedefWhitespaceRule.ts b/src/rules/typedefWhitespaceRule.ts index 205c8d41f82..ea76e575ef5 100644 --- a/src/rules/typedefWhitespaceRule.ts +++ b/src/rules/typedefWhitespaceRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; /* tslint:disable:object-literal-sort-keys */ const SPACE_OPTIONS = { diff --git a/src/rules/useIsnanRule.ts b/src/rules/useIsnanRule.ts index d0902c2fa34..651b30f4265 100644 --- a/src/rules/useIsnanRule.ts +++ b/src/rules/useIsnanRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/variableNameRule.ts b/src/rules/variableNameRule.ts index 18028d786f6..77165f54efa 100644 --- a/src/rules/variableNameRule.ts +++ b/src/rules/variableNameRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const BANNED_KEYWORDS = ["any", "Number", "number", "String", "string", "Boolean", "boolean", "Undefined", "undefined"]; diff --git a/src/rules/whitespaceRule.ts b/src/rules/whitespaceRule.ts index 63465e70912..3e9bc272042 100644 --- a/src/rules/whitespaceRule.ts +++ b/src/rules/whitespaceRule.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; -import * as Lint from "../lint"; +import * as Lint from "../index"; const OPTION_BRANCH = "check-branch"; const OPTION_DECL = "check-decl"; diff --git a/src/test.ts b/src/test.ts index f43e6900a56..de9f71d133d 100644 --- a/src/test.ts +++ b/src/test.ts @@ -24,9 +24,9 @@ import * as ts from "typescript"; import {Fix} from "./language/rule/rule"; import {createCompilerOptions} from "./language/utils"; +import * as Linter from "./linter"; import {LintError} from "./test/lintError"; import * as parse from "./test/parse"; -import * as Linter from "./tslint"; const MARKUP_FILE_EXTENSION = ".lint"; const FIXES_FILE_EXTENSION = ".fix"; @@ -86,13 +86,14 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[ } const lintOptions = { - configuration: tslintConfig, + fix: false, formatter: "prose", formattersDirectory: "", rulesDirectory, }; - const linter = new Linter(fileBasename, fileTextWithoutMarkup, lintOptions, program); - const failures = linter.lint().failures; + const linter = new Linter(lintOptions, program); + linter.lint(fileBasename, fileTextWithoutMarkup, tslintConfig); + const failures = linter.getResult().failures; const errorsFromLinter: LintError[] = failures.map((failure) => { const startLineAndCharacter = failure.getStartPosition().getLineAndCharacter(); const endLineAndCharacter = failure.getEndPosition().getLineAndCharacter(); diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index 31765a06915..5ec6e28e46e 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -26,8 +26,8 @@ import { DEFAULT_CONFIG, findConfiguration, } from "./configuration"; +import * as Linter from "./linter"; import { consoleTestResultHandler, runTest } from "./test"; -import * as Linter from "./tslintMulti"; import { updateNotifierCheck } from "./updateNotifier"; let processed = optimist diff --git a/src/tslint.ts b/src/tslint.ts deleted file mode 100644 index da9b53b106d..00000000000 --- a/src/tslint.ts +++ /dev/null @@ -1,89 +0,0 @@ -/** - * @license - * Copyright 2013 Palantir Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import * as ts from "typescript"; - -import { - DEFAULT_CONFIG, - findConfiguration, - findConfigurationPath, - getRulesDirectories, - loadConfigurationFromPath, -} from "./configuration"; -import { ILinterOptions, ILinterOptionsRaw, LintResult } from "./lint"; -import * as MultiLinter from "./tslintMulti"; -import { arrayify } from "./utils"; - -/** - * Linter that can lint exactly one file. - */ -class Linter { - public static VERSION = MultiLinter.VERSION; - - public static findConfiguration = findConfiguration; - public static findConfigurationPath = findConfigurationPath; - public static getRulesDirectories = getRulesDirectories; - public static loadConfigurationFromPath = loadConfigurationFromPath; - - private options: ILinterOptions; - - /** - * Creates a TypeScript program object from a tsconfig.json file path and optional project directory. - */ - public static createProgram(configFile: string, projectDirectory?: string): ts.Program { - return MultiLinter.createProgram(configFile, projectDirectory); - } - - /** - * Returns a list of source file names from a TypeScript program. This includes all referenced - * files and excludes declaration (".d.ts") files. - */ - public static getFileNames(program: ts.Program): string[] { - return MultiLinter.getFileNames(program); - } - - constructor(private fileName: string, private source: string, options: ILinterOptionsRaw, private program?: ts.Program) { - this.options = this.computeFullOptions(options); - } - - public lint(): LintResult { - const multiLinter: MultiLinter = new MultiLinter(this.options, this.program); - multiLinter.lint(this.fileName, this.source, this.options.configuration); - return multiLinter.getResult(); - } - - private computeFullOptions(options: ILinterOptionsRaw = {}): ILinterOptions { - if (typeof options !== "object") { - throw new Error("Unknown Linter options type: " + typeof options); - } - - let { configuration, formatter, formattersDirectory, rulesDirectory } = options; - - return { - configuration: configuration || DEFAULT_CONFIG, - fix: false, - formatter: formatter || "prose", - formattersDirectory, - rulesDirectory: arrayify(rulesDirectory).concat(arrayify(configuration.rulesDirectory)), - }; - } -} - -// tslint:disable-next-line:no-namespace -namespace Linter {} - -export = Linter; diff --git a/test/executable/executableTests.ts b/test/executable/executableTests.ts index 453a4d141e9..08655c96b56 100644 --- a/test/executable/executableTests.ts +++ b/test/executable/executableTests.ts @@ -68,21 +68,20 @@ describe("Executable", function() { describe("Configuration file", () => { it("exits with code 0 if relative path is passed without `./`", (done) => { - execCli(["-c", "test/config/tslint-almost-empty.json", "src/tslint.ts"], (err) => { + execCli(["-c", "test/config/tslint-almost-empty.json", "src/test.ts"], (err) => { assert.isNull(err, "process should exit without an error"); done(); }); }); it("exits with code 0 if config file that extends relative config file", (done) => { - execCli(["-c", "test/config/tslint-extends-package-no-mod.json", "src/tslint.ts"], (err) => { + execCli(["-c", "test/config/tslint-extends-package-no-mod.json", "src/test.ts"], (err) => { assert.isNull(err, "process should exit without an error"); done(); - }); - }); + }); }); it("exits with code 1 if config file is invalid", (done) => { - execCli(["-c", "test/config/tslint-invalid.json", "src/tslint.ts"], (err, stdout, stderr) => { + execCli(["-c", "test/config/tslint-invalid.json", "src/test.ts"], (err, stdout, stderr) => { assert.isNotNull(err, "process should exit with error"); assert.strictEqual(err.code, 1, "error code should be 1"); @@ -95,7 +94,7 @@ describe("Executable", function() { describe("Custom rules", () => { it("exits with code 1 if nonexisting custom rules directory is passed", (done) => { - execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./someRandomDir", "src/tslint.ts"], (err) => { + execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./someRandomDir", "src/test.ts"], (err) => { assert.isNotNull(err, "process should exit with error"); assert.strictEqual(err.code, 1, "error code should be 1"); done(); @@ -103,7 +102,7 @@ describe("Executable", function() { }); it("exits with code 2 if custom rules directory is passed and file contains lint errors", (done) => { - execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "src/tslint.ts"], (err) => { + execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "src/test.ts"], (err) => { assert.isNotNull(err, "process should exit with error"); assert.strictEqual(err.code, 2, "error code should be 2"); done(); @@ -111,7 +110,7 @@ describe("Executable", function() { }); it("exits with code 2 if custom rules directory is specified in config file and file contains lint errors", (done) => { - execCli(["-c", "./test/config/tslint-custom-rules-with-dir.json", "src/tslint.ts"], (err) => { + execCli(["-c", "./test/config/tslint-custom-rules-with-dir.json", "src/test.ts"], (err) => { assert.isNotNull(err, "process should exit with error"); assert.strictEqual(err.code, 2, "error code should be 2"); done(); @@ -139,7 +138,7 @@ describe("Executable", function() { describe("--force flag", () => { it("exits with code 0 if `--force` flag is passed", (done) => { - execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "--force", "src/tslint.ts"], + execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "--force", "src/test.ts"], (err, stdout) => { assert.isNull(err, "process should exit without an error"); assert.include(stdout, "failure", "errors should be reported"); @@ -249,7 +248,7 @@ describe("Executable", function() { // when glob pattern is passed in double quotes in npm script `process.env` will contain: // on Windows - pattern string without any quotes // on Linux - pattern string without any quotes (glob is not expanded) - execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "src/**/tslint.ts"], (err) => { + execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "src/**/test.ts"], (err) => { assert.isNotNull(err, "process should exit with error"); assert.strictEqual(err.code, 2, "error code should be 2"); done(); @@ -260,7 +259,7 @@ describe("Executable", function() { // when glob pattern is passed in single quotes in npm script `process.env` will contain: // on Windows - pattern string wrapped in single quotes // on Linux - pattern string without any quotes (glob is not expanded) - execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "'src/**/tslint.ts'"], (err) => { + execCli(["-c", "./test/config/tslint-custom-rules.json", "-r", "./test/files/custom-rules", "'src/**/test.ts'"], (err) => { assert.isNotNull(err, "process should exit with error"); assert.strictEqual(err.code, 2, "error code should be 2"); done(); diff --git a/test/lint.ts b/test/lint.ts index baa9d0fd203..b3336b4473d 100644 --- a/test/lint.ts +++ b/test/lint.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -export * from "../src/lint"; +export * from "../src/index"; import * as TestUtils from "./utils"; diff --git a/test/rules/_integration/react/tslint.json b/test/rules/_integration/react/tslint.json index 2d1dbf4cb13..9af967c5098 100644 --- a/test/rules/_integration/react/tslint.json +++ b/test/rules/_integration/react/tslint.json @@ -3,13 +3,13 @@ "curly": true, "eofline": true, "indent": [true, "spaces"], - "max-line-length": true, + "max-line-length": [true, 120], "no-bitwise": true, "no-unused-expression": true, "no-unused-variable": true, "no-use-before-declare": true, "quotemark": [true, "double"], - "semicolon": true, + "semicolon": [true, "always"], "whitespace": [true, "check-branch", "check-decl", From f3289f686194ed491bdbfcba5bbc5fbfd9c34b96 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Mon, 14 Nov 2016 19:00:41 -0500 Subject: [PATCH 068/111] ignore errors in update notifier (can happen if running without executable since package.json can't be found) --- src/updateNotifier.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/updateNotifier.ts b/src/updateNotifier.ts index e740a7fb27d..c6ee143192e 100644 --- a/src/updateNotifier.ts +++ b/src/updateNotifier.ts @@ -18,19 +18,23 @@ // tslint:disable-next-line:no-var-requires const updateNotifier = require("update-notifier"); // tslint:disable-next-line:no-var-requires -const pkg = require("../package.json"); export function updateNotifierCheck(): void { - // Check every 3 days for a new version - const cacheTime: number = 1000 * 60 * 60 * 24 * 3; - const changeLogUrl: string = "https://github.com/palantir/tslint/blob/master/CHANGELOG.md"; - const notifier = updateNotifier({ - pkg, - updateCheckInterval: cacheTime, - }); + try { + const pkg = require("../package.json"); + // Check every 3 days for a new version + const cacheTime: number = 1000 * 60 * 60 * 24 * 3; + const changeLogUrl: string = "https://github.com/palantir/tslint/blob/master/CHANGELOG.md"; + const notifier = updateNotifier({ + pkg, + updateCheckInterval: cacheTime, + }); - if (notifier.notify && notifier.update) { - let message: string = `TSLint update available v${notifier.update.current} → v${notifier.update.latest} \n See ${changeLogUrl}`; - notifier.notify({ message }); + if (notifier.notify && notifier.update) { + let message: string = `TSLint update available v${notifier.update.current} → v${notifier.update.latest} \n See ${changeLogUrl}`; + notifier.notify({ message }); + } + } catch (error) { + // ignore error } }; From 089b71177aa537f2faaf9e47d338d874c6216ffe Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Mon, 14 Nov 2016 19:39:38 -0500 Subject: [PATCH 069/111] Update built-in rule configurations (#1717) --- src/configs/latest.ts | 10 ---------- src/configs/recommended.ts | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/configs/latest.ts b/src/configs/latest.ts index 3579a7245e8..a6523eb76c1 100644 --- a/src/configs/latest.ts +++ b/src/configs/latest.ts @@ -16,16 +16,6 @@ */ export const rules = { - "adjacent-overload-signatures": true, - "cyclomatic-complexity": false, - "no-unsafe-finally": true, - "object-literal-key-quotes": [true, "as-needed"], - "object-literal-shorthand": true, - "only-arrow-functions": [true, "allow-declarations"], - "ordered-imports": [true, { - "import-sources-order": "case-insensitive", - "named-imports-order": "lowercase-last", - }], }; // work around "extends" being a keyword diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index fefef3add69..528a451da46 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -17,15 +17,19 @@ /* tslint:disable:object-literal-key-quotes */ export const rules = { + "adjacent-overload-signatures": true, "align": [true, "parameters", "statements", ], + "array-type": [true, "array-simple"], + "arrow-parens": true, "class-name": true, "comment-format": [true, "check-space", ], "curly": true, + "cyclomatic-complexity": false, "eofline": true, "forin": true, "indent": [true, "spaces"], @@ -38,6 +42,7 @@ export const rules = { { "order": "statics-first" }, ], "new-parens": true, + "max-classes-per-file": [true, 1], "no-any": false, "no-arg": true, "no-bitwise": true, @@ -64,6 +69,7 @@ export const rules = { "no-string-literal": true, "no-switch-case-fall-through": false, "no-trailing-whitespace": true, + "no-unsafe-finally": true, "no-unused-expression": true, "no-unused-new": true, // deprecated as of v4.0 @@ -72,6 +78,8 @@ export const rules = { "no-use-before-declare": false, "no-var-keyword": true, "no-var-requires": true, + "object-literal-key-quotes": [true, "as-needed"], + "object-literal-shorthand": true, "object-literal-sort-keys": true, "one-line": [true, "check-catch", @@ -83,6 +91,12 @@ export const rules = { "one-variable-per-declaration": [true, "ignore-for-loop", ], + "only-arrow-functions": [true, "allow-declarations"], + "ordered-imports": [true, { + "import-sources-order": "case-insensitive", + "named-imports-order": "case-insensitive", + }], + "prefer-for-of": true, "quotemark": [true, "double", "avoid-escape"], "radix": true, "semicolon": [true, "always"], From d0351ad1a965fb9bc41c1f6387261c9f260e3af6 Mon Sep 17 00:00:00 2001 From: Jordan Hawker Date: Mon, 14 Nov 2016 18:40:53 -0800 Subject: [PATCH 070/111] Removes `no-duplicate-variable` from the default & recommended configs (#1718) --- src/configs/recommended.ts | 1 - src/configuration.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index 528a451da46..b5bcb23e808 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -58,7 +58,6 @@ export const rules = { ], "no-construct": true, "no-debugger": true, - "no-duplicate-variable": true, "no-empty": true, "no-eval": true, "no-internal-module": true, diff --git a/src/configuration.ts b/src/configuration.ts index c31517529a2..0d88c5454da 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -66,7 +66,6 @@ export const DEFAULT_CONFIG = { "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, From 67ba6f87c2b6e1d2bc5d1a428531e1a8cfe072e9 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Tue, 15 Nov 2016 14:27:11 -0500 Subject: [PATCH 071/111] Update docs for 4.0.0 (#1645) --- docs/_data/rules.json | 385 +++++++++++++----- .../adjacent-overload-signatures/index.html | 4 +- docs/rules/align/index.html | 5 +- docs/rules/array-type/index.html | 34 ++ docs/rules/arrow-parens/index.html | 3 +- docs/rules/ban/index.html | 41 +- docs/rules/class-name/index.html | 3 +- docs/rules/comment-format/index.html | 5 +- docs/rules/completed-docs/index.html | 38 ++ docs/rules/curly/index.html | 3 +- docs/rules/cyclomatic-complexity/index.html | 39 ++ docs/rules/eofline/index.html | 3 +- docs/rules/file-header/index.html | 7 +- docs/rules/forin/index.html | 3 +- docs/rules/indent/index.html | 5 +- docs/rules/interface-name/index.html | 5 +- docs/rules/jsdoc-format/index.html | 3 +- docs/rules/label-position/index.html | 3 +- docs/rules/linebreak-style/index.html | 5 +- docs/rules/max-classes-per-file/index.html | 41 ++ docs/rules/max-file-line-count/index.html | 5 +- docs/rules/max-line-length/index.html | 5 +- docs/rules/member-access/index.html | 5 +- docs/rules/member-ordering/index.html | 5 +- docs/rules/new-parens/index.html | 3 +- .../index.html | 3 +- docs/rules/no-any/index.html | 3 +- docs/rules/no-arg/index.html | 3 +- docs/rules/no-bitwise/index.html | 3 +- .../no-conditional-assignment/index.html | 3 +- .../no-consecutive-blank-lines/index.html | 19 +- docs/rules/no-console/index.html | 5 +- docs/rules/no-construct/index.html | 3 +- docs/rules/no-debugger/index.html | 3 +- docs/rules/no-default-export/index.html | 3 +- docs/rules/no-duplicate-variable/index.html | 3 +- docs/rules/no-empty/index.html | 3 +- docs/rules/no-eval/index.html | 3 +- docs/rules/no-for-in-array/index.html | 3 +- docs/rules/no-inferrable-types/index.html | 5 +- docs/rules/no-internal-module/index.html | 3 +- docs/rules/no-invalid-this/index.html | 5 +- docs/rules/no-mergeable-namespace/index.html | 3 +- docs/rules/no-namespace/index.html | 5 +- docs/rules/no-null-keyword/index.html | 3 +- docs/rules/no-parameter-properties/index.html | 9 +- docs/rules/no-reference/index.html | 3 +- docs/rules/no-require-imports/index.html | 3 +- docs/rules/no-shadowed-variable/index.html | 3 +- docs/rules/no-string-literal/index.html | 3 +- .../no-switch-case-fall-through/index.html | 3 +- docs/rules/no-trailing-whitespace/index.html | 3 +- docs/rules/no-unsafe-finally/index.html | 3 +- docs/rules/no-unused-expression/index.html | 3 +- docs/rules/no-unused-new/index.html | 3 +- docs/rules/no-unused-variable/index.html | 6 +- docs/rules/no-use-before-declare/index.html | 3 +- docs/rules/no-var-keyword/index.html | 3 +- docs/rules/no-var-requires/index.html | 3 +- .../object-literal-key-quotes/index.html | 5 +- .../rules/object-literal-shorthand/index.html | 4 +- .../rules/object-literal-sort-keys/index.html | 3 +- docs/rules/one-line/index.html | 5 +- .../one-variable-per-declaration/index.html | 5 +- docs/rules/only-arrow-functions/index.html | 5 +- docs/rules/ordered-imports/index.html | 15 +- docs/rules/prefer-for-of/index.html | 14 + docs/rules/quotemark/index.html | 5 +- docs/rules/radix/index.html | 3 +- docs/rules/restrict-plus-operands/index.html | 3 +- docs/rules/semicolon/index.html | 7 +- docs/rules/switch-default/index.html | 3 +- docs/rules/trailing-comma/index.html | 13 +- docs/rules/triple-equals/index.html | 5 +- docs/rules/typedef-whitespace/index.html | 5 +- docs/rules/typedef/index.html | 5 +- docs/rules/use-isnan/index.html | 3 +- docs/rules/variable-name/index.html | 5 +- docs/rules/whitespace/index.html | 5 +- 79 files changed, 667 insertions(+), 244 deletions(-) create mode 100644 docs/rules/array-type/index.html create mode 100644 docs/rules/completed-docs/index.html create mode 100644 docs/rules/cyclomatic-complexity/index.html create mode 100644 docs/rules/max-classes-per-file/index.html create mode 100644 docs/rules/prefer-for-of/index.html diff --git a/docs/_data/rules.json b/docs/_data/rules.json index a431bba3525..5f80eed62c1 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -7,7 +7,9 @@ "optionExamples": [ "true" ], - "type": "typescript" + "rationale": "Improves readability and organization by grouping naturally related items together.", + "type": "typescript", + "typescriptOnly": true }, { "ruleName": "align", @@ -30,7 +32,28 @@ "optionExamples": [ "[true, \"parameters\", \"statements\"]" ], - "type": "style" + "type": "style", + "typescriptOnly": false + }, + { + "ruleName": "array-type", + "description": "Requires using either 'T[]' or 'Array' for arrays.", + "optionsDescription": "\nOne of the following arguments must be provided:\n\n* `\"array\"` enforces use of `T[]` for all types T.\n* `\"generic\"` enforces use of `Array` for all types T.\n* `\"array-simple\"` enforces use of `T[]` if `T` is a simple type (primitive or type reference).", + "options": { + "type": "string", + "enum": [ + "array", + "generic", + "array-simple" + ] + }, + "optionExamples": [ + "[true, array]", + "[true, generic]", + "[true, array-simple]" + ], + "type": "style", + "typescriptOnly": true }, { "ruleName": "arrow-parens", @@ -41,34 +64,29 @@ "optionExamples": [ "true" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "ban", - "description": "Bans the use of specific functions.", - "descriptionDetails": "At this time, there is no way to disable global methods with this rule.", - "optionsDescription": "A list of `['object', 'method', 'optional explanation here']` which ban `object.method()`.", + "description": "Bans the use of specific functions or global methods.", + "optionsDescription": "\nA list of `['object', 'method', 'optional explanation here']` or `['globalMethod']` which ban `object.method()` \nor respectively `globalMethod()`.", "options": { "type": "list", "listType": { "type": "array", - "arrayMembers": [ - { - "type": "string" - }, - { - "type": "string" - }, - { - "type": "string" - } - ] + "items": { + "type": "string" + }, + "minLength": 1, + "maxLength": 3 } }, "optionExamples": [ - "[true, [\"someObject\", \"someFunction\"], [\"someObject\", \"otherFunction\", \"Optional explanation\"]]" + "[true, [\"someGlobalMethod\"], [\"someObject\", \"someFunction\"], \n [\"someObject\", \"otherFunction\", \"Optional explanation\"]]" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "class-name", @@ -79,7 +97,8 @@ "optionExamples": [ "true" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "comment-format", @@ -102,7 +121,31 @@ "optionExamples": [ "[true, \"check-space\", \"check-lowercase\"]" ], - "type": "style" + "type": "style", + "typescriptOnly": false + }, + { + "ruleName": "completed-docs", + "description": "Enforces documentation for important items be filled out.", + "optionsDescription": "\nEither `true` to enable for all, or any of\n`[\"classes\", \"functions\", \"methods\", \"properties\"]\nto choose individual ones.`", + "options": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "classes", + "functions", + "methods", + "properties" + ] + } + }, + "optionExamples": [ + "true", + "[true, [\"classes\", \"functions\"]" + ], + "type": "style", + "typescriptOnly": false }, { "ruleName": "curly", @@ -113,7 +156,25 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false + }, + { + "ruleName": "cyclomatic-complexity", + "description": "Enforces a threshold of cyclomatic complexity.", + "descriptionDetails": "\nCyclomatic complexity is assessed for each function of any type. A starting value of 1\nis assigned and this value is then incremented for every statement which can branch the\ncontrol flow within the function. The following statements and expressions contribute\nto cyclomatic complexity:\n* `catch`\n* `if` and `? :`\n* `||` and `&&` due to short-circuit evaluation\n* `for`, `for in` and `for of` loops\n* `while` and `do while` loops", + "rationale": "\nCyclomatic complexity is a code metric which indicates the level of complexity in a\nfunction. High cyclomatic complexity indicates confusing code which may be prone to\nerrors or difficult to modify.", + "optionsDescription": "\nAn optional upper limit for cyclomatic complexity can be specified. If no limit option\nis provided a default value of $(Rule.DEFAULT_THRESHOLD) will be used.", + "options": { + "type": "number", + "minimum": "$(Rule.MINIMUM_THRESHOLD)" + }, + "optionExamples": [ + "true", + "[true, 20]" + ], + "type": "maintainability", + "typescriptOnly": false }, { "ruleName": "eofline", @@ -124,7 +185,8 @@ "optionExamples": [ "true" ], - "type": "maintainability" + "type": "maintainability", + "typescriptOnly": false }, { "ruleName": "file-header", @@ -134,9 +196,10 @@ "type": "string" }, "optionExamples": [ - "\"true\", \"Copyright \\d{4}\"" + "[true, \"Copyright \\\\d{4}\"]" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "forin", @@ -147,7 +210,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "indent", @@ -164,7 +228,8 @@ "optionExamples": [ "[true, \"spaces\"]" ], - "type": "maintainability" + "type": "maintainability", + "typescriptOnly": false }, { "ruleName": "interface-name", @@ -182,7 +247,8 @@ "[true, \"always-prefix\"]", "[true, \"never-prefix\"]" ], - "type": "style" + "type": "style", + "typescriptOnly": true }, { "ruleName": "jsdoc-format", @@ -194,7 +260,8 @@ "optionExamples": [ "true" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "label-position", @@ -206,7 +273,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "linebreak-style", @@ -223,7 +291,32 @@ "[true, \"LF\"]", "[true, \"CRLF\"]" ], - "type": "maintainability" + "type": "maintainability", + "typescriptOnly": false + }, + { + "ruleName": "max-classes-per-file", + "description": "\nA file may not contain more than the specified number of classes \nif the file name does not match the \"ignore-filename-pattern\" option", + "rationale": "\nEnsures that files have a single responsibility so that that classes each exist in their own files", + "optionsDescription": "\nThe one required argument is an integer indicating the maximum number of classes that can appear in a file.", + "options": { + "type": "array", + "items": [ + { + "type": "number", + "minimum": 1 + } + ], + "additionalItems": false, + "minLength": 1, + "maxLength": 2 + }, + "optionExamples": [ + "[true, 1]", + "[true, 5]" + ], + "type": "maintainability", + "typescriptOnly": false }, { "ruleName": "max-file-line-count", @@ -237,7 +330,8 @@ "optionExamples": [ "[true, 300]" ], - "type": "maintainability" + "type": "maintainability", + "typescriptOnly": false }, { "ruleName": "max-line-length", @@ -251,7 +345,8 @@ "optionExamples": [ "[true, 120]" ], - "type": "maintainability" + "type": "maintainability", + "typescriptOnly": false }, { "ruleName": "member-access", @@ -274,7 +369,8 @@ "true", "[true, \"check-accessor\"]" ], - "type": "typescript" + "type": "typescript", + "typescriptOnly": true }, { "ruleName": "member-ordering", @@ -324,7 +420,8 @@ "optionExamples": [ "[true, { \"order\": \"fields-first\" }]" ], - "type": "typescript" + "type": "typescript", + "typescriptOnly": true }, { "ruleName": "new-parens", @@ -335,7 +432,8 @@ "optionExamples": [ "true" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "no-angle-bracket-type-assertion", @@ -346,7 +444,8 @@ "optionExamples": [ "true" ], - "type": "style" + "type": "style", + "typescriptOnly": true }, { "ruleName": "no-any", @@ -357,7 +456,8 @@ "optionExamples": [ "true" ], - "type": "typescript" + "type": "typescript", + "typescriptOnly": true }, { "ruleName": "no-arg", @@ -368,7 +468,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-bitwise", @@ -380,7 +481,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-conditional-assignment", @@ -392,18 +494,24 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-consecutive-blank-lines", - "description": "Disallows more than one blank line in a row.", + "description": "Disallows one or more blank lines in a row.", "rationale": "Helps maintain a readable style in your codebase.", - "optionsDescription": "Not configurable.", - "options": {}, + "optionsDescription": "\nAn optional number of maximum allowed sequential blanks can be specified. If no value\nis provided, a default of $(Rule.DEFAULT_ALLOWED_BLANKS) will be used.", + "options": { + "type": "number", + "minimum": "$(Rule.MINIMUM_ALLOWED_BLANKS)" + }, "optionExamples": [ - "true" + "true", + "[true, 2]" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "no-console", @@ -419,7 +527,8 @@ "optionExamples": [ "[true, \"log\", \"error\"]" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-construct", @@ -431,7 +540,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-debugger", @@ -442,7 +552,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-default-export", @@ -454,7 +565,8 @@ "optionExamples": [ "true" ], - "type": "maintainability" + "type": "maintainability", + "typescriptOnly": false }, { "ruleName": "no-duplicate-variable", @@ -466,7 +578,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-empty", @@ -478,7 +591,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-eval", @@ -489,7 +603,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-for-in-array", @@ -501,7 +616,8 @@ "true" ], "requiresTypeInfo": true, - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-inferrable-types", @@ -523,7 +639,8 @@ "true", "[true, \"ignore-params\"]" ], - "type": "typescript" + "type": "typescript", + "typescriptOnly": true }, { "ruleName": "no-internal-module", @@ -534,7 +651,8 @@ "optionExamples": [ "true" ], - "type": "typescript" + "type": "typescript", + "typescriptOnly": true }, { "ruleName": "no-invalid-this", @@ -556,7 +674,8 @@ "true", "[true, \"check-function-in-method\"]" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-mergeable-namespace", @@ -566,7 +685,8 @@ "optionExamples": [ "true" ], - "type": "maintainability" + "type": "maintainability", + "typescriptOnly": true }, { "ruleName": "no-namespace", @@ -589,7 +709,8 @@ "true", "[true, \"allow-declarations\"]" ], - "type": "typescript" + "type": "typescript", + "typescriptOnly": true }, { "ruleName": "no-null-keyword", @@ -600,18 +721,20 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-parameter-properties", - "description": "Disallows parameter properties.", + "description": "Disallows parameter properties in class constructors.", "rationale": "\nParameter properties can be confusing to those new to TS as they are less explicit\nthan other ways of declaring and initializing class members.", "optionsDescription": "Not configurable.", "options": null, "optionExamples": [ "true" ], - "type": "style" + "type": "style", + "typescriptOnly": true }, { "ruleName": "no-reference", @@ -622,7 +745,8 @@ "optionExamples": [ "true" ], - "type": "typescript" + "type": "typescript", + "typescriptOnly": false }, { "ruleName": "no-require-imports", @@ -633,7 +757,8 @@ "optionExamples": [ "true" ], - "type": "maintainability" + "type": "maintainability", + "typescriptOnly": false }, { "ruleName": "no-shadowed-variable", @@ -644,7 +769,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-string-literal", @@ -655,7 +781,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-switch-case-fall-through", @@ -667,7 +794,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-trailing-whitespace", @@ -678,18 +806,8 @@ "optionExamples": [ "true" ], - "type": "maintainability" - }, - { - "ruleName": "no-unreachable", - "description": "Disallows unreachable code after `break`, `catch`, `throw`, and `return` statements.", - "rationale": "Unreachable code is often indication of a logic error.", - "optionsDescription": "Not configurable.", - "options": null, - "optionExamples": [ - "true" - ], - "type": "functionality" + "type": "maintainability", + "typescriptOnly": false }, { "ruleName": "no-unsafe-finally", @@ -701,7 +819,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-unused-expression", @@ -713,7 +832,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-unused-new", @@ -725,10 +845,12 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-unused-variable", + "deprecationMessage": "Use the compiler options --noUnusedParameters and --noUnusedLocals instead.", "description": "Disallows unused imports, variables, functions and private class members.", "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.", "options": { @@ -760,7 +882,8 @@ "[true, \"react\"]", "[true, {\"ignore-pattern\": \"^_\"}]" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": true }, { "ruleName": "no-use-before-declare", @@ -771,7 +894,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-var-keyword", @@ -782,7 +906,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "no-var-requires", @@ -793,7 +918,8 @@ "optionExamples": [ "true" ], - "type": "typescript" + "type": "typescript", + "typescriptOnly": true }, { "ruleName": "object-literal-key-quotes", @@ -811,16 +937,19 @@ "[true, \"as-needed\"]", "[true, \"always\"]" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "object-literal-shorthand", "description": "Enforces use of ES6 object literal shorthand when possible.", + "optionsDescription": "Not configurable.", "options": null, "optionExamples": [ "true" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "object-literal-sort-keys", @@ -831,7 +960,8 @@ "optionExamples": [ "true" ], - "type": "maintainability" + "type": "maintainability", + "typescriptOnly": false }, { "ruleName": "one-line", @@ -855,7 +985,8 @@ "optionExamples": [ "[true, \"check-catch\", \"check-finally\", \"check-else\"]" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "one-variable-per-declaration", @@ -876,7 +1007,8 @@ "true", "[true, \"ignore-for-loop\"]" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "only-arrow-functions", @@ -898,13 +1030,14 @@ "true", "[true, \"allow-declarations\"]" ], - "type": "typescript" + "type": "typescript", + "typescriptOnly": false }, { "ruleName": "ordered-imports", "description": "Requires that import statements be alphabetized.", "descriptionDetails": "\nEnforce a consistent ordering for ES6 imports:\n- Named imports must be alphabetized (i.e. \"import {A, B, C} from \"foo\";\")\n - The exact ordering can be controlled by the named-imports-order option.\n - \"longName as name\" imports are ordered by \"longName\".\n- Import sources must be alphabetized within groups, i.e.:\n import * as foo from \"a\";\n import * as bar from \"b\";\n- Groups of imports are delineated by blank lines. You can use these to group imports\n however you like, e.g. by first- vs. third-party or thematically.", - "optionsDescription": "\nYou may set the `\"import-sources-order\"` option to control the ordering of source\nimports (the `\"foo\"` in `import {A, B, C} from \"foo\"`).\n\nPossible values for `\"import-sources-order\"` are:\n* `\"case-insensitive'`: Correct order is `\"Bar\"`, `\"baz\"`, `\"Foo\"`. (This is the default.)\n* `\"lowercase-first\"`: Correct order is `\"baz\"`, `\"Bar\"`, `\"Foo\"`.\n* `\"lowercase-last\"`: Correct order is `\"Bar\"`, `\"Foo\"`, `\"baz\"`.\n\nYou may set the `\"named-imports-order\"` option to control the ordering of named\nimports (the `{A, B, C}` in `import {A, B, C} from \"foo\"`).\n\nPossible values for `\"named-imports-order\"` are:\n\n* `\"case-insensitive'`: Correct order is `{A, b, C}`. (This is the default.)\n* `\"lowercase-first\"`: Correct order is `{b, A, C}`.\n* `\"lowercase-last\"`: Correct order is `{A, C, b}`.\n\n ", + "optionsDescription": "\nYou may set the `\"import-sources-order\"` option to control the ordering of source\nimports (the `\"foo\"` in `import {A, B, C} from \"foo\"`).\n\nPossible values for `\"import-sources-order\"` are:\n* `\"case-insensitive'`: Correct order is `\"Bar\"`, `\"baz\"`, `\"Foo\"`. (This is the default.)\n* `\"lowercase-first\"`: Correct order is `\"baz\"`, `\"Bar\"`, `\"Foo\"`.\n* `\"lowercase-last\"`: Correct order is `\"Bar\"`, `\"Foo\"`, `\"baz\"`.\n* `\"any\"`: Allow any order.\n\nYou may set the `\"named-imports-order\"` option to control the ordering of named\nimports (the `{A, B, C}` in `import {A, B, C} from \"foo\"`).\n\nPossible values for `\"named-imports-order\"` are:\n\n* `\"case-insensitive'`: Correct order is `{A, b, C}`. (This is the default.)\n* `\"lowercase-first\"`: Correct order is `{b, A, C}`.\n* `\"lowercase-last\"`: Correct order is `{A, C, b}`.\n* `\"any\"`: Allow any order.\n\n ", "options": { "type": "object", "properties": { @@ -913,7 +1046,8 @@ "enum": [ "case-insensitive", "lowercase-first", - "lowercase-last" + "lowercase-last", + "any" ] }, "named-imports-order": { @@ -921,7 +1055,8 @@ "enum": [ "case-insensitive", "lowercase-first", - "lowercase-last" + "lowercase-last", + "any" ] } }, @@ -931,7 +1066,20 @@ "true", "[true, {\"import-sources-order\": \"lowercase-last\", \"named-imports-order\": \"lowercase-first\"}]" ], - "type": "style" + "type": "style", + "typescriptOnly": false + }, + { + "ruleName": "prefer-for-of", + "description": "Recommends a 'for-of' loop over a standard 'for' loop if the index is only used to access the array being iterated.", + "rationale": "A for(... of ...) loop is easier to implement and read when the index is not needed.", + "optionsDescription": "Not configurable.", + "options": null, + "optionExamples": [ + "true" + ], + "type": "typescript", + "typescriptOnly": false }, { "ruleName": "quotemark", @@ -956,7 +1104,8 @@ "[true, \"single\", \"avoid-escape\"]", "[true, \"single\", \"jsx-double\"]" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "radix", @@ -967,7 +1116,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "restrict-plus-operands", @@ -978,12 +1128,13 @@ "true" ], "type": "functionality", + "typescriptOnly": false, "requiresTypeInfo": true }, { "ruleName": "semicolon", "description": "Enforces consistent semicolon usage at the end of every statement.", - "optionsDescription": "\nOne of the following arguments must be provided:\n\n* `\"always\"` enforces semicolons at the end of every statement.\n* `\"never\"` disallows semicolons at the end of every statement except for when they are necessary.\n\nThe following arguments may be optionaly provided:\n* `\"ignore-interfaces\"` skips checking semicolons at the end of interface members.", + "optionsDescription": "\nOne of the following arguments must be provided:\n\n* `\"always\"` enforces semicolons at the end of every statement.\n* `\"never\"` disallows semicolons at the end of every statement except for when they are necessary.\n\nThe following arguments may be optionaly provided:\n* `\"ignore-interfaces\"` skips checking semicolons at the end of interface members.\n* `\"ignore-bound-class-methods\"` skips checking semicolons at the end of bound class methods.", "options": { "type": "array", "items": [ @@ -1006,9 +1157,11 @@ "optionExamples": [ "[true, \"always\"]", "[true, \"never\"]", - "[true, \"always\", \"ignore-interfaces\"]" + "[true, \"always\", \"ignore-interfaces\"]", + "[true, \"always\", \"ignore-bound-class-methods\"]" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "switch-default", @@ -1018,12 +1171,13 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "trailing-comma", - "description": "Requires or disallows trailing commas in array and object literals, destructuring assignments and named imports.", - "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 and named import statements.", + "description": "\nRequires or disallows trailing commas in array and object literals, destructuring assignments, function and tuple typings,\nnamed imports and 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 and tuple typings, named import statements\nand function parameters.", "options": { "type": "object", "properties": { @@ -1047,7 +1201,8 @@ "optionExamples": [ "[true, {\"multiline\": \"always\", \"singleline\": \"never\"}]" ], - "type": "maintainability" + "type": "maintainability", + "typescriptOnly": false }, { "ruleName": "triple-equals", @@ -1070,7 +1225,8 @@ "[true, \"allow-null-check\"]", "[true, \"allow-undefined-check\"]" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "typedef", @@ -1096,7 +1252,8 @@ "optionExamples": [ "[true, \"call-signature\", \"parameter\", \"member-variable-declaration\"]" ], - "type": "typescript" + "type": "typescript", + "typescriptOnly": true }, { "ruleName": "typedef-whitespace", @@ -1204,7 +1361,8 @@ "optionExamples": [ "\n[\n true,\n {\n \"call-signature\": \"nospace\",\n \"index-signature\": \"nospace\",\n \"parameter\": \"nospace\",\n \"property-declaration\": \"nospace\",\n \"variable-declaration\": \"nospace\"\n },\n {\n \"call-signature\": \"onespace\",\n \"index-signature\": \"onespace\",\n \"parameter\": \"onespace\",\n \"property-declaration\": \"onespace\",\n \"variable-declaration\": \"onespace\"\n }\n]" ], - "type": "typescript" + "type": "typescript", + "typescriptOnly": true }, { "ruleName": "use-isnan", @@ -1215,7 +1373,8 @@ "optionExamples": [ "true" ], - "type": "functionality" + "type": "functionality", + "typescriptOnly": false }, { "ruleName": "variable-name", @@ -1239,7 +1398,8 @@ "optionExamples": [ "[true, \"ban-keywords\", \"check-format\", \"allow-leading-underscore\"]" ], - "type": "style" + "type": "style", + "typescriptOnly": false }, { "ruleName": "whitespace", @@ -1266,6 +1426,7 @@ "optionExamples": [ "[true, \"check-branch\", \"check-operator\", \"check-typecast\"]" ], - "type": "style" + "type": "style", + "typescriptOnly": false } -] +] \ No newline at end of file diff --git a/docs/rules/adjacent-overload-signatures/index.html b/docs/rules/adjacent-overload-signatures/index.html index d518c87ec36..3506700140c 100644 --- a/docs/rules/adjacent-overload-signatures/index.html +++ b/docs/rules/adjacent-overload-signatures/index.html @@ -5,8 +5,10 @@ options: null optionExamples: - 'true' +rationale: Improves readability and organization by grouping naturally related items together. type: typescript -optionsJSON: 'null' +typescriptOnly: true layout: rule title: 'Rule: adjacent-overload-signatures' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/align/index.html b/docs/rules/align/index.html index 966ce1556f1..f42a1421e39 100644 --- a/docs/rules/align/index.html +++ b/docs/rules/align/index.html @@ -22,6 +22,9 @@ optionExamples: - '[true, "parameters", "statements"]' type: style +typescriptOnly: false +layout: rule +title: 'Rule: align' optionsJSON: |- { "type": "array", @@ -36,6 +39,4 @@ "minLength": 1, "maxLength": 3 } -layout: rule -title: 'Rule: align' --- \ No newline at end of file diff --git a/docs/rules/array-type/index.html b/docs/rules/array-type/index.html new file mode 100644 index 00000000000..5a5cfe27139 --- /dev/null +++ b/docs/rules/array-type/index.html @@ -0,0 +1,34 @@ +--- +ruleName: array-type +description: 'Requires using either ''T[]'' or ''Array'' for arrays.' +optionsDescription: |- + + One of the following arguments must be provided: + + * `"array"` enforces use of `T[]` for all types T. + * `"generic"` enforces use of `Array` for all types T. + * `"array-simple"` enforces use of `T[]` if `T` is a simple type (primitive or type reference). +options: + type: string + enum: + - array + - generic + - array-simple +optionExamples: + - '[true, array]' + - '[true, generic]' + - '[true, array-simple]' +type: style +typescriptOnly: true +layout: rule +title: 'Rule: array-type' +optionsJSON: |- + { + "type": "string", + "enum": [ + "array", + "generic", + "array-simple" + ] + } +--- \ No newline at end of file diff --git a/docs/rules/arrow-parens/index.html b/docs/rules/arrow-parens/index.html index 0d356c11994..e77c46b1d1a 100644 --- a/docs/rules/arrow-parens/index.html +++ b/docs/rules/arrow-parens/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: style -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: arrow-parens' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/ban/index.html b/docs/rules/ban/index.html index 279cc53ec8a..f3005766579 100644 --- a/docs/rules/ban/index.html +++ b/docs/rules/ban/index.html @@ -1,37 +1,36 @@ --- ruleName: ban -description: Bans the use of specific functions. -descriptionDetails: 'At this time, there is no way to disable global methods with this rule.' -optionsDescription: 'A list of `[''object'', ''method'', ''optional explanation here'']` which ban `object.method()`.' +description: Bans the use of specific functions or global methods. +optionsDescription: |- + + A list of `['object', 'method', 'optional explanation here']` or `['globalMethod']` which ban `object.method()` + or respectively `globalMethod()`. options: type: list listType: type: array - arrayMembers: - - type: string - - type: string - - type: string + items: + type: string + minLength: 1 + maxLength: 3 optionExamples: - - '[true, ["someObject", "someFunction"], ["someObject", "otherFunction", "Optional explanation"]]' + - |- + [true, ["someGlobalMethod"], ["someObject", "someFunction"], + ["someObject", "otherFunction", "Optional explanation"]] type: functionality +typescriptOnly: false +layout: rule +title: 'Rule: ban' optionsJSON: |- { "type": "list", "listType": { "type": "array", - "arrayMembers": [ - { - "type": "string" - }, - { - "type": "string" - }, - { - "type": "string" - } - ] + "items": { + "type": "string" + }, + "minLength": 1, + "maxLength": 3 } } -layout: rule -title: 'Rule: ban' --- \ No newline at end of file diff --git a/docs/rules/class-name/index.html b/docs/rules/class-name/index.html index 43fdc02f882..0ae19d6e8be 100644 --- a/docs/rules/class-name/index.html +++ b/docs/rules/class-name/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: style -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: class-name' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/comment-format/index.html b/docs/rules/comment-format/index.html index 1e170990e20..cbc4b7813a0 100644 --- a/docs/rules/comment-format/index.html +++ b/docs/rules/comment-format/index.html @@ -23,6 +23,9 @@ optionExamples: - '[true, "check-space", "check-lowercase"]' type: style +typescriptOnly: false +layout: rule +title: 'Rule: comment-format' optionsJSON: |- { "type": "array", @@ -37,6 +40,4 @@ "minLength": 1, "maxLength": 3 } -layout: rule -title: 'Rule: comment-format' --- \ No newline at end of file diff --git a/docs/rules/completed-docs/index.html b/docs/rules/completed-docs/index.html new file mode 100644 index 00000000000..128a663d3db --- /dev/null +++ b/docs/rules/completed-docs/index.html @@ -0,0 +1,38 @@ +--- +ruleName: completed-docs +description: Enforces documentation for important items be filled out. +optionsDescription: |- + + Either `true` to enable for all, or any of + `["classes", "functions", "methods", "properties"] + to choose individual ones.` +options: + type: array + items: + type: string + enum: + - classes + - functions + - methods + - properties +optionExamples: + - 'true' + - '[true, ["classes", "functions"]' +type: style +typescriptOnly: false +layout: rule +title: 'Rule: completed-docs' +optionsJSON: |- + { + "type": "array", + "items": { + "type": "string", + "enum": [ + "classes", + "functions", + "methods", + "properties" + ] + } + } +--- \ No newline at end of file diff --git a/docs/rules/curly/index.html b/docs/rules/curly/index.html index 1ce4a8eedac..5e9075da7fe 100644 --- a/docs/rules/curly/index.html +++ b/docs/rules/curly/index.html @@ -17,7 +17,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: curly' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/cyclomatic-complexity/index.html b/docs/rules/cyclomatic-complexity/index.html new file mode 100644 index 00000000000..4eddc29446d --- /dev/null +++ b/docs/rules/cyclomatic-complexity/index.html @@ -0,0 +1,39 @@ +--- +ruleName: cyclomatic-complexity +description: Enforces a threshold of cyclomatic complexity. +descriptionDetails: |- + + Cyclomatic complexity is assessed for each function of any type. A starting value of 1 + is assigned and this value is then incremented for every statement which can branch the + control flow within the function. The following statements and expressions contribute + to cyclomatic complexity: + * `catch` + * `if` and `? :` + * `||` and `&&` due to short-circuit evaluation + * `for`, `for in` and `for of` loops + * `while` and `do while` loops +rationale: |- + + Cyclomatic complexity is a code metric which indicates the level of complexity in a + function. High cyclomatic complexity indicates confusing code which may be prone to + errors or difficult to modify. +optionsDescription: |- + + An optional upper limit for cyclomatic complexity can be specified. If no limit option + is provided a default value of $(Rule.DEFAULT_THRESHOLD) will be used. +options: + type: number + minimum: $(Rule.MINIMUM_THRESHOLD) +optionExamples: + - 'true' + - '[true, 20]' +type: maintainability +typescriptOnly: false +layout: rule +title: 'Rule: cyclomatic-complexity' +optionsJSON: |- + { + "type": "number", + "minimum": "$(Rule.MINIMUM_THRESHOLD)" + } +--- \ No newline at end of file diff --git a/docs/rules/eofline/index.html b/docs/rules/eofline/index.html index 81ddde9865e..985298840d8 100644 --- a/docs/rules/eofline/index.html +++ b/docs/rules/eofline/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: maintainability -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: eofline' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/file-header/index.html b/docs/rules/file-header/index.html index 188c64955fc..7cc981b6bb8 100644 --- a/docs/rules/file-header/index.html +++ b/docs/rules/file-header/index.html @@ -5,12 +5,13 @@ options: type: string optionExamples: - - '"true", "Copyright \d{4}"' + - '[true, "Copyright \\d{4}"]' type: style +typescriptOnly: false +layout: rule +title: 'Rule: file-header' optionsJSON: |- { "type": "string" } -layout: rule -title: 'Rule: file-header' --- \ No newline at end of file diff --git a/docs/rules/forin/index.html b/docs/rules/forin/index.html index 9ec8b7baa00..e41a69c1068 100644 --- a/docs/rules/forin/index.html +++ b/docs/rules/forin/index.html @@ -18,7 +18,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: forin' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/indent/index.html b/docs/rules/indent/index.html index 5962ea11c0a..28d55c314b5 100644 --- a/docs/rules/indent/index.html +++ b/docs/rules/indent/index.html @@ -19,6 +19,9 @@ optionExamples: - '[true, "spaces"]' type: maintainability +typescriptOnly: false +layout: rule +title: 'Rule: indent' optionsJSON: |- { "type": "string", @@ -27,6 +30,4 @@ "spaces" ] } -layout: rule -title: 'Rule: indent' --- \ No newline at end of file diff --git a/docs/rules/interface-name/index.html b/docs/rules/interface-name/index.html index 81a93b61162..91375f2a0ec 100644 --- a/docs/rules/interface-name/index.html +++ b/docs/rules/interface-name/index.html @@ -17,6 +17,9 @@ - '[true, "always-prefix"]' - '[true, "never-prefix"]' type: style +typescriptOnly: true +layout: rule +title: 'Rule: interface-name' optionsJSON: |- { "type": "string", @@ -25,6 +28,4 @@ "never-prefix" ] } -layout: rule -title: 'Rule: interface-name' --- \ No newline at end of file diff --git a/docs/rules/jsdoc-format/index.html b/docs/rules/jsdoc-format/index.html index de7cd5e2731..269ceab1b0a 100644 --- a/docs/rules/jsdoc-format/index.html +++ b/docs/rules/jsdoc-format/index.html @@ -15,7 +15,8 @@ optionExamples: - 'true' type: style -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: jsdoc-format' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/label-position/index.html b/docs/rules/label-position/index.html index bd706278995..d82ae64eab8 100644 --- a/docs/rules/label-position/index.html +++ b/docs/rules/label-position/index.html @@ -12,7 +12,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: label-position' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/linebreak-style/index.html b/docs/rules/linebreak-style/index.html index f5c695c8072..363c990858e 100644 --- a/docs/rules/linebreak-style/index.html +++ b/docs/rules/linebreak-style/index.html @@ -16,6 +16,9 @@ - '[true, "LF"]' - '[true, "CRLF"]' type: maintainability +typescriptOnly: false +layout: rule +title: 'Rule: linebreak-style' optionsJSON: |- { "type": "string", @@ -24,6 +27,4 @@ "CRLF" ] } -layout: rule -title: 'Rule: linebreak-style' --- \ No newline at end of file diff --git a/docs/rules/max-classes-per-file/index.html b/docs/rules/max-classes-per-file/index.html new file mode 100644 index 00000000000..1827aab9dc8 --- /dev/null +++ b/docs/rules/max-classes-per-file/index.html @@ -0,0 +1,41 @@ +--- +ruleName: max-classes-per-file +description: |- + + A file may not contain more than the specified number of classes + if the file name does not match the "ignore-filename-pattern" option +rationale: |- + + Ensures that files have a single responsibility so that that classes each exist in their own files +optionsDescription: |- + + The one required argument is an integer indicating the maximum number of classes that can appear in a file. +options: + type: array + items: + - type: number + minimum: 1 + additionalItems: false + minLength: 1 + maxLength: 2 +optionExamples: + - '[true, 1]' + - '[true, 5]' +type: maintainability +typescriptOnly: false +layout: rule +title: 'Rule: max-classes-per-file' +optionsJSON: |- + { + "type": "array", + "items": [ + { + "type": "number", + "minimum": 1 + } + ], + "additionalItems": false, + "minLength": 1, + "maxLength": 2 + } +--- \ No newline at end of file diff --git a/docs/rules/max-file-line-count/index.html b/docs/rules/max-file-line-count/index.html index bdb39e39c5d..88556799827 100644 --- a/docs/rules/max-file-line-count/index.html +++ b/docs/rules/max-file-line-count/index.html @@ -12,11 +12,12 @@ optionExamples: - '[true, 300]' type: maintainability +typescriptOnly: false +layout: rule +title: 'Rule: max-file-line-count' optionsJSON: |- { "type": "number", "minimum": "1" } -layout: rule -title: 'Rule: max-file-line-count' --- \ No newline at end of file diff --git a/docs/rules/max-line-length/index.html b/docs/rules/max-line-length/index.html index e11807c5528..fdd451fce6a 100644 --- a/docs/rules/max-line-length/index.html +++ b/docs/rules/max-line-length/index.html @@ -13,11 +13,12 @@ optionExamples: - '[true, 120]' type: maintainability +typescriptOnly: false +layout: rule +title: 'Rule: max-line-length' optionsJSON: |- { "type": "number", "minimum": "1" } -layout: rule -title: 'Rule: max-line-length' --- \ No newline at end of file diff --git a/docs/rules/member-access/index.html b/docs/rules/member-access/index.html index 006c20c4dfd..ae5c4991013 100644 --- a/docs/rules/member-access/index.html +++ b/docs/rules/member-access/index.html @@ -21,6 +21,9 @@ - 'true' - '[true, "check-accessor"]' type: typescript +typescriptOnly: true +layout: rule +title: 'Rule: member-access' optionsJSON: |- { "type": "array", @@ -34,6 +37,4 @@ "minLength": 0, "maxLength": 2 } -layout: rule -title: 'Rule: member-access' --- \ No newline at end of file diff --git a/docs/rules/member-ordering/index.html b/docs/rules/member-ordering/index.html index 3ea91700dbe..295ced8cb52 100644 --- a/docs/rules/member-ordering/index.html +++ b/docs/rules/member-ordering/index.html @@ -60,6 +60,9 @@ optionExamples: - '[true, { "order": "fields-first" }]' type: typescript +typescriptOnly: true +layout: rule +title: 'Rule: member-ordering' optionsJSON: |- { "type": "object", @@ -101,6 +104,4 @@ }, "additionalProperties": false } -layout: rule -title: 'Rule: member-ordering' --- \ No newline at end of file diff --git a/docs/rules/new-parens/index.html b/docs/rules/new-parens/index.html index d1cdf11ab25..58aa3916f69 100644 --- a/docs/rules/new-parens/index.html +++ b/docs/rules/new-parens/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: style -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: new-parens' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-angle-bracket-type-assertion/index.html b/docs/rules/no-angle-bracket-type-assertion/index.html index 36bf52bb044..7353488bdba 100644 --- a/docs/rules/no-angle-bracket-type-assertion/index.html +++ b/docs/rules/no-angle-bracket-type-assertion/index.html @@ -11,7 +11,8 @@ optionExamples: - 'true' type: style -optionsJSON: 'null' +typescriptOnly: true layout: rule title: 'Rule: no-angle-bracket-type-assertion' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-any/index.html b/docs/rules/no-any/index.html index 08a9394329b..9e96a7e560a 100644 --- a/docs/rules/no-any/index.html +++ b/docs/rules/no-any/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: typescript -optionsJSON: 'null' +typescriptOnly: true layout: rule title: 'Rule: no-any' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-arg/index.html b/docs/rules/no-arg/index.html index 388c3194d36..a49b3401ff5 100644 --- a/docs/rules/no-arg/index.html +++ b/docs/rules/no-arg/index.html @@ -11,7 +11,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-arg' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-bitwise/index.html b/docs/rules/no-bitwise/index.html index e7dbe9f6bf5..9c83ca93d89 100644 --- a/docs/rules/no-bitwise/index.html +++ b/docs/rules/no-bitwise/index.html @@ -17,7 +17,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-bitwise' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-conditional-assignment/index.html b/docs/rules/no-conditional-assignment/index.html index c38f9119579..b7bdc4041ef 100644 --- a/docs/rules/no-conditional-assignment/index.html +++ b/docs/rules/no-conditional-assignment/index.html @@ -12,7 +12,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-conditional-assignment' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-consecutive-blank-lines/index.html b/docs/rules/no-consecutive-blank-lines/index.html index 1e9ec855f7b..180294b281f 100644 --- a/docs/rules/no-consecutive-blank-lines/index.html +++ b/docs/rules/no-consecutive-blank-lines/index.html @@ -1,13 +1,24 @@ --- ruleName: no-consecutive-blank-lines -description: Disallows more than one blank line in a row. +description: Disallows one or more blank lines in a row. rationale: Helps maintain a readable style in your codebase. -optionsDescription: Not configurable. -options: {} +optionsDescription: |- + + An optional number of maximum allowed sequential blanks can be specified. If no value + is provided, a default of $(Rule.DEFAULT_ALLOWED_BLANKS) will be used. +options: + type: number + minimum: $(Rule.MINIMUM_ALLOWED_BLANKS) optionExamples: - 'true' + - '[true, 2]' type: style -optionsJSON: '{}' +typescriptOnly: false layout: rule title: 'Rule: no-consecutive-blank-lines' +optionsJSON: |- + { + "type": "number", + "minimum": "$(Rule.MINIMUM_ALLOWED_BLANKS)" + } --- \ No newline at end of file diff --git a/docs/rules/no-console/index.html b/docs/rules/no-console/index.html index d8066eeee0d..3a04d5c29f2 100644 --- a/docs/rules/no-console/index.html +++ b/docs/rules/no-console/index.html @@ -10,6 +10,9 @@ optionExamples: - '[true, "log", "error"]' type: functionality +typescriptOnly: false +layout: rule +title: 'Rule: no-console' optionsJSON: |- { "type": "array", @@ -17,6 +20,4 @@ "type": "string" } } -layout: rule -title: 'Rule: no-console' --- \ No newline at end of file diff --git a/docs/rules/no-construct/index.html b/docs/rules/no-construct/index.html index a1f54fb6aba..d7f937db798 100644 --- a/docs/rules/no-construct/index.html +++ b/docs/rules/no-construct/index.html @@ -12,7 +12,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-construct' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-debugger/index.html b/docs/rules/no-debugger/index.html index 409c7ae3534..a3133012e5f 100644 --- a/docs/rules/no-debugger/index.html +++ b/docs/rules/no-debugger/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-debugger' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-default-export/index.html b/docs/rules/no-default-export/index.html index ab17c9c46b6..8e7a279a2a7 100644 --- a/docs/rules/no-default-export/index.html +++ b/docs/rules/no-default-export/index.html @@ -12,7 +12,8 @@ optionExamples: - 'true' type: maintainability -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-default-export' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-duplicate-variable/index.html b/docs/rules/no-duplicate-variable/index.html index 26dbce48ecb..3dee824d2ce 100644 --- a/docs/rules/no-duplicate-variable/index.html +++ b/docs/rules/no-duplicate-variable/index.html @@ -14,7 +14,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-duplicate-variable' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-empty/index.html b/docs/rules/no-empty/index.html index 46a17a83dad..5fe4cc64ff0 100644 --- a/docs/rules/no-empty/index.html +++ b/docs/rules/no-empty/index.html @@ -8,7 +8,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-empty' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-eval/index.html b/docs/rules/no-eval/index.html index 30feb3c6ba6..63f08fba017 100644 --- a/docs/rules/no-eval/index.html +++ b/docs/rules/no-eval/index.html @@ -11,7 +11,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-eval' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-for-in-array/index.html b/docs/rules/no-for-in-array/index.html index ac33d240bb1..781e895234f 100644 --- a/docs/rules/no-for-in-array/index.html +++ b/docs/rules/no-for-in-array/index.html @@ -21,7 +21,8 @@ - 'true' requiresTypeInfo: true type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-for-in-array' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-inferrable-types/index.html b/docs/rules/no-inferrable-types/index.html index 1a01bde98cc..4518dc603e5 100644 --- a/docs/rules/no-inferrable-types/index.html +++ b/docs/rules/no-inferrable-types/index.html @@ -20,6 +20,9 @@ - 'true' - '[true, "ignore-params"]' type: typescript +typescriptOnly: true +layout: rule +title: 'Rule: no-inferrable-types' optionsJSON: |- { "type": "array", @@ -32,6 +35,4 @@ "minLength": 0, "maxLength": 1 } -layout: rule -title: 'Rule: no-inferrable-types' --- \ No newline at end of file diff --git a/docs/rules/no-internal-module/index.html b/docs/rules/no-internal-module/index.html index 95a3965c86f..5092d8ef529 100644 --- a/docs/rules/no-internal-module/index.html +++ b/docs/rules/no-internal-module/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: typescript -optionsJSON: 'null' +typescriptOnly: true layout: rule title: 'Rule: no-internal-module' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-invalid-this/index.html b/docs/rules/no-invalid-this/index.html index 1126670a835..fb2d3d34ed2 100644 --- a/docs/rules/no-invalid-this/index.html +++ b/docs/rules/no-invalid-this/index.html @@ -19,6 +19,9 @@ - 'true' - '[true, "check-function-in-method"]' type: functionality +typescriptOnly: false +layout: rule +title: 'Rule: no-invalid-this' optionsJSON: |- { "type": "array", @@ -31,6 +34,4 @@ "minLength": 0, "maxLength": 1 } -layout: rule -title: 'Rule: no-invalid-this' --- \ No newline at end of file diff --git a/docs/rules/no-mergeable-namespace/index.html b/docs/rules/no-mergeable-namespace/index.html index be0ab94e3b1..ca24c662893 100644 --- a/docs/rules/no-mergeable-namespace/index.html +++ b/docs/rules/no-mergeable-namespace/index.html @@ -6,7 +6,8 @@ optionExamples: - 'true' type: maintainability -optionsJSON: 'null' +typescriptOnly: true layout: rule title: 'Rule: no-mergeable-namespace' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-namespace/index.html b/docs/rules/no-namespace/index.html index fe69cd32512..d29ecbf5262 100644 --- a/docs/rules/no-namespace/index.html +++ b/docs/rules/no-namespace/index.html @@ -23,6 +23,9 @@ - 'true' - '[true, "allow-declarations"]' type: typescript +typescriptOnly: true +layout: rule +title: 'Rule: no-namespace' optionsJSON: |- { "type": "array", @@ -35,6 +38,4 @@ "minLength": 0, "maxLength": 1 } -layout: rule -title: 'Rule: no-namespace' --- \ No newline at end of file diff --git a/docs/rules/no-null-keyword/index.html b/docs/rules/no-null-keyword/index.html index 6bb6bb71e6f..c4c46d69f8d 100644 --- a/docs/rules/no-null-keyword/index.html +++ b/docs/rules/no-null-keyword/index.html @@ -10,7 +10,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-null-keyword' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-parameter-properties/index.html b/docs/rules/no-parameter-properties/index.html index d2fc9e99326..bac7fbb8f6e 100644 --- a/docs/rules/no-parameter-properties/index.html +++ b/docs/rules/no-parameter-properties/index.html @@ -1,6 +1,6 @@ --- -ruleName: no-constructor-vars -description: Disallows parameter properties. +ruleName: no-parameter-properties +description: Disallows parameter properties in class constructors. rationale: |- Parameter properties can be confusing to those new to TS as they are less explicit @@ -10,7 +10,8 @@ optionExamples: - 'true' type: style -optionsJSON: 'null' +typescriptOnly: true layout: rule -title: 'Rule: no-constructor-vars' +title: 'Rule: no-parameter-properties' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-reference/index.html b/docs/rules/no-reference/index.html index d77be60532e..85ff055965e 100644 --- a/docs/rules/no-reference/index.html +++ b/docs/rules/no-reference/index.html @@ -10,7 +10,8 @@ optionExamples: - 'true' type: typescript -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-reference' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-require-imports/index.html b/docs/rules/no-require-imports/index.html index b17524c8951..0791ef11775 100644 --- a/docs/rules/no-require-imports/index.html +++ b/docs/rules/no-require-imports/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: maintainability -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-require-imports' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-shadowed-variable/index.html b/docs/rules/no-shadowed-variable/index.html index d6b60ae4316..c9b41de6420 100644 --- a/docs/rules/no-shadowed-variable/index.html +++ b/docs/rules/no-shadowed-variable/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-shadowed-variable' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-string-literal/index.html b/docs/rules/no-string-literal/index.html index 9db77bb7810..c4472e65b53 100644 --- a/docs/rules/no-string-literal/index.html +++ b/docs/rules/no-string-literal/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-string-literal' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-switch-case-fall-through/index.html b/docs/rules/no-switch-case-fall-through/index.html index 52ddb72588a..e6ff8459f6d 100644 --- a/docs/rules/no-switch-case-fall-through/index.html +++ b/docs/rules/no-switch-case-fall-through/index.html @@ -33,7 +33,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-switch-case-fall-through' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-trailing-whitespace/index.html b/docs/rules/no-trailing-whitespace/index.html index 6a2291ced17..eef2dc69bf4 100644 --- a/docs/rules/no-trailing-whitespace/index.html +++ b/docs/rules/no-trailing-whitespace/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: maintainability -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-trailing-whitespace' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-unsafe-finally/index.html b/docs/rules/no-unsafe-finally/index.html index e630ded10c4..1d6e46900c8 100644 --- a/docs/rules/no-unsafe-finally/index.html +++ b/docs/rules/no-unsafe-finally/index.html @@ -16,7 +16,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-unsafe-finally' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-unused-expression/index.html b/docs/rules/no-unused-expression/index.html index e44c9eb01ef..82075de330a 100644 --- a/docs/rules/no-unused-expression/index.html +++ b/docs/rules/no-unused-expression/index.html @@ -13,7 +13,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-unused-expression' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-unused-new/index.html b/docs/rules/no-unused-new/index.html index f2add294cb5..4508b8fb8c6 100644 --- a/docs/rules/no-unused-new/index.html +++ b/docs/rules/no-unused-new/index.html @@ -13,7 +13,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-unused-new' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-unused-variable/index.html b/docs/rules/no-unused-variable/index.html index b892b4d3518..3487ff0e49d 100644 --- a/docs/rules/no-unused-variable/index.html +++ b/docs/rules/no-unused-variable/index.html @@ -1,5 +1,6 @@ --- ruleName: no-unused-variable +deprecationMessage: Use the compiler options --noUnusedParameters and --noUnusedLocals instead. description: 'Disallows unused imports, variables, functions and private class members.' optionsDescription: |- @@ -33,6 +34,9 @@ - '[true, "react"]' - '[true, {"ignore-pattern": "^_"}]' type: functionality +typescriptOnly: true +layout: rule +title: 'Rule: no-unused-variable' optionsJSON: |- { "type": "array", @@ -59,6 +63,4 @@ "minLength": 0, "maxLength": 3 } -layout: rule -title: 'Rule: no-unused-variable' --- \ No newline at end of file diff --git a/docs/rules/no-use-before-declare/index.html b/docs/rules/no-use-before-declare/index.html index e590931e298..d2c24056758 100644 --- a/docs/rules/no-use-before-declare/index.html +++ b/docs/rules/no-use-before-declare/index.html @@ -10,7 +10,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-use-before-declare' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-var-keyword/index.html b/docs/rules/no-var-keyword/index.html index 5fb0d769b0a..addab8d448c 100644 --- a/docs/rules/no-var-keyword/index.html +++ b/docs/rules/no-var-keyword/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: no-var-keyword' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/no-var-requires/index.html b/docs/rules/no-var-requires/index.html index d0d6dd071b8..ecbbca8fe5a 100644 --- a/docs/rules/no-var-requires/index.html +++ b/docs/rules/no-var-requires/index.html @@ -10,7 +10,8 @@ optionExamples: - 'true' type: typescript -optionsJSON: 'null' +typescriptOnly: true layout: rule title: 'Rule: no-var-requires' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/object-literal-key-quotes/index.html b/docs/rules/object-literal-key-quotes/index.html index 016e463b16f..a13b8823c40 100644 --- a/docs/rules/object-literal-key-quotes/index.html +++ b/docs/rules/object-literal-key-quotes/index.html @@ -37,6 +37,9 @@ - '[true, "as-needed"]' - '[true, "always"]' type: style +typescriptOnly: false +layout: rule +title: 'Rule: object-literal-key-quotes' optionsJSON: |- { "type": "string", @@ -45,6 +48,4 @@ "as-needed" ] } -layout: rule -title: 'Rule: object-literal-key-quotes' --- \ No newline at end of file diff --git a/docs/rules/object-literal-shorthand/index.html b/docs/rules/object-literal-shorthand/index.html index 3917afade21..1a6ca8708e8 100644 --- a/docs/rules/object-literal-shorthand/index.html +++ b/docs/rules/object-literal-shorthand/index.html @@ -1,11 +1,13 @@ --- ruleName: object-literal-shorthand description: Enforces use of ES6 object literal shorthand when possible. +optionsDescription: Not configurable. options: null optionExamples: - 'true' type: style -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: object-literal-shorthand' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/object-literal-sort-keys/index.html b/docs/rules/object-literal-sort-keys/index.html index 74c54296cf7..44dcc1850e8 100644 --- a/docs/rules/object-literal-sort-keys/index.html +++ b/docs/rules/object-literal-sort-keys/index.html @@ -7,7 +7,8 @@ optionExamples: - 'true' type: maintainability -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: object-literal-sort-keys' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/one-line/index.html b/docs/rules/one-line/index.html index ed9bb4b3ba7..646e89b8d56 100644 --- a/docs/rules/one-line/index.html +++ b/docs/rules/one-line/index.html @@ -25,6 +25,9 @@ optionExamples: - '[true, "check-catch", "check-finally", "check-else"]' type: style +typescriptOnly: false +layout: rule +title: 'Rule: one-line' optionsJSON: |- { "type": "array", @@ -41,6 +44,4 @@ "minLength": 0, "maxLength": 5 } -layout: rule -title: 'Rule: one-line' --- \ No newline at end of file diff --git a/docs/rules/one-variable-per-declaration/index.html b/docs/rules/one-variable-per-declaration/index.html index f90487ea783..327b8b59f65 100644 --- a/docs/rules/one-variable-per-declaration/index.html +++ b/docs/rules/one-variable-per-declaration/index.html @@ -18,6 +18,9 @@ - 'true' - '[true, "ignore-for-loop"]' type: style +typescriptOnly: false +layout: rule +title: 'Rule: one-variable-per-declaration' optionsJSON: |- { "type": "array", @@ -30,6 +33,4 @@ "minLength": 0, "maxLength": 1 } -layout: rule -title: 'Rule: one-variable-per-declaration' --- \ No newline at end of file diff --git a/docs/rules/only-arrow-functions/index.html b/docs/rules/only-arrow-functions/index.html index 7d5adbd6f63..f88c10f5bbb 100644 --- a/docs/rules/only-arrow-functions/index.html +++ b/docs/rules/only-arrow-functions/index.html @@ -20,6 +20,9 @@ - 'true' - '[true, "allow-declarations"]' type: typescript +typescriptOnly: false +layout: rule +title: 'Rule: only-arrow-functions' optionsJSON: |- { "type": "array", @@ -32,6 +35,4 @@ "minLength": 0, "maxLength": 1 } -layout: rule -title: 'Rule: only-arrow-functions' --- \ No newline at end of file diff --git a/docs/rules/ordered-imports/index.html b/docs/rules/ordered-imports/index.html index 64691a23f70..78d7a0a5466 100644 --- a/docs/rules/ordered-imports/index.html +++ b/docs/rules/ordered-imports/index.html @@ -21,6 +21,7 @@ * `"case-insensitive'`: Correct order is `"Bar"`, `"baz"`, `"Foo"`. (This is the default.) * `"lowercase-first"`: Correct order is `"baz"`, `"Bar"`, `"Foo"`. * `"lowercase-last"`: Correct order is `"Bar"`, `"Foo"`, `"baz"`. + * `"any"`: Allow any order. You may set the `"named-imports-order"` option to control the ordering of named imports (the `{A, B, C}` in `import {A, B, C} from "foo"`). @@ -30,6 +31,7 @@ * `"case-insensitive'`: Correct order is `{A, b, C}`. (This is the default.) * `"lowercase-first"`: Correct order is `{b, A, C}`. * `"lowercase-last"`: Correct order is `{A, C, b}`. + * `"any"`: Allow any order. options: @@ -41,17 +43,22 @@ - case-insensitive - lowercase-first - lowercase-last + - any named-imports-order: type: string enum: - case-insensitive - lowercase-first - lowercase-last + - any additionalProperties: false optionExamples: - 'true' - '[true, {"import-sources-order": "lowercase-last", "named-imports-order": "lowercase-first"}]' type: style +typescriptOnly: false +layout: rule +title: 'Rule: ordered-imports' optionsJSON: |- { "type": "object", @@ -61,7 +68,8 @@ "enum": [ "case-insensitive", "lowercase-first", - "lowercase-last" + "lowercase-last", + "any" ] }, "named-imports-order": { @@ -69,12 +77,11 @@ "enum": [ "case-insensitive", "lowercase-first", - "lowercase-last" + "lowercase-last", + "any" ] } }, "additionalProperties": false } -layout: rule -title: 'Rule: ordered-imports' --- \ No newline at end of file diff --git a/docs/rules/prefer-for-of/index.html b/docs/rules/prefer-for-of/index.html new file mode 100644 index 00000000000..182c695e16f --- /dev/null +++ b/docs/rules/prefer-for-of/index.html @@ -0,0 +1,14 @@ +--- +ruleName: prefer-for-of +description: Recommends a 'for-of' loop over a standard 'for' loop if the index is only used to access the array being iterated. +rationale: A for(... of ...) loop is easier to implement and read when the index is not needed. +optionsDescription: Not configurable. +options: null +optionExamples: + - 'true' +type: typescript +typescriptOnly: false +layout: rule +title: 'Rule: prefer-for-of' +optionsJSON: 'null' +--- \ No newline at end of file diff --git a/docs/rules/quotemark/index.html b/docs/rules/quotemark/index.html index 1163f9023f9..19eb51583cd 100644 --- a/docs/rules/quotemark/index.html +++ b/docs/rules/quotemark/index.html @@ -27,6 +27,9 @@ - '[true, "single", "avoid-escape"]' - '[true, "single", "jsx-double"]' type: style +typescriptOnly: false +layout: rule +title: 'Rule: quotemark' optionsJSON: |- { "type": "array", @@ -43,6 +46,4 @@ "minLength": 0, "maxLength": 5 } -layout: rule -title: 'Rule: quotemark' --- \ No newline at end of file diff --git a/docs/rules/radix/index.html b/docs/rules/radix/index.html index 33209320a3b..f951cffb6ac 100644 --- a/docs/rules/radix/index.html +++ b/docs/rules/radix/index.html @@ -11,7 +11,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: radix' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/restrict-plus-operands/index.html b/docs/rules/restrict-plus-operands/index.html index 902b433010a..1a20bb14ee8 100644 --- a/docs/rules/restrict-plus-operands/index.html +++ b/docs/rules/restrict-plus-operands/index.html @@ -6,8 +6,9 @@ optionExamples: - 'true' type: functionality +typescriptOnly: false requiresTypeInfo: true -optionsJSON: 'null' layout: rule title: 'Rule: restrict-plus-operands' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/semicolon/index.html b/docs/rules/semicolon/index.html index 5bbb10c22e4..095bfb1ee96 100644 --- a/docs/rules/semicolon/index.html +++ b/docs/rules/semicolon/index.html @@ -10,6 +10,7 @@ The following arguments may be optionaly provided: * `"ignore-interfaces"` skips checking semicolons at the end of interface members. + * `"ignore-bound-class-methods"` skips checking semicolons at the end of bound class methods. options: type: array items: @@ -25,7 +26,11 @@ - '[true, "always"]' - '[true, "never"]' - '[true, "always", "ignore-interfaces"]' + - '[true, "always", "ignore-bound-class-methods"]' type: style +typescriptOnly: false +layout: rule +title: 'Rule: semicolon' optionsJSON: |- { "type": "array", @@ -46,6 +51,4 @@ ], "additionalItems": false } -layout: rule -title: 'Rule: semicolon' --- \ No newline at end of file diff --git a/docs/rules/switch-default/index.html b/docs/rules/switch-default/index.html index f6bc874814a..4bfa95371fa 100644 --- a/docs/rules/switch-default/index.html +++ b/docs/rules/switch-default/index.html @@ -6,7 +6,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: switch-default' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/trailing-comma/index.html b/docs/rules/trailing-comma/index.html index ef0150a62c8..c2e2aeeb843 100644 --- a/docs/rules/trailing-comma/index.html +++ b/docs/rules/trailing-comma/index.html @@ -1,6 +1,9 @@ --- ruleName: trailing-comma -description: 'Requires or disallows trailing commas in array and object literals, destructuring assignments and named imports.' +description: |- + + Requires or disallows trailing commas in array and object literals, destructuring assignments, function and tuple typings, + named imports and function parameters. optionsDescription: |- One argument which is an object with the keys `multiline` and `singleline`. @@ -11,7 +14,8 @@ 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 and named import statements. + object literals, function and tuple typings, named import statements + and function parameters. options: type: object properties: @@ -29,6 +33,9 @@ optionExamples: - '[true, {"multiline": "always", "singleline": "never"}]' type: maintainability +typescriptOnly: false +layout: rule +title: 'Rule: trailing-comma' optionsJSON: |- { "type": "object", @@ -50,6 +57,4 @@ }, "additionalProperties": false } -layout: rule -title: 'Rule: trailing-comma' --- \ No newline at end of file diff --git a/docs/rules/triple-equals/index.html b/docs/rules/triple-equals/index.html index 5ad73c8c86d..1fdfe98e5b8 100644 --- a/docs/rules/triple-equals/index.html +++ b/docs/rules/triple-equals/index.html @@ -21,6 +21,9 @@ - '[true, "allow-null-check"]' - '[true, "allow-undefined-check"]' type: functionality +typescriptOnly: false +layout: rule +title: 'Rule: triple-equals' optionsJSON: |- { "type": "array", @@ -34,6 +37,4 @@ "minLength": 0, "maxLength": 2 } -layout: rule -title: 'Rule: triple-equals' --- \ No newline at end of file diff --git a/docs/rules/typedef-whitespace/index.html b/docs/rules/typedef-whitespace/index.html index db7134d3dfb..8fcd3b63087 100644 --- a/docs/rules/typedef-whitespace/index.html +++ b/docs/rules/typedef-whitespace/index.html @@ -55,6 +55,9 @@ } ] type: typescript +typescriptOnly: true +layout: rule +title: 'Rule: typedef-whitespace' optionsJSON: |- { "type": "array", @@ -154,6 +157,4 @@ ], "additionalItems": false } -layout: rule -title: 'Rule: typedef-whitespace' --- \ No newline at end of file diff --git a/docs/rules/typedef/index.html b/docs/rules/typedef/index.html index 727f9ed08b6..67ca7f977f2 100644 --- a/docs/rules/typedef/index.html +++ b/docs/rules/typedef/index.html @@ -29,6 +29,9 @@ optionExamples: - '[true, "call-signature", "parameter", "member-variable-declaration"]' type: typescript +typescriptOnly: true +layout: rule +title: 'Rule: typedef' optionsJSON: |- { "type": "array", @@ -47,6 +50,4 @@ "minLength": 0, "maxLength": 7 } -layout: rule -title: 'Rule: typedef' --- \ No newline at end of file diff --git a/docs/rules/use-isnan/index.html b/docs/rules/use-isnan/index.html index 2c3dbc2a07e..848ec439738 100644 --- a/docs/rules/use-isnan/index.html +++ b/docs/rules/use-isnan/index.html @@ -10,7 +10,8 @@ optionExamples: - 'true' type: functionality -optionsJSON: 'null' +typescriptOnly: false layout: rule title: 'Rule: use-isnan' +optionsJSON: 'null' --- \ No newline at end of file diff --git a/docs/rules/variable-name/index.html b/docs/rules/variable-name/index.html index f7220338766..0808782623f 100644 --- a/docs/rules/variable-name/index.html +++ b/docs/rules/variable-name/index.html @@ -26,6 +26,9 @@ optionExamples: - '[true, "ban-keywords", "check-format", "allow-leading-underscore"]' type: style +typescriptOnly: false +layout: rule +title: 'Rule: variable-name' optionsJSON: |- { "type": "array", @@ -42,6 +45,4 @@ "minLength": 0, "maxLength": 5 } -layout: rule -title: 'Rule: variable-name' --- \ No newline at end of file diff --git a/docs/rules/whitespace/index.html b/docs/rules/whitespace/index.html index 4e591aa49a2..259fd6a8e02 100644 --- a/docs/rules/whitespace/index.html +++ b/docs/rules/whitespace/index.html @@ -30,6 +30,9 @@ optionExamples: - '[true, "check-branch", "check-operator", "check-typecast"]' type: style +typescriptOnly: false +layout: rule +title: 'Rule: whitespace' optionsJSON: |- { "type": "array", @@ -48,6 +51,4 @@ "minLength": 0, "maxLength": 7 } -layout: rule -title: 'Rule: whitespace' --- \ No newline at end of file From 66ad241ab5c9b9ceca97d49772cfe1b295b43303 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Tue, 15 Nov 2016 22:49:03 -0500 Subject: [PATCH 072/111] Update CHANGELOG.md (#1725) --- CHANGELOG.md | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 552676a2477..c3832960da3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,33 @@ Change Log === - +* [rule-change] `indent` rule now ignores template strings (#1611) +* [enhancement] `--fix` option added to automatically fix selected rules (#1697) +* [enhancement] Updated recommend rules (#1717) +* [enhancement] `adjacent-overload-signatures` now works with classes, source files, modules, and namespaces (#1707) +* [enhancement] Users are notified if they are using an old TSLint version (#1696) +* [bugfix] Lint `.jsx` files if `jsRules` are configured (#1714) +* [bugfix] Command line glob patterns now handle single quotes (#1679) + +Thanks to our contributors! +* Andrii Dieiev +* Andy +* Chris Barr +* Davie Schoots +* Jordan Hawker +* Josh Goldberg +* Stepan Riha +* Yuichi Nukiyama + v4.0.0-dev.1 --- * **BREAKING CHANGES** From 752386509e12c99e3cc6fb7e11ceda8fa51ca446 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Tue, 15 Nov 2016 22:51:02 -0500 Subject: [PATCH 073/111] Add debug launch config for generating docs (#1727) --- .npmignore | 2 +- .vscode/launch.json | 21 +++++++++++++++++++++ scripts/tsconfig.json | 3 +-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.npmignore b/.npmignore index fe6cf8753f5..d76bbd86186 100644 --- a/.npmignore +++ b/.npmignore @@ -11,10 +11,10 @@ .vscode appveyor.yml circle.yml -Gruntfile.js tslint.json /build/ /docs/ +/scripts/ /src/ /test/ tscommand*.txt diff --git a/.vscode/launch.json b/.vscode/launch.json index d1c1650a779..a3906afe938 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -63,6 +63,27 @@ "sourceMaps": true, "outFiles": [], "outDir": "${workspaceRoot}/build" + }, + { + "name": "Debug Document Generation", + "type": "node", + "request": "launch", + "program": "${workspaceRoot}/scripts/buildDocs.ts", + "stopOnEntry": false, + "args": ["run", "test"], + "cwd": "${workspaceRoot}", + "preLaunchTask": "tsc", + "runtimeExecutable": null, + "runtimeArgs": [ + "--nolazy" + ], + "env": { + "NODE_ENV": "development" + }, + "console": "internalConsole", + "sourceMaps": true, + "outFiles": [], + "outDir": "${workspaceRoot}/build" } ] } \ No newline at end of file diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index a289747f09e..9cc1d95b417 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -5,8 +5,7 @@ "noImplicitAny": true, "noUnusedParameters": true, "noUnusedLocals": true, - "declaration": false, - "sourceMap": false, + "sourceMap": true, "target": "es5" } } From 99d527296cca04c8f81272768f5dd6de62c23a8e Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 16 Nov 2016 16:59:41 -0500 Subject: [PATCH 074/111] update non-generated docs (#1726) --- README.md | 40 ++++++++++++++++++++++-------- docs/develop/contributing/index.md | 9 ++++--- docs/develop/custom-rules/index.md | 19 +++++++------- docs/develop/docs/index.md | 4 +-- docs/usage/cli/index.md | 20 ++++++++++++--- docs/usage/tslint-json/index.md | 21 +++++++++++++++- package.json | 9 +++---- src/tslint-cli.ts | 2 +- 8 files changed, 87 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 6a78262e40d..01c8c313af2 100644 --- a/README.md +++ b/README.md @@ -79,9 +79,15 @@ The configuration file specifies which rules are enabled and their options. Thes "extends": "tslint:latest", "rules": { /* - * Any rules specified here will override those from the base config we are extending + * Any rules specified here will override those from the base config we are extending. */ - "no-parameter-properties": true + "curly": true + }, + "jsRules": { + /* + * Any rules specified here will override those from the base config we are extending. + */ + "curly": true }, "rulesDirectory": [ /* @@ -108,16 +114,17 @@ Options: ``` -c, --config configuration file +-e, --exclude exclude globs from path expansion +--fix Fixes linting errors for select rules. This may overwrite linted files --force return status code 0 even if there are lint errors -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 -r, --rules-dir rules directory -s, --formatters-dir formatters directory --e, --exclude exclude globs from path expansion --t, --format output format (prose, json, verbose, pmd, msbuild, checkstyle) [default: "prose"] +-t, --format output format (prose, json, stylish, verbose, pmd, msbuild, checkstyle, vso, fileslist) [default: "prose"] --test test that tslint produces the correct output for the specified directory ---project path to tsconfig.json file --type-check enable type checking when linting a project -v, --version current version ``` @@ -145,6 +152,9 @@ tslint accepts the following command-line options: This option can be supplied multiple times if you need multiple globs to indicate which files to exclude. +--fix: + Fixes linting errors for select rules. This may overwrite linted files. + --force: Return status code 0 even if there are any lint errors. Useful while running as npm script. @@ -301,15 +311,19 @@ If we don't have all the rules you're looking for, you can either write your own TSLint ships with a set of core rules that can be configured. However, users are also allowed to write their own rules, which allows them to enforce specific behavior not covered by the core of TSLint. TSLint's internal rules are itself written to be pluggable, so adding a new rule is as simple as creating a new rule file named by convention. New rules can be written in either TypeScript or JavaScript; if written in TypeScript, the code must be compiled to JavaScript before invoking TSLint. -Rule names are always camel-cased and *must* contain the suffix `Rule`. Let us take the example of how to write a new rule to forbid all import statements (you know, *for science*). Let us name the rule file `noImportsRule.ts`. Rules can be referenced in `tslint.json` in their kebab-case forms, so `"no-imports": true` would turn on the rule. +Let us take the example of how to write a new rule to forbid all import statements (you know, *for science*). Let us name the rule file `noImportsRule.ts`. Rules are referenced in `tslint.json` with their kebab-cased identifer, so `"no-imports": true` would configure the rule. + +__Important conventions__: +* Rule identifiers are always kebab-cased. +* Rule files are always camel-cased (`camelCasedRule.ts`). +* Rule files *must* contain the suffix `Rule`. +* The exported class must always be named `Rule` and extend from `Lint.Rules.AbstractRule`. -Now, let us first write the rule in TypeScript. A few things to note: -- We import `tslint/lib/lint` to get the whole `Lint` namespace instead of just the `Linter` class. -- The exported class must always be named `Rule` and extend from `Lint.Rules.AbstractRule`. +Now, let us first write the rule in TypeScript: ```typescript import * as ts from "typescript"; -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint"; export class Rule extends Lint.Rules.AbstractRule { public static FAILURE_STRING = "import statement forbidden"; @@ -336,11 +350,13 @@ Given a walker, TypeScript's parser visits the AST using the visitor pattern. So We still need to hook up this new rule to TSLint. First make sure to compile `noImportsRule.ts`: ```bash -tsc -m commonjs --noImplicitAny noImportsRule.ts node_modules/tslint/lib/tslint.d.ts +tsc --noImplicitAny noImportsRule.ts ``` Then, if using the CLI, provide the directory that contains this rule as an option to `--rules-dir`. If using TSLint as a library or via `grunt-tslint`, the `options` hash must contain `"rulesDirectory": "..."`. If you run the linter, you'll see that we have now successfully banned all import statements via TSLint! +Finally, enable each custom rule in your [`tslint.json` config file][0] config file. + Final notes: - Core rules cannot be overwritten with a custom implementation. @@ -396,3 +412,5 @@ Creating a new release 4. Commit with message `Prepare release ` 5. Run `npm publish` 6. Create a git tag for the new release and push it ([see existing tags here](https://github.com/palantir/tslint/tags)) + +[0]: {{site.baseurl | append: "/usage/tslint-json/"}} diff --git a/docs/develop/contributing/index.md b/docs/develop/contributing/index.md index 56586310848..f78a059839f 100644 --- a/docs/develop/contributing/index.md +++ b/docs/develop/contributing/index.md @@ -4,12 +4,13 @@ title: Contributing permalink: /develop/contributing/ --- -To develop TSLint simply clone the repository, install dependencies and run grunt: +To develop TSLint simply clone the repository and install dependencies: ```bash -git clone git@github.com:palantir/tslint.git +git clone git@github.com:palantir/tslint.git --config core.autocrlf=input --config core.eol=lf npm install -grunt +npm run compile +npm run test ``` #### `next` branch @@ -17,4 +18,4 @@ grunt The [`next` branch of the TSLint repo](https://github.com/palantir/tslint/tree/next) tracks the latest TypeScript compiler as a `devDependency`. This allows you to develop the linter and its rules against the latest features of the language. Releases from this branch are published to npm with the `next` dist-tag, so you can get the latest dev -version of TSLint via `npm install tslint@next`. \ No newline at end of file +version of TSLint via `npm install tslint@next`. diff --git a/docs/develop/custom-rules/index.md b/docs/develop/custom-rules/index.md index b8a39ee1c39..dad79e04c04 100644 --- a/docs/develop/custom-rules/index.md +++ b/docs/develop/custom-rules/index.md @@ -3,20 +3,21 @@ title: Custom Rules layout: page permalink: "/develop/custom-rules/" --- -TSLint ships with a set of core rules that can be configured. However, users are also enabled to write their own rules, which allows them to enforce specific behavior not covered by the core of TSLint. TSLint's internal rules are itself written to be pluggable, so adding a new rule is as simple as creating a new rule file named by convention. New rules can be written in either TypeScript or Javascript; if written in TypeScript, the code must be compiled to Javascript before registering them with TSLint. - -__Important conventions__: Rule identifiers are always kebab-cased. Their implementation files are always `camelCasedRule.ts` and *must* contain the suffix `Rule`. +TSLint ships with a set of core rules that can be configured. However, users are also allowed to write their own rules, which allows them to enforce specific behavior not covered by the core of TSLint. TSLint's internal rules are itself written to be pluggable, so adding a new rule is as simple as creating a new rule file named by convention. New rules can be written in either TypeScript or JavaScript; if written in TypeScript, the code must be compiled to JavaScript before invoking TSLint. Let us take the example of how to write a new rule to forbid all import statements (you know, *for science*). Let us name the rule file `noImportsRule.ts`. Rules are referenced in `tslint.json` with their kebab-cased identifer, so `"no-imports": true` would configure the rule. -Now, let us first write the rule in TypeScript. A few things to note: +__Important conventions__: +* Rule identifiers are always kebab-cased. +* Rule files are always camel-cased (`camelCasedRule.ts`). +* Rule files *must* contain the suffix `Rule`. +* The exported class must always be named `Rule` and extend from `Lint.Rules.AbstractRule`. -- We import `tslint/lib/lint` to get the whole `Lint` namespace instead of just the `Linter` class. -- The exported class must always be named `Rule` and extend from `Lint.Rules.AbstractRule`. +Now, let us first write the rule in TypeScript: -```ts +```typescript import * as ts from "typescript"; -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint"; export class Rule extends Lint.Rules.AbstractRule { public static FAILURE_STRING = "import statement forbidden"; @@ -55,4 +56,4 @@ Final notes: - Core rules cannot be overwritten with a custom implementation. - Custom rules can also take in options just like core rules (retrieved via `this.getOptions()`). -[0]: {{site.baseurl | append: "/usage/tslint-json/"}} \ No newline at end of file +[0]: {{site.baseurl | append: "/usage/tslint-json/"}} diff --git a/docs/develop/docs/index.md b/docs/develop/docs/index.md index e586b66fa05..6b4be4412b9 100644 --- a/docs/develop/docs/index.md +++ b/docs/develop/docs/index.md @@ -9,10 +9,10 @@ It is maintained in the [`/docs` directory][2] of TSLint. To contribute to the docs, whether it be better styling, functionality, or content, just create a PR as you would for any code contribution. #### Updating Rule Documentation #### -The [documentation for rules][3] is automatically generated from the metadata supplied by each rule in its corresponding `.tsx` file. +The [documentation for rules][3] is automatically generated from the metadata supplied by each rule in its corresponding `.ts` file. If you'd like to help improve documentation for them, simply file a PR improving a rule's metadata and a project collaborator will take care of regenerating the docs site once your PR is merged. -Running the `grunt docs` command will regenerate the rules docs based off of the metadata provided in the code. This is normally done each release so that the public docs site is up to date with the latest release. +Running the `npm run docs` command will regenerate the rules docs based off of the metadata provided in the code. This is normally done each release so that the public docs site is up to date with the latest release. #### Creating New Pages #### To create a new page, follow the pattern of existing pages. You'll also need to add appropriate metadata in the `_data/*_sidebar.json` data file if you want it to show up in a sidebar. diff --git a/docs/usage/cli/index.md b/docs/usage/cli/index.md index 52c6cf62f37..6992d54d605 100644 --- a/docs/usage/cli/index.md +++ b/docs/usage/cli/index.md @@ -30,15 +30,18 @@ Options: ``` -c, --config configuration file +-e, --exclude exclude globs from path expansion +--fix Fixes linting errors for select rules. This may overwrite linted files --force return status code 0 even if there are lint errors -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 -r, --rules-dir rules directory -s, --formatters-dir formatters directory --e, --exclude exclude globs from path expansion --t, --format output format (prose, json, verbose, pmd, msbuild, checkstyle, vso) [default: "prose"] +-t, --format output format (prose, json, stylish, verbose, pmd, msbuild, checkstyle, vso, fileslist) [default: "prose"] --test test that tslint produces the correct output for the specified directory +--type-check enable type checking when linting a project -v, --version current version ``` @@ -54,7 +57,7 @@ tslint accepts the following command-line options: to the rules. If no option is specified, the config file named tslint.json is used, so long as it exists in the path. The format of the file is { rules: { /* rules list */ } }, - where /* rules list */ is a key: value comma-seperated list of + where /* rules list */ is a key: value comma-separated list of rulename: rule-options pairs. Rule-options can be either a boolean true/false value denoting whether the rule is used or not, or a list [boolean, ...] where the boolean provides the same role @@ -68,6 +71,9 @@ tslint accepts the following command-line options: This option can be supplied multiple times if you need multiple globs to indicate which files to exclude. +--fix: + Fixes linting errors for select rules. This may overwrite linted files. + --force: Return status code 0 even if there are any lint errors. Useful while running as npm script. @@ -109,6 +115,14 @@ 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: + The location of a tsconfig.json file that will be used to determine which + files will be linted. + +--type-check + Enables the type checker when running linting rules. --project must be + specified in order to enable type checking. + -v, --version: The current version of tslint. diff --git a/docs/usage/tslint-json/index.md b/docs/usage/tslint-json/index.md index 4d2bd202f41..0b3e3135ee0 100644 --- a/docs/usage/tslint-json/index.md +++ b/docs/usage/tslint-json/index.md @@ -20,7 +20,8 @@ A path(s) to a directory of [custom rules][2]. This will always be treated as a * `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. -Not all possible rules are listed here, be sure to [check out the full list][3]. +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. `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. @@ -57,6 +58,24 @@ An example `tslint.json` file might look like this: "check-separator", "check-type" ] + }, + "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" + ] } } ``` diff --git a/package.json b/package.json index 0d14d50c4f1..bd141f1f86b 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "bin": { "tslint": "./bin/tslint" }, - "main": "./lib/tslint/index.js", - "typings": "./lib/tslint/index.d.ts", + "main": "./lib/index.js", + "typings": "./lib/index.d.ts", "repository": { "type": "git", "url": "https://github.com/palantir/tslint.git" @@ -69,8 +69,5 @@ "peerDependencies": { "typescript": ">=2.0.0" }, - "license": "Apache-2.0", - "typescript": { - "definition": "lib/tslint.d.ts" - } + "license": "Apache-2.0" } diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index 5ec6e28e46e..f19093e75d3 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -192,7 +192,7 @@ tslint accepts the following commandline options: formatters are prose (human readable), json (machine readable) and verbose. prose is the default if this option is not used. Other built-in options include pmd, msbuild, checkstyle, and vso. - Additonal formatters can be added and used if the --formatters-dir + Additional formatters can be added and used if the --formatters-dir option is set. --test: From 04a5ac320ff8a69164795a5d4cfbbcfa53864a0f Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 16 Nov 2016 20:26:47 -0500 Subject: [PATCH 075/111] Upgrade typescript to v2.0.10 and fix invalid typescript in comma tests (#1729) --- package.json | 2 +- test/rules/trailing-comma/multiline-always/test.ts.fix | 4 ++-- test/rules/trailing-comma/multiline-always/test.ts.lint | 4 ++-- test/rules/trailing-comma/multiline-never/test.ts.fix | 4 ++-- test/rules/trailing-comma/multiline-never/test.ts.lint | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index bd141f1f86b..f37c601cb3a 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "rimraf": "^2.5.4", "tslint": "latest", "tslint-test-config-non-relative": "file:test/external/tslint-test-config-non-relative", - "typescript": "2.0.3" + "typescript": "2.0.10" }, "peerDependencies": { "typescript": ">=2.0.0" diff --git a/test/rules/trailing-comma/multiline-always/test.ts.fix b/test/rules/trailing-comma/multiline-always/test.ts.fix index cbee7ac25f7..ca1572a3f90 100644 --- a/test/rules/trailing-comma/multiline-always/test.ts.fix +++ b/test/rules/trailing-comma/multiline-always/test.ts.fix @@ -364,7 +364,7 @@ class Test { [ C, C, - ] + ], C, >, >( @@ -474,7 +474,7 @@ interface ITest { [ C, C, - ] + ], C, >, >( diff --git a/test/rules/trailing-comma/multiline-always/test.ts.lint b/test/rules/trailing-comma/multiline-always/test.ts.lint index 64f72d12a5f..3f62655e8ab 100644 --- a/test/rules/trailing-comma/multiline-always/test.ts.lint +++ b/test/rules/trailing-comma/multiline-always/test.ts.lint @@ -390,7 +390,7 @@ class Test { [ C, C, - ] + ], C ~ [Missing trailing comma] > @@ -509,7 +509,7 @@ interface ITest { [ C, C, - ] + ], C ~ [Missing trailing comma] > diff --git a/test/rules/trailing-comma/multiline-never/test.ts.fix b/test/rules/trailing-comma/multiline-never/test.ts.fix index 4240f80dbc5..1b2e7ef79cb 100644 --- a/test/rules/trailing-comma/multiline-never/test.ts.fix +++ b/test/rules/trailing-comma/multiline-never/test.ts.fix @@ -364,7 +364,7 @@ class Test { [ C, C - ] + ], C > >( @@ -430,7 +430,7 @@ interface ITest { [ C, C - ] + ], C > >( diff --git a/test/rules/trailing-comma/multiline-never/test.ts.lint b/test/rules/trailing-comma/multiline-never/test.ts.lint index 359d6063b36..bc6e2ed78be 100644 --- a/test/rules/trailing-comma/multiline-never/test.ts.lint +++ b/test/rules/trailing-comma/multiline-never/test.ts.lint @@ -390,7 +390,7 @@ class Test { C, C, ~ [Unnecessary trailing comma] - ] + ], C > >( @@ -462,7 +462,7 @@ interface ITest { C, C, ~ [Unnecessary trailing comma] - ] + ], C > >( From 0918ca18db1aa134cafc93e4d238d03b3f20db43 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 16 Nov 2016 20:28:11 -0500 Subject: [PATCH 076/111] Fix issue - not all errors displayed (#1730) --- src/linter.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/linter.ts b/src/linter.ts index 30e50209ddb..2b3e504fd6b 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -82,7 +82,7 @@ class Linter { * files and excludes declaration (".d.ts") files. */ public static getFileNames(program: ts.Program): string[] { - return program.getSourceFiles().map(s => s.fileName).filter(l => l.substr(-5) !== ".d.ts"); + return program.getSourceFiles().map((s) => s.fileName).filter((l) => l.substr(-5) !== ".d.ts"); } constructor(private options: ILinterOptions, private program?: ts.Program) { @@ -99,34 +99,38 @@ class Linter { const enabledRules = this.getEnabledRules(fileName, source, configuration); let sourceFile = this.getSourceFile(fileName, source); let hasLinterRun = false; + let fileFailures: RuleFailure[] = []; if (this.options.fix) { this.fixes = []; for (let rule of enabledRules) { - let fileFailures = this.applyRule(rule, sourceFile); - const fixes = fileFailures.map(f => f.getFix()).filter(f => !!f); + let ruleFailures = this.applyRule(rule, sourceFile); + const fixes = ruleFailures.map((f) => f.getFix()).filter((f) => !!f); source = fs.readFileSync(fileName, { encoding: "utf-8" }); if (fixes.length > 0) { - this.fixes = this.fixes.concat(fileFailures); + this.fixes = this.fixes.concat(ruleFailures); source = Fix.applyAll(source, fixes); fs.writeFileSync(fileName, source, { encoding: "utf-8" }); // reload AST if file is modified sourceFile = this.getSourceFile(fileName, source); } - this.failures = this.failures.concat(fileFailures); + fileFailures = fileFailures.concat(ruleFailures); } hasLinterRun = true; } // make a 1st pass or make a 2nd pass if there were any fixes because the positions may be off if (!hasLinterRun || this.fixes.length > 0) { - this.failures = []; + fileFailures = []; for (let rule of enabledRules) { - const fileFailures = this.applyRule(rule, sourceFile); - this.failures = this.failures.concat(fileFailures); + const ruleFailures = this.applyRule(rule, sourceFile); + if (ruleFailures.length > 0) { + fileFailures = fileFailures.concat(ruleFailures); + } } } + this.failures = this.failures.concat(fileFailures); } public getResult(): LintResult { From 776032cf3a70933a20bf224c48e77fbbbb064f41 Mon Sep 17 00:00:00 2001 From: Boris Cherny Date: Wed, 16 Nov 2016 17:44:37 -0800 Subject: [PATCH 077/111] Relax TypedRule detection (fix #1637, fix #1522) (#1728) --- src/language/rule/typedRule.ts | 7 ++++++- src/linter.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/language/rule/typedRule.ts b/src/language/rule/typedRule.ts index 1489165bd55..661eda826c0 100644 --- a/src/language/rule/typedRule.ts +++ b/src/language/rule/typedRule.ts @@ -18,9 +18,14 @@ import * as ts from "typescript"; import {AbstractRule} from "./abstractRule"; -import {RuleFailure} from "./rule"; +import {IRule, RuleFailure} from "./rule"; export abstract class TypedRule extends AbstractRule { + + public static isTypedRule(rule: IRule): rule is TypedRule { + return "applyWithProgram" in rule; + } + public apply(_sourceFile: ts.SourceFile): RuleFailure[] { // if no program is given to the linter, throw an error throw new Error(`${this.getOptions().ruleName} requires type checking`); diff --git a/src/linter.ts b/src/linter.ts index 2b3e504fd6b..f1e508640e8 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -158,7 +158,7 @@ class Linter { private applyRule(rule: IRule, sourceFile: ts.SourceFile) { let ruleFailures: RuleFailure[] = []; - if (this.program && rule instanceof TypedRule) { + if (this.program && TypedRule.isTypedRule(rule)) { ruleFailures = rule.applyWithProgram(sourceFile, this.program); } else { ruleFailures = rule.apply(sourceFile); From 24611ec9c1911040f825c5b45d1567034d72ffde Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 16 Nov 2016 20:55:41 -0500 Subject: [PATCH 078/111] Implement fixer for `arrow-parens` (#1731) --- src/rules/arrowParensRule.ts | 6 ++++-- test/rules/arrow-parens/test.ts.fix | 27 +++++++++++++++++++++++++++ test/rules/arrow-parens/test.ts.lint | 4 ++-- 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 test/rules/arrow-parens/test.ts.fix diff --git a/src/rules/arrowParensRule.ts b/src/rules/arrowParensRule.ts index e3816ed0008..ea877d5d9a1 100644 --- a/src/rules/arrowParensRule.ts +++ b/src/rules/arrowParensRule.ts @@ -58,8 +58,10 @@ class ArrowParensWalker extends Lint.RuleWalker { } if ((firstToken.kind !== ts.SyntaxKind.OpenParenToken || lastToken.kind !== ts.SyntaxKind.CloseParenToken) - && !isGenerics && node.flags !== ts.NodeFlags.Async) { - this.addFailure(this.createFailure(position, width, Rule.FAILURE_STRING)); + && !isGenerics && node.flags !== ts.NodeFlags.Async) { + + const fix = new Lint.Fix(Rule.metadata.ruleName, [new Lint.Replacement(position, width, `(${parameter.getText()})`)]); + this.addFailure(this.createFailure(position, width, Rule.FAILURE_STRING, fix)); } } super.visitArrowFunction(node); diff --git a/test/rules/arrow-parens/test.ts.fix b/test/rules/arrow-parens/test.ts.fix new file mode 100644 index 00000000000..780c4f61339 --- /dev/null +++ b/test/rules/arrow-parens/test.ts.fix @@ -0,0 +1,27 @@ +// valid case +var a = (a) => {}; +var b = (a: number) => {}; +var c = (a, b) => {}; +var f = (...rest) => {}; +var f = a: number => {}; // TSLint don't warn. But syntax is wrong. +class Foo { + a: (a) =>{} +} +var bar = (method: () => T) => { + method(); +}; +var barbar = (method: (a: any) => T) => { + method(""); +}; +var barbarbar = (method: (a) => T) => { + method(""); +}; +var piyo = (method: () => T) => { + method(); +}; +const validAsync = async (param: any) => {}; +const validAsync = async (param) => {}; + +// invalid case +var e = ((a) => {})(1); +var f = (ab) => {}; diff --git a/test/rules/arrow-parens/test.ts.lint b/test/rules/arrow-parens/test.ts.lint index 2975baae8aa..463decd2270 100644 --- a/test/rules/arrow-parens/test.ts.lint +++ b/test/rules/arrow-parens/test.ts.lint @@ -25,5 +25,5 @@ const validAsync = async (param) => {}; // invalid case var e = (a => {})(1); ~ [Parentheses are required around the parameters of an arrow function definition] -var f = a => {}; - ~ [Parentheses are required around the parameters of an arrow function definition] +var f = ab => {}; + ~~ [Parentheses are required around the parameters of an arrow function definition] From 1b8a959af99552f7a573101a8888c92f3acbc358 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Thu, 17 Nov 2016 09:25:30 -0500 Subject: [PATCH 079/111] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3832960da3..badbc85a44e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ v4.0.0 * [enhancement] Changed TypeScript peer dependency to >= 2.0.0 (#1710) * [new-rule] `completed-docs` rule added (#1644) * [new-fixer] `ordered-imports` auto fixed (#1640) +* [new-fixer] `arrow-parens` auto fixed (#1731) * [rule-change] `indent` rule now ignores template strings (#1611) * [enhancement] `--fix` option added to automatically fix selected rules (#1697) * [enhancement] Updated recommend rules (#1717) From fc097b59e1655cf43dbfb26d8067aa665fb51837 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 17 Nov 2016 08:28:41 -0800 Subject: [PATCH 080/111] Simplify re-exports: use `export { Foo }` syntax instead of `export var Foo` (#1732) --- src/index.ts | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 23daf1af5cb..faf6ede9279 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,13 +15,15 @@ * limitations under the License. */ -import * as configuration from "./configuration"; -import * as formatters from "./formatters"; +import * as Configuration from "./configuration"; +import * as Formatters from "./formatters"; import {RuleFailure} from "./language/rule/rule"; -import * as linter from "./linter"; -import * as rules from "./rules"; -import * as test from "./test"; -import * as utils from "./utils"; +import * as Linter from "./linter"; +import * as Rules from "./rules"; +import * as Test from "./test"; +import * as Utils from "./utils"; + +export { Configuration, Formatters, Linter, Rules, Test, Utils }; export * from "./language/rule/rule"; export * from "./enableDisableRules"; @@ -32,13 +34,6 @@ export * from "./language/languageServiceHost"; export * from "./language/walker"; export * from "./language/formatter/formatter"; -export var Configuration = configuration; -export var Formatters = formatters; -export var Linter = linter; -export var Rules = rules; -export var Test = test; -export var Utils = utils; - export interface LintResult { failureCount: number; failures: RuleFailure[]; From c2acb3df5802c5b3fe96a42338dc6a6455f0d173 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Thu, 17 Nov 2016 17:49:41 -0500 Subject: [PATCH 081/111] Prepare release v4.0.0 (#1735) --- package.json | 2 +- scripts/tsconfig.json | 2 +- src/linter.ts | 2 +- src/tsconfig.json | 2 +- test/tsconfig.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index f37c601cb3a..ede2e56f300 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tslint", - "version": "4.0.0-dev", + "version": "4.0.0", "description": "An extensible static analysis linter for the TypeScript language", "bin": { "tslint": "./bin/tslint" diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 9cc1d95b417..a0ebb235e95 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -1,5 +1,5 @@ { - "version": "2.0.3", + "version": "2.0.10", "compilerOptions": { "module": "commonjs", "noImplicitAny": true, diff --git a/src/linter.ts b/src/linter.ts index f1e508640e8..f5d196d6c86 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -41,7 +41,7 @@ import { arrayify, dedent } from "./utils"; * Linter that can lint multiple files in consecutive runs. */ class Linter { - public static VERSION = "4.0.0-dev"; + public static VERSION = "4.0.0"; public static findConfiguration = findConfiguration; public static findConfigurationPath = findConfigurationPath; diff --git a/src/tsconfig.json b/src/tsconfig.json index 797e7d67879..82843d7dc6f 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,5 +1,5 @@ { - "version": "2.0.3", + "version": "2.0.10", "compilerOptions": { "module": "commonjs", "noImplicitAny": true, diff --git a/test/tsconfig.json b/test/tsconfig.json index 29f6a5b36b6..c6911ca7df6 100644 --- a/test/tsconfig.json +++ b/test/tsconfig.json @@ -1,5 +1,5 @@ { - "version": "2.0.3", + "version": "2.0.10", "compilerOptions": { "module": "commonjs", "noImplicitAny": true, From b56a3ee5eaea93bb1d088048a6c1ee079670be26 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 18 Nov 2016 00:03:20 -0500 Subject: [PATCH 082/111] Need to add @types/node since we use `Error` (#1739) Otherwise you see compilation errors on some of our d.ts files --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ede2e56f300..ad70e842a42 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "verify": "npm-run-all clean compile lint test docs" }, "dependencies": { + "@types/node": "^6.0.45", "colors": "^1.1.2", "diff": "^3.0.1", "findup-sync": "~0.3.0", @@ -52,7 +53,6 @@ "@types/glob": "^5.0.30", "@types/js-yaml": "^3.5.28", "@types/mocha": "^2.2.32", - "@types/node": "^6.0.45", "@types/optimist": "0.0.29", "@types/resolve": "0.0.4", "@types/underscore": "^1.7.33", From 3c585bf96a0c3eb659caec75525d71acec5ae1d3 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 18 Nov 2016 11:23:37 -0500 Subject: [PATCH 083/111] Blog entry for 4.0 release (#1734) --- .gitignore | 1 + docs/_posts/2016-11-17-new-for-4.0.md | 77 +++++++++++++++++++++++++++ docs/develop/custom-rules/index.md | 15 ++++++ 3 files changed, 93 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..454d20bfac7 --- /dev/null +++ b/docs/_posts/2016-11-17-new-for-4.0.md @@ -0,0 +1,77 @@ +--- +layout: post +title: "TSLint 4.0 Released" +date: 2016-11-17 15:19:00 +--- + +TSLint 4.0 has been released! With this release comes a few exciting [changes][0]. Some of the highlights: +* **Fixers** - Do you dread turning on a new rule because of all of the new errors? For some of the most common issues, we'll fix them for you. To use this feature, run `tslint` with the `--fix` option. Rules that support the `--fix` feature: + * [array-type][2] + * [arrow-parens][3] + * [no-unused-variable][4] (for imports) + * [no-var-keyword][5] + * [ordered-imports][6] + * [semicolon][7] + * [trailing-comma][8] +* **Linting `.js` files** - *A much-requested feature from our community*. Simplify your toolset by running the same rules you know and love on your .js and .jsx files. Just add a `jsRules` [section][9] to your `tslint.json` file, and TSLint will your JavaScript files. +* **TypeScript 2.0+ required** - This lets us deprecate/remove rules that are checked by the compiler. These rules now cause compilation errors: + * no-duplicate-key + * no-unreachable + * no-unused-variable +* **Node.js API Change** - [Moved and renamed][11] some things to make more sense. Get it all when you use `import * as TSLint from "tslint"`. +* **[Recommended Rules Updated][12]** + * [adjacent-overload-signatures][13] + * [array-type][14] + * [arrow-parens][15] + * [max-classes-per-file][16] + * [no-unsafe-finally][17] + * [object-literal-key-quotes][18] (as needed) + * [object-literal-shorthand][19] + * [only-arrow-functions][20] + * [ordered-imports][21] + * [prefer-for-of][22] +* **Other rules you might find handy**: + * [completed-docs][23] + * [cyclomatic-complexity][24] + +--- + +## Create your own fixer ## +To create your own fixer, instantiate a `Fix` object and pass it in as an argument to `addFailure`. + +This snippet updates the [sample custom rule][25] by adding a fixer which replaces the offending import statement with an empty string: + +```typescript + // create a fixer for this failure + const replacement = new Lint.Replacement(node.getStart(), node.getWidth(), ""); + const fix = new Lint.Fix("no-imports", [replacement]); + + this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING, fix)); +``` + +[0]: https://github.com/palantir/tslint/releases +[1]: https://github.com/palantir/tslint/blob/master/CHANGELOG.md +[2]: {{ site.baseurl }}/rules/array-type +[3]: {{ site.baseurl }}/rules/arrow-parens +[4]: {{ site.baseurl }}/rules/no-unused-variable +[5]: {{ site.baseurl }}/rules/no-var-keyword +[6]: {{ site.baseurl }}/rules/ordered-imports +[7]: {{ site.baseurl }}/rules/semicolon +[8]: {{ site.baseurl }}/rules/trailing-comma +[9]: https://raw.githubusercontent.com/palantir/tslint/master/src/configs/recommended.ts +[10]: {{ site.baseurl }}/usage/third-party-tools/ +[11]: https://github.com/palantir/tslint/pull/1720 +[12]: https://github.com/palantir/tslint/pull/1717/files#diff-6e3940e8ec3d59837c4435f32975ed2c +[13]: {{ site.baseurl }}/rules/adjacent-overload-signatures +[14]: {{ site.baseurl }}/rules/array-type +[15]: {{ site.baseurl }}/rules/arrow-parens +[16]: {{ site.baseurl }}/rules/max-classes-per-file +[17]: {{ site.baseurl }}/rules/no-unsafe-finally +[18]: {{ site.baseurl }}/rules/object-literal-key-quotes +[19]: {{ site.baseurl }}/rules/object-literal-shorthand +[20]: {{ site.baseurl }}/rules/only-arrow-functions +[21]: {{ site.baseurl }}/rules/ordered-imports +[22]: {{ site.baseurl }}/rules/prefer-for-of +[23]: {{ site.baseurl }}/rules/completed-docs +[24]: {{ site.baseurl }}/rules/cyclomatic-complexity +[25]: {{ site.baseurl }}/develop/custom-rules 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. From b90c666c9eefb785dcad9b38bb66fd62488cd7ad Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Fri, 18 Nov 2016 13:24:26 -0500 Subject: [PATCH 084/111] Revert "Need to add @types/node to reg dependencies since we use `Error` interface" (#1740) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ad70e842a42..ede2e56f300 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "verify": "npm-run-all clean compile lint test docs" }, "dependencies": { - "@types/node": "^6.0.45", "colors": "^1.1.2", "diff": "^3.0.1", "findup-sync": "~0.3.0", @@ -53,6 +52,7 @@ "@types/glob": "^5.0.30", "@types/js-yaml": "^3.5.28", "@types/mocha": "^2.2.32", + "@types/node": "^6.0.45", "@types/optimist": "0.0.29", "@types/resolve": "0.0.4", "@types/underscore": "^1.7.33", From 16574686a4076212939e97e4e32b19b1c00b0830 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 18 Nov 2016 17:20:19 -0500 Subject: [PATCH 085/111] Mark `--fix` as boolean so it doesn't consume args (#1742) --- src/tslint-cli.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index f19093e75d3..ab8d3d259c1 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -54,6 +54,7 @@ let processed = optimist }, fix: { describe: "Fixes linting errors for select rules. This may overwrite linted files", + type: "boolean", }, force: { describe: "return status code 0 even if there are lint errors", From b858caed3847819a2cdd66433a34ba0ff37eef9c Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 18 Nov 2016 17:21:50 -0500 Subject: [PATCH 086/111] Additional rule options for `object-literal-key-quotes` (#1733) --- CHANGELOG.md | 1 + docs/_data/rules.json | 6 +- .../object-literal-key-quotes/index.html | 9 +- src/configs/recommended.ts | 2 +- src/rules/objectLiteralKeyQuotesRule.ts | 87 ++++++++++++++----- .../consistent-as-needed/test.js.lint | 50 +++++++++++ .../consistent-as-needed/test.ts.lint | 50 +++++++++++ .../consistent-as-needed/tslint.json | 8 ++ .../consistent/test.js.lint | 44 ++++++++++ .../consistent/test.ts.lint | 44 ++++++++++ .../consistent/tslint.json | 8 ++ 11 files changed, 284 insertions(+), 25 deletions(-) create mode 100644 test/rules/object-literal-key-quotes/consistent-as-needed/test.js.lint create mode 100644 test/rules/object-literal-key-quotes/consistent-as-needed/test.ts.lint create mode 100644 test/rules/object-literal-key-quotes/consistent-as-needed/tslint.json create mode 100644 test/rules/object-literal-key-quotes/consistent/test.js.lint create mode 100644 test/rules/object-literal-key-quotes/consistent/test.ts.lint create mode 100644 test/rules/object-literal-key-quotes/consistent/tslint.json diff --git a/CHANGELOG.md b/CHANGELOG.md index badbc85a44e..3593c9aa05c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ v4.0.0 * [new-fixer] `ordered-imports` auto fixed (#1640) * [new-fixer] `arrow-parens` auto fixed (#1731) * [rule-change] `indent` rule now ignores template strings (#1611) +* [new-rule-option] `object-literal-key-quotes` adds the options `consistent` and `consistent-as-needed` (#1733) * [enhancement] `--fix` option added to automatically fix selected rules (#1697) * [enhancement] Updated recommend rules (#1717) * [enhancement] `adjacent-overload-signatures` now works with classes, source files, modules, and namespaces (#1707) diff --git a/docs/_data/rules.json b/docs/_data/rules.json index 5f80eed62c1..249191ad953 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -925,12 +925,14 @@ "ruleName": "object-literal-key-quotes", "description": "Enforces consistent object literal property quote style.", "descriptionDetails": "\nObject literal property names can be defined in two ways: using literals or using strings.\nFor example, these two objects are equivalent:\n\nvar object1 = {\n property: true\n};\n\nvar object2 = {\n \"property\": true\n};\n\nIn many cases, it doesn’t matter if you choose to use an identifier instead of a string\nor vice-versa. Even so, you might decide to enforce a consistent style in your code.\n\nThis rules lets you enforce consistent quoting of property names. Either they should always\nbe quoted (default behavior) or quoted only as needed (\"as-needed\").", - "optionsDescription": "\nPossible settings are:\n\n* `\"always\"`: Property names should always be quoted. (This is the default.)\n* `\"as-needed\"`: Only property names which require quotes may be quoted (e.g. those with spaces in them).\n\nFor ES6, computed property names (`{[name]: value}`) and methods (`{foo() {}}`) never need\nto be quoted.", + "optionsDescription": "\nPossible settings are:\n\n* `\"always\"`: Property names should always be quoted. (This is the default.)\n* `\"as-needed\"`: Only property names which require quotes may be quoted (e.g. those with spaces in them).\n* `\"consistent\"`: Property names should either all be quoted or unquoted.\n* `\"consistent-as-needed\"`: If any property name requires quotes, then all properties must be quoted. Otherwise, no \nproperty names may be quoted.\n\nFor ES6, computed property names (`{[name]: value}`) and methods (`{foo() {}}`) never need\nto be quoted.", "options": { "type": "string", "enum": [ "always", - "as-needed" + "as-needed", + "consistent", + "consistent-as-needed" ] }, "optionExamples": [ diff --git a/docs/rules/object-literal-key-quotes/index.html b/docs/rules/object-literal-key-quotes/index.html index a13b8823c40..66b593d1860 100644 --- a/docs/rules/object-literal-key-quotes/index.html +++ b/docs/rules/object-literal-key-quotes/index.html @@ -25,6 +25,9 @@ * `"always"`: Property names should always be quoted. (This is the default.) * `"as-needed"`: Only property names which require quotes may be quoted (e.g. those with spaces in them). + * `"consistent"`: Property names should either all be quoted or unquoted. + * `"consistent-as-needed"`: If any property name requires quotes, then all properties must be quoted. Otherwise, no + property names may be quoted. For ES6, computed property names (`{[name]: value}`) and methods (`{foo() {}}`) never need to be quoted. @@ -33,6 +36,8 @@ enum: - always - as-needed + - consistent + - consistent-as-needed optionExamples: - '[true, "as-needed"]' - '[true, "always"]' @@ -45,7 +50,9 @@ "type": "string", "enum": [ "always", - "as-needed" + "as-needed", + "consistent", + "consistent-as-needed" ] } --- \ No newline at end of file diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index b5bcb23e808..75fe9cc7c06 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -77,7 +77,7 @@ export const rules = { "no-use-before-declare": false, "no-var-keyword": true, "no-var-requires": true, - "object-literal-key-quotes": [true, "as-needed"], + "object-literal-key-quotes": [true, "consistent-as-needed"], "object-literal-shorthand": true, "object-literal-sort-keys": true, "one-line": [true, diff --git a/src/rules/objectLiteralKeyQuotesRule.ts b/src/rules/objectLiteralKeyQuotesRule.ts index d05bea1d79a..aab9d2ee470 100644 --- a/src/rules/objectLiteralKeyQuotesRule.ts +++ b/src/rules/objectLiteralKeyQuotesRule.ts @@ -28,13 +28,15 @@ export class Rule extends Lint.Rules.AbstractRule { * \`"always"\`: Property names should always be quoted. (This is the default.) * \`"as-needed"\`: Only property names which require quotes may be quoted (e.g. those with spaces in them). + * \`"consistent"\`: Property names should either all be quoted or unquoted. + * \`"consistent-as-needed"\`: If any property name requires quotes, then all properties must be quoted. Otherwise, no + property names may be quoted. For ES6, computed property names (\`{[name]: value}\`) and methods (\`{foo() {}}\`) never need to be quoted.`, options: { type: "string", - enum: ["always", "as-needed"], - // TODO: eslint also supports "consistent", "consistent-as-needed" modes. + enum: ["always", "as-needed", "consistent", "consistent-as-needed"], // TODO: eslint supports "keywords", "unnecessary" and "numbers" options. }, optionExamples: ["[true, \"as-needed\"]", "[true, \"always\"]"], @@ -43,6 +45,7 @@ export class Rule extends Lint.Rules.AbstractRule { }; /* tslint:enable:object-literal-sort-keys */ + public static INCONSISTENT_PROPERTY = `All property names in this object literal must be consistently quoted or unquoted.`; public static UNNEEDED_QUOTES = (name: string) => `Unnecessarily quoted property '${name}' found.`; public static UNQUOTED_PROPERTY = (name: string) => `Unquoted property '${name}' found.`; @@ -57,10 +60,20 @@ const IDENTIFIER_NAME_REGEX = /^(?:[\$A-Z_a-z])*$/; const NUMBER_REGEX = /^[0-9]+$/; -type QuotesMode = "always" | "as-needed"; +type QuotesMode = "always" | "as-needed" | "consistent" | "consistent-as-needed"; + +interface IObjectLiteralState { + // potential failures for properties that have quotes but don't need them + quotesNotNeededProperties: Lint.RuleFailure[]; + // potential failures for properties that don't have quotes + unquotedProperties: Lint.RuleFailure[]; + // whether or not any of the properties require quotes + hasQuotesNeededProperty: boolean; +} class ObjectLiteralKeyQuotesWalker extends Lint.RuleWalker { private mode: QuotesMode; + private currentState: IObjectLiteralState; constructor(sourceFile: ts.SourceFile, options: Lint.IOptions) { super(sourceFile, options); @@ -70,27 +83,59 @@ class ObjectLiteralKeyQuotesWalker extends Lint.RuleWalker { public visitPropertyAssignment(node: ts.PropertyAssignment) { const name = node.name; - if (this.mode === "always") { - if (name.kind !== ts.SyntaxKind.StringLiteral && - name.kind !== ts.SyntaxKind.ComputedPropertyName) { - this.addFailure(this.createFailure(name.getStart(), name.getWidth(), - Rule.UNQUOTED_PROPERTY(name.getText()))); - } - } else if (this.mode === "as-needed") { - if (name.kind === ts.SyntaxKind.StringLiteral) { - // Check if the quoting is necessary. - const stringNode = name as ts.StringLiteral; - const property = stringNode.text; - - const isIdentifier = IDENTIFIER_NAME_REGEX.test(property); - const isNumber = NUMBER_REGEX.test(property); - if (isIdentifier || (isNumber && Number(property).toString() === property)) { - this.addFailure(this.createFailure(stringNode.getStart(), stringNode.getWidth(), - Rule.UNNEEDED_QUOTES(property))); - } + if (name.kind !== ts.SyntaxKind.StringLiteral && + name.kind !== ts.SyntaxKind.ComputedPropertyName) { + + const errorText = Rule.UNQUOTED_PROPERTY(name.getText()); + this.currentState.unquotedProperties.push(this.createFailure(name.getStart(), name.getWidth(), errorText)); + } + if (name.kind === ts.SyntaxKind.StringLiteral) { + // Check if the quoting is necessary. + const stringNode = name as ts.StringLiteral; + const property = stringNode.text; + + const isIdentifier = IDENTIFIER_NAME_REGEX.test(property); + const isNumber = NUMBER_REGEX.test(property); + if (isIdentifier || (isNumber && Number(property).toString() === property)) { + const errorText = Rule.UNNEEDED_QUOTES(property); + const failure = this.createFailure(stringNode.getStart(), stringNode.getWidth(), errorText); + this.currentState.quotesNotNeededProperties.push(failure); + } else { + this.currentState.hasQuotesNeededProperty = true; } } super.visitPropertyAssignment(node); } + + public visitObjectLiteralExpression(node: ts.ObjectLiteralExpression) { + let state: IObjectLiteralState = { + hasQuotesNeededProperty: false, + quotesNotNeededProperties: [], + unquotedProperties: [], + }; + // a nested object literal should store its parent state to restore when finished + let previousState = this.currentState; + this.currentState = state; + + super.visitObjectLiteralExpression(node); + + if (this.mode === "always" || (this.mode === "consistent-as-needed" && state.hasQuotesNeededProperty)) { + for (const failure of state.unquotedProperties) { + this.addFailure(failure); + } + } else if (this.mode === "as-needed" || (this.mode === "consistent-as-needed" && !state.hasQuotesNeededProperty)) { + for (const failure of state.quotesNotNeededProperties) { + this.addFailure(failure); + } + } else if (this.mode === "consistent") { + const hasQuotedProperties = state.hasQuotesNeededProperty || state.quotesNotNeededProperties.length > 0; + const hasUnquotedProperties = state.unquotedProperties.length > 0; + if (hasQuotedProperties && hasUnquotedProperties) { + this.addFailure(this.createFailure(node.getStart(), 1, Rule.INCONSISTENT_PROPERTY)); + } + } + + this.currentState = previousState; + } } diff --git a/test/rules/object-literal-key-quotes/consistent-as-needed/test.js.lint b/test/rules/object-literal-key-quotes/consistent-as-needed/test.js.lint new file mode 100644 index 00000000000..c7ff0f38013 --- /dev/null +++ b/test/rules/object-literal-key-quotes/consistent-as-needed/test.js.lint @@ -0,0 +1,50 @@ + +const o = { + 'hello': 123, + ~~~~~~~ [Unnecessarily quoted property 'hello' found.] + "bye": 45, + ~~~~~ [Unnecessarily quoted property 'bye' found.] +}; +const v = { + "hello": 123, + ~~~~~~~ [Unnecessarily quoted property 'hello' found.] + "bye": 45, + ~~~~~ [Unnecessarily quoted property 'bye' found.] +}; +const s = { + hello: 123, + bye: 45, +}; +const r = { + "hello": 123, + "bye-bye": 45, +}; +const p = { + hello: 123, + "bye": 45, + ~~~~~ [Unnecessarily quoted property 'bye' found.] +}; +const q = { + hello: 123, + ~~~~~ [Unquoted property 'hello' found.] + "bye-bye": 45, +}; +const t = { + hello: 123, + bye-bye: 45, + nested: { + "bird": 2, + ~~~~~~ [Unnecessarily quoted property 'bird' found.] + egg: 3, + } +}; +const u = { + hello: 123, + bye: 45, + nested: { + "bird": 1, + ~~~~~~ [Unnecessarily quoted property 'bird' found.] + "egg": 2, + ~~~~~ [Unnecessarily quoted property 'egg' found.] + } +}; \ No newline at end of file diff --git a/test/rules/object-literal-key-quotes/consistent-as-needed/test.ts.lint b/test/rules/object-literal-key-quotes/consistent-as-needed/test.ts.lint new file mode 100644 index 00000000000..c7ff0f38013 --- /dev/null +++ b/test/rules/object-literal-key-quotes/consistent-as-needed/test.ts.lint @@ -0,0 +1,50 @@ + +const o = { + 'hello': 123, + ~~~~~~~ [Unnecessarily quoted property 'hello' found.] + "bye": 45, + ~~~~~ [Unnecessarily quoted property 'bye' found.] +}; +const v = { + "hello": 123, + ~~~~~~~ [Unnecessarily quoted property 'hello' found.] + "bye": 45, + ~~~~~ [Unnecessarily quoted property 'bye' found.] +}; +const s = { + hello: 123, + bye: 45, +}; +const r = { + "hello": 123, + "bye-bye": 45, +}; +const p = { + hello: 123, + "bye": 45, + ~~~~~ [Unnecessarily quoted property 'bye' found.] +}; +const q = { + hello: 123, + ~~~~~ [Unquoted property 'hello' found.] + "bye-bye": 45, +}; +const t = { + hello: 123, + bye-bye: 45, + nested: { + "bird": 2, + ~~~~~~ [Unnecessarily quoted property 'bird' found.] + egg: 3, + } +}; +const u = { + hello: 123, + bye: 45, + nested: { + "bird": 1, + ~~~~~~ [Unnecessarily quoted property 'bird' found.] + "egg": 2, + ~~~~~ [Unnecessarily quoted property 'egg' found.] + } +}; \ No newline at end of file diff --git a/test/rules/object-literal-key-quotes/consistent-as-needed/tslint.json b/test/rules/object-literal-key-quotes/consistent-as-needed/tslint.json new file mode 100644 index 00000000000..f597be075cc --- /dev/null +++ b/test/rules/object-literal-key-quotes/consistent-as-needed/tslint.json @@ -0,0 +1,8 @@ +{ + "rules": { + "object-literal-key-quotes": [true, "consistent-as-needed"] + }, + "jsRules": { + "object-literal-key-quotes": [true, "consistent-as-needed"] + } +} diff --git a/test/rules/object-literal-key-quotes/consistent/test.js.lint b/test/rules/object-literal-key-quotes/consistent/test.js.lint new file mode 100644 index 00000000000..a2ee53079b5 --- /dev/null +++ b/test/rules/object-literal-key-quotes/consistent/test.js.lint @@ -0,0 +1,44 @@ + +const o = { + 'hello': 123, + "bye": 45, +}; +const v = { + "hello": 123, + "bye": 45, +}; +const s = { + hello: 123, + bye: 45, +}; +const r = { + "hello": 123, + "bye-bye": 45, +}; +const p = { + ~ [All property names in this object literal must be consistently quoted or unquoted.] + hello: 123, + "bye": 45, +}; +const q = { + ~ [All property names in this object literal must be consistently quoted or unquoted.] + hello: 123, + "bye-bye": 45, +}; +const t = { + hello: 123, + bye-bye: 45, + nested: { + ~ [All property names in this object literal must be consistently quoted or unquoted.] + "bird": 2, + egg: 3, + } +}; +const u = { + hello: 123, + bye: 45, + nested: { + "bird": 1, + "egg": 2, + } +}; \ No newline at end of file diff --git a/test/rules/object-literal-key-quotes/consistent/test.ts.lint b/test/rules/object-literal-key-quotes/consistent/test.ts.lint new file mode 100644 index 00000000000..a2ee53079b5 --- /dev/null +++ b/test/rules/object-literal-key-quotes/consistent/test.ts.lint @@ -0,0 +1,44 @@ + +const o = { + 'hello': 123, + "bye": 45, +}; +const v = { + "hello": 123, + "bye": 45, +}; +const s = { + hello: 123, + bye: 45, +}; +const r = { + "hello": 123, + "bye-bye": 45, +}; +const p = { + ~ [All property names in this object literal must be consistently quoted or unquoted.] + hello: 123, + "bye": 45, +}; +const q = { + ~ [All property names in this object literal must be consistently quoted or unquoted.] + hello: 123, + "bye-bye": 45, +}; +const t = { + hello: 123, + bye-bye: 45, + nested: { + ~ [All property names in this object literal must be consistently quoted or unquoted.] + "bird": 2, + egg: 3, + } +}; +const u = { + hello: 123, + bye: 45, + nested: { + "bird": 1, + "egg": 2, + } +}; \ No newline at end of file diff --git a/test/rules/object-literal-key-quotes/consistent/tslint.json b/test/rules/object-literal-key-quotes/consistent/tslint.json new file mode 100644 index 00000000000..5c9b583e66b --- /dev/null +++ b/test/rules/object-literal-key-quotes/consistent/tslint.json @@ -0,0 +1,8 @@ +{ + "rules": { + "object-literal-key-quotes": [true, "consistent"] + }, + "jsRules": { + "object-literal-key-quotes": [true, "consistent"] + } +} From 33019aa1dfe34f4a59f4892a2528d01b5f92011c Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 18 Nov 2016 21:07:44 -0500 Subject: [PATCH 087/111] Create local Error interface so that node doesn't need to be externally referenced (#1741) --- src/configuration.ts | 8 ++++++++ src/test/lintError.ts | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/configuration.ts b/src/configuration.ts index 0d88c5454da..e295aeada39 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -32,6 +32,14 @@ export interface IConfigurationFile { rules?: any; } +/** + * Define `Error` here to avoid using `Error` from @types/node. + * Using the `node` version causes a compilation error when this code is used as an npm library if @types/node is not already imported. + */ +export interface Error { + message: string; +} + export interface IConfigurationLoadResult { error?: Error; path: string; diff --git a/src/test/lintError.ts b/src/test/lintError.ts index 6b04e7b080a..46968be2599 100644 --- a/src/test/lintError.ts +++ b/src/test/lintError.ts @@ -14,6 +14,8 @@ * limitations under the License. */ +import { Error } from "../configuration"; + export interface PositionInFile { line: number; col: number; @@ -40,5 +42,5 @@ export function errorComparator(err1: LintError, err2: LintError) { } export function lintSyntaxError(message: string) { - return new Error(`Lint File Syntax Error: ${message}`); + return new Error(`Lint File Syntax Error: ${message}`) as Error; } From c2216ee5ce1a78e0242bd32be19ca0919aab2816 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Fri, 18 Nov 2016 21:11:14 -0500 Subject: [PATCH 088/111] 4.0 blog post formatting fixes --- docs/_posts/2016-11-17-new-for-4.0.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 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 454d20bfac7..29a1ca08595 100644 --- a/docs/_posts/2016-11-17-new-for-4.0.md +++ b/docs/_posts/2016-11-17-new-for-4.0.md @@ -5,7 +5,8 @@ date: 2016-11-17 15:19:00 --- TSLint 4.0 has been released! With this release comes a few exciting [changes][0]. Some of the highlights: -* **Fixers** - Do you dread turning on a new rule because of all of the new errors? For some of the most common issues, we'll fix them for you. To use this feature, run `tslint` with the `--fix` option. Rules that support the `--fix` feature: + +* **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,12 +14,16 @@ TSLint 4.0 has been released! With this release comes a few exciting [changes][0 * [ordered-imports][6] * [semicolon][7] * [trailing-comma][8] -* **Linting `.js` files** - *A much-requested feature from our community*. Simplify your toolset by running the same rules you know and love on your .js and .jsx files. Just add a `jsRules` [section][9] to your `tslint.json` file, and TSLint will your JavaScript files. -* **TypeScript 2.0+ required** - This lets us deprecate/remove rules that are checked by the compiler. These rules now cause compilation errors: + +* **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"`. + +* **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,10 +35,11 @@ TSLint 4.0 has been released! With this release comes a few exciting [changes][0 * [only-arrow-functions][20] * [ordered-imports][21] * [prefer-for-of][22] + * **Other rules you might find handy**: * [completed-docs][23] * [cyclomatic-complexity][24] - + --- ## Create your own fixer ## @@ -42,11 +48,11 @@ To create your own fixer, instantiate a `Fix` object and pass it in as an argume 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]); +// 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)); +this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING, fix)); ``` [0]: https://github.com/palantir/tslint/releases From 7c5f3a4b3555cd5e0e6c8b30567b2743c9ea6bf5 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 18 Nov 2016 21:28:56 -0500 Subject: [PATCH 089/111] Format develop/custom-rules/index.md --- docs/develop/custom-rules/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/develop/custom-rules/index.md b/docs/develop/custom-rules/index.md index c9d45c7308f..8cc3cded4f7 100644 --- a/docs/develop/custom-rules/index.md +++ b/docs/develop/custom-rules/index.md @@ -58,12 +58,12 @@ 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 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)); +// create a failure at the current position +this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING, fix)); ``` --- Final notes: From 104bba2564e90114efa90bb0794eeb5b41f04e91 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 18 Nov 2016 22:48:24 -0500 Subject: [PATCH 090/111] Fix linting errors (#1744) --- CHANGELOG.md | 8 +++++ README.md | 6 ++-- docs/develop/custom-formatters/index.md | 2 +- src/configs/recommended.ts | 2 +- src/enableDisableRules.ts | 4 +-- src/linter.ts | 4 +-- src/rules/adjacentOverloadSignaturesRule.ts | 12 ++++---- src/rules/alignRule.ts | 2 +- src/rules/banRule.ts | 4 +-- src/rules/commentFormatRule.ts | 4 +-- src/rules/completedDocsRule.ts | 2 +- src/rules/curlyRule.ts | 4 +-- src/rules/cyclomaticComplexityRule.ts | 13 +++++---- src/rules/linebreakStyleRule.ts | 2 +- src/rules/maxClassesPerFileRule.ts | 4 +-- src/rules/maxFileLineCountRule.ts | 4 +-- src/rules/maxLineLengthRule.ts | 2 +- src/rules/memberAccessRule.ts | 2 +- src/rules/noDuplicateVariableRule.ts | 4 ++- src/rules/noEmptyRule.ts | 2 +- src/rules/noInferrableTypesRule.ts | 4 ++- src/rules/noParameterPropertiesRule.ts | 4 ++- src/rules/noShadowedVariableRule.ts | 4 ++- src/rules/noSwitchCaseFallThroughRule.ts | 2 +- src/rules/noUnsafeFinallyRule.ts | 12 ++++---- src/rules/noUnusedExpressionRule.ts | 2 +- src/rules/noUnusedVariableRule.ts | 11 +++---- src/rules/objectLiteralKeyQuotesRule.ts | 29 +++++++++++++++---- src/rules/objectLiteralShorthandRule.ts | 2 +- src/rules/objectLiteralSortKeysRule.ts | 4 ++- src/rules/orderedImportsRule.ts | 4 +-- src/rules/preferForOfRule.ts | 2 +- src/rules/quotemarkRule.ts | 2 +- src/rules/restrictPlusOperandsRule.ts | 4 ++- src/rules/trailingCommaRule.ts | 6 ++-- src/rules/typedefWhitespaceRule.ts | 10 +++---- src/test.ts | 2 +- src/test/parse.ts | 6 ++-- src/tslint-cli.ts | 26 ++++++++--------- src/utils.ts | 2 +- test/configurationTests.ts | 2 +- test/executable/executableTests.ts | 2 +- .../rules/ruleOneRule.js | 2 +- .../rules/ruleThreeRule.js | 2 +- .../rules/ruleTwoRule.js | 2 +- test/files/custom-rules-2/noFailRule.js | 2 +- test/files/custom-rules/alwaysFailRule.js | 2 +- test/ruleLoaderTests.ts | 18 ++++++------ .../default/false-positives.ts.lint | 10 +++++++ .../no-unused-variable/default/import.ts.fix | 4 +++ .../no-unused-variable/default/import.ts.lint | 4 +++ test/rules/semicolon/always/test.ts.fix | 2 ++ test/rules/semicolon/always/test.ts.lint | 2 ++ tslint.json | 1 + 54 files changed, 171 insertions(+), 109 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3593c9aa05c..21ff0dce1f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Change Log === +v4.0.0-dev.2 +--- +* Include latest v4.0.0 changes + v4.0.0 --- * **BREAKING CHANGES** @@ -193,6 +197,10 @@ Thanks to our contributors! * @janaagaard75 * @mprobst +v3.12.0-dev.2 +--- +* [enhancement] Support TypeScript v2.0.0-dev builds + v3.12.1 --- * Stable release containing changes from the last dev release (v3.12.0-dev.1) diff --git a/README.md b/README.md index 01c8c313af2..d89e42499ee 100644 --- a/README.md +++ b/README.md @@ -355,7 +355,7 @@ tsc --noImplicitAny noImportsRule.ts Then, if using the CLI, provide the directory that contains this rule as an option to `--rules-dir`. If using TSLint as a library or via `grunt-tslint`, the `options` hash must contain `"rulesDirectory": "..."`. If you run the linter, you'll see that we have now successfully banned all import statements via TSLint! -Finally, enable each custom rule in your [`tslint.json` config file][0] config file. +Finally, enable each custom rule in your [`tslint.json` config file](https://palantir.github.io/tslint/usage/tslint-json/) config file. Final notes: @@ -370,7 +370,7 @@ Just like rules, additional formatters can also be supplied to TSLint via `--for ```typescript import * as ts from "typescript"; -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint"; export class Formatter extends Lint.Formatters.AbstractFormatter { public format(failures: Lint.RuleFailure[]): string { @@ -412,5 +412,3 @@ Creating a new release 4. Commit with message `Prepare release ` 5. Run `npm publish` 6. Create a git tag for the new release and push it ([see existing tags here](https://github.com/palantir/tslint/tags)) - -[0]: {{site.baseurl | append: "/usage/tslint-json/"}} diff --git a/docs/develop/custom-formatters/index.md b/docs/develop/custom-formatters/index.md index a88daad73ca..173c8e3f868 100644 --- a/docs/develop/custom-formatters/index.md +++ b/docs/develop/custom-formatters/index.md @@ -8,7 +8,7 @@ Just like [custom rules][0], additional formatters can also be supplied to TSLin ```ts import * as ts from "typescript"; -import * as Lint from "tslint/lib/lint"; +import * as Lint from "tslint"; export class Formatter extends Lint.Formatters.AbstractFormatter { public format(failures: Lint.RuleFailure[]): string { diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index 75fe9cc7c06..77acc19835a 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -36,13 +36,13 @@ export const rules = { "interface-name": [true, "always-prefix"], "jsdoc-format": true, "label-position": true, + "max-classes-per-file": [true, 1], "max-line-length": [true, 120], "member-access": true, "member-ordering": [true, { "order": "statics-first" }, ], "new-parens": true, - "max-classes-per-file": [true, 1], "no-any": false, "no-arg": true, "no-bitwise": true, diff --git a/src/enableDisableRules.ts b/src/enableDisableRules.ts index b67ca86b43a..ae9f42dec9e 100644 --- a/src/enableDisableRules.ts +++ b/src/enableDisableRules.ts @@ -48,7 +48,7 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker { private getStartOfLinePosition(node: ts.SourceFile, position: number, lineOffset = 0) { return node.getPositionOfLineAndCharacter( - node.getLineAndCharacterOfPosition(position).line + lineOffset, 0 + node.getLineAndCharacterOfPosition(position).line + lineOffset, 0, ); } @@ -73,7 +73,7 @@ export class EnableDisableRulesWalker extends SkippableTokenAwareRuleWalker { rulesList = commentTextParts[1].split(/\s+/).slice(1); // remove empty items and potential comment end. - rulesList = rulesList.filter(item => !!item && item.indexOf("*/") === -1); + rulesList = rulesList.filter((item) => !!item && item.indexOf("*/") === -1); // potentially there were no items, so default to `all`. rulesList = rulesList.length > 0 ? rulesList : ["all"]; diff --git a/src/linter.ts b/src/linter.ts index f5d196d6c86..39c192e1627 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -20,11 +20,11 @@ import * as ts from "typescript"; import { DEFAULT_CONFIG, - IConfigurationFile, findConfiguration, findConfigurationPath, getRelativePath, getRulesDirectories, + IConfigurationFile, loadConfigurationFromPath, } from "./configuration"; import { EnableDisableRulesWalker } from "./enableDisableRules"; @@ -41,7 +41,7 @@ import { arrayify, dedent } from "./utils"; * Linter that can lint multiple files in consecutive runs. */ class Linter { - public static VERSION = "4.0.0"; + public static VERSION = "4.0.0-dev.2"; public static findConfiguration = findConfiguration; public static findConfigurationPath = findConfigurationPath; diff --git a/src/rules/adjacentOverloadSignaturesRule.ts b/src/rules/adjacentOverloadSignaturesRule.ts index 65e44933bbf..e95c1f303ed 100644 --- a/src/rules/adjacentOverloadSignaturesRule.ts +++ b/src/rules/adjacentOverloadSignaturesRule.ts @@ -34,7 +34,9 @@ export class Rule extends Lint.Rules.AbstractRule { }; /* tslint:enable:object-literal-sort-keys */ - public static FAILURE_STRING_FACTORY = (name: string) => `All '${name}' signatures should be adjacent`; + public static FAILURE_STRING_FACTORY = (name: string) => { + return `All '${name}' signatures should be adjacent`; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new AdjacentOverloadSignaturesWalker(sourceFile, this.getOptions())); @@ -56,7 +58,7 @@ class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker { } public visitInterfaceDeclaration(node: ts.InterfaceDeclaration): void { - this.checkOverloadsAdjacent(node.members, member => member.name && getTextOfPropertyName(member.name)); + this.checkOverloadsAdjacent(node.members, (member) => member.name && getTextOfPropertyName(member.name)); super.visitInterfaceDeclaration(node); } @@ -71,7 +73,7 @@ class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker { } private visitStatements(statements: ts.Statement[]) { - this.checkOverloadsAdjacent(statements, statement => { + this.checkOverloadsAdjacent(statements, (statement) => { if (statement.kind === ts.SyntaxKind.FunctionDeclaration) { const name = (statement as ts.FunctionDeclaration).name; return name && name.text; @@ -81,8 +83,8 @@ class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker { }); } - private visitMembers(members: (ts.TypeElement | ts.ClassElement)[]) { - this.checkOverloadsAdjacent(members, member => member.name && getTextOfPropertyName(member.name)); + private visitMembers(members: Array) { + this.checkOverloadsAdjacent(members, (member) => member.name && getTextOfPropertyName(member.name)); } /** 'getOverloadName' may return undefined for nodes that cannot be overloads, e.g. a `const` declaration. */ diff --git a/src/rules/alignRule.ts b/src/rules/alignRule.ts index 65141617e21..44bb0aa7256 100644 --- a/src/rules/alignRule.ts +++ b/src/rules/alignRule.ts @@ -61,7 +61,7 @@ export class Rule extends Lint.Rules.AbstractRule { type SourcePosition = { line: number; character: number; -} +}; class AlignWalker extends Lint.RuleWalker { public visitConstructorDeclaration(node: ts.ConstructorDeclaration) { diff --git a/src/rules/banRule.ts b/src/rules/banRule.ts index a621978f4be..341f7276026 100644 --- a/src/rules/banRule.ts +++ b/src/rules/banRule.ts @@ -45,7 +45,7 @@ export class Rule extends Lint.Rules.AbstractRule { public static FAILURE_STRING_FACTORY = (expression: string, messageAddition?: string) => { return `Calls to '${expression}' are not allowed.${messageAddition ? " " + messageAddition : ""}`; - }; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { const options = this.getOptions(); @@ -102,7 +102,7 @@ export class BanFunctionWalker extends Lint.RuleWalker { const failure = this.createFailure( expression.getStart(), expression.getWidth(), - Rule.FAILURE_STRING_FACTORY(`${leftSideExpression}.${rightSideExpression}`, bannedFunction[2]) + Rule.FAILURE_STRING_FACTORY(`${leftSideExpression}.${rightSideExpression}`, bannedFunction[2]), ); this.addFailure(failure); } diff --git a/src/rules/commentFormatRule.ts b/src/rules/commentFormatRule.ts index 5b074c364e9..c51689d56d7 100644 --- a/src/rules/commentFormatRule.ts +++ b/src/rules/commentFormatRule.ts @@ -118,11 +118,11 @@ function startsWith(commentText: string, changeCase: (str: string) => string) { } function startsWithLowercase(commentText: string) { - return startsWith(commentText, c => c.toLowerCase()); + return startsWith(commentText, (c) => c.toLowerCase()); } function startsWithUppercase(commentText: string) { - return startsWith(commentText, c => c.toUpperCase()); + return startsWith(commentText, (c) => c.toUpperCase()); } function startsWithSpace(commentText: string) { diff --git a/src/rules/completedDocsRule.ts b/src/rules/completedDocsRule.ts index b5d2b265ebd..a43ad746ac2 100644 --- a/src/rules/completedDocsRule.ts +++ b/src/rules/completedDocsRule.ts @@ -106,7 +106,7 @@ export class CompletedDocsWalker extends Lint.ProgramAwareRuleWalker { const comments = this.getTypeChecker().getSymbolAtLocation(node.name).getDocumentationComment(); - if (comments.map(comment => comment.text).join("").trim() === "") { + if (comments.map((comment) => comment.text).join("").trim() === "") { this.addFailure(this.createDocumentationFailure(node, nodeToCheck)); } } diff --git a/src/rules/curlyRule.ts b/src/rules/curlyRule.ts index b86b74b7221..bcddb77b349 100644 --- a/src/rules/curlyRule.ts +++ b/src/rules/curlyRule.ts @@ -83,7 +83,7 @@ class CurlyWalker extends Lint.RuleWalker { this.addFailure(this.createFailure( node.getStart(), node.thenStatement.getEnd() - node.getStart(), - Rule.IF_FAILURE_STRING + Rule.IF_FAILURE_STRING, )); } @@ -97,7 +97,7 @@ class CurlyWalker extends Lint.RuleWalker { this.addFailure(this.createFailure( elseKeywordNode.getStart(), node.elseStatement.getEnd() - elseKeywordNode.getStart(), - Rule.ELSE_FAILURE_STRING + Rule.ELSE_FAILURE_STRING, )); } diff --git a/src/rules/cyclomaticComplexityRule.ts b/src/rules/cyclomaticComplexityRule.ts index 8f4ddc430ed..ddefdee516f 100644 --- a/src/rules/cyclomaticComplexityRule.ts +++ b/src/rules/cyclomaticComplexityRule.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import * as Lint from "../index"; import * as ts from "typescript"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { @@ -54,10 +54,13 @@ export class Rule extends Lint.Rules.AbstractRule { }; /* tslint:enable:object-literal-sort-keys */ - public static ANONYMOUS_FAILURE_STRING = (expected: number, actual: number) => - `The function has a cyclomatic complexity of ${actual} which is higher than the threshold of ${expected}`; - public static NAMED_FAILURE_STRING = (expected: number, actual: number, name: string) => - `The function ${name} has a cyclomatic complexity of ${actual} which is higher than the threshold of ${expected}`; + public static ANONYMOUS_FAILURE_STRING = (expected: number, actual: number) => { + return `The function has a cyclomatic complexity of ${actual} which is higher than the threshold of ${expected}`; + } + + public static NAMED_FAILURE_STRING = (expected: number, actual: number, name: string) => { + return `The function ${name} has a cyclomatic complexity of ${actual} which is higher than the threshold of ${expected}`; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new CyclomaticComplexityWalker(sourceFile, this.getOptions(), this.threshold)); diff --git a/src/rules/linebreakStyleRule.ts b/src/rules/linebreakStyleRule.ts index 2fc8bf2a999..a8cff31c5f7 100644 --- a/src/rules/linebreakStyleRule.ts +++ b/src/rules/linebreakStyleRule.ts @@ -53,7 +53,7 @@ export class Rule extends Lint.Rules.AbstractRule { sourceFile.languageVersion, false, sourceFile.languageVariant, - sourceFile.getFullText() + sourceFile.getFullText(), ); const linebreakStyle = this.getOptions().ruleArguments[0] || OPTION_LINEBREAK_STYLE_LF; diff --git a/src/rules/maxClassesPerFileRule.ts b/src/rules/maxClassesPerFileRule.ts index cd7d112b10b..5bb613adaa4 100644 --- a/src/rules/maxClassesPerFileRule.ts +++ b/src/rules/maxClassesPerFileRule.ts @@ -1,5 +1,5 @@ -import * as Lint from "../index"; -import * as ts from "typescript"; +import * as ts from "typescript"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { diff --git a/src/rules/maxFileLineCountRule.ts b/src/rules/maxFileLineCountRule.ts index 7995c6d28d5..641800d2b11 100644 --- a/src/rules/maxFileLineCountRule.ts +++ b/src/rules/maxFileLineCountRule.ts @@ -14,8 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import * as Lint from "../index"; import * as ts from "typescript"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ @@ -40,7 +40,7 @@ export class Rule extends Lint.Rules.AbstractRule { let msg = `This file has ${lineCount} lines, which exceeds the maximum of ${lineLimit} lines allowed. `; msg += `Consider breaking this file up into smaller parts`; return msg; - }; + } public isEnabled(): boolean { if (super.isEnabled()) { diff --git a/src/rules/maxLineLengthRule.ts b/src/rules/maxLineLengthRule.ts index bf356a4bf8e..d46730c2624 100644 --- a/src/rules/maxLineLengthRule.ts +++ b/src/rules/maxLineLengthRule.ts @@ -41,7 +41,7 @@ export class Rule extends Lint.Rules.AbstractRule { public static FAILURE_STRING_FACTORY = (lineLimit: number) => { return `Exceeds maximum line length of ${lineLimit}`; - }; + } public isEnabled(): boolean { if (super.isEnabled()) { diff --git a/src/rules/memberAccessRule.ts b/src/rules/memberAccessRule.ts index 817b38dc2da..8fef76d20f3 100644 --- a/src/rules/memberAccessRule.ts +++ b/src/rules/memberAccessRule.ts @@ -101,7 +101,7 @@ export class MemberAccessWalker extends Lint.RuleWalker { node.modifiers, ts.SyntaxKind.PublicKeyword, ts.SyntaxKind.PrivateKeyword, - ts.SyntaxKind.ProtectedKeyword + ts.SyntaxKind.ProtectedKeyword, ); if (!hasAnyVisibilityModifiers) { diff --git a/src/rules/noDuplicateVariableRule.ts b/src/rules/noDuplicateVariableRule.ts index 5d636721831..7dc9473bfdb 100644 --- a/src/rules/noDuplicateVariableRule.ts +++ b/src/rules/noDuplicateVariableRule.ts @@ -38,7 +38,9 @@ export class Rule extends Lint.Rules.AbstractRule { }; /* tslint:enable:object-literal-sort-keys */ - public static FAILURE_STRING_FACTORY = (name: string) => `Duplicate variable: '${name}'`; + public static FAILURE_STRING_FACTORY = (name: string) => { + return `Duplicate variable: '${name}'`; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new NoDuplicateVariableWalker(sourceFile, this.getOptions())); diff --git a/src/rules/noEmptyRule.ts b/src/rules/noEmptyRule.ts index fe3b216665c..d6dbbe1b695 100644 --- a/src/rules/noEmptyRule.ts +++ b/src/rules/noEmptyRule.ts @@ -69,7 +69,7 @@ class BlockWalker extends Lint.RuleWalker { ts.SyntaxKind.PrivateKeyword, ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.PublicKeyword, - ts.SyntaxKind.ReadonlyKeyword + ts.SyntaxKind.ReadonlyKeyword, ); if (hasPropertyAccessModifier) { diff --git a/src/rules/noInferrableTypesRule.ts b/src/rules/noInferrableTypesRule.ts index 257030e7565..79c918d9cc8 100644 --- a/src/rules/noInferrableTypesRule.ts +++ b/src/rules/noInferrableTypesRule.ts @@ -47,7 +47,9 @@ export class Rule extends Lint.Rules.AbstractRule { }; /* tslint:enable:object-literal-sort-keys */ - public static FAILURE_STRING_FACTORY = (type: string) => `LHS type (${type}) inferred by RHS expression, remove type annotation`; + public static FAILURE_STRING_FACTORY = (type: string) => { + return `LHS type (${type}) inferred by RHS expression, remove type annotation`; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new NoInferrableTypesWalker(sourceFile, this.getOptions())); diff --git a/src/rules/noParameterPropertiesRule.ts b/src/rules/noParameterPropertiesRule.ts index 9561d64fb00..d4ee70be800 100644 --- a/src/rules/noParameterPropertiesRule.ts +++ b/src/rules/noParameterPropertiesRule.ts @@ -35,7 +35,9 @@ export class Rule extends Lint.Rules.AbstractRule { }; /* tslint:enable:object-literal-sort-keys */ - public static FAILURE_STRING_FACTORY = (ident: string) => `Property '${ident}' cannot be declared in the constructor`; + public static FAILURE_STRING_FACTORY = (ident: string) => { + return `Property '${ident}' cannot be declared in the constructor`; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new NoParameterPropertiesWalker(sourceFile, this.getOptions())); diff --git a/src/rules/noShadowedVariableRule.ts b/src/rules/noShadowedVariableRule.ts index e50c3b168df..6b2ffa0057e 100644 --- a/src/rules/noShadowedVariableRule.ts +++ b/src/rules/noShadowedVariableRule.ts @@ -33,7 +33,9 @@ export class Rule extends Lint.Rules.AbstractRule { }; /* tslint:enable:object-literal-sort-keys */ - public static FAILURE_STRING_FACTORY = (name: string) => `Shadowed variable: '${name}'`; + public static FAILURE_STRING_FACTORY = (name: string) => { + return `Shadowed variable: '${name}'`; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new NoShadowedVariableWalker(sourceFile, this.getOptions())); diff --git a/src/rules/noSwitchCaseFallThroughRule.ts b/src/rules/noSwitchCaseFallThroughRule.ts index 218a6bd4dc0..29b8cc7b678 100644 --- a/src/rules/noSwitchCaseFallThroughRule.ts +++ b/src/rules/noSwitchCaseFallThroughRule.ts @@ -83,7 +83,7 @@ export class NoSwitchCaseFallThroughWalker extends Lint.RuleWalker { this.addFailure(this.createFailure( switchClauses[i + 1].getStart(), "case".length, - `${Rule.FAILURE_STRING_PART}'case'` + `${Rule.FAILURE_STRING_PART}'case'`, )); } } diff --git a/src/rules/noUnsafeFinallyRule.ts b/src/rules/noUnsafeFinallyRule.ts index 1a5664ba4f1..bfe8669a5a7 100644 --- a/src/rules/noUnsafeFinallyRule.ts +++ b/src/rules/noUnsafeFinallyRule.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import * as Lint from "../index"; import * as ts from "typescript"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ @@ -40,14 +40,12 @@ export class Rule extends Lint.Rules.AbstractRule { /* tslint:enable:object-literal-sort-keys */ public static FAILURE_TYPE_BREAK = "break"; - public static FAILURE_TYPE_CONTINUE = "continue"; - public static FAILURE_TYPE_RETURN = "return"; - public static FAILURE_TYPE_THROW = "throw"; - - public static FAILURE_STRING_FACTORY = (name: string) => `${name} statements in finally blocks are forbidden.`; + public static FAILURE_STRING_FACTORY = (name: string) => { + return `${name} statements in finally blocks are forbidden.`; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new NoReturnInFinallyScopeAwareWalker(sourceFile, this.getOptions())); @@ -81,7 +79,7 @@ interface IFinallyScope { /** * A collection of `break` or `continue` labels in this scope. */ - labels: Array; + labels: string[]; } /** diff --git a/src/rules/noUnusedExpressionRule.ts b/src/rules/noUnusedExpressionRule.ts index 83c51a222c9..4fa5285e7e3 100644 --- a/src/rules/noUnusedExpressionRule.ts +++ b/src/rules/noUnusedExpressionRule.ts @@ -70,7 +70,7 @@ export class NoUnusedExpressionWalker extends Lint.RuleWalker { if (checkPreviousSiblings) { const siblings: ts.Node[] = []; - ts.forEachChild(node.parent, child => { siblings.push(child); }); + ts.forEachChild(node.parent, (child) => { siblings.push(child); }); return siblings.slice(0, siblings.indexOf(node)).every((n) => NoUnusedExpressionWalker.isDirective(n, false)); } else { return true; diff --git a/src/rules/noUnusedVariableRule.ts b/src/rules/noUnusedVariableRule.ts index 280e0bc2a76..3e1dcb54485 100644 --- a/src/rules/noUnusedVariableRule.ts +++ b/src/rules/noUnusedVariableRule.ts @@ -74,8 +74,9 @@ export class Rule extends Lint.Rules.AbstractRule { public static FAILURE_TYPE_PARAM = "parameter"; public static FAILURE_TYPE_PROP = "property"; public static FAILURE_TYPE_VAR = "variable"; - - public static FAILURE_STRING_FACTORY = (type: string, name: string) => `Unused ${type}: '${name}'`; + public static FAILURE_STRING_FACTORY = (type: string, name: string) => { + return `Unused ${type}: '${name}'`; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { const languageService = Lint.createLanguageService(sourceFile.fileName, sourceFile.getFullText()); @@ -196,7 +197,7 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker { if (importClause.namedBindings != null) { if (importClause.namedBindings.kind === ts.SyntaxKind.NamedImports) { let imports = node.importClause.namedBindings as ts.NamedImports; - usedNamedImports = imports.elements.map(e => this.isUsed(e.name.text, e.name.getStart())); + usedNamedImports = imports.elements.map((e) => this.isUsed(e.name.text, e.name.getStart())); } // Avoid deleting the whole statement if there's an import * inside if (importClause.namedBindings.kind === ts.SyntaxKind.NamespaceImport) { @@ -205,7 +206,7 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker { } // Delete the entire import statement if named and default imports all unused - if (!usesDefaultImport && usedNamedImports.every(e => !e)) { + if (!usesDefaultImport && usedNamedImports.every((e) => !e)) { this.fail(Rule.FAILURE_TYPE_IMPORT, node.getText(), node.getStart(), this.deleteImportStatement(node)); super.visitImportDeclaration(node); return; @@ -222,7 +223,7 @@ class NoUnusedVariablesWalker extends Lint.RuleWalker { if (importClause.namedBindings != null && importClause.namedBindings.kind === ts.SyntaxKind.NamedImports) { // Delete the entire named imports if all unused, including curly braces. - if (usedNamedImports.every(e => !e)) { + if (usedNamedImports.every((e) => !e)) { const start = importClause.name != null ? importClause.name.getEnd() : importClause.namedBindings.getStart(); this.fail(Rule.FAILURE_TYPE_IMPORT, importClause.namedBindings.getText(), importClause.namedBindings.getStart(), [ this.deleteText(start, importClause.namedBindings.getEnd() - start), diff --git a/src/rules/objectLiteralKeyQuotesRule.ts b/src/rules/objectLiteralKeyQuotesRule.ts index aab9d2ee470..46ba55f8caa 100644 --- a/src/rules/objectLiteralKeyQuotesRule.ts +++ b/src/rules/objectLiteralKeyQuotesRule.ts @@ -1,5 +1,22 @@ -import * as Lint from "../index"; +/** + * @license + * Copyright 2016 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import * as ts from "typescript"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ @@ -46,8 +63,12 @@ export class Rule extends Lint.Rules.AbstractRule { /* tslint:enable:object-literal-sort-keys */ public static INCONSISTENT_PROPERTY = `All property names in this object literal must be consistently quoted or unquoted.`; - public static UNNEEDED_QUOTES = (name: string) => `Unnecessarily quoted property '${name}' found.`; - public static UNQUOTED_PROPERTY = (name: string) => `Unquoted property '${name}' found.`; + public static UNNEEDED_QUOTES = (name: string) => { + return `Unnecessarily quoted property '${name}' found.`; + } + public static UNQUOTED_PROPERTY = (name: string) => { + return `Unquoted property '${name}' found.`; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { const objectLiteralKeyQuotesWalker = new ObjectLiteralKeyQuotesWalker(sourceFile, this.getOptions()); @@ -57,9 +78,7 @@ export class Rule extends Lint.Rules.AbstractRule { // This is simplistic. See https://mothereff.in/js-properties for the gorey details. const IDENTIFIER_NAME_REGEX = /^(?:[\$A-Z_a-z])*$/; - const NUMBER_REGEX = /^[0-9]+$/; - type QuotesMode = "always" | "as-needed" | "consistent" | "consistent-as-needed"; interface IObjectLiteralState { diff --git a/src/rules/objectLiteralShorthandRule.ts b/src/rules/objectLiteralShorthandRule.ts index ed59daa3828..aefc93181a8 100644 --- a/src/rules/objectLiteralShorthandRule.ts +++ b/src/rules/objectLiteralShorthandRule.ts @@ -1,5 +1,5 @@ -import * as Lint from "../index"; import * as ts from "typescript"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/objectLiteralSortKeysRule.ts b/src/rules/objectLiteralSortKeysRule.ts index 48b9567e3ec..78dc7d96efa 100644 --- a/src/rules/objectLiteralSortKeysRule.ts +++ b/src/rules/objectLiteralSortKeysRule.ts @@ -33,7 +33,9 @@ export class Rule extends Lint.Rules.AbstractRule { }; /* tslint:enable:object-literal-sort-keys */ - public static FAILURE_STRING_FACTORY = (name: string) => `The key '${name}' is not sorted alphabetically`; + public static FAILURE_STRING_FACTORY = (name: string) => { + return `The key '${name}' is not sorted alphabetically`; + } public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new ObjectLiteralSortKeysWalker(sourceFile, this.getOptions())); diff --git a/src/rules/orderedImportsRule.ts b/src/rules/orderedImportsRule.ts index b241f212e21..a78e4fc26e2 100644 --- a/src/rules/orderedImportsRule.ts +++ b/src/rules/orderedImportsRule.ts @@ -89,7 +89,7 @@ export class Rule extends Lint.Rules.AbstractRule { // Convert aBcD --> AbCd function flipCase(x: string): string { - return x.split("").map(char => { + return x.split("").map((char) => { if (char >= "a" && char <= "z") { return char.toUpperCase(); } else if (char >= "A" && char <= "Z") { @@ -143,7 +143,7 @@ function sortByKey(xs: T[], getSortKey: (x: T) => string): T[] { // Transformations to apply to produce the desired ordering of imports. // The imports must be lexicographically sorted after applying the transform. const TRANSFORMS: {[ordering: string]: (x: string) => string} = { - any: () => "", + "any": () => "", "case-insensitive": (x: string) => x.toLowerCase(), "lowercase-first": flipCase, "lowercase-last": (x: string) => x, diff --git a/src/rules/preferForOfRule.ts b/src/rules/preferForOfRule.ts index 68183ea3c49..51edb4eca1f 100644 --- a/src/rules/preferForOfRule.ts +++ b/src/rules/preferForOfRule.ts @@ -15,8 +15,8 @@ * limitations under the License. */ -import * as Lint from "../index"; import * as ts from "typescript"; +import * as Lint from "../index"; export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ diff --git a/src/rules/quotemarkRule.ts b/src/rules/quotemarkRule.ts index ab159c96be5..ebfb7bda6f3 100644 --- a/src/rules/quotemarkRule.ts +++ b/src/rules/quotemarkRule.ts @@ -21,7 +21,7 @@ import * as Lint from "../index"; enum QuoteMark { SINGLE_QUOTES, - DOUBLE_QUOTES + DOUBLE_QUOTES, } export class Rule extends Lint.Rules.AbstractRule { diff --git a/src/rules/restrictPlusOperandsRule.ts b/src/rules/restrictPlusOperandsRule.ts index d5fe764fad6..05becd841fa 100644 --- a/src/rules/restrictPlusOperandsRule.ts +++ b/src/rules/restrictPlusOperandsRule.ts @@ -34,7 +34,9 @@ export class Rule extends Lint.Rules.TypedRule { /* tslint:enable:object-literal-sort-keys */ public static MISMATCHED_TYPES_FAILURE = "Types of values used in '+' operation must match"; - public static UNSUPPORTED_TYPE_FAILURE_FACTORY = (type: string) => `cannot add type ${type}`; + public static UNSUPPORTED_TYPE_FAILURE_FACTORY = (type: string) => { + return `cannot add type ${type}`; + } public applyWithProgram(sourceFile: ts.SourceFile, program: ts.Program): Lint.RuleFailure[] { return this.applyWithWalker(new RestrictPlusOperandsWalker(sourceFile, this.getOptions(), program)); diff --git a/src/rules/trailingCommaRule.ts b/src/rules/trailingCommaRule.ts index 35d50dd61bd..845cf4be0f7 100644 --- a/src/rules/trailingCommaRule.ts +++ b/src/rules/trailingCommaRule.ts @@ -66,7 +66,7 @@ export class Rule extends Lint.Rules.AbstractRule { } class TrailingCommaWalker extends Lint.RuleWalker { - private static SYNTAX_LIST_WRAPPER_TOKENS: [ts.SyntaxKind, ts.SyntaxKind][] = [ + private static SYNTAX_LIST_WRAPPER_TOKENS: Array<[ts.SyntaxKind, ts.SyntaxKind]> = [ [ts.SyntaxKind.OpenBraceToken, ts.SyntaxKind.CloseBraceToken], [ts.SyntaxKind.OpenBracketToken, ts.SyntaxKind.CloseBracketToken], [ts.SyntaxKind.OpenParenToken, ts.SyntaxKind.CloseParenToken], @@ -189,8 +189,8 @@ class TrailingCommaWalker extends Lint.RuleWalker { // as opposed to optionals alongside it. So instead of children[i + 1] having // [ PropertySignature, Semicolon, PropertySignature, Semicolon ], the AST is // [ PropertySignature, PropertySignature], where the Semicolons are under PropertySignature - const hasSemicolon = grandChildren.some(grandChild => { - return grandChild.getChildren().some(ggc => ggc.kind === ts.SyntaxKind.SemicolonToken); + const hasSemicolon = grandChildren.some((grandChild) => { + return grandChild.getChildren().some((ggc) => ggc.kind === ts.SyntaxKind.SemicolonToken); }); if (!hasSemicolon) { diff --git a/src/rules/typedefWhitespaceRule.ts b/src/rules/typedefWhitespaceRule.ts index ea76e575ef5..c7cbb094262 100644 --- a/src/rules/typedefWhitespaceRule.ts +++ b/src/rules/typedefWhitespaceRule.ts @@ -30,7 +30,7 @@ const SPACE_OBJECT = { properties: { "call-signature": SPACE_OPTIONS, "index-signature": SPACE_OPTIONS, - parameter: SPACE_OPTIONS, + "parameter": SPACE_OPTIONS, "property-declaration": SPACE_OPTIONS, "variable-declaration": SPACE_OPTIONS, }, @@ -90,9 +90,7 @@ export class Rule extends Lint.Rules.AbstractRule { class TypedefWhitespaceWalker extends Lint.RuleWalker { private static getColonPosition(node: ts.Node) { - const colon = node.getChildren().filter((child) => - child.kind === ts.SyntaxKind.ColonToken - )[0]; + const colon = node.getChildren().filter((child) => child.kind === ts.SyntaxKind.ColonToken)[0]; return colon == null ? -1 : colon.getStart(); } @@ -241,7 +239,7 @@ class TypedefWhitespaceWalker extends Lint.RuleWalker { hasLeadingWhitespace, hasSeveralLeadingWhitespaces, colonPosition - 1, - message + message, ); } } @@ -283,7 +281,7 @@ class TypedefWhitespaceWalker extends Lint.RuleWalker { hasTrailingWhitespace, hasSeveralTrailingWhitespaces, colonPosition + 1, - message + message, ); } } diff --git a/src/test.ts b/src/test.ts index de9f71d133d..90c8e94cc75 100644 --- a/src/test.ts +++ b/src/test.ts @@ -119,7 +119,7 @@ export function runTest(testDirectory: string, rulesDirectory?: string | string[ const stat = fs.statSync(fixedFile); if (stat.isFile()) { fixedFileText = fs.readFileSync(fixedFile, "utf8"); - const fixes = failures.filter(f => f.hasFix()).map(f => f.getFix()); + const fixes = failures.filter((f) => f.hasFix()).map((f) => f.getFix()); newFileText = Fix.applyAll(fileTextWithoutMarkup, fixes); } } catch (e) { diff --git a/src/test/parse.ts b/src/test/parse.ts index 24366ecbc58..d0f8c8d2abc 100644 --- a/src/test/parse.ts +++ b/src/test/parse.ts @@ -24,7 +24,7 @@ import { parseLine, printLine, } from "./lines"; -import {LintError, errorComparator, lintSyntaxError} from "./lintError"; +import {errorComparator, LintError, lintSyntaxError} from "./lintError"; /** * Takes the full text of a .lint file and returns the contents of the file @@ -83,7 +83,7 @@ export function parseErrorsFromMarkup(text: string): LintError[] { for (let nextLineNo = lineNo + 1; ; ++nextLineNo) { if (!isValidErrorMarkupContinuation(errorLinesForCodeLines, nextLineNo)) { throw lintSyntaxError( - `Error mark starting at ${errorStartPos.line}:${errorStartPos.col} does not end correctly.` + `Error mark starting at ${errorStartPos.line}:${errorStartPos.col} does not end correctly.`, ); } else { const nextErrorLine = errorLinesForCodeLines[nextLineNo].shift(); @@ -122,7 +122,7 @@ export function createMarkupFromErrors(code: string, lintErrors: LintError[]) { errorLinesForCodeText[startPos.line].push(new EndErrorLine( startPos.col, endPos.col, - message + message, )); } else { // multiline error diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index ab8d3d259c1..7018a2e76fe 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -43,58 +43,58 @@ let processed = optimist } }) .options({ - c: { + "c": { alias: "config", describe: "configuration file", }, - e: { + "e": { alias: "exclude", describe: "exclude globs from path expansion", type: "string", }, - fix: { + "fix": { describe: "Fixes linting errors for select rules. This may overwrite linted files", type: "boolean", }, - force: { + "force": { describe: "return status code 0 even if there are lint errors", type: "boolean", }, - h: { + "h": { alias: "help", describe: "display detailed help", }, - i: { + "i": { alias: "init", describe: "generate a tslint.json config file in the current working directory", }, - o: { + "o": { alias: "out", describe: "output file", }, - project: { + "project": { describe: "tsconfig.json file", }, - r: { + "r": { alias: "rules-dir", describe: "rules directory", }, - s: { + "s": { alias: "formatters-dir", describe: "formatters directory", }, - t: { + "t": { alias: "format", default: "prose", describe: "output format (prose, json, stylish, verbose, pmd, msbuild, checkstyle, vso, fileslist)", }, - test: { + "test": { describe: "test that tslint produces the correct output for the specified directory", }, "type-check": { describe: "enable type checking when linting a project", }, - v: { + "v": { alias: "version", describe: "current version", }, diff --git a/src/utils.ts b/src/utils.ts index c8b58e36c79..7279b2a7396 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -55,7 +55,7 @@ export function dedent(strings: TemplateStringsArray, ...values: string[]) { } // find the smallest indent, we don't want to remove all leading whitespace - const indent = Math.min(...match.map(el => el.length)); + const indent = Math.min(...match.map((el) => el.length)); const regexp = new RegExp("^[ \\t]{" + indent + "}", "gm"); fullString = indent > 0 ? fullString.replace(regexp, "") : fullString; return fullString; diff --git a/test/configurationTests.ts b/test/configurationTests.ts index 1a4d28eda2a..11134abcacb 100644 --- a/test/configurationTests.ts +++ b/test/configurationTests.ts @@ -16,7 +16,7 @@ import * as fs from "fs"; -import { IConfigurationFile, extendConfigurationFile, loadConfigurationFromPath } from "../src/configuration"; +import { extendConfigurationFile, IConfigurationFile, loadConfigurationFromPath } from "../src/configuration"; import { createTempFile } from "./utils"; describe("Configuration", () => { diff --git a/test/executable/executableTests.ts b/test/executable/executableTests.ts index 08655c96b56..60a2f7262b1 100644 --- a/test/executable/executableTests.ts +++ b/test/executable/executableTests.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import { createTempFile, denormalizeWinPath } from "../utils"; import * as cp from "child_process"; import * as fs from "fs"; import * as os from "os"; import * as path from "path"; +import { createTempFile, denormalizeWinPath } from "../utils"; // when tests are run with mocha from npm scripts CWD points to project root const EXECUTABLE_DIR = path.resolve(process.cwd(), "test", "executable"); diff --git a/test/external/tslint-test-custom-rules/rules/ruleOneRule.js b/test/external/tslint-test-custom-rules/rules/ruleOneRule.js index 1d2ff62d1af..9b8b16e0fb8 100644 --- a/test/external/tslint-test-custom-rules/rules/ruleOneRule.js +++ b/test/external/tslint-test-custom-rules/rules/ruleOneRule.js @@ -3,7 +3,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var Lint = require("tslint/lib/lint"); +var Lint = require("tslint"); var Rule = (function (_super) { __extends(Rule, _super); function Rule() { diff --git a/test/external/tslint-test-custom-rules/rules/ruleThreeRule.js b/test/external/tslint-test-custom-rules/rules/ruleThreeRule.js index 1d2ff62d1af..9b8b16e0fb8 100644 --- a/test/external/tslint-test-custom-rules/rules/ruleThreeRule.js +++ b/test/external/tslint-test-custom-rules/rules/ruleThreeRule.js @@ -3,7 +3,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var Lint = require("tslint/lib/lint"); +var Lint = require("tslint"); var Rule = (function (_super) { __extends(Rule, _super); function Rule() { diff --git a/test/external/tslint-test-custom-rules/rules/ruleTwoRule.js b/test/external/tslint-test-custom-rules/rules/ruleTwoRule.js index 1d2ff62d1af..9b8b16e0fb8 100644 --- a/test/external/tslint-test-custom-rules/rules/ruleTwoRule.js +++ b/test/external/tslint-test-custom-rules/rules/ruleTwoRule.js @@ -3,7 +3,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var Lint = require("tslint/lib/lint"); +var Lint = require("tslint"); var Rule = (function (_super) { __extends(Rule, _super); function Rule() { diff --git a/test/files/custom-rules-2/noFailRule.js b/test/files/custom-rules-2/noFailRule.js index 1d2ff62d1af..9b8b16e0fb8 100644 --- a/test/files/custom-rules-2/noFailRule.js +++ b/test/files/custom-rules-2/noFailRule.js @@ -3,7 +3,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var Lint = require("tslint/lib/lint"); +var Lint = require("tslint"); var Rule = (function (_super) { __extends(Rule, _super); function Rule() { diff --git a/test/files/custom-rules/alwaysFailRule.js b/test/files/custom-rules/alwaysFailRule.js index ee3abbe634d..b6d3d25921c 100644 --- a/test/files/custom-rules/alwaysFailRule.js +++ b/test/files/custom-rules/alwaysFailRule.js @@ -3,7 +3,7 @@ var __extends = (this && this.__extends) || function (d, b) { function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; -var Lint = require("tslint/lib/lint"); +var Lint = require("tslint"); var Rule = (function (_super) { __extends(Rule, _super); function Rule() { diff --git a/test/ruleLoaderTests.ts b/test/ruleLoaderTests.ts index daa8b1f6422..f9bb790b35e 100644 --- a/test/ruleLoaderTests.ts +++ b/test/ruleLoaderTests.ts @@ -23,10 +23,10 @@ describe("Rule Loader", () => { it("loads core rules", () => { const validConfiguration: {[name: string]: any} = { "class-name": true, - eofline: true, - forin: false, + "eofline": true, + "forin": false, "no-debugger": true, - quotemark: "single", + "quotemark": "single", }; const rules = loadRules(validConfiguration, {}, RULES_DIRECTORY); @@ -48,8 +48,8 @@ describe("Rule Loader", () => { it("doesn't ignore leading or trailing underscores or dashes", () => { /* tslint:disable:object-literal-sort-keys */ const invalidConfiguration: {[name: string]: any} = { - _indent: 6, - forin_: true, + "_indent": 6, + "forin_": true, "-quotemark": "single", "eofline-": true, }; @@ -64,10 +64,10 @@ describe("Rule Loader", () => { it("works with rulesDirectory argument as an Array", () => { const validConfiguration: {[name: string]: any} = { "class-name": true, - eofline: true, - forin: false, + "eofline": true, + "forin": false, "no-debugger": true, - quotemark: "single", + "quotemark": "single", }; const rules = loadRules(validConfiguration, {}, [RULES_DIRECTORY]); @@ -90,7 +90,7 @@ describe("Rule Loader", () => { assert.throws( () => loadRules(invalidConfiguration, {}, RULES_DIRECTORY, true), - /array-type/ + /array-type/, ); }); }); diff --git a/test/rules/no-unused-variable/default/false-positives.ts.lint b/test/rules/no-unused-variable/default/false-positives.ts.lint index 30cd304ee5b..bfd2b0ac19d 100644 --- a/test/rules/no-unused-variable/default/false-positives.ts.lint +++ b/test/rules/no-unused-variable/default/false-positives.ts.lint @@ -40,3 +40,13 @@ interface MyDateTimeOpts extends DateTimeOpts { let opts: MyDateTimeOpts; console.log(opts.timezoneOffset - 1); + +import * as myLib from 'myLib'; +export { myLib }; + +import foo from 'foo'; +const bar = {foo}; +myFunc(bar); + +import a from "module"; +export { a }; diff --git a/test/rules/no-unused-variable/default/import.ts.fix b/test/rules/no-unused-variable/default/import.ts.fix index c8de8aeeee8..081f3e24ca0 100644 --- a/test/rules/no-unused-variable/default/import.ts.fix +++ b/test/rules/no-unused-variable/default/import.ts.fix @@ -37,3 +37,7 @@ baz(); namedExport(); import "jquery"; + +import abc = require('abc'); +import def = abc.someVar; +console.log(def); diff --git a/test/rules/no-unused-variable/default/import.ts.lint b/test/rules/no-unused-variable/default/import.ts.lint index a0f019f289b..539dde7c3e1 100644 --- a/test/rules/no-unused-variable/default/import.ts.lint +++ b/test/rules/no-unused-variable/default/import.ts.lint @@ -58,3 +58,7 @@ baz(); namedExport(); import "jquery"; + +import abc = require('abc'); +import def = abc.someVar; +console.log(def); diff --git a/test/rules/semicolon/always/test.ts.fix b/test/rules/semicolon/always/test.ts.fix index b4e5a93118d..049d84d358f 100644 --- a/test/rules/semicolon/always/test.ts.fix +++ b/test/rules/semicolon/always/test.ts.fix @@ -68,6 +68,8 @@ interface ITest { foo?: string; bar: number; baz: boolean; + + readonly raz: number; } import {Router} from 'aurelia-router'; diff --git a/test/rules/semicolon/always/test.ts.lint b/test/rules/semicolon/always/test.ts.lint index ff46b4c6637..e99a82a7461 100644 --- a/test/rules/semicolon/always/test.ts.lint +++ b/test/rules/semicolon/always/test.ts.lint @@ -92,6 +92,8 @@ interface ITest { bar: number ~nil [Missing semicolon] baz: boolean; + + readonly raz: number; } import {Router} from 'aurelia-router'; diff --git a/tslint.json b/tslint.json index f0eae7a1393..c496ae41946 100644 --- a/tslint.json +++ b/tslint.json @@ -2,6 +2,7 @@ "extends": "tslint:latest", "rules": { "interface-name": false, + "max-classes-per-file": false, "max-line-length": [true, 140], "member-ordering": [true, "public-before-private", From be864a190f9dd3e46a3f7f32e6e3bf6d34d8ec5f Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 18 Nov 2016 22:57:19 -0500 Subject: [PATCH 091/111] Allow null keyword in a type position (originally #1277) (#1745) --- src/linter.ts | 2 +- src/rules/noNullKeywordRule.ts | 12 +++++++++++- test/rules/no-null-keyword/test.ts.lint | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/linter.ts b/src/linter.ts index 39c192e1627..7132b293b0c 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -41,7 +41,7 @@ import { arrayify, dedent } from "./utils"; * Linter that can lint multiple files in consecutive runs. */ class Linter { - public static VERSION = "4.0.0-dev.2"; + public static VERSION = "4.0.0"; public static findConfiguration = findConfiguration; public static findConfigurationPath = findConfigurationPath; diff --git a/src/rules/noNullKeywordRule.ts b/src/rules/noNullKeywordRule.ts index 40e2e1af9f6..6592c1640d1 100644 --- a/src/rules/noNullKeywordRule.ts +++ b/src/rules/noNullKeywordRule.ts @@ -47,8 +47,18 @@ export class Rule extends Lint.Rules.AbstractRule { class NullWalker extends Lint.RuleWalker { public visitNode(node: ts.Node) { super.visitNode(node); - if (node.kind === ts.SyntaxKind.NullKeyword) { + if (node.kind === ts.SyntaxKind.NullKeyword && !isPartOfType(node)) { this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING)); } } } + +function isPartOfType({ parent }: ts.Node) { + while (parent != null) { + if (ts.SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= ts.SyntaxKind.LastTypeNode) { + return true; + } + parent = parent.parent; + } + return false; +} diff --git a/test/rules/no-null-keyword/test.ts.lint b/test/rules/no-null-keyword/test.ts.lint index 1cab307c4a1..5eb317ac348 100644 --- a/test/rules/no-null-keyword/test.ts.lint +++ b/test/rules/no-null-keyword/test.ts.lint @@ -2,3 +2,8 @@ var x = null; // error ~~~~ [Use 'undefined' instead of 'null'] console.log(null, x); // error ~~~~ [Use 'undefined' instead of 'null'] + +let match(): string | null; +interface foo { + bar: [number, null, string]; +} From fbe5fd47906336b1a104db7c023357492fea9142 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 18 Nov 2016 22:58:49 -0500 Subject: [PATCH 092/111] Fix TS 2.0 one-line rule bug (originally #1429) (#1746) --- src/rules/oneLineRule.ts | 2 +- test/rules/one-line/all/test.ts.lint | 3 +++ test/rules/one-line/none/test.ts.lint | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rules/oneLineRule.ts b/src/rules/oneLineRule.ts index 561c31d78c7..bad0235d9d4 100644 --- a/src/rules/oneLineRule.ts +++ b/src/rules/oneLineRule.ts @@ -196,7 +196,7 @@ class OneLineWalker extends Lint.RuleWalker { public visitModuleDeclaration(node: ts.ModuleDeclaration) { const nameNode = node.name; const body = node.body; - if (body.kind === ts.SyntaxKind.ModuleBlock) { + if (body != null && body.kind === ts.SyntaxKind.ModuleBlock) { const openBraceToken = body.getChildAt(0); this.handleOpeningBrace(nameNode, openBraceToken); } diff --git a/test/rules/one-line/all/test.ts.lint b/test/rules/one-line/all/test.ts.lint index 769f784e529..f33ea57e051 100644 --- a/test/rules/one-line/all/test.ts.lint +++ b/test/rules/one-line/all/test.ts.lint @@ -140,3 +140,6 @@ let geoConfig: { timeout: 5000, enableHighAccuracy: false }; + +declare module "*"; +declare module "someLibrary/*"; diff --git a/test/rules/one-line/none/test.ts.lint b/test/rules/one-line/none/test.ts.lint index 751e45661ff..a6a5ddca080 100644 --- a/test/rules/one-line/none/test.ts.lint +++ b/test/rules/one-line/none/test.ts.lint @@ -119,3 +119,6 @@ let geoConfig: { timeout: 5000, enableHighAccuracy: false }; + +declare module "*"; +declare module "someLibrary/*"; From 273f160ec0b18086be36a51ea21d566c47357985 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Fri, 18 Nov 2016 23:13:31 -0500 Subject: [PATCH 093/111] Clarify `no-unused-variable` deprecation message with "tsc" --- src/rules/noUnusedVariableRule.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rules/noUnusedVariableRule.ts b/src/rules/noUnusedVariableRule.ts index 3e1dcb54485..70c1703d0f3 100644 --- a/src/rules/noUnusedVariableRule.ts +++ b/src/rules/noUnusedVariableRule.ts @@ -31,7 +31,7 @@ export class Rule extends Lint.Rules.AbstractRule { /* tslint:disable:object-literal-sort-keys */ public static metadata: Lint.IRuleMetadata = { ruleName: "no-unused-variable", - deprecationMessage: "Use the compiler options --noUnusedParameters and --noUnusedLocals instead.", + deprecationMessage: "Use the tsc compiler options --noUnusedParameters and --noUnusedLocals instead.", description: "Disallows unused imports, variables, functions and private class members.", optionsDescription: Lint.Utils.dedent` Three optional arguments may be optionally provided: From c76559eebbec2b9ceb8471b04d17e4a6b1293644 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Sat, 19 Nov 2016 01:38:20 -0500 Subject: [PATCH 094/111] Clarify blog post text --- docs/_posts/2016-11-17-new-for-4.0.md | 5 ++++- 1 file changed, 4 insertions(+), 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 29a1ca08595..b92a1284ecd 100644 --- a/docs/_posts/2016-11-17-new-for-4.0.md +++ b/docs/_posts/2016-11-17-new-for-4.0.md @@ -15,13 +15,15 @@ TSLint 4.0 has been released! With this release comes a few exciting [changes][0 * [semicolon][7] * [trailing-comma][8] + * **Linting `.js` files**. *A much-requested feature from our community*. Simplify your toolset by running the same rules you know and love on your .js and .jsx files. Just add a `jsRules` [section][9] to your `tslint.json` file, and TSLint will your JavaScript files. -* **TypeScript 2.0+ required**. This lets us deprecate/remove rules that are checked by the compiler. These rules now cause compilation errors: +* **TypeScript 2.0+ required**. This lets us deprecate/remove rules that are checked by the compiler. Problematic code that once violated these rules now cause compilation errors in `tsc`: * 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]** @@ -36,6 +38,7 @@ TSLint 4.0 has been released! With this release comes a few exciting [changes][0 * [ordered-imports][21] * [prefer-for-of][22] + * **Other rules you might find handy**: * [completed-docs][23] * [cyclomatic-complexity][24] From 5128ef5997727c8ccd1176a23313309ba97857d9 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Sun, 20 Nov 2016 01:06:32 +0100 Subject: [PATCH 095/111] Fix description of maxClassesPerFileRule (#1750) --- src/rules/maxClassesPerFileRule.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rules/maxClassesPerFileRule.ts b/src/rules/maxClassesPerFileRule.ts index 5bb613adaa4..04b4a933ccc 100644 --- a/src/rules/maxClassesPerFileRule.ts +++ b/src/rules/maxClassesPerFileRule.ts @@ -7,8 +7,7 @@ export class Rule extends Lint.Rules.AbstractRule { public static metadata: Lint.IRuleMetadata = { ruleName: "max-classes-per-file", description: Lint.Utils.dedent` - A file may not contain more than the specified number of classes - if the file name does not match the "ignore-filename-pattern" option`, + A file may not contain more than the specified number of classes`, rationale: Lint.Utils.dedent` Ensures that files have a single responsibility so that that classes each exist in their own files`, optionsDescription: Lint.Utils.dedent` From 3b5e8939fe64a721b9e1a3081b62f8cba33537bc Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sat, 19 Nov 2016 19:19:18 -0500 Subject: [PATCH 096/111] Remove no-unused-variable from recommended config (#1754) Fixes #1748 --- src/configs/recommended.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/configs/recommended.ts b/src/configs/recommended.ts index 77acc19835a..a1f4dac224b 100644 --- a/src/configs/recommended.ts +++ b/src/configs/recommended.ts @@ -71,8 +71,6 @@ export const rules = { "no-unsafe-finally": true, "no-unused-expression": true, "no-unused-new": true, - // deprecated as of v4.0 - "no-unused-variable": false, // disable this rule as it is very heavy performance-wise and not that useful "no-use-before-declare": false, "no-var-keyword": true, From ac05171f547a1b0711df7ff7301fd9bd5f5a7265 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Sat, 19 Nov 2016 19:23:13 -0500 Subject: [PATCH 097/111] Prepare release v4.0.1 (#1755) --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/linter.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21ff0dce1f6..ce21cbf741b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Change Log === +v4.0.1 +--- +* [bugfix] Removed `no-unused-variable` rule from recommended config, as it was causing spurious deprecation warnings. + v4.0.0-dev.2 --- * Include latest v4.0.0 changes diff --git a/package.json b/package.json index ede2e56f300..40ad22d92a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tslint", - "version": "4.0.0", + "version": "4.0.1", "description": "An extensible static analysis linter for the TypeScript language", "bin": { "tslint": "./bin/tslint" diff --git a/src/linter.ts b/src/linter.ts index 7132b293b0c..928ab96443d 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -41,7 +41,7 @@ import { arrayify, dedent } from "./utils"; * Linter that can lint multiple files in consecutive runs. */ class Linter { - public static VERSION = "4.0.0"; + public static VERSION = "4.0.1"; public static findConfiguration = findConfiguration; public static findConfigurationPath = findConfigurationPath; From 84eeb10352350b0f12aa52416b541af120109d13 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 21 Nov 2016 12:58:52 -0500 Subject: [PATCH 098/111] Fix README code samples to match module APIs --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d89e42499ee..5ee5d18a85a 100644 --- a/README.md +++ b/README.md @@ -213,9 +213,9 @@ tslint accepts the following command-line options: #### Library -```javascript -const Linter = require("tslint"); -const fs = require("fs"); +```js +import { Linter } from "tslint"; +import * as fs from "fs"; const fileName = "Specify file name"; const configuration = { @@ -240,7 +240,7 @@ const result = linter.lint(); To enable rules that work with the type checker, a TypeScript program object must be passed to the linter when using the programmatic API. Helper functions are provided to create a program from a `tsconfig.json` file. A project directory can be specified if project files do not lie in the same directory as the `tsconfig.json` file. -```javascript +```js const program = Linter.createProgram("tsconfig.json", "projectDir/"); const files = Linter.getFileNames(program); const results = files.map(file => { @@ -321,20 +321,20 @@ __Important conventions__: Now, let us first write the rule in TypeScript: -```typescript +```ts import * as ts from "typescript"; -import * as Lint from "tslint"; +import { Rules, RuleFailure, RuleWalker } from "tslint"; -export class Rule extends Lint.Rules.AbstractRule { +export class Rule extends Rules.AbstractRule { public static FAILURE_STRING = "import statement forbidden"; - public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { + public apply(sourceFile: ts.SourceFile): RuleFailure[] { return this.applyWithWalker(new NoImportsWalker(sourceFile, this.getOptions())); } } // The walker takes care of all the work. -class NoImportsWalker extends Lint.RuleWalker { +class NoImportsWalker extends RuleWalker { public visitImportDeclaration(node: ts.ImportDeclaration) { // create a failure at the current position this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING)); @@ -370,11 +370,11 @@ Just like rules, additional formatters can also be supplied to TSLint via `--for ```typescript import * as ts from "typescript"; -import * as Lint from "tslint"; +import { Formatters, RuleFailure } from "tslint"; -export class Formatter extends Lint.Formatters.AbstractFormatter { - public format(failures: Lint.RuleFailure[]): string { - var failuresJSON = failures.map((failure: Lint.RuleFailure) => failure.toJson()); +export class Formatter extends Formatters.AbstractFormatter { + public format(failures: RuleFailure[]): string { + var failuresJSON = failures.map((failure: RuleFailure) => failure.toJson()); return JSON.stringify(failuresJSON); } } From 9a7d7195c7a670e15a70947288d7ae9cd0032659 Mon Sep 17 00:00:00 2001 From: gustavderdrache Date: Mon, 21 Nov 2016 14:26:37 -0500 Subject: [PATCH 099/111] Don't flag "" as a JS property name. (#1762) --- src/rules/objectLiteralKeyQuotesRule.ts | 2 +- test/rules/object-literal-key-quotes/as-needed/test.js.lint | 1 + test/rules/object-literal-key-quotes/as-needed/test.ts.lint | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rules/objectLiteralKeyQuotesRule.ts b/src/rules/objectLiteralKeyQuotesRule.ts index 46ba55f8caa..413581f298b 100644 --- a/src/rules/objectLiteralKeyQuotesRule.ts +++ b/src/rules/objectLiteralKeyQuotesRule.ts @@ -77,7 +77,7 @@ export class Rule extends Lint.Rules.AbstractRule { } // This is simplistic. See https://mothereff.in/js-properties for the gorey details. -const IDENTIFIER_NAME_REGEX = /^(?:[\$A-Z_a-z])*$/; +const IDENTIFIER_NAME_REGEX = /^(?:[\$A-Z_a-z])+$/; const NUMBER_REGEX = /^[0-9]+$/; type QuotesMode = "always" | "as-needed" | "consistent" | "consistent-as-needed"; diff --git a/test/rules/object-literal-key-quotes/as-needed/test.js.lint b/test/rules/object-literal-key-quotes/as-needed/test.js.lint index e6dc627b5d0..86c24145018 100644 --- a/test/rules/object-literal-key-quotes/as-needed/test.js.lint +++ b/test/rules/object-literal-key-quotes/as-needed/test.js.lint @@ -19,4 +19,5 @@ const o = { "0x0": 0, "true": 0, // failure ~~~~~~ [Unnecessarily quoted property 'true' found.] + '': 'always quote the empty string', }; diff --git a/test/rules/object-literal-key-quotes/as-needed/test.ts.lint b/test/rules/object-literal-key-quotes/as-needed/test.ts.lint index e6dc627b5d0..86c24145018 100644 --- a/test/rules/object-literal-key-quotes/as-needed/test.ts.lint +++ b/test/rules/object-literal-key-quotes/as-needed/test.ts.lint @@ -19,4 +19,5 @@ const o = { "0x0": 0, "true": 0, // failure ~~~~~~ [Unnecessarily quoted property 'true' found.] + '': 'always quote the empty string', }; From 169fc1b2b0f305c7023e211fb266e02d63abc4ab Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Mon, 21 Nov 2016 14:54:05 -0500 Subject: [PATCH 100/111] Extend timeout for executableTests (#1766) --- docs/_data/rules.json | 2 +- docs/rules/max-classes-per-file/index.html | 3 +-- test/executable/executableTests.ts | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/_data/rules.json b/docs/_data/rules.json index 249191ad953..29873e94fe6 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -296,7 +296,7 @@ }, { "ruleName": "max-classes-per-file", - "description": "\nA file may not contain more than the specified number of classes \nif the file name does not match the \"ignore-filename-pattern\" option", + "description": "\nA file may not contain more than the specified number of classes", "rationale": "\nEnsures that files have a single responsibility so that that classes each exist in their own files", "optionsDescription": "\nThe one required argument is an integer indicating the maximum number of classes that can appear in a file.", "options": { diff --git a/docs/rules/max-classes-per-file/index.html b/docs/rules/max-classes-per-file/index.html index 1827aab9dc8..985d4d6824a 100644 --- a/docs/rules/max-classes-per-file/index.html +++ b/docs/rules/max-classes-per-file/index.html @@ -2,8 +2,7 @@ ruleName: max-classes-per-file description: |- - A file may not contain more than the specified number of classes - if the file name does not match the "ignore-filename-pattern" option + A file may not contain more than the specified number of classes rationale: |- Ensures that files have a single responsibility so that that classes each exist in their own files diff --git a/test/executable/executableTests.ts b/test/executable/executableTests.ts index 60a2f7262b1..2b9288c827b 100644 --- a/test/executable/executableTests.ts +++ b/test/executable/executableTests.ts @@ -28,6 +28,8 @@ const TEMP_JSON_PATH = path.resolve(EXECUTABLE_DIR, "tslint.json"); /* tslint:disable:only-arrow-functions */ describe("Executable", function() { this.slow(3000); // the executable is JIT-ed each time it runs; avoid showing slowness warnings + this.timeout(4000); + describe("Files", () => { it("exits with code 1 if no arguments passed", (done) => { execCli([], (err, stdout, stderr) => { From 33ea88c21fff3ef547f2c45d23de8bec9fd93de3 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Mon, 21 Nov 2016 15:43:34 -0500 Subject: [PATCH 101/111] Was not reporting correct # of fixes (#1767) --- src/linter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/linter.ts b/src/linter.ts index 928ab96443d..3a0837d0e46 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -102,7 +102,6 @@ class Linter { let fileFailures: RuleFailure[] = []; if (this.options.fix) { - this.fixes = []; for (let rule of enabledRules) { let ruleFailures = this.applyRule(rule, sourceFile); const fixes = ruleFailures.map((f) => f.getFix()).filter((f) => !!f); From 69a32e6600d471eeaa2992ef4e0e978cfa83f2c9 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Mon, 21 Nov 2016 16:02:23 -0500 Subject: [PATCH 102/111] Fatal errors from API should be unhandled and caught in tslint-cli (#1764) --- docs/_data/rules.json | 2 +- docs/rules/no-unused-variable/index.html | 2 +- src/configuration.ts | 15 ++------- src/error.ts | 40 ++++++++++++++++++++++++ src/test/lintError.ts | 2 +- src/tslint-cli.ts | 20 +++++++----- 6 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 src/error.ts diff --git a/docs/_data/rules.json b/docs/_data/rules.json index 29873e94fe6..61d5c2d6c0b 100644 --- a/docs/_data/rules.json +++ b/docs/_data/rules.json @@ -850,7 +850,7 @@ }, { "ruleName": "no-unused-variable", - "deprecationMessage": "Use the compiler options --noUnusedParameters and --noUnusedLocals instead.", + "deprecationMessage": "Use the tsc compiler options --noUnusedParameters and --noUnusedLocals instead.", "description": "Disallows unused imports, variables, functions and private class members.", "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.", "options": { diff --git a/docs/rules/no-unused-variable/index.html b/docs/rules/no-unused-variable/index.html index 3487ff0e49d..abb1bd4e72a 100644 --- a/docs/rules/no-unused-variable/index.html +++ b/docs/rules/no-unused-variable/index.html @@ -1,6 +1,6 @@ --- ruleName: no-unused-variable -deprecationMessage: Use the compiler options --noUnusedParameters and --noUnusedLocals instead. +deprecationMessage: Use the tsc compiler options --noUnusedParameters and --noUnusedLocals instead. description: 'Disallows unused imports, variables, functions and private class members.' optionsDescription: |- diff --git a/src/configuration.ts b/src/configuration.ts index e295aeada39..1f699b587f4 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -19,6 +19,7 @@ import findup = require("findup-sync"); import * as fs from "fs"; import * as path from "path"; import * as resolve from "resolve"; +import { FatalError } from "./error"; import {arrayify, objectify, stripComments} from "./utils"; @@ -32,16 +33,7 @@ export interface IConfigurationFile { rules?: any; } -/** - * Define `Error` here to avoid using `Error` from @types/node. - * Using the `node` version causes a compilation error when this code is used as an npm library if @types/node is not already imported. - */ -export interface Error { - message: string; -} - export interface IConfigurationLoadResult { - error?: Error; path: string; results?: IConfigurationFile; } @@ -119,11 +111,10 @@ export function findConfiguration(configFile: string, inputFilePath: string): IC try { loadResult.results = loadConfigurationFromPath(path); + return loadResult; } catch (error) { - loadResult.error = error; + throw new FatalError(`Failed to load ${path}: ${error.message}`, error); } - - return loadResult; } /** diff --git a/src/error.ts b/src/error.ts new file mode 100644 index 00000000000..f18aacd485c --- /dev/null +++ b/src/error.ts @@ -0,0 +1,40 @@ +/** + * @license + * Copyright 2016 Palantir Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Generic error typing for EcmaScript errors + * Define `Error` here to avoid using `Error` from @types/node. + * Using the `node` version causes a compilation error when this code is used as an npm library if @types/node is not already imported. + */ +export declare class Error { + public name?: string; + public message: string; + public stack?: string; + constructor(message?: string); +} + +/** + * Used to exit the program and display a friendly message without the callstack. + */ +export class FatalError extends Error { + public static NAME = "FatalError"; + constructor(public message: string, public innerError?: Error) { + super(message); + this.name = FatalError.NAME; + this.stack = new Error().stack; + } +} diff --git a/src/test/lintError.ts b/src/test/lintError.ts index 46968be2599..5f90a4b3a81 100644 --- a/src/test/lintError.ts +++ b/src/test/lintError.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Error } from "../configuration"; +import { Error } from "../error"; export interface PositionInFile { line: number; diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index 7018a2e76fe..dc722d1f9e0 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -26,6 +26,7 @@ import { DEFAULT_CONFIG, findConfiguration, } from "./configuration"; +import { FatalError } from "./error"; import * as Linter from "./linter"; import { consoleTestResultHandler, runTest } from "./test"; import { updateNotifierCheck } from "./updateNotifier"; @@ -259,13 +260,7 @@ const processFiles = (files: string[], program?: ts.Program) => { const contents = fs.readFileSync(file, "utf8"); const configLoad = findConfiguration(possibleConfigAbsolutePath, file); - - if (configLoad.results) { - linter.lint(file, contents, configLoad.results); - } else { - console.error(`Failed to load ${configLoad.path}: ${configLoad.error.message}`); - process.exit(1); - } + linter.lint(file, contents, configLoad.results); } const lintResult = linter.getResult(); @@ -332,4 +327,13 @@ files = files .map((file: string) => glob.sync(file, { ignore: ignorePatterns, nodir: true })) .reduce((a: string[], b: string[]) => a.concat(b)); -processFiles(files, program); +try { + processFiles(files, program); +} catch (error) { + if (error.name === FatalError.NAME) { + console.error(error.message); + process.exit(1); + } + // rethrow unhandled error + throw error; +} From 51e399084e9f8cf9bca97f91404a7d342178fc63 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Mon, 21 Nov 2016 19:17:54 -0500 Subject: [PATCH 103/111] Update doc - bullet points not formatted correctly --- docs/develop/custom-rules/index.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/develop/custom-rules/index.md b/docs/develop/custom-rules/index.md index 8cc3cded4f7..36806f85425 100644 --- a/docs/develop/custom-rules/index.md +++ b/docs/develop/custom-rules/index.md @@ -8,10 +8,10 @@ TSLint ships with a set of core rules that can be configured. However, users are Let us take the example of how to write a new rule to forbid all import statements (you know, *for science*). Let us name the rule file `noImportsRule.ts`. Rules are referenced in `tslint.json` with their kebab-cased identifer, so `"no-imports": true` would configure the rule. __Important conventions__: -* Rule identifiers are always kebab-cased. -* Rule files are always camel-cased (`camelCasedRule.ts`). -* Rule files *must* contain the suffix `Rule`. -* The exported class must always be named `Rule` and extend from `Lint.Rules.AbstractRule`. +- Rule identifiers are always kebab-cased. +- Rule files are always camel-cased (`camelCasedRule.ts`). +- Rule files *must* contain the suffix `Rule`. +- The exported class must always be named `Rule` and extend from `Lint.Rules.AbstractRule`. Now, let us first write the rule in TypeScript: From 539075224e2d4de48242511f29dbd808bed83984 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 22 Nov 2016 00:52:13 -0500 Subject: [PATCH 104/111] Update README features list to include auto fixing --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ee5d18a85a..35fc869fee5 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ TSLint supports: - custom formatters (failure reporters) - inline disabling / enabling of rules - configuration presets (`tslint:latest`, `tslint-react`, etc.) & composition +- automatic fixing of formatting & style violations - integration with [msbuild](https://github.com/joshuakgoldberg/tslint.msbuild), [grunt](https://github.com/palantir/grunt-tslint), [gulp](https://github.com/panuhorsmalahti/gulp-tslint), [atom](https://github.com/AtomLinter/linter-tslint), [eclipse](https://github.com/palantir/eclipse-tslint), [emacs](http://flycheck.org), [sublime](https://packagecontrol.io/packages/SublimeLinter-contrib-tslint), [vim](https://github.com/scrooloose/syntastic), [visual studio](https://visualstudiogallery.msdn.microsoft.com/6edc26d4-47d8-4987-82ee-7c820d79be1d), [vscode](https://marketplace.visualstudio.com/items?itemName=eg2.tslint), [webstorm](https://www.jetbrains.com/webstorm/help/tslint.html), and more Table of Contents @@ -115,7 +116,7 @@ Options: ``` -c, --config configuration file -e, --exclude exclude globs from path expansion ---fix Fixes linting errors for select rules. This may overwrite linted files +--fix fixes linting errors for select rules (his may overwrite linted files) --force return status code 0 even if there are lint errors -h, --help display detailed help -i, --init generate a tslint.json config file in the current working directory From 1c0f16fc7f286ad6b84e5189262f16d3bf126f1e Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Tue, 22 Nov 2016 14:58:34 -0500 Subject: [PATCH 105/111] 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 b92a1284ecd..2bbf2404c95 100644 --- a/docs/_posts/2016-11-17-new-for-4.0.md +++ b/docs/_posts/2016-11-17-new-for-4.0.md @@ -16,7 +16,7 @@ TSLint 4.0 has been released! With this release comes a few exciting [changes][0 * [trailing-comma][8] -* **Linting `.js` files**. *A much-requested feature from our community*. Simplify your toolset by running the same rules you know and love on your .js and .jsx files. Just add a `jsRules` [section][9] to your `tslint.json` file, and TSLint will your JavaScript files. +* **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 lint your JavaScript files. * **TypeScript 2.0+ required**. This lets us deprecate/remove rules that are checked by the compiler. Problematic code that once violated these rules now cause compilation errors in `tsc`: * no-duplicate-key From d29f4840436dd1a499d0a112a344d42b104cc487 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Tue, 22 Nov 2016 16:17:35 -0500 Subject: [PATCH 106/111] Rewrite `prefer-for-of` rule (#1758) --- src/rules/preferForOfRule.ts | 197 +++++++++++++++++--------- test/rules/prefer-for-of/test.ts.lint | 120 +++++++++------- 2 files changed, 201 insertions(+), 116 deletions(-) diff --git a/src/rules/preferForOfRule.ts b/src/rules/preferForOfRule.ts index 51edb4eca1f..7142a298ded 100644 --- a/src/rules/preferForOfRule.ts +++ b/src/rules/preferForOfRule.ts @@ -35,89 +35,158 @@ export class Rule extends Lint.Rules.AbstractRule { public static FAILURE_STRING = "Expected a 'for-of' loop instead of a 'for' loop with this simple iteration"; public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { - const languageService = Lint.createLanguageService(sourceFile.fileName, sourceFile.getFullText()); - return this.applyWithWalker(new PreferForOfWalker(sourceFile, this.getOptions(), languageService)); + return this.applyWithWalker(new PreferForOfWalker(sourceFile, this.getOptions())); } } +interface IIncrementorState { + arrayToken: ts.LeftHandSideExpression; + endIncrementPos: number; + onlyArrayAccess: boolean; +} + class PreferForOfWalker extends Lint.RuleWalker { - constructor(sourceFile: ts.SourceFile, options: Lint.IOptions, private languageService: ts.LanguageService) { + // a map of incrementors and whether or not they are only used to index into an array reference in the for loop + private incrementorMap: { [name: string]: IIncrementorState }; + + constructor(sourceFile: ts.SourceFile, options: Lint.IOptions) { super(sourceFile, options); + this.incrementorMap = {}; } public visitForStatement(node: ts.ForStatement) { - const arrayAccessNode = this.locateArrayNodeInForLoop(node); - - if (arrayAccessNode !== undefined) { - // Skip arrays thats just loop over a hard coded number - // If we are accessing the length of the array, then we are likely looping over it's values - if (arrayAccessNode.kind === ts.SyntaxKind.PropertyAccessExpression && arrayAccessNode.getLastToken().getText() === "length") { - let incrementorVariable = node.incrementor.getFirstToken(); - if (/\+|-/g.test(incrementorVariable.getText())) { - // If it's formatted as `++i` instead, we need to get the OTHER token - incrementorVariable = node.incrementor.getLastToken(); - } - const arrayToken = arrayAccessNode.getChildAt(0); - const loopSyntaxText = node.statement.getText(); - // Find all usages of the incrementor variable - const fileName = this.getSourceFile().fileName; - const highlights = this.languageService.getDocumentHighlights(fileName, incrementorVariable.getStart(), [fileName]); - - if (highlights && highlights.length > 0) { - // There are *usually* three usages when setting up the for loop, - // so remove those from the count to get the count inside the loop block - const incrementorCount = highlights[0].highlightSpans.length - 3; - - // Find `array[i]`-like usages by building up a regex - const arrayTokenForRegex = arrayToken.getText().replace(".", "\\."); - const incrementorForRegex = incrementorVariable.getText().replace(".", "\\."); - const regex = new RegExp(`${arrayTokenForRegex}\\[\\s*${incrementorForRegex}\\s*\\]`, "g"); - const accessMatches = loopSyntaxText.match(regex); - const matchCount = (accessMatches || []).length; - - // If there are more usages of the array item being access than the incrementor variable - // being used, then this loop could be replaced with a for-of loop instead. - // This means that the incrementor variable is not used on its own anywhere and is ONLY - // used to access the array item. - if (matchCount >= incrementorCount) { - const failure = this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING); - this.addFailure(failure); + const arrayNodeInfo = this.getForLoopHeaderInfo(node); + let indexVariableName: string; + if (arrayNodeInfo != null) { + const { indexVariable, arrayToken } = arrayNodeInfo; + indexVariableName = indexVariable.getText(); + + // store `for` loop state + this.incrementorMap[indexVariableName] = { + arrayToken, + endIncrementPos: node.incrementor.end, + onlyArrayAccess: true, + }; + } + + super.visitForStatement(node); + + if (indexVariableName != null) { + const incrementorState = this.incrementorMap[indexVariableName]; + if (incrementorState.onlyArrayAccess) { + const length = incrementorState.endIncrementPos - node.getStart() + 1; + const failure = this.createFailure(node.getStart(), length, Rule.FAILURE_STRING); + this.addFailure(failure); + } + + // remove current `for` loop state + delete this.incrementorMap[indexVariableName]; + } + } + + public visitIdentifier(node: ts.Identifier) { + const incrementorState = this.incrementorMap[node.text]; + + // check if the identifier is an iterator and is currently in the `for` loop body + if (incrementorState != null && incrementorState.arrayToken != null && incrementorState.endIncrementPos < node.getStart()) { + // mark `onlyArrayAccess` false if iterator is used on anything except the array in the `for` loop header + if (node.parent.kind !== ts.SyntaxKind.ElementAccessExpression + || incrementorState.arrayToken.getText() !== ( node.parent).expression.getText()) { + + incrementorState.onlyArrayAccess = false; + } + } + super.visitIdentifier(node); + } + + // returns the iterator and array of a `for` loop if the `for` loop is basic. Otherwise, `null` + private getForLoopHeaderInfo(forLoop: ts.ForStatement) { + let indexVariableName: string; + let indexVariable: ts.Identifier; + + // assign `indexVariableName` if initializer is simple and starts at 0 + if (forLoop.initializer != null && forLoop.initializer.kind === ts.SyntaxKind.VariableDeclarationList) { + const syntaxList = forLoop.initializer.getChildAt(1); + if (syntaxList.kind === ts.SyntaxKind.SyntaxList && syntaxList.getChildCount() === 1) { + const assignment = syntaxList.getChildAt(0); + if (assignment.kind === ts.SyntaxKind.VariableDeclaration) { + const value = assignment.getChildAt(2).getText(); + if (value === "0") { + indexVariable = assignment.getChildAt(0); + indexVariableName = indexVariable.getText(); } } } } - super.visitForStatement(node); + // ensure `for` condition + if (indexVariableName == null + || forLoop.condition == null + || forLoop.condition.kind !== ts.SyntaxKind.BinaryExpression + || forLoop.condition.getChildAt(0).getText() !== indexVariableName + || forLoop.condition.getChildAt(1).getText() !== "<") { + + return null; + } + + if (!this.isIncremented(forLoop.incrementor, indexVariableName)) { + return null; + } + + // ensure that the condition checks a `length` property + const conditionRight = forLoop.condition.getChildAt(2); + if (conditionRight.kind === ts.SyntaxKind.PropertyAccessExpression) { + const propertyAccess = conditionRight; + if (propertyAccess.name.getText() === "length") { + return { indexVariable, arrayToken: propertyAccess.expression }; + } + } + + return null; } - private locateArrayNodeInForLoop(forLoop: ts.ForStatement): ts.Node { - // Some oddly formatted (yet still valid!) `for` loops might not have children in the condition - // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for - if (forLoop.condition !== undefined) { - let arrayAccessNode = forLoop.condition.getChildAt(2); - // If We haven't found it, maybe it's not a standard for loop, try looking in the initializer for the array - // Something like `for(var t=0, len=arr.length; t < len; t++)` - if (arrayAccessNode.kind !== ts.SyntaxKind.PropertyAccessExpression && forLoop.initializer !== undefined) { - for (let initNode of forLoop.initializer.getChildren()) { - // look in `var t=0, len=arr.length;` - if (initNode.kind === ts.SyntaxKind.SyntaxList) { - for (let initVar of initNode.getChildren()) { - // look in `t=0, len=arr.length;` - if (initVar.kind === ts.SyntaxKind.VariableDeclaration) { - for (let initVarPart of initVar.getChildren()) { - // look in `len=arr.length` - if (initVarPart.kind === ts.SyntaxKind.PropertyAccessExpression) { - arrayAccessNode = initVarPart; - } - } - } - } + private isIncremented(node: ts.Node, indexVariableName: string) { + if (node == null) { + return false; + } + + // ensure variable is incremented + if (node.kind === ts.SyntaxKind.PrefixUnaryExpression) { + const incrementor = node; + if (incrementor.operator === ts.SyntaxKind.PlusPlusToken && incrementor.operand.getText() === indexVariableName) { + // x++ + return true; + } + } else if (node.kind === ts.SyntaxKind.PostfixUnaryExpression) { + const incrementor = node; + if (incrementor.operator === ts.SyntaxKind.PlusPlusToken && incrementor.operand.getText() === indexVariableName) { + // ++x + return true; + } + } else if (node.kind === ts.SyntaxKind.BinaryExpression) { + const binaryExpression = node; + if (binaryExpression.operatorToken.getText() === "+=" + && binaryExpression.left.getText() === indexVariableName + && binaryExpression.right.getText() === "1") { + // x += 1 + return true; + } + if (binaryExpression.operatorToken.getText() === "=" + && binaryExpression.left.getText() === indexVariableName) { + const addExpression = binaryExpression.right; + if (addExpression.operatorToken.getText() === "+") { + if (addExpression.right.getText() === indexVariableName && addExpression.left.getText() === "1") { + // x = 1 + x + return true; + } else if (addExpression.left.getText() === indexVariableName && addExpression.right.getText() === "1") { + // x = x + 1 + return true; } } } - return arrayAccessNode; } else { - return undefined; + return false; } + return false; } } diff --git a/test/rules/prefer-for-of/test.ts.lint b/test/rules/prefer-for-of/test.ts.lint index 0457f270347..ac67a99dacb 100644 --- a/test/rules/prefer-for-of/test.ts.lint +++ b/test/rules/prefer-for-of/test.ts.lint @@ -1,70 +1,46 @@ function sampleFunc() { - //This loop only uses the iterator to access the array item, so we can recommend a for-of loop here - for (var a = 0; a <= obj.arr.length; a++) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // This loop only uses the iterator to access the array item, so we can recommend a for-of loop here + for (var a = 0; a < obj.arr.length; a++) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] console.log(obj.arr[a]); -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } -~~~~~ [0] - //Same as above, but no curly braces - for (var b = 0; b <= obj.arr.length; b++) console.log(obj.arr[b]); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + // Same as above, but no curly braces + for (var b = 0; b < obj.arr.length; b++) console.log(obj.arr[b]); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] - //the index is used by itself, so a normal for loop is allowed here - for (var c = 0; c <= arr.length; c++) { + // the index is used by itself, so a normal for loop is allowed here + for (var c = 0; c < arr.length; c++) { doMath(c); } - //Same as above, but no curly braces - for (var d = 0; d <= arr.length; d++) doMath(d); + // Same as above, but no curly braces + for (var d = 0; d < arr.length; d++) doMath(d); - //the index is used by itself, so a normal for loop is allowed here - for (var e = 0; e <= arr.length; e++) { + // the index is used by itself, so a normal for loop is allowed here + for (var e = 0; e < arr.length; e++) { if(e > 5) { doMath(e); } console.log(arr[e]); } - //This iterates off of a hard-coded number and should be allowed + // This iterates off of a hard-coded number and should be allowed for (var f = 0; f <= 40; f++) { doMath(f); } - //Same as above, but no curly braces + // Same as above, but no curly braces for (var g = 0; g <= 40; g++) doMath(g); - //Loop set up different, but uses the index alone - this is ok - for(var h=0, len=arr.length; h < len; h++) { - doMath(h); - } - - //Same as above, but no curly braces - for(var i=0, len=arr.length; i < len; i++) doMath(i); - - //Loop set up different, but uses the index alone - this is ok - for(var j=0, len=arr.length; j < len; j++){ - if(j > 5) { - doMath(j); - } - console.log(arr[j]); - } + // multiple operations in the initializer + for(var h=0, len=arr.length; h < len; h++) {} - //Loop set up different, only uses the index to access the array - this should fail - for(var k=0, len=arr.length; k < len; k++) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - console.log(arr[k]); -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - } -~~~~~ [0] - - //Same as above, but no curly braces - for(var l=0, len=arr.length; l < len; l++) console.log(arr[l]); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + // Same as above, but no curly braces + for(var i=0, len=arr.length; i < len; i++) arr[i]; - //Odd for loop setups + // Odd for loop setups var m = 0; for (;;) { if (m > 3) break; @@ -79,28 +55,68 @@ function sampleFunc() { var o = 0; for (; o < arr.length; o++) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ console.log(arr[o]); -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ } -~~~~~ [0] - //Prefix incrementor + // Prefix incrementor for(let p = 0; p < arr.length; ++p) { - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] arr[p].whatever(); -~~~~~~~~~~~~~~~~~~~~~~~~~~ } -~~~~~ [0] - //For in loops ARE allowed + // empty + for(let x = 0; x < arr.length; x++) {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + + // missing + for(; x < arr.length; x++) {} + for(let x = 0;; x++) {} + for(let x = 0; x < arr.length;) {} + + // mismatch + for(let x = 0; NOTX < arr.length; x++) {} + for(let x = 0; x < arr.length; NOTX++) {} + for(let NOTX = 0; x < arr.length; x++) {} + + // decrement + for(let x = 0; x < arr.length; x--) {} + + // not `<` + for(let x = 0; x <= arr.length; x++) {} + + // wrong starting point + for(let x = 1; x < arr.length; x++) {} + + // not `length` property + for(let x = 0; x < arr.length(); x++) {} + + // alternate incrementor + for(let x = 0; x < arr.length; x+=1) {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + for(let x = 0; x < arr.length; x=x+1) {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + for(let x = 0; x < arr.length; x=1+x) {} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [0] + + // adds too much + for(let x = 0; x < arr.length; x+=11) {} + for(let x = 0; x < arr.length; x=x+11) {} + + for(let x = 0; x < arr.length; x++) { + x++; + } + + // unexpected condition + for(let x = 0; true; x++) {} + + // For-in loops ARE allowed for (var q in obj) { if (obj.hasOwnProperty(q)) { console.log(q); } } - //For of loops ARE allowed + // For-of loops ARE allowed for (var r of arr) { console.log(r); } From 716e1e72e155db1a01933c47660af698a4865b17 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Tue, 22 Nov 2016 16:36:02 -0500 Subject: [PATCH 107/111] fix `adjacent-overload-signatures` to treat static as non-overload (#1772) --- src/rules/adjacentOverloadSignaturesRule.ts | 30 +++++++++++++------ .../adjacent-overload-signatures/test.ts.lint | 6 ++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/rules/adjacentOverloadSignaturesRule.ts b/src/rules/adjacentOverloadSignaturesRule.ts index e95c1f303ed..918aab31031 100644 --- a/src/rules/adjacentOverloadSignaturesRule.ts +++ b/src/rules/adjacentOverloadSignaturesRule.ts @@ -58,7 +58,9 @@ class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker { } public visitInterfaceDeclaration(node: ts.InterfaceDeclaration): void { - this.checkOverloadsAdjacent(node.members, (member) => member.name && getTextOfPropertyName(member.name)); + this.checkOverloadsAdjacent(node.members, (member) => { + return getTextOfPropertyName(member); + }); super.visitInterfaceDeclaration(node); } @@ -84,7 +86,9 @@ class AdjacentOverloadSignaturesWalker extends Lint.RuleWalker { } private visitMembers(members: Array) { - this.checkOverloadsAdjacent(members, (member) => member.name && getTextOfPropertyName(member.name)); + this.checkOverloadsAdjacent(members, (member) => { + return getTextOfPropertyName(member); + }); } /** 'getOverloadName' may return undefined for nodes that cannot be overloads, e.g. a `const` declaration. */ @@ -109,19 +113,27 @@ function isLiteralExpression(node: ts.Node): node is ts.LiteralExpression { return node.kind === ts.SyntaxKind.StringLiteral || node.kind === ts.SyntaxKind.NumericLiteral; } -function getTextOfPropertyName(name: ts.PropertyName): string { - switch (name.kind) { +function getTextOfPropertyName(node: ts.InterfaceDeclaration | ts.TypeElement | ts.ClassElement): string { + let nameText: string; + if (node.name == null) { + return null; + } + switch (node.name.kind) { case ts.SyntaxKind.Identifier: - return (name as ts.Identifier).text; + nameText = (node.name as ts.Identifier).text; + break; case ts.SyntaxKind.ComputedPropertyName: - const { expression } = (name as ts.ComputedPropertyName); + const { expression } = (node.name as ts.ComputedPropertyName); if (isLiteralExpression(expression)) { - return expression.text; + nameText = expression.text; } break; default: - if (isLiteralExpression(name)) { - return name.text; + if (isLiteralExpression(node.name)) { + nameText = ( node.name).text; } } + + const suffix = Lint.hasModifier(node.modifiers, ts.SyntaxKind.StaticKeyword) ? " __static__" : ""; + return nameText + suffix; } diff --git a/test/rules/adjacent-overload-signatures/test.ts.lint b/test/rules/adjacent-overload-signatures/test.ts.lint index 9b65ef3d1b2..de6a26b2f28 100644 --- a/test/rules/adjacent-overload-signatures/test.ts.lint +++ b/test/rules/adjacent-overload-signatures/test.ts.lint @@ -111,3 +111,9 @@ declare namespace N { export function a(x: number): void; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [All 'a' signatures should be adjacent] } + +class Foo { + public static bar() {} + constructor() {} + public bar() {} +} \ No newline at end of file From 353156312a8bcf15738e9331673974e1ad90aa77 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Tue, 22 Nov 2016 16:36:21 -0500 Subject: [PATCH 108/111] Don't exit on missing rules (#1771) --- src/ruleLoader.ts | 23 +++++++++++++---------- test/ruleLoaderTests.ts | 40 ++++++---------------------------------- 2 files changed, 19 insertions(+), 44 deletions(-) diff --git a/src/ruleLoader.ts b/src/ruleLoader.ts index 5a4e79860c7..7c6cebb5047 100644 --- a/src/ruleLoader.ts +++ b/src/ruleLoader.ts @@ -21,6 +21,7 @@ import {camelize} from "underscore.string"; import {getRulesDirectories} from "./configuration"; import {IDisabledInterval, IRule} from "./language/rule/rule"; +import {dedent} from "./utils"; const moduleDirectory = path.dirname(module.filename); const CORE_RULES_DIRECTORY = path.resolve(moduleDirectory, ".", "rules"); @@ -65,26 +66,28 @@ export function loadRules(ruleConfiguration: {[name: string]: any}, } if (notFoundRules.length > 0) { - const ERROR_MESSAGE = ` + const warning = dedent` Could not find implementations for the following rules specified in the configuration: - ${notFoundRules.join("\n")} + ${notFoundRules.join("\n ")} Try upgrading TSLint and/or ensuring that you have all necessary custom rules installed. If TSLint was recently upgraded, you may have old rules configured which need to be cleaned up. `; - throw new Error(ERROR_MESSAGE); - } else if (notAllowedInJsRules.length > 0) { - const JS_ERROR_MESSAGE = ` + console.warn(warning); + } + if (notAllowedInJsRules.length > 0) { + const warning = dedent` Following rules specified in configuration couldn't be applied to .js or .jsx files: - ${notAllowedInJsRules.join("\n")} - + ${notAllowedInJsRules.join("\n ")} Make sure to exclude them from "jsRules" section of your tslint.json. `; - throw new Error(JS_ERROR_MESSAGE); - } else { - return rules; + console.warn(warning); + } + if (rules.length === 0) { + console.warn("No valid rules have been specified"); } + return rules; } export function findRule(name: string, rulesDirectories?: string | string[]) { diff --git a/test/ruleLoaderTests.ts b/test/ruleLoaderTests.ts index f9bb790b35e..21f784254f4 100644 --- a/test/ruleLoaderTests.ts +++ b/test/ruleLoaderTests.ts @@ -33,32 +33,15 @@ describe("Rule Loader", () => { assert.equal(rules.length, 5); }); - it("throws if an invalid rule is found", () => { + it("ignores invalid rules", () => { const invalidConfiguration: {[name: string]: any} = { - invalidConfig1: true, - invalidConfig2: false, - }; - - assert.throws( - () => loadRules(invalidConfiguration, {}, RULES_DIRECTORY), - /invalidConfig1\ninvalidConfig2/, - ); - }); - - it("doesn't ignore leading or trailing underscores or dashes", () => { - /* tslint:disable:object-literal-sort-keys */ - const invalidConfiguration: {[name: string]: any} = { - "_indent": 6, - "forin_": true, - "-quotemark": "single", - "eofline-": true, + "class-name": true, + "invalidConfig1": true, + "invalidConfig2": false, }; - /* tslint:enable:object-literal-sort-keys */ - assert.throws( - () => loadRules(invalidConfiguration, {}, RULES_DIRECTORY), - /_indent\nforin_\n-quotemark\neofline-/, - ); + const rules = loadRules(invalidConfiguration, {}, [RULES_DIRECTORY]); + assert.equal(rules.length, 1); }); it("works with rulesDirectory argument as an Array", () => { @@ -82,15 +65,4 @@ describe("Rule Loader", () => { const rules = loadRules(validConfiguration, {}, RULES_DIRECTORY, true); assert.equal(rules.length, 1); }); - - it("throws if an invalid rule is adopted", () => { - const invalidConfiguration: {[name: string]: any} = { - "array-type": [true, "array"], - }; - - assert.throws( - () => loadRules(invalidConfiguration, {}, RULES_DIRECTORY, true), - /array-type/, - ); - }); }); From 750f7c582d6444dd77e82c24af40eeb7d6268a6e Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 23 Nov 2016 11:25:56 -0500 Subject: [PATCH 109/111] Prepare version 4.0.2 (#1778) --- CHANGELOG.md | 12 ++++++++++++ README.md | 2 +- package.json | 2 +- src/linter.ts | 2 +- src/tslint-cli.ts | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce21cbf741b..7cf7707f374 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ Change Log === +v4.0.2 +--- +* [enhancement] Don't exit when a rule can't be found. Print as a warning instead (#1771) +* [bugfix] Don't flag a property named as empty string as not needing quotes in an object literal (#1762) +* [bugfix] Report correct number of fixes done by --fix (#1767) +* [bugfix] Allow 3rd party apps to see exception when the config is invalid (#1764) +* [bugfix] Fix false positives and exceptions in `prefer-for-of` (#1758) +* [bugfix] Fix `adjacent-overload-signatures` false positive when a static function has the same name (#1772) + +Thanks to our contributors! +* @gustavderdrache + v4.0.1 --- * [bugfix] Removed `no-unused-variable` rule from recommended config, as it was causing spurious deprecation warnings. diff --git a/README.md b/README.md index 35fc869fee5..662d9c150e9 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ Options: ``` -c, --config configuration file -e, --exclude exclude globs from path expansion ---fix fixes linting errors for select rules (his may overwrite linted files) +--fix fixes linting errors for select rules (this may overwrite linted files) --force return status code 0 even if there are lint errors -h, --help display detailed help -i, --init generate a tslint.json config file in the current working directory diff --git a/package.json b/package.json index 40ad22d92a6..0a5f8b5775a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tslint", - "version": "4.0.1", + "version": "4.0.2", "description": "An extensible static analysis linter for the TypeScript language", "bin": { "tslint": "./bin/tslint" diff --git a/src/linter.ts b/src/linter.ts index 3a0837d0e46..e522288f358 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -41,7 +41,7 @@ import { arrayify, dedent } from "./utils"; * Linter that can lint multiple files in consecutive runs. */ class Linter { - public static VERSION = "4.0.1"; + public static VERSION = "4.0.2"; public static findConfiguration = findConfiguration; public static findConfigurationPath = findConfigurationPath; diff --git a/src/tslint-cli.ts b/src/tslint-cli.ts index dc722d1f9e0..c8f2dc3e9a6 100644 --- a/src/tslint-cli.ts +++ b/src/tslint-cli.ts @@ -54,7 +54,7 @@ let processed = optimist type: "string", }, "fix": { - describe: "Fixes linting errors for select rules. This may overwrite linted files", + describe: "fixes linting errors for select rules (this may overwrite linted files)", type: "boolean", }, "force": { From 69c4674db2a3a5650efc81511e5148ddfe926855 Mon Sep 17 00:00:00 2001 From: Noah Chen Date: Wed, 23 Nov 2016 12:21:08 -0500 Subject: [PATCH 110/111] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cf7707f374..849622ab17d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ Change Log v4.0.2 --- * [enhancement] Don't exit when a rule can't be found. Print as a warning instead (#1771) +* [api-change] Allow 3rd party apps to see exception when the config is invalid (#1764) * [bugfix] Don't flag a property named as empty string as not needing quotes in an object literal (#1762) * [bugfix] Report correct number of fixes done by --fix (#1767) -* [bugfix] Allow 3rd party apps to see exception when the config is invalid (#1764) * [bugfix] Fix false positives and exceptions in `prefer-for-of` (#1758) * [bugfix] Fix `adjacent-overload-signatures` false positive when a static function has the same name (#1772) From e0869e4308ee35d293b5fd21c6a88dbff12c25a1 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 23 Nov 2016 13:18:36 -0800 Subject: [PATCH 111/111] Make only-arrow-functions allow functions with a `this` parameter (#1597) --- src/rules/onlyArrowFunctionsRule.ts | 23 +++++++++++++++---- .../allow-declarations/test.ts.lint | 3 +++ .../only-arrow-functions/default/test.ts.lint | 3 +++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/rules/onlyArrowFunctionsRule.ts b/src/rules/onlyArrowFunctionsRule.ts index 5d144558884..ad7734e071b 100644 --- a/src/rules/onlyArrowFunctionsRule.ts +++ b/src/rules/onlyArrowFunctionsRule.ts @@ -56,16 +56,31 @@ export class Rule extends Lint.Rules.AbstractRule { class OnlyArrowFunctionsWalker extends Lint.RuleWalker { public visitFunctionDeclaration(node: ts.FunctionDeclaration) { - if (!node.asteriskToken && !this.hasOption(OPTION_ALLOW_DECLARATIONS)) { - this.addFailure(this.createFailure(node.getStart(), "function".length, Rule.FAILURE_STRING)); + if (!this.hasOption(OPTION_ALLOW_DECLARATIONS)) { + this.failUnlessExempt(node); } super.visitFunctionDeclaration(node); } public visitFunctionExpression(node: ts.FunctionExpression) { - if (!node.asteriskToken) { + this.failUnlessExempt(node); + super.visitFunctionExpression(node); + } + + private failUnlessExempt(node: ts.FunctionLikeDeclaration) { + if (!functionIsExempt(node)) { this.addFailure(this.createFailure(node.getStart(), "function".length, Rule.FAILURE_STRING)); } - super.visitFunctionExpression(node); } } + +/** Generator functions and functions explicitly declaring `this` are allowed. */ +function functionIsExempt(node: ts.FunctionLikeDeclaration) { + return node.asteriskToken || hasThisParameter(node); +} + +function hasThisParameter(node: ts.FunctionLikeDeclaration) { + const first = node.parameters[0]; + return first && first.name.kind === ts.SyntaxKind.Identifier && + (first.name as ts.Identifier).originalKeywordKind === ts.SyntaxKind.ThisKeyword; +} diff --git a/test/rules/only-arrow-functions/allow-declarations/test.ts.lint b/test/rules/only-arrow-functions/allow-declarations/test.ts.lint index 22dbf05bec4..6b0ce7a08a8 100644 --- a/test/rules/only-arrow-functions/allow-declarations/test.ts.lint +++ b/test/rules/only-arrow-functions/allow-declarations/test.ts.lint @@ -20,4 +20,7 @@ function () { function* generator() {} let generator = function*() {} +function hasThisParameter(this) {} +let hasThisParameter = function(this) {} + [0]: non-arrow functions are forbidden diff --git a/test/rules/only-arrow-functions/default/test.ts.lint b/test/rules/only-arrow-functions/default/test.ts.lint index ddacd8e2fc5..bad11677983 100644 --- a/test/rules/only-arrow-functions/default/test.ts.lint +++ b/test/rules/only-arrow-functions/default/test.ts.lint @@ -23,4 +23,7 @@ function () { function* generator() {} let generator = function*() {} +function hasThisParameter(this) {} +let hasThisParameter = function(this) {} + [0]: non-arrow functions are forbidden