Skip to content

Commit b570537

Browse files
committed
Merge remote-tracking branch 'origin/main' into alpha
2 parents c0b01b0 + 137dc26 commit b570537

13 files changed

+118
-84
lines changed

.eslint-doc-generatorrc.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const prettier = require('prettier');
2+
const prettierConfig = require('./.prettierrc.js');
3+
4+
/** @type {import('eslint-doc-generator').GenerateOptions} */
5+
const config = {
6+
postprocess: (content) =>
7+
prettier.format(content, { ...prettierConfig, parser: 'markdown' }),
8+
};
9+
10+
module.exports = config;

.eslintrc.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module.exports = {
2+
root: true,
3+
extends: [
4+
'kentcdodds',
5+
'plugin:jest/recommended',
6+
'plugin:jest-formatting/recommended',
7+
'prettier',
8+
],
9+
rules: {
10+
// Base
11+
'max-lines-per-function': 'off',
12+
'no-restricted-imports': [
13+
'error',
14+
{
15+
patterns: [
16+
{
17+
group: ['@typescript-eslint/utils/dist/*'],
18+
message: 'Import from `@typescript-eslint/utils` instead.',
19+
},
20+
],
21+
},
22+
],
23+
24+
// Import
25+
'import/order': [
26+
'warn',
27+
{
28+
groups: ['builtin', 'external', 'parent', 'sibling', 'index'],
29+
'newlines-between': 'always',
30+
alphabetize: {
31+
order: 'asc',
32+
caseInsensitive: false,
33+
},
34+
},
35+
],
36+
},
37+
overrides: [
38+
{
39+
// TypeScript
40+
files: ['**/*.ts?(x)'],
41+
parser: '@typescript-eslint/parser',
42+
parserOptions: {
43+
tsconfigRootDir: __dirname,
44+
project: ['./tsconfig.eslint.json'],
45+
},
46+
extends: [
47+
'plugin:@typescript-eslint/recommended',
48+
'plugin:@typescript-eslint/recommended-requiring-type-checking',
49+
],
50+
rules: {
51+
'@typescript-eslint/explicit-function-return-type': 'off',
52+
'@typescript-eslint/no-unused-vars': [
53+
'warn',
54+
{ argsIgnorePattern: '^_' },
55+
],
56+
'@typescript-eslint/no-use-before-define': 'off',
57+
},
58+
},
59+
],
60+
};

.eslintrc.json

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/pipeline.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ name: Pipeline
33
on:
44
push:
55
branches:
6-
# semantic-release valid branches, excluding all-contributors
6+
# semantic-release valid branches
77
- '+([0-9])?(.{+([0-9]),x}).x'
88
- 'main'
99
- 'next'
1010
- 'next-major'
1111
- 'beta'
1212
- 'alpha'
13-
- '!all-contributors/**'
1413
pull_request:
1514
types: [opened, synchronize]
1615

@@ -46,15 +45,16 @@ jobs:
4645
run: npm run format:check
4746

4847
- name: Check autogenerated docs
49-
run: npm run docs:gen && npm run format && git diff --exit-code
48+
run: npm run generate-all && git diff --exit-code
5049

5150
tests:
5251
name: Tests (Node v${{ matrix.node }} - ESLint v${{ matrix.eslint }})
5352
runs-on: ubuntu-latest
5453

5554
strategy:
5655
matrix:
57-
node: [12.22.0, 12, 14.17.0, 14, '16.0', 16, '18.0', 18]
56+
# The .x indicates "the most recent one"
57+
node: [19.x, 18.x, 17.x, 16.x, 14.x, 14.17.0, 12.x, 12.22.0]
5858
eslint: [7.5, 7, 8]
5959

6060
steps:

