Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b41f473
essential functions of script
twofingerrightclick Oct 15, 2020
a86b6a7
saving md
twofingerrightclick Oct 15, 2020
b840d3d
saving md
twofingerrightclick Oct 15, 2020
17ff571
saving md
twofingerrightclick Oct 15, 2020
8e709ad
saving md
twofingerrightclick Oct 15, 2020
346a657
saving md
twofingerrightclick Oct 15, 2020
3afe460
saving md
twofingerrightclick Oct 15, 2020
4fcf9af
saving md
twofingerrightclick Oct 15, 2020
dfb894e
Test action
twofingerrightclick Oct 15, 2020
08cd660
test action
twofingerrightclick Oct 15, 2020
2a5c592
Create main.yml
twofingerrightclick Oct 20, 2020
cc3109c
Update main.yml
twofingerrightclick Oct 20, 2020
c2298ed
Merge pull request #128 from IntelliTect/GuidelineXMLtoMD
twofingerrightclick Oct 20, 2020
d92eaf3
Moved MarkdownOut files to the XML project
twofingerrightclick Oct 20, 2020
c9b1029
Merge pull request #129 from IntelliTect/GuidelineXMLtoMD
twofingerrightclick Oct 20, 2020
e70fca2
Update main.yml
twofingerrightclick Oct 20, 2020
78199e6
use system specific set path directory seperator for file access
twofingerrightclick Oct 20, 2020
93901c0
Merge pull request #130 from IntelliTect/GuidelineXMLtoMD
twofingerrightclick Oct 20, 2020
01fb5d5
Update main.yml
twofingerrightclick Oct 20, 2020
ca7854e
Update main.yml
twofingerrightclick Oct 20, 2020
82bf5ad
Update main.yml
twofingerrightclick Oct 20, 2020
2a3957e
Update main.yml
twofingerrightclick Oct 20, 2020
805daa6
Update main.yml
twofingerrightclick Oct 20, 2020
c7c6c4c
Update main.yml
twofingerrightclick Oct 20, 2020
2d6ad13
Update main.yml
twofingerrightclick Oct 20, 2020
59ea57a
remove extra files and rename output MD file
twofingerrightclick Oct 20, 2020
b0ee0bc
Update and rename main.yml to ConvertGuidelinesXmlToMarkdown.yml
twofingerrightclick Oct 20, 2020
d786a5b
Update ConvertGuidelinesXmlToMarkdown.yml
twofingerrightclick Oct 20, 2020
747496e
Print C# guidelines as a heading at top of file
twofingerrightclick Oct 21, 2020
5a6eed5
Update ConvertGuidelinesXmlToMarkdown.yml
twofingerrightclick Oct 21, 2020
f62cbf7
Update ConvertGuidelinesXmlToMarkdown.yml
twofingerrightclick Oct 21, 2020
fde717f
new coding guidelines MD File created
twofingerrightclick Oct 21, 2020
117388a
Apply suggestions from code review
twofingerrightclick Oct 21, 2020
49bf2bd
Added IntelliTect Analyzers and suppressed some null string warnings.
twofingerrightclick Oct 21, 2020
d850aed
Guideline class now has correct GetHashCode and Equals methods
twofingerrightclick Oct 21, 2020
703ef59
Update ConvertGuidelinesXmlToMarkdown.yml
twofingerrightclick Oct 22, 2020
f35ef84
Use simple-diff action
twofingerrightclick Oct 22, 2020
0d12591
Update ConvertGuidelinesXmlToMarkdown.yml
twofingerrightclick Oct 23, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/ConvertGuidelinesXmlToMarkdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#if the guidelines xml file is modified between commits to the master branch the associate markdown file is updated
name: Update csharp Markdown

on:
push:
branches:
- 'master'

jobs:
build:
runs-on: ubuntu-latest

env:
XmlFileName: "Guidelines(8th Edition).xml"

steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Simple Diff
uses: mudlabs/simple-diff@v1.0.2
id: diff
with:
# The path of the file or folder to find in the commits diff tree.
path: ./docs/${{ env.XmlFileName }}
# continue even if the xml file if the file isn't found in the diff tree (it wasn't changed). strict=true causes the action to fail otherwise
strict : false
- name: Guidelines xml status
run: |
echo "${{ env.XmlFileName }} modified = ${{ steps.diff.outputs.modified }}"
echo "${{ steps.diff.outputs.name }}"

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.301
if: steps.diff.outputs.modified == true

- name: restore_compile_run_createMD
run: |
dotnet restore
dotnet run --configuration Release --project ./XMLtoMD/GuidelineXmlToMD/GuidelineXmlToMD.csproj
./XMLtoMD/GuidelineXmlToMD/bin/Release/netcoreapp3.1/GuidelineXmlToMD "${{ env.XmlFileName }}"
if: steps.diff.outputs.modified == true

- name: Create commit and push to CodingGuideLinesMDUpdate
run: |
git config user.name '${{ github.actor }}'
git config user.email '${{ github.actor }}@users.noreply.github.com'
git add -A
git commit -m "new coding guidelines MD File created"
git push origin '${{ github.ref }}'
if: steps.diff.outputs.modified == true
11 changes: 11 additions & 0 deletions XMLtoMD/GuidelineXmlToMD/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "<Pending>")]
Copy link
Member

Choose a reason for hiding this comment

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

Suppressed warnings should have Justification filled out or be addressed.

[assembly: SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "From an Old Github Project, not for production")]
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "<Pending>")]

32 changes: 32 additions & 0 deletions XMLtoMD/GuidelineXmlToMD/Guideline.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;


namespace GuidelineXmlToMD
{
public class Guideline
{
public string Key { get; set; } = "";
public string Text { get; set; } = "";

public string Severity { get; set; } = "";

public string Section { get; set; } = "";
public string Subsection { get; set; } = "";

public List<string> Comments { get;} = new List<string>();
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
public List<string> Comments { get;} = new List<string>();
public List<string> Comments { get; } = new List<string>();


public override int GetHashCode()
{
return Key.GetHashCode();
}

public override bool Equals(object obj)
{
Guideline otherGuideline = obj as Guideline;

return otherGuideline != null && string.Equals(otherGuideline.Key, this.Key);
}

}

}
42 changes: 42 additions & 0 deletions XMLtoMD/GuidelineXmlToMD/GuidelineXmlFileReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace GuidelineXmlToMD
{
static class GuidelineXmlFileReader
{
public const string _Guideline = "guideline";
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice if these constants were put in their own static class. Since these are related to the structure of the XML and should be put in a class with a name that reflects that.

An even cleaner option is to use xsd to generate the XML classes/serializer so that you don't need to do it yourself.
You can find the doc on that here

public const string _Key = "key";
public const string _Severity = "severity";

public const string _Section = "section";
public const string _Subsection = "subsection";
public const string _Comments = "comments";


public static ICollection<Guideline> ReadExisitingGuidelinesFile(string pathToExistingGuidelinesXml)
{

XDocument previousGuidelines = XDocument.Load(pathToExistingGuidelinesXml);

HashSet<Guideline> guidelines = new HashSet<Guideline>();

foreach (XElement guidelineFromXml in previousGuidelines.Root.DescendantNodes().OfType<XElement>())
{
Guideline guideline = new Guideline();
guideline.Severity = guidelineFromXml.Attribute(_Severity)?.Value;
guideline.Subsection = guidelineFromXml.Attribute(_Subsection)?.Value;
guideline.Section = guidelineFromXml.Attribute(_Section)?.Value;
guideline.Text = guidelineFromXml?.Value;
guideline.Key = guidelineFromXml.Attribute(_Key)?.Value;

guidelines.Add(guideline);
}
return guidelines;
}

}
}
16 changes: 16 additions & 0 deletions XMLtoMD/GuidelineXmlToMD/GuidelineXmlToMD.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="MarkdownOut\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="IntelliTect.Analyzers" Version="0.1.8" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions XMLtoMD/GuidelineXmlToMD/GuidelineXmlToMD.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30225.117
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GuidelineXmlToMD", "GuidelineXmlToMD.csproj", "{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9C7CC15-01DB-46FE-922A-6EB41CE1759B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A1FCF330-0100-466C-A566-FF92F0B59E10}
EndGlobalSection
EndGlobal
47 changes: 47 additions & 0 deletions XMLtoMD/GuidelineXmlToMD/MarkdownOut/MdExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace MarkdownOut {
Copy link
Member

@Keboo Keboo Oct 28, 2020

Choose a reason for hiding this comment

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

Braces should be put on their own line. The .editorconfig should be flagging these. If it isn't it could be because it is a level higher than the solution. If that is the case, don't have a separate solution for this project and just added to the main solution.


/// <summary>
/// A container for extension methods related to Markdown styling and formatting.
/// </summary>
public static class MdExtensions {

/// <summary>
/// Styles one or more substrings of the provided string using the specified
/// <see cref="MdStyle"/>.
/// </summary>
/// <param name="str">The string containing the substring to style.</param>
/// <param name="substring">The substring to style.</param>
/// <param name="style">The Markdown style to apply.</param>
/// <param name="firstOnly">
/// If true, only the first occurrence of the substring is styled; otherwise, all
/// occurrences of the substring are styled.
/// </param>
/// <returns>
/// The selectively styled string. If <paramref name="str"/> does not contain any
/// occurrences of <paramref name="substring"/>, it is returned unchanged.
/// </returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "<Pending>")]
Copy link
Member

Choose a reason for hiding this comment

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

This appears to duplicate the one in the global suppression file.

public static string StyleSubstring(this string str, string substring, MdStyle style,
bool firstOnly = false) {
if (string.IsNullOrEmpty(str))
{
throw new System.ArgumentException("cannot stylize empty string", nameof(str));
}

if (string.IsNullOrEmpty(substring))
{
throw new System.ArgumentException("cannot stylize empty string", nameof(str));
}

if (!firstOnly) {
return str?.Replace(substring, MdText.Style(substring, style), System.StringComparison.Ordinal);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return str?.Replace(substring, MdText.Style(substring, style), System.StringComparison.Ordinal);
return str.Replace(substring, MdText.Style(substring, style), System.StringComparison.Ordinal);

}
int pos = str.IndexOf(substring, System.StringComparison.Ordinal);
if (pos < 0) {
return str;
}
return str.Substring(0, pos) + MdText.Style(substring, style)
+ str.Substring(pos + substring.Length);
}
}
}
65 changes: 65 additions & 0 deletions XMLtoMD/GuidelineXmlToMD/MarkdownOut/MdFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
namespace MarkdownOut {

/// <summary>
/// Specifies a Markdown format to apply to a line or block of text. Formats are applied with a
/// prefix string and, unlike Markdown styles (see <see cref="MdStyle"/>), cannot be selectively
/// applied to substrings.
/// </summary>
public enum MdFormat {

/// <summary>
/// No text format.
/// </summary>
None,

/// <summary>
/// Heading 1 text format (inserts the string <c>"# "</c> in front of text).
/// </summary>
Heading1,

/// <summary>
/// Heading 2 text format (inserts the string <c>"## "</c> in front of text).
/// </summary>
Heading2,

/// <summary>
/// Heading 3 text format (inserts the string <c>"### "</c> in front of text).
/// </summary>
Heading3,

/// <summary>
/// Heading 4 text format (inserts the string <c>"#### "</c> in front of text).
/// </summary>
Heading4,

/// <summary>
/// Heading 5 text format (inserts the string <c>"##### "</c> in front of text).
/// </summary>
Heading5,

/// <summary>
/// Heading 6 text format (inserts the string <c>"###### "</c> in front of text).
/// </summary>
Heading6,

/// <summary>
/// Quote text format (inserts the string <c>"> "</c> in front of text).
/// </summary>
Quote,

/// <summary>
/// Unordered list item text format (inserts the string <c>"- "</c> in front of text).
/// </summary>
UnorderedListItem,

/// <summary>
/// Ordered list item text format (inserts the string <c>"1. "</c> in front of text).
/// </summary>
OrderedListItem,

/// <summary>
/// Creates a link to the heading that matches text to write (formats the text as [Foo](#foo)).
/// </summary>
InternalLink,
}
}
40 changes: 40 additions & 0 deletions XMLtoMD/GuidelineXmlToMD/MarkdownOut/MdStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
namespace MarkdownOut {

/// <summary>
/// Specifies a Markdown style to apply to a string of text. Styles are applied by wrapping text
/// with a special string on each side and can be selectively applied to substrings.
/// </summary>
public enum MdStyle {

/// <summary>
/// No text styling.
/// </summary>
None,

/// <summary>
/// Italic text styling (surrounds text with a single <c>*</c> character on each side).
/// </summary>
Italic,

/// <summary>
/// Bold text styling (surrounds text with two <c>*</c> characters on each side).
/// </summary>
Bold,

/// <summary>
/// Bold italic text styling (surrounds text with three <c>*</c> characters on each side).
/// </summary>
BoldItalic,

/// <summary>
/// Code text styling (surrounds text with a single <c>`</c> character on each side).
/// </summary>
Code,

/// <summary>
/// Strike-through text styling (surrounds text with two <c>~</c> characters on each side).
/// This style may not be supported by all Markdown parsers.
/// </summary>
StrikeThrough,
}
}
Loading