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

chore: improve linting #25235

Merged
merged 31 commits into from
Dec 29, 2022
Merged

chore: improve linting #25235

merged 31 commits into from
Dec 29, 2022

Conversation

flotwig
Copy link
Contributor

@flotwig flotwig commented Dec 20, 2022

  • For cypress-io/cypress-internal#513

User facing changelog

Additional details

  • Simplifies linting a few ways:
  • Corrects a few common linting issues:
    • "no-unused-vars: off" is present in a lot of our rules. I've removed most of these and fixed the errors that arose.
    • Some packages had .eslintrc but no yarn lint command, meaning linting only happened in the IDE, not in CI. Fixed this where needed.
  • Also removes an unused jscodeshift dep/script
  • Future PRs will further unify the eslintrcs to extend from a few common base scenarios.

Steps to test

How has the user experience changed?

PR Tasks

  • Have tests been added/updated?
  • [na] Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [na] Has a PR for user-facing changes been opened in cypress-documentation?
  • [na] Have API changes been updated in the type definitions?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 20, 2022

Thanks for taking the time to open a PR!

@cypress
Copy link

cypress bot commented Dec 20, 2022



Test summary

26392 0 1179 0Flakiness 30


Run details

Project cypress
Status Passed
Commit 9590db3
Started Dec 29, 2022 4:48 PM
Ended Dec 29, 2022 5:06 PM
Duration 18:18 💡
OS Linux Debian -
Browser Multiple

View run in Cypress Dashboard ➡️


Flakiness

create-from-component.cy.ts Flakiness
1 ... > runs generated spec
runner/reporter-ct-vite.errors.cy.ts Flakiness
1 Vite - errors ui > cy.readFile
commands/net_stubbing.cy.ts Flakiness
1 network stubbing > intercepting request > can delay and throttle a StaticResponse
2 network stubbing > intercepting request > can delay and throttle a StaticResponse
3 network stubbing > intercepting request > can delay and throttle a StaticResponse
This comment includes only the first 5 flaky tests. See all 30 flaky tests in the Cypress Dashboard.

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@flotwig flotwig changed the title chore: simplify linting chore: improve linting repo-wide Dec 21, 2022
@@ -1,6 +1,7 @@
/// <reference types="cypress" />

declare namespace Cypress {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not totally sure what the right thing to do here is, I made this change to fix the lint error from no-unused-vars but this doesn't look exactly right. Should E on line 14 extend Subject instead of HTMLElement? @jordanpowell88 any ideas?

Copy link
Contributor

@lmiller1990 lmiller1990 Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doe we need Chainable to have Subject? We might be able to omit it. Should it just be

declare namespace Cypress {
  interface Chainable {
    /**
    * Get one or more DOM elements by an XPath selector.
    * **Note:** you can test XPath expressions from DevTools console using $x(...) function, for example $x('//div') to find all divs.
    * @see https://github.com/cypress-io/cypress-xpath
    * @example
    * cy.xpath(`//ul[@class="todo-list"]//li`)
    *   .should('have.length', 3)
    */
    xpath<E extends Node = HTMLElement>(selector: string, options?: Partial<Loggable & Timeoutable>): Chainable<JQuery<E>>
  }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some examples in the docs that don't pass Subject to Chainable: https://docs.cypress.io/guides/tooling/typescript-support#Types-for-Custom-Commands

Comment on lines -179 to -181
"js-codemod": "cpojer/js-codemod",
"jscodemods": "https://github.com/cypress-io/jscodemods.git#01b546e",
"jscodeshift": "0.7.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing these 3 historical deps got rid of 249 transitive dependencies and 74 MB:

Before:

~ echo **/node_modules/* | wc -w
7371
~ du -c -B M **/node_modules/*
...
2792M   total

After:

~ echo **/node_modules/* | wc -w
7122
~ du -c -B M **/node_modules/*
...
2718M   total

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I wonder if there's a tool we can use to detect unused dependencies and prune more?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's called depcheck: https://github.com/depcheck/depcheck I want to add this to the repo at some point for sure.

@flotwig flotwig marked this pull request as ready for review December 21, 2022 21:51
Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code seems fine. I tried doing yarn lint-changed but I got a strange error:

$ yarn lint-changed                                            simplify-linting
yarn run v1.22.11
$ lint-changed

Oops! Something went wrong! :(

ESLint: 7.22.0

Error: 'patterns' must be a non-empty string or an array of non-empty strings
    at ESLint.lintFiles (/home/lachlan/code/work/dev/node_modules/eslint/lib/eslint/eslint.js:524:19)
    at Object.execute (/home/lachlan/code/work/dev/node_modules/eslint/lib/cli.js:296:36)
    at main (/home/lachlan/code/work/dev/node_modules/eslint/bin/eslint.js:142:52)
    at Object.<anonymous> (/home/lachlan/code/work/dev/node_modules/eslint/bin/eslint.js:146:2)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47
error Command failed with exit code 1.

I'm not sure if this ever worked, though, or if anyone uses it. The pre-commit lint hook still works fine, I tested it out.

Comment on lines -179 to -181
"js-codemod": "cpojer/js-codemod",
"jscodemods": "https://github.com/cypress-io/jscodemods.git#01b546e",
"jscodeshift": "0.7.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I wonder if there's a tool we can use to detect unused dependencies and prune more?

packages/driver/cypress/fixtures/dangling-element.html Outdated Show resolved Hide resolved
.eslintrc.js Outdated Show resolved Hide resolved
@flotwig
Copy link
Contributor Author

flotwig commented Dec 29, 2022

I'm not sure if this ever worked, though, or if anyone uses it. The pre-commit lint hook still works fine, I tested it out.

@lmiller1990 It seems broken in develop too. I opened a PR here to remove it, since lint-staged covers the functionality: #25308

@flotwig flotwig changed the title chore: improve linting repo-wide chore: improve linting Dec 29, 2022
@flotwig flotwig merged commit 1b1ed9c into develop Dec 29, 2022
@flotwig flotwig deleted the simplify-linting branch December 29, 2022 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants