Repository: nzakas/eslint-plugin-typescript (js)

Issue:
add support for optional modifiers to type-annotation-spacing
typescript 2.8 added `+`/`-` in mapped types to add/remove optional qualifiers.
```TS
type Foo<T> = { [P in keyof T] +?: T[P] }
type Foo<T> = { [P in keyof T] -?: T[P] }
```

`type-annotation-spacing` does not currently support this.


Pull request:
Add support for optional modifiers to type-annotation-spacing.
Closes #158 

Patch:
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..eab87a1
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,8 @@
+# avoids End-of-line problems for Windows Devs
+# automatically converts crlf -> lf
+#   (linters can turn off their line-ending checks)
+*.ts text eol=lf
+*.tsx text eol=lf
+*.js text eol=lf
+*.jsx text eol=lf
+*.d.ts text eol=lf
\ No newline at end of file
diff --git a/README.md b/README.md
index 6a6d9ae..64af18d 100644
--- a/README.md
+++ b/README.md
@@ -55,6 +55,7 @@ Then configure the rules you want to use under the rules section.
 * [`typescript/class-name-casing`](./docs/rules/class-name-casing.md) — Require PascalCased class and interface names (`class-name` from TSLint)
 * [`typescript/explicit-function-return-type`](./docs/rules/explicit-function-return-type.md) — Require explicit return types on functions and class methods
 * [`typescript/explicit-member-accessibility`](./docs/rules/explicit-member-accessibility.md) — Require explicit accessibility modifiers on class properties and methods (`member-access` from TSLint)
+* [`typescript/generic-type-naming`](./docs/rules/generic-type-naming.md) — Enforces naming of generic type variables
 * [`typescript/interface-name-prefix`](./docs/rules/interface-name-prefix.md) — Require that interface names be prefixed with `I` (`interface-name` from TSLint)
 * [`typescript/member-delimiter-style`](./docs/rules/member-delimiter-style.md) — Require a specific member delimiter style for interfaces and type literals
 * [`typescript/member-naming`](./docs/rules/member-naming.md) — Enforces naming conventions for class members by visibility.
