Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: lo1tuma/eslint-plugin-mocha
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 96b14bb425ca3cbcea62e460bd253553bda4d40c
Choose a base ref
...
head repository: lo1tuma/eslint-plugin-mocha
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b2d8c9e0933f4200c6030bbacb5896951a0cd85d
Choose a head ref

Commits on Nov 22, 2019

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    6c19bc1 View commit details
  2. Merge pull request #222 from lo1tuma/coveralls

    ✉️ Send a webhook to Coveralls when the build completes
    lo1tuma authored Nov 22, 2019
    Copy the full SHA
    e40722d View commit details
  3. Copy the full SHA
    7923c98 View commit details
  4. ♻️ Replace Travis build badge with GitHub Actions badge (#223)

    ♻️ Replace Travis build badge with GitHub Actions badge
    screendriver authored Nov 22, 2019
    Copy the full SHA
    78d355c View commit details

Commits on Dec 11, 2019

  1. Copy the full SHA
    1954cf3 View commit details

Commits on Jan 31, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    0efea30 View commit details

Commits on Feb 17, 2020

  1. Alphabetize rule lists

    Fix alphabetization within config rule list and alphabetize rule list (for easier comparison to ensure no rules are missing in either list).
    
    Also adds `'mocha/no-return-from-async': 'off',` to `recommended` config for consistency (since all other rules are included in the list).
    brettz9 authored Feb 17, 2020
    Copy the full SHA
    aa6cb09 View commit details
  2. - Add fixable property to fixable rules (and mention in docs)

    Per docs at https://eslint.org/docs/developer-guide/working-with-rules :
      "Without the fixable property, ESLint does not apply fixes even if the rule implements fix functions. Omit the fixable property if the rule is not fixable."
    brettz9 committed Feb 17, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f766402 View commit details
  3. - npm: Add package-lock.json

    brettz9 committed Feb 17, 2020
    Copy the full SHA
    29ee0d1 View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    920a215 View commit details
  5. Copy the full SHA
    7007b33 View commit details
  6. - Add "Options" heading in each doc file where options are available …

    …(and ensure consistent level 2 heading)
    brettz9 committed Feb 17, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7254907 View commit details
  7. Merge pull request #227 from brettz9/patch-1

    Alphabetize rule lists
    lo1tuma authored Feb 17, 2020
    Copy the full SHA
    bdad369 View commit details
  8. Merge pull request #226 from cruzdanilo/master

    add plugin to recommended config
    lo1tuma authored Feb 17, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f8141df View commit details
  9. Merge pull request #228 from brettz9/fixable

    Add `fixable` property to fixable rules (and mention in docs)
    lo1tuma authored Feb 17, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a147956 View commit details
  10. Merge pull request #230 from brettz9/package-lock

    - npm: Add package-lock.json
    lo1tuma authored Feb 17, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    07948bd View commit details
  11. Merge pull request #231 from brettz9/doc-highlighting

    Doc syntax issue
    lo1tuma authored Feb 17, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    57add13 View commit details
  12. Merge pull request #232 from brettz9/regexp-u-flags

    Add `u` flag in RegExp for `valid-test-description` and `valid-suite-description`
    lo1tuma authored Feb 17, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    347d544 View commit details
  13. Merge pull request #233 from brettz9/options-in-docs

    "Options" heading in doc files (and consistent level 2 heading)
    lo1tuma authored Feb 17, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6ac703b View commit details
  14. - Indicate whether rule is recommended (also put into table along wit…

    …h info on whether "fixable")
    brettz9 committed Feb 17, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    04cdbaa View commit details
  15. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    68a3c07 View commit details
  16. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fdb3843 View commit details

Commits on Feb 18, 2020

  1. Merge pull request #229 from brettz9/recommended-rules

    Indicate whether rule is recommended
    lo1tuma authored Feb 18, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c1f8049 View commit details
  2. Merge pull request #234 from brettz9/schemas-for-options

    Add schemas for options (and remove for files which are using settings)
    lo1tuma authored Feb 18, 2020
    Copy the full SHA
    8cf8640 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    471e354 View commit details
  4. Merge pull request #235 from brettz9/nondeprecated-rule-format

    Nondeprecated rule format
    lo1tuma authored Feb 18, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    36c9e67 View commit details
  5. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8778d96 View commit details
  6. Merge pull request #236 from lo1tuma/no-hooks-option

    no-hooks: add option to allow certain kind of hooks
    lo1tuma authored Feb 18, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7eea93d View commit details
  7. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6255546 View commit details
  8. Merge pull request #237 from lo1tuma/template-strings

    Check static template strings in valid-test-description and valid-suite-description
    lo1tuma authored Feb 18, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1c3a545 View commit details
  9. Copy the full SHA
    46f716d View commit details
  10. Copy the full SHA
    2633908 View commit details

Commits on Feb 19, 2020

  1. Merge pull request #239 from lo1tuma/fix-top-level

    Fix max-top-level-suites to ignore generated suites
    lo1tuma authored Feb 19, 2020
    Copy the full SHA
    a18680d View commit details
  2. Merge pull request #238 from lo1tuma/fix-nested

    no-hooks-for-single-case: fix false postive in nested suites
    lo1tuma authored Feb 19, 2020
    Copy the full SHA
    c470a3d View commit details
  3. Update dependencies

    lo1tuma committed Feb 19, 2020
    Copy the full SHA
    b91a2f8 View commit details
  4. 6.3.0

    lo1tuma committed Feb 19, 2020
    Copy the full SHA
    b2d8c9e View commit details
Showing with 4,592 additions and 813 deletions.
  1. +4 −0 .github/workflows/ci.yml
  2. +32 −0 CHANGELOG.md
  3. +1 −1 README.md
  4. +23 −21 docs/rules/README.md
  5. +2 −0 docs/rules/max-top-level-suites.md
  6. +2 −0 docs/rules/no-async-describe.md
  7. +2 −2 docs/rules/no-exclusive-tests.md
  8. +1 −1 docs/rules/no-hooks-for-single-case.md
  9. +15 −0 docs/rules/no-hooks.md
  10. +2 −0 docs/rules/no-mocha-arrows.md
  11. +2 −2 docs/rules/no-skipped-tests.md
  12. +4 −3 docs/rules/no-synchronous-tests.md
  13. +2 −0 docs/rules/prefer-arrow-callback.md
  14. +2 −0 docs/rules/valid-suite-description.md
  15. +2 −0 docs/rules/valid-test-description.md
  16. +17 −15 index.js
  17. +34 −32 lib/rules/handle-done-callback.js
  18. +43 −35 lib/rules/max-top-level-suites.js
  19. +54 −48 lib/rules/no-async-describe.js
  20. +39 −53 lib/rules/no-exclusive-tests.js
  21. +14 −12 lib/rules/no-global-tests.js
  22. +66 −53 lib/rules/no-hooks-for-single-case.js
  23. +34 −10 lib/rules/no-hooks.js
  24. +23 −21 lib/rules/no-identical-title.js
  25. +50 −45 lib/rules/no-mocha-arrows.js
  26. +48 −46 lib/rules/no-nested-tests.js
  27. +17 −15 lib/rules/no-pending-tests.js
  28. +14 −12 lib/rules/no-return-and-callback.js
  29. +14 −12 lib/rules/no-return-from-async.js
  30. +88 −86 lib/rules/no-setup-in-describe.js
  31. +36 −34 lib/rules/no-sibling-hooks.js
  32. +40 −62 lib/rules/no-skipped-tests.js
  33. +51 −48 lib/rules/no-synchronous-tests.js
  34. +26 −24 lib/rules/no-top-level-hooks.js
  35. +79 −37 lib/rules/valid-suite-description.js
  36. +78 −38 lib/rules/valid-test-description.js
  37. +0 −5 lib/util/ast.js
  38. +3,503 −0 package-lock.json
  39. +9 −8 package.json
  40. +1 −1 test/index.js
  41. +2 −1 test/rules/max-top-level-suites.js
  42. +14 −13 test/rules/no-hooks-for-single-case.js
  43. +46 −1 test/rules/no-hooks.js
  44. +30 −8 test/rules/valid-suite-description.js
  45. +26 −8 test/rules/valid-test-description.js
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -25,6 +25,10 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./build/lcov.info
parallel: true
coverage:
needs: build
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@master
with:
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
## 6.3.0 (February 19, 2020)

### Bug Fixes

* no-hooks-for-single-case: fix false postive in nested suites ([#238](https://github.com/lo1tuma/eslint-plugin-mocha/pull/238))
* Fix max-top-level-suites to ignore generated suites ([#239](https://github.com/lo1tuma/eslint-plugin-mocha/pull/239))
* Check static template strings in valid-test-description and valid-suite-description ([#237](https://github.com/lo1tuma/eslint-plugin-mocha/pull/237))

### Enhancements

* no-hooks: add option to allow certain kind of hooks ([#236](https://github.com/lo1tuma/eslint-plugin-mocha/pull/236))
* Add schemas for options (and remove for files which are using settings) ([#234](https://github.com/lo1tuma/eslint-plugin-mocha/pull/234))
* Add `u` flag in RegExp for `valid-test-description` and `valid-suite-description` ([#232](https://github.com/lo1tuma/eslint-plugin-mocha/pull/232))
* Add `fixable` property to fixable rules (and mention in docs) ([#228](https://github.com/lo1tuma/eslint-plugin-mocha/pull/228))
* add plugin to recommended config ([#226](https://github.com/lo1tuma/eslint-plugin-mocha/pull/226))

### Documentation

* Indicate whether rule is recommended ([#229](https://github.com/lo1tuma/eslint-plugin-mocha/pull/229))
* "Options" heading in doc files (and consistent level 2 heading) ([#233](https://github.com/lo1tuma/eslint-plugin-mocha/pull/233))
* Doc syntax issue ([#231](https://github.com/lo1tuma/eslint-plugin-mocha/pull/231))

### Code Refactoring

* Nondeprecated rule format ([#235](https://github.com/lo1tuma/eslint-plugin-mocha/pull/235))
* Alphabetize rule lists ([#227](https://github.com/lo1tuma/eslint-plugin-mocha/pull/227))

### Build-Related

* - npm: Add package-lock.json ([#230](https://github.com/lo1tuma/eslint-plugin-mocha/pull/230))
* ✉️ Send a webhook to Coveralls when the build completes ([#222](https://github.com/lo1tuma/eslint-plugin-mocha/pull/222))

## 6.2.2 (November 22, 2019)

### Bug Fixes
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![NPM Version](https://img.shields.io/npm/v/eslint-plugin-mocha.svg?style=flat)](https://www.npmjs.org/package/eslint-plugin-mocha)
[![Build Status](https://img.shields.io/travis/lo1tuma/eslint-plugin-mocha/master.svg?style=flat)](https://travis-ci.org/lo1tuma/eslint-plugin-mocha)
[![GitHub Actions status](https://github.com/lo1tuma/eslint-plugin-mocha/workflows/CI/badge.svg)](https://github.com/lo1tuma/eslint-plugin-mocha/actions)
[![Coverage Status](https://img.shields.io/coveralls/lo1tuma/eslint-plugin-mocha/master.svg?style=flat)](https://coveralls.io/r/lo1tuma/eslint-plugin-mocha)
[![Peer Dependencies](http://img.shields.io/david/peer/lo1tuma/eslint-plugin-mocha.svg?style=flat)](https://david-dm.org/lo1tuma/eslint-plugin-mocha#info=peerDependencies&view=table)
[![NPM Downloads](https://img.shields.io/npm/dm/eslint-plugin-mocha.svg?style=flat)](https://www.npmjs.org/package/eslint-plugin-mocha)
44 changes: 23 additions & 21 deletions docs/rules/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# Rules

* [handle-done-callback](handle-done-callback.md) - enforces handling of callbacks for async tests
* [max-top-level-suites](max-top-level-suites.md) - limit the number of top-level suites in a single file
* [no-exclusive-tests](no-exclusive-tests.md) - disallow exclusive mocha tests
* [no-global-tests](no-global-tests.md) - disallow global tests
* [no-hooks](no-hooks.md) - disallow hooks
* [no-hooks-for-single-case](no-hooks-for-single-case.md) - disallow hooks for a single test or test suite
* [no-identical-title](no-identical-title.md) - disallow identical titles
* [no-mocha-arrows](no-mocha-arrows.md) - disallow arrow functions as arguments to mocha globals
* [no-nested-tests](no-nested-tests.md) - disallow tests to be nested within other tests
* [no-pending-tests](no-pending-tests.md) - disallow pending/unimplemented mocha tests
* [no-return-and-callback](no-return-and-callback.md) - disallow returning in a test or hook function that uses a callback
* [no-return-from-async](no-return-from-async.md) - disallow returning from an async test or hook
* [no-setup-in-describe](no-setup-in-describe.md) - disallow calling functions and dot operators directly in describe blocks
* [no-sibling-hooks](no-sibling-hooks.md) - disallow duplicate uses of a hook at the same level inside a describe
* [no-skipped-tests](no-skipped-tests.md) - disallow skipped mocha tests (fixable)
* [no-synchronous-tests](no-synchronous-tests.md) - disallow synchronous tests
* [no-top-level-hooks](no-top-level-hooks.md) - disallow top-level hooks
* [prefer-arrow-callback](prefer-arrow-callback.md) - prefer arrow function callbacks (mocha-aware)
* [valid-suite-description](valid-suite-description.md) - match suite descriptions against a pre-configured regular expression
* [valid-test-description](valid-test-description.md) - match test descriptions against a pre-configured regular expression
* [no-async-describe](no-async-describe.md) - disallow async functions passed to describe
|recommended|fixable|rule|description|
|-|-|-|-|
|:heavy_check_mark:|| [handle-done-callback](handle-done-callback.md) | enforces handling of callbacks for async tests
|:heavy_check_mark:|| [max-top-level-suites](max-top-level-suites.md) | limit the number of top-level suites in a single file
|:heavy_check_mark:|:wrench:| [no-async-describe](no-async-describe.md) | disallow async functions passed to describe
|:heavy_check_mark:|| [no-exclusive-tests](no-exclusive-tests.md) | disallow exclusive mocha tests
|:heavy_check_mark:|| [no-global-tests](no-global-tests.md) | disallow global tests
||| [no-hooks](no-hooks.md) | disallow hooks
|:heavy_check_mark:|| [no-hooks-for-single-case](no-hooks-for-single-case.md) | disallow hooks for a single test or test suite
|:heavy_check_mark:|| [no-identical-title](no-identical-title.md) | disallow identical titles
|:heavy_check_mark:|:wrench:| [no-mocha-arrows](no-mocha-arrows.md) | disallow arrow functions as arguments to mocha globals
|:heavy_check_mark:|| [no-nested-tests](no-nested-tests.md) | disallow tests to be nested within other tests
|:heavy_check_mark:|| [no-pending-tests](no-pending-tests.md) | disallow pending/unimplemented mocha tests
|:heavy_check_mark:|| [no-return-and-callback](no-return-and-callback.md) | disallow returning in a test or hook function that uses a callback
||| [no-return-from-async](no-return-from-async.md) | disallow returning from an async test or hook
|:heavy_check_mark:|| [no-setup-in-describe](no-setup-in-describe.md) | disallow calling functions and dot operators directly in describe blocks
|:heavy_check_mark:|| [no-sibling-hooks](no-sibling-hooks.md) | disallow duplicate uses of a hook at the same level inside a describe
|:heavy_check_mark:|:wrench:| [no-skipped-tests](no-skipped-tests.md) | disallow skipped mocha tests
||| [no-synchronous-tests](no-synchronous-tests.md) | disallow synchronous tests
|:heavy_check_mark:|| [no-top-level-hooks](no-top-level-hooks.md) | disallow top-level hooks
||:wrench:| [prefer-arrow-callback](prefer-arrow-callback.md) | prefer arrow function callbacks (mocha-aware)
||| [valid-suite-description](valid-suite-description.md) | match suite descriptions against a pre-configured regular expression
||| [valid-test-description](valid-test-description.md) | match test descriptions against a pre-configured regular expression
2 changes: 2 additions & 0 deletions docs/rules/max-top-level-suites.md
Original file line number Diff line number Diff line change
@@ -33,6 +33,8 @@ describe('foo', function () {
});
```

## Options

If you want to change the suite limit to, for instance, 2 suites per file:

```js
2 changes: 2 additions & 0 deletions docs/rules/no-async-describe.md
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ describe('the thing', async function () {
});
```

**Fixable:** Problems detected by this rule are automatically fixable using the `--fix` flag on the command line.

## Rule Details

The rule supports "describe", "context" and "suite" suite function names and different valid suite name prefixes like "skip" or "only".
4 changes: 2 additions & 2 deletions docs/rules/no-exclusive-tests.md
Original file line number Diff line number Diff line change
@@ -49,9 +49,9 @@ suite.skip("bar", function () {});
test.skip("bar", function () {});
```

# Options
## Settings

This rule supports the following shared configuration options:
This rule supports the following shared configuration setting:

* `additionalTestFunctions`: An array of extra test functions to protect. This might be used with a custom Mocha extension, such as [`ember-mocha`](https://github.com/switchfly/ember-mocha)

2 changes: 1 addition & 1 deletion docs/rules/no-hooks-for-single-case.md
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ describe('foo', function () {
});
```

# Options
## Options

This rule supports the following options:

15 changes: 15 additions & 0 deletions docs/rules/no-hooks.md
Original file line number Diff line number Diff line change
@@ -43,6 +43,21 @@ describe('foo', function () {
});
```

## Options

This rule supports the following options:

* `allow`: An array containing the names of hooks to allow. Defaults to an empty array.

```json
{
"rules": {
"mocha/no-hooks": ["error", {"allow": ["after"]}]
}
}
```


## When Not To Use It

* If you use another library which exposes a similar API as mocha (e.g. `before`, `after`), you should turn this rule off, because it would raise warnings.
2 changes: 2 additions & 0 deletions docs/rules/no-mocha-arrows.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@

Mocha [discourages](http://mochajs.org/#arrow-functions) passing it arrow functions as arguments. This rule prevents their use on the Mocha globals.

**Fixable:** Problems detected by this rule are automatically fixable using the `--fix` flag on the command line.

## Rule Details

This rule looks for occurrences of the Mocha functions (`describe`, `it`, `beforeEach`, etc.) within the source code.
4 changes: 2 additions & 2 deletions docs/rules/no-skipped-tests.md
Original file line number Diff line number Diff line change
@@ -44,9 +44,9 @@ suite.only("bar", function () {});
test.only("bar", function () {});
```

# Options
## Settings

This rule supports the following shared configuration options:
This rule supports the following shared configuration settings:

* `additionalTestFunctions`: An array of extra test functions to protect. This might be used with a custom Mocha extension, such as [`ember-mocha`](https://github.com/switchfly/ember-mocha)
* `additionalXFunctions`: An array of extra x-function to protect
7 changes: 4 additions & 3 deletions docs/rules/no-synchronous-tests.md
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ By default, this rule looks for the presence of one of:
- An async function provided to a mocha test statement.
- A return statement within the function body of any mocha test statement.

If none of these three options is used in a test method, the rule will raise a warning.
If none of these three alternatives is used in a test method, the rule will raise a warning.

The following patterns are considered warnings:

@@ -37,9 +37,11 @@ it('should do foo', async function () {

it('should do foo', function () {
return promise;
}
});
```

## Options

You can change the acceptable asynchronous test methods to only allow a combination of async functions/callbacks/promises:

```js
@@ -48,7 +50,6 @@ rules: {
},
```

### Caveats:

This rule cannot guarantee that a returned function call is actually a promise, it only confirms that the return was made.
2 changes: 2 additions & 0 deletions docs/rules/prefer-arrow-callback.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ You will want to disable the original `prefer-arrow-callback` rule and configure
}
```

**Fixable:** Problems detected by this rule are automatically fixable using the `--fix` flag on the command line.

## Rule Overview

Arrow functions can be an attractive alternative to function expressions for callbacks or function arguments.
2 changes: 2 additions & 0 deletions docs/rules/valid-suite-description.md
Original file line number Diff line number Diff line change
@@ -42,6 +42,8 @@ context("Test suite", function() { });
suite("Test suite", function() { });
```

## Options

There is also possible to configure a custom list of suite names and a custom error message via the second and third rule configuration option:

```js
2 changes: 2 additions & 0 deletions docs/rules/valid-test-description.md
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@ This rule enforces the test descriptions to follow the desired format.
By default, the regular expression is configured to be "^should" which requires test descriptions to start with "should".
By default, the rule supports "it", "specify" and "test" test function names, but it can be configured to look for different test names via rule configuration.

## Options

Example of a custom rule configuration:

```js
32 changes: 17 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -2,33 +2,35 @@

module.exports = {
rules: {
'no-exclusive-tests': require('./lib/rules/no-exclusive-tests'),
'no-pending-tests': require('./lib/rules/no-pending-tests'),
'no-skipped-tests': require('./lib/rules/no-skipped-tests'),
'handle-done-callback': require('./lib/rules/handle-done-callback'),
'no-synchronous-tests': require('./lib/rules/no-synchronous-tests'),
'max-top-level-suites': require('./lib/rules/max-top-level-suites'),
'no-async-describe': require('./lib/rules/no-async-describe'),
'no-exclusive-tests': require('./lib/rules/no-exclusive-tests'),
'no-global-tests': require('./lib/rules/no-global-tests'),
'no-return-and-callback': require('./lib/rules/no-return-and-callback'),
'no-return-from-async': require('./lib/rules/no-return-from-async'),
'valid-test-description': require('./lib/rules/valid-test-description'),
'valid-suite-description': require('./lib/rules/valid-suite-description'),
'no-mocha-arrows': require('./lib/rules/no-mocha-arrows'),
'no-hooks': require('./lib/rules/no-hooks'),
'no-hooks-for-single-case': require('./lib/rules/no-hooks-for-single-case'),
'no-sibling-hooks': require('./lib/rules/no-sibling-hooks'),
'no-top-level-hooks': require('./lib/rules/no-top-level-hooks'),
'no-identical-title': require('./lib/rules/no-identical-title'),
'max-top-level-suites': require('./lib/rules/max-top-level-suites'),
'no-mocha-arrows': require('./lib/rules/no-mocha-arrows'),
'no-nested-tests': require('./lib/rules/no-nested-tests'),
'no-pending-tests': require('./lib/rules/no-pending-tests'),
'no-return-and-callback': require('./lib/rules/no-return-and-callback'),
'no-return-from-async': require('./lib/rules/no-return-from-async'),
'no-setup-in-describe': require('./lib/rules/no-setup-in-describe'),
'no-sibling-hooks': require('./lib/rules/no-sibling-hooks'),
'no-skipped-tests': require('./lib/rules/no-skipped-tests'),
'no-synchronous-tests': require('./lib/rules/no-synchronous-tests'),
'no-top-level-hooks': require('./lib/rules/no-top-level-hooks'),
'prefer-arrow-callback': require('./lib/rules/prefer-arrow-callback'),
'no-async-describe': require('./lib/rules/no-async-describe')
'valid-suite-description': require('./lib/rules/valid-suite-description'),
'valid-test-description': require('./lib/rules/valid-test-description')
},
configs: {
recommended: {
plugins: [ 'mocha' ],
rules: {
'mocha/handle-done-callback': 'error',
'mocha/max-top-level-suites': [ 'error', { limit: 1 } ],
'mocha/no-async-describe': 'error',
'mocha/no-exclusive-tests': 'warn',
'mocha/no-global-tests': 'error',
'mocha/no-hooks': 'off',
@@ -38,15 +40,15 @@ module.exports = {
'mocha/no-nested-tests': 'error',
'mocha/no-pending-tests': 'warn',
'mocha/no-return-and-callback': 'error',
'mocha/no-return-from-async': 'off',
'mocha/no-setup-in-describe': 'error',
'mocha/no-sibling-hooks': 'error',
'mocha/no-skipped-tests': 'warn',
'mocha/no-synchronous-tests': 'off',
'mocha/no-top-level-hooks': 'warn',
'mocha/prefer-arrow-callback': 'off',
'mocha/valid-suite-description': 'off',
'mocha/valid-test-description': 'off',
'mocha/no-async-describe': 'error'
'mocha/valid-test-description': 'off'
}
}
}
66 changes: 34 additions & 32 deletions lib/rules/handle-done-callback.js
Original file line number Diff line number Diff line change
@@ -3,46 +3,48 @@
const find = require('ramda/src/find');
const astUtils = require('../util/ast');

module.exports = function (context) {
function isAsyncFunction(functionExpression) {
return functionExpression.params.length === 1;
}
module.exports = {
create(context) {
function isAsyncFunction(functionExpression) {
return functionExpression.params.length === 1;
}

function findParamInScope(paramName, scope) {
return find(function (variable) {
return variable.name === paramName && variable.defs[0].type === 'Parameter';
}, scope.variables);
}
function findParamInScope(paramName, scope) {
return find(function (variable) {
return variable.name === paramName && variable.defs[0].type === 'Parameter';
}, scope.variables);
}

function isReferenceHandled(reference) {
const parent = context.getNodeByRangeIndex(reference.identifier.range[0]).parent;
function isReferenceHandled(reference) {
const parent = context.getNodeByRangeIndex(reference.identifier.range[0]).parent;

return parent.type === 'CallExpression';
}
return parent.type === 'CallExpression';
}

function hasHandledReferences(references) {
return references.some(isReferenceHandled);
}
function hasHandledReferences(references) {
return references.some(isReferenceHandled);
}

function checkAsyncMochaFunction(functionExpression) {
const scope = context.getScope();
const callback = functionExpression.params[0];
const callbackName = callback.name;
const callbackVariable = findParamInScope(callbackName, scope);
function checkAsyncMochaFunction(functionExpression) {
const scope = context.getScope();
const callback = functionExpression.params[0];
const callbackName = callback.name;
const callbackVariable = findParamInScope(callbackName, scope);

if (callbackVariable && !hasHandledReferences(callbackVariable.references)) {
context.report(callback, 'Expected "{{name}}" callback to be handled.', { name: callbackName });
if (callbackVariable && !hasHandledReferences(callbackVariable.references)) {
context.report(callback, 'Expected "{{name}}" callback to be handled.', { name: callbackName });
}
}
}

function check(node) {
if (astUtils.hasParentMochaFunctionCall(node) && isAsyncFunction(node)) {
checkAsyncMochaFunction(node);
function check(node) {
if (astUtils.hasParentMochaFunctionCall(node) && isAsyncFunction(node)) {
checkAsyncMochaFunction(node);
}
}
}

return {
FunctionExpression: check,
ArrowFunctionExpression: check
};
return {
FunctionExpression: check,
ArrowFunctionExpression: check
};
}
};
Loading