Skip to content

Commit

Permalink
Merge branch 'lint' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
codejedi365 committed Oct 5, 2021
2 parents 89b5b14 + 7abf140 commit 0d42767
Show file tree
Hide file tree
Showing 28 changed files with 15,299 additions and 9,783 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/**
coverage/**
package-lock.json
73 changes: 73 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const invalidCodeBlockRules = {
// Invalid rules for embedded code-blocks
"import/no-unresolved": "off",
"no-undef": "off",
"no-unused-expressions": "off",
"no-unused-vars": "off",
"no-unreachable": "off"
};

module.exports = {
root: true,
overrides: [
{
files: ["*.ts"],
excludedFiles: ["*.md/*.ts"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.eslint.json",
sourceType: "module"
},
plugins: ["@typescript-eslint", "eslint-plugin"],
extends: [
"eslint:recommended",
"airbnb-base",
"airbnb-typescript/base",
"plugin:eslint-plugin/rules-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:prettier/recommended"
]
},
{
files: ["tests/**"],
env: {
"jest/globals": true
},
extends: [
"plugin:jest/recommended",
"plugin:jest/style",
"plugin:eslint-plugin/tests-recommended"
],
plugins: ["jest"],
rules: {
"import/no-extraneous-dependencies": [
"error",
{ devDependencies: true }
]
}
},
{
files: ["*.js"],
extends: [
"eslint:recommended",
"airbnb-base",
"plugin:prettier/recommended"
]
},
{
files: ["*.md"],
extends: ["plugin:mdx/recommended"],
settings: {
"mdx/code-blocks": true
}
},
{
// Markdown JS code-blocks (virtual filepath)
files: ["**/*.md/*.js"],
rules: {
...invalidCodeBlockRules
}
}
]
};
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
11 changes: 11 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"arrowParens": "always",
"printWidth": 80,
"proseWrap": "always",
"quoteProps": "consistent",
"semi": true,
"singleQuote": false,
"tabWidth": 4,
"useTabs": false,
"trailingComma": "none"
}
8 changes: 8 additions & 0 deletions .remarkrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"plugins": [
"preset-lint-consistent",
"preset-lint-markdown-style-guide",
"preset-lint-recommended",
"preset-prettier"
]
}
107 changes: 56 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,57 @@
# eslint-plugin-testcafe-community

ESLint rules for [testcafe](https://github.com/DevExpress/testcafe) from the testcafe community.

## Installation

You'll first need to install [ESLint](http://eslint.org):

```
npm i eslint --save-dev
```

Next, install `eslint-plugin-testcafe-community`:

```
npm install eslint-plugin-testcafe-community --save-dev
```

**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-testcafe-community` globally.

## Recommended configuration

This plugin export a recommended configuration that enforce good practices.

To enable this configuration use the extends property in your .eslintrc config file:

```
{
"plugins": [
"testcafe-community"
],
"extends": "plugin:testcafe-community/recommended"
}
```

See [ESLint documentation](http://eslint.org/docs/user-guide/configuring#extending-configuration-files) for more information about extending configuration files.

## Supported Rules

✔️ indicates that a rule is recommended for all users.

🛠 indicates that a rule is fixable.

# eslint-plugin-testcafe-community

ESLint rules for [testcafe](https://github.com/DevExpress/testcafe) from the
testcafe community.

## Installation

You'll first need to install [ESLint](http://eslint.org):

```sh
npm i eslint --save-dev
```

Next, install `eslint-plugin-testcafe-community`:

```sh
npm install eslint-plugin-testcafe-community --save-dev
```

**Note:** If you installed ESLint globally (using the `-g` flag) then you must
also install `eslint-plugin-testcafe-community` globally.

## Recommended configuration

This plugin export a recommended configuration that enforce good practices.

To enable this configuration use the extends property in your .eslintrc config
file:

```json
{
"plugins": ["testcafe-community"],
"extends": "plugin:testcafe-community/recommended"
}
```

See
[ESLint documentation](http://eslint.org/docs/user-guide/configuring#extending-configuration-files)
for more information about extending configuration files.

## Supported Rules

✔️ indicates that a rule is recommended for all users.

🛠 indicates that a rule is fixable.

<!-- __BEGIN AUTOGENERATED RULES TABLE__ -->
| Name | ✔️ | 🛠 | Description |
| ----- | ----- | ----- | ----------- |
| [expectExpect](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/expectExpect.md) | ✔️ | | Ensure tests have at least one expect |
| [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. |
| [noIdenticalTitle](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noIdenticalTitle.md) | ✔️ | | Don't use identical titles for your tests |
| [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 |
| [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 |
<!-- __END AUTOGENERATED RULES TABLE__ -->

| Name | ✔️ | 🛠 | Description |
| ------------------------------------------------------------------------------------------------------------------------------------- | --- | --- | ----------------------------------------------------------------------- |
| [expectExpect](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/expectExpect.md) | ✔️ | | Ensure tests have at least one expect |
| [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. |
| [noIdenticalTitle](https://github.com/testcafe-community/eslint-plugin-testcafe-community/blob/master/docs/rules/noIdenticalTitle.md) | ✔️ | | Don't use identical titles for your tests |
| [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 |
| [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 |

<!-- __END AUTOGENERATED RULES TABLE__ -->
71 changes: 36 additions & 35 deletions build/generate-readme-table.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
"use strict";
import fs from "fs";
import path from "path";
import { rules } from "../lib";
import { repository } from "../package.json";

const fs = require("fs");
const path = require("path");
const { rules } = require("../lib");
const { repository } = require("../package.json");
const repoURL = repository.url.replace(/^git:\/\//, "");

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

const expectedTableLines = Object.keys(rules)
.sort()
.reduce(
(lines, ruleId) => {
const rule = rules[ruleId];
.sort()
.reduce(
(lines, ruleId) => {
const rule = rules[ruleId];

const tr = [
`[${ruleId}](https://${repoURL}/blob/master/docs/rules/${ruleId}.md)`,
rule.meta.docs.recommended ? "✔️" : "",
rule.meta.fixable ? "🛠" : "",
rule.meta.docs.description
].join(" | ")
const tr = [
`[${ruleId}](https://${repoURL}/blob/master/docs/rules/${ruleId}.md)`,
rule.meta.docs.recommended ? "✔️" : "",
rule.meta.fixable ? "🛠" : "",
rule.meta.docs.description
].join(" | ");

lines.push(`| ${tr} |`);
lines.push(`| ${tr} |`);

return lines;
},
[
"| Name | ✔️ | 🛠 | Description |",
"| ----- | ----- | ----- | ----------- |"
]
)
.join("\n");
return lines;
},
[
"| Name | ✔️ | 🛠 | Description |",
"| ----- | ----- | ----- | ----------- |"
]
)
.join("\n");

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

if (!readmeContents.includes(BEGIN_TABLE_MARKER)) {
throw new Error(
`Could not find '${BEGIN_TABLE_MARKER}' marker in README.md.`
);
throw new Error(
`Could not find '${BEGIN_TABLE_MARKER}' marker in README.md.`
);
}

if (!readmeContents.includes(END_TABLE_MARKER)) {
throw new Error(`Could not find '${END_TABLE_MARKER}' marker in README.md.`);
throw new Error(
`Could not find '${END_TABLE_MARKER}' marker in README.md.`
);
}

const linesStartIndex =
readmeContents.indexOf(BEGIN_TABLE_MARKER) + BEGIN_TABLE_MARKER.length;
readmeContents.indexOf(BEGIN_TABLE_MARKER) + BEGIN_TABLE_MARKER.length;
const linesEndIndex = readmeContents.indexOf(END_TABLE_MARKER);

const updatedReadmeContents = [
readmeContents.slice(0, linesStartIndex),
expectedTableLines,
readmeContents.slice(linesEndIndex)
readmeContents.slice(0, linesStartIndex),
expectedTableLines,
readmeContents.slice(linesEndIndex)
].join("\n");

if (require.main === module) {
// Run on command line
fs.writeFileSync(README_LOCATION, updatedReadmeContents);
// Run on command line
fs.writeFileSync(README_LOCATION, updatedReadmeContents);
} else {
module.exports = updatedReadmeContents;
module.exports = updatedReadmeContents;
}
35 changes: 19 additions & 16 deletions docs/rules/expect-expect.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
# All tests should have at least one assertion via t.expect(). (expect-expect)
# All tests should have at least one assertion via t.expect(). (expect-expect)

## Rule Details

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.
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.

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

```js
// Example 1: Forgot to add an assertion but provided an action
test('should do stuff', async (t) => {
await t.click(Selector("foo"))
})

// Example 2: empty test scaffolding
test('test something', (t) => {
// TODO: Test something
})
// Example 1: Forgot to add an assertion but provided an action
test("should do stuff", async (t) => {
await t.click(Selector("foo"));
});

// Example 2: empty test scaffolding
test("test something", (t) => {
// TODO: Test something
});
```

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

```js
test('should change text to clicked', async (t) => {
const text = Selector("bar")
await t.click(Selector("foo"))
await t.expect(text).toEqual("button clicked") // Makes an assertion
})
test("should change text to clicked", async (t) => {
const text = Selector("bar");
await t.click(Selector("foo"));
await t.expect(text).toEqual("button clicked"); // Makes an assertion
});
```

## When Not To Use It
Expand Down
Loading

0 comments on commit 0d42767

Please sign in to comment.