From 37fab66f73e1d42b571402c433010c7008219a1c Mon Sep 17 00:00:00 2001 From: mzkmnk Date: Sat, 4 Jan 2025 00:06:12 +0900 Subject: [PATCH 1/4] add:code_quality.yml add:review.yml chore:ci.yml -> angular_build.yml --- .../workflows/{ci.yml => angular_build.yml} | 7 ++++-- .github/workflows/code_quality.yml | 21 ++++++++++++++++ .github/workflows/review.yml | 24 +++++++++++++++++++ .../with-storage-sync.spec.ts | 3 ++- 4 files changed, 52 insertions(+), 3 deletions(-) rename .github/workflows/{ci.yml => angular_build.yml} (85%) create mode 100644 .github/workflows/code_quality.yml create mode 100644 .github/workflows/review.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/angular_build.yml similarity index 85% rename from .github/workflows/ci.yml rename to .github/workflows/angular_build.yml index e75aacc7..5253864c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/angular_build.yml @@ -6,6 +6,9 @@ on: jobs: build: + permissions: + contents: read + pull-requests: write runs-on: ubuntu-latest @@ -15,7 +18,7 @@ jobs: steps: - name: repository checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: node.js setup uses: actions/setup-node@v3 @@ -33,7 +36,7 @@ jobs: - name: dependency install run: npm ci - - name: testing + - name: angular test run: npm run test - name: angular building diff --git a/.github/workflows/code_quality.yml b/.github/workflows/code_quality.yml new file mode 100644 index 00000000..63cd83cb --- /dev/null +++ b/.github/workflows/code_quality.yml @@ -0,0 +1,21 @@ +name: Code quality + +on: + pull_request: + types: + - opened + - ready_for_review + - synchronize + +jobs: + quality: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Biome + uses: biomejs/setup-biome@v2 + with: + version: latest + - name: Run Biome + run: biome ci ./projects/ngrx-extension/src diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml new file mode 100644 index 00000000..a31a5bb9 --- /dev/null +++ b/.github/workflows/review.yml @@ -0,0 +1,24 @@ +name: reviewdog +on: + pull_request: + types: + - opened + - ready_for_review + - synchronize +jobs: + biome: + name: runner / Biome + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v4 + - uses: mongolyy/reviewdog-action-biome@v1 + with: + github_token: ${{ secrets.github_token }} + reporter: github-pr-review + level: error + filter_mode: nofilter + fail_on_error: true + biome_flags: './projects/ngrx-extension/src' diff --git a/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts b/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts index bba6f994..c58890d2 100644 --- a/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts +++ b/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts @@ -7,7 +7,8 @@ import { TestBed } from '@angular/core/testing'; import { getState, patchState, signalStore, withState } from '@ngrx/signals'; import { withStorageSync } from './with-storage-sync'; -describe('withStorageSync', () => { +// todo +describe('withStorageSync test', () => { beforeEach(() => { localStorage.clear(); }); From e02a8242c86d3c1437ffe832b400b6ffe76752bc Mon Sep 17 00:00:00 2001 From: mzkmnk Date: Sat, 4 Jan 2025 17:02:35 +0900 Subject: [PATCH 2/4] testing --- .../src/lib/with-storage-sync/with-storage-sync.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts b/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts index c58890d2..862e2918 100644 --- a/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts +++ b/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts @@ -7,7 +7,6 @@ import { TestBed } from '@angular/core/testing'; import { getState, patchState, signalStore, withState } from '@ngrx/signals'; import { withStorageSync } from './with-storage-sync'; -// todo describe('withStorageSync test', () => { beforeEach(() => { localStorage.clear(); From 8fe78a2974d0b17608ce1d0030bf799128cc2b45 Mon Sep 17 00:00:00 2001 From: mzkmnk Date: Sat, 4 Jan 2025 17:04:14 +0900 Subject: [PATCH 3/4] fix:non-null assertion --- .../lib/with-storage-sync/with-storage-sync.spec.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts b/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts index 862e2918..8d734dd2 100644 --- a/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts +++ b/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.spec.ts @@ -7,7 +7,7 @@ import { TestBed } from '@angular/core/testing'; import { getState, patchState, signalStore, withState } from '@ngrx/signals'; import { withStorageSync } from './with-storage-sync'; -describe('withStorageSync test', () => { +describe('withStorageSync', () => { beforeEach(() => { localStorage.clear(); }); @@ -80,7 +80,7 @@ describe('withStorageSync test', () => { ...initialAppState, products: { ...initialAppState.products, - items: JSON.parse(localStorage.getItem('products-items')!), + items: JSON.parse(localStorage.getItem('products-items') ?? '[]'), }, }); }); @@ -149,7 +149,7 @@ describe('withStorageSync test', () => { ...initialAppState, products: { ...initialAppState.products, - items: JSON.parse(localStorage.getItem('products-items')!), + items: JSON.parse(localStorage.getItem('products-items') ?? '[]'), }, }); }); @@ -210,7 +210,9 @@ describe('withStorageSync test', () => { ...initialAppState, products: { ...initialAppState.products, - items: JSON.parse(localStorage.getItem(`${prefix}-products-items`)!), + items: JSON.parse( + localStorage.getItem(`${prefix}-products-items`) ?? '[]', + ), }, }); }); From 5bfe6462220641ae4a37dceeef88429c39344cd8 Mon Sep 17 00:00:00 2001 From: mzkmnk Date: Sat, 4 Jan 2025 17:17:02 +0900 Subject: [PATCH 4/4] fix:biome error --- biome.json | 7 ++++++- .../with-storage-sync/with-storage-sync.ts | 19 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/biome.json b/biome.json index 7974e60c..324cea38 100644 --- a/biome.json +++ b/biome.json @@ -19,7 +19,12 @@ "linter": { "enabled": true, "rules": { - "recommended": true + "recommended": true, + "complexity": { + "noBannedTypes": { + "level": "off" + } + } } }, "javascript": { diff --git a/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.ts b/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.ts index 3f903fe9..56fc075b 100644 --- a/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.ts +++ b/projects/ngrx-extension/src/lib/with-storage-sync/with-storage-sync.ts @@ -54,7 +54,7 @@ export function withStorageSync({ prefix, (key, fullKeyPath, objectState) => { // If the store does not have the specified key - if (!(objectState as Record).hasOwnProperty(key)) { + if (!Object.hasOwn(objectState as Record, key)) { throw new Error(`[${key}] ${key} not found`); } @@ -131,7 +131,7 @@ function writeDfs( prefix: string, callback: (key: string, fullKeyPath: string, objectState: unknown) => void, ): void { - nodes.forEach((node) => { + for (const node of nodes) { if (typeof node === 'string') { const fullKeyPath = prefix === '' ? node : `${prefix}-${node}`; // If the current node is the end, call the callback to write data to storage @@ -144,7 +144,7 @@ function writeDfs( writeDfs(nestedState, childNode, newPrefix, callback); } } - }); + } } /** @@ -160,7 +160,7 @@ function readDfs( prefix: string, callback: (fullKeyPath: string) => void, ): void { - nodes.forEach((node) => { + for (const node of nodes) { if (typeof node === 'string') { const fullPathKey = prefix === '' ? node : `${prefix}-${node}`; callback(fullPathKey); @@ -170,7 +170,16 @@ function readDfs( readDfs(childNode, newPrefix, callback); } } - }); + if (typeof node === 'string') { + const fullPathKey = prefix === '' ? node : `${prefix}-${node}`; + callback(fullPathKey); + } else { + for (const [key, childNode] of Object.entries(node)) { + const newPrefix = prefix === '' ? key : `${prefix}-${node}`; + readDfs(childNode, newPrefix, callback); + } + } + } } /**