Repository: nzakas/eslint-plugin-typescript
Pull request #119 (2018-03-13 17:16:19)

Chore: Update eslint-plugin-node to v6.0.x
https://github.com/mysticatea/eslint-plugin-node/releases/tag/v6.0.0


Patch:
diff --git a/README.md b/README.md
index ccc1723..c64b194 100644
--- a/README.md
+++ b/README.md
@@ -70,6 +70,7 @@ Then configure the rules you want to use under the rules section.
 * [`typescript/no-type-alias`](./docs/rules/no-type-alias.md) — Disallow the use of type aliases (`interface-over-type-literal` from TSLint)
 * [`typescript/no-unused-vars`](./docs/rules/no-unused-vars.md) — Prevent TypeScript-specific constructs from being erroneously flagged as unused
 * [`typescript/no-use-before-define`](./docs/rules/no-use-before-define.md) — Disallow the use of variables before they are defined
+* [`typescript/no-var-requires`](./docs/rules/no-var-requires.md) — Disallows the use of require statements except in import statements (`no-var-requires` from TSLint)
 * [`typescript/prefer-namespace-keyword`](./docs/rules/prefer-namespace-keyword.md) — Require the use of the `namespace` keyword instead of the `module` keyword to declare custom TypeScript modules. (`no-internal-module` from TSLint)
 * [`typescript/type-annotation-spacing`](./docs/rules/type-annotation-spacing.md) — Require consistent spacing around type annotations
 <!-- end rule list -->