.github/workflows/smoke-test.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@ jobs:
1111
test:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
15-
- uses: actions/setup-node@v3
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
17+
- name: Use Node
18+
uses: actions/setup-node@v3
1619
with:
1720
node-version-file: '.nvmrc'
18-
cache: 'npm'
21+
1922
- run: |
2023
npm install
2124
npm run build
25+
2226
- run: npm link
2327
working-directory: ./dist
28+
2429
- run: npm link eslint-plugin-testing-library
30+
2531
- uses: AriPerkkio/eslint-remote-tester-run-action@v3
2632
with:
2733
issue-title: 'Results of weekly scheduled smoke test'

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
package-lock=false
22
auto-install-peers=true
3+
enable-pre-post-scripts=true

CONTRIBUTING.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ The following will be run on every commit:
3838
- Check all tests are passing
3939
- Check commit message is following [Conventional Commit specification](https://www.conventionalcommits.org/en/v1.0.0/)
4040
41-
If you ever need to update a snapshot, you can run `npm run test:update`
42-
4341
## Rule naming conventions
4442
4543
Based on [ESLint's Rule Naming Conventions](https://eslint.org/docs/developer-guide/working-with-rules#rule-naming-conventions), you must follow these rules:
@@ -65,7 +63,7 @@ each rule has three files named with its identifier (e.g. `no-debugging-utils`):
6563
6664
Additionally, you need to do a couple of extra things:
6765
68-
- Run `npm run generate:rules-list` to include your rule in the "Supported Rules" table within the [README.md](./README.md)
66+
- Run `npm run generate:rules-doc` to include your rule in the "Supported Rules" table within the [README.md](./README.md)
6967
7068
### Custom rule creator
7169

lib/rules/no-await-sync-events.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,16 @@ export default createTestingLibraryRule<Options, MessageIds>({
151151
return;
152152
}
153153

154+
const eventModuleName = getPropertyIdentifierNode(node)?.name;
155+
const eventFullName = eventModuleName
156+
? `${eventModuleName}.${simulateEventFunctionName}`
157+
: simulateEventFunctionName;
158+
154159
context.report({
155160
node,
156161
messageId: 'noAwaitSyncEvents',
157162
data: {
158-
name: `${
159-
getPropertyIdentifierNode(node)?.name
160-
}.${simulateEventFunctionName}`,
163+
name: eventFullName,
161164
},
162165
});
163166
},

lib/rules/no-dom-import.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ const DOM_TESTING_LIBRARY_MODULES = [
1212
'@testing-library/dom',
1313
];
1414

15-
const correctModuleNameByFramework = {
15+
const CORRECT_MODULE_NAME_BY_FRAMEWORK: Record<
16+
'angular' | 'marko' | string,
17+
string | undefined
18+
> = {
1619
angular: '@testing-library/angular', // ATL is *always* called `@testing-library/angular`
1720
marko: '@marko/testing-library', // Marko TL is called `@marko/testing-library`
1821
};
19-
const getCorrectModuleName = (moduleName: string, framework: string): string =>
20-
correctModuleNameByFramework[framework] ||
21-
moduleName.replace('dom', framework);
22+
const getCorrectModuleName = (
23+
moduleName: string,
24+
framework: string
25+
): string => {
26+
return (
27+
CORRECT_MODULE_NAME_BY_FRAMEWORK[framework] ??
28+
moduleName.replace('dom', framework)
29+
);
30+
};
2231

2332
export default createTestingLibraryRule<Options, MessageIds>({
2433
name: RULE_NAME,

lib/rules/no-wait-for-snapshot.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ export default createTestingLibraryRule<Options, MessageIds>({
6868
}
6969

7070
return {
71-
[`Identifier[name=${SNAPSHOT_REGEXP}]`](node: TSESTree.Identifier) {
71+
[`Identifier[name=${String(SNAPSHOT_REGEXP)}]`](
72+
node: TSESTree.Identifier
73+
) {
7274
const closestAsyncUtil = getClosestAsyncUtil(node);
7375
if (closestAsyncUtil === null) {
7476
return;

lib/utils/file-import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copied from https://github.com/babel/babel/blob/b35c78f08dd854b08575fc66ebca323fdbc59dab/packages/babel-helpers/src/helpers.js#L615-L619
22
// eslint-disable-next-line @typescript-eslint/no-explicit-any
33
const interopRequireDefault = <T>(obj: any): { default: T } =>
4-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
4+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-return
55
obj?.__esModule ? obj : { default: obj };
66

77
export const importDefault = <T>(moduleName: string): T =>

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "eslint-plugin-testing-library",
33
"version": "0.0.0-semantically-released",
4-
"description": "ESLint rules for Testing Library",
4+
"description": "ESLint plugin to follow best practices and anticipate common mistakes when writing tests with Testing Library",
55
"keywords": [
66
"eslint",
77
"eslintplugin",
@@ -21,16 +21,17 @@
2121
"license": "MIT",
2222
"author": {
2323
"name": "Mario Beltrán Alarcón",
24-
"email": "[email protected]",
24+
"email": "[email protected]",
2525
"url": "https://mario.dev/"
2626
},
2727
"main": "index.js",
2828
"scripts": {
29+
"prebuild": "del-cli dist",
2930
"build": "tsc",
3031
"postbuild": "cpy README.md ./dist && cpy package.json ./dist && cpy LICENSE ./dist",
31-
"docs:gen": "run-p \"docs:gen:*\"",
32-
"docs:gen:configs": "ts-node tools/generate-configs",
33-
"docs:gen:rules-list": "npm run build && npm run rule-doc-generator && npm run format",
32+
"generate-all": "run-p \"generate:*\"",
33+
"generate:configs": "ts-node tools/generate-configs",
34+
"generate:rules-doc": "npm run build && npm run rule-doc-generator",
3435
"format": "npm run prettier-base -- --write",
3536
"format:check": "npm run prettier-base -- --check",
3637
"lint": "eslint . --max-warnings 0 --ext .js,.ts",
@@ -41,7 +42,6 @@
4142
"semantic-release": "semantic-release",
4243
"test": "jest",
4344
"test:ci": "jest --ci --coverage",
44-
"test:update": "npm run test -- --u",
4545
"test:watch": "npm run test -- --watch",
4646
"type-check": "tsc --noEmit"
4747
},
@@ -59,6 +59,7 @@
5959
"@typescript-eslint/eslint-plugin": "^5.43.0",
6060
"@typescript-eslint/parser": "^5.43.0",
6161
"cpy-cli": "^4.2.0",
62+
"del-cli": "^5.0.0",
6263
"eslint": "^8.28.0",
6364
"eslint-config-kentcdodds": "^20.4.0",
6465
"eslint-config-prettier": "^8.5.0",
@@ -70,13 +71,13 @@
7071
"eslint-plugin-prettier": "^4.2.1",
7172
"eslint-plugin-promise": "^6.1.1",
7273
"eslint-remote-tester": "^3.0.0",
73-
"eslint-remote-tester-repositories": "^0.0.7",
74+
"eslint-remote-tester-repositories": "^1.0.0",
7475
"husky": "^8.0.2",
7576
"is-ci": "^3.0.1",
7677
"jest": "^28.1.3",
7778
"lint-staged": "^13.0.3",
7879
"npm-run-all": "^4.1.5",
79-
"prettier": "2.8.0",
80+
"prettier": "2.8.1",
8081
"semantic-release": "^19.0.5",
8182
"ts-jest": "^28.0.8",
8283
"ts-node": "^10.9.1",

tests/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ it('should export configs that refer to actual rules', () => {
6767
expect(rule.startsWith(ruleNamePrefix)).toBe(true);
6868
expect(ruleNames).toContain(ruleName);
6969

70+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
7071
expect(() => require(`../lib/rules/${ruleName}`)).not.toThrow();
7172
});
7273
});

0 commit comments

Comments
 (0)