Skip to content

Commit

Permalink
Changed the file to typescript file and added return types to avoid l…
Browse files Browse the repository at this point in the history
…inting errors
  • Loading branch information
yugal07 committed Jan 18, 2025
1 parent bdd13e8 commit f8d20e3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
9 changes: 0 additions & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,5 @@
"docs/sidebars.ts",
"docs/src/**",
"docs/blog/**"
],
"overrides": [
{
"files": ["scripts/githooks/check-localstorage-usage.js"],
"rules": {
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/explicit-function-return-type": "off"
}
}
]
}
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ jobs:

- name: Check for localStorage Usage
run: |
chmod +x scripts/githooks/check-localstorage-usage.js
node scripts/githooks/check-localstorage-usage.js --scan-entire-repo
chmod +x scripts/githooks/check-localstorage-usage.ts
tsx scripts/githooks/check-localstorage-usage.ts --scan-entire-repo
- name: Compare translation files
run: |
Expand Down
2 changes: 1 addition & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{

Check warning on line 1 in .lintstagedrc.json

View workflow job for this annotation

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

File ignored by default.
"**/*.{ts,tsx,yml}": "eslint --fix",
"**/*.{ts,tsx,json,scss,css,yml}": "prettier --write",
"**/*.{ts,tsx}": "node scripts/githooks/check-localstorage-usage.js"
"**/*.{ts,tsx}": "tsx scripts/githooks/check-localstorage-usage.ts"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"update:toc": "node scripts/githooks/update-toc.js",
"lint-staged": "lint-staged --concurrent false",
"setup": "tsx setup.ts",
"check-localstorage": "node scripts/githooks/check-localstorage-usage.js"
"check-localstorage": "tsx scripts/githooks/check-localstorage-usage.ts"
},
"eslintConfig": {
"extends": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,49 @@
import { readFileSync, existsSync } from 'fs';
import path from 'path';
import { execSync } from 'child_process';
import type { ExecSyncOptionsWithStringEncoding } from 'child_process';

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

const containsSkipComment = (file) => {
const containsSkipComment = (file: string): boolean => {
try {
const content = readFileSync(file, 'utf-8');
return content.includes('// SKIP_LOCALSTORAGE_CHECK');
} catch (error) {
console.error(`Error reading file ${file}:`, error.message);
console.error(
`Error reading file ${file}:`,
error instanceof Error ? error.message : error,
);
return false;
}
};

const getModifiedFiles = () => {
const getModifiedFiles = (): string[] => {
try {
const options: ExecSyncOptionsWithStringEncoding = { encoding: 'utf-8' };

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

const result = execSync('git diff --cached --name-only', {
encoding: 'utf-8',
});
const result = execSync('git diff --cached --name-only', options);
return result.trim().split('\n');
} catch (error) {
console.error('Error fetching modified files:', error.message);
console.error(
'Error fetching modified files:',
error instanceof Error ? error.message : error,
);
process.exit(1);
}
return [];
};

const files = getModifiedFiles();

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

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

// Skip files with specific names or containing a skip comment
if (
fileName === 'check-localstorage-usage.js' ||
fileName === 'check-localstorage-usage.ts' || // Updated extension
fileName === 'useLocalstorage.test.ts' ||
fileName === 'useLocalstorage.ts' ||
containsSkipComment(file)
Expand All @@ -73,7 +78,10 @@ const checkLocalStorageUsage = (file) => {
console.log(`File ${file} does not exist.`);
}
} catch (error) {
console.error(`Error reading file ${file}:`, error.message);
console.error(
`Error reading file ${file}:`,
error instanceof Error ? error.message : error,
);
}
};

Expand Down

0 comments on commit f8d20e3

Please sign in to comment.