Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove analyzers from IDE extensions #1303

Draft
wants to merge 46 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8310b69
Remove analyzers from IDE extensions
josefpihrt Nov 30, 2023
b2df85d
update
josefpihrt Nov 30, 2023
5182c17
update
josefpihrt Nov 30, 2023
565159e
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 1, 2023
ec81df6
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 2, 2023
b71c95e
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 3, 2023
22907e0
update
josefpihrt Dec 3, 2023
72ffd70
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 3, 2023
5e39a7a
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 3, 2023
92cb501
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 5, 2023
657f38e
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 5, 2023
3e9c2ea
update
josefpihrt Dec 5, 2023
76953af
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 5, 2023
ff95ca6
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 5, 2023
011f5e6
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 7, 2023
44b5d36
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 7, 2023
d454134
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 9, 2023
6686460
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 12, 2023
3c35a75
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 20, 2023
4bb7b01
update
josefpihrt Dec 20, 2023
1b04d63
update
josefpihrt Dec 20, 2023
e8cfebd
update
josefpihrt Dec 20, 2023
9bcc96c
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Dec 31, 2023
f375ebd
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Jan 2, 2024
1a93e7d
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Jan 9, 2024
6bdd2a8
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Jan 9, 2024
ecb6155
update
josefpihrt Jan 9, 2024
ca3571a
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Jan 9, 2024
ee0653f
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Jan 14, 2024
c630731
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Jan 18, 2024
5a10ba2
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Jan 21, 2024
ae73243
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Jan 24, 2024
e35ae59
merge main
josefpihrt Jan 24, 2024
6149835
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Jan 24, 2024
75daaf0
merge main
josefpihrt Jan 26, 2024
8d4d756
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Jan 29, 2024
e219ff9
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Jan 29, 2024
194ba3b
update
josefpihrt Feb 4, 2024
6532f8d
update
josefpihrt Feb 4, 2024
a2e1ece
update
josefpihrt Feb 5, 2024
5c0a3fd
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Feb 6, 2024
1fb751d
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Feb 7, 2024
a93b3ab
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Feb 17, 2024
db8ecc1
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Feb 17, 2024
457b914
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Feb 20, 2024
ffbb24a
Merge branch 'main' into feature/remove-analyzers-from-ide
josefpihrt Feb 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 62 additions & 4 deletions .github/workflows/build.yml
Expand Up @@ -198,6 +198,28 @@ jobs:
pattern: vs_extension_*
delete-merged: true

