dotnet / dotnet/roslynator

Suggestion: Analyzer for using Path.Combine

Open
#619 0 comments 0 reactions 0 assignees View on GitHub
Area-Analyzers Feature Request
Dominant language
C#
Stars
3.5k
Forks
294
Avg merge
2h 30m
Merged PRs (30d)
4

Description

In cross-platform development (and probably at all), you should not use a hard-coded path.
For example,
```csharp
var path = @"paTh\To\subfOlder";
```
Will not behave as expected on Linux.
Each path must be by using `Path.Combine`, and with awareness about the case.

In addition, identify a line in the text:
```csharp
var secondLine = text.split("\r\n")[1];
```

Will not run as expected on Linux, and will need to use:
```csharp
var secondLine = text.split(Environment.NewLine)[1];
```

Is there such an analyzer?
Is it possible to develop?

(I'm new in the Analyzers, but know AST and so on, so with some general intent or design, I believe I can develop myself)

Contributor guide

Open the contributing guide

Research direction

Review Roslynator's existing C# analyzer architecture and determine whether diagnostics for hard-coded paths and platform-specific line splitting fit the project. Define the analyzer scope, expected diagnostics, and what tests would demonstrate that both examples are handled; the issue does not name files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.