Giter VIP home page Giter VIP logo

resxformatter's Introduction

ResxFormatter

Optimizes resx files after saving: Removes schema and comments (in particular the 3KB documentation that is included in every resx file) and sorts entries alphabetically so that they look like this:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <schema />
  <resheader name="resmimetype">
    <value>text/microsoft-resx</value>
  </resheader>
  <resheader name="version">
    <value>2.0</value>
  </resheader>
  <resheader name="reader">
    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <resheader name="writer">
    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
  </resheader>
  <data name="a" xml:space="preserve">
    <value>LESS CLUTTER</value>
  </data>
  <data name="b" xml:space="preserve">
    <value>SORTED BY KEYS</value>
  </data>
</root>

Use only with a source control system and at your own risk. See the change log for changes and road map.


Download this extension from the Visual Studio Marketplace or get the CI build.

Build status

Settings

EditorConfig

Formatting rules are configured in the EditorConfig file as follows:

[*.resx]
resx_formatter_sort_entries=true
resx_formatter_remove_xsd_schema=true
resx_formatter_remove_documentation_comment=true
resx_formatter_sort_comparer=OrdinalIgnoreCase

Comparer can be one of the following: InvariantCulture, InvariantCultureIgnoreCase, OrdinalIgnoreCase, Ordinal. The default value is Ordinal.

ℹ️ You can format all resx files in the current solution folder via Extensions > ResxFormatter menu.

Visual Studio

A few things can be configured and probably you want to have this done as follows:

Settings

Use the experimental setting with caution since it may have undesired side effects. It is also worth to note, that the extension may insert schema or documentation comment in order to match the desired effect of your EditorConfig settings.

Contributing

Please use the issue tracker for submitting bug reports or feature requests.

License

MIT License

Third Party Licenses

Library License
EditorConfig .NET Core MIT License
xUnit Apache License 2.0 / MIT License
NFluent Apache License 2.0
Community toolkit for Visual Studio extensions Apache License 2.0

resxformatter's People

Contributors

stefanegli avatar

Stargazers

Tomáš Hübelbauer avatar  avatar  avatar  avatar  avatar Ulysses avatar Jesse Plamondon-Willard avatar  avatar Piero Castillo avatar  avatar Sander Soots avatar Daniel Zilcsak avatar Kersten Behrens avatar  avatar

Watchers

Jesse Plamondon-Willard avatar  avatar Tom Mason avatar  avatar Daniel Zilcsak avatar

resxformatter's Issues

Status of ResxFormatter for VS2022?

Hi Stefan

Thank you very much for ResXFormatter, it's a simple but so useful tool notably when using git. I saw there is a preview version for VS2022, as of August 2021. What's the status for it? Is it stable, does it has bugs, would you have a release date in mind?

Thank again for your time and effort on it!

Configure a culture invariant sort option

