Skip to content

Commit

Permalink
Code clean up (#2692)
Browse files Browse the repository at this point in the history
  • Loading branch information
BernieWhite authored Jan 3, 2025
1 parent 8716ba7 commit 03a0692
Show file tree
Hide file tree
Showing 38 changed files with 175 additions and 230 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ dotnet_style_readonly_field = true:suggestion
csharp_style_namespace_declarations = file_scoped:error
dotnet_diagnostic.IDE0005.severity = error

# Compiler warnings
dotnet_diagnostic.CS0472.severity = error
dotnet_diagnostic.CS0436.severity = error

# License header
file_header_template = Copyright (c) Microsoft Corporation.\nLicensed under the MIT License.
dotnet_diagnostic.IDE0073.severity = error
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
global-json-file: global.json

- name: Install dependencies
shell: pwsh
Expand Down Expand Up @@ -115,7 +115,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
global-json-file: global.json

- if: ${{ matrix.shell == 'pwsh' }}
name: Install dependencies (PowerShell)
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
global-json-file: global.json

- name: Install dependencies
timeout-minutes: 3
Expand Down Expand Up @@ -214,6 +214,11 @@ jobs:
with:
node-version: 20

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- name: Install dependencies
timeout-minutes: 3
run: |
Expand Down
44 changes: 2 additions & 42 deletions docs/hooks/old_hooks.py → docs/hooks/maml_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import mkdocs.structure.pages

log = logging.getLogger(f"mkdocs.plugins.{__name__}")
rulesItem: mkdocs.structure.nav.Section = mkdocs.structure.nav.Section("Rules", [])

# Replace MAML headers
def on_page_markdown(markdown: str, page: mkdocs.structure.nav.Page, config: mkdocs.config.Config, files: mkdocs.structure.files.Files) -> str:
'''Hook on_page_markdown event.'''

markdown = markdown.replace("## about_PSRule_Assert", "")
markdown = markdown.replace("## about_PSRule_Baseline", "")
markdown = markdown.replace("## about_PSRule_Badges", "")
Expand Down Expand Up @@ -59,44 +60,3 @@ def on_page_markdown(markdown: str, page: mkdocs.structure.nav.Page, config: mkd
markdown = re.sub(r"\@([\w-]*)", r"[@\g<1>](https://github.com/\g<1>)", markdown)

return markdown

# Dynamically build reference nav
def build_reference_nav(nav: mkdocs.structure.nav.Navigation, config: mkdocs.config.Config, files: mkdocs.structure.files.Files) -> mkdocs.structure.nav.Navigation:
build_rule_nav(nav, config, files)
build_baseline_nav(nav, config, files)
return nav

# Build Rules list
def build_rule_nav(nav: mkdocs.structure.nav.Navigation, config: mkdocs.config.Config, files: mkdocs.structure.files.Files):
children = []
item: mkdocs.structure.nav.Section = mkdocs.structure.nav.Section("Rules", children)

for f in files:
if not f.is_documentation_page():
continue

if not f._get_stem().startswith("Azure."):
continue

if f._get_dest_path(False).__contains__("/rules/"):
children.append(mkdocs.structure.pages.Page(f._get_stem(), f, config))

referenceItem: mkdocs.structure.nav.Section = next(x for x in nav if x.title == "Reference")
referenceItem.children.append(item)
mkdocs.structure.nav._add_parent_links(nav)

# Build Baselines list
def build_baseline_nav(nav: mkdocs.structure.nav.Navigation, config: mkdocs.config.Config, files: mkdocs.structure.files.Files):
children = []
item: mkdocs.structure.nav.Section = mkdocs.structure.nav.Section("Baselines", children)

for f in files:
if not f.is_documentation_page():
continue

if f._get_dest_path(False).__contains__("/baselines/"):
children.append(mkdocs.structure.pages.Page(f._get_stem(), f, config))

referenceItem: mkdocs.structure.nav.Section = next(x for x in nav if x.title == "Reference")
referenceItem.children.append(item)
mkdocs.structure.nav._add_parent_links(nav)
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ plugins:
'changelog.md': 'CHANGELOG-v3.md'

hooks:
- docs/hooks/old_hooks.py
- docs/hooks/maml_formatting.py

# watch:
# - includes
Expand Down
1 change: 1 addition & 0 deletions ps-rule-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ input:
- '!**/*.psd1'
- '!**/*.psm1'
- '*.Designer.cs'
- '*.csproj'
6 changes: 3 additions & 3 deletions src/PSRule.Benchmark/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1986,8 +1986,8 @@
},
"YamlDotNet": {
"type": "Transitive",
"resolved": "16.2.1",
"contentHash": "im6zTVgesjcfTRfuMpnx51Rg2svWenp/3q5XBfcIzgj8PNIkkSD2xEl9HWcVi2SaJPP9XcXUdzed9gSDEuf1TA=="
"resolved": "16.3.0",
"contentHash": "SgMOdxbz8X65z8hraIs6hOEdnkH6hESTAIUa7viEngHOYaH+6q5XJmwr1+yb9vJpNQ19hCQY69xbFsLtXpobQA=="
},
"Microsoft.PSRule.Badges": {
"type": "Project",
Expand All @@ -2012,7 +2012,7 @@
"type": "Project",
"dependencies": {
"Newtonsoft.Json": "[13.0.3, )",
"YamlDotNet": "[16.2.1, )"
"YamlDotNet": "[16.3.0, )"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/PSRule.CommandLine/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1636,8 +1636,8 @@
},
"YamlDotNet": {
"type": "Transitive",
"resolved": "16.2.1",
"contentHash": "im6zTVgesjcfTRfuMpnx51Rg2svWenp/3q5XBfcIzgj8PNIkkSD2xEl9HWcVi2SaJPP9XcXUdzed9gSDEuf1TA=="
"resolved": "16.3.0",
"contentHash": "SgMOdxbz8X65z8hraIs6hOEdnkH6hESTAIUa7viEngHOYaH+6q5XJmwr1+yb9vJpNQ19hCQY69xbFsLtXpobQA=="
},
"Microsoft.PSRule.Badges": {
"type": "Project",
Expand Down Expand Up @@ -1668,7 +1668,7 @@
"type": "Project",
"dependencies": {
"Newtonsoft.Json": "[13.0.3, )",
"YamlDotNet": "[16.2.1, )"
"YamlDotNet": "[16.3.0, )"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/PSRule.EditorServices/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1635,8 +1635,8 @@
},
"YamlDotNet": {
"type": "Transitive",
"resolved": "16.2.1",
"contentHash": "im6zTVgesjcfTRfuMpnx51Rg2svWenp/3q5XBfcIzgj8PNIkkSD2xEl9HWcVi2SaJPP9XcXUdzed9gSDEuf1TA=="
"resolved": "16.3.0",
"contentHash": "SgMOdxbz8X65z8hraIs6hOEdnkH6hESTAIUa7viEngHOYaH+6q5XJmwr1+yb9vJpNQ19hCQY69xbFsLtXpobQA=="
},
"Microsoft.PSRule.Badges": {
"type": "Project",
Expand Down Expand Up @@ -1676,7 +1676,7 @@
"type": "Project",
"dependencies": {
"Newtonsoft.Json": "[13.0.3, )",
"YamlDotNet": "[16.2.1, )"
"YamlDotNet": "[16.3.0, )"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/PSRule.SDK/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1033,8 +1033,8 @@
},
"YamlDotNet": {
"type": "Transitive",
"resolved": "16.2.1",
"contentHash": "im6zTVgesjcfTRfuMpnx51Rg2svWenp/3q5XBfcIzgj8PNIkkSD2xEl9HWcVi2SaJPP9XcXUdzed9gSDEuf1TA=="
"resolved": "16.3.0",
"contentHash": "SgMOdxbz8X65z8hraIs6hOEdnkH6hESTAIUa7viEngHOYaH+6q5XJmwr1+yb9vJpNQ19hCQY69xbFsLtXpobQA=="
},
"Microsoft.PSRule.Badges": {
"type": "Project",
Expand All @@ -1059,7 +1059,7 @@
"type": "Project",
"dependencies": {
"Newtonsoft.Json": "[13.0.3, )",
"YamlDotNet": "[16.2.1, )"
"YamlDotNet": "[16.3.0, )"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/PSRule.Tool/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1633,8 +1633,8 @@
},
"YamlDotNet": {
"type": "Transitive",
"resolved": "16.2.1",
"contentHash": "im6zTVgesjcfTRfuMpnx51Rg2svWenp/3q5XBfcIzgj8PNIkkSD2xEl9HWcVi2SaJPP9XcXUdzed9gSDEuf1TA=="
"resolved": "16.3.0",
"contentHash": "SgMOdxbz8X65z8hraIs6hOEdnkH6hESTAIUa7viEngHOYaH+6q5XJmwr1+yb9vJpNQ19hCQY69xbFsLtXpobQA=="
},
"Microsoft.PSRule.Badges": {
"type": "Project",
Expand Down Expand Up @@ -1674,7 +1674,7 @@
"type": "Project",
"dependencies": {
"Newtonsoft.Json": "[13.0.3, )",
"YamlDotNet": "[16.2.1, )"
"YamlDotNet": "[16.3.0, )"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/PSRule.Types/Definitions/IResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public interface IResource : ILanguageBlock
/// <summary>
/// The source location of the resource.
/// </summary>
ISourceExtent Extent { get; }
ISourceExtent? Extent { get; }

/// <summary>
/// Additional information about the resource.
Expand Down
11 changes: 0 additions & 11 deletions src/PSRule.Types/Emitters/InternalFileStream.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/PSRule.Types/Options/BaselineOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public BaselineOption()
/// Create an option instance based on an existing object.
/// </summary>
/// <param name="option">The existing object to copy.</param>
public BaselineOption(BaselineOption option)
public BaselineOption(BaselineOption? option)
{
if (option == null)
return;
Expand Down Expand Up @@ -67,7 +67,7 @@ public override int GetHashCode()
/// The new instance uses any non-null values from <paramref name="o1"/>.
/// Any null values from <paramref name="o1"/> are replaced with <paramref name="o2"/>.
/// </summary>
public static BaselineOption Combine(BaselineOption o1, BaselineOption o2)
public static BaselineOption Combine(BaselineOption? o1, BaselineOption? o2)
{
var result = new BaselineOption(o1)
{
Expand Down
4 changes: 2 additions & 2 deletions src/PSRule.Types/Options/ExecutionOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ExecutionOption()
/// Creates a execution option by copying an existing instance.
/// </summary>
/// <param name="option">The option instance to copy.</param>
public ExecutionOption(ExecutionOption option)
public ExecutionOption(ExecutionOption? option)
{
if (option == null)
return;
Expand Down Expand Up @@ -143,7 +143,7 @@ public override int GetHashCode()
/// Merge two option instances by replacing any unset properties from <paramref name="o1"/> with <paramref name="o2"/> values.
/// Values from <paramref name="o1"/> that are set are not overridden.
/// </summary>
internal static ExecutionOption Combine(ExecutionOption o1, ExecutionOption o2)
internal static ExecutionOption Combine(ExecutionOption? o1, ExecutionOption? o2)
{
var result = new ExecutionOption(o1)
{
Expand Down
4 changes: 2 additions & 2 deletions src/PSRule.Types/Options/OverrideOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public OverrideOption()
/// Create an option instance based on an existing object.
/// </summary>
/// <param name="option">The existing object to copy.</param>
public OverrideOption(OverrideOption option)
public OverrideOption(OverrideOption? option)
{
if (option == null)
return;
Expand Down Expand Up @@ -71,7 +71,7 @@ public override int GetHashCode()
/// The new instance uses any non-null values from <paramref name="o1"/>.
/// Any null values from <paramref name="o1"/> are replaced with <paramref name="o2"/>.
/// </summary>
public static OverrideOption Combine(OverrideOption o1, OverrideOption o2)
public static OverrideOption Combine(OverrideOption? o1, OverrideOption? o2)
{
var result = new OverrideOption(o1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/PSRule/Commands/ExportConventionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected override void ProcessRecord()
var context = RunspaceContext.CurrentThread;
if (context == null) return;

var source = context.Source;
var source = context.Source!;
var errorPreference = GetErrorActionPreference();
var commentMetadata = GetCommentMetadata(source, MyInvocation.ScriptLineNumber, MyInvocation.OffsetInLine);
var metadata = new ResourceMetadata
Expand Down
Loading

0 comments on commit 03a0692

Please sign in to comment.