Skip to content

Code Quality: Enforced usage of FileExtensionHelpers #18050

Merged
yair100 merged 2 commits into
files-community:mainfrom
Lamparter:mothods
Jun 9, 2026
Merged

Code Quality: Enforced usage of FileExtensionHelpers #18050
yair100 merged 2 commits into
files-community:mainfrom
Lamparter:mothods

Conversation

@Lamparter

@Lamparter Lamparter commented Jan 11, 2026

Copy link
Copy Markdown
Contributor

Resolved / Related Issues

Steps used to test these changes

  • Create a file with any one of the file extension types inside FileExtensionHelpers
  • See that the the file preview mode works correctly
    • Since the file preview pane is one of the heaviest users of the helper changed in this PR, it will fail to preview a file if the FileExtensionHelper isn't working correctly
    • If the file previews correctly, then one can know that the helper works

See the images below where I've demonstrated this


image

Generic file

image

Code file

image

Markdown file (unsure whether this is the expected behaviour for the markdown preview, but this PR wouldn't affect that)

image

RTF file

image

Plaintext file

Copilot AI review requested due to automatic review settings January 11, 2026 21:13
@Lamparter Lamparter changed the title Unify extension helpers Code Quality: Enforce usage of FileExtensionHelpers across the codebase Jan 11, 2026
@Lamparter Lamparter changed the title Code Quality: Enforce usage of FileExtensionHelpers across the codebase Code Quality: Enforced usage of FileExtensionHelpers Jan 11, 2026
@yair100

yair100 commented Jan 11, 2026

Copy link
Copy Markdown
Member

Please fill out the PR template and the steps taken to test each file format and extension.

Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
@yair100 yair100 added the changes requested Changes are needed for this pull request label Jan 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request unifies file extension checking by consolidating extension helper methods from individual preview view models into a central FileExtensionHelpers class, addressing issue #18049.

Changes:

  • Adds new helper methods to FileExtensionHelpers (IsCodeFile, IsPdfFile, IsHtmlFile, IsMarkdownFile, IsRichTextFile, IsTextFile) and migrates the code file extensions dictionary from CodePreviewViewModel
  • Removes duplicate ContainsExtension methods from all preview view models (TextPreviewViewModel, RichTextPreviewViewModel, PDFPreviewViewModel, MarkdownPreviewViewModel, ImagePreviewViewModel, HtmlPreviewViewModel, CodePreviewViewModel)
  • Updates call sites in InfoPaneViewModel and AdaptiveLayoutHelpers to use the centralized helpers

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 22 comments.

Show a summary per file
File Description
src/Files.Shared/Helpers/FileExtensionHelpers.cs Adds new helper methods and CodeFileExtensions dictionary; updates documentation from "Check" to "Checks"
src/Files.Shared/Files.Shared.csproj Adds ColorCode.Core package reference
src/Files.App/ViewModels/UserControls/Previews/TextPreviewViewModel.cs Removes ContainsExtension method
src/Files.App/ViewModels/UserControls/Previews/RichTextPreviewViewModel.cs Removes ContainsExtension method
src/Files.App/ViewModels/UserControls/Previews/PDFPreviewViewModel.cs Removes ContainsExtension method
src/Files.App/ViewModels/UserControls/Previews/MarkdownPreviewViewModel.cs Removes ContainsExtension method
src/Files.App/ViewModels/UserControls/Previews/ImagePreviewViewModel.cs Removes ContainsExtension method and TODO comment
src/Files.App/ViewModels/UserControls/Previews/HtmlPreviewViewModel.cs Removes ContainsExtension method
src/Files.App/ViewModels/UserControls/Previews/CodePreviewViewModel.cs Removes ContainsExtension method and GetDictionary; uses shared CodeFileExtensions
src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs Updates to use centralized FileExtensionHelpers methods
src/Files.App/Helpers/Layout/AdaptiveLayoutHelpers.cs Updates to use FileExtensionHelpers.IsImageFile
Directory.Packages.props Adds ColorCode.Core version 2.0.15

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
@Lamparter Lamparter requested a review from yair100 January 11, 2026 21:25
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
Comment thread src/Files.App/ViewModels/UserControls/InfoPaneViewModel.cs Outdated
Comment thread src/Files.Shared/Helpers/FileExtensionHelpers.cs Outdated
@Lamparter

Copy link
Copy Markdown
Contributor Author

@yaira2 requesting your review

@Lamparter

Copy link
Copy Markdown
Contributor Author

Hmm, looks like some things got messed up when you rebased, let me solve that quickly

@Lamparter Lamparter requested a review from yair100 April 27, 2026 22:52
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@yair100 yair100 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yair100 yair100 added ready to merge Pull requests that are approved and ready to merge and removed changes requested Changes are needed for this pull request labels Jun 9, 2026
@yair100 yair100 merged commit cbe216e into files-community:main Jun 9, 2026
6 checks passed
@Lamparter Lamparter deleted the mothods branch June 9, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge Pull requests that are approved and ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code Quality: Enforce usage of FileExtensionHelpers to check file extensions across codebase

3 participants