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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Experimental] Enable git hooks for code validation and setup test suite #1171
[Experimental] Enable git hooks for code validation and setup test suite #1171
Conversation
Hi @lambdaclan Please update us about this. Is this ready for review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We switched to yarn for dependency insallation so you'll have to use npm run ci
instead of npm ci
For me I would
|
"pack:workers": "webpack --mode=production --node-env=production --config _scripts/webpack.workers.config.js", | ||
"pack:workers-silent": "webpack --no-stats --mode=production --node-env=production --config _scripts/webpack.workers.config.js", | ||
"postinstall": "npm run rebuild:electron", | ||
"prettier": "prettier --write \"{src,_scripts}/**/*.{js,ts,vue}\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"prettier": "prettier --write \"{src,_scripts}/**/*.{js,ts,vue}\"", | |
"prettier": "prettier --check \"{src,_scripts}/**/*.{js,ts,vue}\"", |
Closing PR in favor of #1788 |
Title
Implement various qol features for improving code quality.
Pull Request Type
Experimental (discussion needed before merging upstream)
Related issue
N/A
Special note
I feel sad about having to even add this section but you never know who will be reading this so here it goes. All the "criticisms" mentioned below are made in good faith and in an attempt to point out the issues with the current setup so that we can improve the application we all use and care about. I made an effort to use constructive comments in a heartfelt, meaningful tone that does not imply criticism towards the maintainers and any contributors.
Description
Currently the project does not include an automated way to ensure that the code being committed and pushed upstream is validated against the measures we have in place such as ESLint and Prettier. Furthermore, although the project does have some checks in place the code overall is not in a valid state. It will take time and effort to make all files pass the checks so we need to make sure that it stays like that and that new additions do not change the status.
Linting, formatting and testing make more sense when run before committing/pushing code. By doing so we ensure no errors ever make it into the repository and maintain a consistent coding style for the multiple contributors working on the project regardless of the editors and IDEs they use. It will also speed up the PR process since the checks run by the CI should be green by default leaving more time for the maintainers to look into what actually matters the code changes without having to worry about styling and linting errors.
The check for either tool can be run manually but that can complicate things because the scripts will run the checks on the whole codebase rather than just the files that are staged in git. This can actually be disruptive, running a lint process on the whole project can be slow, linting/formatting results can be irrelevant to the work being done and the number of flagged files can be overwhelming putting people off from running the checks in the first place. We need a better way to run checks only on files that will be committed.
To continue with, the existing GitHub action workflows only check for linting errors but do not perform any formatting checks although the setup is already in place.
Beyond the topic of code styling checks and their automation the project currently does not have a test suite or any tests for that matter. I will not discuss the merits of software testing since I have already established (through the project's communication channels) that we are in agreement that a test suite for FreeTube is indeed desired. Having a testing framework in place will encourage authoring of tests for at least all new code and will hopefully spark an interest to go back and test the existing code as well.
Looking a bit further into the future, having tests that we can trust and rely on will allow us to better prepare for what I am assuming will inevitably happen down the road, the switch to Vue 3 and TypeScript. Those are quite big topics that will require a lot of effort and refactoring so any help we can get would be beneficial.
Feature list
This PR aims to tackle the issues mentioned above as follows:
Tools and frameworks
Git hooks
.simple-git-hooks.json
and.lintstagedrc.json
) which make adjustments fairly trivial.npm install
through a post install script.[--no-verify
](https://git-scm.com/docs/githooks#_pre_commit) flag which is why we still need the checks to run in CI.Testing
General QOL additions
prettier:local
has been added which uses [pretty-quick] (https://github.com/azz/pretty-quick) to only format the changed or staged files since last commit files via Prettier. pretty-quick is also recommended by Prettier as a pre-commit mechanism. This script is meant to be run manually and possibly after the automated checks flag some files.Screenshots and demos
Git hooks installation
Git hooks content
Pre commit demo 1
Pretty quick demo
Pre commit demo 2
Pre commit demo 3
Test suite demo
Pre push demo
Testing
Has this pull request been tested?
Please describe shortly how you tested it and whether there are any ramifications remaining.
This section will make more sense now that we will have a test suite 馃帀 we can even turn down PRs (might be extreme for some) that do not include tests along with the changes added.
The overall functionality has been tested:
Desktop:
Additional discussion points
eslint --fix
then we will need a way to run that only on modified files somehow.--cache
flag of ESLint which only checks changed files and is off by default.