diff --git a/docs/rules/no-var-requires.md b/docs/rules/no-var-requires.md
new file mode 100644
index 0000000..d376176
--- /dev/null
+++ b/docs/rules/no-var-requires.md
@@ -0,0 +1,28 @@
+# Disallows the use of require statements except in import statements (no-var-requires)
+
+In other words, the use of forms such as `var foo = require("foo")` are banned. Instead use ES6 style imports or `import foo = require("foo")` imports.
+
+## Rule Details
+
+Examples of **incorrect** code for this rule:
+
+```ts
+var foo = require("foo");
+const foo = require("foo");
+let foo = require("foo");
+```
+
+Examples of **correct** code for this rule:
+
+```ts
+import foo = require("foo");
+require("foo");
+```
+
+## When Not To Use It
+
+If you don't care about TypeScript module syntax, then you will not need this rule.
+
+## Compatibility
+
+* TSLint: [no-var-requires](https://palantir.github.io/tslint/rules/no-var-requires/)
diff --git a/lib/rules/member-ordering.js b/lib/rules/member-ordering.js
index 0785e5b..28e0513 100644
--- a/lib/rules/member-ordering.js
+++ b/lib/rules/member-ordering.js
@@ -172,23 +172,9 @@ module.exports = {
          */
         function shouldBeProcessedAsMethod(node) {
             // check for bound methods in ClassProperty nodes.
-            if (
-                node.value &&
-                functionExpressions.indexOf(node.value.type) > -1
-            ) {
-                return true;
-            }
-
-            // check for bound methods in TSPropertySignature nodes.
-            if (
-                node.typeAnnotation &&
-                node.typeAnnotation.typeAnnotation &&
-                node.typeAnnotation.typeAnnotation.type === "TSFunctionType"
-            ) {
-                return true;
-            }
-
-            return false;
+            return (
+                node.value && functionExpressions.indexOf(node.value.type) > -1
+            );
         }
 
         /**
diff --git a/lib/rules/no-var-requires.js b/lib/rules/no-var-requires.js
new file mode 100644
index 0000000..d4e6592
--- /dev/null
+++ b/lib/rules/no-var-requires.js
@@ -0,0 +1,45 @@
+/**
+ * @fileoverview Disallows the use of require statements except in import statements.
+ * @author Macklin Underdown
+ */
+"use strict";
+
+const util = require("../util");
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+
+module.exports = {
+    meta: {
+        docs: {
+            description:
+                "Disallows the use of require statements except in import statements",
+            extraDescription: [util.tslintRule("no-var-requires")],
+            category: "TypeScript",
+            url:
+                "https://github.com/nzakas/eslint-plugin-typescript/blob/master/docs/rules/no-var-requires.md"
+        },
+        schema: []
+    },
+    create(context) {
+        //----------------------------------------------------------------------
+        // Public
+        //----------------------------------------------------------------------
+
+        return {
+            CallExpression(node) {
+                if (
+                    node.callee.name === "require" &&
+                    node.parent.type === "VariableDeclarator"
+                ) {
+                    context.report({
+                        node,
+                        message:
+                            "Require statement not part of import statement"
+                    });
+                }
+            }
+        };
+    }
+};
diff --git a/package.json b/package.json
index 7fcb0e3..dd8c3c3 100644
--- a/package.json
+++ b/package.json
@@ -27,12 +27,12 @@
     "eslint-config-eslint": "^4.0.0",
     "eslint-config-prettier": "^2.9.0",
     "eslint-docs": "^0.1.1",
-    "eslint-plugin-node": "^5.1.1",
+    "eslint-plugin-node": "^6.0.1",
     "eslint-plugin-prettier": "^2.2.0",
     "husky": "^0.14.3",
     "lint-staged": "^6.0.0",
     "mocha": "^4.0.1",
-    "prettier": "1.9.1",
+    "prettier": "^1.11.1",
     "typescript": "~2.6.1",
     "typescript-eslint-parser": "^10.0.0"
   },


Test patch:
diff --git a/tests/lib/rules/member-ordering.js b/tests/lib/rules/member-ordering.js
index ea23bcc..1fee670 100644
--- a/tests/lib/rules/member-ordering.js
+++ b/tests/lib/rules/member-ordering.js
@@ -540,6 +540,21 @@ class Foo {
         },
         {
             code: `
+class Foo {
+    private required: boolean;
+    private typeChecker: (data: any) => boolean;
+    constructor(validator: (data: any) => boolean) {
+        this.typeChecker = validator;
+    }
+    check(data: any): boolean {
+        return this.typeChecker(data);
+    }
+}
+            `,
+            options: [{ classes: ["field", "constructor", "method"] }]
+        },
+        {
+            code: `
 class Foo {
     public static G() {}
     protected static H() {}
@@ -1184,9 +1199,9 @@ class Foo {
 class Foo {
     J() {}
     K = () => {}
-    L: () => {}
     constructor () {}
     A: string;
+    L: () => {}
 }
             `,
             options: [{ default: ["method", "constructor", "field"] }]
@@ -1194,8 +1209,8 @@ class Foo {
         `
 interface Foo {
     A: string;
+    K: () => {};
     J();
-    K: () => {}
 }
         `,
         {
@@ -1211,8 +1226,8 @@ interface Foo {
         `
 type Foo = {
     A: string;
-    J();
     K: () => {}
+    J();
 }
         `,
         {
@@ -2903,12 +2918,6 @@ class Foo {
                         "Member K should be declared before all constructor definitions.",
                     line: 5,
                     column: 5
-                },
-                {
-                    message:
-                        "Member L should be declared before all constructor definitions.",
-                    line: 6,
-                    column: 5
                 }
             ]
         },
@@ -2916,32 +2925,14 @@ class Foo {
             code: `
 interface Foo {
     K: () => {}
-    A: string;
-    J();
-}
-            `,
-            errors: [
-                {
-                    message:
-                        "Member A should be declared before all method definitions.",
-                    line: 4,
-                    column: 5
-                }
-            ]
-        },
-        {
-            code: `
-interface Foo {
     J();
     A: string;
-    K: () => {}
 }
             `,
-            options: [{ default: ["method", "constructor", "field"] }],
             errors: [
                 {
                     message:
-                        "Member K should be declared before all field definitions.",
+                        "Member A should be declared before all method definitions.",
                     line: 5,
                     column: 5
                 }
@@ -2951,15 +2942,15 @@ interface Foo {
             code: `
 type Foo = {
     K: () => {}
-    A: string;
     J();
+    A: string;
 }
             `,
             errors: [
                 {
                     message:
                         "Member A should be declared before all method definitions.",
-                    line: 4,
+                    line: 5,
                     column: 5
                 }
             ]
@@ -2967,16 +2958,16 @@ type Foo = {
         {
             code: `
 type Foo = {
-    J();
     A: string;
     K: () => {}
+    J();
 }
             `,
             options: [{ default: ["method", "constructor", "field"] }],
             errors: [
                 {
                     message:
-                        "Member K should be declared before all field definitions.",
+                        "Member J should be declared before all field definitions.",
                     line: 5,
                     column: 5
                 }
diff --git a/tests/lib/rules/no-var-requires.js b/tests/lib/rules/no-var-requires.js
new file mode 100644
index 0000000..4715cb9
--- /dev/null
+++ b/tests/lib/rules/no-var-requires.js
@@ -0,0 +1,56 @@
+/**
+ * @fileoverview Disallows the use of require statements except in import statements.
+ * @author Macklin Underdown
+ */
+"use strict";
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+
+const rule = require("../../../lib/rules/no-var-requires"),
+    RuleTester = require("eslint").RuleTester;
+
+//------------------------------------------------------------------------------
+// Tests
+//------------------------------------------------------------------------------
+
+const ruleTester = new RuleTester({
+    parser: "typescript-eslint-parser"
+});
+
+ruleTester.run("no-var-requires", rule, {
+    valid: ["import foo = require('foo')", "require('foo')"],
+    invalid: [
+        {
+            code: "var foo = require('foo')",
+            errors: [
+                {
+                    message: "Require statement not part of import statement",
+                    line: 1,
+                    column: 11
+                }
+            ]
+        },
+        {
+            code: "const foo = require('foo')",
+            errors: [
+                {
+                    message: "Require statement not part of import statement",
+                    line: 1,
+                    column: 13
+                }
+            ]
+        },
+        {
+            code: "let foo = require('foo')",
+            errors: [
+                {
+                    message: "Require statement not part of import statement",
+                    line: 1,
+                    column: 11
+                }
+            ]
+        }
+    ]
+});