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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 43 additions & 0 deletions .github/workflows/js-linting.yml
Original file line number Diff line number Diff line change
@@ -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.


on:
push:
branches:
- trunk
paths:
- "**.js"
- "**.mjs"
- .github/workflows/js-linting.yml
pull_request:
paths:
- "**.js"
- "**.mjs"
- .github/workflows/js-linting.yml
Comment on lines +4 to +15
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 👌


concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
FORCE_COLOR: 2

jobs:
JSLintingCheck:
name: Lint JavaScript
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Prepare node
uses: woocommerce/grow/prepare-node@actions-v1
with:
node-version-file: .nvmrc

- name: Prepare annotation formatter
uses: woocommerce/grow/eslint-annotation@actions-v1

# Turn off import/no-unresolved rule since this check doesn't install packages for all sub-packages.
- name: Lint JavaScript and annotate linting errors
run: |
npm run lint:js -- --rule 'import/no-unresolved: 0' --format ./eslintFormatter.cjs
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/fermium
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require( '@wordpress/prettier-config' );
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Grow Packages

[![JavaScript Linting](https://github.com/woocommerce/grow/actions/workflows/js-linting.yml/badge.svg)](https://github.com/woocommerce/grow/actions/workflows/js-linting.yml)

This repository is a container for packages, mostly dev tools to serve the Grow Team.
The packages here are too experimental or too Grow-specific to be shared Woo-wide.

Expand Down
Loading