Skip to content

Commit

Permalink
fix: rename check-localstorage-usage script from .ts to .js and updat…
Browse files Browse the repository at this point in the history
…e workflow to use Node
  • Loading branch information
Priyanshuthapliyal2005 committed Jan 30, 2025
1 parent 0148cbb commit 58ca696
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 26 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@
run: npm run check-tsdoc
- name: Check for localStorage Usage
run: |
npm install ts-node
chmod +x scripts/githooks/check-localstorage-usage.ts
npx ts-node --esm scripts/githooks/check-localstorage-usage.ts --scan-entire-repo
chmod +x scripts/githooks/check-localstorage-usage.js
node scripts/githooks/check-localstorage-usage.js --scan-entire-repo
- name: Compare translation files
run: >
chmod +x .github/workflows/scripts/compare_translations.py
Expand Down Expand Up @@ -225,7 +224,7 @@
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 22.x
node-version: 20.x
- name: Install Dependencies
run: npm install
- name: Get changed TypeScript files
Expand Down Expand Up @@ -453,7 +452,7 @@
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
node-version: 20
cache: yarn
cache-dependency-path: docs/
- name: Install dependencies
Expand Down
39 changes: 18 additions & 21 deletions scripts/githooks/check-localstorage-usage.ts → scripts/githooks/check-localstorage-usage.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/usr/bin/env node

import { readFileSync, existsSync } from 'fs';
import path from 'path';
import { execSync } from 'child_process';
import type { ExecSyncOptionsWithStringEncoding } from 'child_process';
const fs = require('fs');

Check failure on line 3 in scripts/githooks/check-localstorage-usage.js

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

Require statement not part of import statement

Check failure on line 3 in scripts/githooks/check-localstorage-usage.js

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

A `require()` style import is forbidden
const path = require('path');

Check failure on line 4 in scripts/githooks/check-localstorage-usage.js

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

Require statement not part of import statement

Check failure on line 4 in scripts/githooks/check-localstorage-usage.js

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

A `require()` style import is forbidden
const { execSync } = require('child_process');

Check failure on line 5 in scripts/githooks/check-localstorage-usage.js

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

Require statement not part of import statement

Check failure on line 5 in scripts/githooks/check-localstorage-usage.js

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

A `require()` style import is forbidden

const args: string[] = process.argv.slice(2);
const scanEntireRepo: boolean = args.includes('--scan-entire-repo');
const args = process.argv.slice(2);
const scanEntireRepo = args.includes('--scan-entire-repo');

const containsSkipComment = (file: string): boolean => {
const containsSkipComment = (file) => {

Check failure on line 10 in scripts/githooks/check-localstorage-usage.js

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

Missing return type on function
try {
const content = readFileSync(file, 'utf-8');
const content = fs.readFileSync(file, 'utf-8');
return content.includes('// SKIP_LOCALSTORAGE_CHECK');
} catch (error) {
console.error(
Expand All @@ -21,16 +20,14 @@ const containsSkipComment = (file: string): boolean => {
}
};

const getModifiedFiles = (): string[] => {
const getModifiedFiles = () => {

Check failure on line 23 in scripts/githooks/check-localstorage-usage.js

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

Missing return type on function
try {
const options: ExecSyncOptionsWithStringEncoding = { encoding: 'utf-8' };

if (scanEntireRepo) {
const result = execSync('git ls-files | grep ".tsx\\?$"', options);
const result = execSync('git ls-files | grep ".tsx\\?$"', { encoding: 'utf-8' });

Check failure on line 26 in scripts/githooks/check-localstorage-usage.js

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

Replace `·encoding:·'utf-8'` with `⏎········encoding:·'utf-8',⏎·····`
return result.trim().split('\n');
}

const result = execSync('git diff --cached --name-only', options);
const result = execSync('git diff --cached --name-only', { encoding: 'utf-8' });

Check failure on line 30 in scripts/githooks/check-localstorage-usage.js

View workflow job for this annotation

GitHub Actions / Performs linting, formatting, type-checking, checking for different source and target branch

Replace `·encoding:·'utf-8'` with `⏎······encoding:·'utf-8',⏎···`
return result.trim().split('\n');
} catch (error) {
console.error(
Expand All @@ -42,10 +39,10 @@ const getModifiedFiles = (): string[] => {
return [];
};

const files: string[] = getModifiedFiles();
const filesWithLocalStorage: string[] = [];
const files = getModifiedFiles();
const filesWithLocalStorage = [];

const checkLocalStorageUsage = (file: string): void => {
const checkLocalStorageUsage = (file) => {
if (!file) {
return;
}
Expand All @@ -54,18 +51,18 @@ const checkLocalStorageUsage = (file: string): void => {

// Skip files with specific names or containing a skip comment
if (
fileName === 'check-localstorage-usage.ts' || // Updated extension
fileName === 'useLocalstorage.test.ts' ||
fileName === 'useLocalstorage.ts' ||
fileName === 'check-localstorage-usage.js' || // Updated extension
fileName === 'useLocalstorage.test.js' ||
fileName === 'useLocalstorage.js' ||
containsSkipComment(file)
) {
console.log(`Skipping file: ${file}`);
return;
}

try {
if (existsSync(file)) {
const content = readFileSync(file, 'utf-8');
if (fs.existsSync(file)) {
const content = fs.readFileSync(file, 'utf-8');

if (
content.includes('localStorage.getItem') ||
Expand Down

0 comments on commit 58ca696

Please sign in to comment.