Skip to content

Commit

Permalink
Create format, lint action and add commit message validator (#53)
Browse files Browse the repository at this point in the history
* feat(actions): create format and lint action, also add husky commit msg checker

* Prettified Code!

---------

Co-authored-by: danieljancar <danieljancar@users.noreply.github.com>
  • Loading branch information
danieljancar and danieljancar authored Feb 21, 2024
1 parent 8d2fd9f commit 55d71f8
Show file tree
Hide file tree
Showing 16 changed files with 1,317 additions and 108 deletions.
10 changes: 10 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": ["@commitlint/config-conventional"],
"rules": {
"type-enum": [
2,
"always",
["chore", "docs", "feat", "fix", "refactor", "style", "test"]
]
}
}
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"ecmaVersion": "latest",
"sourceType": "module"
},
"ignorePatterns": ["apps/", "dist/", "node_modules/"]
"ignorePatterns": ["dist/", "node_modules/"]
}
24 changes: 24 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Formatting

on:
pull_request:
branches:
- develop

jobs:
prettier:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Prettify code
uses: creyD/prettier_action@v4.3
with:
prettier_options: '--write **/*.{js,ts,tsx,json,md,css}'
github_token: ${{ secrets.GITHUB_TOKEN }}
24 changes: 24 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Linter

on:
pull_request:
branches:
- develop

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: npm install

- name: Lint code
run: npm run lint
2 changes: 1 addition & 1 deletion .github/workflows/needs-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Issue Triage Labeler

on:
issues:
types: [ opened ]
types: [opened]

jobs:
label-triage:
Expand Down
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
npm run prettier
npm run lint
git add .
2 changes: 1 addition & 1 deletion apps/course/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
}
}
<div class="min-h-screen">
<router-outlet (activate)="onActivate($event)"></router-outlet>
<router-outlet (activate)="onActivate()"></router-outlet>
</div>
3 changes: 2 additions & 1 deletion apps/course/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export class AppComponent {
this.isBigScreen = window.innerWidth > 640;
}

onActivate(event: any) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onActivate() {
window.scroll({
top: 0,
left: 0,
Expand Down
2 changes: 1 addition & 1 deletion apps/course/src/app/core/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class AuthService {
.then(() => {
this.toastService.showToast('Logged in successfully.', 'success');
})
.catch((error) => {
.catch(() => {
this.toastService.showToast(
"Couldn't log in, please try again.",
'error',
Expand Down
1 change: 1 addition & 0 deletions apps/course/src/app/core/data/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class CourseService {
): Observable<Course[]> {
return this.afs
.collection<Course>(this.COURSES_COLLECTION, (ref) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let query = ref as any;

if (searchTerm) {
Expand Down
2 changes: 2 additions & 0 deletions apps/course/src/app/core/utility/toast.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Injectable } from '@angular/core';
providedIn: 'root',
})
export class ToastService {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private toasts: any[] = [];

constructor() {}
Expand All @@ -29,6 +30,7 @@ export class ToastService {
setTimeout(() => this.removeToast(toast), 5000);
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private removeToast(toast: any) {
const index = this.toasts.indexOf(toast);
if (index > -1) {
Expand Down
12 changes: 2 additions & 10 deletions apps/course/src/app/guards/auth.guard.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// auth.guard.ts
import { Injectable } from '@angular/core';
import {
ActivatedRouteSnapshot,
CanActivate,
Router,
RouterStateSnapshot,
} from '@angular/router';
import { CanActivate, Router } from '@angular/router';
import { AngularFireAuth } from '@angular/fire/compat/auth';
import { Observable } from 'rxjs';
import { map, take, tap } from 'rxjs/operators';
Expand All @@ -21,10 +16,7 @@ export class AuthGuard implements CanActivate {
private toastService: ToastService,
) {}

canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot,
): Observable<boolean> | Promise<boolean> | boolean {
canActivate(): Observable<boolean> | Promise<boolean> | boolean {
return this.afa.authState.pipe(
take(1),
map((user) => !!user),
Expand Down
8 changes: 4 additions & 4 deletions apps/course/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
"useDefineForClassFields": false,
"paths": {
"enums": ["./dist/enums"],
"types": ["./dist/types"],
"types": ["./dist/types"]
},
"lib": ["ES2022", "dom"],
"lib": ["ES2022", "dom"]
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true,
},
"strictTemplates": true
}
}
Loading

0 comments on commit 55d71f8

Please sign in to comment.