Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"csharpier": {
"version": "1.0.1",
"commands": [
"csharpier"
]
}
}
}
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "6.0.100",
"version": "8.0.100",
"rollForward": "latestMinor"
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PublishToken="_PLACEHOLDER_"
# EAP: 2020.3-EAP2-SNAPSHOT
# Nightly: 2020.3-SNAPSHOT
ProductVersion=2025.1
PluginVersion=2025.1.0
PluginVersion=2025.1.1

# Kotlin 1.4 will bundle the stdlib dependency by default, causing problems with the version bundled with the IDE
# https://blog.jetbrains.com/kotlin/2020/07/kotlin-1-4-rc-released/#stdlib-default
Expand Down
7 changes: 0 additions & 7 deletions src/dotnet/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
<Project>

<PropertyGroup>
<LangVersion>Latest</LangVersion>
<NoPackageAnalysis>true</NoPackageAnalysis>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>

<BaseIntermediateOutputPath>obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
<DefaultItemExcludes>$(DefaultItemExcludes);obj\**</DefaultItemExcludes>
<OutputPath>bin\$(MSBuildProjectName)\$(Configuration)\</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<DefineConstants>TRACE;DEBUG;JET_MODE_ASSERT</DefineConstants>
</PropertyGroup>

<Import Project="Plugin.props" />

<PropertyGroup>
<WaveVersion>$(SdkVersion.Substring(2,2))$(SdkVersion.Substring(5,1)).0.0</WaveVersion>
</PropertyGroup>

<ItemDefinitionGroup>
<EmbeddedResource>
<Generator>JetResourceGenerator</Generator>
</EmbeddedResource>
</ItemDefinitionGroup>

