Skip to content

Commit

Permalink
run autoformatter on all files (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoC0de committed Jul 23, 2023
1 parent 6a2fa48 commit e22a97e
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"jetbrains.resharper.globaltools": {
"version": "2022.3.1",
"version": "2023.1.4",
"commands": ["jb"]
}
}
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
hooks:
- id: "prettier"
additional_dependencies:
- prettier@v2.7.1
- prettier@v2.8.8
- "@prettier/plugin-xml@2.2.0"
- prettier-plugin-ini@v1.1.0
args:
Expand All @@ -32,7 +32,7 @@ repos:
require_serial: true
stages: [commit, merge-commit]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
exclude: \.(pdf|meta|prefab|shader|controller|asset|cginc|mat|unity|anim|shadergraph)$
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ The **Installed packages** part of the list shows packages directly installed as
The **Implicitly installed packages** part shows packages that are installed as transitive dependencies.
Click the **Uninstall** button to uninstall the package.
When uninstalling an **explicitely** installed package, all of its dependencies that are not a dependency of any other package or the project itself will also be uninstalled.
When uninstalling an **explicitely** installed package, all of its dependencies that are not a dependency of any other package or the project itself will also be uninstalled.
If **Add as explicit** is clicked on an **implicitly** installed package, it will be moved to the first part of the list and will **not** be automatically uninstalled in a scenario described above.
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetForUnity.Tests/Assets/Tests/Editor/NuGetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void InstallJsonTest()
[Test]
public void InstallRoslynAnalyzerTest()
{
var analyzer = new NugetPackageIdentifier("ErrorProne.NET.CoreAnalyzers", "0.1.2") {IsManuallyInstalled = true};
var analyzer = new NugetPackageIdentifier("ErrorProne.NET.CoreAnalyzers", "0.1.2") { IsManuallyInstalled = true };
if (NugetHelper.NugetConfigFile == null)
{
NugetHelper.LoadNugetConfigFile();
Expand Down
11 changes: 8 additions & 3 deletions src/NuGetForUnity/Editor/NugetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -864,13 +864,17 @@ public static void UpdateInstalledPackages()
if (Directory.Exists(NugetConfigFile.RepositoryPath))
{
var manuallyInstalledPackagesNumber = 0;

void AddPackageToInstalled(NugetPackage package)
{
if (!installedPackages.ContainsKey(package.Id))
{
package.IsManuallyInstalled =
PackagesConfigFile.Packages.Find(pkg => pkg.Id == package.Id)?.IsManuallyInstalled ?? false;
if (package.IsManuallyInstalled) manuallyInstalledPackagesNumber++;
package.IsManuallyInstalled = PackagesConfigFile.Packages.Find(pkg => pkg.Id == package.Id)?.IsManuallyInstalled ?? false;
if (package.IsManuallyInstalled)
{
manuallyInstalledPackagesNumber++;
}

installedPackages.Add(package.Id, package);
}
else
Expand Down Expand Up @@ -902,6 +906,7 @@ void AddPackageToInstalled(NugetPackage package)
{
PackagesConfigFile.SetManuallyInstalledFlag(rootPackage);
}

PackagesConfigFile.Save(PackagesConfigFilePath);
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/NuGetForUnity/Editor/NugetODataResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public static List<NugetPackage> Parse(XDocument document)
{
var packages = new List<NugetPackage>();

if (document.Root == null) return packages;
if (document.Root == null)
{
return packages;
}

IEnumerable<XElement> packageEntries;
if (document.Root.Name.Equals(XName.Get("entry", AtomNamespace)))
Expand All @@ -63,8 +66,7 @@ public static List<NugetPackage> Parse(XDocument document)
{
var package = new NugetPackage
{
Id = entry.GetAtomElement("title").Value,
DownloadUrl = entry.GetAtomElement("content").Attribute("src")?.Value
Id = entry.GetAtomElement("title").Value, DownloadUrl = entry.GetAtomElement("content").Attribute("src")?.Value,
};

var entryProperties = entry.Element(XName.Get("properties", MetaDataNamespace));
Expand Down
8 changes: 4 additions & 4 deletions src/NuGetForUnity/Editor/NugetPackageIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ public class NugetPackageIdentifier : IEquatable<NugetPackageIdentifier>, ICompa
public string Id;

/// <summary>
/// Gets or sets the version number of the NuGet package.
/// Gets or sets whether this package was installed manually or just as a dependency.
/// </summary>
public string Version;
public bool IsManuallyInstalled;

/// <summary>
/// Gets or sets whether this package was installed manually or just as a dependency.
/// Gets or sets the version number of the NuGet package.
/// </summary>
public bool IsManuallyInstalled;
public string Version;

/// <summary>
/// Initializes a new instance of a <see cref="NugetPackageIdentifider" /> with empty ID and Version.
Expand Down
62 changes: 35 additions & 27 deletions src/NuGetForUnity/Editor/NugetWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ public class NugetWindow : EditorWindow

private const string GitHubReleasesApiUrl = "https://api.github.com/repos/GlitchEnzo/NuGetForUnity/releases?per_page=10";

private static GUIStyle cachedHeaderStyle;

private static GUIStyle cachedBackgroundStyle;

private static GUIStyle cachedFoldoutStyle;

private static GUIStyle cachedContrastStyle;

private readonly Dictionary<string, bool> foldouts = new Dictionary<string, bool>();

/// <summary>
Expand Down Expand Up @@ -64,6 +72,8 @@ public class NugetWindow : EditorWindow
[SerializeField]
private Texture2D defaultIcon;

private List<NugetPackage> filteredInstalledPackages;

/// <summary>
/// True when the NugetWindow has initialized. This is used to skip time-consuming reloading operations when the assembly is reloaded.
/// </summary>
Expand All @@ -77,8 +87,6 @@ public class NugetWindow : EditorWindow

private string lastInstalledSearchTerm;

private List<NugetPackage> filteredInstalledPackages;

/// <summary>
/// The number of packages to skip when requesting a list of packages from the server. This is used to get a new group of packages.
/// </summary>
Expand All @@ -105,6 +113,8 @@ public class NugetWindow : EditorWindow
/// </summary>
private bool showAllUpdateVersions;

private bool showImplicitlyInstalled;

/// <summary>
/// True to show beta and alpha package versions. False to only show stable versions.
/// </summary>
Expand All @@ -126,16 +136,6 @@ public class NugetWindow : EditorWindow
/// </summary>
private string updatesSearchTerm = "Search";

private bool showImplicitlyInstalled;

private static GUIStyle cachedHeaderStyle;

private static GUIStyle cachedBackgroundStyle;

private static GUIStyle cachedFoldoutStyle;

private static GUIStyle cachedContrastStyle;

/// <summary>
/// The filtered list of package updates available.
/// </summary>
Expand Down Expand Up @@ -172,14 +172,17 @@ private List<NugetPackage> FilteredInstalledPackages
else
{
filteredInstalledPackages = NugetHelper.InstalledPackages.Where(
package => package.Id.IndexOf(installedSearchTerm, StringComparison.InvariantCultureIgnoreCase) >= 0 ||
package.Title.IndexOf(installedSearchTerm, StringComparison.InvariantCultureIgnoreCase) >= 0).ToList();
package => package.Id.IndexOf(installedSearchTerm, StringComparison.InvariantCultureIgnoreCase) >= 0 ||
package.Title.IndexOf(installedSearchTerm, StringComparison.InvariantCultureIgnoreCase) >= 0)
.ToList();
}
filteredInstalledPackages.Sort((p1, p2) =>
{
var cmp = p2.IsManuallyInstalled.CompareTo(p1.IsManuallyInstalled);
return cmp != 0 ? cmp : string.Compare(p1.Id, p2.Id, StringComparison.Ordinal);
});

filteredInstalledPackages.Sort(
(p1, p2) =>
{
var cmp = p2.IsManuallyInstalled.CompareTo(p1.IsManuallyInstalled);
return cmp != 0 ? cmp : string.Compare(p1.Id, p2.Id, StringComparison.Ordinal);
});

return filteredInstalledPackages;
}
Expand Down Expand Up @@ -393,12 +396,12 @@ private void Refresh(bool forceFullRefresh)
/// </summary>
private void UpdateOnlinePackages()
{
availablePackages = NugetHelper.Search(
onlineSearchTerm != "Search" ? onlineSearchTerm : string.Empty,
showAllOnlineVersions,
showOnlinePrerelease,
numberToGet,
numberToSkip);
availablePackages = NugetHelper.Search(
onlineSearchTerm != "Search" ? onlineSearchTerm : string.Empty,
showAllOnlineVersions,
showOnlinePrerelease,
numberToGet,
numberToSkip);
}

private void UpdateInstalledPackages()
Expand Down Expand Up @@ -544,7 +547,7 @@ private static GUIStyle GetFoldoutStyle()
onFocused = { textColor = Color.white },
active = { textColor = Color.white },
onActive = { textColor = Color.white },
alignment = TextAnchor.MiddleLeft
alignment = TextAnchor.MiddleLeft,
};

return cachedFoldoutStyle;
Expand Down Expand Up @@ -601,7 +604,12 @@ private void DrawInstalled()
var rectangle = EditorGUILayout.GetControlRect(true, 20f, headerStyle);
EditorGUI.LabelField(rectangle, "", headerStyle);

showImplicitlyInstalled = EditorGUI.Foldout(rectangle, showImplicitlyInstalled, "Implicitly installed packages", true, GetFoldoutStyle());
showImplicitlyInstalled = EditorGUI.Foldout(
rectangle,
showImplicitlyInstalled,
"Implicitly installed packages",
true,
GetFoldoutStyle());
if (showImplicitlyInstalled)
{
DrawPackages(installedPackages.SkipWhile(package => package.IsManuallyInstalled), true);
Expand Down
4 changes: 2 additions & 2 deletions src/NuGetForUnity/Editor/PackagesConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ public static PackagesConfigFile Load(string filepath)
{
Id = packageElement.Attribute("id").Value,
Version = packageElement.Attribute("version").Value,
IsManuallyInstalled = packageElement.Attribute("manuallyInstalled")?.Value.Equals("true",
StringComparison.OrdinalIgnoreCase) ?? false,
IsManuallyInstalled =
packageElement.Attribute("manuallyInstalled")?.Value.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false,
AutoReferenced = (bool)(packageElement.Attributes(AutoReferencedAttributeName).FirstOrDefault() ??
new XAttribute(AutoReferencedAttributeName, true)),
};
Expand Down
12 changes: 12 additions & 0 deletions tools/format-all.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
$ErrorActionPreference = 'Stop'

$repositoryRoot = Resolve-Path $PSScriptRoot\..
$currentLocation = Get-Location

try {
Set-Location $repositoryRoot
. pre-commit run --verbose --all-files --hook-stage manual
}
finally {
Set-Location $currentLocation
}
49 changes: 49 additions & 0 deletions tools/update-tools.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
$ErrorActionPreference = 'Stop'

$repositoryRoot = Resolve-Path $PSScriptRoot\..
$currentLocation = Get-Location

function Get-LatestVersionGitHubTag {
param (
[string]$Organization,
[string]$Repository
)

foreach ($pageSize in @(10, 100)) {
$lastTags = (Invoke-WebRequest -Method GET -Uri https://api.github.com/repos/$Organization/$Repository/tags?per_page=$pageSize).Content | ConvertFrom-Json
$latestStableTag = $lastTags | Where-Object { $_.name -match '^v?[\d\.]+$' }
if ($latestStableTag -and $latestStableTag[0].name -match "v?([\d\.]+$)") {
return $Matches[1]
}
}

throw "Unable to find latest tag for GitHub repository $Organization/$Repository"
}

try {
Set-Location $repositoryRoot
Write-Host -ForegroundColor Green "Update ReSharper global tool"
. dotnet tool update JetBrains.ReSharper.GlobalTools
Write-Host -ForegroundColor Green "Update pre-commit"
. pip install --upgrade pre-commit --user
. pre-commit autoupdate
$content = Get-Content -Path ".\.pre-commit-config.yaml" -Raw
if ($content -match "(?smi)repo: https://github.com/pre-commit/mirrors-prettier\s*rev:\s*v([\d.]+)")
{
$prettierVersion = $Matches[1]
$content = $content -replace "prettier@v([\d.]+)", "prettier@v$prettierVersion"

$xrmlPluginVersion = Get-LatestVersionGitHubTag -Organization "prettier" -Repository "plugin-xml"
$content = $content -replace "@prettier/plugin-xml@([\d.]+)", "@prettier/plugin-xml@$xrmlPluginVersion"

$iniPluginVersion = Get-LatestVersionGitHubTag -Organization "kddnewton" -Repository "prettier-plugin-ini"
$content = $content -replace "prettier-plugin-ini@v([\d.]+)", "prettier-plugin-ini@v$iniPluginVersion"
}

Write-Host -ForegroundColor Green "Fromat config with pre-commit"
Set-Content -Path ".\.pre-commit-config.yaml" -Value $content
. pre-commit run --verbose --files .\.pre-commit-config.yaml .\.config\dotnet-tools.json
}
finally {
Set-Location $currentLocation
}

0 comments on commit e22a97e

Please sign in to comment.