build_vs_extension_with_analyzers:
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'v')
needs: pre_build
runs-on: windows-latest
env:
Version: ${{ needs.pre_build.outputs.version }}
DeployExtension: false
RoslynatorExtensionWithAnalyzers: true
defaults:
run:
working-directory: src/VisualStudio
steps:
- uses: actions/checkout@v4
- run: (Get-Content source.extension-with-analyzers.vsixmanifest) -replace 'Version="1.0.0"', 'Version="${{ needs.pre_build.outputs.version3 }}"' | Set-Content source.extension-with-analyzers.vsixmanifest
- run: dotnet restore
- uses: microsoft/setup-msbuild@v2
- run: msbuild -m
- uses: actions/upload-artifact@v4
with:
name: vs_extension_with_analyzers
path: src/VisualStudio/bin/Release/net472/*.vsix

build_vs_code_extension:
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'v')
needs: [ pre_build, build_analyzers ]
Expand All @@ -221,10 +243,6 @@ jobs:
cp bin/Release/netstandard2.0/Roslynator.Workspaces.Core.dll package/roslyn/common
cp bin/Release/netstandard2.0/Roslynator.Workspaces.Common.dll package/roslyn/common
cp bin/Release/netstandard2.0/Roslynator.CSharp.Workspaces.dll package/roslyn/common
cp bin/Release/netstandard2.0/Roslynator.CSharp.Analyzers.dll package/roslyn/analyzers
cp bin/Release/netstandard2.0/Roslynator.CSharp.Analyzers.CodeFixes.dll package/roslyn/analyzers
cp bin/Release/netstandard2.0/Roslynator.Formatting.Analyzers.dll package/roslyn/analyzers
cp bin/Release/netstandard2.0/Roslynator.Formatting.Analyzers.CodeFixes.dll package/roslyn/analyzers
cp bin/Release/netstandard2.0/Roslynator.CSharp.Refactorings.dll package/roslyn/refactorings
cp bin/Release/netstandard2.0/Roslynator.CSharp.CodeFixes.dll package/roslyn/fixes
name: Copy DLLs to package
Expand All @@ -248,6 +266,46 @@ jobs:
name: ovsx_extension
path: src/VisualStudioCode/package/*.vsix

build_vs_code_extension_with_analyzers:
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'v')
needs: [ pre_build, build_analyzers ]
runs-on: ubuntu-22.04
env:
Version: ${{ needs.pre_build.outputs.version }}
defaults:
run:
working-directory: src/VisualStudioCode
steps:
- uses: actions/checkout@v4
- run: dotnet restore
- run: dotnet build --no-restore
- run: |
mkdir package/roslyn/analyzers
mkdir package/roslyn/refactorings
mkdir package/roslyn/fixes
cp bin/Release/netstandard2.0/Roslynator.Core.dll package/roslyn/common
cp bin/Release/netstandard2.0/Roslynator.Common.dll package/roslyn/common
cp bin/Release/netstandard2.0/Roslynator.CSharp.dll package/roslyn/common
cp bin/Release/netstandard2.0/Roslynator.Workspaces.Core.dll package/roslyn/common
cp bin/Release/netstandard2.0/Roslynator.Workspaces.Common.dll package/roslyn/common
cp bin/Release/netstandard2.0/Roslynator.CSharp.Workspaces.dll package/roslyn/common
cp bin/Release/netstandard2.0/Roslynator.CSharp.Analyzers.dll package/roslyn/analyzers
cp bin/Release/netstandard2.0/Roslynator.CSharp.Analyzers.CodeFixes.dll package/roslyn/analyzers
cp bin/Release/netstandard2.0/Roslynator.CSharp.Refactorings.dll package/roslyn/refactorings
cp bin/Release/netstandard2.0/Roslynator.CSharp.CodeFixes.dll package/roslyn/fixes
name: Copy DLLs to package
- run: >
sed -i 's/"version": "1.0.0"/"version": "${{ needs.pre_build.outputs.version3 }}"/' package/package.json
- run: npm install
working-directory: src/VisualStudioCode/package
- run: npm install -g @vscode/vsce
- run: vsce package
working-directory: src/VisualStudioCode/package
- uses: actions/upload-artifact@v4
with:
name: vs_code_extension_with_analyzers
path: src/VisualStudioCode/package/*.vsix

build_core_cli:
if: github.ref_type != 'tag' || startsWith(github.ref_name, 'cli-v')
needs: pre_build
Expand Down
5 changes: 1 addition & 4 deletions README.md
Expand Up @@ -2,9 +2,6 @@

Roslynator is a set of code analysis tools for C#, powered by [Roslyn](https://github.com/dotnet/roslyn).

IMPORTANT: Analyzers will be removed from Roslynator IDE extensions in the next major release.
It's recommended to use Roslynator NuGet packages (e.g. [Roslynator.Analyzers](https://www.nuget.org/packages/roslynator.analyzers)) instead.

## Tools

- IDE extensions for:
Expand All @@ -14,8 +11,8 @@ It's recommended to use Roslynator NuGet packages (e.g. [Roslynator.Analyzers](h
- [Open VSX](https://open-vsx.org/extension/josefpihrt-vscode/roslynator)
- [NuGet packages](#nuget-packages) that contain collection of analyzers
- [Roslynator.Analyzers](https://www.nuget.org/packages/Roslynator.Analyzers)
- [Roslynator.CodeAnalysis.Analyzers](https://www.nuget.org/packages/Roslynator.CodeAnalysis.Analyzers)
- [Roslynator.Formatting.Analyzers](https://www.nuget.org/packages/Roslynator.Formatting.Analyzers)
- [Roslynator.CodeAnalysis.Analyzers](https://www.nuget.org/packages/Roslynator.CodeAnalysis.Analyzers)
- [Testing framework](#testing-framework) that allows unit testing of analyzers, refactoring and code fixes
- [.NET client libraries](#client-libraries) that extend Roslyn API
- [Command line tool](#command-line-tool)
Expand Down
13 changes: 2 additions & 11 deletions src/Common/Configuration/EditorConfigCodeAnalysisConfig.cs
Expand Up @@ -19,20 +19,11 @@ internal class EditorConfigCodeAnalysisConfig

is_global = true

# Options in this file can be used to change default configuration of analyzers, refactorings and compiler diagnostic fixes.
# Options in this file can be used to change default configuration of refactorings and compiler diagnostic fixes.
# Options can be used both in default configuration file (.roslynatorconfig) and in standard .editorconfig file.
# Default configuration is loaded once when IDE starts. Therefore, it may be necessary to restart IDE for changes to take effect.
# Full list of available options: https://josefpihrt.github.io/docs/roslynator/configuration

# Set severity for all analyzers that are enabled by default (https://docs.microsoft.com/en-us/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2022#set-rule-severity-of-multiple-analyzer-rules-at-once-in-an-editorconfig-file)
dotnet_analyzer_diagnostic.category-roslynator.severity = default|none|silent|suggestion|warning|error

# Enable/disable all analyzers by default.
# NOTE: This option can be used only in .roslynatorconfig file
roslynator_analyzers.enabled_by_default = true|false

## Set severity for a specific analyzer
#dotnet_diagnostic.<ANALYZER_ID>.severity = default|none|silent|suggestion|warning|error

## Enable/disable all refactorings
#roslynator_refactorings.enabled = true|false

Expand Down
130 changes: 68 additions & 62 deletions src/Tools/CodeGeneration/EditorConfig/EditorConfigGenerator.cs
Expand Up @@ -12,88 +12,94 @@ namespace Roslynator.CodeGeneration.EditorConfig;

public static class EditorConfigGenerator
{
public static string GenerateEditorConfig(RoslynatorMetadata metadata, bool commentOut)
public static string GenerateEditorConfig(RoslynatorMetadata metadata, bool includeAnalyzers, bool commentOut)
{
var optionMap = new Dictionary<string, HashSet<AnalyzerMetadata>>();

foreach (AnalyzerMetadata analyzer in metadata.Analyzers)
if (includeAnalyzers)
{
foreach (AnalyzerConfigOption option in analyzer.ConfigOptions)
foreach (AnalyzerMetadata analyzer in metadata.Analyzers)
{
if (!optionMap.TryGetValue(option.Key, out HashSet<AnalyzerMetadata> optionAnalyzers))
optionAnalyzers = new HashSet<AnalyzerMetadata>();
foreach (AnalyzerConfigOption option in analyzer.ConfigOptions)
{
if (!optionMap.TryGetValue(option.Key, out HashSet<AnalyzerMetadata> optionAnalyzers))
optionAnalyzers = new HashSet<AnalyzerMetadata>();

optionAnalyzers.Add(analyzer);
optionMap[option.Key] = optionAnalyzers;
optionAnalyzers.Add(analyzer);
optionMap[option.Key] = optionAnalyzers;
}
}
}

using (var w = new EditorConfigWriter(new StringWriter()))
{
w.WriteLine();
w.WriteLine("# Options");
w.WriteLine();

var isSeparatedWithNewLine = true;

foreach (AnalyzerOptionMetadata option in metadata.ConfigOptions
.Where(f => !f.IsObsolete)
.OrderBy(f => f.Key))
if (includeAnalyzers)
{
if (optionMap.TryGetValue(option.Key, out HashSet<AnalyzerMetadata> analyzers)
&& !isSeparatedWithNewLine)
{
w.WriteLine();
}

w.WriteCommentCharIf(commentOut);
w.WriteEntry($"{option.Key}", option.DefaultValuePlaceholder);

string defaultValue = option.DefaultValue;
w.WriteLine();
w.WriteLine("# Options");
w.WriteLine();

if (defaultValue is not null)
w.WriteLine($"# Default: {defaultValue}");
var isSeparatedWithNewLine = true;

if (analyzers?.Count > 0)
foreach (AnalyzerOptionMetadata option in metadata.ConfigOptions
.Where(f => !f.IsObsolete)
.OrderBy(f => f.Key))
{
w.WriteLine("# Applicable to: " + string.Join(", ", analyzers.OrderBy(f => f.Id).Select(f => f.Id.ToLowerInvariant())));
w.WriteLine();
isSeparatedWithNewLine = true;
if (optionMap.TryGetValue(option.Key, out HashSet<AnalyzerMetadata> analyzers)
&& !isSeparatedWithNewLine)
{
w.WriteLine();
}

w.WriteCommentCharIf(commentOut);
w.WriteEntry($"{option.Key}", option.DefaultValuePlaceholder);

string defaultValue = option.DefaultValue;

if (defaultValue is not null)
w.WriteLine($"# Default: {defaultValue}");

if (analyzers?.Count > 0)
{
w.WriteLine("# Applicable to: " + string.Join(", ", analyzers.OrderBy(f => f.Id).Select(f => f.Id.ToLowerInvariant())));
w.WriteLine();
isSeparatedWithNewLine = true;
}
else
{
isSeparatedWithNewLine = false;
}
}
else
{
isSeparatedWithNewLine = false;
}
}

w.WriteLine();
w.WriteLine("# Analyzers");
w.WriteLine();

foreach (AnalyzerMetadata analyzer in metadata.Analyzers
.Where(f => f.Status == AnalyzerStatus.Enabled && !f.Tags.Contains("HideFromConfiguration"))
.OrderBy(f => f.Id))
{
w.WriteLine($"# {analyzer.Title.TrimEnd('.')}");
w.WriteCommentCharIf(commentOut);
w.WriteAnalyzer(
analyzer.Id.ToLowerInvariant(),
(analyzer.IsEnabledByDefault)
? ((DiagnosticSeverity)Enum.Parse(typeof(DiagnosticSeverity), analyzer.DefaultSeverity)).ToReportDiagnostic()
: ReportDiagnostic.Suppress);
w.WriteLine();
w.WriteLine("# Analyzers");
w.WriteLine();

if (analyzer.ConfigOptions.Count > 0)
foreach (AnalyzerMetadata analyzer in metadata.Analyzers
.Where(f => f.Status == AnalyzerStatus.Enabled && !f.Tags.Contains("HideFromConfiguration"))
.OrderBy(f => f.Id))
{
w.WriteLine("# Options: "
+ string.Join(
", ",
analyzer.ConfigOptions
.Where(f => metadata.ConfigOptions.FirstOrDefault(ff => ff.Key == f.Key)?.IsObsolete != true)
.OrderBy(f => f.Key)
.Select(f2 => metadata.ConfigOptions.First(f => f.Key == f2.Key).Key)));
}
w.WriteLine($"# {analyzer.Title.TrimEnd('.')}");
w.WriteCommentCharIf(commentOut);
w.WriteAnalyzer(
analyzer.Id.ToLowerInvariant(),
(analyzer.IsEnabledByDefault)
? ((DiagnosticSeverity)Enum.Parse(typeof(DiagnosticSeverity), analyzer.DefaultSeverity)).ToReportDiagnostic()
: ReportDiagnostic.Suppress);

if (analyzer.ConfigOptions.Count > 0)
{
w.WriteLine("# Options: "
+ string.Join(
", ",
analyzer.ConfigOptions
.Where(f => metadata.ConfigOptions.FirstOrDefault(ff => ff.Key == f.Key)?.IsObsolete != true)
.OrderBy(f => f.Key)
.Select(f2 => metadata.ConfigOptions.First(f => f.Key == f2.Key).Key)));
}

w.WriteLine();
w.WriteLine();
}
}

w.WriteLine();
Expand Down
7 changes: 0 additions & 7 deletions src/Tools/CodeGeneration/Markdown/MarkdownGenerator.cs
Expand Up @@ -259,13 +259,6 @@ static IEnumerable<MElement> CreateAppliesTo(AnalyzerMetadata analyzer)
{
yield return Heading2("Applies to");

if (!analyzer.Id.StartsWith("RCS9"))
{
yield return BulletItem(Link("Extension for VS 2022", "https://marketplace.visualstudio.com/items?itemName=josefpihrt.Roslynator2022"));
yield return BulletItem(Link("Extension for VS Code", "https://marketplace.visualstudio.com/items?itemName=josefpihrt-vscode.roslynator"));
yield return BulletItem(Link("Extension for Open VSX", "https://open-vsx.org/extension/josefpihrt-vscode/roslynator"));
}

if (analyzer.Id.StartsWith("RCS0"))
yield return BulletItem(Link(new[] { "Package ", "Roslynator.Formatting.Analyzers" }, "https://www.nuget.org/packages/Roslynator.Formatting.Analyzers"));

Expand Down
2 changes: 1 addition & 1 deletion src/Tools/CodeGenerator/Program.cs
Expand Up @@ -101,7 +101,7 @@ private static void Main(string[] args)
@"export const configurationFileContent = {
roslynatorconfig: `"
+ EditorConfigCodeAnalysisConfig.FileDefaultContent
+ EditorConfigGenerator.GenerateEditorConfig(metadata, commentOut: true)
+ EditorConfigGenerator.GenerateEditorConfig(metadata, includeAnalyzers: false, commentOut: true)
+ @"`
};",
new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/ConfigurationFileGenerator/Program.cs
Expand Up @@ -35,7 +35,7 @@ private static void Main(string[] args)

```editorconfig title=".editorconfig"
"""
+ EditorConfigGenerator.GenerateEditorConfig(metadata, commentOut: false)
+ EditorConfigGenerator.GenerateEditorConfig(metadata, includeAnalyzers: true, commentOut: false)
+ @"```
";

Expand Down
11 changes: 3 additions & 8 deletions src/Tools/ConfigurationFileGenerator/configuration.md
Expand Up @@ -6,13 +6,11 @@ Use EditorConfig file to configure analyzers, refactoring and compiler diagnosti
# Set severity for all analyzers that are enabled by default (https://docs.microsoft.com/en-us/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2022#set-rule-severity-of-multiple-analyzer-rules-at-once-in-an-editorconfig-file)
dotnet_analyzer_diagnostic.category-roslynator.severity = default|none|silent|suggestion|warning|error

# Enable/disable all analyzers by default
# NOTE: This option can be used only in .roslynatorconfig file
roslynator_analyzers.enabled_by_default = true|false

# Set severity for a specific analyzer
dotnet_diagnostic.<ANALYZER_ID>.severity = default|none|silent|suggestion|warning|error

# NOTE: Following options can be used both in .editorconfig file and in .roslynatorconfig file (see below):

# Enable/disable all refactorings
roslynator_refactorings.enabled = true|false

Expand All @@ -33,9 +31,7 @@ if an analyzer is enabled but required option is not set. ROS0003 is disabled by

## Default Configuration

If you want to configure Roslynator on a user-wide basis you have to use Roslynator config file (`.roslynatorconfig`).

**IMPORTANT:** Default configuration file can be used only with VS extension or VS code extension.
Default configuration file can be used to configure Visual Studio extension or VS Code extension (refactorings and code fixes).

### Format

Expand All @@ -44,7 +40,6 @@ Namely, file must contain top-level entry `is_global = true` and cannot contain

```ini
is_global = true
roslynator_analyzers.enabled_by_default = true
```

### Location
Expand Down
16 changes: 8 additions & 8 deletions src/VisualStudio/Overview.md
@@ -1,22 +1,22 @@
## Overview

* A collection of 500+ analyzers, refactorings and fixes for C#, powered by [Roslyn](https://github.com/dotnet/roslyn).
* A collection of refactorings and fixes for C#, powered by [Roslyn](https://github.com/dotnet/roslyn).
* [Project website](https://github.com/dotnet/roslynator)
* [List of analyzers](https://josefpihrt.github.io/docs/roslynator/analyzers)
* [List of refactorings](https://josefpihrt.github.io/docs/roslynator/refactorings)
* [List of code fixes for CS diagnostics](https://josefpihrt.github.io/docs/roslynator/fixes)
* [Release notes](https://github.com/dotnet/roslynator/blob/main/ChangeLog.md)

IMPORTANT: Analyzers will be removed from Roslynator extension in the next major release.
As a replacement, use Roslynator NuGet packages (e.g. [Roslynator.Analyzers](https://www.nuget.org/packages/roslynator.analyzers)).
## Analyzers

## Donation
It' recommended to also use Roslynator analyzers to improve code quality.
To use Roslynator analyzers, install following NuGet packages to a project/solution:

Although Roslynator is free of charge, any [donation](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BX85UA346VTN6) is welcome and supports further development.
- [Roslynator.Analyzers](https://www.nuget.org/packages/Roslynator.Analyzers)
- [Roslynator.Formatting.Analyzers](https://www.nuget.org/packages/Roslynator.Formatting.Analyzers)

## Related Products
## Donation

* Package [Roslynator.Analyzers](http://www.nuget.org/packages/Roslynator.Analyzers/) contains only analyzers.
Although Roslynator is free of charge, any [donation](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BX85UA346VTN6) is welcome and supports further development.

## Documentation

Expand Down