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

Add eslint and JavaScript linting in GitHub Actions #36

Merged
merged 8 commits into from
Jul 21, 2022

Conversation

eason9487
Copy link
Member

@eason9487 eason9487 commented Jul 13, 2022

Changes proposed in this Pull Request:

Implements parts of #4

  • Add eslint, related deps and their configurations.
  • Add a GitHub Actions workflow to run JavaScript linting.
  • Fix all linting errors and warnings.

Before merging this PR:

Detailed test instructions:

  1. npm install
  2. npm run lint:js locally to test the eslint
    • 💡 It may gets some import/no-unresolved warnings because the node_modules directories in sub-packages don't exist. Those warnings will disappear after running npm install in those sub-packages.
  3. View the check that was intentionally left with linting errors and warnings.
  4. View the annotations attached to this PR:
    github com_woocommerce_grow_pull_36_files
  5. View the Check tab of this PR to see the successful linting check.

Comment on lines +4 to +15
push:
branches:
- trunk
paths:
- "**.js"
- "**.mjs"
- .github/workflows/js-linting.yml
pull_request:
paths:
- "**.js"
- "**.mjs"
- .github/workflows/js-linting.yml
Copy link
Contributor

Choose a reason for hiding this comment

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

💅 Maybe running this WorkFlow on PR against trunk would be enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

If the linting check only runs on PR against trunk, PR to PR, like this current one (#34), wouldn't be run. I think finding out linting errors earlier should be ideal.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I meant is to remove the push directive.

Copy link
Member Author

Choose a reason for hiding this comment

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

The temporarily merged code of a PR to be run checks is not always the same as the merged one after a PR actually gets merged.

For example, if there are other commits are pushed to trunk after this PR was opened, this PR won't be triggered and run the check again if there are no conflicts. When two PR change the same file like this:

const config = {
+	hello: '123', // Added by PR A
	howdy: '000',
+	hello: '456', // Added by PR B
 };
};

Both PR could pass the check, but it would be a problem after merging. When this happens, the check run on push events of trunk might find out this problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right! Thanks for the explanation 👌

@@ -0,0 +1,43 @@
name: JavaScript Linting
Copy link
Contributor

@puntope puntope Jul 15, 2022

Choose a reason for hiding this comment

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

💅 If we are going to set up a global package.json I'd also add a .nvmrc file

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in fa4b346.

@puntope
Copy link
Contributor

puntope commented Jul 15, 2022

When I run npm run lint:js I got this error:

Screenshot 2022-07-15 at 16 49 55

eason9487 added a commit that referenced this pull request Jul 18, 2022
@eason9487
Copy link
Member Author

@puntope, thanks for the review.

When I run npm run lint:js I got this error: [...]

Thanks for catching this. Seems it results in a different node_modules structure in the initial install, and somehow the flatted structure of package-lock after running npm dedupe conflicts with npm install. I added the "prettier": "npm:[email protected]" by 6489389 to make it stable.

Could you help with another round of code reviews?

@eason9487 eason9487 requested a review from puntope July 18, 2022 02:49
Copy link
Contributor

@puntope puntope left a comment

Choose a reason for hiding this comment

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

✅ LGTM

  • Tested lint:js locally. I checked forcing some errors.
  • Checked the action check
  • Checked the code quality

Base automatically changed from add/actions-linting-formatters to trunk July 21, 2022 02:48
@eason9487 eason9487 merged commit 735838a into trunk Jul 21, 2022
@eason9487 eason9487 deleted the add/4-eslint-and-gha-check branch July 21, 2022 03:29
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.

2 participants