Steps to recreate:
image

  1. Set machine localization to US English ->
    (Control Panel -> Clock and region -> Formats -> English (United States)

  2. Create an en-us resx file with the following labels:
    "Api"
    "Assigned"
    "Attribute"
    "Average"
    "Azure"

  3. See the resx be sorted to the above alphabetical order.

  4. Update machine localization from En-Us over to Estonian
    (Control Panel -> Clock and Region -> Formats -> Estonian (Estonia))

  5. Open Visual Studio > Navigate to the Resx file

  6. Create a new label + hit save.

  7. The order is updated to:

"Api"
"Assigned"
"Azure"
"Attribute"
"Average"

Why
According to the Estonian alphabet Z comes before T So it alphabetizes based on the local machine rules for the user as opposed to the resx language of choice.

Potential Solution
Add an option on sorting to allow culture invariant sorting, so all resx will follow the same pattern independent of if the team is across different localizations.

Reorder Alphabetically

When I update from 2.0.68 to 3.0.76 I noticed that newly added resx entries no longer reordered themselves alphabetically, older entries stayed as is. The designer file is fine and orders itself correctly.

Desktop

  • OS: Windows 11 Enterprise
  • Version 10.0.22000 Build 22000
  • IDE: Visual Studio Professional 2022

Additional context
Moving back to 2.0.68 worked. I also tried to make 3.0.76 work with changing settings in Tools -> options -> ResxFormatter -> General and with making changes in .editorconfig

Failed to Load the ResxPackage in Visual Studio 2017

Describe the bug
I get the following error in the ActivityLog when loading the ResxFormatter package (2.0.68)

<description>
SetSite failed for package [ResxFormatterPackage]Source:'Microsoft.VisualStudio.Shell.15.0' Description: Due to high risk of deadlock you cannot call GetService from a background thread in an AsyncPackage derived class. You should instead call GetServiceAsync (without calling Result or Wait on the resultant Task object) or switch to the UI thread with the JoinableTaskFactory.SwitchToMainThreadAsync method before calling GetService.
System.InvalidOperationException: Due to high risk of deadlock you cannot call GetService from a background thread in an AsyncPackage derived class. You should instead call GetServiceAsync (without calling Result or Wait on the resultant Task object) or switch to the UI thread with the JoinableTaskFactory.SwitchToMainThreadAsync method before calling GetService.
 at Microsoft.VisualStudio.Shell.AsyncPackage.GetService(Type serviceType)
 at Microsoft.VisualStudio.Shell.Package.System.IServiceProvider.GetService(Type serviceType)
 at Microsoft.VisualStudio.Shell.Package.PackageContainer.GetService(Type serviceType)
 at System.ComponentModel.Container.Site.GetService(Type service)
 at System.ComponentModel.Component.GetService(Type service)
 at Microsoft.VisualStudio.Shell.DialogPage.get_SettingsManager()
 at Microsoft.VisualStudio.Shell.DialogPage.LoadSettingsFromStorage()
 at Microsoft.VisualStudio.Shell.DialogPage.set_Site(ISite value)
 at System.ComponentModel.Container.Add(IComponent component, String name)
 at System.ComponentModel.Container.Add(IComponent component)
 at Microsoft.VisualStudio.Shell.Package.GetDialogPage(Type dialogPageType)
 at ResxFormatter.ResxFormatterPackage.get_Settings()
 at ResxFormatter.ResxFormatterPackage.<InitializeAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.VisualStudio.Shell.AsyncPackage.<>c__DisplayClass17_0.<<Microsoft-VisualStudio-Shell-Interop-IAsyncLoadablePackageInitialize-Initialize>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 at Microsoft.VisualStudio.Threading.JoinableTask.<JoinAsync>d__78.MoveNext()</description>

To Reproduce
Just install the package in Visual Studio 2017 using vsixinstaller

Expected behavior
No error when package loading

Screenshots
image

Desktop (please complete the following information):
Windows 10

Smartphone (please complete the following information):
N/A

Additional context
Just add the following statement (as first statement) to the protected override async Task InitializeAsync(....) (ResxFormatterPackage.cs):

            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

Strip comments from Designer.cs files

Please strip the comments from the Designer.cs file that is being generated by VisualStudio from resx files.

In our team we have VisualStudio installations with different language settings (i.e. English and German) and every time someone touches a resx file (for localization) the corresponding Designer.cs file is being generated and all comments therein are being replaced in whatever language has is being configured in the local VisualStudio. That leads to crazy conflicts when two people with different language settings are editing the same resx file.

So I propose, for any resx file your extension is editing, look for a corresponding Designer.cs file and strip comments from there, also.

Example:
"Localization.resx" is being edited
"Localization.Designer.cs" file is being generated by VisualStudio

=> ResxFormatter should strip comments from both files.

Case-insensitive Sort

The sort function that was added uses StringComparer.Ordinal, making it case-sensitive. This messes up the order of all of my resx files because the previous extension I had for older versions of VS sorted case-insensitively.

I'm not sure whether this was intentional, since the Sort.resx test case is very simple with three lower-case strings.

abc
def
ghi

However when you try to sort resx files with mixed-case strings, they don't come out in case-insensitive order:

Alaska
ARIZONA
Aardvark
amazing
ABOUT

Is sorted as:

ABOUT
ARIZONA
Aardvark
Alaska
amazing

Describe the solution you'd like
What I would like this to sort as would be in pure alphabetical order, regardless of case:

Aardvark
ABOUT
Alaska
amazing
ARIZONA

To do this requires using StringComparer.OrdinalIgnoreCase instead of StringComparer.Ordinal.

I have a patch which adds a new option, resx_formatter_sort_entries_case_sensitive. This works in conjunction with resx_formatter_sort_entries so that if resx_formatter_sort_entries is false, the new option is ignored.

I have not added a test case yet but can quite easily once it's said that this is a feature you want to add.

Resource file will not reload when changed and saved

Describe the bug
Resource file will not reload when changed and saved when setting Reload file after saving is set to AfterModification

To Reproduce
Steps to reproduce the behavior:

  • Set "Reload file after saving" to "AfterModification"
  • Change a resource file
  • Save resource file

Expected behavior
Changed resource file is reloaded

Screenshots
n.a.

Desktop (please complete the following information):
n.a.

Smartphone (please complete the following information):
n.a.

Additional context
Line 88 in ResxFormatterPackage.cs should read:
if ((formatter.Run(document.Path) && settings.ReloadFile == ReloadMode.AfterModification)

Disable generation of resx files

First, thank you very, very much for this extension. It's a must have.

As you know, most of the context of a resx file is clutter, in fact, most of the time, the entire file is useless.

Would it be possible to add an option to automatically delete empty resx files or, better yet, disable their generation?

Thanks again.

Not working in Visual Studio 2019 v16.7.2

Describe the bug
The extension was working ok but at some point recently it stopped working. I'm keeping my VS2019 updated, using the last version v16.7.2, in windows 10. When I hit save (in the save icon or with the ctrl + s shortcut), the resource strings are not being sorted. The file is not being updated in any way. I tried in two different computers.

Capture

resx_formatter_remove_documentation_comment should not ADD the documentation comment

Describe the bug
The setting resx_formatter_remove_documentation_comment is either named misleadingly or incorrect.

What resx_formatter_remove_documentation_comment=true does:

  • removes all XML comments, not just the documentation comment

What resx_formatter_remove_documentation_comment=false does:

  • Adds the documentation comment
  • Keeps existing non-documentation comments.

Expected behavior
What resx_formatter_remove_documentation_comment=true should do:

  • Remove only the documentation comment - maybe identified by Microsoft ResX Schema string

What resx_formatter_remove_documentation_comment=false should do:

  • Keep existing comments the way they are.

Desktop (please complete the following information):

  • Version 3.1.80

Additional context
I think it should be totally legit to have XML comments throughout the ResX file and the extension just ignoring them.

Crash on launch with 1.1.44 and VS 16.9.3

Describe the bug
SetSite failed for package [ResxFormatterPackage]Source: 'mscorlib' Description: An item with the same key has already been added. System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add)&#x000D;&#x000A; at EditorConfig.Core.EditorConfigFile.Parse(String file) in /home/runner/work/editorconfig-core-net/editorconfig-core-net/src/EditorConfig.Core/EditorConfigFile.cs:line 72&#x000D;&#x000A; at EditorConfig.Core.EditorConfigFile..ctor(String file) in /home/runner/work/editorconfig-core-net/editorconfig-core-net/src/EditorConfig.Core/EditorConfigFile.cs:line 43&#x000D;&#x000A; at EditorConfig.Core.EditorConfigParser.&lt;&gt;c.&lt;ParseConfigFilesTillRoot&gt;b__16_0(String f) in /home/runner/work/editorconfig-core-net/editorconfig-core-net/src/EditorConfig.Core/EditorConfigParser.cs:line 105&#x000D;&#x000A; at System.Linq.Enumerable.&lt;&gt;c__DisplayClass7_03.<CombineSelectors>b__0(TSource x) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()&#x000D;&#x000A; at EditorConfig.Core.EditorConfigParser.&lt;ParseConfigFilesTillRoot&gt;d__16.MoveNext() in /home/runner/work/editorconfig-core-net/editorconfig-core-net/src/EditorConfig.Core/EditorConfigParser.cs:line 105&#x000D;&#x000A; at System.Linq.Buffer1..ctor(IEnumerable1 source)&#x000D;&#x000A; at System.Linq.Enumerable.&lt;ReverseIterator&gt;d__751.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)&#x000D;&#x000A; at EditorConfig.Core.EditorConfigParser.GetConfigurationFilesTillRoot(String file) in /home/runner/work/editorconfig-core-net/editorconfig-core-net/src/EditorConfig.Core/EditorConfigParser.cs:line 100&#x000D;&#x000A; at EditorConfig.Core.EditorConfigParser.Parse(String fileName, IEnumerable1 editorConfigFiles) in /home/runner/work/editorconfig-core-net/editorconfig-core-net/src/EditorConfig.Core/EditorConfigParser.cs:line 72 at ResxFormatter.ResxEditorConfigSettings..ctor(String targetFile) at ResxFormatter.ResxFormatterPackage.ApplyEditorConfigSettings(OptionPageGrid currentSettings) at ResxFormatter.ResxFormatterPackage.get_Settings() at ResxFormatter.ResxFormatterPackage.<InitializeAsync>d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.Shell.AsyncPackage.<>c__DisplayClass20_0.<<Microsoft-VisualStudio-Shell-Interop-IAsyncLoadablePackageInitialize-Initialize>b__1>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.VisualStudio.Shell.UIThreadReentrancyScope.WaitOnTaskCompleteInternal(Task task, CancellationToken cancel, Int32 ms) at Microsoft.VisualStudio.Shell.UIThreadReentrancyScope.WaitOnTaskComplete(Task task, CancellationToken cancel, Int32 ms) at Microsoft.VisualStudio.Services.VsTask.<>c__DisplayClass100_1.<InternalGetResult>b__1() at Microsoft.VisualStudio.Services.VsTask.IgnoreObjectDisposedException(Action action) at Microsoft.VisualStudio.Services.VsTask.<>c__DisplayClass100_0.<InternalGetResult>b__0() at Microsoft.VisualStudio.Services.VsTask.<>c__DisplayClass108_0.<InvokeWithWaitDialog>b__0() at Microsoft.VisualStudio.Services.VsTask.InvokeWithWaitDialog[T](Func`1 function) at Microsoft.VisualStudio.Services.VsTask.InvokeWithWaitDialog(Action action) at Microsoft.VisualStudio.Services.VsTask.InternalGetResult(Boolean ignoreUIThreadCheck) at Microsoft.VisualStudio.Services.VsTask.GetResult()

To Reproduce
Steps to reproduce the behavior:

  1. Download 1.1.44
  2. Open visual studio
  3. See error, error log pasted from ActivityLog.xml

Expected behavior
No error

Also tried to clear MEF cache, did not have effect.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.