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

Added Linting as a part of CI #393

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

tarunsinghofficial
Copy link
Contributor

@tarunsinghofficial tarunsinghofficial commented Aug 23, 2024

Overview

This PR introduces and fixes #392 for automated linting to our Continuous Integration (CI) pipeline. It aims to ensure consistent code style and catch potential errors early in the development process.

Changes

  • Added a new GitHub Actions workflow file: .github/workflows/ci.yml
  • Configured the workflow to run on push to main/master branches and on pull requests
  • Added a .prettierignore to ignore some package managers
  • Implemented Prettier and ESLint checks for all files
  • Added specific checks for changed files in pull requests

Implementation Details

The new CI workflow does the following:

  1. Check out the code
  2. Sets up Node.js
  3. Installs dependencies
  4. Runs Prettier on all files
  5. Runs ESLint on all files
  6. For pull requests, run Prettier and ESLint on changed files only

Notes

  • Caching of npm artifacts was considered but not implemented. We can add this later if build times become an issue.
  • The workflow is configured to use Node.js version 18. We may need to update this in the future.

Please review and let me know if any changes or additions are needed.

@tarunsinghofficial
Copy link
Contributor Author

tarunsinghofficial commented Aug 26, 2024

@hoch please review the PR, at your convenience. Thanks :)

@tarunsinghofficial
Copy link
Contributor Author

hi @hoch. Any update on this?

@tarunsinghofficial
Copy link
Contributor Author

Hi @hoch, Any update on this PR?

@hoch
Copy link
Member

hoch commented Nov 29, 2024

Apologies. I am currently swamped by urgent tasks at work. I'll ask around if other team members are able to review this change.

@mjwilson-google mjwilson-google self-requested a review January 2, 2025 18:48
Copy link
Collaborator

@mjwilson-google mjwilson-google left a comment

Choose a reason for hiding this comment

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

Hi @tarunsinghofficial, thank you for raising and working on this issue. I'll take on the review since Hongchan has been overloaded recently.

The overall approach looks good to me. I left some comments, please take a look and let me know what you think.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
- name: Run ESLint
run: npm run lint:eslint

- name: Lint changed files
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like the above "Run Prettier" and "Run ESLint" steps will run the linters on all files, and then this step will run the linters again just on the changed files. That seems redundant to me. Is it possible to either run on all files, or just run on the changed files? Or am I not correctly understanding what's happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can just run linting on the changed files, so that there is no redundancy.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove the "Run Prettier" step above too?

@@ -0,0 +1,4 @@
# Package Managers
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it's a problem to exclude these explicitly, but it seems like the commands added in package.json as well as the grep in the "Lint changed files" step will already avoid passing these files to the linters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed unnecessary exclusions since they're already excluded by other parts of the config.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove this entire file now?

.prettierrc.json Outdated Show resolved Hide resolved
.prettierrc.json Outdated Show resolved Hide resolved
.prettierrc.json Outdated Show resolved Hide resolved
@@ -12,6 +12,8 @@
"start:eleventy": "eleventy --serve",
"start:postcss": "postcss src/styles/*.css --dir _site --watch",
"format": "npx eslint --fix _site/audio-worklet/**/*.js && npx prettier --write --loglevel silent _site/audio-worklet/**/*.html",
"lint:prettier": "prettier --check src/**/*.js src/**/*.html",
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we remove the "Lint changed files" step we may want to add the other relevant filetypes here.

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 decided to keep the "Lint changed files" step, which runs linters only on the changed files. As a result, there's no need to modify the package.json file to include additional file types for linting, since the dynamic filtering for relevant files is handled in the "Lint changed files" step itself.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove the "lint:prettier" and "lint:eslint" lines now too?

Copy link
Collaborator

@mjwilson-google mjwilson-google left a comment

Choose a reason for hiding this comment

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

Thank you, looking even better! Just a few more comments.

- name: Run ESLint
run: npm run lint:eslint

- name: Lint changed files
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove the "Run Prettier" step above too?

@@ -0,0 +1,4 @@
# Package Managers
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove this entire file now?

@@ -12,6 +12,8 @@
"start:eleventy": "eleventy --serve",
"start:postcss": "postcss src/styles/*.css --dir _site --watch",
"format": "npx eslint --fix _site/audio-worklet/**/*.js && npx prettier --write --loglevel silent _site/audio-worklet/**/*.html",
"lint:prettier": "prettier --check src/**/*.js src/**/*.html",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove the "lint:prettier" and "lint:eslint" lines now too?

run: npm run lint:prettier

- name: Lint changed files
if: github.event_name == 'pull_request'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this step does the actual linting, and it only runs on 'pull_request', we should probably do one of the following:

  • Either remove the push line from the on section at the top of the file
  • Or, allow this linting to run on both push and pull request

What do you think?

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.

Add Linting as a part of CI pipeline
3 participants