Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Add typescript-specific edge case test to space-infix-ops #10986

Merged
merged 1 commit into from Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
155 changes: 155 additions & 0 deletions tests/fixtures/parsers/typescript-parsers/type-alias.js
@@ -0,0 +1,155 @@
"use strict";

exports.parse = () => ({
type: "Program",
range: [0, 16],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 16 }
},
body: [
{
type: "VariableDeclaration",
range: [0, 16],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 16 }
},
kind: "type",
declarations: [
{
type: "VariableDeclarator",
id: {
type: "Identifier",
range: [
5,
8
],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 8 }
},
name: "Foo"
},
init: {
type: "TSTypeReference",
range: [14, 15],
loc: {
start: { line: 1, column: 14 },
end: { line: 1, column: 15 }
},
typeName: {
type: "Identifier",
range: [14, 15],
loc: {
start: { line: 1, column: 14 },
end: { line: 1, column: 15 }
},
name: "T"
}
},
range: [5, 16],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 16 }
},
typeParameters: {
type: "TSTypeParameterDeclaration",
range: [8, 11],
loc: {
start: { line: 1, column: 8 },
end: { line: 1, column: 11 }
},
params: [
{
type: "TSTypeParameter",
range: [9, 10],
loc: {
start: { line: 1, column: 9 },
end: { line: 1, column: 10 }
},
name: "T"
}
]
}
}
]
}
],
sourceType: "script",
tokens: [
{
type: "Identifier",
value: "type",
range: [0, 4],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 4 }
}
},
{
type: "Identifier",
value: "Foo",
range: [5, 8],
loc: {
start: { line: 1, column: 5 },
end: { line: 1, column: 8 }
}
},
{
type: "Punctuator",
value: "<",
range: [8, 9],
loc: {
start: { line: 1, column: 8 },
end: { line: 1, column: 9 }
}
},
{
type: "Identifier",
value: "T",
range: [9, 10],
loc: {
start: { line: 1, column: 9 },
end: { line: 1, column: 10 }
}
},
{
type: "Punctuator",
value: ">",
range: [10, 11],
loc: {
start: { line: 1, column: 10 },
end: { line: 1, column: 11 }
}
},
{
type: "Punctuator",
value: "=",
range: [12, 13],
loc: {
start: { line: 1, column: 12 },
end: { line: 1, column: 13 }
}
},
{
type: "Identifier",
value: "T",
range: [14, 15],
loc: {
start: { line: 1, column: 14 },
end: { line: 1, column: 15 }
}
},
{
type: "Punctuator",
value: ";",
range: [15, 16],
loc: {
start: { line: 1, column: 15 },
end: { line: 1, column: 16 }
}
}
],
comments: []
})
5 changes: 4 additions & 1 deletion tests/lib/rules/space-infix-ops.js
Expand Up @@ -44,7 +44,10 @@ ruleTester.run("space-infix-ops", rule, {
{ code: "function foo(a: number = 0) { }", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-parameter-type-annotation") },
{ code: "function foo(): Bar { }", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-return-type-annotation") },
{ code: "var foo: Bar = '';", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/variable-declaration-init-type-annotation") },
{ code: "const foo = function(a: number = 0): Bar { };", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-expression-type-annotation") }
{ code: "const foo = function(a: number = 0): Bar { };", parserOptions: { ecmaVersion: 6 }, parser: parser("type-annotations/function-expression-type-annotation") },

// TypeScript Type Aliases
{ code: "type Foo<T> = T;", parserOptions: { ecmaVersion: 6 }, parser: parser("typescript-parsers/type-alias") }
],
invalid: [
{
Expand Down