Repository: lo1tuma/eslint-plugin-mocha (ts)

Issue:
max-top-level-suites not being triggered for mocha/recommended plugin
It's mentioned in the rules [markdown](https://github.com/lo1tuma/eslint-plugin-mocha/tree/master/docs/rules#rules) that `max-top-level-suites` is included in the `mocha/recommended` plugin.

However, I'm _not_ able to trigger the rule with the following simple test:
```javascript
import * as assert from 'assert';

describe('Array.length', function () {
  it('should return the correct length of the array', function () {
    assert.equal([1, 2, 3].length, 3);
  });
});

describe('Array.indexOf()', function () {
  it('should return -1 when the value is not present', function () {
    assert.equal([1, 2, 3].indexOf(4), -1);
  });
});
```

What seems weird to me is that I _am_ able to trigger the other rules (e.g. `no-global-tests`, `no-identical-title`).

Pull request:
Fix max-top-level-suites to work with ES modules
Fixes #248.

Patch:
diff --git a/lib/rules/max-top-level-suites.js b/lib/rules/max-top-level-suites.js
index 67fb352..ce35b8f 100644
--- a/lib/rules/max-top-level-suites.js
+++ b/lib/rules/max-top-level-suites.js
@@ -11,6 +11,10 @@ const { additionalSuiteNames } = require('../util/settings');
 
 const defaultSuiteLimit = 1;
 
+function isTopLevelScope(scope) {
+    return scope.type === 'module' || scope.upper === null;
+}
+
 module.exports = {
     meta: {
         type: 'suggestion',
@@ -43,7 +47,7 @@ module.exports = {
                 if (astUtil.isDescribe(node, additionalSuiteNames(settings))) {
                     const scope = context.getScope();
 
-                    if (scope.upper === null) {
+                    if (isTopLevelScope(scope)) {
                         topLevelDescribes.push(node);
                     }
                 }


Test patch:
diff --git a/test/rules/max-top-level-suites.js b/test/rules/max-top-level-suites.js
index d38bdfd..6ce54df 100644
--- a/test/rules/max-top-level-suites.js
+++ b/test/rules/max-top-level-suites.js
@@ -54,7 +54,21 @@ ruleTester.run('max-top-level-suites', rules['max-top-level-suites'], {
             }
         },
         'someOtherFunction();',
-        'describe("top", function () {}); function foo() { describe("not necessarily top", function () {}); }'
+        'describe("top", function () {}); function foo() { describe("not necessarily top", function () {}); }',
+        {
+            code: 'describe("", function () { });',
+            parserOptions: {
+                sourceType: 'module',
+                ecmaVersion: 2015
+            }
+        },
+        {
+            code: 'describe("", function () { describe("", function () {}); });',
+            parserOptions: {
+                sourceType: 'module',
+                ecmaVersion: 2015
+            }
+        }
     ],
 
     invalid: [
@@ -65,6 +79,17 @@ ruleTester.run('max-top-level-suites', rules['max-top-level-suites'], {
                 { message: 'The number of top-level suites is more than 1.' }
             ]
         },
+        {
+            code: 'describe("", function () { });' +
+                  'describe("", function () { });',
+            parserOptions: {
+                sourceType: 'module',
+                ecmaVersion: 2015
+            },
+            errors: [
+                { message: 'The number of top-level suites is more than 1.' }
+            ]
+        },
         {
             code: 'describe("this is a test", function () { });' +
                   'describe("this is a different test", function () { });' +