-
-
Notifications
You must be signed in to change notification settings - Fork 813
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Addressing Continuous Refreshing in Development Environment (#1466)
* Update documentation * used custom hook for localstorage * Revert "Update documentation" This reverts commit 521d8b5. * fixing documentation conflicts * removed documentation.zip * Add pre-commit hook to check localStorage usage * added check for file in check-localstorage-usage.js script * Update OrgList.test.tsx * Update getRefreshToken.test.ts * updated script and workflow to check for flag * Update documentation --------- Co-authored-by: chandel-aman <[email protected]>
- Loading branch information
1 parent
df259fc
commit b58ce55
Showing
194 changed files
with
884 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"**/*.{ts,tsx,yml}": "eslint --fix", | ||
"**/*.{ts,tsx,json,scss,css,yml}": "prettier --write" | ||
"**/*.{ts,tsx,json,scss,css,yml}": "prettier --write", | ||
"**/*.{ts,tsx}": "node scripts/githooks/check-localstorage-usage.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env node | ||
|
||
import { readFileSync, existsSync } from 'fs'; | ||
import path from 'path'; | ||
import { execSync } from 'child_process'; | ||
|
||
const args = process.argv.slice(2); | ||
const scanEntireRepo = args.includes('--scan-entire-repo'); | ||
|
||
const containsSkipComment = (file) => { | ||
try { | ||
const content = readFileSync(file, 'utf-8'); | ||
return content.includes('// SKIP_LOCALSTORAGE_CHECK'); | ||
} catch (error) { | ||
console.error(`Error reading file ${file}:`, error.message); | ||
return false; | ||
} | ||
}; | ||
|
||
const getModifiedFiles = () => { | ||
try { | ||
if (scanEntireRepo) { | ||
const result = execSync('git ls-files | grep ".tsx\\?$"', { | ||
encoding: 'utf-8', | ||
}); | ||
return result.trim().split('\n'); | ||
} | ||
|
||
const result = execSync('git diff --cached --name-only', { | ||
encoding: 'utf-8', | ||
}); | ||
return result.trim().split('\n'); | ||
} catch (error) { | ||
console.error('Error fetching modified files:', error.message); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
const files = getModifiedFiles(); | ||
|
||
const filesWithLocalStorage = []; | ||
|
||
const checkLocalStorageUsage = (file) => { | ||
if (!file) { | ||
return; | ||
} | ||
|
||
const fileName = path.basename(file); | ||
|
||
// Skip files with specific names or containing a skip comment | ||
if ( | ||
fileName === 'check-localstorage-usage.js' || | ||
fileName === 'useLocalstorage.test.ts' || | ||
fileName === 'useLocalstorage.ts' || | ||
containsSkipComment(file) | ||
) { | ||
console.log(`Skipping file: ${file}`); | ||
return; | ||
} | ||
|
||
try { | ||
if (existsSync(file)) { | ||
const content = readFileSync(file, 'utf-8'); | ||
|
||
if ( | ||
content.includes('localStorage.getItem') || | ||
content.includes('localStorage.setItem') || | ||
content.includes('localStorage.removeItem') | ||
) { | ||
filesWithLocalStorage.push(file); | ||
} | ||
} else { | ||
console.log(`File ${file} does not exist.`); | ||
} | ||
} catch (error) { | ||
console.error(`Error reading file ${file}:`, error.message); | ||
} | ||
}; | ||
|
||
files.forEach(checkLocalStorageUsage); | ||
|
||
if (filesWithLocalStorage.length > 0) { | ||
console.error('\x1b[31m%s\x1b[0m', '\nError: Found usage of localStorage'); | ||
console.error('\nFiles with localStorage usage:'); | ||
filesWithLocalStorage.forEach((file) => console.error(file)); | ||
|
||
console.info( | ||
'\x1b[34m%s\x1b[0m', | ||
'\nInfo: Consider using custom hook functions.' | ||
); | ||
console.info( | ||
'Please use the getItem, setItem, and removeItem functions provided by the custom hook useLocalStorage.\n' | ||
); | ||
|
||
process.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.