Skip to content

Commit 0d42767

Browse files
committed
Merge branch 'lint' into next
2 parents 89b5b14 + 7abf140 commit 0d42767

28 files changed

+15299
-9783
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/**
2+
coverage/**
3+
package-lock.json

.eslintrc.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const invalidCodeBlockRules = {
2+
// Invalid rules for embedded code-blocks
3+
"import/no-unresolved": "off",
4+
"no-undef": "off",
5+
"no-unused-expressions": "off",
6+
"no-unused-vars": "off",
7+
"no-unreachable": "off"
8+
};
9+
10+
module.exports = {
11+
root: true,
12+
overrides: [
13+
{
14+
files: ["*.ts"],
15+
excludedFiles: ["*.md/*.ts"],
16+
parser: "@typescript-eslint/parser",
17+
parserOptions: {
18+
project: "tsconfig.eslint.json",
19+
sourceType: "module"
20+
},
21+
plugins: ["@typescript-eslint", "eslint-plugin"],
22+
extends: [
23+
"eslint:recommended",
24+
"airbnb-base",
25+
"airbnb-typescript/base",
26+
"plugin:eslint-plugin/rules-recommended",
27+
"plugin:@typescript-eslint/recommended",
28+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
29+
"plugin:prettier/recommended"
30+
]
31+
},
32+
{
33+
files: ["tests/**"],
34+
env: {
35+
"jest/globals": true
36+
},
37+
extends: [
38+
"plugin:jest/recommended",
39+
"plugin:jest/style",
40+
"plugin:eslint-plugin/tests-recommended"
41+
],
42+
plugins: ["jest"],
43+
rules: {
44+
"import/no-extraneous-dependencies": [
45+
"error",
46+
{ devDependencies: true }
47+
]
48+
}
49+
},
50+
{
51+
files: ["*.js"],
52+
extends: [
53+
"eslint:recommended",
54+
"airbnb-base",
55+
"plugin:prettier/recommended"
56+
]
57+
},
58+
{
59+
files: ["*.md"],
60+
extends: ["plugin:mdx/recommended"],
61+
settings: {
62+
"mdx/code-blocks": true
63+
}
64+
},
65+
{
66+
// Markdown JS code-blocks (virtual filepath)
67+
files: ["**/*.md/*.js"],
68+
rules: {
69+
...invalidCodeBlockRules
70+
}
71+
}
72+
]
73+
};

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.prettierrc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"arrowParens": "always",
3+
"printWidth": 80,
4+
"proseWrap": "always",
5+
"quoteProps": "consistent",
6+
"semi": true,
7+
"singleQuote": false,
8+
"tabWidth": 4,
9+
"useTabs": false,
10+
"trailingComma": "none"
11+
}

.remarkrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"plugins": [
3+
"preset-lint-consistent",
4+
"preset-lint-markdown-style-guide",
5+
"preset-lint-recommended",
6+
"preset-prettier"
7+
]
8+
}

README.md

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,57 @@
1-
# eslint-plugin-testcafe-community
2-
3-
ESLint rules for [testcafe](https://github.com/DevExpress/testcafe) from the testcafe community.
4-
5-
## Installation
6-
7-
You'll first need to install [ESLint](http://eslint.org):
8-
9-
```
10-
npm i eslint --save-dev
11-
```
12-
13-
Next, install `eslint-plugin-testcafe-community`:
14-
15-
```
16-
npm install eslint-plugin-testcafe-community --save-dev
17-
```
18-
19-
**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-testcafe-community` globally.
20-
21-
## Recommended configuration
22-
23-
This plugin export a recommended configuration that enforce good practices.
24-
25-
To enable this configuration use the extends property in your .eslintrc config file:
26-
27-
```
28-
{
29-
"plugins": [
30-
"testcafe-community"
31-
],
32-
"extends": "plugin:testcafe-community/recommended"
33-
}
34-
```
35-
36-
See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information about extending configuration files.
37-
38-
## Supported Rules
39-
40-
✔️ indicates that a rule is recommended for all users.
41-
42-
🛠 indicates that a rule is fixable.
43-
1+
# eslint-plugin-testcafe-community
2+
3+
ESLint rules for [testcafe](https://github.com/DevExpress/testcafe) from the
4+
testcafe community.
5+
6+
## Installation
7+
8+
You'll first need to install [ESLint](http://eslint.org):
9+
10+
```sh
11+
npm i eslint --save-dev
12+
```
13+
14+
Next, install `eslint-plugin-testcafe-community`:
15+
16+
```sh
17+
npm install eslint-plugin-testcafe-community --save-dev
18+
```
19+
20+
**Note:** If you installed ESLint globally (using the `-g` flag) then you must
21+
also install `eslint-plugin-testcafe-community` globally.
22+
23+
## Recommended configuration
24+
25+
This plugin export a recommended configuration that enforce good practices.
26+
27+
To enable this configuration use the extends property in your .eslintrc config
28+
file:
29+
30+
```json
31+
{
32+
"plugins": ["testcafe-community"],
33+
"extends": "plugin:testcafe-community/recommended"
34+
}
35+
```
36+
37+
See
38+
[ESLint documentation](http://eslint.org/docs/user-guide/configuring#extending-configuration-files)
39+
for more information about extending configuration files.
40+
41+
## Supported Rules
42+
43+
✔️ indicates that a rule is recommended for all users.
44+
45+
🛠 indicates that a rule is fixable.
46+
4447
<!-- __BEGIN AUTOGENERATED RULES TABLE__ -->
45-
| Name | ✔️ | 🛠 | Description |
46-
| ----- | ----- | ----- | ----------- |
47-
| [expectExpect](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/expectExpect.md) | ✔️ | | Ensure tests have at least one expect |
48-
| [noDebug](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noDebug.md) | ✔️ | | Don't allow `t.debug()` to be committed to the repository. |
49-
| [noIdenticalTitle](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noIdenticalTitle.md) | ✔️ | | Don't use identical titles for your tests |
50-
| [noOnly](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noOnly.md) | ✔️ | | Don't allow `test.only` to be added to the repository |
51-
| [noSkip](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noSkip.md) | ✔️ | | Don't allow `test.skip` or `fixture.skip` to be added to the repository |
52-
<!-- __END AUTOGENERATED RULES TABLE__ -->
48+
49+
| Name | ✔️ | 🛠 | Description |
50+
| ------------------------------------------------------------------------------------------------------------------------------------- | --- | --- | ----------------------------------------------------------------------- |
51+
| [expectExpect](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/expectExpect.md) | ✔️ | | Ensure tests have at least one expect |
52+
| [noDebug](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noDebug.md) | ✔️ | | Don't allow `t.debug()` to be committed to the repository. |
53+
| [noIdenticalTitle](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noIdenticalTitle.md) | ✔️ | | Don't use identical titles for your tests |
54+
| [noOnly](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noOnly.md) | ✔️ | | Don't allow `test.only` to be added to the repository |
55+
| [noSkip](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noSkip.md) | ✔️ | | Don't allow `test.skip` or `fixture.skip` to be added to the repository |
56+
57+
<!-- __END AUTOGENERATED RULES TABLE__ -->

build/generate-readme-table.ts

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,65 @@
1-
"use strict";
1+
import fs from "fs";
2+
import path from "path";
3+
import { rules } from "../lib";
4+
import { repository } from "../package.json";
25

3-
const fs = require("fs");
4-
const path = require("path");
5-
const { rules } = require("../lib");
6-
const { repository } = require("../package.json");
76
const repoURL = repository.url.replace(/^git:\/\//, "");
87

98
const README_LOCATION = path.resolve(__dirname, "..", "README.md");
109
const BEGIN_TABLE_MARKER = "<!-- __BEGIN AUTOGENERATED RULES TABLE__ -->";
1110
const END_TABLE_MARKER = "<!-- __END AUTOGENERATED RULES TABLE__ -->";
1211

1312
const expectedTableLines = Object.keys(rules)
14-
.sort()
15-
.reduce(
16-
(lines, ruleId) => {
17-
const rule = rules[ruleId];
13+
.sort()
14+
.reduce(
15+
(lines, ruleId) => {
16+
const rule = rules[ruleId];
1817

19-
const tr = [
20-
`[${ruleId}](https://${repoURL}/blob/master/docs/rules/${ruleId}.md)`,
21-
rule.meta.docs.recommended ? "✔️" : "",
22-
rule.meta.fixable ? "🛠" : "",
23-
rule.meta.docs.description
24-
].join(" | ")
18+
const tr = [
19+
`[${ruleId}](https://${repoURL}/blob/master/docs/rules/${ruleId}.md)`,
20+
rule.meta.docs.recommended ? "✔️" : "",
21+
rule.meta.fixable ? "🛠" : "",
22+
rule.meta.docs.description
23+
].join(" | ");
2524

26-
lines.push(`| ${tr} |`);
25+
lines.push(`| ${tr} |`);
2726

28-
return lines;
29-
},
30-
[
31-
"| Name | ✔️ | 🛠 | Description |",
32-
"| ----- | ----- | ----- | ----------- |"
33-
]
34-
)
35-
.join("\n");
27+
return lines;
28+
},
29+
[
30+
"| Name | ✔️ | 🛠 | Description |",
31+
"| ----- | ----- | ----- | ----------- |"
32+
]
33+
)
34+
.join("\n");
3635

3736
const readmeContents = fs.readFileSync(README_LOCATION, "utf8");
3837

3938
if (!readmeContents.includes(BEGIN_TABLE_MARKER)) {
40-
throw new Error(
41-
`Could not find '${BEGIN_TABLE_MARKER}' marker in README.md.`
42-
);
39+
throw new Error(
40+
`Could not find '${BEGIN_TABLE_MARKER}' marker in README.md.`
41+
);
4342
}
4443

4544
if (!readmeContents.includes(END_TABLE_MARKER)) {
46-
throw new Error(`Could not find '${END_TABLE_MARKER}' marker in README.md.`);
45+
throw new Error(
46+
`Could not find '${END_TABLE_MARKER}' marker in README.md.`
47+
);
4748
}
4849

4950
const linesStartIndex =
50-
readmeContents.indexOf(BEGIN_TABLE_MARKER) + BEGIN_TABLE_MARKER.length;
51+
readmeContents.indexOf(BEGIN_TABLE_MARKER) + BEGIN_TABLE_MARKER.length;
5152
const linesEndIndex = readmeContents.indexOf(END_TABLE_MARKER);
5253

5354
const updatedReadmeContents = [
54-
readmeContents.slice(0, linesStartIndex),
55-
expectedTableLines,
56-
readmeContents.slice(linesEndIndex)
55+
readmeContents.slice(0, linesStartIndex),
56+
expectedTableLines,
57+
readmeContents.slice(linesEndIndex)
5758
].join("\n");
5859

5960
if (require.main === module) {
60-
// Run on command line
61-
fs.writeFileSync(README_LOCATION, updatedReadmeContents);
61+
// Run on command line
62+
fs.writeFileSync(README_LOCATION, updatedReadmeContents);
6263
} else {
63-
module.exports = updatedReadmeContents;
64+
module.exports = updatedReadmeContents;
6465
}

docs/rules/expect-expect.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
# All tests should have at least one assertion via t.expect(). (expect-expect)
1+
# All tests should have at least one assertion via t.expect(). (expect-expect)
22

33
## Rule Details
44

5-
This rule aims to ensure a `t.expect()` function call exists within a defined test block. There maybe times in local development you don't have an assertion defined, but this rule aims to prevent a test case from being accidentally committed and falsfully report a pass when it doesn't test any condition.
5+
This rule aims to ensure a `t.expect()` function call exists within a defined
6+
test block. There maybe times in local development you don't have an assertion
7+
defined, but this rule aims to prevent a test case from being accidentally
8+
committed and falsfully report a pass when it doesn't test any condition.
69

710
Examples of **incorrect** code for this rule:
811

912
```js
10-
// Example 1: Forgot to add an assertion but provided an action
11-
test('should do stuff', async (t) => {
12-
await t.click(Selector("foo"))
13-
})
14-
15-
// Example 2: empty test scaffolding
16-
test('test something', (t) => {
17-
// TODO: Test something
18-
})
13+
// Example 1: Forgot to add an assertion but provided an action
14+
test("should do stuff", async (t) => {
15+
await t.click(Selector("foo"));
16+
});
17+
18+
// Example 2: empty test scaffolding
19+
test("test something", (t) => {
20+
// TODO: Test something
21+
});
1922
```
2023

2124
Examples of **correct** code for this rule:
2225

2326
```js
24-
test('should change text to clicked', async (t) => {
25-
const text = Selector("bar")
26-
await t.click(Selector("foo"))
27-
await t.expect(text).toEqual("button clicked") // Makes an assertion
28-
})
27+
test("should change text to clicked", async (t) => {
28+
const text = Selector("bar");
29+
await t.click(Selector("foo"));
30+
await t.expect(text).toEqual("button clicked"); // Makes an assertion
31+
});
2932
```
3033

3134
## When Not To Use It

0 commit comments

Comments
 (0)