Skip to content

Commit eae3807

Browse files
committed
Remove submodule
1 parent b30afe2 commit eae3807

36 files changed

+2611
-1
lines changed

Flow.Launcher.Localization

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: build
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [ "main" ]
7+
pull_request:
8+
9+
jobs:
10+
11+
build:
12+
13+
runs-on: windows-latest
14+
15+
env:
16+
Dotnet_Version: 8.0.x
17+
Project_Path: Flow.Launcher.Localization\Flow.Launcher.Localization.csproj
18+
19+
steps:
20+
21+
# Checkout codes
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
# Install the .NET Core workload
26+
- name: Setup .NET
27+
uses: actions/setup-dotnet@v4
28+
with:
29+
dotnet-version: ${{ env.Dotnet_Version }}
30+
31+
# Restore dependencies
32+
- name: Restore dependencies
33+
run: dotnet restore ${{ env.Project_Path }}
34+
35+
# Build the project
36+
- name: Build
37+
run: dotnet build ${{ env.Project_Path }} --configuration Release --no-restore
38+
39+
# Execute all unit tests in the solution
40+
- name: Execute unit tests
41+
if: github.event_name == 'push' && github.ref != 'refs/heads/main'
42+
run: dotnet test --configuration Release --no-build
43+
44+
# Pack the NuGet package
45+
- name: Create NuGet package
46+
run: dotnet pack ${{ env.Project_Path }} --configuration Release --no-build --output nupkgs
47+
48+
# Upload the NuGet package
49+
- name: Upload NuGet package
50+
uses: actions/upload-artifact@v4
51+
with:
52+
name: Full nupkg
53+
path: nupkgs/Flow.Launcher.Localization.*.nupkg
54+
compression-level: 0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Assign PR to creator
2+
3+
on:
4+
pull_request_target:
5+
types: [opened]
6+
7+
permissions:
8+
pull-requests: write
9+
10+
jobs:
11+
automation:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Assign PR to creator
15+
uses: toshimaru/[email protected]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: publish
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- '*'
8+
9+
jobs:
10+
11+
publish:
12+
13+
runs-on: windows-latest
14+
15+
env:
16+
Dotnet_Version: 8.0.x
17+
Project_Path: Flow.Launcher.Localization\Flow.Launcher.Localization.csproj
18+
19+
steps:
20+
21+
# Checkout codes
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
# Install the .NET Core workload
26+
- name: Setup .NET
27+
uses: actions/setup-dotnet@v4
28+
with:
29+
dotnet-version: ${{ env.Dotnet_Version }}
30+
31+
# Restore dependencies
32+
- name: Restore dependencies
33+
run: dotnet restore ${{ env.Project_Path }}
34+
35+
# Build the project
36+
- name: Build
37+
run: dotnet build ${{ env.Project_Path }} --configuration Release --no-restore
38+
39+
# Pack the NuGet package
40+
- name: Create NuGet package
41+
run: dotnet pack ${{ env.Project_Path }} --configuration Release --no-build --output nupkgs
42+
43+
# Publish to NuGet.org
44+
- name: Push to NuGet
45+
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
46+
run: nuget push nupkgs\*.nupkg -source 'https://api.nuget.org/v3/index.json' -apikey ${{ secrets.NUGET_API_KEY }}
47+
48+
# Get package version
49+
- name: Get Package Version
50+
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
51+
run: |
52+
$version = [system.diagnostics.fileversioninfo]::getversioninfo("Flow.Launcher.Localization\bin\Release\netstandard2.0\Flow.Launcher.Localization.dll").fileversion
53+
echo "release_version=$version" | out-file -filepath $env:github_env -encoding utf-8 -append
54+
55+
# Publish to GitHub releases
56+
- name: Publish GitHub releases
57+
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
58+
uses: softprops/action-gh-release@v1
59+
with:
60+
files: "nupkgs/*.nupkg"
61+
tag_name: "v${{ env.release_version }}"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.idea/
2+
.vs/
3+
bin/
4+
obj/
5+
/packages/
6+
riderModule.iml
7+
/_ReSharper.Caches/
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Flow.Launcher.Localization.Shared;
2+
using Microsoft.CodeAnalysis;
3+
4+
namespace Flow.Launcher.Localization.Analyzers
5+
{
6+
public static class AnalyzerDiagnostics
7+
{
8+
public static readonly DiagnosticDescriptor OldLocalizationApiUsed = new DiagnosticDescriptor(
9+
"FLAN0001",
10+
"Old localization API used",
11+
$"Use `{Constants.ClassName}.{{0}}({{1}})` instead",
12+
"Localization",
13+
DiagnosticSeverity.Warning,
14+
isEnabledByDefault: true
15+
);
16+
17+
public static readonly DiagnosticDescriptor ContextIsAField = new DiagnosticDescriptor(
18+
"FLAN0002",
19+
"Plugin context is a field",
20+
"Plugin context must be at least internal static property",
21+
"Localization",
22+
DiagnosticSeverity.Error,
23+
isEnabledByDefault: true
24+
);
25+
26+
public static readonly DiagnosticDescriptor ContextIsNotStatic = new DiagnosticDescriptor(
27+
"FLAN0003",
28+
"Plugin context is not static",
29+
"Plugin context must be at least internal static property",
30+
"Localization",
31+
DiagnosticSeverity.Error,
32+
isEnabledByDefault: true
33+
);
34+
35+
public static readonly DiagnosticDescriptor ContextAccessIsTooRestrictive = new DiagnosticDescriptor(
36+
"FLAN0004",
37+
"Plugin context property access modifier is too restrictive",
38+
"Plugin context property must be at least internal static property",
39+
"Localization",
40+
DiagnosticSeverity.Error,
41+
isEnabledByDefault: true
42+
);
43+
44+
public static readonly DiagnosticDescriptor ContextIsNotDeclared = new DiagnosticDescriptor(
45+
"FLAN0005",
46+
"Plugin context is not declared",
47+
$"Plugin context must be at least internal static property of type `{Constants.PluginContextTypeName}`",
48+
"Localization",
49+
DiagnosticSeverity.Error,
50+
isEnabledByDefault: true
51+
);
52+
}
53+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
; Shipped analyzer releases
2+
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
; Unshipped analyzer release
2+
; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md
3+
### New Rules
4+
5+
Rule ID | Category | Severity | Notes
6+
--------|----------|----------|-------
7+
FLAN0001 | Localization | Warning | FLAN0001_OldLocalizationApiUsed
8+
FLAN0002 | Localization | Error | FLAN0002_ContextIsAField
9+
FLAN0003 | Localization | Error | FLAN0003_ContextIsNotStatic
10+
FLAN0004 | Localization | Error | FLAN0004_ContextAccessIsTooRestrictive
11+
FLAN0005 | Localization | Error | FLAN0005_ContextIsNotDeclared
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
6+
<RootNamespace>Flow.Launcher.Localization.Analyzers</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
11+
<PrivateAssets>all</PrivateAssets>
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
</PackageReference>
14+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
15+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.13.0" />
16+
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\Flow.Launcher.Localization.Shared\Flow.Launcher.Localization.Shared.csproj" />
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using System.Collections.Immutable;
2+
using System.Linq;
3+
using Flow.Launcher.Localization.Shared;
4+
using Microsoft.CodeAnalysis;
5+
using Microsoft.CodeAnalysis.CSharp;
6+
using Microsoft.CodeAnalysis.CSharp.Syntax;
7+
using Microsoft.CodeAnalysis.Diagnostics;
8+
9+
namespace Flow.Launcher.Localization.Analyzers.Localize
10+
{
11+
[DiagnosticAnalyzer(LanguageNames.CSharp)]
12+
public class ContextAvailabilityAnalyzer : DiagnosticAnalyzer
13+
{
14+
#region DiagnosticAnalyzer
15+
16+
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(
17+
AnalyzerDiagnostics.ContextIsAField,
18+
AnalyzerDiagnostics.ContextIsNotStatic,
19+
AnalyzerDiagnostics.ContextAccessIsTooRestrictive,
20+
AnalyzerDiagnostics.ContextIsNotDeclared
21+
);
22+
23+
public override void Initialize(AnalysisContext context)
24+
{
25+
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
26+
context.EnableConcurrentExecution();
27+
context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.ClassDeclaration);
28+
}
29+
30+
#endregion
31+
32+
#region Analyze Methods
33+
34+
private static void AnalyzeNode(SyntaxNodeAnalysisContext context)
35+
{
36+
var configOptions = context.Options.AnalyzerConfigOptionsProvider;
37+
var useDI = configOptions.GetFLLUseDependencyInjection();
38+
if (useDI)
39+
{
40+
// If we use dependency injection, we don't need to check for this context property
41+
return;
42+
}
43+
44+
var classDeclaration = (ClassDeclarationSyntax)context.Node;
45+
var semanticModel = context.SemanticModel;
46+
var pluginClassInfo = Helper.GetPluginClassInfo(classDeclaration, semanticModel, context.CancellationToken);
47+
if (pluginClassInfo == null)
48+
{
49+
// Cannot find class that implements IPluginI18n
50+
return;
51+
}
52+
53+
// Context property is found, check if it's a valid property
54+
if (pluginClassInfo.PropertyName != null)
55+
{
56+
if (!pluginClassInfo.IsStatic)
57+
{
58+
context.ReportDiagnostic(Diagnostic.Create(
59+
AnalyzerDiagnostics.ContextIsNotStatic,
60+
pluginClassInfo.CodeFixLocation
61+
));
62+
return;
63+
}
64+
65+
if (pluginClassInfo.IsPrivate || pluginClassInfo.IsProtected)
66+
{
67+
context.ReportDiagnostic(Diagnostic.Create(
68+
AnalyzerDiagnostics.ContextAccessIsTooRestrictive,
69+
pluginClassInfo.CodeFixLocation
70+
));
71+
return;
72+
}
73+
74+
// If the context property is valid, we don't need to check for anything else
75+
return;
76+
}
77+
78+
// Context property is not found, check if it's declared as a field
79+
var fieldDeclaration = classDeclaration.Members
80+
.OfType<FieldDeclarationSyntax>()
81+
.SelectMany(f => f.Declaration.Variables)
82+
.Select(f => semanticModel.GetDeclaredSymbol(f))
83+
.FirstOrDefault(f => f is IFieldSymbol fs && fs.Type.Name is Constants.PluginContextTypeName);
84+
var parentSyntax = fieldDeclaration
85+
?.DeclaringSyntaxReferences[0]
86+
.GetSyntax()
87+
.FirstAncestorOrSelf<FieldDeclarationSyntax>();
88+
if (parentSyntax != null)
89+
{
90+
context.ReportDiagnostic(Diagnostic.Create(
91+
AnalyzerDiagnostics.ContextIsAField,
92+
parentSyntax.GetLocation()
93+
));
94+
return;
95+
}
96+
97+
// Context property is not found, report an error
98+
context.ReportDiagnostic(Diagnostic.Create(
99+
AnalyzerDiagnostics.ContextIsNotDeclared,
100+
classDeclaration.Identifier.GetLocation()
101+
));
102+
}
103+
104+
#endregion
105+
}
106+
}

0 commit comments

Comments
 (0)