Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Colin7780/f25cc87471e8289fbed8f45ee0f57294 to your computer and use it in GitHub Desktop.
Save Colin7780/f25cc87471e8289fbed8f45ee0f57294 to your computer and use it in GitHub Desktop.
Follow these 7 systematic steps to clean up and optimize codebase:
**Step 1: Identify and remove unused files and code**
- Scan project directory for files that are no longer referenced or used
- Look for old backup files, temporary files, and deprecated modules
- Remove entire files or code blocks that serve no purpose in the current application
- Use IDE's "Find Usages" feature to verify files aren't being imported elsewhere
**Step 2: Remove unused imports, variables, functions, and types**
- Clean up import statements at the top of files - remove any imports that aren't being used
- Identify variables that are declared but never referenced
- Remove functions that are defined but never called
- Delete type definitions, interfaces, or classes that aren't being utilized
- Use linting tools to automatically detect unused elements
**Step 3: Identify and refactor duplicate code**
- Search for repeated code patterns across codebase
- Look for similar functions that could be consolidated into one reusable function
- Identify duplicate logic that can be extracted into shared utilities
- Refactor repeated code blocks into functions, methods, or modules
- Apply the DRY (Don't Repeat self) principle
**Step 4: Remove unnecessary console logs, dead or obsolete code, and comments**
- Delete console.log statements used for debugging (keep only essential logging)
- Remove commented-out code blocks that are no longer needed
- Delete obsolete functions or methods that have been replaced
- Clean up outdated comments and documentation
- Remove experimental code that didn't make it to production
**Step 5: Run linters and formatters, and fix errors/warnings**
- Execute project's linting tools (ESLint, TSLint, etc.)
- Run code formatters (Prettier, Black, etc.) to ensure consistent styling
- Address all linting errors and warnings
- Fix syntax issues, style violations, and potential bugs
- Ensure code follows team's coding standards
**Step 6: Review and test**
- Conduct a thorough code review of all changes made
- Run test suite to ensure nothing was broken during cleanup
- Test critical functionality manually if needed
- Verify that the application still works as expected
- Check that performance hasn't been negatively impacted
**Step 7: Submit the changes**
- Stage and commit cleanup changes with clear, descriptive commit messages
- Create a pull request or merge request for team review
- Document what was cleaned up in commit/PR description
- Deploy to staging environment for final validation before production
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment