From 3202907959328e69d6ca40acacc0d5f60569b468 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Wed, 21 Aug 2024 20:57:49 +0100 Subject: [PATCH 01/13] Check path names --- .github/workflows/continuous_integration.yml | 1 + tools/ci/check_path_names.sh | 28 ++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tools/ci/check_path_names.sh diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index d52ea0e45f3d5..6806bf0287285 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -48,6 +48,7 @@ jobs: find . -name "*.php" -print0 | xargs -0 -n1 php -l find . -name "*.json" -not -path "*/node_modules/*" -print0 | xargs -0 python ./tools/json_verifier.py bash tools/ci/check_grep.sh + bash tools/ci/check_path_names.sh tools/build/build --ci lint tgui-test tools/bootstrap/python -m dmi.test tools/bootstrap/python -m mapmerge2.dmm_test diff --git a/tools/ci/check_path_names.sh b/tools/ci/check_path_names.sh new file mode 100644 index 0000000000000..c8c94afbc9875 --- /dev/null +++ b/tools/ci/check_path_names.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -euo pipefail + +#ANSI Escape Codes for colors to increase contrast of errors +RED="\033[0;31m" +GREEN="\033[0;32m" +BLUE="\033[0;34m" +NC="\033[0m" # No Color + +st=0 + +# Check for inconsistent capitalisation +# Allows full capitalisation within sections (proc/get_RGB) +# Allows full capitalisation (proc/REF) +# Disallows inconsistent capitalisation (proc/Ref, prof/ReF) +regex_path_name = "^\s*(?:\/\w+)*\/?proc\/((?:[a-z]+[A-Z]+[a-z]*_|[a-z]*[A-Z]+[a-z]+_|[A-Z]+[a-z]+[A-Z]+_)+\w*|\w*_(?:[a-z]+[A-Z]+[a-z]*|[a-z]*[A-Z]+[a-z]+|[A-Z]+[a-z]+[A-Z]+)|[a-z]+[A-Z]+[a-z]*|[a-z]*[A-Z]+[a-z]+|[A-Z]+[a-z]+[A-Z]+)+\(" + +for code in code/**/*.dm +do + if [[ code =~ "LINT_PATHNAME_IGNORE"]] + if [[ code =~ $regex_path_name]] # If it starts with brackets it's a list + then + echo "The proc ${BASH_REMATCH[1]} contains upper-case letters when it should use snake_case." + st=1 + fi +done + +exit $st From fecff9b129d3491fb920ddd958c946ff046b994c Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:02:01 +0100 Subject: [PATCH 02/13] Update check_path_names.sh --- tools/ci/check_path_names.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/ci/check_path_names.sh b/tools/ci/check_path_names.sh index c8c94afbc9875..3fd79a22c1854 100644 --- a/tools/ci/check_path_names.sh +++ b/tools/ci/check_path_names.sh @@ -9,11 +9,14 @@ NC="\033[0m" # No Color st=0 + +echo -e "${BLUE}Checking for proc name violations...${NC}" + # Check for inconsistent capitalisation # Allows full capitalisation within sections (proc/get_RGB) # Allows full capitalisation (proc/REF) # Disallows inconsistent capitalisation (proc/Ref, prof/ReF) -regex_path_name = "^\s*(?:\/\w+)*\/?proc\/((?:[a-z]+[A-Z]+[a-z]*_|[a-z]*[A-Z]+[a-z]+_|[A-Z]+[a-z]+[A-Z]+_)+\w*|\w*_(?:[a-z]+[A-Z]+[a-z]*|[a-z]*[A-Z]+[a-z]+|[A-Z]+[a-z]+[A-Z]+)|[a-z]+[A-Z]+[a-z]*|[a-z]*[A-Z]+[a-z]+|[A-Z]+[a-z]+[A-Z]+)+\(" +regex_path_name="^\s*(?:\/\w+)*\/?proc\/((?:[a-z]+[A-Z]+[a-z]*_|[a-z]*[A-Z]+[a-z]+_|[A-Z]+[a-z]+[A-Z]+_)+\w*|\w*_(?:[a-z]+[A-Z]+[a-z]*|[a-z]*[A-Z]+[a-z]+|[A-Z]+[a-z]+[A-Z]+)|[a-z]+[A-Z]+[a-z]*|[a-z]*[A-Z]+[a-z]+|[A-Z]+[a-z]+[A-Z]+)+\(" for code in code/**/*.dm do From 5639fc2616a40ec5153e5f698162f8cc6516b62d Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Thu, 22 Aug 2024 21:53:53 +0100 Subject: [PATCH 03/13] Update check_path_names.sh --- tools/ci/check_path_names.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/ci/check_path_names.sh b/tools/ci/check_path_names.sh index 3fd79a22c1854..b005919201f52 100644 --- a/tools/ci/check_path_names.sh +++ b/tools/ci/check_path_names.sh @@ -21,7 +21,10 @@ regex_path_name="^\s*(?:\/\w+)*\/?proc\/((?:[a-z]+[A-Z]+[a-z]*_|[a-z]*[A-Z]+[a-z for code in code/**/*.dm do if [[ code =~ "LINT_PATHNAME_IGNORE"]] - if [[ code =~ $regex_path_name]] # If it starts with brackets it's a list + then + continue + fi + if [[ code =~ $regex_path_name]] # If it starts with brackets it's a list then echo "The proc ${BASH_REMATCH[1]} contains upper-case letters when it should use snake_case." st=1 From d767af63f76fd841938785f3895916e0d4de88c9 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:08:53 +0100 Subject: [PATCH 04/13] Update check_path_names.sh --- tools/ci/check_path_names.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/ci/check_path_names.sh b/tools/ci/check_path_names.sh index b005919201f52..5884a9c1d8538 100644 --- a/tools/ci/check_path_names.sh +++ b/tools/ci/check_path_names.sh @@ -1,7 +1,7 @@ #!/bin/bash set -euo pipefail -#ANSI Escape Codes for colors to increase contrast of errors +# ANSI Escape Codes for colors to increase contrast of errors RED="\033[0;31m" GREEN="\033[0;32m" BLUE="\033[0;34m" @@ -9,25 +9,25 @@ NC="\033[0m" # No Color st=0 - echo -e "${BLUE}Checking for proc name violations...${NC}" -# Check for inconsistent capitalisation -# Allows full capitalisation within sections (proc/get_RGB) -# Allows full capitalisation (proc/REF) -# Disallows inconsistent capitalisation (proc/Ref, prof/ReF) +# Regex to match inconsistent capitalization in proc names regex_path_name="^\s*(?:\/\w+)*\/?proc\/((?:[a-z]+[A-Z]+[a-z]*_|[a-z]*[A-Z]+[a-z]+_|[A-Z]+[a-z]+[A-Z]+_)+\w*|\w*_(?:[a-z]+[A-Z]+[a-z]*|[a-z]*[A-Z]+[a-z]+|[A-Z]+[a-z]+[A-Z]+)|[a-z]+[A-Z]+[a-z]*|[a-z]*[A-Z]+[a-z]+|[A-Z]+[a-z]+[A-Z]+)+\(" -for code in code/**/*.dm -do - if [[ code =~ "LINT_PATHNAME_IGNORE"]] - then - continue - fi - if [[ code =~ $regex_path_name]] # If it starts with brackets it's a list - then - echo "The proc ${BASH_REMATCH[1]} contains upper-case letters when it should use snake_case." - st=1 +# Find and loop through every .dm file in the code/ directory +find code/ -type f -name "*.dm" | while IFS= read -r file; do + # Check if the file contains the string "LINT_PATHNAME_IGNORE" + if grep -q "LINT_PATHNAME_IGNORE" "$file"; then + continue + fi + + # Run the regex against the contents of the file and store the result + matches=$(grep -Po "$regex_path_name" "$file" || true) + + if [[ -n "$matches" ]]; then + echo -e "${RED}Violation found in file: $file${NC}" + echo "$matches" + st=1 fi done From a1710f70860096013e32b989c3303a48ec4ffe52 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:35:59 +0100 Subject: [PATCH 05/13] Adds an update program --- tools/SnakeCaseUpdate/.gitignore | 398 +++++++++++++++++++ tools/SnakeCaseUpdate/Program.cs | 65 +++ tools/SnakeCaseUpdate/SnakeCaseUpdate.csproj | 10 + tools/SnakeCaseUpdate/SnakeCaseUpdate.sln | 25 ++ 4 files changed, 498 insertions(+) create mode 100644 tools/SnakeCaseUpdate/.gitignore create mode 100644 tools/SnakeCaseUpdate/Program.cs create mode 100644 tools/SnakeCaseUpdate/SnakeCaseUpdate.csproj create mode 100644 tools/SnakeCaseUpdate/SnakeCaseUpdate.sln diff --git a/tools/SnakeCaseUpdate/.gitignore b/tools/SnakeCaseUpdate/.gitignore new file mode 100644 index 0000000000000..8dd4607a4b3c4 --- /dev/null +++ b/tools/SnakeCaseUpdate/.gitignore @@ -0,0 +1,398 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml \ No newline at end of file diff --git a/tools/SnakeCaseUpdate/Program.cs b/tools/SnakeCaseUpdate/Program.cs new file mode 100644 index 0000000000000..80e3114d4922a --- /dev/null +++ b/tools/SnakeCaseUpdate/Program.cs @@ -0,0 +1,65 @@ +using System.Text.RegularExpressions; + +static string ToSnakeCase(string name) +{ + return Regex.Replace(name, "([a-z])([A-Z])", "$1_$2").ToLower(); +} + +static void UpdateFile(string filePath, string oldName, string newName) +{ + var text = File.ReadAllText(filePath); + var updated = Regex.Replace(text, $@"\b{Regex.Escape(oldName)}\(", $"{newName}(", RegexOptions.Multiline); + if (updated == text) + return; + Console.WriteLine($"Updated {oldName} to {newName} in {filePath}"); + + //File.WriteAllText(filePath, updated); +} + +string basePath = "../../../../../code"; +string regexPattern = @"^\s*(?:\/\w+)*\/?proc\/((?:[a-z]+[A-Z]+[a-z]*_|[a-z]*[A-Z]+[a-z]+_|[A-Z]+[a-z]+[A-Z]+_)+\w*|\w*_(?:[a-z]+[A-Z]+[a-z]*|[a-z]*[A-Z]+[a-z]+|[A-Z]+[a-z]+[A-Z]+)|[a-z]+[A-Z]+[a-z]*|[a-z]*[A-Z]+[a-z]+|[A-Z]+[a-z]+[A-Z]+)+\("; +string ignoreString = "LINT_PATHNAME_IGNORE"; +int minFunctionNameLength = 7; + +var files = Directory.EnumerateFiles(basePath, "*.dm", SearchOption.AllDirectories); + +foreach (var file in files) +{ + // Skip files containing the ignore string + var fileContent = File.ReadAllText(file); + if (fileContent.Contains(ignoreString)) + continue; + + var matches = Regex.Matches(fileContent, regexPattern, RegexOptions.Compiled | RegexOptions.Multiline); + + foreach (Match match in matches) + { + var funcName = match.Groups[1].Value; + + if (!string.IsNullOrEmpty(funcName) && funcName.Length >= minFunctionNameLength) + { + string snakeCaseName = ToSnakeCase(funcName); + + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine($"Updating function {funcName} to {snakeCaseName} in {file}"); + Console.ResetColor(); + + // Update function name in the definition + UpdateFile(file, funcName, snakeCaseName); + + // Update function references in the entire codebase + foreach (var refFile in files) + { + if (refFile == file) continue; // Skip the file being updated + + UpdateFile(refFile, funcName, snakeCaseName); + } + } + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"Skipped {funcName}"); + Console.ResetColor(); + } + } +} diff --git a/tools/SnakeCaseUpdate/SnakeCaseUpdate.csproj b/tools/SnakeCaseUpdate/SnakeCaseUpdate.csproj new file mode 100644 index 0000000000000..2150e3797ba5e --- /dev/null +++ b/tools/SnakeCaseUpdate/SnakeCaseUpdate.csproj @@ -0,0 +1,10 @@ + + + + Exe + net8.0 + enable + enable + + + diff --git a/tools/SnakeCaseUpdate/SnakeCaseUpdate.sln b/tools/SnakeCaseUpdate/SnakeCaseUpdate.sln new file mode 100644 index 0000000000000..5098dc28eda66 --- /dev/null +++ b/tools/SnakeCaseUpdate/SnakeCaseUpdate.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.35027.167 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnakeCaseUpdate", "SnakeCaseUpdate.csproj", "{33861A54-99CC-40D1-B4D0-3C8A3A8CF45A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {33861A54-99CC-40D1-B4D0-3C8A3A8CF45A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {33861A54-99CC-40D1-B4D0-3C8A3A8CF45A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {33861A54-99CC-40D1-B4D0-3C8A3A8CF45A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {33861A54-99CC-40D1-B4D0-3C8A3A8CF45A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D00FD726-735C-4C55-9E57-8ADE1477912D} + EndGlobalSection +EndGlobal From 6eeb04c4dd985a9f9de3c9579c3050cc3581fcbc Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:38:53 +0100 Subject: [PATCH 06/13] Allow initialise to stay --- tools/SnakeCaseUpdate/Program.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/SnakeCaseUpdate/Program.cs b/tools/SnakeCaseUpdate/Program.cs index 80e3114d4922a..ca3ab91427ad3 100644 --- a/tools/SnakeCaseUpdate/Program.cs +++ b/tools/SnakeCaseUpdate/Program.cs @@ -13,7 +13,7 @@ static void UpdateFile(string filePath, string oldName, string newName) return; Console.WriteLine($"Updated {oldName} to {newName} in {filePath}"); - //File.WriteAllText(filePath, updated); + File.WriteAllText(filePath, updated); } string basePath = "../../../../../code"; @@ -36,6 +36,10 @@ static void UpdateFile(string filePath, string oldName, string newName) { var funcName = match.Groups[1].Value; + // Fine... you get the right to live + if (funcName == "Initialize") + continue; + if (!string.IsNullOrEmpty(funcName) && funcName.Length >= minFunctionNameLength) { string snakeCaseName = ToSnakeCase(funcName); @@ -44,14 +48,9 @@ static void UpdateFile(string filePath, string oldName, string newName) Console.WriteLine($"Updating function {funcName} to {snakeCaseName} in {file}"); Console.ResetColor(); - // Update function name in the definition - UpdateFile(file, funcName, snakeCaseName); - // Update function references in the entire codebase foreach (var refFile in files) { - if (refFile == file) continue; // Skip the file being updated - UpdateFile(refFile, funcName, snakeCaseName); } } From 136dd7710b37f09b23ed9f82a0de1bd9e6e8a053 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:42:49 +0100 Subject: [PATCH 07/13] Update .gitignore --- tools/SnakeCaseUpdate/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/SnakeCaseUpdate/.gitignore b/tools/SnakeCaseUpdate/.gitignore index 8dd4607a4b3c4..8a30d258ed9d0 100644 --- a/tools/SnakeCaseUpdate/.gitignore +++ b/tools/SnakeCaseUpdate/.gitignore @@ -395,4 +395,4 @@ FodyWeavers.xsd *.msp # JetBrains Rider -*.sln.iml \ No newline at end of file +*.sln.iml From 3e95c6488a526cb37802e4ed5b11262d34da1c18 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:46:05 +0100 Subject: [PATCH 08/13] Updates a few things that could cause us problems --- code/__DEFINES/tgs.dm | 2 ++ code/controllers/subsystem/dbcore.dm | 2 ++ tools/SnakeCaseUpdate/Program.cs | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/code/__DEFINES/tgs.dm b/code/__DEFINES/tgs.dm index 4766b3dfe661e..38eb9e708950e 100644 --- a/code/__DEFINES/tgs.dm +++ b/code/__DEFINES/tgs.dm @@ -1,3 +1,5 @@ +// LINT_PATHNAME_IGNORE + // tgstation-server DMAPI // The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in IETF RFC 2119. diff --git a/code/controllers/subsystem/dbcore.dm b/code/controllers/subsystem/dbcore.dm index 556af64d4f899..7c2c301b3336a 100644 --- a/code/controllers/subsystem/dbcore.dm +++ b/code/controllers/subsystem/dbcore.dm @@ -1,3 +1,5 @@ +// LINT_PATHNAME_IGNORE + SUBSYSTEM_DEF(dbcore) name = "Database" flags = SS_TICKER diff --git a/tools/SnakeCaseUpdate/Program.cs b/tools/SnakeCaseUpdate/Program.cs index ca3ab91427ad3..c8e1c12e787c8 100644 --- a/tools/SnakeCaseUpdate/Program.cs +++ b/tools/SnakeCaseUpdate/Program.cs @@ -37,7 +37,7 @@ static void UpdateFile(string filePath, string oldName, string newName) var funcName = match.Groups[1].Value; // Fine... you get the right to live - if (funcName == "Initialize") + if (funcName == "Initialize" || funcName == "Destroy" || funcName == "Entered" || funcName == "Exited" || funcName == "Animate") continue; if (!string.IsNullOrEmpty(funcName) && funcName.Length >= minFunctionNameLength) From b03b384ab3cdafc6814369cec8204a254e29709d Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:58:34 +0100 Subject: [PATCH 09/13] Optimises the update script --- tools/SnakeCaseUpdate/Program.cs | 50 +++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/tools/SnakeCaseUpdate/Program.cs b/tools/SnakeCaseUpdate/Program.cs index c8e1c12e787c8..baea0f17bd181 100644 --- a/tools/SnakeCaseUpdate/Program.cs +++ b/tools/SnakeCaseUpdate/Program.cs @@ -5,15 +5,14 @@ static string ToSnakeCase(string name) return Regex.Replace(name, "([a-z])([A-Z])", "$1_$2").ToLower(); } -static void UpdateFile(string filePath, string oldName, string newName) +static bool UpdateFile(string filePath, string oldName, string newName) { var text = File.ReadAllText(filePath); var updated = Regex.Replace(text, $@"\b{Regex.Escape(oldName)}\(", $"{newName}(", RegexOptions.Multiline); if (updated == text) - return; - Console.WriteLine($"Updated {oldName} to {newName} in {filePath}"); - + return false; File.WriteAllText(filePath, updated); + return true; } string basePath = "../../../../../code"; @@ -23,6 +22,13 @@ static void UpdateFile(string filePath, string oldName, string newName) var files = Directory.EnumerateFiles(basePath, "*.dm", SearchOption.AllDirectories); +Dictionary updatedFunctionNames = new Dictionary(); + +List skippedFunctionNames = new List(); + + +Console.ForegroundColor = ConsoleColor.Yellow; + foreach (var file in files) { // Skip files containing the ignore string @@ -43,22 +49,32 @@ static void UpdateFile(string filePath, string oldName, string newName) if (!string.IsNullOrEmpty(funcName) && funcName.Length >= minFunctionNameLength) { string snakeCaseName = ToSnakeCase(funcName); - - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine($"Updating function {funcName} to {snakeCaseName} in {file}"); - Console.ResetColor(); - - // Update function references in the entire codebase - foreach (var refFile in files) - { - UpdateFile(refFile, funcName, snakeCaseName); - } + updatedFunctionNames.TryAdd(funcName, snakeCaseName); + Console.WriteLine($"Renaming {funcName} to {snakeCaseName}"); } else { - Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"Skipped {funcName}"); - Console.ResetColor(); + skippedFunctionNames.Add(funcName); } } } + +Console.ForegroundColor = ConsoleColor.Green; +Parallel.ForEach(files, (file, _, _) => { + int updates = 0; + foreach (var update in updatedFunctionNames) + { + updates += UpdateFile(file, update.Key, update.Value) ? 1 : 0; + } + if (updates > 0) + Console.WriteLine($"Updating {file}, applied {updates} updates..."); +}); +Console.ResetColor(); + +Console.ForegroundColor = ConsoleColor.Red; +Console.WriteLine($"Skipped the following function names due to being too short to reliably rename:"); +foreach (var skipped in skippedFunctionNames) +{ + Console.WriteLine(skipped); +} +Console.ResetColor(); From d99cd612786d8049539d5a710167841243d64db6 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Thu, 22 Aug 2024 22:59:15 +0100 Subject: [PATCH 10/13] Skip these files too --- code/datums/tgs_event_handler.dm | 2 ++ code/modules/tgs/core/tgs_version.dm | 2 ++ 2 files changed, 4 insertions(+) diff --git a/code/datums/tgs_event_handler.dm b/code/datums/tgs_event_handler.dm index f48ea7bff8d62..68f15fc3aa65b 100644 --- a/code/datums/tgs_event_handler.dm +++ b/code/datums/tgs_event_handler.dm @@ -1,3 +1,5 @@ +// LINT_PATHNAME_IGNORE + /datum/tgs_event_handler/impl var/datum/timedevent/reattach_timer diff --git a/code/modules/tgs/core/tgs_version.dm b/code/modules/tgs/core/tgs_version.dm index bc561e67487a2..d0a453548b018 100644 --- a/code/modules/tgs/core/tgs_version.dm +++ b/code/modules/tgs/core/tgs_version.dm @@ -1,3 +1,5 @@ +// LINT_PATHNAME_IGNORE + /datum/tgs_version/New(raw_parameter) ..() src.raw_parameter = raw_parameter From 8ac3ffda680383a52ca73192dd4f9a1f7d8fe750 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Thu, 22 Aug 2024 23:07:50 +0100 Subject: [PATCH 11/13] Fixes some more script issues --- tools/SnakeCaseUpdate/Program.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tools/SnakeCaseUpdate/Program.cs b/tools/SnakeCaseUpdate/Program.cs index baea0f17bd181..5f0099a90c774 100644 --- a/tools/SnakeCaseUpdate/Program.cs +++ b/tools/SnakeCaseUpdate/Program.cs @@ -8,7 +8,8 @@ static string ToSnakeCase(string name) static bool UpdateFile(string filePath, string oldName, string newName) { var text = File.ReadAllText(filePath); - var updated = Regex.Replace(text, $@"\b{Regex.Escape(oldName)}\(", $"{newName}(", RegexOptions.Multiline); + var updated = Regex.Replace(text, $@"[^/]{Regex.Escape(oldName)}\(", $"{newName}(", RegexOptions.Multiline); + updated = Regex.Replace(text, $@"_REF\({Regex.Escape(oldName)}\)", @$"REF\({newName}\)", RegexOptions.Multiline); if (updated == text) return false; File.WriteAllText(filePath, updated); @@ -43,8 +44,11 @@ static bool UpdateFile(string filePath, string oldName, string newName) var funcName = match.Groups[1].Value; // Fine... you get the right to live - if (funcName == "Initialize" || funcName == "Destroy" || funcName == "Entered" || funcName == "Exited" || funcName == "Animate") + if (funcName == "Initialize" || funcName == "Destroy" || funcName == "Entered" || funcName == "Exited" || funcName == "Animate" || funcName == "Replace" || funcName == "Execute") + { + skippedFunctionNames.Add(funcName); continue; + } if (!string.IsNullOrEmpty(funcName) && funcName.Length >= minFunctionNameLength) { From 51c665aa8b5f32a9c4070edf30da5dd6ee49d297 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Thu, 22 Aug 2024 23:11:32 +0100 Subject: [PATCH 12/13] Update Program.cs --- tools/SnakeCaseUpdate/Program.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/SnakeCaseUpdate/Program.cs b/tools/SnakeCaseUpdate/Program.cs index 5f0099a90c774..c68b12604a219 100644 --- a/tools/SnakeCaseUpdate/Program.cs +++ b/tools/SnakeCaseUpdate/Program.cs @@ -8,8 +8,7 @@ static string ToSnakeCase(string name) static bool UpdateFile(string filePath, string oldName, string newName) { var text = File.ReadAllText(filePath); - var updated = Regex.Replace(text, $@"[^/]{Regex.Escape(oldName)}\(", $"{newName}(", RegexOptions.Multiline); - updated = Regex.Replace(text, $@"_REF\({Regex.Escape(oldName)}\)", @$"REF\({newName}\)", RegexOptions.Multiline); + var updated = Regex.Replace(text, $@"([^/]|_REF\(){Regex.Escape(oldName)}[()]", $"$1{newName}(", RegexOptions.Multiline); if (updated == text) return false; File.WriteAllText(filePath, updated); From fc667763fa770ebff20f684afb701fabc3e58fed Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Thu, 22 Aug 2024 23:21:21 +0100 Subject: [PATCH 13/13] Update check_path_names.sh --- tools/ci/check_path_names.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci/check_path_names.sh b/tools/ci/check_path_names.sh index 5884a9c1d8538..ee158995f8bde 100644 --- a/tools/ci/check_path_names.sh +++ b/tools/ci/check_path_names.sh @@ -25,7 +25,7 @@ find code/ -type f -name "*.dm" | while IFS= read -r file; do matches=$(grep -Po "$regex_path_name" "$file" || true) if [[ -n "$matches" ]]; then - echo -e "${RED}Violation found in file: $file${NC}" + echo -e "${RED}ERROR: Non-snake case proc found in file: $file${NC}" echo "$matches" st=1 fi