feat: add ignoreFileExtensions option#228
Conversation
b2820bf to
ba40f6d
Compare
b8875b7 to
b09be88
Compare
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds an ignoreFileExtensions configuration option to Sheriff, enabling users to specify which file extensions should be ignored during import traversal. This addresses performance issues caused by processing non-code files and provides flexibility for project-specific configurations.
- Introduces the
ignoreFileExtensionsconfiguration option with sensible defaults for common non-code files - Updates the filesystem traversal logic to skip files with ignored extensions early in the process
- Adds comprehensive test coverage and documentation for the new feature
Reviewed Changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/lib/config/default-file-extensions.ts | Defines default list of file extensions to ignore (images, styles, fonts, etc.) |
| packages/core/src/lib/config/user-sheriff-config.ts | Adds the ignoreFileExtensions property to the user configuration interface |
| packages/core/src/lib/config/parse-config.ts | Implements parsing logic for the new configuration option with function/array support |
| packages/core/src/lib/file-info/traverse-filesystem.ts | Updates filesystem traversal to skip files with ignored extensions |
| packages/core/src/lib/file-info/generate-unassigned-file-info.ts | Passes ignore extensions parameter through the traversal chain |
| test-projects/angular-iv/tests/ | Adds integration tests to verify ignored extensions functionality |
| docs/ | Adds comprehensive documentation and release notes for the new feature |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| ignoreFileExtensions, | ||
| }; | ||
| }; | ||
|
|
There was a problem hiding this comment.
The function getIgnoreFileExtensions lacks documentation. Consider adding a JSDoc comment explaining its purpose, parameters, and return value, especially since it handles both array and function inputs for the configuration option.
| /** | |
| * Returns a normalized array of file extensions to ignore. | |
| * | |
| * @param ignoreFileExtensions - Either an array of file extensions to ignore, | |
| * or a function that receives the default ignore list and returns a new array. | |
| * @returns A deduplicated, lowercased array of file extensions to ignore. | |
| */ |
| // skip json imports | ||
| if (fileName.endsWith('.json')) { | ||
| // skip configured ignored extensions early | ||
| const fileExtension = fileName.split('.').pop()?.toLowerCase(); |
There was a problem hiding this comment.
The file extension extraction logic using split('.').pop() could fail for files without extensions or complex filenames. Consider using a more robust approach like path.extname() from Node.js or add validation to handle edge cases like files starting with dots or multiple dots.
| const fileExtension = fileName.split('.').pop()?.toLowerCase(); | |
| const fileExtension = path.extname(fileName).toLowerCase().replace(/^\./, ''); |



Adds the possbility to ignore files based on their extension and comes with a default of common files that should be ignored.
Fixes