Skip to content
Closed
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
11 changes: 0 additions & 11 deletions Flow.Launcher.Localization.Analyzers/AnalyzerReleases.Unshipped.md

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions Flow.Launcher.Localization.slnx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<Solution>
<Project Path="Flow.Launcher.Localization.Analyzers/Flow.Launcher.Localization.Analyzers.csproj" />
<Project Path="Flow.Launcher.Localization.SourceGenerators/Flow.Launcher.Localization.SourceGenerators.csproj" />
<Project Path="Flow.Launcher.Localization/Flow.Launcher.Localization.csproj" />
</Solution>
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
; Shipped analyzer releases
; Unshipped analyzer release
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md

### New Rules

Rule ID | Category | Severity | Notes
--------|----------|----------|-------
FLAN0001 | Localization | Warning | FLAN0001_OldLocalizationApiUsed
FLAN0002 | Localization | Error | FLAN0002_ContextIsAField
FLAN0003 | Localization | Error | FLAN0003_ContextIsNotStatic
FLAN0004 | Localization | Error | FLAN0004_ContextAccessIsTooRestrictive
FLAN0005 | Localization | Error | FLAN0005_ContextIsNotDeclared
FLSG0001 | Localization | Warning | FLSG0001_CouldNotFindResourceDictionaries
FLSG0002 | Localization | Warning | FLSG0002_CouldNotFindPluginEntryClass
FLSG0003 | Localization | Warning | FLSG0003_CouldNotFindContextProperty
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Immutable;
using System.Linq;
using Flow.Launcher.Localization.Diagnostics;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Flow.Launcher.Localization.Analyzers.Localize
namespace Flow.Launcher.Localization.Analyzers
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class ContextAvailabilityAnalyzer : DiagnosticAnalyzer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Composition;
using System.Linq;
using System.Threading.Tasks;
using Flow.Launcher.Localization.Diagnostics;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
Expand All @@ -11,7 +12,7 @@
using Microsoft.CodeAnalysis.Simplification;
using Microsoft.CodeAnalysis.Text;

namespace Flow.Launcher.Localization.Analyzers.Localize
namespace Flow.Launcher.Localization.Analyzers
{
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(ContextAvailabilityAnalyzerCodeFixProvider)), Shared]
public class ContextAvailabilityAnalyzerCodeFixProvider : CodeFixProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Immutable;
using System.Linq;
using Flow.Launcher.Localization.Diagnostics;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;

namespace Flow.Launcher.Localization.Analyzers.Localize
namespace Flow.Launcher.Localization.Analyzers
{
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class OldGetTranslateAnalyzer : DiagnosticAnalyzer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
using System.Composition;
using System.Linq;
using System.Threading.Tasks;
using Flow.Launcher.Localization.Diagnostics;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

namespace Flow.Launcher.Localization.Analyzers.Localize
namespace Flow.Launcher.Localization.Analyzers
{
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(OldGetTranslateAnalyzerCodeFixProvider)), Shared]
public class OldGetTranslateAnalyzerCodeFixProvider : CodeFixProvider
Expand Down Expand Up @@ -60,7 +61,6 @@ private static Document FixOldTranslation(CodeFixContext context, SyntaxNode roo
return context.Document;
}


private static string GetTranslationKey(ExpressionSyntax syntax)
{
if (
Expand All @@ -72,8 +72,8 @@ literalExpressionSyntax.Token.Value is string translationKey
}

private static Document FixOldTranslationWithoutStringFormat(
CodeFixContext context, string translationKey, SyntaxNode root, InvocationExpressionSyntax invocationExpr
) {
CodeFixContext context, string translationKey, SyntaxNode root, InvocationExpressionSyntax invocationExpr)
{
var newInvocationExpr = SyntaxFactory.ParseExpression(
$"Localize.{translationKey}()"
);
Expand Down Expand Up @@ -101,14 +101,13 @@ private static Document FixOldTranslationWithStringFormat(
SeparatedSyntaxList<ArgumentSyntax> argumentList,
string translationKey2,
SyntaxNode root,
InvocationExpressionSyntax invocationExpr
) {
InvocationExpressionSyntax invocationExpr)
{
var newArguments = string.Join(", ", argumentList.Skip(1).Select(a => a.Expression));
var newInnerInvocationExpr = SyntaxFactory.ParseExpression($"Localize.{translationKey2}({newArguments})");

var newRoot = root.ReplaceNode(invocationExpr, newInnerInvocationExpr);
return context.Document.WithSyntaxRoot(newRoot);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.CodeAnalysis;

namespace Flow.Launcher.Localization.Analyzers
namespace Flow.Launcher.Localization.Diagnostics
{
public static class AnalyzerDiagnostics
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.CodeAnalysis;

namespace Flow.Launcher.Localization.SourceGenerators
namespace Flow.Launcher.Localization.Diagnostics
{
public static class SourceGeneratorDiagnostics
{
Expand Down
10 changes: 7 additions & 3 deletions Flow.Launcher.Localization/Flow.Launcher.Localization.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.0</Version>
<Version>0.0.1</Version>
<TargetFramework>netstandard2.0</TargetFramework>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<RootNamespace>Flow.Launcher.Localization</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Flow.Launcher.Localization.Analyzers\Flow.Launcher.Localization.Analyzers.csproj" />
<ProjectReference Include="..\Flow.Launcher.Localization.SourceGenerators\Flow.Launcher.Localization.SourceGenerators.csproj" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.9.2"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using Flow.Launcher.Localization.Diagnostics;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;

namespace Flow.Launcher.Localization.SourceGenerators.Localize
namespace Flow.Launcher.Localization.Generators
{
[Generator]
public partial class LocalizeSourceGenerator : ISourceGenerator
Expand Down