Skip to content

Commit

Permalink
chore: document rules that support suggestions in README
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Jun 20, 2020
1 parent f67f56f commit 7e4e37a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ installations requiring long-term consistency.
| [no-mocks-import](docs/rules/no-mocks-import.md) | Disallow manually importing from **mocks** | ![recommended][] | |
| [no-restricted-matchers](docs/rules/no-restricted-matchers.md) | Disallow specific matchers & modifiers | | |
| [no-standalone-expect](docs/rules/no-standalone-expect.md) | Prevents expects that are outside of an it or test block. | ![recommended][] | |
| [no-test-callback](docs/rules/no-test-callback.md) | Avoid using a callback in asynchronous tests | ![recommended][] | ![fixable][] |
| [no-test-callback](docs/rules/no-test-callback.md) | Avoid using a callback in asynchronous tests | ![recommended][] | ![suggest][] |
| [no-test-prefixes](docs/rules/no-test-prefixes.md) | Use `.only` and `.skip` over `f` and `x` | ![recommended][] | ![fixable][] |
| [no-test-return-statement](docs/rules/no-test-return-statement.md) | Disallow explicitly returning from tests | | |
| [no-try-expect](docs/rules/no-try-expect.md) | Prefer using toThrow for exception tests | ![recommended][] | |
| [prefer-called-with](docs/rules/prefer-called-with.md) | Suggest using `toBeCalledWith()` OR `toHaveBeenCalledWith()` | | |
| [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | |
| [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | ![suggest][] |
| [prefer-hooks-on-top](docs/rules/prefer-hooks-on-top.md) | Suggest to have all hooks at top level | | |
| [prefer-spy-on](docs/rules/prefer-spy-on.md) | Suggest using `jest.spyOn()` | | ![fixable][] |
| [prefer-strict-equal](docs/rules/prefer-strict-equal.md) | Suggest using toStrictEqual() | | ![fixable][] |
| [prefer-strict-equal](docs/rules/prefer-strict-equal.md) | Suggest using toStrictEqual() | | ![suggest][] |
| [prefer-to-be-null](docs/rules/prefer-to-be-null.md) | Suggest using `toBeNull()` | ![style][] | ![fixable][] |
| [prefer-to-be-undefined](docs/rules/prefer-to-be-undefined.md) | Suggest using `toBeUndefined()` | ![style][] | ![fixable][] |
| [prefer-to-contain](docs/rules/prefer-to-contain.md) | Suggest using `toContain()` | ![style][] | ![fixable][] |
Expand Down Expand Up @@ -186,5 +186,6 @@ ensure consistency and readability in jest test suites.
https://github.com/dangreenisrael/eslint-plugin-jest-formatting

[recommended]: https://img.shields.io/badge/-recommended-lightgrey.svg
[suggest]: https://img.shields.io/badge/-suggest-yellow.svg
[fixable]: https://img.shields.io/badge/-fixable-green.svg
[style]: https://img.shields.io/badge/-style-blue.svg
22 changes: 15 additions & 7 deletions tools/generate-rules-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

import * as fs from 'fs';
import * as path from 'path';
import ESLint from 'eslint';
import { TSESLint } from '@typescript-eslint/experimental-utils';
import prettier from 'prettier';
import config from '../src/index';

type FixType = 'fixable' | 'suggest';

interface RuleDetails {
name: string;
description: string;
fixable: boolean;
fixable: FixType | false;
}

type RuleModule = TSESLint.RuleModule<string, unknown[]>;

const staticElements = {
listHeaderRow: ['Rule', 'Description', 'Configurations', 'Fixable'],
listSpacerRow: Array(5).fill('-'),
Expand All @@ -33,7 +37,7 @@ const buildRuleRow = (rule: RuleDetails): string[] => [
`[${rule.name}](docs/rules/${rule.name}.md)`,
rule.description,
getConfigurationColumnValueForRule(rule),
rule.fixable ? '![fixable][]' : '',
rule.fixable ? `![${rule.fixable}][]` : '',
];

const generateRulesListMarkdown = (details: RuleDetails[]): string =>
Expand Down Expand Up @@ -77,24 +81,28 @@ const importDefault = (moduleName: string) =>
// eslint-disable-next-line @typescript-eslint/no-require-imports
interopRequireDefault(require(moduleName)).default;

const requireJestRule = (name: string): ESLint.Rule.RuleModule =>
const requireJestRule = (name: string): RuleModule =>
importDefault(
`../src/rules/${name}`,
// path.join('..', 'src', 'rules', name),
) as ESLint.Rule.RuleModule;
) as RuleModule;

const details: RuleDetails[] = Object.keys(config.configs.all.rules)
.map(name => name.split('/')[1])
.map(name => [name, requireJestRule(name)] as const)
.filter(
(nameAndRule): nameAndRule is [string, Required<ESLint.Rule.RuleModule>] =>
(nameAndRule): nameAndRule is [string, Required<RuleModule>] =>
!!nameAndRule[1].meta && !nameAndRule[1].meta.deprecated,
)
.map(
([name, rule]): RuleDetails => ({
name,
description: rule.meta.docs?.description ?? '',
fixable: !!rule.meta.fixable,
fixable: rule.meta.fixable
? 'fixable'
: rule.meta.docs?.suggestion
? 'suggest'
: false,
}),
);

Expand Down

0 comments on commit 7e4e37a

Please sign in to comment.