diff --git a/cmd/rslint/api.go b/cmd/rslint/api.go index 238b944f..28ad1315 100644 --- a/cmd/rslint/api.go +++ b/cmd/rslint/api.go @@ -18,6 +18,7 @@ import ( rslintconfig "github.com/typescript-eslint/rslint/internal/config" "github.com/typescript-eslint/rslint/internal/linter" "github.com/typescript-eslint/rslint/internal/rule" + "github.com/typescript-eslint/rslint/internal/rules/adjacent_overload_signatures" "github.com/typescript-eslint/rslint/internal/rules/await_thenable" "github.com/typescript-eslint/rslint/internal/rules/no_array_delete" "github.com/typescript-eslint/rslint/internal/rules/no_base_to_string" @@ -98,6 +99,7 @@ func (h *IPCHandler) HandleLint(req ipc.LintRequest) (*ipc.LintResponse, error) // Create rules var rules = []rule.Rule{ + adjacent_overload_signatures.AdjacentOverloadSignaturesRule, await_thenable.AwaitThenableRule, no_array_delete.NoArrayDeleteRule, no_base_to_string.NoBaseToStringRule, diff --git a/internal/config/config.go b/internal/config/config.go index ec57e2c0..342458ee 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -2,6 +2,7 @@ package config import ( "github.com/typescript-eslint/rslint/internal/rule" + "github.com/typescript-eslint/rslint/internal/rules/adjacent_overload_signatures" "github.com/typescript-eslint/rslint/internal/rules/await_thenable" "github.com/typescript-eslint/rslint/internal/rules/no_array_delete" "github.com/typescript-eslint/rslint/internal/rules/no_base_to_string" @@ -214,6 +215,8 @@ func (config RslintConfig) GetRulesForFile(filePath string) map[string]*RuleConf // RegisterAllTypeSriptEslintPluginRules registers all available rules in the global registry func RegisterAllTypeSriptEslintPluginRules() { + GlobalRuleRegistry.Register("@typescript-eslint/adjacent-overload-signatures", adjacent_overload_signatures.AdjacentOverloadSignaturesRule) + GlobalRuleRegistry.Register("adjacent-overload-signatures", adjacent_overload_signatures.AdjacentOverloadSignaturesRule) GlobalRuleRegistry.Register("@typescript-eslint/await-thenable", await_thenable.AwaitThenableRule) GlobalRuleRegistry.Register("@typescript-eslint/no-array-delete", no_array_delete.NoArrayDeleteRule) GlobalRuleRegistry.Register("@typescript-eslint/no-base-to-string", no_base_to_string.NoBaseToStringRule) diff --git a/internal/rules/adjacent_overload_signatures/adjacent_overload_signatures.go b/internal/rules/adjacent_overload_signatures/adjacent_overload_signatures.go new file mode 100644 index 00000000..b452d035 --- /dev/null +++ b/internal/rules/adjacent_overload_signatures/adjacent_overload_signatures.go @@ -0,0 +1,211 @@ +package adjacent_overload_signatures + +import ( + "fmt" + + "github.com/microsoft/typescript-go/shim/ast" + "github.com/typescript-eslint/rslint/internal/rule" + "github.com/typescript-eslint/rslint/internal/utils" +) + +func buildAdjacentSignatureMessage() rule.RuleMessage { + return rule.RuleMessage{ + Id: "adjacentSignature", + Description: "All {{name}} signatures should be adjacent.", + } +} + +type Method struct { + CallSignature bool + Name string + Static bool + NameType utils.MemberNameType +} + +// getMemberMethod gets the name and attribute of the member being processed. +// Returns the name and attribute of the member or nil if it's a member not relevant to the rule. +func getMemberMethod(ctx rule.RuleContext, member *ast.Node) *Method { + if member == nil { + return nil + } + + switch member.Kind { + case ast.KindExportDeclaration: + // Export declarations (e.g., export { foo }) are not relevant for this rule + // They don't declare new functions/methods, just re-export existing ones + return nil + + case ast.KindFunctionDeclaration: + funcDecl := member.AsFunctionDeclaration() + if funcDecl.Name() == nil { + return nil + } + name := funcDecl.Name().Text() + return &Method{ + Name: name, + NameType: utils.MemberNameTypeNormal, + CallSignature: false, + Static: false, + } + + case ast.KindMethodDeclaration: + methodDecl := member.AsMethodDeclaration() + name, nameType := utils.GetNameFromMember(ctx.SourceFile, methodDecl.Name()) + return &Method{ + Name: name, + NameType: nameType, + CallSignature: false, + Static: ast.IsStatic(member), + } + + case ast.KindMethodSignature: + methodSig := member.AsMethodSignatureDeclaration() + name, nameType := utils.GetNameFromMember(ctx.SourceFile, methodSig.Name()) + return &Method{ + Name: name, + NameType: nameType, + CallSignature: false, + Static: false, + } + + case ast.KindCallSignature: + return &Method{ + Name: "call", + NameType: utils.MemberNameTypeNormal, + CallSignature: true, + Static: false, + } + + case ast.KindConstructSignature: + return &Method{ + Name: "new", + NameType: utils.MemberNameTypeNormal, + CallSignature: false, + Static: false, + } + + case ast.KindConstructor: + return &Method{ + Name: "constructor", + NameType: utils.MemberNameTypeNormal, + CallSignature: false, + Static: false, + } + } + + return nil +} + +func hasStaticModifier(modifiers []ast.ModifierLike) bool { + for _, modifier := range modifiers { + if modifier.Kind == ast.KindStaticKeyword { + return true + } + } + return false +} + +func isSameMethod(method1 *Method, method2 *Method) bool { + if method2 == nil { + return false + } + return method1.Name == method2.Name && + method1.Static == method2.Static && + method1.CallSignature == method2.CallSignature && + method1.NameType == method2.NameType +} + +func getMembers(node *ast.Node) []*ast.Node { + switch node.Kind { + case ast.KindClassDeclaration: + classDecl := node.AsClassDeclaration() + return classDecl.Members.Nodes + case ast.KindSourceFile: + sourceFile := node.AsSourceFile() + return sourceFile.Statements.Nodes + case ast.KindModuleBlock: + moduleBlock := node.AsModuleBlock() + return moduleBlock.Statements.Nodes + case ast.KindInterfaceDeclaration: + interfaceDecl := node.AsInterfaceDeclaration() + return interfaceDecl.Members.Nodes + case ast.KindBlock: + block := node.AsBlock() + return block.Statements.Nodes + case ast.KindTypeLiteral: + typeLiteral := node.AsTypeLiteralNode() + return typeLiteral.Members.Nodes + } + return nil +} + +func checkBodyForOverloadMethods(ctx rule.RuleContext, node *ast.Node) { + members := getMembers(node) + if members == nil { + return + } + + // Keep track of the last method we saw for each name + // When we see a method again, check if it was the immediately previous member + methodLastSeenIndex := make(map[string]int) + var lastMethodKey string + lastMethodIdx := -1 + + for memberIdx, member := range members { + method := getMemberMethod(ctx, member) + if method == nil { + // This member is not a method/function + continue + } + + // Create a key for this method (includes name, static, callSignature, nameType) + key := fmt.Sprintf("%s:%t:%t:%d", method.Name, method.Static, method.CallSignature, method.NameType) + + if _, seen := methodLastSeenIndex[key]; seen { + // We've seen this method before + // Check if the previous occurrence was the last method we saw + if lastMethodKey != key || lastMethodIdx != memberIdx-1 { + // There was something between the last occurrence and this one + staticPrefix := "" + if method.Static { + staticPrefix = "static " + } + ctx.ReportNode(member, rule.RuleMessage{ + Id: "adjacentSignature", + Description: fmt.Sprintf("All %s%s signatures should be adjacent.", staticPrefix, method.Name), + }) + } + } + + // Update the last seen index for this method + methodLastSeenIndex[key] = memberIdx + lastMethodKey = key + lastMethodIdx = memberIdx + } +} + +var AdjacentOverloadSignaturesRule = rule.Rule{ + Name: "adjacent-overload-signatures", + Run: func(ctx rule.RuleContext, options any) rule.RuleListeners { + // Check the source file at the beginning + checkBodyForOverloadMethods(ctx, &ctx.SourceFile.NodeBase.Node) + + return rule.RuleListeners{ + ast.KindBlock: func(node *ast.Node) { + checkBodyForOverloadMethods(ctx, node) + }, + ast.KindClassDeclaration: func(node *ast.Node) { + checkBodyForOverloadMethods(ctx, node) + }, + ast.KindInterfaceDeclaration: func(node *ast.Node) { + checkBodyForOverloadMethods(ctx, node) + }, + ast.KindModuleBlock: func(node *ast.Node) { + checkBodyForOverloadMethods(ctx, node) + }, + ast.KindTypeLiteral: func(node *ast.Node) { + checkBodyForOverloadMethods(ctx, node) + }, + } + }, +} diff --git a/internal/rules/adjacent_overload_signatures/adjacent_overload_signatures_test.go b/internal/rules/adjacent_overload_signatures/adjacent_overload_signatures_test.go new file mode 100644 index 00000000..c30c3036 --- /dev/null +++ b/internal/rules/adjacent_overload_signatures/adjacent_overload_signatures_test.go @@ -0,0 +1,884 @@ +package adjacent_overload_signatures + +import ( + "testing" + + "github.com/typescript-eslint/rslint/internal/rule_tester" + "github.com/typescript-eslint/rslint/internal/rules/fixtures" +) + +func TestAdjacentOverloadSignaturesRule(t *testing.T) { + rule_tester.RunRuleTester(fixtures.GetRootDir(), "tsconfig.json", t, &AdjacentOverloadSignaturesRule, []rule_tester.ValidTestCase{ + {Code: ` +function error(a: string); +function error(b: number); +function error(ab: string | number) {} +export { error }; + `}, + {Code: ` +import { connect } from 'react-redux'; +export interface ErrorMessageModel { + message: string; +} +function mapStateToProps() {} +function mapDispatchToProps() {} +export default connect(mapStateToProps, mapDispatchToProps)(ErrorMessage); + `}, + {Code: ` +export const foo = 'a', + bar = 'b'; +export interface Foo {} +export class Foo {} + `}, + {Code: ` +export interface Foo {} +export const foo = 'a', + bar = 'b'; +export class Foo {} + `}, + {Code: ` +const foo = 'a', + bar = 'b'; +interface Foo {} +class Foo {} + `}, + {Code: ` +interface Foo {} +const foo = 'a', + bar = 'b'; +class Foo {} + `}, + {Code: ` +export class Foo {} +export class Bar {} +export type FooBar = Foo | Bar; + `}, + {Code: ` +export interface Foo {} +export class Foo {} +export class Bar {} +export type FooBar = Foo | Bar; + `}, + {Code: ` +export function foo(s: string); +export function foo(n: number); +export function foo(sn: string | number) {} +export function bar(): void {} +export function baz(): void {} + `}, + {Code: ` +function foo(s: string); +function foo(n: number); +function foo(sn: string | number) {} +function bar(): void {} +function baz(): void {} + `}, + {Code: ` +declare function foo(s: string); +declare function foo(n: number); +declare function foo(sn: string | number); +declare function bar(): void; +declare function baz(): void; + `}, + {Code: ` +declare module 'Foo' { + export function foo(s: string): void; + export function foo(n: number): void; + export function foo(sn: string | number): void; + export function bar(): void; + export function baz(): void; +} + `}, + {Code: ` +declare namespace Foo { + export function foo(s: string): void; + export function foo(n: number): void; + export function foo(sn: string | number): void; + export function bar(): void; + export function baz(): void; +} + `}, + {Code: ` +type Foo = { + foo(s: string): void; + foo(n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +}; + `}, + {Code: ` +type Foo = { + foo(s: string): void; + ['foo'](n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +}; + `}, + {Code: ` +interface Foo { + (s: string): void; + (n: number): void; + (sn: string | number): void; + foo(n: number): void; + bar(): void; + baz(): void; +} + `}, + {Code: ` +interface Foo { + (s: string): void; + (n: number): void; + (sn: string | number): void; + foo(n: number): void; + bar(): void; + baz(): void; + call(): void; +} + `}, + {Code: ` +interface Foo { + foo(s: string): void; + foo(n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +} + `}, + {Code: ` +interface Foo { + foo(s: string): void; + ['foo'](n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +} + `}, + {Code: ` +interface Foo { + foo(): void; + bar: { + baz(s: string): void; + baz(n: number): void; + baz(sn: string | number): void; + }; +} + `}, + {Code: ` +interface Foo { + new (s: string); + new (n: number); + new (sn: string | number); + foo(): void; +} + `}, + {Code: ` +class Foo { + constructor(s: string); + constructor(n: number); + constructor(sn: string | number) {} + bar(): void {} + baz(): void {} +} + `}, + {Code: ` +class Foo { + foo(s: string): void; + foo(n: number): void; + foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `}, + {Code: ` +class Foo { + foo(s: string): void; + ['foo'](n: number): void; + foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `}, + {Code: ` +class Foo { + name: string; + foo(s: string): void; + foo(n: number): void; + foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `}, + {Code: ` +class Foo { + name: string; + static foo(s: string): void; + static foo(n: number): void; + static foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `}, + {Code: ` +class Test { + static test() {} + untest() {} + test() {} +} + `}, + {Code: `export default function (foo: T) {}`}, + {Code: `export default function named(foo: T) {}`}, + {Code: ` +interface Foo { + [Symbol.toStringTag](): void; + [Symbol.iterator](): void; +} + `}, + {Code: ` +class Test { + #private(): void; + #private(arg: number): void {} + + bar() {} + + '#private'(): void; + '#private'(arg: number): void {} +} + `}, + {Code: ` +function wrap() { + function foo(s: string); + function foo(n: number); + function foo(sn: string | number) {} +} + `}, + {Code: ` +if (true) { + function foo(s: string); + function foo(n: number); + function foo(sn: string | number) {} +} + `}, + }, []rule_tester.InvalidTestCase{ + { + Code: ` +function wrap() { + function foo(s: string); + function foo(n: number); + type bar = number; + function foo(sn: string | number) {} +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 6, + Column: 3, + }, + }, + }, + { + Code: ` +if (true) { + function foo(s: string); + function foo(n: number); + let a = 1; + function foo(sn: string | number) {} + foo(a); +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 6, + Column: 3, + }, + }, + }, + { + Code: ` +export function foo(s: string); +export function foo(n: number); +export function bar(): void {} +export function baz(): void {} +export function foo(sn: string | number) {} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 6, + Column: 1, + }, + }, + }, + { + Code: ` +export function foo(s: string); +export function foo(n: number); +export type bar = number; +export type baz = number | string; +export function foo(sn: string | number) {} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 6, + Column: 1, + }, + }, + }, + { + Code: ` +function foo(s: string); +function foo(n: number); +function bar(): void {} +function baz(): void {} +function foo(sn: string | number) {} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 6, + Column: 1, + }, + }, + }, + { + Code: ` +function foo(s: string); +function foo(n: number); +type bar = number; +type baz = number | string; +function foo(sn: string | number) {} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 6, + Column: 1, + }, + }, + }, + { + Code: ` +function foo(s: string) {} +function foo(n: number) {} +const a = ''; +const b = ''; +function foo(sn: string | number) {} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 6, + Column: 1, + }, + }, + }, + { + Code: ` +function foo(s: string) {} +function foo(n: number) {} +class Bar {} +function foo(sn: string | number) {} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 5, + Column: 1, + }, + }, + }, + { + Code: ` +function foo(s: string) {} +function foo(n: number) {} +function foo(sn: string | number) {} +class Bar { + foo(s: string); + foo(n: number); + name: string; + foo(sn: string | number) {} +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 9, + Column: 3, + }, + }, + }, + { + Code: ` +declare function foo(s: string); +declare function foo(n: number); +declare function bar(): void; +declare function baz(): void; +declare function foo(sn: string | number); + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 6, + Column: 1, + }, + }, + }, + { + Code: ` +declare function foo(s: string); +declare function foo(n: number); +const a = ''; +const b = ''; +declare function foo(sn: string | number); + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 6, + Column: 1, + }, + }, + }, + { + Code: ` +declare module 'Foo' { + export function foo(s: string): void; + export function foo(n: number): void; + export function bar(): void; + export function baz(): void; + export function foo(sn: string | number): void; +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +declare module 'Foo' { + export function foo(s: string): void; + export function foo(n: number): void; + export function foo(sn: string | number): void; + function baz(s: string): void; + export function bar(): void; + function baz(n: number): void; + function baz(sn: string | number): void; +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 8, + Column: 3, + }, + }, + }, + { + Code: ` +declare namespace Foo { + export function foo(s: string): void; + export function foo(n: number): void; + export function bar(): void; + export function baz(): void; + export function foo(sn: string | number): void; +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +declare namespace Foo { + export function foo(s: string): void; + export function foo(n: number): void; + export function foo(sn: string | number): void; + function baz(s: string): void; + export function bar(): void; + function baz(n: number): void; + function baz(sn: string | number): void; +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 8, + Column: 3, + }, + }, + }, + { + Code: ` +type Foo = { + foo(s: string): void; + foo(n: number): void; + bar(): void; + baz(): void; + foo(sn: string | number): void; +}; + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +type Foo = { + foo(s: string): void; + ['foo'](n: number): void; + bar(): void; + baz(): void; + foo(sn: string | number): void; +}; + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +type Foo = { + foo(s: string): void; + name: string; + foo(n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +}; + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 5, + Column: 3, + }, + }, + }, + { + Code: ` +interface Foo { + (s: string): void; + foo(n: number): void; + (n: number): void; + (sn: string | number): void; + bar(): void; + baz(): void; + call(): void; +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 5, + Column: 3, + }, + }, + }, + { + Code: ` +interface Foo { + foo(s: string): void; + foo(n: number): void; + bar(): void; + baz(): void; + foo(sn: string | number): void; +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +interface Foo { + foo(s: string): void; + ['foo'](n: number): void; + bar(): void; + baz(): void; + foo(sn: string | number): void; +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +interface Foo { + foo(s: string): void; + 'foo'(n: number): void; + bar(): void; + baz(): void; + foo(sn: string | number): void; +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +interface Foo { + foo(s: string): void; + name: string; + foo(n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 5, + Column: 3, + }, + }, + }, + { + Code: ` +interface Foo { + foo(): void; + bar: { + baz(s: string): void; + baz(n: number): void; + foo(): void; + baz(sn: string | number): void; + }; +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 8, + Column: 5, + }, + }, + }, + { + Code: ` +interface Foo { + new (s: string); + new (n: number); + foo(): void; + bar(): void; + new (sn: string | number); +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +interface Foo { + new (s: string); + foo(): void; + new (n: number); + bar(): void; + new (sn: string | number); +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 5, + Column: 3, + }, + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +class Foo { + constructor(s: string); + constructor(n: number); + bar(): void {} + baz(): void {} + constructor(sn: string | number) {} +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +class Foo { + foo(s: string): void; + foo(n: number): void; + bar(): void {} + baz(): void {} + foo(sn: string | number): void {} +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +class Foo { + foo(s: string): void; + ['foo'](n: number): void; + bar(): void {} + baz(): void {} + foo(sn: string | number): void {} +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 7, + Column: 3, + }, + }, + }, + { + Code: ` +class Foo { + // prettier-ignore + "foo"(s: string): void; + foo(n: number): void; + bar(): void {} + baz(): void {} + foo(sn: string | number): void {} +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 8, + Column: 3, + }, + }, + }, + { + Code: ` +class Foo { + constructor(s: string); + name: string; + constructor(n: number); + constructor(sn: string | number) {} + bar(): void {} + baz(): void {} +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 5, + Column: 3, + }, + }, + }, + { + Code: ` +class Foo { + foo(s: string): void; + name: string; + foo(n: number): void; + foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 5, + Column: 3, + }, + }, + }, + { + Code: ` +class Foo { + static foo(s: string): void; + name: string; + static foo(n: number): void; + static foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 5, + Column: 3, + }, + }, + }, + { + Code: ` +class Test { + #private(): void; + '#private'(): void; + #private(arg: number): void {} + '#private'(arg: number): void {} +} + `, + Errors: []rule_tester.InvalidTestCaseError{ + { + MessageId: "adjacentSignature", + Line: 5, + Column: 3, + }, + { + MessageId: "adjacentSignature", + Line: 6, + Column: 3, + }, + }, + }, + }) +} \ No newline at end of file diff --git a/packages/rslint-test-tools/tests/typescript-eslint/rules/adjacent-overload-signatures.test.ts b/packages/rslint-test-tools/tests/typescript-eslint/rules/adjacent-overload-signatures.test.ts new file mode 100644 index 00000000..ac97e15c --- /dev/null +++ b/packages/rslint-test-tools/tests/typescript-eslint/rules/adjacent-overload-signatures.test.ts @@ -0,0 +1,929 @@ +import { noFormat, RuleTester, getFixturesRootDir } from '../RuleTester.ts'; + +const rootPath = getFixturesRootDir(); + +const ruleTester = new RuleTester({ + languageOptions: { + parserOptions: { + project: './tsconfig.json', + tsconfigRootDir: rootPath, + }, + }, +}); + +ruleTester.run('adjacent-overload-signatures', { + valid: [ + ` +function error(a: string); +function error(b: number); +function error(ab: string | number) {} +export { error }; + `, + ` +import { connect } from 'react-redux'; +export interface ErrorMessageModel { + message: string; +} +function mapStateToProps() {} +function mapDispatchToProps() {} +export default connect(mapStateToProps, mapDispatchToProps)(ErrorMessage); + `, + ` +export const foo = 'a', + bar = 'b'; +export interface Foo {} +export class Foo {} + `, + ` +export interface Foo {} +export const foo = 'a', + bar = 'b'; +export class Foo {} + `, + ` +const foo = 'a', + bar = 'b'; +interface Foo {} +class Foo {} + `, + ` +interface Foo {} +const foo = 'a', + bar = 'b'; +class Foo {} + `, + ` +export class Foo {} +export class Bar {} +export type FooBar = Foo | Bar; + `, + ` +export interface Foo {} +export class Foo {} +export class Bar {} +export type FooBar = Foo | Bar; + `, + ` +export function foo(s: string); +export function foo(n: number); +export function foo(sn: string | number) {} +export function bar(): void {} +export function baz(): void {} + `, + ` +function foo(s: string); +function foo(n: number); +function foo(sn: string | number) {} +function bar(): void {} +function baz(): void {} + `, + ` +declare function foo(s: string); +declare function foo(n: number); +declare function foo(sn: string | number); +declare function bar(): void; +declare function baz(): void; + `, + ` +declare module 'Foo' { + export function foo(s: string): void; + export function foo(n: number): void; + export function foo(sn: string | number): void; + export function bar(): void; + export function baz(): void; +} + `, + ` +declare namespace Foo { + export function foo(s: string): void; + export function foo(n: number): void; + export function foo(sn: string | number): void; + export function bar(): void; + export function baz(): void; +} + `, + ` +type Foo = { + foo(s: string): void; + foo(n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +}; + `, + ` +type Foo = { + foo(s: string): void; + ['foo'](n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +}; + `, + ` +interface Foo { + (s: string): void; + (n: number): void; + (sn: string | number): void; + foo(n: number): void; + bar(): void; + baz(): void; +} + `, + ` +interface Foo { + (s: string): void; + (n: number): void; + (sn: string | number): void; + foo(n: number): void; + bar(): void; + baz(): void; + call(): void; +} + `, + ` +interface Foo { + foo(s: string): void; + foo(n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +} + `, + ` +interface Foo { + foo(s: string): void; + ['foo'](n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +} + `, + ` +interface Foo { + foo(): void; + bar: { + baz(s: string): void; + baz(n: number): void; + baz(sn: string | number): void; + }; +} + `, + ` +interface Foo { + new (s: string); + new (n: number); + new (sn: string | number); + foo(): void; +} + `, + ` +class Foo { + constructor(s: string); + constructor(n: number); + constructor(sn: string | number) {} + bar(): void {} + baz(): void {} +} + `, + ` +class Foo { + foo(s: string): void; + foo(n: number): void; + foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `, + ` +class Foo { + foo(s: string): void; + ['foo'](n: number): void; + foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `, + ` +class Foo { + name: string; + foo(s: string): void; + foo(n: number): void; + foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `, + ` +class Foo { + name: string; + static foo(s: string): void; + static foo(n: number): void; + static foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `, + ` +class Test { + static test() {} + untest() {} + test() {} +} + `, + // examples from https://github.com/nzakas/eslint-plugin-typescript/issues/138 + 'export default function (foo: T) {}', + 'export default function named(foo: T) {}', + ` +interface Foo { + [Symbol.toStringTag](): void; + [Symbol.iterator](): void; +} + `, + // private members + ` +class Test { + #private(): void; + #private(arg: number): void {} + + bar() {} + + '#private'(): void; + '#private'(arg: number): void {} +} + `, + // block statement + ` +function wrap() { + function foo(s: string); + function foo(n: number); + function foo(sn: string | number) {} +} + `, + ` +if (true) { + function foo(s: string); + function foo(n: number); + function foo(sn: string | number) {} +} + `, + ], + invalid: [ + { + code: ` +function wrap() { + function foo(s: string); + function foo(n: number); + type bar = number; + function foo(sn: string | number) {} +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 6, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +if (true) { + function foo(s: string); + function foo(n: number); + let a = 1; + function foo(sn: string | number) {} + foo(a); +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 6, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +export function foo(s: string); +export function foo(n: number); +export function bar(): void {} +export function baz(): void {} +export function foo(sn: string | number) {} + `, + errors: [ + { + column: 1, + data: { name: 'foo' }, + line: 6, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +export function foo(s: string); +export function foo(n: number); +export type bar = number; +export type baz = number | string; +export function foo(sn: string | number) {} + `, + errors: [ + { + column: 1, + data: { name: 'foo' }, + line: 6, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +function foo(s: string); +function foo(n: number); +function bar(): void {} +function baz(): void {} +function foo(sn: string | number) {} + `, + errors: [ + { + column: 1, + data: { name: 'foo' }, + line: 6, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +function foo(s: string); +function foo(n: number); +type bar = number; +type baz = number | string; +function foo(sn: string | number) {} + `, + errors: [ + { + column: 1, + data: { name: 'foo' }, + line: 6, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +function foo(s: string) {} +function foo(n: number) {} +const a = ''; +const b = ''; +function foo(sn: string | number) {} + `, + errors: [ + { + column: 1, + data: { name: 'foo' }, + line: 6, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +function foo(s: string) {} +function foo(n: number) {} +class Bar {} +function foo(sn: string | number) {} + `, + errors: [ + { + column: 1, + data: { name: 'foo' }, + line: 5, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +function foo(s: string) {} +function foo(n: number) {} +function foo(sn: string | number) {} +class Bar { + foo(s: string); + foo(n: number); + name: string; + foo(sn: string | number) {} +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 9, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +declare function foo(s: string); +declare function foo(n: number); +declare function bar(): void; +declare function baz(): void; +declare function foo(sn: string | number); + `, + errors: [ + { + column: 1, + data: { name: 'foo' }, + line: 6, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +declare function foo(s: string); +declare function foo(n: number); +const a = ''; +const b = ''; +declare function foo(sn: string | number); + `, + errors: [ + { + column: 1, + data: { name: 'foo' }, + line: 6, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +declare module 'Foo' { + export function foo(s: string): void; + export function foo(n: number): void; + export function bar(): void; + export function baz(): void; + export function foo(sn: string | number): void; +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +declare module 'Foo' { + export function foo(s: string): void; + export function foo(n: number): void; + export function foo(sn: string | number): void; + function baz(s: string): void; + export function bar(): void; + function baz(n: number): void; + function baz(sn: string | number): void; +} + `, + errors: [ + { + column: 3, + data: { name: 'baz' }, + line: 8, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +declare namespace Foo { + export function foo(s: string): void; + export function foo(n: number): void; + export function bar(): void; + export function baz(): void; + export function foo(sn: string | number): void; +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +declare namespace Foo { + export function foo(s: string): void; + export function foo(n: number): void; + export function foo(sn: string | number): void; + function baz(s: string): void; + export function bar(): void; + function baz(n: number): void; + function baz(sn: string | number): void; +} + `, + errors: [ + { + column: 3, + data: { name: 'baz' }, + line: 8, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +type Foo = { + foo(s: string): void; + foo(n: number): void; + bar(): void; + baz(): void; + foo(sn: string | number): void; +}; + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +type Foo = { + foo(s: string): void; + ['foo'](n: number): void; + bar(): void; + baz(): void; + foo(sn: string | number): void; +}; + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +type Foo = { + foo(s: string): void; + name: string; + foo(n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +}; + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 5, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +interface Foo { + (s: string): void; + foo(n: number): void; + (n: number): void; + (sn: string | number): void; + bar(): void; + baz(): void; + call(): void; +} + `, + errors: [ + { + column: 3, + data: { name: 'call' }, + line: 5, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +interface Foo { + foo(s: string): void; + foo(n: number): void; + bar(): void; + baz(): void; + foo(sn: string | number): void; +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +interface Foo { + foo(s: string): void; + ['foo'](n: number): void; + bar(): void; + baz(): void; + foo(sn: string | number): void; +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +interface Foo { + foo(s: string): void; + 'foo'(n: number): void; + bar(): void; + baz(): void; + foo(sn: string | number): void; +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +interface Foo { + foo(s: string): void; + name: string; + foo(n: number): void; + foo(sn: string | number): void; + bar(): void; + baz(): void; +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 5, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +interface Foo { + foo(): void; + bar: { + baz(s: string): void; + baz(n: number): void; + foo(): void; + baz(sn: string | number): void; + }; +} + `, + errors: [ + { + column: 5, + data: { name: 'baz' }, + line: 8, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +interface Foo { + new (s: string); + new (n: number); + foo(): void; + bar(): void; + new (sn: string | number); +} + `, + errors: [ + { + column: 3, + data: { name: 'new' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +interface Foo { + new (s: string); + foo(): void; + new (n: number); + bar(): void; + new (sn: string | number); +} + `, + errors: [ + { + column: 3, + data: { name: 'new' }, + line: 5, + messageId: 'adjacentOverloadSignatures', + }, + { + column: 3, + data: { name: 'new' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +class Foo { + constructor(s: string); + constructor(n: number); + bar(): void {} + baz(): void {} + constructor(sn: string | number) {} +} + `, + errors: [ + { + column: 3, + data: { name: 'constructor' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +class Foo { + foo(s: string): void; + foo(n: number): void; + bar(): void {} + baz(): void {} + foo(sn: string | number): void {} +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +class Foo { + foo(s: string): void; + ['foo'](n: number): void; + bar(): void {} + baz(): void {} + foo(sn: string | number): void {} +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 7, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +class Foo { + // prettier-ignore + "foo"(s: string): void; + foo(n: number): void; + bar(): void {} + baz(): void {} + foo(sn: string | number): void {} +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 8, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +class Foo { + constructor(s: string); + name: string; + constructor(n: number); + constructor(sn: string | number) {} + bar(): void {} + baz(): void {} +} + `, + errors: [ + { + column: 3, + data: { name: 'constructor' }, + line: 5, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +class Foo { + foo(s: string): void; + name: string; + foo(n: number): void; + foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `, + errors: [ + { + column: 3, + data: { name: 'foo' }, + line: 5, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + { + code: ` +class Foo { + static foo(s: string): void; + name: string; + static foo(n: number): void; + static foo(sn: string | number): void {} + bar(): void {} + baz(): void {} +} + `, + errors: [ + { + column: 3, + data: { name: 'static foo' }, + line: 5, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + // private members + { + code: ` +class Test { + #private(): void; + '#private'(): void; + #private(arg: number): void {} + '#private'(arg: number): void {} +} + `, + errors: [ + { + column: 3, + data: { name: '#private' }, + line: 5, + messageId: 'adjacentOverloadSignatures', + }, + { + column: 3, + data: { name: '"#private"' }, + line: 6, + messageId: 'adjacentOverloadSignatures', + }, + ], + }, + ], +}); diff --git a/packages/rslint-test-tools/tests/typescript-eslint/rules/adjacent-overload-signatures.test.ts.snapshot b/packages/rslint-test-tools/tests/typescript-eslint/rules/adjacent-overload-signatures.test.ts.snapshot new file mode 100644 index 00000000..e785ef6f --- /dev/null +++ b/packages/rslint-test-tools/tests/typescript-eslint/rules/adjacent-overload-signatures.test.ts.snapshot @@ -0,0 +1,879 @@ +exports[`adjacent-overload-signatures > invalid 1`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 39 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 10`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 43 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 11`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 43 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 12`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 50 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 13`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All baz signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 33 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 14`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 50 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 15`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All baz signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 33 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 16`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 34 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 17`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 34 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 18`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 24 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 19`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All call signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 21 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 2`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 39 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 20`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 34 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 21`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 34 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 22`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 34 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 23`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 24 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 24`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All baz signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 36 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 25`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All new signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 29 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 26`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All new signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + { + "ruleName": "adjacent-overload-signatures", + "message": "All new signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 29 + } + } + } + ], + "errorCount": 2, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 27`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All constructor signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 38 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 28`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 36 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 29`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 36 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 3`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 44 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 30`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 36 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 31`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All constructor signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 26 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 32`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 24 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 33`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All static foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 31 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 34`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All #private signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 5, + "column": 3 + }, + "end": { + "line": 5, + "column": 33 + } + } + }, + { + "ruleName": "adjacent-overload-signatures", + "message": "All '#private' signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 35 + } + } + } + ], + "errorCount": 2, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 4`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 44 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 5`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 37 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 6`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 37 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 7`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 37 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 8`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 37 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; + +exports[`adjacent-overload-signatures > invalid 9`] = ` +{ + "diagnostics": [ + { + "ruleName": "adjacent-overload-signatures", + "message": "All foo signatures should be adjacent.", + "filePath": "src/virtual.ts", + "range": { + "start": { + "line": 9, + "column": 3 + }, + "end": { + "line": 9, + "column": 30 + } + } + } + ], + "errorCount": 1, + "fileCount": 1, + "ruleCount": 1 +} +`; diff --git a/packages/rslint/tests/api.test.mjs.snapshot b/packages/rslint/tests/api.test.mjs.snapshot index feec506f..6917fdd1 100644 --- a/packages/rslint/tests/api.test.mjs.snapshot +++ b/packages/rslint/tests/api.test.mjs.snapshot @@ -34,7 +34,7 @@ exports[`lint api > diag snapshot 1`] = ` ], "errorCount": 2, "fileCount": 1, - "ruleCount": 40 + "ruleCount": 41 } `; @@ -59,6 +59,6 @@ exports[`lint api > virtual file support 1`] = ` ], "errorCount": 1, "fileCount": 1, - "ruleCount": 40 + "ruleCount": 41 } `; diff --git a/typescript-go b/typescript-go index c05da65e..623088c7 160000 --- a/typescript-go +++ b/typescript-go @@ -1 +1 @@ -Subproject commit c05da65ec4298d5930c59b559e9d5e00dfab8af3 +Subproject commit 623088c7d877a7660eeaf5b0e1072455589716b4