How belav/csharpier works
Main Components
• Core Formatting Engine – This is the backbone of CSharpier and includes components responsible for parsing C# code (using Roslyn), generating the syntax, applying formatting rules, and then printing the formatted output. It’s represented by modules like “CSharpier”, “CodeFormatter”, “DocPrinter”, “SyntaxPrinter”, and related utility classes.
• CLI Application – Found in Src/CSharpier.Cli and its tests (Src/CSharpier.Cli.Tests). This component provides a command-line interface where a user can invoke “dotnet csharpier” to format code.
• Integration/Extension Projects – These include components for editor integrations such as Visual Studio (Src/CSharpier.VisualStudio), Rider (Src/CSharpier.Rider), and VSCode, as well as integration with MsBuild (Src/CSharpier.MsBuild) and possibly other build tools.
• Playground & Website – The Playground (Src/CSharpier.Playground) and Website (Src/Website) provide user interfaces (often web-based) for demo purposes, documentation, and an online “try-it-out” experience.
• Testing and Code Generation – There are dedicated test projects (in Tests and various Src/CSharpier.Tests directories) as well as generators (e.g., Src/CSharpier.Generators, Src/CSharpier.FakeGenerators) which help validate the formatting rules.
• Build and Infrastructure Scripts – The repository also includes various CI/CD workflows, configuration files (e.g., .github/workflows), Dockerfiles, and helper scripts (in Shell and Scripts directories) which orchestrate automated testing, publishing, and deployment.
Relationships and Interactions
• The Playground and Website interact with both the core services and potentially the CLI interfaces in a client-server or web service-like pattern to provide a live demonstration of the formatting.
• Testing components are connected to the core engine and CLI components, ensuring that changes in the formatting logic trigger comprehensive automated tests.
• Code generators and tools (from the Generators folders) interface with the core library or help update/reinforce the compatibility between new Roslyn features and the tool’s formatting output.
• The CI/CD and build scripts (GitHub workflows, Dockerfiles, shell scripts) interact with all the above components to build, test, and deploy the tool and its extensions.
Architectural Patterns and Design Principles
• Modularity and Separation of Concerns: The project is structured into separate solutions, projects, and libraries to decouple the engine from the different integration points.
• Reusability: The core formatting library is reused across the CLI, integration projects, and even for generating formatted documentation on the website.
• Automated Testing and CI: Multiple test suites (including integration tests, end-to-end tests, and formatting tests) help ensure the tool maintains a consistent output.
• Consistent Configuration Management: Use of Directory.Build.props/Directory.Packages.props and centralized configuration across the solution that helps maintain consistent dependency versions and build settings.
Incorporate Relevant Technologies and Frameworks
• .NET / C# and Roslyn – The primary platform and language; Roslyn is the parsing and code analysis engine.
• Prettier-inspired Printing Engine – While the printing process is evolved from the original prettier, it has been adapted to cater to C# formatting rules.
• Docker, GitHub Actions, and MSBuild – Employed for CI/CD, testing, packaging, and deployment.
• Web Technologies – In the Website and Playground (e.g., use of Docusaurus for documentation and modern front-end frameworks in ClientApp).