Skip to content

Commit

Permalink
Tidy up readme and make some minor syntax changes
Browse files Browse the repository at this point in the history
  • Loading branch information
levibuzolic committed Aug 13, 2021
1 parent ab5266f commit c6db141
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

[![Version](https://img.shields.io/npm/v/eslint-plugin-no-only-tests.svg)](https://www.npmjs.com/package/eslint-plugin-no-only-tests) [![Downloads](https://img.shields.io/npm/dm/eslint-plugin-no-only-tests.svg)](https://npmcharts.com/compare/eslint-plugin-no-only-tests?minimal=true) [![GitHub Tests](https://github.com/levibuzolic/eslint-plugin-no-only-tests/workflows/Tests/badge.svg)](https://github.com/levibuzolic/eslint-plugin-no-only-tests/actions?query=workflow%3ATests)

ESLint rule for `.only` tests in [mocha](https://mochajs.org/) and other JS testing libraries.
ESLint rule for `.only` tests in [mocha](https://mochajs.org/), [jest](https://jestjs.io/), [jasmin](https://jasmine.github.io/) and other JS testing libraries.

Currently matches the following test blocks by default: `describe`, `it`, `context`, `tape`, `test`, `fixture`, `serial`.
By default the following test blocks are matched by default: `describe`, `it`, `context`, `tape`, `test`, `fixture`, `serial`.

Designed to prevent you from committing `.only` tests to CI, disabling tests for your whole team.
Designed to prevent you from committing focused (`.only`) tests to CI, which may prevent your entire test suite from running.

As of v2.3 you can now override the test blocks and focus functions.
If the testing framework you use doesn't use `.only` to focus tests, you can override the matchers with [options](#options).

## Installation

First you'll need to install [ESLint](http://eslint.org) then the plugin:
[Install ESLint](https://eslint.org/docs/user-guide/getting-started) if you haven't done so already, then install `eslint-plugin-no-only-tests`:

```bash
npm install --save-dev eslint eslint-plugin-no-only-tests
npm install --save-dev eslint-plugin-no-only-tests
# or
yarn add --dev eslint eslint-plugin-no-only-tests
yarn add --dev eslint-plugin-no-only-tests
```

> **Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-no-only-tests` globally.
Expand All @@ -27,26 +27,29 @@ yarn add --dev eslint eslint-plugin-no-only-tests
Add `no-only-tests` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:

```json
{
"plugins": [
"no-only-tests"
]
}
"plugins": [
"no-only-tests"
]
```

Then configure the rules you want to use under the rules section.
Then add the rule to the rules section of your `.eslintrc`:

```json
"rules": {
"no-only-tests/no-only-tests": "error"
}
```

If you use a testing framework that uses an unsupported block name, or a different way of focusing test (something other than `.only`) you can specify an array of blocks and focus methods to match in the options.
If you use a testing framework that uses a test block name that isn't present in the [defaults](#options), or a different way of focusing test (something other than `.only`) you can specify an array of blocks and focus methods to match in the options.

```json
"rules": {
"no-only-tests/no-only-tests": ["error", {"block": ["test", "it", "assert"], "focus": ["only", "focus"]}]
"no-only-tests/no-only-tests": [
"error", {
"block": ["test", "it", "assert"],
"focus": ["only", "focus"]
}
]
}
```

Expand Down
12 changes: 6 additions & 6 deletions rules/no-only-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ module.exports = {
],
},
create(context) {
var options = context.options[0] || {};
var block = options.block || BLOCK_DEFAULTS;
var focus = options.focus || FOCUS_DEFAULTS;
var fix = !!options.fix;
const options = context.options[0] || {};
const block = options.block || BLOCK_DEFAULTS;
const focus = options.focus || FOCUS_DEFAULTS;
const fix = !!options.fix;

return {
Identifier(node) {
var parentObject = node.parent && node.parent.object;
const parentObject = node.parent && node.parent.object;
if (parentObject == null) return;
if (focus.indexOf(node.name) === -1) return;

var callPath = getCallPath(node.parent).join('.');
const callPath = getCallPath(node.parent).join('.');

// comparison guarantees that matching is done with the beginning of call path
if (block.find(b => callPath.split(b)[0] === '')) {
Expand Down

0 comments on commit c6db141

Please sign in to comment.