diff --git a/docs/rules/generic-type-naming.md b/docs/rules/generic-type-naming.md
new file mode 100644
index 0000000..a13513d
--- /dev/null
+++ b/docs/rules/generic-type-naming.md
@@ -0,0 +1,42 @@
+# Enforces naming of generic type variables (generic-type-naming)
+
+It can be helpful to enforce a consistent naming style for generic type variables used within a type.
+For example, prefixing them with `T` and ensuring a somewhat descriptive name, or enforcing Hungarian notation.
+
+## Rule Details
+
+This rule allows you to enforce conventions over type variables. By default, it does nothing.
+
+## Options
+
+The rule takes a single string option, which is a regular expression that type variables should match.
+
+Examples of **correct** code with a configuration of `'^T[A-Z][a-zA-Z]+$'`:
+
+```typescript
+type ReadOnly<TType extends object> = {
+  readonly [TKey in keyof TType]: TType[TKey];
+}
+
+interface SimpleMap<TValue> {
+  [key: string]: TValue;
+}
+```
+
+Examples of **incorrect** code with a configuration of `'^T[A-Z][a-zA-Z]+$'`:
+
+```typescript
+type ReadOnly<T extends object> = {
+  readonly [Key in keyof T]: T[Key];
+}
+
+interface SimpleMap<T> {
+  [key: string]: T;
+}
+```
+
+## When Not To Use It
+If you do not want to enforce a naming convention for type variables.
+
+## Further Reading
+- [TypeScript Generics](https://www.typescriptlang.org/docs/handbook/generics.html)
diff --git a/lib/rules/adjacent-overload-signatures.js b/lib/rules/adjacent-overload-signatures.js
index d40bed3..89e713c 100644
--- a/lib/rules/adjacent-overload-signatures.js
+++ b/lib/rules/adjacent-overload-signatures.js
@@ -47,7 +47,7 @@ module.exports = {
                 case "TSNamespaceFunctionDeclaration":
                 case "TSEmptyBodyFunctionDeclaration":
                 case "TSEmptyBodyDeclareFunction": {
-                    return member.id.name;
+                    return member.id && member.id.name;
                 }
                 case "TSMethodSignature": {
                     return (
diff --git a/lib/rules/generic-type-naming.js b/lib/rules/generic-type-naming.js
new file mode 100644
index 0000000..10e66e5
--- /dev/null
+++ b/lib/rules/generic-type-naming.js
@@ -0,0 +1,71 @@
+/**
+ * @fileoverview Enforces naming of generic type variables.
+ */
+"use strict";
+
+/**
+ *
+ * @param {any} context ESLint context
+ * @param {string} rule Option
+ * @returns {Function} Node's visitor function
+ */
+function createTypeParameterChecker(context, rule) {
+    const regex = new RegExp(rule);
+
+    return function checkTypeParameters(pnode) {
+        const params = pnode.typeParameters && pnode.typeParameters.params;
+
+        if (!Array.isArray(params) || params.length === 0) {
+            return;
+        }
+        params.forEach(node => {
+            const type = node.type;
+
+            if (type === "TSTypeParameter" || type === "TypeParameter") {
+                const name = node.name;
+
+                if (name && !regex.test(name)) {
+                    const data = { name, rule };
+
+                    context.report({
+                        node,
+                        message:
+                            "Type parameter {{name}} does not match rule {{rule}}",
+                        data
+                    });
+                }
+            }
+        });
+    };
+}
+
+module.exports = {
+    meta: {
+        docs: {
+            description: "Enforces naming of generic type variables",
+            category: "TypeScript",
+            url:
+                "https://github.com/nzakas/eslint-plugin-typescript/blob/master/docs/rules/generic-type-naming.md"
+        }
+    },
+
+    create(context) {
+        const rule = context.options[0];
+
+        if (!rule) {
+            return {};
+        }
+
+        const checkTypeParameters = createTypeParameterChecker(context, rule);
+
+        return {
+            VariableDeclarator: checkTypeParameters,
+            ClassDeclaration: checkTypeParameters,
+            InterfaceDeclaration: checkTypeParameters,
+            TSInterfaceDeclaration: checkTypeParameters,
+            FunctionDeclaration: checkTypeParameters,
+            TSCallSignature: checkTypeParameters,
+            CallSignature: checkTypeParameters
+        };
+    }
+};
diff --git a/lib/rules/interface-name-prefix.js b/lib/rules/interface-name-prefix.js
index 5e82e74..26ec48e 100644
--- a/lib/rules/interface-name-prefix.js
+++ b/lib/rules/interface-name-prefix.js
@@ -43,19 +43,8 @@ module.exports = {
             if (typeof name !== "string") {
                 return false;
             }
-            if (name.length === 0) {
-                return false;
-            }
-            const first = name.charAt(0);
-            const second = name.charAt(1);
 
-            if (second === "") {
-                return false;
-            }
-            if (first !== "I" || second !== second.toUpperCase()) {
-                return false;
-            }
-            return true;
+            return /^I[A-Z]/.test(name);
         }
 
         /**
diff --git a/lib/rules/no-unused-vars.js b/lib/rules/no-unused-vars.js
index f940bfe..60093a8 100644
--- a/lib/rules/no-unused-vars.js
+++ b/lib/rules/no-unused-vars.js
@@ -122,6 +122,15 @@ module.exports = {
 
                     break;
 
+                case "TSTypeParameter": {
+                    markTypeAnnotationAsUsed(annotation.constraint);
+                    break;
+                }
+                case "TSMappedType": {
+                    markTypeAnnotationAsUsed(annotation.typeAnnotation);
+                    markTypeAnnotationAsUsed(annotation.typeParameter);
+                    break;
+                }
                 default:
                     break;
             }
@@ -247,6 +256,9 @@ module.exports = {
             if (node.decorators) {
                 node.decorators.forEach(markDecoratorAsUsed);
             }
+            if (node.typeParameters && node.typeParameters.params) {
+                node.typeParameters.params.forEach(markTypeAnnotationAsUsed);
+            }
         }
 
         //----------------------------------------------------------------------
diff --git a/lib/rules/prefer-namespace-keyword.js b/lib/rules/prefer-namespace-keyword.js
index fe0c5af..0c14aab 100644
--- a/lib/rules/prefer-namespace-keyword.js
+++ b/lib/rules/prefer-namespace-keyword.js
@@ -27,48 +27,32 @@ module.exports = {
     create(context) {
         const sourceCode = context.getSourceCode();
 
-        //----------------------------------------------------------------------
-        // Helpers
-        //----------------------------------------------------------------------
-
-        /**
-         * Determines if node is a TypeScript module declaration (instead of a namespace/module).
-         * @param {ASTNode} node the node to be evaluated.
-         * @returns {boolean} true when node is an external declaration.
-         * @private
-         */
-        function isTypeScriptModuleDeclaration(node) {
-            return node.id && node.id.type === "Literal";
-        }
-
-        /**
-         * Gets the start index of the keyword `module`.
-         * @param {TSNode} node the node to be evaluated.
-         * @returns {number} the start index.
-         * @private
-         */
-        function getStartIndex(node) {
-            if (
-                node.modifiers &&
-                node.modifiers.length > 0 &&
-                node.modifiers[0].type === "TSDeclareKeyword"
-            ) {
-                return node.range[0] + "declare".length + 1;
-            }
-            return node.range[0];
-        }
-
         //----------------------------------------------------------------------
         // Public
         //----------------------------------------------------------------------
         return {
             TSModuleDeclaration(node) {
-                const declaration = sourceCode.getText(node);
+                // Get tokens of the declaration header.
+                const firstToken = sourceCode.getFirstToken(node);
+                const tokens = [firstToken].concat(
+                    sourceCode.getTokensBetween(
+                        firstToken,
+                        sourceCode.getFirstToken(node.body)
+                    )
+                );
 
-                if (
-                    isTypeScriptModuleDeclaration(node) ||
-                    /\bnamespace\b/.test(declaration)
-                ) {
+                // Get 'module' token and the next one.
+                const moduleKeywordIndex = tokens.findIndex(
+                    t => t.type === "Identifier" && t.value === "module"
+                );
+                const moduleKeywordToken =
+                    moduleKeywordIndex === -1
+                        ? null
+                        : tokens[moduleKeywordIndex];
+                const moduleNameToken = tokens[moduleKeywordIndex + 1];
+
+                // Do nothing if the 'module' token was not found or the module name is a string.
+                if (!moduleKeywordToken || moduleNameToken.type === "String") {
                     return;
                 }
 
@@ -77,10 +61,8 @@ module.exports = {
                     message:
                         "Use 'namespace' instead of 'module' to declare custom TypeScript modules",
                     fix(fixer) {
-                        const start = getStartIndex(node);
-
-                        return fixer.replaceTextRange(
-                            [start, start + "module".length],
+                        return fixer.replaceText(
+                            moduleKeywordToken,
                             "namespace"
                         );
                     }
diff --git a/lib/rules/type-annotation-spacing.js b/lib/rules/type-annotation-spacing.js
index f4c956c..a908a54 100644
--- a/lib/rules/type-annotation-spacing.js
+++ b/lib/rules/type-annotation-spacing.js
@@ -98,6 +98,16 @@ module.exports = {
                 type = "?:";
                 punctuatorTokenStart = previousToken;
                 previousToken = sourceCode.getTokenBefore(previousToken);
+
+                // handle the +/- modifiers for optional modification operators
+                if (
+                    previousToken.value === "+" ||
+                    previousToken.value === "-"
+                ) {
+                    type = `${previousToken.value}?:`;
+                    punctuatorTokenStart = previousToken;
+                    previousToken = sourceCode.getTokenBefore(previousToken);
+                }
             }
 
             const previousDelta =
diff --git a/package.json b/package.json
index d9ba96c..7f6be40 100644
--- a/package.json
+++ b/package.json
@@ -15,6 +15,7 @@
     "lint:fix": "eslint lib/ tests/ --fix",
     "docs": "eslint-docs",
     "docs:check": "eslint-docs check",
+    "format": "prettier --write --tab-width 4 lib/**/*.js tests/**/*.js",
     "mocha": "mocha tests --recursive --reporter=dot",
     "test": "npm run lint && npm run mocha && npm run docs:check",
     "precommit": "npm test && lint-staged"


Test patch:
diff --git a/tests/lib/rules/generic-type-naming.js b/tests/lib/rules/generic-type-naming.js
new file mode 100644
index 0000000..7f1ed3a
--- /dev/null
+++ b/tests/lib/rules/generic-type-naming.js
@@ -0,0 +1,74 @@
+"use strict";
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+
+const rule = require("../../../lib/rules/generic-type-naming"),
+    RuleTester = require("eslint").RuleTester;
+
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
+const ruleTester = new RuleTester({
+    parser: "typescript-eslint-parser"
+});
+
+const messagePattern = "Type parameter {{name}} does not match rule {{rule}}";
+
+/**
+ * Creates error object
+ * @param {Object} data Data
+ * @returns {Object} Object with message property
+ */
+function error(data) {
+    let message = messagePattern;
+
+    Object.keys(data).forEach(key => {
+        message = message.replace(new RegExp(`{{${key}}}`, "g"), data[key]);
+    });
+    return { message };
+}
+
+ruleTester.run("generic-type-naming", rule, {
+    valid: [
+        { code: "class<T,U,V> { }", options: [] },
+        { code: "type ReadOnly<T extends object> = {}", options: [] },
+        { code: "interface SimpleMap<V> { }", options: [] },
+        { code: "function get<T>() {}", options: [] },
+        { code: "interface GenericIdentityFn { <T>(arg: T): T }", options: [] },
+        { code: "class<x> { }", options: ["^x+$"] },
+        {
+            code: "class CounterContainer extends Container<Counter> { }",
+            options: ["^T$"]
+        }
+    ],
+    invalid: [
+        {
+            code: "class<x> { }",
+            options: ["^[A-Z]+$"],
+            errors: [error({ name: "x", rule: "^[A-Z]+$" })]
+        },
+        {
+            code: "interface SimpleMap<x> { }",
+            options: ["^[A-Z]+$"],
+            errors: [error({ name: "x", rule: "^[A-Z]+$" })]
+        },
+        {
+            code: "type R<x> = {}",
+            options: ["^[A-Z]+$"],
+            errors: [error({ name: "x", rule: "^[A-Z]+$" })]
+        },
+        {
+            code: "function get<x>() {}",
+            options: ["^[A-Z]+$"],
+            errors: [error({ name: "x", rule: "^[A-Z]+$" })]
+        },
+        {
+            code: "interface GenericIdentityFn { <x>(arg: x): x }",
+            options: ["^[A-Z]+$"],
+            errors: [error({ name: "x", rule: "^[A-Z]+$" })]
+        }
+    ]
+});
diff --git a/tests/lib/rules/interface-name-prefix.js b/tests/lib/rules/interface-name-prefix.js
index 98f2120..c15d72a 100644
--- a/tests/lib/rules/interface-name-prefix.js
+++ b/tests/lib/rules/interface-name-prefix.js
@@ -54,6 +54,14 @@ interface Iguana {
             code: `
 interface Animal {
     name: string;
+}
+            `,
+            options: ["never"]
+        },
+        {
+            code: `
+interface I18n {
+    name: string;
 }
             `,
             options: ["never"]
diff --git a/tests/lib/rules/no-unused-vars.js b/tests/lib/rules/no-unused-vars.js
index c470d3c..ddcba30 100644
--- a/tests/lib/rules/no-unused-vars.js
+++ b/tests/lib/rules/no-unused-vars.js
@@ -315,6 +315,30 @@ import { SomeOther } from 'some';
 import { Another } from 'some';
 interface A extends Nullable<SomeOther> {
     do(a: Nullable<Another>);
+}
+        `,
+        `
+import { Foo } from './types';
+
+class Bar<T extends Foo> {}
+
+new Bar<number>()
+        `,
+        `
+import { Foo, Bar } from './types';
+
+class Baz<T extends Foo & Bar> {}
+
+new Baz<any>()
+        `,
+        `
+type Foo = "a" | "b" | "c"
+type Bar = number
+
+export const map: { [name in Foo]: Bar } = {
+    a: 1,
+    b: 2,
+    c: 3
 }
         `
     ],
diff --git a/tests/lib/rules/prefer-namespace-keyword.js b/tests/lib/rules/prefer-namespace-keyword.js
index fda02cc..b50bbd2 100644
--- a/tests/lib/rules/prefer-namespace-keyword.js
+++ b/tests/lib/rules/prefer-namespace-keyword.js
@@ -23,7 +23,8 @@ ruleTester.run("prefer-namespace-keyword", rule, {
     valid: [
         "declare module 'foo' { }",
         "namespace foo { }",
-        "declare namespace foo { }"
+        "declare namespace foo { }",
+        "declare global { }"
     ],
     invalid: [
         {
diff --git a/tests/lib/rules/type-annotation-spacing.js b/tests/lib/rules/type-annotation-spacing.js
index 2642425..c1cc12b 100644
--- a/tests/lib/rules/type-annotation-spacing.js
+++ b/tests/lib/rules/type-annotation-spacing.js
@@ -5907,3 +5907,356 @@ type Foo = {
         }
     ]
 });
+
+//------------------------------------------------------------------------------
+// Optional w/Addition/Removal Annotation Tests
+//------------------------------------------------------------------------------
+
+const operators = ["+?:", "-?:"];
+
+ruleTester.run("type-annotation-spacing", rule, {
+    valid: operators.reduce(
+        (validCases, operator) =>
+            validCases.concat([
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    options: []
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    options: [{ after: true }]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    options: [{ before: false }]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    options: [{ after: true, before: false }]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator}T[P] }`,
+                    options: [{ after: false, before: true }]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    options: [{ before: true }]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    options: [{ after: true, before: true }]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator}T[P] }`,
+                    options: [{ after: false }]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator}T[P] }`,
+                    options: [{ after: false, before: false }]
+                }
+            ]),
+        []
+    ),
+    invalid: operators.reduce(
+        (validCases, operator) =>
+            validCases.concat([
+                // space before + after cases
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    options: [{ after: true }],
+                    output: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Unexpected space before the '${operator}'`,
+                            line: 1,
+                            column: 32
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    options: [{ before: false }],
+                    output: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Unexpected space before the '${operator}'`,
+                            line: 1,
+                            column: 32
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    options: [{ after: true, before: false }],
+                    output: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Unexpected space before the '${operator}'`,
+                            line: 1,
+                            column: 32
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    options: [{ after: false }],
+                    output: `type Foo<T> = { [P in keyof T]${operator}T[P] }`,
+                    errors: [
+                        {
+                            message: `Unexpected space before the '${operator}'`,
+                            line: 1,
+                            column: 32
+                        },
+                        {
+                            message: `Unexpected space after the '${operator}'`,
+                            line: 1,
+                            column: 34
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    options: [{ after: false, before: false }],
+                    output: `type Foo<T> = { [P in keyof T]${operator}T[P] }`,
+                    errors: [
+                        {
+                            message: `Unexpected space before the '${operator}'`,
+                            line: 1,
+                            column: 32
+                        },
+                        {
+                            message: `Unexpected space after the '${operator}'`,
+                            line: 1,
+                            column: 34
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    options: [{ after: false, before: true }],
+                    output: `type Foo<T> = { [P in keyof T] ${operator}T[P] }`,
+                    errors: [
+                        {
+                            message: `Unexpected space after the '${operator}'`,
+                            line: 1,
+                            column: 34
+                        }
+                    ]
+                },
+                // no space cases
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator}T[P] }`,
+                    options: [{ after: true }],
+                    output: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Expected a space after the '${operator}'`,
+                            line: 1,
+                            column: 33
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator}T[P] }`,
+                    options: [{ before: true }],
+                    output: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Expected a space before the '${operator}'`,
+                            line: 1,
+                            column: 31
+                        },
+                        {
+                            message: `Expected a space after the '${operator}'`,
+                            line: 1,
+                            column: 33
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator}T[P] }`,
+                    options: [{ after: true, before: true }],
+                    output: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Expected a space before the '${operator}'`,
+                            line: 1,
+                            column: 31
+                        },
+                        {
+                            message: `Expected a space after the '${operator}'`,
+                            line: 1,
+                            column: 33
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator}T[P] }`,
+                    options: [{ after: true, before: false }],
+                    output: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Expected a space after the '${operator}'`,
+                            line: 1,
+                            column: 33
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator}T[P] }`,
+                    options: [{ after: false, before: true }],
+                    output: `type Foo<T> = { [P in keyof T] ${operator}T[P] }`,
+                    errors: [
+                        {
+                            message: `Expected a space before the '${operator}'`,
+                            line: 1,
+                            column: 31
+                        }
+                    ]
+                },
+                // space before cases
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator}T[P] }`,
+                    options: [],
+                    output: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Unexpected space before the '${operator}'`,
+                            line: 1,
+                            column: 32
+                        },
+                        {
+                            message: `Expected a space after the '${operator}'`,
+                            line: 1,
+                            column: 34
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator}T[P] }`,
+                    options: [{ after: true }],
+                    output: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Unexpected space before the '${operator}'`,
+                            line: 1,
+                            column: 32
+                        },
+                        {
+                            message: `Expected a space after the '${operator}'`,
+                            line: 1,
+                            column: 34
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator}T[P] }`,
+                    options: [{ before: true }],
+                    output: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Expected a space after the '${operator}'`,
+                            line: 1,
+                            column: 34
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator}T[P] }`,
+                    options: [{ after: true, before: false }],
+                    output: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Unexpected space before the '${operator}'`,
+                            line: 1,
+                            column: 32
+                        },
+                        {
+                            message: `Expected a space after the '${operator}'`,
+                            line: 1,
+                            column: 34
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T] ${operator}T[P] }`,
+                    options: [{ after: true, before: true }],
+                    output: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Expected a space after the '${operator}'`,
+                            line: 1,
+                            column: 34
+                        }
+                    ]
+                },
+                // space after cases
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    options: [{ after: false }],
+                    output: `type Foo<T> = { [P in keyof T]${operator}T[P] }`,
+                    errors: [
+                        {
+                            message: `Unexpected space after the '${operator}'`,
+                            line: 1,
+                            column: 33
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    options: [{ before: true }],
+                    output: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Expected a space before the '${operator}'`,
+                            line: 1,
+                            column: 31
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    options: [{ after: true, before: true }],
+                    output: `type Foo<T> = { [P in keyof T] ${operator} T[P] }`,
+                    errors: [
+                        {
+                            message: `Expected a space before the '${operator}'`,
+                            line: 1,
+                            column: 31
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    options: [{ after: false, before: true }],
+                    output: `type Foo<T> = { [P in keyof T] ${operator}T[P] }`,
+                    errors: [
+                        {
+                            message: `Expected a space before the '${operator}'`,
+                            line: 1,
+                            column: 31
+                        },
+                        {
+                            message: `Unexpected space after the '${operator}'`,
+                            line: 1,
+                            column: 33
+                        }
+                    ]
+                },
+                {
+                    code: `type Foo<T> = { [P in keyof T]${operator} T[P] }`,
+                    options: [{ after: false, before: false }],
+                    output: `type Foo<T> = { [P in keyof T]${operator}T[P] }`,
+                    errors: [
+                        {
+                            message: `Unexpected space after the '${operator}'`,
+                            line: 1,
+                            column: 33
+                        }
+                    ]
+                }
+            ]),
+        []
+    )
+});