</Project>
2 changes: 1 addition & 1 deletion src/dotnet/MO.CleanCode/CleanCodeHighlightingGroupIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public static class CleanCodeHighlightingGroupIds
{
public const string CleanCode = "CleanCode";
}
}
}
5 changes: 3 additions & 2 deletions src/dotnet/MO.CleanCode/Extension/ExpressionExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace CleanCode.Extension
{
public static class ExpressionExt
{
public static int GetExpressionCount<T>(this IExpression expression) where T : ITreeNode => expression.GetChildrenRecursive<T>().Count();
public static int GetExpressionCount<T>(this IExpression expression)
where T : ITreeNode => expression.GetChildrenRecursive<T>().Count();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ namespace CleanCode.Features.ChainedReferences;

public abstract class ChainedReferencesCheck<T> : ElementProblemAnalyzer<T>
{
protected static void HighlightMethodChainsThatAreTooLong(ITreeNode statement, IHighlightingConsumer consumer, int threshold)
protected static void HighlightMethodChainsThatAreTooLong(
ITreeNode statement,
IHighlightingConsumer consumer,
int threshold
)
{
var children = statement.Children();

Expand All @@ -25,7 +29,11 @@ protected static void HighlightMethodChainsThatAreTooLong(ITreeNode statement, I
}
}

private static void HighlightReferenceExpressionIfNeeded(IReferenceExpression referenceExpression, IHighlightingConsumer consumer, int threshold)
private static void HighlightReferenceExpressionIfNeeded(
IReferenceExpression referenceExpression,
IHighlightingConsumer consumer,
int threshold
)
{
var types = new HashSet<IType>();

Expand All @@ -34,15 +42,19 @@ private static void HighlightReferenceExpressionIfNeeded(IReferenceExpression re

while (nextReferenceExpression != null)
{
var childReturnType = ExtensionMethodsCsharp.TryGetClosedReturnTypeFrom(nextReferenceExpression);
var childReturnType = ExtensionMethodsCsharp.TryGetClosedReturnTypeFrom(
nextReferenceExpression
);

if (childReturnType != null)
{
types.Add(childReturnType);
chainLength++;
}

nextReferenceExpression = ExtensionMethodsVb.TryGetFirstReferenceExpression(nextReferenceExpression);
nextReferenceExpression = ExtensionMethodsVb.TryGetFirstReferenceExpression(
nextReferenceExpression
);
}

var isFluentChain = types.Count == 1;
Expand All @@ -52,11 +64,20 @@ private static void HighlightReferenceExpressionIfNeeded(IReferenceExpression re
}
}

private static void AddHighlighting(IReferenceExpression reference, IHighlightingConsumer consumer, int threshold, int currentValue)
private static void AddHighlighting(
IReferenceExpression reference,
IHighlightingConsumer consumer,
int threshold,
int currentValue
)
{
var nameIdentifier = reference.NameIdentifier;
var documentRange = nameIdentifier.GetDocumentRange();
var highlighting = new MaximumChainedReferencesHighlighting(documentRange, threshold, currentValue);
var highlighting = new MaximumChainedReferencesHighlighting(
documentRange,
threshold,
currentValue
);
consumer.AddHighlighting(highlighting);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@

namespace CleanCode.Features.ChainedReferences
{
[ElementProblemAnalyzer(typeof(ICSharpStatement), HighlightingTypes = new[]
{
typeof(MaximumChainedReferencesHighlighting)
})]
[ElementProblemAnalyzer(
typeof(ICSharpStatement),
HighlightingTypes = new[] { typeof(MaximumChainedReferencesHighlighting) }
)]
public class ChainedReferencesCheckCs : ChainedReferencesCheck<ICSharpStatement>
{
protected override void Run(ICSharpStatement element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
protected override void Run(
ICSharpStatement element,
ElementProblemAnalyzerData data,
IHighlightingConsumer consumer
)
{
if (element.CanBeEmbedded) return;

var threshold = data.SettingsStore.GetValue((CleanCodeSettings s) => s.MaximumChainedReferences);
if (element.CanBeEmbedded)
return;

var threshold = data.SettingsStore.GetValue(
(CleanCodeSettings s) => s.MaximumChainedReferences
);
HighlightMethodChainsThatAreTooLong(element, consumer, threshold);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@

namespace CleanCode.Features.ChainedReferences
{
[ElementProblemAnalyzer(typeof(IVBStatement), HighlightingTypes = new[]
{
typeof(MaximumChainedReferencesHighlighting)
})]
[ElementProblemAnalyzer(
typeof(IVBStatement),
HighlightingTypes = new[] { typeof(MaximumChainedReferencesHighlighting) }
)]
public class ChainedReferencesCheckVb : ChainedReferencesCheck<IVBStatement>
{
protected override void Run(IVBStatement element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
protected override void Run(
IVBStatement element,
ElementProblemAnalyzerData data,
IHighlightingConsumer consumer
)
{
var threshold = data.SettingsStore.GetValue((CleanCodeSettings s) => s.MaximumChainedReferences);
var threshold = data.SettingsStore.GetValue(
(CleanCodeSettings s) => s.MaximumChainedReferences
);
HighlightMethodChainsThatAreTooLong(element, consumer, threshold);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,33 @@

namespace CleanCode.Features.ChainedReferences
{
[RegisterConfigurableSeverity(SeverityID,
[RegisterConfigurableSeverity(
SeverityID,
null,
CleanCodeHighlightingGroupIds.CleanCode,
"Too many chained references",
"Too many chained references can break the Law of Demeter.",
Severity.WARNING)]
Severity.WARNING
)]
[ConfigurableSeverityHighlighting(SeverityID, CSharpLanguage.Name + "," + VBLanguage.Name)]
public class MaximumChainedReferencesHighlighting : IHighlighting
{
private const string SeverityID = "TooManyChainedReferences";

private readonly DocumentRange _documentRange;

public MaximumChainedReferencesHighlighting(DocumentRange documentRange, int threshold, int currentValue)
public MaximumChainedReferencesHighlighting(
DocumentRange documentRange,
int threshold,
int currentValue
)
{
ToolTip = string.Format(CultureInfo.CurrentCulture,
ToolTip = string.Format(
CultureInfo.CurrentCulture,
Warnings.ChainedReferences,
currentValue,
threshold);
threshold
);

_documentRange = documentRange;
}
Expand All @@ -38,4 +46,4 @@ public MaximumChainedReferencesHighlighting(DocumentRange documentRange, int thr

public bool IsValid() => !string.IsNullOrWhiteSpace(ToolTip);
}
}
}
19 changes: 12 additions & 7 deletions src/dotnet/MO.CleanCode/Features/ClassTooBig/ClassTooBigCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ namespace CleanCode.Features.ClassTooBig;

public abstract class ClassTooBigCheck<T> : ElementProblemAnalyzer<T>
{
protected static void CheckIfClassIsTooBig<TMethodDeclaration>(ITreeNode declaration,
protected static void CheckIfClassIsTooBig<TMethodDeclaration>(
ITreeNode declaration,
ITreeNode element,
ElementProblemAnalyzerData data,
IHighlightingConsumer consumer)
ElementProblemAnalyzerData data,
IHighlightingConsumer consumer
)
where TMethodDeclaration : ITreeNode
{
var maxLength = data.SettingsStore.GetValue((CleanCodeSettings s) => s.MaximumMethodsInClass);
var maxLength = data.SettingsStore.GetValue(
(CleanCodeSettings s) => s.MaximumMethodsInClass
);
var statementCount = element.CountChildren<TMethodDeclaration>();

if (statementCount <= maxLength) return;

if (statementCount <= maxLength)
return;

var documentRange = declaration.GetDocumentRange();
var highlighting = new ClassTooBigHighlighting(documentRange, maxLength, statementCount);
consumer.AddHighlighting(highlighting);
}
}
}
23 changes: 16 additions & 7 deletions src/dotnet/MO.CleanCode/Features/ClassTooBig/ClassTooBigCheckCs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@

namespace CleanCode.Features.ClassTooBig
{
[ElementProblemAnalyzer(typeof(IClassDeclaration), HighlightingTypes = new[]
{
typeof(ClassTooBigHighlighting)
})]
[ElementProblemAnalyzer(
typeof(IClassDeclaration),
HighlightingTypes = new[] { typeof(ClassTooBigHighlighting) }
)]
public class ClassTooBigCheckCs : ClassTooBigCheck<IClassDeclaration>
{
protected override void Run(IClassDeclaration element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
protected override void Run(
IClassDeclaration element,
ElementProblemAnalyzerData data,
IHighlightingConsumer consumer
)
{
CheckIfClassIsTooBig<IMethodDeclaration>(element.NameIdentifier, element, data, consumer);
CheckIfClassIsTooBig<IMethodDeclaration>(
element.NameIdentifier,
element,
data,
consumer
);
}
}
}
}
16 changes: 10 additions & 6 deletions src/dotnet/MO.CleanCode/Features/ClassTooBig/ClassTooBigCheckVb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@

namespace CleanCode.Features.ClassTooBig
{
[ElementProblemAnalyzer(typeof(IClassDeclaration), HighlightingTypes = new[]
{
typeof(ClassTooBigHighlighting)
})]
[ElementProblemAnalyzer(
typeof(IClassDeclaration),
HighlightingTypes = new[] { typeof(ClassTooBigHighlighting) }
)]
public class ClassTooBigCheckVb : ClassTooBigCheck<IClassDeclaration>
{
protected override void Run(IClassDeclaration element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
protected override void Run(
IClassDeclaration element,
ElementProblemAnalyzerData data,
IHighlightingConsumer consumer
)
{
CheckIfClassIsTooBig<IMethodDeclaration>(element.Name, element, data, consumer);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

namespace CleanCode.Features.ClassTooBig
{
[RegisterConfigurableSeverity(SeverityID,
[RegisterConfigurableSeverity(
SeverityID,
null,
CleanCodeHighlightingGroupIds.CleanCode,
"Class too big",
"This class contains too many methods",
Severity.SUGGESTION)]
Severity.SUGGESTION
)]
[ConfigurableSeverityHighlighting(SeverityID, CSharpLanguage.Name + "," + VBLanguage.Name)]
public class ClassTooBigHighlighting : IHighlighting
{
Expand All @@ -22,7 +24,12 @@ public class ClassTooBigHighlighting : IHighlighting

public ClassTooBigHighlighting(DocumentRange documentRange, int threshold, int currentValue)
{
ToolTip = string.Format(CultureInfo.CurrentCulture, Warnings.ClassTooBig, currentValue, threshold);
ToolTip = string.Format(
CultureInfo.CurrentCulture,
Warnings.ClassTooBig,
currentValue,
threshold
);
_documentRange = documentRange;
}

Expand All @@ -34,4 +41,4 @@ public ClassTooBigHighlighting(DocumentRange documentRange, int threshold, int c

public bool IsValid() => !string.IsNullOrWhiteSpace(ToolTip);
}
}
}
Loading