Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge foretagsplatsen fork into core #112

Closed
wants to merge 110 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
a62aaa7
Update package-lock.json
DamienCassou Jun 27, 2022
6ce98ba
Remove dependency toward CircleCI
DamienCassou Jun 27, 2022
32b6e91
Replace yarn with npm in a line of package.json
DamienCassou Jun 27, 2022
2b7ddd7
Replace github.com/cypress-io with github.com/foretagsplatsen
DamienCassou Jun 27, 2022
0ea3030
Add .github/dependabot.yml
DamienCassou Jun 27, 2022
33eb0ea
Get rid of husky (at least for now)
DamienCassou Jun 27, 2022
93cfe75
Update eslint
DamienCassou Jun 27, 2022
576f73e
Replace eslint configuration
DamienCassou Jun 27, 2022
d781c45
Make code adhere to linting rules
DamienCassou Jun 27, 2022
b19b3dc
Add initial .ignore
DamienCassou Jun 27, 2022
5942f8c
Add a GitHub action
DamienCassou Jun 27, 2022
e177d83
Merge pull request #1 from foretagsplatsen/update-stack
DamienCassou Jun 27, 2022
ac2be75
Add .editorconfig
DamienCassou Jun 27, 2022
54eb19f
Add npm script "make-rule" to ease creation of rules
DamienCassou Jun 27, 2022
c211fea
Merge pull request #5 from foretagsplatsen/add-script-make-rule
DamienCassou Jun 27, 2022
531f605
chore(deps): bump globals from 11.12.0 to 13.15.0
dependabot[bot] Jun 27, 2022
6bb718f
Merge pull request #2 from foretagsplatsen/dependabot/npm_and_yarn/gl…
DamienCassou Jun 27, 2022
8e45864
chore(deps-dev): bump semantic-release from 15.13.18 to 19.0.3
dependabot[bot] Jun 27, 2022
7b340a0
Merge pull request #4 from foretagsplatsen/dependabot/npm_and_yarn/se…
DamienCassou Jun 27, 2022
2e6bdb6
Add myself as CODEOWNERS
DamienCassou Jun 27, 2022
dd730c9
Merge pull request #6 from foretagsplatsen/make-myself-codeowner
DamienCassou Jun 27, 2022
e136322
chore(deps-dev): bump jest from 24.8.0 to 28.1.1
dependabot[bot] Jun 27, 2022
b794a14
Remove duplicated jest configuration
DamienCassou Jun 27, 2022
58fe775
Merge pull request #3 from foretagsplatsen/dependabot/npm_and_yarn/je…
DamienCassou Jun 27, 2022
3f3d391
Fix name of the package
DamienCassou Jun 28, 2022
211e3f9
Update version number in package.json
DamienCassou Jun 28, 2022
17ad353
Add "publish" script
DamienCassou Jun 28, 2022
7323d4d
Merge pull request #7 from foretagsplatsen/fix-package-json
DamienCassou Jun 28, 2022
93488cc
Add missing @finsit prefix in recommended config
DamienCassou Jun 28, 2022
a4343bc
Merge pull request #8 from foretagsplatsen/fix-definition-of-recommen…
DamienCassou Jun 28, 2022
0e648e6
Release 3.0.2
DamienCassou Jun 28, 2022
a89d64c
Merge pull request #9 from foretagsplatsen/release-3.0.2
DamienCassou Jun 28, 2022
941d874
Improve the 'lint' script
DamienCassou Jun 28, 2022
552332d
Applying linting rules to the .eslintrc.cjs file
DamienCassou Jun 28, 2022
87ba16f
Change the parserOptions.sourceType to "script" in .eslintrc.js
DamienCassou Jun 28, 2022
1e1cdd6
Add eslint plugins to improve the quality of the project
DamienCassou Jun 28, 2022
4a83ae2
Apply new eslint rules to the code base
DamienCassou Jun 28, 2022
725b783
Merge pull request #10 from foretagsplatsen/improve-code-quality-with…
DamienCassou Jun 28, 2022
bc92aaa
Allow `_` as unused variable name
DamienCassou Jun 28, 2022
0b5a599
Enforce node >= 8.10 to benefit from the regexp 's' flag
DamienCassou Jun 28, 2022
f5a84f3
Reformat rule table in README
DamienCassou Jun 28, 2022
a3ba7b2
Add no-single-expect-in-then-or-should rule
DamienCassou Jun 28, 2022
f852371
Add no-expect-for-stub rule
DamienCassou Jun 28, 2022
4bd04a5
Merge pull request #11 from foretagsplatsen/add-rules
DamienCassou Jun 29, 2022
4c610a3
Remove unused `context` in `getExpectArgument()`
DamienCassou Jun 29, 2022
972ff5c
Refactor getExpectArgument()
DamienCassou Jun 29, 2022
aa7c605
Add no-useless-then-or-should
DamienCassou Jun 29, 2022
f390d9e
Merge pull request #12 from foretagsplatsen/no-useless-then-or-should
DamienCassou Jun 30, 2022
57fbf04
Release 3.1.0
DamienCassou Jul 1, 2022
6a44f29
Merge pull request #13 from foretagsplatsen/release-3.1.0
DamienCassou Jul 1, 2022
395e11e
chore(deps-dev): bump eslint from 8.18.0 to 8.19.0
dependabot[bot] Jul 4, 2022
815bbff
chore(deps-dev): bump eslint-plugin-eslint-plugin from 4.3.0 to 4.4.0
dependabot[bot] Jul 4, 2022
d621789
Merge pull request #16 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Jul 5, 2022
58e0021
Merge pull request #17 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Jul 5, 2022
128b5e6
chore(deps-dev): bump jest from 28.1.1 to 28.1.2
dependabot[bot] Jul 5, 2022
7fb583a
Merge pull request #18 from foretagsplatsen/dependabot/npm_and_yarn/j…
DamienCassou Jul 5, 2022
d4bd838
Fix regexp in expect-helpers.js
DamienCassou Jul 4, 2022
4d9c204
Fix function documentation in no-single-expect-in-then-or-should
DamienCassou Jul 4, 2022
c550f0e
Release 3.1.1
DamienCassou Jul 4, 2022
5b57543
Merge pull request #15 from foretagsplatsen/release-3.1.1
DamienCassou Jul 5, 2022
b4c2db6
chore(deps-dev): bump eslint-plugin-eslint-plugin from 4.4.0 to 4.4.1
dependabot[bot] Jul 11, 2022
ee85ee3
Merge pull request #19 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Jul 18, 2022
d431e12
chore(deps): bump globals from 13.15.0 to 13.16.0
dependabot[bot] Jul 18, 2022
b95470c
Merge pull request #20 from foretagsplatsen/dependabot/npm_and_yarn/g…
DamienCassou Jul 18, 2022
b2e6eb2
chore(deps-dev): bump generator-eslint from 3.0.1 to 4.0.0
dependabot[bot] Jul 18, 2022
c9bf653
Merge pull request #24 from foretagsplatsen/dependabot/npm_and_yarn/g…
DamienCassou Jul 18, 2022
c2d946a
chore(deps-dev): bump jest from 28.1.2 to 28.1.3
dependabot[bot] Jul 18, 2022
81121e0
Merge pull request #22 from foretagsplatsen/dependabot/npm_and_yarn/j…
DamienCassou Jul 18, 2022
865f164
chore(deps-dev): bump eslint from 8.19.0 to 8.20.0
dependabot[bot] Jul 18, 2022
b819c36
Merge pull request #21 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Jul 18, 2022
18a5148
chore(deps-dev): bump eslint-plugin-eslint-plugin from 4.4.1 to 5.0.1
dependabot[bot] Jul 18, 2022
80d1190
Use message ids to comply with new eslint rules
DamienCassou Jul 18, 2022
ab40c98
Merge pull request #23 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Jul 19, 2022
40cb705
chore(deps): bump globals from 13.16.0 to 13.17.0
dependabot[bot] Jul 25, 2022
f02a299
Merge pull request #25 from foretagsplatsen/dependabot/npm_and_yarn/g…
DamienCassou Jul 25, 2022
f10960a
chore(deps-dev): bump eslint from 8.20.0 to 8.22.0
dependabot[bot] Aug 15, 2022
ab8e4b9
Merge pull request #29 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Aug 16, 2022
63e36be
chore(deps-dev): bump eslint-plugin-eslint-plugin from 5.0.1 to 5.0.4
dependabot[bot] Aug 16, 2022
303acaf
Merge pull request #30 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Aug 16, 2022
bc764b4
chore(deps-dev): bump eslint-plugin-eslint-plugin from 5.0.4 to 5.0.5
dependabot[bot] Aug 22, 2022
6e3d9e7
Merge pull request #31 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Aug 22, 2022
d430ba4
chore(deps-dev): bump semantic-release from 19.0.3 to 19.0.5
dependabot[bot] Aug 29, 2022
bb3b1fc
Merge pull request #32 from foretagsplatsen/dependabot/npm_and_yarn/s…
DamienCassou Sep 5, 2022
d96556f
chore(deps-dev): bump eslint-plugin-eslint-plugin from 5.0.5 to 5.0.6
dependabot[bot] Aug 29, 2022
19b9204
Merge pull request #33 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Sep 5, 2022
f7efb65
chore(deps-dev): bump jest from 28.1.3 to 29.0.1
dependabot[bot] Aug 29, 2022
3aaf8d4
Merge pull request #34 from foretagsplatsen/dependabot/npm_and_yarn/j…
DamienCassou Sep 5, 2022
eff9a1c
chore(deps-dev): bump eslint-plugin-promise from 6.0.0 to 6.0.1
dependabot[bot] Aug 29, 2022
c31ef96
Merge pull request #35 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Sep 5, 2022
3ab5560
chore(deps-dev): bump eslint from 8.22.0 to 8.23.0
dependabot[bot] Aug 29, 2022
ac6570b
Merge pull request #36 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Sep 5, 2022
9ccea6c
chore(deps-dev): bump jest from 29.0.1 to 29.0.2
dependabot[bot] Sep 5, 2022
92c780e
Merge pull request #37 from foretagsplatsen/dependabot/npm_and_yarn/j…
DamienCassou Sep 6, 2022
89f0d0a
chore(deps-dev): bump eslint from 8.23.0 to 8.23.1
dependabot[bot] Sep 12, 2022
c13d141
Merge pull request #39 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Sep 12, 2022
64b890b
chore(deps-dev): bump jest from 29.0.2 to 29.0.3
dependabot[bot] Sep 12, 2022
c4d742b
Merge pull request #40 from foretagsplatsen/dependabot/npm_and_yarn/j…
DamienCassou Sep 12, 2022
66a7c25
chore(deps-dev): bump eslint from 8.23.1 to 8.24.0
dependabot[bot] Sep 26, 2022
5aaa16f
Merge pull request #41 from foretagsplatsen/dependabot/npm_and_yarn/e…
DamienCassou Sep 26, 2022
66862f0
Merge branch 'master' of https://github.com/foretagsplatsen/eslint-pl…
jaffrepaul Sep 27, 2022
5c93918
revert to circle CI & remove GHA
jaffrepaul Oct 4, 2022
6746e22
revert package.json values
jaffrepaul Oct 4, 2022
dcce8db
remove eslint v4 test in favor of adding v7
jaffrepaul Oct 4, 2022
5bd19fa
bring back husky
jaffrepaul Oct 4, 2022
24f94ac
set recommended rules back to base project
jaffrepaul Sep 28, 2022
a8d9744
update contributors & note rule script
jaffrepaul Sep 27, 2022
c680ef3
remove unnecessary packages in favor of reverting to core config
jaffrepaul Oct 4, 2022
72301c7
revert eslint version & config to work with core
jaffrepaul Oct 5, 2022
6739c2e
install legacy-deps
jaffrepaul Oct 5, 2022
f2c7b41
fix lint errors
jaffrepaul Oct 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions circle.yml → .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ workflows:
main:
jobs:
- lint
- test-v4
- test-v5
- test-v6
- test-v7
- release:
requires:
- lint
- test-v4
- test-v5
- test-v6
- test-v7
filters:
branches:
only:
Expand All @@ -22,7 +22,7 @@ workflows:
jobs:
lint:
docker:
- image: circleci/node:8
- image: circleci/node:14
steps:
- checkout
- run:
Expand All @@ -32,45 +32,45 @@ jobs:
name: Lint code
command: npm run lint

