From a9950fcb4a1cf54dcb7fb7ac5d5c60a3cd79a86c Mon Sep 17 00:00:00 2001 From: Kwok Chi Leong Date: Wed, 21 Aug 2019 02:58:27 +0800 Subject: [PATCH] [@types/eslint] Added rules definitions for ESLint (#37704) * [@types/map-to-obj] New type definition * [@types/map-to-obj] Fixed typo * [@types/eslint] Added rules definitions for ESLint * [@types/eslint] Fixed coding style * [@types/eslint] Updated headers * Revert "[@types/eslint] Fixed coding style" This reverts commit b1ac79f159efe5bd70a0295e76853f19c52045f7. * [@types/eslint] Removed unused file * [@types/eslint] fixed tsconfig.json --- types/eslint/index.d.ts | 3 +- types/eslint/package.json | 11 + types/eslint/ts3.1/eslint-tests.ts | 573 ++++++ types/eslint/ts3.1/helpers.d.ts | 3 + types/eslint/ts3.1/index.d.ts | 589 ++++++ types/eslint/ts3.1/rules/best-practices.d.ts | 876 +++++++++ types/eslint/ts3.1/rules/deprecated.d.ts | 258 +++ types/eslint/ts3.1/rules/ecmascript-6.d.ts | 444 +++++ types/eslint/ts3.1/rules/index.d.ts | 14 + types/eslint/ts3.1/rules/node-commonjs.d.ts | 124 ++ types/eslint/ts3.1/rules/possible-errors.d.ts | 472 +++++ types/eslint/ts3.1/rules/strict-mode.d.ts | 13 + .../eslint/ts3.1/rules/stylistic-issues.d.ts | 1739 +++++++++++++++++ types/eslint/ts3.1/rules/variables.d.ts | 171 ++ types/eslint/ts3.1/tsconfig.json | 33 + types/eslint/ts3.1/tslint.json | 1 + 16 files changed, 5323 insertions(+), 1 deletion(-) create mode 100644 types/eslint/package.json create mode 100644 types/eslint/ts3.1/eslint-tests.ts create mode 100644 types/eslint/ts3.1/helpers.d.ts create mode 100644 types/eslint/ts3.1/index.d.ts create mode 100644 types/eslint/ts3.1/rules/best-practices.d.ts create mode 100644 types/eslint/ts3.1/rules/deprecated.d.ts create mode 100644 types/eslint/ts3.1/rules/ecmascript-6.d.ts create mode 100644 types/eslint/ts3.1/rules/index.d.ts create mode 100644 types/eslint/ts3.1/rules/node-commonjs.d.ts create mode 100644 types/eslint/ts3.1/rules/possible-errors.d.ts create mode 100644 types/eslint/ts3.1/rules/strict-mode.d.ts create mode 100644 types/eslint/ts3.1/rules/stylistic-issues.d.ts create mode 100644 types/eslint/ts3.1/rules/variables.d.ts create mode 100644 types/eslint/ts3.1/tsconfig.json create mode 100644 types/eslint/ts3.1/tslint.json diff --git a/types/eslint/index.d.ts b/types/eslint/index.d.ts index b3cbfbc8df..c8fbc14981 100644 --- a/types/eslint/index.d.ts +++ b/types/eslint/index.d.ts @@ -1,8 +1,9 @@ -// Type definitions for eslint 4.16 +// Type definitions for eslint 6.1 // Project: https://eslint.org // Definitions by: Pierre-Marie Dartus // Jed Fox // Saad Quadri +// Jason Kwok // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 diff --git a/types/eslint/package.json b/types/eslint/package.json new file mode 100644 index 0000000000..c1f0c68752 --- /dev/null +++ b/types/eslint/package.json @@ -0,0 +1,11 @@ +{ + "private": true, + "types": "index", + "typesVersions": { + ">=3.1.0-0": { + "*": [ + "ts3.1/*" + ] + } + } +} \ No newline at end of file diff --git a/types/eslint/ts3.1/eslint-tests.ts b/types/eslint/ts3.1/eslint-tests.ts new file mode 100644 index 0000000000..f6347dc917 --- /dev/null +++ b/types/eslint/ts3.1/eslint-tests.ts @@ -0,0 +1,573 @@ +import { Comment } from 'estree'; +import { AST, SourceCode, Rule, Linter, CLIEngine, RuleTester, Scope } from 'eslint'; + +const SOURCE = `var foo = bar;`; + +const AST: AST.Program = { + type: 'Program', + sourceType: 'module', + body: [], + comments: [], + tokens: [], + loc: { + start: { line: 0, column: 0 }, + end: { line: 0, column: 0 } + }, + range: [0, 0], +}; + +const TOKEN: AST.Token = { + type: 'Identifier', + value: 'foo', + loc: { + start: { line: 0, column: 0 }, + end: { line: 0, column: 3 } + }, + range: [0, 3] +}; + +const COMMENT: Comment = { + type: 'Block', + value: 'foo', + loc: { + start: { line: 0, column: 0 }, + end: { line: 0, column: 0 } + }, + range: [0, 0], +}; + +//#region SourceCode + +let sourceCode = new SourceCode(SOURCE, AST); + +SourceCode.splitLines(SOURCE); + +sourceCode.getText(); +sourceCode.getText(AST); +sourceCode.getText(AST, 0); +sourceCode.getText(AST, 0, 0); + +sourceCode.getLines(); + +sourceCode.getAllComments(); + +sourceCode.getComments(AST).leading; +sourceCode.getComments(AST).trailing; + +sourceCode.getJSDocComment(AST); + +sourceCode.getNodeByRangeIndex(0); + +sourceCode.getNodeByRangeIndex(0); + +sourceCode.isSpaceBetweenTokens(TOKEN, TOKEN); + +const loc = sourceCode.getLocFromIndex(0); +loc.line; // $ExpectType number +loc.column; // $ExpectType number + +sourceCode.getIndexFromLoc({ line: 0, column: 0 }); + +sourceCode.getTokenByRangeStart(0); +sourceCode.getTokenByRangeStart(0, { includeComments: true }); + +sourceCode.getFirstToken(AST); +sourceCode.getFirstToken(AST, 0); +sourceCode.getFirstToken(AST, { skip: 0 }); +sourceCode.getFirstToken(AST, t => t.type === 'Identifier'); +sourceCode.getFirstToken(AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getFirstToken(AST, { skip: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getFirstToken(AST, { includeComments: true }); +sourceCode.getFirstToken(AST, { includeComments: true, skip: 0 }); +sourceCode.getFirstToken(AST, { includeComments: true, skip: 0, filter: t => t.type === 'Identifier' }); + +sourceCode.getFirstTokens(AST); +sourceCode.getFirstTokens(AST, 0); +sourceCode.getFirstTokens(AST, { count: 0 }); +sourceCode.getFirstTokens(AST, t => t.type === 'Identifier'); +sourceCode.getFirstTokens(AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getFirstTokens(AST, { count: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getFirstTokens(AST, { includeComments: true }); +sourceCode.getFirstTokens(AST, { includeComments: true, count: 0 }); +sourceCode.getFirstTokens(AST, { includeComments: true, count: 0, filter: t => t.type === 'Identifier' }); + +sourceCode.getLastToken(AST); +sourceCode.getLastToken(AST, 0); +sourceCode.getLastToken(AST, { skip: 0 }); +sourceCode.getLastToken(AST, t => t.type === 'Identifier'); +sourceCode.getLastToken(AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getLastToken(AST, { skip: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getLastToken(AST, { includeComments: true }); +sourceCode.getLastToken(AST, { includeComments: true, skip: 0 }); +sourceCode.getLastToken(AST, { includeComments: true, skip: 0, filter: t => t.type === 'Identifier' }); + +sourceCode.getLastTokens(AST); +sourceCode.getLastTokens(AST, 0); +sourceCode.getLastTokens(AST, { count: 0 }); +sourceCode.getLastTokens(AST, t => t.type === 'Identifier'); +sourceCode.getLastTokens(AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getLastTokens(AST, { count: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getLastTokens(AST, { includeComments: true }); +sourceCode.getLastTokens(AST, { includeComments: true, count: 0 }); +sourceCode.getLastTokens(AST, { includeComments: true, count: 0, filter: t => t.type === 'Identifier' }); + +sourceCode.getTokenBefore(AST); +sourceCode.getTokenBefore(AST, 0); +sourceCode.getTokenBefore(AST, { skip: 0 }); +sourceCode.getTokenBefore(AST, t => t.type === 'Identifier'); +sourceCode.getTokenBefore(AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getTokenBefore(AST, { skip: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getTokenBefore(AST, { includeComments: true }); +sourceCode.getTokenBefore(AST, { includeComments: true, skip: 0 }); +sourceCode.getTokenBefore(AST, { includeComments: true, skip: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getTokenBefore(TOKEN, 0); +sourceCode.getTokenBefore(COMMENT, 0); + +sourceCode.getTokensBefore(AST); +sourceCode.getTokensBefore(AST, 0); +sourceCode.getTokensBefore(AST, { count: 0 }); +sourceCode.getTokensBefore(AST, t => t.type === 'Identifier'); +sourceCode.getTokensBefore(AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getTokensBefore(AST, { count: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getTokensBefore(AST, { includeComments: true }); +sourceCode.getTokensBefore(AST, { includeComments: true, count: 0 }); +sourceCode.getTokensBefore(AST, { includeComments: true, count: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getTokensBefore(TOKEN, 0); +sourceCode.getTokensBefore(COMMENT, 0); + +sourceCode.getTokenAfter(AST); +sourceCode.getTokenAfter(AST, 0); +sourceCode.getTokenAfter(AST, { skip: 0 }); +sourceCode.getTokenAfter(AST, t => t.type === 'Identifier'); +sourceCode.getTokenAfter(AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getTokenAfter(AST, { skip: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getTokenAfter(AST, { includeComments: true }); +sourceCode.getTokenAfter(AST, { includeComments: true, skip: 0 }); +sourceCode.getTokenAfter(AST, { includeComments: true, skip: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getTokenAfter(TOKEN, 0); +sourceCode.getTokenAfter(COMMENT, 0); + +sourceCode.getTokensAfter(AST); +sourceCode.getTokensAfter(AST, 0); +sourceCode.getTokensAfter(AST, { count: 0 }); +sourceCode.getTokensAfter(AST, t => t.type === 'Identifier'); +sourceCode.getTokensAfter(AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getTokensAfter(AST, { count: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getTokensAfter(AST, { includeComments: true }); +sourceCode.getTokensAfter(AST, { includeComments: true, count: 0 }); +sourceCode.getTokensAfter(AST, { includeComments: true, count: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getTokensAfter(TOKEN, 0); +sourceCode.getTokensAfter(COMMENT, 0); + +sourceCode.getFirstTokenBetween(AST, AST); +sourceCode.getFirstTokenBetween(AST, AST, 0); +sourceCode.getFirstTokenBetween(AST, AST, { skip: 0 }); +sourceCode.getFirstTokenBetween(AST, AST, t => t.type === 'Identifier'); +sourceCode.getFirstTokenBetween(AST, AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getFirstTokenBetween(AST, AST, { skip: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getFirstTokenBetween(AST, AST, { includeComments: true }); +sourceCode.getFirstTokenBetween(AST, AST, { includeComments: true, skip: 0 }); +sourceCode.getFirstTokenBetween(AST, AST, { includeComments: true, skip: 0, filter: t => t.type === 'Identifier' }); + +sourceCode.getFirstTokensBetween(AST, AST); +sourceCode.getFirstTokensBetween(AST, AST, 0); +sourceCode.getFirstTokensBetween(AST, AST, { count: 0 }); +sourceCode.getFirstTokensBetween(AST, AST, t => t.type === 'Identifier'); +sourceCode.getFirstTokensBetween(AST, AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getFirstTokensBetween(AST, AST, { count: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getFirstTokensBetween(AST, AST, { includeComments: true }); +sourceCode.getFirstTokensBetween(AST, AST, { includeComments: true, count: 0 }); +sourceCode.getFirstTokensBetween(AST, AST, { includeComments: true, count: 0, filter: t => t.type === 'Identifier' }); + +sourceCode.getLastTokenBetween(AST, AST); +sourceCode.getLastTokenBetween(AST, AST, 0); +sourceCode.getLastTokenBetween(AST, AST, { skip: 0 }); +sourceCode.getLastTokenBetween(AST, AST, t => t.type === 'Identifier'); +sourceCode.getLastTokenBetween(AST, AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getLastTokenBetween(AST, AST, { skip: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getLastTokenBetween(AST, AST, { includeComments: true }); +sourceCode.getLastTokenBetween(AST, AST, { includeComments: true, skip: 0 }); +sourceCode.getLastTokenBetween(AST, AST, { includeComments: true, skip: 0, filter: t => t.type === 'Identifier' }); + +sourceCode.getLastTokensBetween(AST, AST); +sourceCode.getLastTokensBetween(AST, AST, 0); +sourceCode.getLastTokensBetween(AST, AST, { count: 0 }); +sourceCode.getLastTokensBetween(AST, AST, t => t.type === 'Identifier'); +sourceCode.getLastTokensBetween(AST, AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getLastTokensBetween(AST, AST, { count: 0, filter: t => t.type === 'Identifier' }); +sourceCode.getLastTokensBetween(AST, AST, { includeComments: true }); +sourceCode.getLastTokensBetween(AST, AST, { includeComments: true, count: 0 }); +sourceCode.getLastTokensBetween(AST, AST, { includeComments: true, count: 0, filter: t => t.type === 'Identifier' }); + +sourceCode.getTokensBetween(AST, AST); +sourceCode.getTokensBetween(AST, AST, 0); + +sourceCode.getTokens(AST); +sourceCode.getTokens(AST, 0); +sourceCode.getTokens(AST, 0, 0); +sourceCode.getTokens(AST, t => t.type === 'Identifier'); +sourceCode.getTokens(AST, { filter: t => t.type === 'Identifier' }); +sourceCode.getTokens(AST, { includeComments: true }); +sourceCode.getTokens(AST, { includeComments: true, filter: t => t.type === 'Identifier' }); + +sourceCode.commentsExistBetween(AST, AST); +sourceCode.commentsExistBetween(TOKEN, TOKEN); + +sourceCode.getCommentsBefore(AST); +sourceCode.getCommentsBefore(TOKEN); + +sourceCode.getCommentsAfter(AST); +sourceCode.getCommentsAfter(TOKEN); + +sourceCode.getCommentsInside(AST); + +//#endregion + +//#region Scope + +const scopeManager: Scope.ScopeManager = { + scopes: [], + globalScope: null, + acquire(node, inner) { + return scopeManager.scopes[0]; + }, + getDeclaredVariables() { + return []; + } +}; + +const scope = scopeManager.scopes[0]; + +const variable = scope.variables[0]; + +variable.name = 'foo'; + +variable.identifiers[0].type = 'Identifier'; + +variable.defs[0].name.type = 'Identifier'; +variable.defs[0].type; +variable.defs[0].node; +variable.defs[0].parent; + +const reference = scope.references[0]; + +reference.from = scope; +reference.identifier.type = 'Identifier'; +reference.resolved = variable; +reference.writeExpr = AST; +reference.init = true; + +reference.isRead(); +reference.isReadOnly(); +reference.isWrite(); +reference.isWriteOnly(); +reference.isReadWrite(); + +//#endregion + +//#region Rule + +let rule: Rule.RuleModule; + +rule = { create(context) { return {}; } }; +rule = { create(context) { return {}; }, meta: {} }; +rule = { create(context) { return {}; }, meta: { + docs: { + description: 'disallow the use of `console`', + category: 'Possible Errors', + recommended: true, + url: 'https://eslint.org/docs/rules/no-console', + } +}}; +rule = { create(context) { return {}; }, meta: { fixable: 'whitespace' }}; +rule = { create(context) { return {}; }, meta: { fixable: 'code' }}; +rule = { create(context) { return {}; }, meta: { schema: [{ enum: ['always', 'never'] }] }}; +rule = { create(context) { return {}; }, meta: { deprecated: true }}; +rule = { + create(context) { + return {}; + }, + meta: { type: 'layout' }, +}; + +rule = { + create(context) { + context.getAncestors(); + + context.getDeclaredVariables(AST); + + context.getFilename(); + + context.getSourceCode(); + + context.getScope(); + + context.markVariableAsUsed('foo'); + + context.report({ message: 'foo', node: AST }); + context.report({ message: 'foo', loc: { line: 0, column: 0 } }); + context.report({ message: 'foo', node: AST, data: { foo: 'bar' } }); + context.report({ message: 'foo', node: AST, fix: () => null }); + context.report({ message: 'foo', node: AST, fix: ruleFixer => ruleFixer.replaceText(AST, 'foo') }); + + context.report({ + message: 'foo', + node: AST, + fix: ruleFixer => { + ruleFixer.insertTextAfter(AST, 'foo'); + ruleFixer.insertTextAfter(TOKEN, 'foo'); + + ruleFixer.insertTextAfterRange([0, 0], 'foo'); + + ruleFixer.insertTextBefore(AST, 'foo'); + ruleFixer.insertTextBefore(TOKEN, 'foo'); + + ruleFixer.insertTextBeforeRange([0, 0], 'foo'); + + ruleFixer.remove(AST); + ruleFixer.remove(TOKEN); + + ruleFixer.removeRange([0, 0]); + + ruleFixer.replaceText(AST, 'foo'); + ruleFixer.replaceText(TOKEN, 'foo'); + + ruleFixer.replaceTextRange([0, 0], 'foo'); + + return null; + } + }); + + return { + onCodePathStart(codePath, node) {}, + onCodePathEnd(codePath, node) {}, + onCodePathSegmentStart(segment, node) {}, + onCodePathSegmentEnd(segment, node) {}, + onCodePathSegmentLoop(fromSegment, toSegment, node) {}, + IfStatement(node) {}, + 'Program:exit'() {}, + }; + }, +}; + +//#endregion + +//#region Linter + +const linter = new Linter(); + +linter.version; + +linter.verify(SOURCE, {}); +linter.verify(new SourceCode(SOURCE, AST), {}); + +linter.verify(SOURCE, {}, 'test.js'); +linter.verify(SOURCE, {}, {}); +linter.verify(SOURCE, {}, { filename: 'test.js' }); +linter.verify(SOURCE, {}, { allowInlineConfig: false }); +linter.verify(SOURCE, {}, { reportUnusedDisableDirectives: true }); +linter.verify(SOURCE, {}, { preprocess: input => input.split(' ') }); +linter.verify(SOURCE, {}, { postprocess: problemList => problemList[0] }); + +linter.verify(SOURCE, { parserOptions: { ecmaVersion: 6 } }, 'test.js'); +linter.verify(SOURCE, { parserOptions: { ecmaVersion: 6, ecmaFeatures: { globalReturn: true } } }, 'test.js'); +linter.verify(SOURCE, { parserOptions: { ecmaVersion: 6, ecmaFeatures: { experimentalObjectRestSpread: true } } }, 'test.js'); +linter.verify(SOURCE, { env: { node: true } }, 'test.js'); +linter.verify(SOURCE, { globals: { foo: true } }, 'test.js'); +linter.verify(SOURCE, { parser: 'custom-parser' }, 'test.js'); +linter.verify(SOURCE, { settings: { info: 'foo' } }, 'test.js'); +linter.verify(SOURCE, { processor: 'a-plugin/a-processor' }, 'test.js'); +linter.verify(SOURCE, { plugins: ['a-plugin'] }, 'test.js'); +linter.verify(SOURCE, { root: true }, 'test.js'); +linter.verify(SOURCE, { extends: 'eslint-config-bad-guy' }, 'test.js'); +linter.verify(SOURCE, { extends: ['eslint-config-bad-guy', 'eslint-config-roblox'] }, 'test.js'); + +linter.verify(SOURCE, { rules: {} }, 'test.js'); +linter.verify(SOURCE, { rules: { quotes: 2 } }, 'test.js'); +linter.verify(SOURCE, { rules: { quotes: [2, 'double'] } }, 'test.js'); +linter.verify(SOURCE, { rules: { 'no-unused-vars': [2, { vars: 'all' }] } }, 'test.js'); +linter.verify(SOURCE, { rules: { 'no-console': 1 } }, 'test.js'); +linter.verify(SOURCE, { rules: { 'no-console': 0 } }, 'test.js'); +linter.verify(SOURCE, { rules: { 'no-console': 'error' } }, 'test.js'); +linter.verify(SOURCE, { + rules: { 'no-console': 'error' }, + overrides: [ + { + excludedFiles: ['*-test.js', '*.spec.js'], + files: ['*-test.js', '*.spec.js'], + rules: { + 'no-unused-expressions': 'off' + } + } + ] +}, 'test.js'); +linter.verify(SOURCE, { rules: { 'no-console': 'warn' } }, 'test.js'); +linter.verify(SOURCE, { rules: { 'no-console': 'off' } }, 'test.js'); + +const lintingResult = linter.verify(SOURCE, {}); + +for (const msg of lintingResult) { + msg.severity = 1; + msg.severity = 2; + + msg.ruleId = 'foo'; + + msg.fatal = true; + + msg.line = 0; + msg.endLine = 0; + msg.column = 0; + msg.endColumn = 0; + + msg.source = SOURCE; + + if (msg.fix) { + msg.fix.text = 'foo'; + msg.fix.range = [0, 0]; + } +} + +linter.verifyAndFix(SOURCE, {}); +linter.verifyAndFix(SOURCE, {}, 'test.js'); +linter.verifyAndFix(SOURCE, {}, { fix: false }); + +const fixResult = linter.verifyAndFix(SOURCE, {}); + +fixResult.fixed = true; +fixResult.output = 'foo'; + +for (const msg of fixResult.messages) { + msg.ruleId = 'foo'; +} + +sourceCode = linter.getSourceCode(); + +linter.defineRule('test', rule); + +linter.defineRules({ + foo: rule, + bar: rule, +}); + +linter.getRules(); + +linter.defineParser('custom-parser', { parse: (src, opts) => AST }); +linter.defineParser('custom-parser', { + parseForESLint(src, opts) { + return { + ast: AST, + visitorKeys: {}, + parserServices: {}, + scopeManager, + }; + } +}); + +//#endregion + +//#region CLIEngine + +let cli: CLIEngine; + +cli = new CLIEngine({ allowInlineConfig: false }); +cli = new CLIEngine({ baseConfig: false }); +cli = new CLIEngine({ baseConfig: { extends: ['lynt'] }}); +cli = new CLIEngine({ cache: true }); +cli = new CLIEngine({ cacheFile: 'foo' }); +cli = new CLIEngine({ configFile: 'foo' }); +cli = new CLIEngine({ cwd: 'foo' }); +cli = new CLIEngine({ envs: ['browser'] }); +cli = new CLIEngine({ extensions: ['js'] }); +cli = new CLIEngine({ fix: true }); +cli = new CLIEngine({ globals: ['foo'] }); +cli = new CLIEngine({ ignore: true }); +cli = new CLIEngine({ ignorePath: 'foo' }); +cli = new CLIEngine({ ignorePattern: 'foo' }); +cli = new CLIEngine({ ignorePattern: ['foo', 'bar'] }); +cli = new CLIEngine({ useEslintrc: false }); +cli = new CLIEngine({ parserOptions: {} }); +cli = new CLIEngine({ plugins: ['foo'] }); +cli = new CLIEngine({ rules: { 'test/example-rule': 1 } }); +cli = new CLIEngine({ rulePaths: ['foo'] }); +cli = new CLIEngine({ reportUnusedDisableDirectives: true }); + +let cliReport = cli.executeOnFiles(['myfile.js', 'lib/']); + +cliReport = cli.executeOnText(SOURCE, 'foo'); + +cli.resolveFileGlobPatterns(['**/*']); + +cli.getConfigForFile('./config.json'); + +cli.addPlugin('my-fancy-plugin', {}); + +cli.isPathIgnored('./dist/index.js'); + +let formatter: CLIEngine.Formatter; + +formatter = cli.getFormatter('codeframe'); +formatter = cli.getFormatter(); + +formatter(cliReport.results); + +CLIEngine.getErrorResults(cliReport.results); + +CLIEngine.outputFixes(cliReport); + +cliReport.errorCount = 0; +cliReport.warningCount = 0; +cliReport.fixableErrorCount = 0; +cliReport.fixableWarningCount = 0; + +for (const file of cliReport.results) { + file.filePath = 'foo.js'; + + file.errorCount = 0; + file.warningCount = 0; + file.fixableErrorCount = 0; + file.fixableWarningCount = 0; + + file.source = 'foo'; + file.output = 'foo'; + + for (const message of file.messages) { + message.ruleId = 'foo'; + } +} + +//#endregion + +//#region RuleTester + +const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 2015 } }); + +ruleTester.run('my-rule', rule, { + valid: [ + { code: 'foo' }, + { code: 'foo', options: [{ allowFoo: true }] }, + { code: 'foo', filename: 'test.js' }, + { code: 'foo', parserOptions: {} }, + { code: 'foo', settings: { foo: true } }, + { code: 'foo', parser: 'foo' }, + { code: 'foo', globals: { foo: true } }, + ], + + invalid: [ + { code: 'foo', errors: 1 }, + { code: 'foo', errors: ['foo'] }, + { code: 'foo', errors: [{ message: 'foo' }] }, + { code: 'foo', errors: [{ message: 'foo', type: 'foo' }] }, + { code: 'foo', errors: [{ message: 'foo', data: { foo: true } }] }, + { code: 'foo', errors: [{ message: 'foo', line: 0 }] }, + ] +}); + +ruleTester.run('simple-valid-test', rule, { + valid: [ + 'foo', + 'bar', + { code: 'foo', options: [{ allowFoo: true }] }, + ] +}); + +//#endregion diff --git a/types/eslint/ts3.1/helpers.d.ts b/types/eslint/ts3.1/helpers.d.ts new file mode 100644 index 0000000000..f67bb88e57 --- /dev/null +++ b/types/eslint/ts3.1/helpers.d.ts @@ -0,0 +1,3 @@ +type Prepend = ((_: Addend, ..._1: Tuple) => any) extends (( + ..._: infer Result +) => any) ? Result : never; diff --git a/types/eslint/ts3.1/index.d.ts b/types/eslint/ts3.1/index.d.ts new file mode 100644 index 0000000000..5b8891c9c6 --- /dev/null +++ b/types/eslint/ts3.1/index.d.ts @@ -0,0 +1,589 @@ +/// + +import { JSONSchema4 } from 'json-schema'; +import * as ESTree from 'estree'; + +export namespace AST { + type TokenType = + | 'Boolean' + | 'Null' + | 'Identifier' + | 'Keyword' + | 'Punctuator' + | 'JSXIdentifier' + | 'JSXText' + | 'Numeric' + | 'String' + | 'RegularExpression'; + + interface Token { + type: TokenType; + value: string; + range: Range; + loc: SourceLocation; + } + + interface SourceLocation { + start: ESTree.Position; + end: ESTree.Position; + } + + type Range = [number, number]; + + interface Program extends ESTree.Program { + comments: ESTree.Comment[]; + tokens: Token[]; + loc: SourceLocation; + range: Range; + } +} + +export namespace Scope { + interface ScopeManager { + scopes: Scope[]; + globalScope: Scope | null; + + acquire(node: ESTree.Node, inner?: boolean): Scope | null; + + getDeclaredVariables(node: ESTree.Node): Variable[]; + } + + interface Scope { + type: 'block' | 'catch' | 'class' | 'for' | 'function' | 'function-expression-name' | 'global' | 'module' | 'switch' | 'with' | 'TDZ'; + isStrict: boolean; + upper: Scope | null; + childScopes: Scope[]; + variableScope: Scope; + block: ESTree.Node; + variables: Variable[]; + set: Map; + references: Reference[]; + through: Reference[]; + functionExpressionScope: boolean; + } + + interface Variable { + name: string; + identifiers: ESTree.Identifier[]; + references: Reference[]; + defs: Definition[]; + } + + interface Reference { + identifier: ESTree.Identifier; + from: Scope; + resolved: Variable | null; + writeExpr: ESTree.Node | null; + init: boolean; + + isWrite(): boolean; + + isRead(): boolean; + + isWriteOnly(): boolean; + + isReadOnly(): boolean; + + isReadWrite(): boolean; + } + + type DefinitionType = + | { type: 'CatchClause', node: ESTree.CatchClause, parent: null } + | { type: 'ClassName', node: ESTree.ClassDeclaration | ESTree.ClassExpression, parent: null } + | { type: 'FunctionName', node: ESTree.FunctionDeclaration | ESTree.FunctionExpression, parent: null } + | { type: 'ImplicitGlobalVariable', node: ESTree.Program, parent: null } + | { type: 'ImportBinding', node: ESTree.ImportSpecifier | ESTree.ImportDefaultSpecifier | ESTree.ImportNamespaceSpecifier, parent: ESTree.ImportDeclaration } + | { type: 'Parameter', node: ESTree.FunctionDeclaration | ESTree.FunctionExpression | ESTree.ArrowFunctionExpression, parent: null } + | { type: 'TDZ', node: any, parent: null } + | { type: 'Variable', node: ESTree.VariableDeclarator, parent: ESTree.VariableDeclaration }; + + type Definition = DefinitionType & { name: ESTree.Identifier }; +} + +//#region SourceCode + +export class SourceCode { + text: string; + ast: AST.Program; + lines: string[]; + hasBOM: boolean; + parserServices: SourceCode.ParserServices; + scopeManager: Scope.ScopeManager; + visitorKeys: SourceCode.VisitorKeys; + + constructor(text: string, ast: AST.Program); + constructor(config: SourceCode.Config); + + static splitLines(text: string): string[]; + + getText(node?: ESTree.Node, beforeCount?: number, afterCount?: number): string; + + getLines(): string[]; + + getAllComments(): ESTree.Comment[]; + + getComments(node: ESTree.Node): { leading: ESTree.Comment[], trailing: ESTree.Comment[] }; + + getJSDocComment(node: ESTree.Node): AST.Token | null; + + getNodeByRangeIndex(index: number): ESTree.Node | null; + + isSpaceBetweenTokens(first: AST.Token, second: AST.Token): boolean; + + getLocFromIndex(index: number): ESTree.Position; + + getIndexFromLoc(location: ESTree.Position): number; + + // Inherited methods from TokenStore + // --------------------------------- + + getTokenByRangeStart(offset: number, options?: { includeComments?: boolean }): AST.Token | null; + + getFirstToken(node: ESTree.Node, options?: SourceCode.CursorWithSkipOptions): AST.Token | null; + + getFirstTokens(node: ESTree.Node, options?: SourceCode.CursorWithCountOptions): AST.Token[]; + + getLastToken(node: ESTree.Node, options?: SourceCode.CursorWithSkipOptions): AST.Token | null; + + getLastTokens(node: ESTree.Node, options?: SourceCode.CursorWithCountOptions): AST.Token[]; + + getTokenBefore(node: ESTree.Node | AST.Token | ESTree.Comment, options?: SourceCode.CursorWithSkipOptions): AST.Token | null; + + getTokensBefore(node: ESTree.Node | AST.Token | ESTree.Comment, options?: SourceCode.CursorWithCountOptions): AST.Token[]; + + getTokenAfter(node: ESTree.Node | AST.Token | ESTree.Comment, options?: SourceCode.CursorWithSkipOptions): AST.Token | null; + + getTokensAfter(node: ESTree.Node | AST.Token | ESTree.Comment, options?: SourceCode.CursorWithCountOptions): AST.Token[]; + + getFirstTokenBetween( + left: ESTree.Node | AST.Token | ESTree.Comment, + right: ESTree.Node | AST.Token | ESTree.Comment, + options?: SourceCode.CursorWithSkipOptions + ): AST.Token | null; + + getFirstTokensBetween( + left: ESTree.Node | AST.Token | ESTree.Comment, + right: ESTree.Node | AST.Token | ESTree.Comment, + options?: SourceCode.CursorWithCountOptions + ): AST.Token[]; + + getLastTokenBetween( + left: ESTree.Node | AST.Token | ESTree.Comment, + right: ESTree.Node | AST.Token | ESTree.Comment, + options?: SourceCode.CursorWithSkipOptions + ): AST.Token | null; + + getLastTokensBetween( + left: ESTree.Node | AST.Token | ESTree.Comment, + right: ESTree.Node | AST.Token | ESTree.Comment, + options?: SourceCode.CursorWithCountOptions + ): AST.Token[]; + + getTokensBetween( + left: ESTree.Node | AST.Token | ESTree.Comment, + right: ESTree.Node | AST.Token | ESTree.Comment, + padding?: number | SourceCode.FilterPredicate | SourceCode.CursorWithCountOptions + ): AST.Token[]; + + getTokens(node: ESTree.Node, beforeCount?: number, afterCount?: number): AST.Token[]; + getTokens(node: ESTree.Node, options: SourceCode.FilterPredicate | SourceCode.CursorWithCountOptions): AST.Token[]; + + commentsExistBetween(left: ESTree.Node | AST.Token, right: ESTree.Node | AST.Token): boolean; + + getCommentsBefore(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[]; + + getCommentsAfter(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[]; + + getCommentsInside(node: ESTree.Node): ESTree.Comment[]; +} + +export namespace SourceCode { + interface Config { + text: string; + ast: AST.Program; + parserServices?: ParserServices; + scopeManager?: Scope.ScopeManager; + visitorKeys?: VisitorKeys; + } + + type ParserServices = any; + + interface VisitorKeys { + [nodeType: string]: string[]; + } + + type FilterPredicate = (tokenOrComment: AST.Token | ESTree.Comment) => boolean; + + type CursorWithSkipOptions = number | FilterPredicate | { + includeComments?: boolean; + filter?: FilterPredicate; + skip?: number; + }; + + type CursorWithCountOptions = number | FilterPredicate | { + includeComments?: boolean; + filter?: FilterPredicate; + count?: number; + }; +} + +//#endregion + +export namespace Rule { + interface RuleModule { + create(context: RuleContext): RuleListener; + meta?: RuleMetaData; + } + + type NodeTypes = ESTree.Node['type']; + type NodeListener = { [T in NodeTypes]?: (node: ESTree.Node) => void }; + + interface RuleListener extends NodeListener { + onCodePathStart?(codePath: CodePath, node: ESTree.Node): void; + + onCodePathEnd?(codePath: CodePath, node: ESTree.Node): void; + + onCodePathSegmentStart?(segment: CodePathSegment, node: ESTree.Node): void; + + onCodePathSegmentEnd?(segment: CodePathSegment, node: ESTree.Node): void; + + onCodePathSegmentLoop?(fromSegment: CodePathSegment, toSegment: CodePathSegment, node: ESTree.Node): void; + + [key: string]: + | ((codePath: CodePath, node: ESTree.Node) => void) + | ((segment: CodePathSegment, node: ESTree.Node) => void) + | ((fromSegment: CodePathSegment, toSegment: CodePathSegment, node: ESTree.Node) => void) + | ((node: ESTree.Node) => void) + | undefined; + } + + interface CodePath { + id: string; + initialSegment: CodePathSegment; + finalSegments: CodePathSegment[]; + returnedSegments: CodePathSegment[]; + thrownSegments: CodePathSegment[]; + currentSegments: CodePathSegment[]; + upper: CodePath | null; + childCodePaths: CodePath[]; + } + + interface CodePathSegment { + id: string; + nextSegments: CodePathSegment[]; + prevSegments: CodePathSegment[]; + reachable: boolean; + } + + interface RuleMetaData { + docs?: { + description?: string; + category?: string; + recommended?: boolean; + url?: string; + }; + messages?: { [messageId: string]: string }; + fixable?: 'code' | 'whitespace'; + schema?: JSONSchema4 | JSONSchema4[]; + deprecated?: boolean; + type?: 'problem' | 'suggestion' | 'layout'; + } + + interface RuleContext { + id: string; + options: any[]; + settings: { [name: string]: any }; + parserPath: string; + parserOptions: Linter.ParserOptions; + parserServices: SourceCode.ParserServices; + + getAncestors(): ESTree.Node[]; + + getDeclaredVariables(node: ESTree.Node): Scope.Variable[]; + + getFilename(): string; + + getScope(): Scope.Scope; + + getSourceCode(): SourceCode; + + markVariableAsUsed(name: string): boolean; + + report(descriptor: ReportDescriptor): void; + } + + type ReportDescriptor = ReportDescriptorMessage & ReportDescriptorLocation & ReportDescriptorOptions; + type ReportDescriptorMessage = { message: string } | { messageId: string }; + type ReportDescriptorLocation = + | { node: ESTree.Node } + | { loc: AST.SourceLocation | { line: number; column: number } }; + interface ReportDescriptorOptions { + data?: { [key: string]: string }; + + fix?(fixer: RuleFixer): null | Fix | IterableIterator; + } + + interface RuleFixer { + insertTextAfter(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix; + + insertTextAfterRange(range: AST.Range, text: string): Fix; + + insertTextBefore(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix; + + insertTextBeforeRange(range: AST.Range, text: string): Fix; + + remove(nodeOrToken: ESTree.Node | AST.Token): Fix; + + removeRange(range: AST.Range): Fix; + + replaceText(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix; + + replaceTextRange(range: AST.Range, text: string): Fix; + } + + interface Fix { + range: AST.Range; + text: string; + } +} + +//#region Linter + +export class Linter { + version: string; + + verify(code: SourceCode | string, config: Linter.Config, filename?: string): Linter.LintMessage[]; + verify(code: SourceCode | string, config: Linter.Config, options: Linter.LintOptions): Linter.LintMessage[]; + + verifyAndFix(code: string, config: Linter.Config, filename?: string): Linter.FixReport; + verifyAndFix(code: string, config: Linter.Config, options: Linter.FixOptions): Linter.FixReport; + + getSourceCode(): SourceCode; + + defineRule(name: string, rule: Rule.RuleModule): void; + + defineRules(rules: { [name: string]: Rule.RuleModule }): void; + + getRules(): Map; + + defineParser(name: string, parser: Linter.ParserModule): void; +} + +export namespace Linter { + type Severity = 0 | 1 | 2; + + type RuleLevel = Severity | 'off' | 'warn' | 'error'; + type RuleLevelAndOptions = Prepend, RuleLevel>; + + type RuleEntry = RuleLevel | RuleLevelAndOptions; + + interface RulesRecord { + [rule: string]: RuleEntry; + } + + interface HasRules { + rules?: Partial; + } + + interface RuleOverride extends HasRules { + excludedFiles?: string[]; + files?: string[]; + } + + interface Config extends HasRules { + parser?: string; + parserOptions?: ParserOptions; + settings?: { [name: string]: any }; + env?: { [name: string]: boolean }; + globals?: { [name: string]: boolean }; + extends?: string | string[]; + overrides?: RuleOverride[]; + processor?: string; + plugins?: string[]; + root?: boolean; + } + + interface ParserOptions { + ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 2015 | 2016 | 2017 | 2018; + sourceType?: 'script' | 'module'; + ecmaFeatures?: { + globalReturn?: boolean; + impliedStrict?: boolean; + jsx?: boolean; + experimentalObjectRestSpread?: boolean; + [key: string]: any; + }; + [key: string]: any; + } + + interface LintOptions { + filename?: string; + preprocess?: (code: string) => string[]; + postprocess?: (problemLists: LintMessage[][]) => LintMessage[]; + allowInlineConfig?: boolean; + reportUnusedDisableDirectives?: boolean; + } + + interface LintMessage { + column: number; + line: number; + endColumn?: number; + endLine?: number; + ruleId: string | null; + message: string; + nodeType: string; + fatal?: true; + severity: Severity; + fix?: Rule.Fix; + source: string | null; + } + + interface FixOptions extends LintOptions { + fix?: boolean; + } + + interface FixReport { + fixed: boolean; + output: string; + messages: LintMessage[]; + } + + type ParserModule = { + parse(text: string, options?: any): AST.Program; + } | { + parseForESLint(text: string, options?: any): ESLintParseResult; + }; + + interface ESLintParseResult { + ast: AST.Program; + parserServices?: SourceCode.ParserServices; + scopeManager?: Scope.ScopeManager; + visitorKeys?: SourceCode.VisitorKeys; + } +} + +//#endregion + +//#region CLIEngine + +export class CLIEngine { + version: string; + + constructor(options: CLIEngine.Options); + + executeOnFiles(patterns: string[]): CLIEngine.LintReport; + + resolveFileGlobPatterns(patterns: string[]): string[]; + + getConfigForFile(filePath: string): Linter.Config; + + executeOnText(text: string, filename?: string): CLIEngine.LintReport; + + addPlugin(name: string, pluginObject: any): void; + + isPathIgnored(filePath: string): boolean; + + getFormatter(format?: string): CLIEngine.Formatter; + + getRules(): Map; + + static getErrorResults(results: CLIEngine.LintResult[]): CLIEngine.LintResult[]; + + static outputFixes(report: CLIEngine.LintReport): void; +} + +export namespace CLIEngine { + class Options { + allowInlineConfig?: boolean; + baseConfig?: false | { [name: string]: any }; + cache?: boolean; + cacheFile?: string; + cacheLocation?: string; + configFile?: string; + cwd?: string; + envs?: string[]; + extensions?: string[]; + fix?: boolean; + globals?: string[]; + ignore?: boolean; + ignorePath?: string; + ignorePattern?: string | string[]; + useEslintrc?: boolean; + parser?: string; + parserOptions?: Linter.ParserOptions; + plugins?: string[]; + rules?: { + [name: string]: Linter.RuleLevel | Linter.RuleLevelAndOptions; + }; + rulePaths?: string[]; + reportUnusedDisableDirectives?: boolean; + } + + interface LintResult { + filePath: string; + messages: Linter.LintMessage[]; + errorCount: number; + warningCount: number; + fixableErrorCount: number; + fixableWarningCount: number; + output?: string; + source?: string; + } + + interface LintReport { + results: LintResult[]; + errorCount: number; + warningCount: number; + fixableErrorCount: number; + fixableWarningCount: number; + } + + type Formatter = (results: LintResult[]) => string; +} + +//#endregion + +//#region RuleTester + +export class RuleTester { + constructor(config?: any); + + run( + name: string, + rule: Rule.RuleModule, + tests: { + valid?: Array; + invalid?: RuleTester.InvalidTestCase[]; + }, + ): void; +} + +export namespace RuleTester { + interface ValidTestCase { + code: string; + options?: any; + filename?: string; + parserOptions?: Linter.ParserOptions; + settings?: { [name: string]: any }; + parser?: string; + globals?: { [name: string]: boolean }; + } + + interface InvalidTestCase extends ValidTestCase { + errors: number | Array; + output?: string | null; + } + + interface TestCaseError { + message?: string | RegExp; + messageId?: string; + type?: string; + data?: any; + line?: number; + column?: number; + endLine?: number; + endColumn?: number; + } +} + +//#endregion diff --git a/types/eslint/ts3.1/rules/best-practices.d.ts b/types/eslint/ts3.1/rules/best-practices.d.ts new file mode 100644 index 0000000000..97d68d6a06 --- /dev/null +++ b/types/eslint/ts3.1/rules/best-practices.d.ts @@ -0,0 +1,876 @@ +import { Linter } from '../index'; + +export interface BestPractices extends Linter.RulesRecord { + /** + * Rule to enforce getter and setter pairs in objects. + * + * @since 0.22.0 + * @see https://eslint.org/docs/rules/accessor-pairs + */ + 'accessor-pairs': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + setWithoutGet: boolean; + /** + * @default false + */ + getWithoutSet: boolean; + }> + ]>; + + /** + * Rule to enforce `return` statements in callbacks of array methods. + * + * @since 2.0.0-alpha-1 + * @see https://eslint.org/docs/rules/array-callback-return + */ + 'array-callback-return': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + allowImplicit: boolean; + }> + ]>; + + /** + * Rule to enforce the use of variables within the scope they are defined. + * + * @since 0.1.0 + * @see https://eslint.org/docs/rules/block-scoped-var + */ + 'block-scoped-var': Linter.RuleEntry<[]>; + + /** + * Rule to enforce that class methods utilize `this`. + * + * @since 3.4.0 + * @see https://eslint.org/docs/rules/class-methods-use-this + */ + 'class-methods-use-this': Linter.RuleEntry<[ + Partial<{ + exceptMethods: string[]; + }> + ]>; + + /** + * Rule to enforce a maximum cyclomatic complexity allowed in a program. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/complexity + */ + 'complexity': Linter.RuleEntry<[ + Partial<{ + /** + * @default 20 + */ + max: number; + /** + * @deprecated + * @default 20 + */ + maximum: number; + }> | number + ]>; + + /** + * Rule to require `return` statements to either always or never specify values. + * + * @since 0.4.0 + * @see https://eslint.org/docs/rules/consistent-return + */ + 'consistent-return': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + treatUndefinedAsUnspecified: boolean; + }> + ]>; + + /** + * Rule to enforce consistent brace style for all control statements. + * + * @since 0.0.2 + * @see https://eslint.org/docs/rules/curly + */ + 'curly': Linter.RuleEntry<[ + 'all' | 'multi' | 'multi-line' | 'multi-or-nest' | 'consistent' + ]>; + + /** + * Rule to require `default` cases in `switch` statements. + * + * @since 0.6.0 + * @see https://eslint.org/docs/rules/default-case + */ + 'default-case': Linter.RuleEntry<[ + Partial<{ + /** + * @default '^no default$' + */ + commentPattern: string; + }> + ]>; + + /** + * Rule to enforce consistent newlines before and after dots. + * + * @since 0.21.0 + * @see https://eslint.org/docs/rules/dot-location + */ + 'dot-location': Linter.RuleEntry<[ + 'object' | 'property' + ]>; + + /** + * Rule to enforce dot notation whenever possible. + * + * @since 0.0.7 + * @see https://eslint.org/docs/rules/dot-notation + */ + 'dot-notation': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + allowKeywords: boolean; + allowPattern: string; + }> + ]>; + + /** + * Rule to require the use of `===` and `!==`. + * + * @since 0.0.2 + * @see https://eslint.org/docs/rules/eqeqeq + */ + 'eqeqeq': Linter.RuleEntry<[ + 'always', + Partial<{ + /** + * @default 'always' + */ + null: 'always' | 'never' | 'ignore'; + }> + ]> | Linter.RuleEntry<[ + 'smart' | 'allow-null' + ]>; + + /** + * Rule to require `for-in` loops to include an `if` statement. + * + * @since 0.0.6 + * @see https://eslint.org/docs/rules/guard-for-in + */ + 'guard-for-in': Linter.RuleEntry<[]>; + + /** + * Rule to enforce a maximum number of classes per file. + * + * @since 5.0.0-alpha.3 + * @see https://eslint.org/docs/rules/max-classes-per-file + */ + 'max-classes-per-file': Linter.RuleEntry<[ + number + ]>; + + /** + * Rule to disallow the use of `alert`, `confirm`, and `prompt`. + * + * @since 0.0.5 + * @see https://eslint.org/docs/rules/no-alert + */ + 'no-alert': Linter.RuleEntry<[]>; + + /** + * Rule to disallow the use of `arguments.caller` or `arguments.callee`. + * + * @since 0.0.6 + * @see https://eslint.org/docs/rules/no-caller + */ + 'no-caller': Linter.RuleEntry<[]>; + + /** + * Rule to disallow lexical declarations in case clauses. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 1.9.0 + * @see https://eslint.org/docs/rules/no-case-declarations + */ + 'no-case-declarations': Linter.RuleEntry<[]>; + + /** + * Rule to disallow division operators explicitly at the beginning of regular expressions. + * + * @since 0.1.0 + * @see https://eslint.org/docs/rules/no-div-regex + */ + 'no-div-regex': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `else` blocks after `return` statements in `if` statements. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-else-return + */ + 'no-else-return': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + allowElseIf: boolean; + }> + ]>; + + /** + * Rule to disallow empty functions. + * + * @since 2.0.0 + * @see https://eslint.org/docs/rules/no-empty-function + */ + 'no-empty-function': Linter.RuleEntry<[ + Partial<{ + /** + * @default [] + */ + allow: Array<'functions' | 'arrowFunctions' | 'generatorFunctions' | 'methods' | 'generatorMethods' | 'getters' | 'setters' | 'constructors'>; + }> + ]>; + + /** + * Rule to disallow empty destructuring patterns. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 1.7.0 + * @see https://eslint.org/docs/rules/no-empty-pattern + */ + 'no-empty-pattern': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `null` comparisons without type-checking operators. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-eq-null + */ + 'no-eq-null': Linter.RuleEntry<[]>; + + /** + * Rule to disallow the use of `eval()`. + * + * @since 0.0.2 + * @see https://eslint.org/docs/rules/no-eval + */ + 'no-eval': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + allowIndirect: boolean; + }> + ]>; + + /** + * Rule to disallow extending native types. + * + * @since 0.1.4 + * @see https://eslint.org/docs/rules/no-extend-native + */ + 'no-extend-native': Linter.RuleEntry<[ + Partial<{ + exceptions: string[]; + }> + ]>; + + /** + * Rule to disallow unnecessary calls to `.bind()`. + * + * @since 0.8.0 + * @see https://eslint.org/docs/rules/no-extra-bind + */ + 'no-extra-bind': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unnecessary labels. + * + * @since 2.0.0-rc.0 + * @see https://eslint.org/docs/rules/no-extra-label + */ + 'no-extra-label': Linter.RuleEntry<[]>; + + /** + * Rule to disallow fallthrough of `case` statements. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.7 + * @see https://eslint.org/docs/rules/no-fallthrough + */ + 'no-fallthrough': Linter.RuleEntry<[ + Partial<{ + /** + * @default 'falls?\s?through' + */ + commentPattern: string; + }> + ]>; + + /** + * Rule to disallow leading or trailing decimal points in numeric literals. + * + * @since 0.0.6 + * @see https://eslint.org/docs/rules/no-floating-decimal + */ + 'no-floating-decimal': Linter.RuleEntry<[]>; + + /** + * Rule to disallow assignments to native objects or read-only global variables. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 3.3.0 + * @see https://eslint.org/docs/rules/no-global-assign + */ + 'no-global-assign': Linter.RuleEntry<[ + Partial<{ + exceptions: string[]; + }> + ]>; + + /** + * Rule to disallow shorthand type conversions. + * + * @since 1.0.0-rc-2 + * @see https://eslint.org/docs/rules/no-implicit-coercion + */ + 'no-implicit-coercion': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + boolean: boolean; + /** + * @default true + */ + number: boolean; + /** + * @default true + */ + string: boolean; + /** + * @default [] + */ + allow: Array<'~' | '!!' | '+' | '*'>; + }> + ]>; + + /** + * Rule to disallow variable and `function` declarations in the global scope. + * + * @since 2.0.0-alpha-1 + * @see https://eslint.org/docs/rules/no-implicit-globals + */ + 'no-implicit-globals': Linter.RuleEntry<[]>; + + /** + * Rule to disallow the use of `eval()`-like methods. + * + * @since 0.0.7 + * @see https://eslint.org/docs/rules/no-implied-eval + */ + 'no-implied-eval': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `this` keywords outside of classes or class-like objects. + * + * @since 1.0.0-rc-2 + * @see https://eslint.org/docs/rules/no-invalid-this + */ + 'no-invalid-this': Linter.RuleEntry<[]>; + + /** + * Rule to disallow the use of the `__iterator__` property. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-iterator + */ + 'no-iterator': Linter.RuleEntry<[]>; + + /** + * Rule to disallow labeled statements. + * + * @since 0.4.0 + * @see https://eslint.org/docs/rules/no-labels + */ + 'no-labels': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + allowLoop: boolean; + /** + * @default false + */ + allowSwitch: boolean; + }> + ]>; + + /** + * Rule to disallow unnecessary nested blocks. + * + * @since 0.4.0 + * @see https://eslint.org/docs/rules/no-lone-blocks + */ + 'no-lone-blocks': Linter.RuleEntry<[]>; + + /** + * Rule to disallow function declarations that contain unsafe references inside loop statements. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-loop-func + */ + 'no-loop-func': Linter.RuleEntry<[]>; + + /** + * Rule to disallow magic numbers. + * + * @since 1.7.0 + * @see https://eslint.org/docs/rules/no-magic-numbers + */ + 'no-magic-numbers': Linter.RuleEntry<[ + Partial<{ + /** + * @default [] + */ + ignore: number[]; + /** + * @default false + */ + ignoreArrayIndexes: boolean; + /** + * @default false + */ + enforceConst: boolean; + /** + * @default false + */ + detectObjects: boolean; + }> + ]>; + + /** + * Rule to disallow multiple spaces. + * + * @since 0.9.0 + * @see https://eslint.org/docs/rules/no-multi-spaces + */ + 'no-multi-spaces': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + ignoreEOLComments: boolean; + /** + * @default { Property: true } + */ + exceptions: Record; + }> + ]>; + + /** + * Rule to disallow multiline strings. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-multi-str + */ + 'no-multi-str': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `new` operators outside of assignments or comparisons. + * + * @since 0.0.7 + * @see https://eslint.org/docs/rules/no-new + */ + 'no-new': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `new` operators with the `Function` object. + * + * @since 0.0.7 + * @see https://eslint.org/docs/rules/no-new-func + */ + 'no-new-func': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `new` operators with the `String`, `Number`, and `Boolean` objects. + * + * @since 0.0.6 + * @see https://eslint.org/docs/rules/no-new-wrappers + */ + 'no-new-wrappers': Linter.RuleEntry<[]>; + + /** + * Rule to disallow octal literals. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.6 + * @see https://eslint.org/docs/rules/no-octal + */ + 'no-octal': Linter.RuleEntry<[]>; + + /** + * Rule to disallow octal escape sequences in string literals. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-octal-escape + */ + 'no-octal-escape': Linter.RuleEntry<[]>; + + /** + * Rule to disallow reassigning `function` parameters. + * + * @since 0.18.0 + * @see https://eslint.org/docs/rules/no-param-reassign + */ + 'no-param-reassign': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + props: boolean; + /** + * @default [] + */ + ignorePropertyModificationsFor: string[]; + }> + ]>; + + /** + * Rule to disallow the use of the `__proto__` property. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-proto + */ + 'no-proto': Linter.RuleEntry<[]>; + + /** + * Rule to disallow variable redeclaration. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-redeclare + */ + 'no-redeclare': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + builtinGlobals: boolean; + }> + ]>; + + /** + * Rule to disallow certain properties on certain objects. + * + * @since 3.5.0 + * @see https://eslint.org/docs/rules/no-restricted-properties + */ + 'no-restricted-properties': Linter.RuleEntry<[ + ...Array<{ + object: string; + property?: string; + message?: string; + } | { + property: string; + message?: string; + }> + ]>; + + /** + * Rule to disallow assignment operators in `return` statements. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-return-assign + */ + 'no-return-assign': Linter.RuleEntry<[ + 'except-parens' | 'always' + ]>; + + /** + * Rule to disallow unnecessary `return await`. + * + * @since 3.10.0 + * @see https://eslint.org/docs/rules/no-return-await + */ + 'no-return-await': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `javascript:` urls. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-script-url + */ + 'no-script-url': Linter.RuleEntry<[]>; + + /** + * Rule to disallow assignments where both sides are exactly the same. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 2.0.0-rc.0 + * @see https://eslint.org/docs/rules/no-self-assign + */ + 'no-self-assign': Linter.RuleEntry<[]>; + + /** + * Rule to disallow comparisons where both sides are exactly the same. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-self-compare + */ + 'no-self-compare': Linter.RuleEntry<[]>; + + /** + * Rule to disallow comma operators. + * + * @since 0.5.1 + * @see https://eslint.org/docs/rules/no-sequences + */ + 'no-sequences': Linter.RuleEntry<[]>; + + /** + * Rule to disallow throwing literals as exceptions. + * + * @since 0.15.0 + * @see https://eslint.org/docs/rules/no-throw-literal + */ + 'no-throw-literal': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unmodified loop conditions. + * + * @since 2.0.0-alpha-2 + * @see https://eslint.org/docs/rules/no-unmodified-loop-condition + */ + 'no-unmodified-loop-condition': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unused expressions. + * + * @since 0.1.0 + * @see https://eslint.org/docs/rules/no-unused-expressions + */ + 'no-unused-expressions': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + allowShortCircuit: boolean; + /** + * @default false + */ + allowTernary: boolean; + /** + * @default false + */ + allowTaggedTemplates: boolean; + }> + ]>; + + /** + * Rule to disallow unused labels. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 2.0.0-rc.0 + * @see https://eslint.org/docs/rules/no-unused-labels + */ + 'no-unused-labels': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unnecessary calls to `.call()` and `.apply()`. + * + * @since 1.0.0-rc-1 + * @see https://eslint.org/docs/rules/no-useless-call + */ + 'no-useless-call': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unnecessary `catch` clauses. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 5.11.0 + * @see https://eslint.org/docs/rules/no-useless-catch + */ + 'no-useless-catch': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unnecessary concatenation of literals or template literals. + * + * @since 1.3.0 + * @see https://eslint.org/docs/rules/no-useless-concat + */ + 'no-useless-concat': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unnecessary escape characters. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 2.5.0 + * @see https://eslint.org/docs/rules/no-useless-escape + */ + 'no-useless-escape': Linter.RuleEntry<[]>; + + /** + * Rule to disallow redundant return statements. + * + * @since 3.9.0 + * @see https://eslint.org/docs/rules/no-useless-return + */ + 'no-useless-return': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `void` operators. + * + * @since 0.8.0 + * @see https://eslint.org/docs/rules/no-void + */ + 'no-void': Linter.RuleEntry<[]>; + + /** + * Rule to disallow specified warning terms in comments. + * + * @since 0.4.4 + * @see https://eslint.org/docs/rules/no-warning-comments + */ + 'no-warning-comments': Linter.RuleEntry<[ + { + /** + * @default ["todo", "fixme", "xxx"] + */ + terms: string[]; + /** + * @default 'start' + */ + location: 'start' | 'anywhere'; + } + ]>; + + /** + * Rule to disallow `with` statements. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.2 + * @see https://eslint.org/docs/rules/no-with + */ + 'no-with': Linter.RuleEntry<[]>; + + /** + * Rule to enforce using named capture group in regular expression. + * + * @since 5.15.0 + * @see https://eslint.org/docs/rules/prefer-named-capture-group + */ + 'prefer-named-capture-group': Linter.RuleEntry<[]>; + + /** + * Rule to require using Error objects as Promise rejection reasons. + * + * @since 3.14.0 + * @see https://eslint.org/docs/rules/prefer-promise-reject-errors + */ + 'prefer-promise-reject-errors': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + allowEmptyReject: boolean; + }> + ]>; + + /** + * Rule to enforce the consistent use of the radix argument when using `parseInt()`. + * + * @since 0.0.7 + * @see https://eslint.org/docs/rules/radix + */ + 'radix': Linter.RuleEntry<[ + 'always' | 'as-needed' + ]>; + + /** + * Rule to disallow async functions which have no `await` expression. + * + * @since 3.11.0 + * @see https://eslint.org/docs/rules/require-await + */ + 'require-await': Linter.RuleEntry<[]>; + + /** + * Rule to enforce the use of `u` flag on RegExp. + * + * @since 5.3.0 + * @see https://eslint.org/docs/rules/require-unicode-regexp + */ + 'require-unicode-regexp': Linter.RuleEntry<[]>; + + /** + * Rule to require `var` declarations be placed at the top of their containing scope. + * + * @since 0.8.0 + * @see https://eslint.org/docs/rules/vars-on-top + */ + 'vars-on-top': Linter.RuleEntry<[]>; + + /** + * Rule to require parentheses around immediate `function` invocations. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/wrap-iife + */ + 'wrap-iife': Linter.RuleEntry<[ + 'outside' | 'inside' | 'any', + Partial<{ + /** + * @default false + */ + functionPrototypeMethods: boolean; + }> + ]>; + + /** + * Rule to require or disallow “Yoda” conditions. + * + * @since 0.7.1 + * @see https://eslint.org/docs/rules/yoda + */ + 'yoda': Linter.RuleEntry<[ + 'never', + Partial<{ + exceptRange: boolean; + onlyEquality: boolean; + }> + ]> | Linter.RuleEntry<[ + 'always' + ]>; +} diff --git a/types/eslint/ts3.1/rules/deprecated.d.ts b/types/eslint/ts3.1/rules/deprecated.d.ts new file mode 100644 index 0000000000..d08ba8dc76 --- /dev/null +++ b/types/eslint/ts3.1/rules/deprecated.d.ts @@ -0,0 +1,258 @@ +import { Linter } from '../index'; + +export interface Deprecated extends Linter.RulesRecord { + /** + * Rule to enforce consistent indentation. + * + * @since 4.0.0-alpha.0 + * @deprecated since 4.0.0, use [`indent`](https://eslint.org/docs/rules/indent) instead. + * @see https://eslint.org/docs/rules/indent-legacy + */ + 'indent-legacy': Linter.RuleEntry<[ + number | 'tab', + Partial<{ + /** + * @default 0 + */ + SwitchCase: number; + /** + * @default 1 + */ + VariableDeclarator: Partial<{ + /** + * @default 1 + */ + var: number | 'first'; + /** + * @default 1 + */ + let: number | 'first'; + /** + * @default 1 + */ + const: number | 'first'; + }> | number | 'first'; + /** + * @default 1 + */ + outerIIFEBody: number; + /** + * @default 1 + */ + MemberExpression: number | 'off'; + /** + * @default { parameters: 1, body: 1 } + */ + FunctionDeclaration: Partial<{ + /** + * @default 1 + */ + parameters: number | 'first' | 'off'; + /** + * @default 1 + */ + body: number; + }>; + /** + * @default { parameters: 1, body: 1 } + */ + FunctionExpression: Partial<{ + /** + * @default 1 + */ + parameters: number | 'first' | 'off'; + /** + * @default 1 + */ + body: number; + }>; + /** + * @default { arguments: 1 } + */ + CallExpression: Partial<{ + /** + * @default 1 + */ + arguments: number | 'first' | 'off'; + }>; + /** + * @default 1 + */ + ArrayExpression: number | 'first' | 'off'; + /** + * @default 1 + */ + ObjectExpression: number | 'first' | 'off'; + /** + * @default 1 + */ + ImportDeclaration: number | 'first' | 'off'; + /** + * @default false + */ + flatTernaryExpressions: boolean; + ignoredNodes: string[]; + /** + * @default false + */ + ignoreComments: boolean; + }> + ]>; + + /** + * Rule to require or disallow newlines around directives. + * + * @since 3.5.0 + * @deprecated since 4.0.0, use [`padding-line-between-statements`](https://eslint.org/docs/rules/padding-line-between-statements) instead. + * @see https://eslint.org/docs/rules/lines-around-directive + */ + 'lines-around-directive': Linter.RuleEntry<[ + 'always' | 'never' + ]>; + + /** + * Rule to require or disallow an empty line after variable declarations. + * + * @since 0.18.0 + * @deprecated since 4.0.0, use [`padding-line-between-statements`](https://eslint.org/docs/rules/padding-line-between-statements) instead. + * @see https://eslint.org/docs/rules/newline-after-var + */ + 'newline-after-var': Linter.RuleEntry<[ + 'always' | 'never' + ]>; + + /** + * Rule to require an empty line before `return` statements. + * + * @since 2.3.0 + * @deprecated since 4.0.0, use [`padding-line-between-statements`](https://eslint.org/docs/rules/padding-line-between-statements) instead. + * @see https://eslint.org/docs/rules/newline-before-return + */ + 'newline-before-return': Linter.RuleEntry<[]>; + + /** + * Rule to disallow shadowing of variables inside of `catch`. + * + * @since 0.0.9 + * @deprecated since 5.1.0, use [`no-shadow`](https://eslint.org/docs/rules/no-shadow) instead. + * @see https://eslint.org/docs/rules/no-catch-shadow + */ + 'no-catch-shadow': Linter.RuleEntry<[]>; + + /** + * Rule to disallow reassignment of native objects. + * + * @since 0.0.9 + * @deprecated since 3.3.0, use [`no-global-assign`](https://eslint.org/docs/rules/no-global-assign) instead. + * @see https://eslint.org/docs/rules/no-native-reassign + */ + 'no-native-reassign': Linter.RuleEntry<[ + Partial<{ + exceptions: string[]; + }> + ]>; + + /** + * Rule to disallow negating the left operand in `in` expressions. + * + * @since 0.1.2 + * @deprecated since 3.3.0, use [`no-unsafe-negation`](https://eslint.org/docs/rules/no-unsafe-negation) instead. + * @see https://eslint.org/docs/rules/no-negated-in-lhs + */ + 'no-negated-in-lhs': Linter.RuleEntry<[]>; + + /** + * Rule to disallow spacing between function identifiers and their applications. + * + * @since 0.1.2 + * @deprecated since 3.3.0, use [`func-call-spacing`](https://eslint.org/docs/rules/func-call-spacing) instead. + * @see https://eslint.org/docs/rules/no-spaced-func + */ + 'no-spaced-func': Linter.RuleEntry<[]>; + + /** + * Rule to suggest using `Reflect` methods where applicable. + * + * @since 1.0.0-rc-2 + * @deprecated since 3.9.0 + * @see https://eslint.org/docs/rules/prefer-reflect + */ + 'prefer-reflect': Linter.RuleEntry<[ + Partial<{ + exceptions: string[]; + }> + ]>; + + /** + * Rule to require JSDoc comments. + * + * @since 1.4.0 + * @deprecated since 5.10.0 + * @see https://eslint.org/docs/rules/require-jsdoc + */ + 'require-jsdoc': Linter.RuleEntry<[ + Partial<{ + require: Partial<{ + /** + * @default true + */ + FunctionDeclaration: boolean; + /** + * @default false + */ + MethodDefinition: boolean; + /** + * @default false + */ + ClassDeclaration: boolean; + /** + * @default false + */ + ArrowFunctionExpression: boolean; + /** + * @default false + */ + FunctionExpression: boolean; + }>; + }> + ]>; + + /** + * Rule to enforce valid JSDoc comments. + * + * @since 0.4.0 + * @deprecated since 5.10.0 + * @see https://eslint.org/docs/rules/valid-jsdoc + */ + 'valid-jsdoc': Linter.RuleEntry<[ + Partial<{ + prefer: Record; + preferType: Record; + /** + * @default true + */ + requireReturn: boolean; + /** + * @default true + */ + requireReturnType: boolean; + /** + * @remarks + * Also accept for regular expression pattern + */ + matchDescription: string; + /** + * @default true + */ + requireParamDescription: boolean; + /** + * @default true + */ + requireReturnDescription: boolean; + /** + * @default true + */ + requireParamType: boolean; + }> + ]>; +} diff --git a/types/eslint/ts3.1/rules/ecmascript-6.d.ts b/types/eslint/ts3.1/rules/ecmascript-6.d.ts new file mode 100644 index 0000000000..d3f7de934c --- /dev/null +++ b/types/eslint/ts3.1/rules/ecmascript-6.d.ts @@ -0,0 +1,444 @@ +import { Linter } from '../index'; + +export interface ECMAScript6 extends Linter.RulesRecord { + /** + * Rule to require braces around arrow function bodies. + * + * @since 1.8.0 + * @see https://eslint.org/docs/rules/arrow-body-style + */ + 'arrow-body-style': Linter.RuleEntry<[ + 'as-needed', + Partial<{ + /** + * @default false + */ + requireReturnForObjectLiteral: boolean; + }> + ]> | Linter.RuleEntry<[ + 'always' | 'never' + ]>; + + /** + * Rule to require parentheses around arrow function arguments. + * + * @since 1.0.0-rc-1 + * @see https://eslint.org/docs/rules/arrow-parens + */ + 'arrow-parens': Linter.RuleEntry<[ + 'always' + ]> | Linter.RuleEntry<[ + 'as-needed', + Partial<{ + /** + * @default false + */ + requireForBlockBody: boolean; + }> + ]>; + + /** + * Rule to enforce consistent spacing before and after the arrow in arrow functions. + * + * @since 1.0.0-rc-1 + * @see https://eslint.org/docs/rules/arrow-spacing + */ + 'arrow-spacing': Linter.RuleEntry<[]>; + + /** + * Rule to require `super()` calls in constructors. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.24.0 + * @see https://eslint.org/docs/rules/constructor-super + */ + 'constructor-super': Linter.RuleEntry<[]>; + + /** + * Rule to enforce consistent spacing around `*` operators in generator functions. + * + * @since 0.17.0 + * @see https://eslint.org/docs/rules/generator-star-spacing + */ + 'generator-star-spacing': Linter.RuleEntry<[ + Partial<{ + before: boolean; + after: boolean; + named: Partial<{ + before: boolean; + after: boolean; + }> | 'before' | 'after' | 'both' | 'neither'; + anonymous: Partial<{ + before: boolean; + after: boolean; + }> | 'before' | 'after' | 'both' | 'neither'; + method: Partial<{ + before: boolean; + after: boolean; + }> | 'before' | 'after' | 'both' | 'neither'; + }> | 'before' | 'after' | 'both' | 'neither' + ]>; + + /** + * Rule to disallow reassigning class members. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 1.0.0-rc-1 + * @see https://eslint.org/docs/rules/no-class-assign + */ + 'no-class-assign': Linter.RuleEntry<[]>; + + /** + * Rule to disallow arrow functions where they could be confused with comparisons. + * + * @since 2.0.0-alpha-2 + * @see https://eslint.org/docs/rules/no-confusing-arrow + */ + 'no-confusing-arrow': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + allowParens: boolean; + }> + ]>; + + /** + * Rule to disallow reassigning `const` variables. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 1.0.0-rc-1 + * @see https://eslint.org/docs/rules/no-const-assign + */ + 'no-const-assign': Linter.RuleEntry<[]>; + + /** + * Rule to disallow duplicate class members. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 1.2.0 + * @see https://eslint.org/docs/rules/no-dupe-class-members + */ + 'no-dupe-class-members': Linter.RuleEntry<[]>; + + /** + * Rule to disallow duplicate module imports. + * + * @since 2.5.0 + * @see https://eslint.org/docs/rules/no-duplicate-import + */ + 'no-duplicate-import': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + includeExports: boolean; + }> + ]>; + + /** + * Rule to disallow `new` operators with the `Symbol` object. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 2.0.0-beta.1 + * @see https://eslint.org/docs/rules/no-new-symbol + */ + 'no-new-symbol': Linter.RuleEntry<[]>; + + /** + * Rule to disallow specified modules when loaded by `import`. + * + * @since 2.0.0-alpha-1 + * @see https://eslint.org/docs/rules/no-restricted-imports + */ + 'no-restricted-imports': Linter.RuleEntry<[ + ...Array; + patterns: string[]; + }>> + ]>; + + /** + * Rule to disallow `this`/`super` before calling `super()` in constructors. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.24.0 + * @see https://eslint.org/docs/rules/no-this-before-super + */ + 'no-this-before-super': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unnecessary computed property keys in object literals. + * + * @since 2.9.0 + * @see https://eslint.org/docs/rules/no-useless-computed-key + */ + 'no-useless-computed-key': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unnecessary constructors. + * + * @since 2.0.0-beta.1 + * @see https://eslint.org/docs/rules/no-useless-constructor + */ + 'no-useless-constructor': Linter.RuleEntry<[]>; + + /** + * Rule to disallow renaming import, export, and destructured assignments to the same name. + * + * @since 2.11.0 + * @see https://eslint.org/docs/rules/no-useless-rename + */ + 'no-useless-rename': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + ignoreImport: boolean; + /** + * @default false + */ + ignoreExport: boolean; + /** + * @default false + */ + ignoreDestructuring: boolean; + }> + ]>; + + /** + * Rule to require `let` or `const` instead of `var`. + * + * @since 0.12.0 + * @see https://eslint.org/docs/rules/no-var + */ + 'no-var': Linter.RuleEntry<[]>; + + /** + * Rule to require or disallow method and property shorthand syntax for object literals. + * + * @since 0.20.0 + * @see https://eslint.org/docs/rules/object-shorthand + */ + 'object-shorthand': Linter.RuleEntry<[ + 'always' | 'methods', + Partial<{ + /** + * @default false + */ + avoidQuotes: boolean; + /** + * @default false + */ + ignoreConstructors: boolean; + /** + * @default false + */ + avoidExplicitReturnArrows: boolean; + }> + ]> | Linter.RuleEntry<[ + 'properties', + Partial<{ + /** + * @default false + */ + avoidQuotes: boolean; + }> + ]> | Linter.RuleEntry<[ + 'never' | 'consistent' | 'consistent-as-needed' + ]>; + + /** + * Rule to require using arrow functions for callbacks. + * + * @since 1.2.0 + * @see https://eslint.org/docs/rules/prefer-arrow-callback + */ + 'prefer-arrow-callback': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + allowNamedFunctions: boolean; + /** + * @default true + */ + allowUnboundThis: boolean; + }> + ]>; + + /** + * Rule to require `const` declarations for variables that are never reassigned after declared. + * + * @since 0.23.0 + * @see https://eslint.org/docs/rules/prefer-const + */ + 'prefer-const': Linter.RuleEntry<[ + Partial<{ + /** + * @default 'any' + */ + destructuring: 'any' | 'all'; + /** + * @default false + */ + ignoreReadBeforeAssign: boolean; + }> + ]>; + + /** + * Rule to require destructuring from arrays and/or objects. + * + * @since 3.13.0 + * @see https://eslint.org/docs/rules/prefer-destructuring + */ + 'prefer-destructuring': Linter.RuleEntry<[ + Partial<{ + VariableDeclarator: Partial<{ + array: boolean; + object: boolean; + }>; + AssignmentExpression: Partial<{ + array: boolean; + object: boolean; + }>; + } | { + array: boolean; + object: boolean; + }>, + Partial<{ + enforceForRenamedProperties: boolean; + }> + ]>; + + /** + * Rule to disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals. + * + * @since 3.5.0 + * @see https://eslint.org/docs/rules/prefer-numeric-literals + */ + 'prefer-numeric-literals': Linter.RuleEntry<[]>; + + /** + * Rule to require rest parameters instead of `arguments`. + * + * @since 2.0.0-alpha-1 + * @see https://eslint.org/docs/rules/prefer-rest-params + */ + 'prefer-rest-params': Linter.RuleEntry<[]>; + + /** + * Rule to require spread operators instead of `.apply()`. + * + * @since 1.0.0-rc-1 + * @see https://eslint.org/docs/rules/prefer-spread + */ + 'prefer-spread': Linter.RuleEntry<[]>; + + /** + * Rule to require template literals instead of string concatenation. + * + * @since 1.2.0 + * @see https://eslint.org/docs/rules/prefer-template + */ + 'prefer-template': Linter.RuleEntry<[]>; + + /** + * Rule to require generator functions to contain `yield`. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 1.0.0-rc-1 + * @see https://eslint.org/docs/rules/require-yield + */ + 'require-yield': Linter.RuleEntry<[]>; + + /** + * Rule to enforce spacing between rest and spread operators and their expressions. + * + * @since 2.12.0 + * @see https://eslint.org/docs/rules/rest-spread-spacing + */ + 'rest-spread-spacing': Linter.RuleEntry<[ + 'never' | 'always' + ]>; + + /** + * Rule to enforce sorted import declarations within modules. + * + * @since 2.0.0-beta.1 + * @see https://eslint.org/docs/rules/sort-imports + */ + 'sort-imports': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + ignoreCase: boolean; + /** + * @default false + */ + ignoreDeclarationSort: boolean; + /** + * @default false + */ + ignoreMemberSort: boolean; + /** + * @default ['none', 'all', 'multiple', 'single'] + */ + memberSyntaxSortOrder: Array<'none' | 'all' | 'multiple' | 'single'>; + }> + ]>; + + /** + * Rule to require symbol descriptions. + * + * @since 3.4.0 + * @see https://eslint.org/docs/rules/symbol-description + */ + 'symbol-description': Linter.RuleEntry<[]>; + + /** + * Rule to require or disallow spacing around embedded expressions of template strings. + * + * @since 2.0.0-rc.0 + * @see https://eslint.org/docs/rules/template-curly-spacing + */ + 'template-curly-spacing': Linter.RuleEntry<[ + 'never' | 'always' + ]>; + + /** + * Rule to require or disallow spacing around the `*` in `yield*` expressions. + * + * @since 2.0.0-alpha-1 + * @see https://eslint.org/docs/rules/yield-star-spacing + */ + 'yield-star-spacing': Linter.RuleEntry<[ + Partial<{ + before: boolean; + after: boolean; + }> | 'before' | 'after' | 'both' | 'neither' + ]>; +} diff --git a/types/eslint/ts3.1/rules/index.d.ts b/types/eslint/ts3.1/rules/index.d.ts new file mode 100644 index 0000000000..32e599fdb4 --- /dev/null +++ b/types/eslint/ts3.1/rules/index.d.ts @@ -0,0 +1,14 @@ +import { Linter } from '../index'; + +import { BestPractices } from "./best-practices"; +import { Deprecated } from "./deprecated"; +import { ECMAScript6 } from "./ecmascript-6"; +import { NodeJSAndCommonJS } from "./node-commonjs"; +import { PossibleErrors } from "./possible-errors"; +import { StrictMode } from "./strict-mode"; +import { StylisticIssues } from "./stylistic-issues"; +import { Variables } from "./variables"; + +export interface ESLintRules extends Linter.RulesRecord, + PossibleErrors, BestPractices, StrictMode, Variables, NodeJSAndCommonJS, + StylisticIssues, ECMAScript6, Deprecated {} diff --git a/types/eslint/ts3.1/rules/node-commonjs.d.ts b/types/eslint/ts3.1/rules/node-commonjs.d.ts new file mode 100644 index 0000000000..1d63e0c31c --- /dev/null +++ b/types/eslint/ts3.1/rules/node-commonjs.d.ts @@ -0,0 +1,124 @@ +import { Linter } from '../index'; + +export interface NodeJSAndCommonJS extends Linter.RulesRecord { + /** + * Rule to require `return` statements after callbacks. + * + * @since 1.0.0-rc-1 + * @see https://eslint.org/docs/rules/callback-return + */ + 'callback-return': Linter.RuleEntry<[ + string[] + ]>; + + /** + * Rule to require `require()` calls to be placed at top-level module scope. + * + * @since 1.4.0 + * @see https://eslint.org/docs/rules/global-require + */ + 'global-require': Linter.RuleEntry<[]>; + + /** + * Rule to require error handling in callbacks. + * + * @since 0.4.5 + * @see https://eslint.org/docs/rules/handle-callback-err + */ + 'handle-callback-err': Linter.RuleEntry<[ + string + ]>; + + /** + * Rule to disallow use of the `Buffer()` constructor. + * + * @since 4.0.0-alpha.0 + * @see https://eslint.org/docs/rules/no-buffer-constructor + */ + 'no-buffer-constructor': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `require` calls to be mixed with regular variable declarations. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-mixed-requires + */ + 'no-mixed-requires': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + grouping: boolean; + /** + * @default false + */ + allowCall: boolean; + }> + ]>; + + /** + * Rule to disallow `new` operators with calls to `require`. + * + * @since 0.6.0 + * @see https://eslint.org/docs/rules/no-new-require + */ + 'no-new-require': Linter.RuleEntry<[]>; + + /** + * Rule to disallow string concatenation when using `__dirname` and `__filename`. + * + * @since 0.4.0 + * @see https://eslint.org/docs/rules/no-path-concat + */ + 'no-path-concat': Linter.RuleEntry<[]>; + + /** + * Rule to disallow the use of `process.env`. + * + * @since 0.9.0 + * @see https://eslint.org/docs/rules/no-process-env + */ + 'no-process-env': Linter.RuleEntry<[]>; + + /** + * Rule to disallow the use of `process.exit()`. + * + * @since 0.4.0 + * @see https://eslint.org/docs/rules/no-process-exit + */ + 'no-process-exit': Linter.RuleEntry<[]>; + + /** + * Rule to disallow specified modules when loaded by `require`. + * + * @since 0.6.0 + * @see https://eslint.org/docs/rules/no-restricted-modules + */ + 'no-restricted-modules': Linter.RuleEntry<[ + ...Array; + patterns: string[]; + }>> + ]>; + + /** + * Rule to disallow synchronous methods. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-sync + */ + 'no-sync': Linter.RuleEntry<[ + { + /** + * @default false + */ + allowAtRootLevel: boolean; + } + ]>; +} diff --git a/types/eslint/ts3.1/rules/possible-errors.d.ts b/types/eslint/ts3.1/rules/possible-errors.d.ts new file mode 100644 index 0000000000..8df0e4f8ae --- /dev/null +++ b/types/eslint/ts3.1/rules/possible-errors.d.ts @@ -0,0 +1,472 @@ +import { Linter } from '../index'; + +export interface PossibleErrors extends Linter.RulesRecord { + /** + * Rule to enforce `for` loop update clause moving the counter in the right direction. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 4.0.0-beta.0 + * @see https://eslint.org/docs/rules/for-direction + */ + 'for-direction': Linter.RuleEntry<[]>; + + /** + * Rule to enforce `return` statements in getters. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 4.2.0 + * @see https://eslint.org/docs/rules/getter-return + */ + 'getter-return': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + allowImplicit: boolean; + }> + ]>; + + /** + * Rule to disallow using an async function as a `Promise` executor. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 5.3.0 + * @see https://eslint.org/docs/rules/no-async-promise-executor + */ + 'no-async-promise-executor': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `await` inside of loops. + * + * @since 3.12.0 + * @see https://eslint.org/docs/rules/no-await-in-loop + */ + 'no-await-in-loop': Linter.RuleEntry<[]>; + + /** + * Rule to disallow comparing against `-0`. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 3.17.0 + * @see https://eslint.org/docs/rules/no-compare-neg-zero + */ + 'no-compare-neg-zero': Linter.RuleEntry<[]>; + + /** + * Rule to disallow assignment operators in conditional statements. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-cond-assign + */ + 'no-cond-assign': Linter.RuleEntry<[ + 'except-parens' | 'always' + ]>; + + /** + * Rule to disallow the use of `console`. + * + * @since 0.0.2 + * @see https://eslint.org/docs/rules/no-console + */ + 'no-console': Linter.RuleEntry<[ + Partial<{ + allow: Array; + }> + ]>; + + /** + * Rule to disallow constant expressions in conditions. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.4.1 + * @see https://eslint.org/docs/rules/no-constant-condition + */ + 'no-constant-condition': Linter.RuleEntry<[ + { + /** + * @default true + */ + checkLoops: boolean; + } + ]>; + + /** + * Rule to disallow control characters in regular expressions. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.1.0 + * @see https://eslint.org/docs/rules/no-control-regex + */ + 'no-control-regex': Linter.RuleEntry<[]>; + + /** + * Rule to disallow the use of `debugger`. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.2 + * @see https://eslint.org/docs/rules/no-debugger + */ + 'no-debugger': Linter.RuleEntry<[]>; + + /** + * Rule to disallow duplicate arguments in `function` definitions. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.16.0 + * @see https://eslint.org/docs/rules/no-dupe-args + */ + 'no-dupe-args': Linter.RuleEntry<[]>; + + /** + * Rule to disallow duplicate keys in object literals. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-dupe-keys + */ + 'no-dupe-keys': Linter.RuleEntry<[]>; + + /** + * Rule to disallow a duplicate case label. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.17.0 + * @see https://eslint.org/docs/rules/no-duplicate-case + */ + 'no-duplicate-case': Linter.RuleEntry<[]>; + + /** + * Rule to disallow empty block statements. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.2 + * @see https://eslint.org/docs/rules/no-empty + */ + 'no-empty': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + allowEmptyCatch: boolean; + }> + ]>; + + /** + * Rule to disallow empty character classes in regular expressions. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.22.0 + * @see https://eslint.org/docs/rules/no-empty-character-class + */ + 'no-empty-character-class': Linter.RuleEntry<[]>; + + /** + * Rule to disallow reassigning exceptions in `catch` clauses. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-ex-assign + */ + 'no-ex-assign': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unnecessary boolean casts. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.4.0 + * @see https://eslint.org/docs/rules/no-extra-boolean-cast + */ + 'no-extra-boolean-cast': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unnecessary parentheses. + * + * @since 0.1.4 + * @see https://eslint.org/docs/rules/no-extra-parens + */ + 'no-extra-parens': Linter.RuleEntry<[ + 'all', + Partial<{ + /** + * @default true, + */ + conditionalAssign: boolean; + /** + * @default true + */ + returnAssign: boolean; + /** + * @default true + */ + nestedBinaryExpressions: boolean; + /** + * @default 'none' + */ + ignoreJSX: 'none' | 'all' | 'multi-line' | 'single-line'; + /** + * @default true + */ + enforceForArrowConditionals: boolean; + }> + ]> | Linter.RuleEntry<[ + 'functions' + ]>; + + /** + * Rule to disallow unnecessary semicolons. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-extra-semi + */ + 'no-extra-semi': Linter.RuleEntry<[]>; + + /** + * Rule to disallow reassigning `function` declarations. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-func-assign + */ + 'no-func-assign': Linter.RuleEntry<[]>; + + /** + * Rule to disallow variable or `function` declarations in nested blocks. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.6.0 + * @see https://eslint.org/docs/rules/no-inner-declarations + */ + 'no-inner-declarations': Linter.RuleEntry<[ + 'functions' | 'both' + ]>; + + /** + * Rule to disallow invalid regular expression strings in `RegExp` constructors. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.1.4 + * @see https://eslint.org/docs/rules/no-invalid-regexp + */ + 'no-invalid-regexp': Linter.RuleEntry<[ + Partial<{ + allowConstructorFlags: string[]; + }> + ]>; + + /** + * Rule to disallow irregular whitespace. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.9.0 + * @see https://eslint.org/docs/rules/no-irregular-whitespace + */ + 'no-irregular-whitespace': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + skipStrings: boolean; + /** + * @default false + */ + skipComments: boolean; + /** + * @default false + */ + skipRegExps: boolean; + /** + * @default false + */ + skipTemplates: boolean; + }> + ]>; + + /** + * Rule to disallow characters which are made with multiple code points in character class syntax. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 5.3.0 + * @see https://eslint.org/docs/rules/no-misleading-character-class + */ + 'no-misleading-character-class': Linter.RuleEntry<[]>; + + /** + * Rule to disallow calling global object properties as functions. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-obj-calls + */ + 'no-obj-calls': Linter.RuleEntry<[]>; + + /** + * Rule to disallow use of `Object.prototypes` builtins directly. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 2.11.0 + * @see https://eslint.org/docs/rules/no-prototype-builtins + */ + 'no-prototype-builtins': Linter.RuleEntry<[]>; + + /** + * Rule to disallow multiple spaces in regular expressions. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.4.0 + * @see https://eslint.org/docs/rules/no-regex-spaces + */ + 'no-regex-spaces': Linter.RuleEntry<[]>; + + /** + * Rule to disallow sparse arrays. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.4.0 + * @see https://eslint.org/docs/rules/no-sparse-arrays + */ + 'no-sparse-arrays': Linter.RuleEntry<[]>; + + /** + * Rule to disallow template literal placeholder syntax in regular strings. + * + * @since 3.3.0 + * @see https://eslint.org/docs/rules/no-template-curly-in-string + */ + 'no-template-curly-in-string': Linter.RuleEntry<[]>; + + /** + * Rule to disallow confusing multiline expressions. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.24.0 + * @see https://eslint.org/docs/rules/no-unexpected-multiline + */ + 'no-unexpected-multiline': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unreachable code after `return`, `throw`, `continue`, and `break` statements. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.6 + * @see https://eslint.org/docs/rules/no-unreachable + */ + 'no-unreachable': Linter.RuleEntry<[]>; + + /** + * Rule to disallow control flow statements in `finally` blocks. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 2.9.0 + * @see https://eslint.org/docs/rules/no-unsafe-finally + */ + 'no-unsafe-finally': Linter.RuleEntry<[]>; + + /** + * Rule to disallow negating the left operand of relational operators. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 3.3.0 + * @see https://eslint.org/docs/rules/no-unsafe-negation + */ + 'no-unsafe-negation': Linter.RuleEntry<[]>; + + /** + * Rule to disallow assignments that can lead to race conditions due to usage of `await` or `yield`. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 5.3.0 + * @see https://eslint.org/docs/rules/require-atomic-updates + */ + 'require-atomic-updates': Linter.RuleEntry<[]>; + + /** + * Rule to require calls to `isNaN()` when checking for `NaN`. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.6 + * @see https://eslint.org/docs/rules/use-isnan + */ + 'use-isnan': Linter.RuleEntry<[]>; + + /** + * Rule to enforce comparing `typeof` expressions against valid strings. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.5.0 + * @see https://eslint.org/docs/rules/valid-typeof + */ + 'valid-typeof': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + requireStringLiterals: boolean; + }> + ]>; +} diff --git a/types/eslint/ts3.1/rules/strict-mode.d.ts b/types/eslint/ts3.1/rules/strict-mode.d.ts new file mode 100644 index 0000000000..eec7b7d4f9 --- /dev/null +++ b/types/eslint/ts3.1/rules/strict-mode.d.ts @@ -0,0 +1,13 @@ +import { Linter } from '../index'; + +export interface StrictMode extends Linter.RulesRecord { + /** + * Rule to require or disallow strict mode directives. + * + * @since 0.1.0 + * @see https://eslint.org/docs/rules/strict + */ + 'strict': Linter.RuleEntry<[ + 'safe' | 'global' | 'function' | 'never' + ]>; +} diff --git a/types/eslint/ts3.1/rules/stylistic-issues.d.ts b/types/eslint/ts3.1/rules/stylistic-issues.d.ts new file mode 100644 index 0000000000..7c9848a0ef --- /dev/null +++ b/types/eslint/ts3.1/rules/stylistic-issues.d.ts @@ -0,0 +1,1739 @@ +import { Linter } from '../index'; + +export interface StylisticIssues extends Linter.RulesRecord { + /** + * Rule to enforce linebreaks after opening and before closing array brackets. + * + * @since 4.0.0-alpha.1 + * @see https://eslint.org/docs/rules/array-bracket-newline + */ + 'array-bracket-newline': Linter.RuleEntry<[ + 'always' | 'never' | 'consistent' | Partial<{ + /** + * @default true + */ + multiline: boolean; + /** + * @default null + */ + minItems: number | null; + }> + ]>; + + /** + * Rule to enforce consistent spacing inside array brackets. + * + * @since 0.24.0 + * @see https://eslint.org/docs/rules/array-bracket-spacing + */ + 'array-bracket-spacing': Linter.RuleEntry<[ + 'never', + Partial<{ + /** + * @default false + */ + singleValue: boolean; + /** + * @default false + */ + objectsInArrays: boolean; + /** + * @default false + */ + arraysInArrays: boolean; + }> + ]> | Linter.RuleEntry<[ + 'always', + Partial<{ + /** + * @default true + */ + singleValue: boolean; + /** + * @default true + */ + objectsInArrays: boolean; + /** + * @default true + */ + arraysInArrays: boolean; + }> + ]>; + + /** + * Rule to enforce line breaks after each array element. + * + * @since 4.0.0-rc.0 + * @see https://eslint.org/docs/rules/array-element-newline + */ + 'array-element-newline': Linter.RuleEntry<[ + 'always' | 'never' | 'consistent' | Partial<{ + /** + * @default true + */ + multiline: boolean; + /** + * @default null + */ + minItems: number | null; + }> + ]>; + + /** + * Rule to disallow or enforce spaces inside of blocks after opening block and before closing block. + * + * @since 1.2.0 + * @see https://eslint.org/docs/rules/block-spacing + */ + 'block-spacing': Linter.RuleEntry<[ + 'always' | 'never' + ]>; + + /** + * Rule to enforce consistent brace style for blocks. + * + * @since 0.0.7 + * @see https://eslint.org/docs/rules/brace-style + */ + 'brace-style': Linter.RuleEntry<[ + '1tbs' | 'stroustrup' | 'allman', + Partial<{ + /** + * @default false + */ + allowSingleLine: boolean; + }> + ]>; + + /** + * Rule to enforce camelcase naming convention. + * + * @since 0.0.2 + * @see https://eslint.org/docs/rules/camelcase + */ + 'camelcase': Linter.RuleEntry<[ + Partial<{ + /** + * @default 'always' + */ + properties: 'always' | 'never'; + /** + * @default false + */ + ignoreDestructuring: boolean; + /** + * @remarks + * Also accept for regular expression patterns + */ + allow: string[]; + }> + ]>; + + /** + * Rule to enforce or disallow capitalization of the first letter of a comment. + * + * @since 3.11.0 + * @see https://eslint.org/docs/rules/capitalized-comments + */ + 'capitalized-comments': Linter.RuleEntry<[ + 'always' | 'never', + Partial<{ + ignorePattern: string[]; + /** + * @default false + */ + ignoreInlineComments: boolean; + /** + * @default false + */ + ignoreConsecutiveComments: boolean; + }> + ]>; + + /** + * Rule to require or disallow trailing commas. + * + * @since 0.16.0 + * @see https://eslint.org/docs/rules/comma-dangle + */ + 'comma-dangle': Linter.RuleEntry<[ + 'never' | 'always' | 'always-multiline' | 'only-multiline' | Partial<{ + /** + * @default 'never' + */ + arrays: 'never' | 'always' | 'always-multiline' | 'only-multiline'; + /** + * @default 'never' + */ + objects: 'never' | 'always' | 'always-multiline' | 'only-multiline'; + /** + * @default 'never' + */ + imports: 'never' | 'always' | 'always-multiline' | 'only-multiline'; + /** + * @default 'never' + */ + exports: 'never' | 'always' | 'always-multiline' | 'only-multiline'; + /** + * @default 'never' + */ + functions: 'never' | 'always' | 'always-multiline' | 'only-multiline'; + }> + ]>; + + /** + * Rule to enforce consistent spacing before and after commas. + * + * @since 0.9.0 + * @see https://eslint.org/docs/rules/comma-spacing + */ + 'comma-spacing': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + before: boolean; + /** + * @default true + */ + after: boolean; + }> + ]>; + + /** + * Rule to enforce consistent comma style. + * + * @since 0.9.0 + * @see https://eslint.org/docs/rules/comma-style + */ + 'comma-style': Linter.RuleEntry<[ + 'last' | 'first', + Partial<{ + exceptions: Record; + }> + ]>; + + /** + * Rule to enforce consistent spacing inside computed property brackets. + * + * @since 0.23.0 + * @see https://eslint.org/docs/rules/computed-property-spacing + */ + 'computed-property-spacing': Linter.RuleEntry<[ + 'never' | 'always' + ]>; + + /** + * Rule to enforce consistent naming when capturing the current execution context. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/consistent-this + */ + 'consistent-this': Linter.RuleEntry<[ + ...string[] + ]>; + + /** + * Rule to require or disallow newline at the end of files. + * + * @since 0.7.1 + * @see https://eslint.org/docs/rules/eol-last + */ + 'eol-last': Linter.RuleEntry<[ + 'always' | 'never' // | 'unix' | 'windows' + ]>; + + /** + * Rule to require or disallow spacing between function identifiers and their invocations. + * + * @since 3.3.0 + * @see https://eslint.org/docs/rules/func-call-spacing + */ + 'func-call-spacing': Linter.RuleEntry<[ + 'never' | 'always' + ]>; + + /** + * Rule to require function names to match the name of the variable or property to which they are assigned. + * + * @since 3.8.0 + * @see https://eslint.org/docs/rules/func-name-matching + */ + 'func-name-matching': Linter.RuleEntry<[ + 'always' | 'never', + Partial<{ + /** + * @default false + */ + considerPropertyDescriptor: boolean; + /** + * @default false + */ + includeCommonJSModuleExports: boolean; + }> + ]> | Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + considerPropertyDescriptor: boolean; + /** + * @default false + */ + includeCommonJSModuleExports: boolean; + }> + ]>; + + /** + * Rule to require or disallow named `function` expressions. + * + * @since 0.4.0 + * @see https://eslint.org/docs/rules/func-names + */ + 'func-names': Linter.RuleEntry<[ + 'always' | 'as-needed' | 'never', + Partial<{ + generators: 'always' | 'as-needed' | 'never'; + }> + ]>; + + /** + * Rule to enforce the consistent use of either `function` declarations or expressions. + * + * @since 0.2.0 + * @see https://eslint.org/docs/rules/func-style + */ + 'func-style': Linter.RuleEntry<[ + 'expression' | 'declaration', + Partial<{ + /** + * @default false + */ + allowArrowFunctions: boolean; + }> + ]>; + + /** + * Rule to enforce consistent line breaks inside function parentheses. + * + * @since 4.6.0 + * @see https://eslint.org/docs/rules/function-paren-newline + */ + 'function-paren-newline': Linter.RuleEntry<[ + 'always' | 'never' | 'multiline' | 'multiline-arguments' | 'consistent' | Partial<{ + minItems: number; + }> + ]>; + + /** + * Rule to disallow specified identifiers. + * + * @since 2.0.0-beta.2 + * @see https://eslint.org/docs/rules/id-blacklist + */ + 'id-blacklist': Linter.RuleEntry<[ + ...string[] + ]>; + + /** + * Rule to enforce minimum and maximum identifier lengths. + * + * @since 1.0.0 + * @see https://eslint.org/docs/rules/id-length + */ + 'id-length': Linter.RuleEntry<[ + Partial<{ + /** + * @default 2 + */ + min: number; + /** + * @default Infinity + */ + max: number; + /** + * @default 'always' + */ + properties: 'always' | 'never'; + exceptions: string[]; + }> + ]>; + + /** + * Rule to require identifiers to match a specified regular expression. + * + * @since 1.0.0 + * @see https://eslint.org/docs/rules/id-match + */ + 'id-match': Linter.RuleEntry<[ + string, + Partial<{ + /** + * @default false + */ + properties: boolean; + /** + * @default false + */ + onlyDeclarations: boolean; + /** + * @default false + */ + ignoreDestructuring: boolean; + }> + ]>; + + /** + * Rule to enforce the location of arrow function bodies. + * + * @since 4.12.0 + * @see https://eslint.org/docs/rules/implicit-arrow-linebreak + */ + 'implicit-arrow-linebreak': Linter.RuleEntry<[ + 'beside' | 'below' + ]>; + + /** + * Rule to enforce consistent indentation. + * + * @since 0.14.0 + * @see https://eslint.org/docs/rules/indent + */ + 'indent': Linter.RuleEntry<[ + number | 'tab', + Partial<{ + /** + * @default 0 + */ + SwitchCase: number; + /** + * @default 1 + */ + VariableDeclarator: Partial<{ + /** + * @default 1 + */ + var: number | 'first'; + /** + * @default 1 + */ + let: number | 'first'; + /** + * @default 1 + */ + const: number | 'first'; + }> | number | 'first'; + /** + * @default 1 + */ + outerIIFEBody: number; + /** + * @default 1 + */ + MemberExpression: number | 'off'; + /** + * @default { parameters: 1, body: 1 } + */ + FunctionDeclaration: Partial<{ + /** + * @default 1 + */ + parameters: number | 'first' | 'off'; + /** + * @default 1 + */ + body: number; + }>; + /** + * @default { parameters: 1, body: 1 } + */ + FunctionExpression: Partial<{ + /** + * @default 1 + */ + parameters: number | 'first' | 'off'; + /** + * @default 1 + */ + body: number; + }>; + /** + * @default { arguments: 1 } + */ + CallExpression: Partial<{ + /** + * @default 1 + */ + arguments: number | 'first' | 'off'; + }>; + /** + * @default 1 + */ + ArrayExpression: number | 'first' | 'off'; + /** + * @default 1 + */ + ObjectExpression: number | 'first' | 'off'; + /** + * @default 1 + */ + ImportDeclaration: number | 'first' | 'off'; + /** + * @default false + */ + flatTernaryExpressions: boolean; + ignoredNodes: string[]; + /** + * @default false + */ + ignoreComments: boolean; + }> + ]>; + + /** + * Rule to enforce the consistent use of either double or single quotes in JSX attributes. + * + * @since 1.4.0 + * @see https://eslint.org/docs/rules/jsx-quotes + */ + 'jsx-quotes': Linter.RuleEntry<[ + 'prefer-double' | 'prefer-single' + ]>; + + /** + * Rule to enforce consistent spacing between keys and values in object literal properties. + * + * @since 0.9.0 + * @see https://eslint.org/docs/rules/key-spacing + */ + 'key-spacing': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + beforeColon: boolean; + /** + * @default true + */ + afterColon: boolean; + /** + * @default 'strict' + */ + mode: 'strict' | 'minimum'; + align: Partial<{ + /** + * @default false + */ + beforeColon: boolean; + /** + * @default true + */ + afterColon: boolean; + /** + * @default 'colon' + */ + on: 'value' | 'colon'; + /** + * @default 'strict' + */ + mode: 'strict' | 'minimum'; + }> | 'value' | 'colon'; + } | { + singleLine?: Partial<{ + /** + * @default false + */ + beforeColon: boolean; + /** + * @default true + */ + afterColon: boolean; + /** + * @default 'strict' + */ + mode: 'strict' | 'minimum'; + }>; + multiLine?: Partial<{ + /** + * @default false + */ + beforeColon: boolean; + /** + * @default true + */ + afterColon: boolean; + /** + * @default 'strict' + */ + mode: 'strict' | 'minimum'; + align: Partial<{ + /** + * @default false + */ + beforeColon: boolean; + /** + * @default true + */ + afterColon: boolean; + /** + * @default 'colon' + */ + on: 'value' | 'colon'; + /** + * @default 'strict' + */ + mode: 'strict' | 'minimum'; + }> | 'value' | 'colon'; + }>; + }> | { + align: Partial<{ + /** + * @default false + */ + beforeColon: boolean; + /** + * @default true + */ + afterColon: boolean; + /** + * @default 'colon' + */ + on: 'value' | 'colon'; + /** + * @default 'strict' + */ + mode: 'strict' | 'minimum'; + }>; + singleLine?: Partial<{ + /** + * @default false + */ + beforeColon: boolean; + /** + * @default true + */ + afterColon: boolean; + /** + * @default 'strict' + */ + mode: 'strict' | 'minimum'; + }>; + multiLine?: Partial<{ + /** + * @default false + */ + beforeColon: boolean; + /** + * @default true + */ + afterColon: boolean; + /** + * @default 'strict' + */ + mode: 'strict' | 'minimum'; + }>; + } + ]>; + + /** + * Rule to enforce consistent spacing before and after keywords. + * + * @since 2.0.0-beta.1 + * @see https://eslint.org/docs/rules/keyword-spacing + */ + 'keyword-spacing': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + before: boolean; + /** + * @default true + */ + after: boolean; + overrides: Record>; + }> + ]>; + + /** + * Rule to enforce position of line comments. + * + * @since 3.5.0 + * @see https://eslint.org/docs/rules/line-comment-position + */ + 'line-comment-position': Linter.RuleEntry<[ + Partial<{ + /** + * @default 'above' + */ + position: 'above' | 'beside'; + ignorePattern: string; + /** + * @default true + */ + applyDefaultIgnorePatterns: boolean; + }> + ]>; + + /** + * Rule to enforce consistent linebreak style. + * + * @since 0.21.0 + * @see https://eslint.org/docs/rules/linebreak-style + */ + 'linebreak-style': Linter.RuleEntry<[ + 'unix' | 'windows' + ]>; + + /** + * Rule to require empty lines around comments. + * + * @since 0.22.0 + * @see https://eslint.org/docs/rules/lines-around-comment + */ + 'lines-around-comment': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + beforeBlockComment: boolean; + /** + * @default false + */ + afterBlockComment: boolean; + /** + * @default false + */ + beforeLineComment: boolean; + /** + * @default false + */ + afterLineComment: boolean; + /** + * @default false + */ + allowBlockStart: boolean; + /** + * @default false + */ + allowBlockEnd: boolean; + /** + * @default false + */ + allowObjectStart: boolean; + /** + * @default false + */ + allowObjectEnd: boolean; + /** + * @default false + */ + allowArrayStart: boolean; + /** + * @default false + */ + allowArrayEnd: boolean; + /** + * @default false + */ + allowClassStart: boolean; + /** + * @default false + */ + allowClassEnd: boolean; + ignorePattern: string; + /** + * @default true + */ + applyDefaultIgnorePatterns: boolean; + }> + ]>; + + /** + * Rule to require or disallow an empty line between class members. + * + * @since 4.9.0 + * @see https://eslint.org/docs/rules/lines-between-class-members + */ + 'lines-between-class-members': Linter.RuleEntry<[ + 'always' | 'never', + Partial<{ + /** + * @default false + */ + exceptAfterSingleLine: boolean; + }> + ]>; + + /** + * Rule to enforce a maximum depth that blocks can be nested. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/max-depth + */ + 'max-depth': Linter.RuleEntry<[ + Partial<{ + /** + * @default 4 + */ + max: number; + }> + ]>; + + /** + * Rule to enforce a maximum line length. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/max-len + */ + 'max-len': Linter.RuleEntry<[ + Partial<{ + /** + * @default 80 + */ + code: number; + /** + * @default 4 + */ + tabWidth: number; + comments: number; + ignorePattern: string; + /** + * @default false + */ + ignoreComments: boolean; + /** + * @default false + */ + ignoreTrailingComments: boolean; + /** + * @default false + */ + ignoreUrls: boolean; + /** + * @default false + */ + ignoreStrings: boolean; + /** + * @default false + */ + ignoreTemplateLiterals: boolean; + /** + * @default false + */ + ignoreRegExpLiterals: boolean; + }> + ]>; + + /** + * Rule to enforce a maximum number of lines per file. + * + * @since 2.12.0 + * @see https://eslint.org/docs/rules/max-lines + */ + 'max-lines': Linter.RuleEntry<[ + Partial<{ + /** + * @default 300 + */ + max: number; + /** + * @default false + */ + skipBlankLines: boolean; + /** + * @default false + */ + skipComments: boolean; + }> | number + ]>; + + /** + * Rule to enforce a maximum number of line of code in a function. + * + * @since 5.0.0 + * @see https://eslint.org/docs/rules/max-lines-per-function + */ + 'max-lines-per-function': Linter.RuleEntry<[ + Partial<{ + /** + * @default 50 + */ + max: number; + /** + * @default false + */ + skipBlankLines: boolean; + /** + * @default false + */ + skipComments: boolean; + /** + * @default false + */ + IIFEs: boolean; + }> + ]>; + + /** + * Rule to enforce a maximum depth that callbacks can be nested. + * + * @since 0.2.0 + * @see https://eslint.org/docs/rules/max-nested-callbacks + */ + 'max-nested-callbacks': Linter.RuleEntry<[ + Partial<{ + /** + * @default 10 + */ + max: number; + }> | number + ]>; + + /** + * Rule to enforce a maximum number of parameters in function definitions. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/max-params + */ + 'max-params': Linter.RuleEntry<[ + Partial<{ + /** + * @default 3 + */ + max: number; + }> | number + ]>; + + /** + * Rule to enforce a maximum number of statements allowed in function blocks. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/max-statements + */ + 'max-statements': Linter.RuleEntry<[ + Partial<{ + /** + * @default 10 + */ + max: number; + /** + * @default false + */ + ignoreTopLevelFunctions: boolean; + }> | number + ]>; + + /** + * Rule to enforce a maximum number of statements allowed per line. + * + * @since 2.5.0 + * @see https://eslint.org/docs/rules/max-statements-per-line + */ + 'max-statements-per-line': Linter.RuleEntry<[ + Partial<{ + /** + * @default 1 + */ + max: number; + }> | number + ]>; + + /** + * Rule to enforce a particular style for multiline comments. + * + * @since 4.10.0 + * @see https://eslint.org/docs/rules/multiline-comment-style + */ + 'multiline-comment-style': Linter.RuleEntry<[ + 'starred-block' | 'bare-block' | 'separate-lines' + ]>; + + /** + * Rule to enforce newlines between operands of ternary expressions. + * + * @since 3.1.0 + * @see https://eslint.org/docs/rules/multiline-ternary + */ + 'multiline-ternary': Linter.RuleEntry<[ + 'always' | 'always-multiline' | 'never' + ]>; + + /** + * Rule to require constructor names to begin with a capital letter. + * + * @since 0.0.3-0 + * @see https://eslint.org/docs/rules/new-cap + */ + 'new-cap': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + newIsCap: boolean; + /** + * @default true + */ + capIsNew: boolean; + newIsCapExceptions: string[]; + newIsCapExceptionPattern: string; + capIsNewExceptions: string[]; + capIsNewExceptionPattern: string; + /** + * @default true + */ + properties: boolean; + }> + ]>; + + /** + * Rule to enforce or disallow parentheses when invoking a constructor with no arguments. + * + * @since 0.0.6 + * @see https://eslint.org/docs/rules/new-parens + */ + 'new-parens': Linter.RuleEntry<[ + 'always' | 'never' + ]>; + + /** + * Rule to require a newline after each call in a method chain. + * + * @since 2.0.0-rc.0 + * @see https://eslint.org/docs/rules/newline-per-chained-call + */ + 'newline-per-chained-call': Linter.RuleEntry<[ + { + /** + * @default 2 + */ + ignoreChainWithDepth: number; + } + ]>; + + /** + * Rule to disallow `Array` constructors. + * + * @since 0.4.0 + * @see https://eslint.org/docs/rules/no-array-constructor + */ + 'no-array-constructor': Linter.RuleEntry<[]>; + + /** + * Rule to disallow bitwise operators. + * + * @since 0.0.2 + * @see https://eslint.org/docs/rules/no-bitwise + */ + 'no-bitwise': Linter.RuleEntry<[ + Partial<{ + allow: string[]; + /** + * @default false + */ + int32Hint: boolean; + }> + ]>; + + /** + * Rule to disallow `continue` statements. + * + * @since 0.19.0 + * @see https://eslint.org/docs/rules/no-continue + */ + 'no-continue': Linter.RuleEntry<[]>; + + /** + * Rule to disallow inline comments after code. + * + * @since 0.10.0 + * @see https://eslint.org/docs/rules/no-inline-comments + */ + 'no-inline-comments': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `if` statements as the only statement in `else` blocks. + * + * @since 0.6.0 + * @see https://eslint.org/docs/rules/no-lonely-if + */ + 'no-lonely-if': Linter.RuleEntry<[]>; + + /** + * Rule to disallow mixed binary operators. + * + * @since 2.12.0 + * @see https://eslint.org/docs/rules/no-mixed-operators + */ + 'no-mixed-operators': Linter.RuleEntry<[ + Partial<{ + /** + * @default + * [ + * ["+", "-", "*", "/", "%", "**"], + * ["&", "|", "^", "~", "<<", ">>", ">>>"], + * ["==", "!=", "===", "!==", ">", ">=", "<", "<="], + * ["&&", "||"], + * ["in", "instanceof"] + * ] + */ + groups: string[][]; + /** + * @default true + */ + allowSamePrecedence: boolean; + }> + ]>; + + /** + * Rule to disallow mixed spaces and tabs for indentation. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.7.1 + * @see https://eslint.org/docs/rules/no-mixed-spaces-and-tabs + */ + 'no-mixed-spaces-and-tabs': Linter.RuleEntry<[ + 'smart-tabs' + ]>; + + /** + * Rule to disallow use of chained assignment expressions. + * + * @since 3.14.0 + * @see https://eslint.org/docs/rules/no-multi-assign + */ + 'no-multi-assign': Linter.RuleEntry<[]>; + + /** + * Rule to disallow multiple empty lines. + * + * @since 0.9.0 + * @see https://eslint.org/docs/rules/no-multiple-empty-lines + */ + 'no-multiple-empty-lines': Linter.RuleEntry<[ + Partial<{ + /** + * @default 2 + */ + max: number; + maxEOF: number; + maxBOF: number; + }> | number + ]>; + + /** + * Rule to disallow negated conditions. + * + * @since 1.6.0 + * @see https://eslint.org/docs/rules/no-negated-condition + */ + 'no-negated-condition': Linter.RuleEntry<[]>; + + /** + * Rule to disallow nested ternary expressions. + * + * @since 0.2.0 + * @see https://eslint.org/docs/rules/no-nested-ternary + */ + 'no-nested-ternary': Linter.RuleEntry<[]>; + + /** + * Rule to disallow `Object` constructors. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-new-object + */ + 'no-new-object': Linter.RuleEntry<[]>; + + /** + * Rule to disallow the unary operators `++` and `--`. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-plusplus + */ + 'no-plusplus': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + allowForLoopAfterthoughts: boolean; + }> + ]>; + + /** + * Rule to disallow specified syntax. + * + * @since 1.4.0 + * @see https://eslint.org/docs/rules/no-restricted-syntax + */ + 'no-restricted-syntax': Linter.RuleEntry<[ + ...Array + ]>; + + /** + * Rule to disallow all tabs. + * + * @since 3.2.0 + * @see https://eslint.org/docs/rules/no-tabs + */ + 'no-tabs': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + allowIndentationTabs: boolean; + }> + ]>; + + /** + * Rule to disallow ternary operators. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-ternary + */ + 'no-ternary': Linter.RuleEntry<[]>; + + /** + * Rule to disallow trailing whitespace at the end of lines. + * + * @since 0.7.1 + * @see https://eslint.org/docs/rules/no-trailing-spaces + */ + 'no-trailing-spaces': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + skipBlankLines: boolean; + /** + * @default false + */ + ignoreComments: boolean; + }> + ]>; + + /** + * Rule to disallow dangling underscores in identifiers. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-underscore-dangle + */ + 'no-underscore-dangle': Linter.RuleEntry<[ + Partial<{ + allow: string[]; + /** + * @default false + */ + allowAfterThis: boolean; + /** + * @default false + */ + allowAfterSuper: boolean; + /** + * @default false + */ + enforceInMethodNames: boolean; + }> + ]>; + + /** + * Rule to disallow ternary operators when simpler alternatives exist. + * + * @since 0.21.0 + * @see https://eslint.org/docs/rules/no-unneeded-ternary + */ + 'no-unneeded-ternary': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + defaultAssignment: boolean; + }> + ]>; + + /** + * Rule to disallow whitespace before properties. + * + * @since 2.0.0-beta.1 + * @see https://eslint.org/docs/rules/no-whitespace-before-property + */ + 'no-whitespace-before-property': Linter.RuleEntry<[]>; + + /** + * Rule to enforce the location of single-line statements. + * + * @since 3.17.0 + * @see https://eslint.org/docs/rules/nonblock-statement-body-position + */ + 'nonblock-statement-body-position': Linter.RuleEntry<[ + 'beside' | 'below' | 'any', + Partial<{ + overrides: Record; + }> + ]>; + + /** + * Rule to enforce consistent line breaks inside braces. + * + * @since 2.12.0 + * @see https://eslint.org/docs/rules/object-curly-newline + */ + 'object-curly-newline': Linter.RuleEntry<[ + | 'always' | 'never' + | Partial<{ + /** + * @default false + */ + multiline: boolean; + minProperties: number; + /** + * @default true + */ + consistent: boolean; + }> + | Partial>> + ]>; + + /** + * Rule to enforce consistent spacing inside braces. + * + * @since 0.22.0 + * @see https://eslint.org/docs/rules/object-curly-spacing + */ + 'object-curly-spacing': Linter.RuleEntry<[ + 'never', + { + /** + * @default false + */ + arraysInObjects: boolean; + /** + * @default false + */ + objectsInObjects: boolean; + } + ]> | Linter.RuleEntry<[ + 'always', + { + /** + * @default true + */ + arraysInObjects: boolean; + /** + * @default true + */ + objectsInObjects: boolean; + } + ]>; + + /** + * Rule to enforce placing object properties on separate lines. + * + * @since 2.10.0 + * @see https://eslint.org/docs/rules/object-property-newline + */ + 'object-property-newline': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + allowAllPropertiesOnSameLine: boolean; + }> + ]>; + + /** + * Rule to enforce variables to be declared either together or separately in functions. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/one-var + */ + 'one-var': Linter.RuleEntry<[ + | 'always' | 'never' | 'consecutive' + | Partial<{ + /** + * @default false + */ + separateRequires: boolean; + } & Record<'var' | 'let' | 'const', 'always' | 'never' | 'consecutive'>> + | Partial> + ]>; + + /** + * Rule to require or disallow newlines around variable declarations. + * + * @since 2.0.0-beta.3 + * @see https://eslint.org/docs/rules/one-var-declaration-per-line + */ + 'one-var-declaration-per-line': Linter.RuleEntry<[ + 'initializations' | 'always' + ]>; + + /** + * Rule to require or disallow assignment operator shorthand where possible. + * + * @since 0.10.0 + * @see https://eslint.org/docs/rules/operator-assignment + */ + 'operator-assignment': Linter.RuleEntry<[ + 'always' | 'never' + ]>; + + /** + * Rule to enforce consistent linebreak style for operators. + * + * @since 0.19.0 + * @see https://eslint.org/docs/rules/operator-linebreak + */ + 'operator-linebreak': Linter.RuleEntry<[ + 'after' | 'before' | 'none', + Partial<{ + overrides: Record; + }> + ]>; + + /** + * Rule to require or disallow padding within blocks. + * + * @since 0.9.0 + * @see https://eslint.org/docs/rules/padded-blocks + */ + 'padded-blocks': Linter.RuleEntry<[ + | 'always' | 'never' + | Partial>, + { + /** + * @default false + */ + allowSingleLineBlocks: boolean; + } + ]>; + + /** + * Rule to require or disallow padding lines between statements. + * + * @since 4.0.0-beta.0 + * @see https://eslint.org/docs/rules/padding-line-between-statements + */ + 'padding-line-between-statements': Linter.RuleEntry<[ + ...Array<{ + blankLine: 'any' | 'never' | 'always'; + } & Record<'prev' | 'next', string | string[]>> + ]>; + + /** + * Rule to disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead. + * + * @since 5.0.0-alpha.3 + * @see https://eslint.org/docs/rules/prefer-object-spread + */ + 'prefer-object-spread': Linter.RuleEntry<[]>; + + /** + * Rule to require quotes around object literal property names. + * + * @since 0.0.6 + * @see https://eslint.org/docs/rules/quote-props + */ + 'quote-props': Linter.RuleEntry<[ + 'always' | 'consistent' + ]> | Linter.RuleEntry<[ + 'as-needed', + Partial<{ + /** + * @default false + */ + keywords: boolean; + /** + * @default true + */ + unnecessary: boolean; + /** + * @default false + */ + numbers: boolean; + }> + ]> | Linter.RuleEntry<[ + 'consistent-as-needed', + Partial<{ + /** + * @default false + */ + keywords: boolean; + }> + ]>; + + /** + * Rule to enforce the consistent use of either backticks, double, or single quotes. + * + * @since 0.0.7 + * @see https://eslint.org/docs/rules/quotes + */ + 'quotes': Linter.RuleEntry<[ + 'double' | 'single' | 'backtick', + Partial<{ + /** + * @default false + */ + avoidEscape: boolean; + /** + * @default false + */ + allowTemplateLiterals: boolean; + }> + ]>; + + /** + * Rule to require or disallow semicolons instead of ASI. + * + * @since 0.0.6 + * @see https://eslint.org/docs/rules/semi + */ + 'semi': Linter.RuleEntry<[ + 'always', + Partial<{ + /** + * @default false + */ + omitLastInOneLineBlock: boolean; + }> + ]> | Linter.RuleEntry<[ + 'never', + Partial<{ + /** + * @default 'any' + */ + beforeStatementContinuationChars: 'any' | 'always' | 'never'; + }> + ]>; + + /** + * Rule to enforce consistent spacing before and after semicolons. + * + * @since 0.16.0 + * @see https://eslint.org/docs/rules/semi-spacing + */ + 'semi-spacing': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + before: boolean; + /** + * @default true + */ + after: boolean; + }> + ]>; + + /** + * Rule to enforce location of semicolons. + * + * @since 4.0.0-beta.0 + * @see https://eslint.org/docs/rules/semi-style + */ + 'semi-style': Linter.RuleEntry<[ + 'last' | 'first' + ]>; + + /** + * Rule to require object keys to be sorted. + * + * @since 3.3.0 + * @see https://eslint.org/docs/rules/sort-keys + */ + 'sort-keys': Linter.RuleEntry<[ + 'asc' | 'desc', + Partial<{ + /** + * @default true + */ + caseSensitive: boolean; + /** + * @default 2 + */ + minKeys: number; + /** + * @default false + */ + natural: boolean; + }> + ]>; + + /** + * Rule to require variables within the same declaration block to be sorted. + * + * @since 0.2.0 + * @see https://eslint.org/docs/rules/sort-vars + */ + 'sort-vars': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + ignoreCase: boolean; + }> + ]>; + + /** + * Rule to enforce consistent spacing before blocks. + * + * @since 0.9.0 + * @see https://eslint.org/docs/rules/space-before-blocks + */ + 'space-before-blocks': Linter.RuleEntry<[ + | 'always' | 'never' + | Partial> + ]>; + + /** + * Rule to enforce consistent spacing before `function` definition opening parenthesis. + * + * @since 0.18.0 + * @see https://eslint.org/docs/rules/space-before-function-paren + */ + 'space-before-function-paren': Linter.RuleEntry<[ + | 'always' | 'never' + | Partial> + ]>; + + /** + * Rule to enforce consistent spacing inside parentheses. + * + * @since 0.8.0 + * @see https://eslint.org/docs/rules/space-in-parens + */ + 'space-in-parens': Linter.RuleEntry<[ + 'never' | 'always', + Partial<{ + exceptions: string[]; + }> + ]>; + + /** + * Rule to require spacing around infix operators. + * + * @since 0.2.0 + * @see https://eslint.org/docs/rules/space-infix-ops + */ + 'space-infix-ops': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + int32Hint: boolean; + }> + ]>; + + /** + * Rule to enforce consistent spacing before or after unary operators. + * + * @since 0.10.0 + * @see https://eslint.org/docs/rules/space-unary-ops + */ + 'space-unary-ops': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + words: boolean; + /** + * @default false + */ + nonwords: boolean; + overrides: Record; + }> + ]>; + + /** + * Rule to enforce consistent spacing after the `//` or `/*` in a comment. + * + * @since 0.23.0 + * @see https://eslint.org/docs/rules/spaced-comment + */ + 'spaced-comment': Linter.RuleEntry<[ + 'always' | 'never', + { + exceptions: string[]; + markers: string[]; + line: { + exceptions: string[]; + markers: string[]; + }; + block: { + exceptions: string[]; + markers: string[]; + /** + * @default false + */ + balanced: boolean; + }; + } + ]>; + + /** + * Rule to enforce spacing around colons of switch statements. + * + * @since 4.0.0-beta.0 + * @see https://eslint.org/docs/rules/switch-colon-spacing + */ + 'switch-colon-spacing': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + before: boolean; + /** + * @default true + */ + after: boolean; + }> + ]>; + + /** + * Rule to require or disallow spacing between template tags and their literals. + * + * @since 3.15.0 + * @see https://eslint.org/docs/rules/template-tag-spacing + */ + 'template-tag-spacing': Linter.RuleEntry<[ + 'never' | 'always' + ]>; + + /** + * Rule to require or disallow Unicode byte order mark (BOM). + * + * @since 2.11.0 + * @see https://eslint.org/docs/rules/unicode-bom + */ + 'unicode-bom': Linter.RuleEntry<[ + 'never' | 'always' + ]>; + + /** + * Rule to require parenthesis around regex literals. + * + * @since 0.1.0 + * @see https://eslint.org/docs/rules/wrap-regex + */ + 'wrap-regex': Linter.RuleEntry<[]>; +} diff --git a/types/eslint/ts3.1/rules/variables.d.ts b/types/eslint/ts3.1/rules/variables.d.ts new file mode 100644 index 0000000000..795801fa29 --- /dev/null +++ b/types/eslint/ts3.1/rules/variables.d.ts @@ -0,0 +1,171 @@ +import { Linter } from '../index'; + +export interface Variables extends Linter.RulesRecord { + /** + * Rule to require or disallow initialization in variable declarations. + * + * @since 1.0.0-rc-1 + * @see https://eslint.org/docs/rules/init-declarations + */ + 'init-declarations': Linter.RuleEntry<[ + 'always' + ]> | Linter.RuleEntry<[ + 'never', + Partial<{ + ignoreForLoopInit: boolean; + }> + ]>; + + /** + * Rule to disallow deleting variables. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-delete-var + */ + 'no-delete-var': Linter.RuleEntry<[]>; + + /** + * Rule to disallow labels that share a name with a variable. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-label-var + */ + 'no-label-var': Linter.RuleEntry<[]>; + + /** + * Rule to disallow specified global variables. + * + * @since 2.3.0 + * @see https://eslint.org/docs/rules/no-restricted-globals + */ + 'no-restricted-globals': Linter.RuleEntry<[ + ...Array + ]>; + + /** + * Rule to disallow variable declarations from shadowing variables declared in the outer scope. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-shadow + */ + 'no-shadow': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + builtinGlobals: boolean; + /** + * @default 'functions' + */ + hoist: 'functions' | 'all' | 'never'; + allow: string[]; + }> + ]>; + + /** + * Rule to disallow identifiers from shadowing restricted names. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.1.4 + * @see https://eslint.org/docs/rules/no-shadow-restricted-names + */ + 'no-shadow-restricted-names': Linter.RuleEntry<[]>; + + /** + * Rule to disallow the use of undeclared variables unless mentioned in `global` comments. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-undef + */ + 'no-undef': Linter.RuleEntry<[ + Partial<{ + /** + * @default false + */ + typeof: boolean; + }> + ]>; + + /** + * Rule to disallow initializing variables to `undefined`. + * + * @since 0.0.6 + * @see https://eslint.org/docs/rules/no-undef-init + */ + 'no-undef-init': Linter.RuleEntry<[]>; + + /** + * Rule to disallow the use of `undefined` as an identifier. + * + * @since 0.7.1 + * @see https://eslint.org/docs/rules/no-undefined + */ + 'no-undefined': Linter.RuleEntry<[]>; + + /** + * Rule to disallow unused variables. + * + * @remarks + * Recommended by ESLint, the rule was enabled in `eslint:recommended`. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-unused-vars + */ + 'no-unused-vars': Linter.RuleEntry<[ + Partial<{ + /** + * @default 'all' + */ + vars: 'all' | 'local'; + varsIgnorePattern: string; + /** + * @default 'after-used' + */ + args: 'after-used' | 'all' | 'none'; + /** + * @default false + */ + ignoreRestSiblings: boolean; + argsIgnorePattern: string; + /** + * @default 'none' + */ + caughtErrors: 'none' | 'all'; + caughtErrorsIgnorePattern: string; + }> + ]>; + + /** + * Rule to disallow the use of variables before they are defined. + * + * @since 0.0.9 + * @see https://eslint.org/docs/rules/no-use-before-define + */ + 'no-use-before-define': Linter.RuleEntry<[ + Partial<{ + /** + * @default true + */ + functions: boolean; + /** + * @default true + */ + classes: boolean; + /** + * @default true + */ + variables: boolean; + }> | 'nofunc' + ]>; +} diff --git a/types/eslint/ts3.1/tsconfig.json b/types/eslint/ts3.1/tsconfig.json new file mode 100644 index 0000000000..2168a3832c --- /dev/null +++ b/types/eslint/ts3.1/tsconfig.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "dom", + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../../", + "typeRoots": [ + "../../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "rules/index.d.ts", + "rules/best-practices.d.ts", + "rules/deprecated.d.ts", + "rules/ecmascript-6.d.ts", + "rules/node-commonjs.d.ts", + "rules/possible-errors.d.ts", + "rules/strict-mode.d.ts", + "rules/stylistic-issues.d.ts", + "rules/variables.d.ts", + "eslint-tests.ts" + ] +} \ No newline at end of file diff --git a/types/eslint/ts3.1/tslint.json b/types/eslint/ts3.1/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/eslint/ts3.1/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }