Skip to content

Commit

Permalink
More stylecop fixes (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikEJ authored Jan 21, 2025
1 parent 43c204f commit b5a9a7a
Show file tree
Hide file tree
Showing 73 changed files with 627 additions and 1,147 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

<ItemGroup>
<!-- Shared code analyzers used for all projects in the solution -->
<!--<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />-->
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
</ItemGroup>
</Project>
6 changes: 1 addition & 5 deletions SqlServer.Dac/Visitors/CreateLoginVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Microsoft.SqlServer.TransactSql.ScriptDom;

namespace SqlServer.Dac.Visitors
{
/// <summary>
///
/// </summary>
/// <seealso cref="Microsoft.SqlServer.TransactSql.ScriptDom.TSqlFragmentVisitor" />
public class CreateLoginVisitor : BaseVisitor, IVisitor<CreateLoginStatement>
{
public IList<CreateLoginStatement> Statements { get; } = new List<CreateLoginStatement>();
Expand Down
6 changes: 1 addition & 5 deletions SqlServer.Dac/Visitors/CreateRoleVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Microsoft.SqlServer.TransactSql.ScriptDom;

namespace SqlServer.Dac.Visitors
{
/// <summary>
///
/// </summary>
/// <seealso cref="Microsoft.SqlServer.TransactSql.ScriptDom.TSqlFragmentVisitor" />
public class CreateRoleVisitor : BaseVisitor, IVisitor<CreateRoleStatement>
{
public IList<CreateRoleStatement> Statements { get; } = new List<CreateRoleStatement>();
Expand Down
6 changes: 1 addition & 5 deletions SqlServer.Dac/Visitors/CreateUserVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Microsoft.SqlServer.TransactSql.ScriptDom;

namespace SqlServer.Dac.Visitors
{
/// <summary>
///
/// </summary>
/// <seealso cref="Microsoft.SqlServer.TransactSql.ScriptDom.TSqlFragmentVisitor" />
public class CreateUserVisitor : BaseVisitor, IVisitor<CreateUserStatement>
{
public IList<CreateUserStatement> Statements { get; } = new List<CreateUserStatement>();
Expand Down
12 changes: 6 additions & 6 deletions SqlServer.Dac/Visitors/FunctionCallVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Microsoft.SqlServer.TransactSql.ScriptDom;

namespace SqlServer.Dac.Visitors
{
public class FunctionCallVisitor : BaseVisitor, IVisitor<FunctionCall>
{
private readonly IList<string> _functionNames;
private readonly IList<string> functionNames;
public FunctionCallVisitor()
{
_functionNames = new List<string>();
functionNames = new List<string>();
}

public FunctionCallVisitor(params string[] functionNames)
{
_functionNames = functionNames.ToList();
this.functionNames = functionNames.ToList();
}

public IList<FunctionCall> Statements { get; } = new List<FunctionCall>();
Expand All @@ -25,11 +25,11 @@ public int Count

public override void ExplicitVisit(FunctionCall node)
{
if (!_functionNames.Any())
if (!functionNames.Any())
{
Statements.Add(node);
}
else if (_functionNames.Any(f => Comparer.Equals(f, node.FunctionName.Value)))
else if (functionNames.Any(f => Comparer.Equals(f, node.FunctionName.Value)))
{
Statements.Add(node);
}
Expand Down
8 changes: 4 additions & 4 deletions SqlServer.Dac/Visitors/TypesVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System;
using System.Collections.Generic;
using Microsoft.SqlServer.TransactSql.ScriptDom;

namespace SqlServer.Dac.Visitors
{
public class TypesVisitor : BaseVisitor, IVisitor<TSqlFragment>
{
private readonly List<Type> _types = new List<Type>();
private readonly List<Type> types = new List<Type>();
public IList<TSqlFragment> Statements { get; } = new List<TSqlFragment>();
public int Count
{
Expand All @@ -20,12 +20,12 @@ public TypesVisitor(params Type[] typesToLookFor)
throw new ArgumentNullException(nameof(typesToLookFor));
}

_types = new List<Type>(typesToLookFor);
types = new List<Type>(typesToLookFor);
}

public override void Visit(TSqlFragment fragment)
{
if (_types.Contains(fragment.GetType()))
if (types.Contains(fragment.GetType()))
{
Statements.Add(fragment);
}
Expand Down
4 changes: 1 addition & 3 deletions SqlServer.Rules.Report/IssueTypeComparer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace SqlServer.Rules.Report;


public class IssueTypeComparer : IEqualityComparer<IssueType>
{
public bool Equals(IssueType x, IssueType y)
Expand Down
30 changes: 30 additions & 0 deletions SqlServer.Rules.Test/Docs/DocsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using LoxSmoke.DocXml;
using Microsoft.SqlServer.Dac.CodeAnalysis;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SqlServer.Rules.Design;
using TSQLSmellSCA;

namespace SqlServer.Rules.Tests.Docs;

public static class DocsExtensions
{
public static string ToSentence(this string input)
{
var parts = Regex.Split(input, @"([A-Z]?[a-z]+)").Where(str => !string.IsNullOrEmpty(str));
return string.Join(' ', parts);
}

public static string ToId(this string input)
{
return new string(input.Split('.').Last());
}
}
15 changes: 0 additions & 15 deletions SqlServer.Rules.Test/Docs/DocsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using LoxSmoke.DocXml;
using Microsoft.SqlServer.Dac.CodeAnalysis;
Expand Down Expand Up @@ -341,17 +340,3 @@ private static Dictionary<string, List<string>> CollectRuleScripts(string rulesS
return ruleScripts;
}
}

public static class DocsExtensions
{
public static string ToSentence(this string input)
{
var parts = Regex.Split(input, @"([A-Z]?[a-z]+)").Where(str => !string.IsNullOrEmpty(str));
return string.Join(' ', parts);
}

public static string ToId(this string input)
{
return new string(input.Split('.').Last());
}
}
34 changes: 0 additions & 34 deletions SqlServer.Rules.Test/Utils/ArgumentValidation.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,4 @@
//------------------------------------------------------------------------------
// <copyright company="Microsoft">
//
// The MIT License (MIT)
//
// Copyright (c) 2015 Microsoft
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// </copyright>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Data.SqlClient;

namespace SqlServer.Rules.Tests.Utils;

Expand Down
27 changes: 0 additions & 27 deletions SqlServer.Rules.Test/Utils/CommonConstants.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
//------------------------------------------------------------------------------
// <copyright company="Microsoft">
//
// The MIT License (MIT)
//
// Copyright (c) 2015 Microsoft
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// </copyright>
//------------------------------------------------------------------------------

namespace SqlServer.Rules.Tests.Utils;

internal sealed class CommonConstants
Expand Down
6 changes: 2 additions & 4 deletions SqlServer.Rules.Test/Utils/DisposableList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ private void Dispose(bool isDisposing)
}
}

/// <summary>
/// Add an item to the list.
/// </summary>
public T Add<T>(T item) where T : IDisposable
public T Add<T>(T item)
where T : IDisposable
{
base.Add(item);

Expand Down
27 changes: 0 additions & 27 deletions SqlServer.Rules.Test/Utils/InstanceInfo.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
//------------------------------------------------------------------------------
// <copyright company="Microsoft">
//
// The MIT License (MIT)
//
// Copyright (c) 2015 Microsoft
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// </copyright>
//------------------------------------------------------------------------------

using System;
using System.Globalization;
using Microsoft.Data.SqlClient;
Expand Down
4 changes: 2 additions & 2 deletions SqlServer.Rules.Test/Utils/RuleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ private TSqlModel CreateScriptedModel()
// LoadAsScriptBackedModel = true,
// ModelStorageType = Microsoft.SqlServer.Dac.DacSchemaModelStorageType.Memory
// });

return model;
}

Expand Down Expand Up @@ -251,7 +250,8 @@ private CodeAnalysisService CreateCodeAnalysisService(string ruleIdToRun)

Assert.IsTrue(
service.GetRules().Any(rule => rule.RuleId.Equals(ruleIdToRun, StringComparison.OrdinalIgnoreCase)),
"Expected rule '{0}' not found by the service", ruleIdToRun);
"Expected rule '{0}' not found by the service",
ruleIdToRun);
return service;
}

Expand Down
Loading

0 comments on commit b5a9a7a

Please sign in to comment.