test-v4:
test-v5:
docker:
- image: circleci/node:8
- image: circleci/node:14
steps:
- checkout
- run:
name: Install dependencies
command: npm install
- run:
name: Test ESLint 4
command: npm run test:v4
name: Test ESLint 5
command: npm run test

test-v5:
test-v6:
docker:
- image: circleci/node:8
- image: circleci/node:14
steps:
- checkout
- run:
name: Install dependencies
command: npm install
- run:
name: Test ESLint 5
command: npm run test
name: Test ESLint 6
command: npm run test:v6

test-v6:
test-v7:
docker:
- image: circleci/node:8
- image: circleci/node:14
steps:
- checkout
- run:
name: Install dependencies
command: npm install
- run:
name: Test ESLint 6
command: npm run test:v6
name: Test ESLint 7
command: npm run test:v7

release:
docker:
- image: circleci/node:8
- image: circleci/node:14
steps:
- checkout
- run:
Expand Down
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8
indent_style = space

[*.{js,cjs,mjs}]
indent_style = space
indent_size = 2

[*.json]
indent_size = 2
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
open-pull-requests-limit: 1000 # we don't want to limit PRs
schedule:
interval: "weekly"
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint
1 change: 1 addition & 0 deletions .ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.git
37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,24 @@ These rules enforce some of the [best practices recommended for using Cypress](h

Rules with a check mark (✅) are enabled by default while using the `plugin:cypress/recommended` config.

**NOTE**: These rules currently require eslint 5.0 or greater. If you would like support added for eslint 4.x, please 👍 [this issue](https://github.com/cypress-io/eslint-plugin-cypress/issues/14).

| | Rule ID | Description |
| :-- | :------------------------------------------------------------------------- | :-------------------------------------------------------------- |
| ✅ | [no-assigning-return-values](./docs/rules/no-assigning-return-values.md) | Prevent assigning return values of cy calls |
| ✅ | [no-unnecessary-waiting](./docs/rules/no-unnecessary-waiting.md) | Prevent waiting for arbitrary time periods |
| ✅ | [no-async-tests](./docs/rules/no-async-tests.md) | Prevent using async/await in Cypress test case |
| | [no-force](./docs/rules/no-force.md) | Disallow using `force: true` with action commands |
| | [assertion-before-screenshot](./docs/rules/assertion-before-screenshot.md) | Ensure screenshots are preceded by an assertion |
| | [require-data-selectors](./docs/rules/require-data-selectors.md) | Only allow data-\* attribute selectors (require-data-selectors) |
| | [no-pause](./docs/rules/no-pause.md) | Disallow `cy.pause()` parent command |

| | Rule ID | Description |
|:---|:-----------------------------------------------------------------------------------------|:----------------------------------------------------------------|
| ✅ | [no-assigning-return-values](./docs/rules/no-assigning-return-values.md) | Prevent assigning return values of cy calls |
| ✅ | [no-unnecessary-waiting](./docs/rules/no-unnecessary-waiting.md) | Prevent waiting for arbitrary time periods |
| ✅ | [no-async-tests](./docs/rules/no-async-tests.md) | Prevent using async/await in Cypress test case |
| | [no-force](./docs/rules/no-force.md) | Disallow using `force: true` with action commands |
| | [assertion-before-screenshot](./docs/rules/assertion-before-screenshot.md) | Ensure screenshots are preceded by an assertion |
| | [require-data-selectors](./docs/rules/require-data-selectors.md) | Only allow data-\* attribute selectors (require-data-selectors) |
| | [no-pause](./docs/rules/no-pause.md) | Disallow `cy.pause()` parent command |
| | [no-single-expect-in-then-or-should](./docs/rules/no-single-expect-in-then-or-should.md) | Simplify tests by avoiding lonely expect() |
| | [no-expect-for-stub](./docs/rules/no-expect-for-stub.md) | Avoid expect(stub)… |
| | [no-useless-then-or-should](./docs/rules/no-useless-then-or-should.md) | Avoid `.should()` and `.then()` when only wrapping commands |

## Creating a rule
Use the `make-rule` script for an interactive guide to scaffold out the rule with associated spec and documentation files.
```sh
npm run make-rule
```
## Chai and `no-unused-expressions`

Using an assertion such as `expect(value).to.be.true` can fail the ESLint rule `no-unused-expressions` even though it's not an error in this case. To fix this, you can install and use [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly).
Expand Down Expand Up @@ -161,7 +167,8 @@ Or you can simply add its `recommended` config:

To add a new rule:
* Fork and clone this repository
* Generate a new rule (a [yeoman generator](https://github.com/eslint/generator-eslint) is available)
* Install dependencies with `npm install`
* Generate a new rule with `npm run make-rule`
* Run `yarn start` or `npm start`
* Write test scenarios then implement logic
* Describe the rule in the generated `docs` file
Expand All @@ -170,3 +177,7 @@ To add a new rule:
* Create a PR

Use the following commit message conventions: https://github.com/semantic-release/semantic-release#commit-message-format

## Community Recognition

This package was made with the help and contribution of [Damien Cassou](https://github.com/DamienCassou).
49 changes: 49 additions & 0 deletions docs/rules/no-expect-for-stub.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Avoid expect(stub)… (no-expect-for-stub)

Disallow usage of `expect()` with a [Sinon-Chai
chainer](https://docs.cypress.io/guides/references/assertions#Sinon-Chai)
(e.g., `expect(stub).to.have.been.calledOnce`) preferring the usage of
`should()`.

Some problems reported by this rule are automatically fixable by the
`--fix` command line option. Please be aware that fixing the code with
this rule requires that the stub is aliased (using the [`.as()`
Cypress command](https://docs.cypress.io/api/commands/as)): if that's
not the case, you will have to add an alias manually for the test to
pass.

## Rule Details

This rule makes code easier to read when `expect()` is used on a stub
with [Sinon-Chai chainer
chainer](https://docs.cypress.io/guides/references/assertions#Sinon-Chai).

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

```js
let onBudgetChanged = cy.stub().as("onBudgetChanged");
// … do something with onBudgetChanged…

cy.get("foo").click();

cy.then(() => {
expect(onBudgetChanged).to.be.called;
});
```

Note that the `expect()` call is wrapped in a `cy.then()`. This is
mandatory if the `expect()` is to be called after the Cypress commands
above it which is usually the case.

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

```js
// do something with cy.stub().as("onBudgetChanged")
cy.get("foo").click();
cy.get("@onBudgetChanged").should("be.called");
```

## When Not To Use It

- When you don't mind having code that is harder to read than necessary.
- When you don't want to add aliases to the stubs/spies.
35 changes: 35 additions & 0 deletions docs/rules/no-single-expect-in-then-or-should.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Simplify tests by avoiding lonely expect()

Disallow usage of expect() statements when they are alone in a
`then()` or `should()`.

Some problems reported by this rule are automatically fixable by the
`--fix` command line option.

## Rule Details

This rule makes code easier to read when both conditions are met:
1. a `then()` (or `should()`) contains a single call to `expect()` and
2. the `then()` (or `should()`) has the same argument as `expect()`.

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

```js
cy.wait("@PutCountry")
.its("request.body.userIds")
.then((userIds) => {
expect(userIds).to.have.members(expectedUserIds);
});
```

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

```js
cy.wait("@PutCountry")
.its("request.body.userIds")
.should("have.members", expectedUserIds);
```

## When Not To Use It

When you don't mind having code that is harder to read than necessary.
32 changes: 32 additions & 0 deletions docs/rules/no-useless-then-or-should.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Avoid `.should()` and `.then()` when only wrapping commands (no-useless-then-or-should)

.should()` and `.then()` can be removed when they only wrap commands
and their function argument doesn't take any argument.

## Rule Details

This rule simplifies code by removing unneeded calls to `cy.should()`
and `cy.then()`.

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

```js
cy.then(() => cy.contains("foo"))

cy.should(() => {
cy.get("@stub").should("have.been.called");
cy.contains("foo");
})
```

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

```js
cy.contains("foo")

cy.get("@stub").should("have.been.called");
```

## When Not To Use It

When you don't mind having code that is harder to read than necessary.
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ module.exports = {
'no-unnecessary-waiting': require('./lib/rules/no-unnecessary-waiting'),
'no-async-tests': require('./lib/rules/no-async-tests'),
'assertion-before-screenshot': require('./lib/rules/assertion-before-screenshot'),
'no-single-expect-in-then-or-should': require('./lib/rules/no-single-expect-in-then-or-should'),
'no-useless-then-or-should': require('./lib/rules/no-useless-then-or-should'),
'no-expect-for-stub': require('./lib/rules/no-expect-for-stub'),
'require-data-selectors': require('./lib/rules/require-data-selectors'),
'no-force': require('./lib/rules/no-force'),
'no-pause': require('./lib/rules/no-pause'),
Expand Down
6 changes: 0 additions & 6 deletions jest.config.js

This file was deleted.

Loading