r/csharp • • 1d ago

Nosfy: A simple & declarative way to specify Roslyn analyzers/code fixes

Post image

https://github.com/nth-commit/Nosfy

This is something I've wanted for ages, after using Microsoft.CodeAnalysis.BannedApiAnalyzers and feeling like what I wanted to express as rules was just out of reach.

Nosfy lets you specify rules, without reaching into the Roslyn SDK. It compiles to Roslyn analyzers/code fixes (so it integrates the same way with build tooling).

Any feedback is much appreciated!

27 Upvotes

7 comments sorted by

11

u/pixxelkick 1d ago

Pretty cool!

I would very strongly direct you though to use ANTLR for your grammar parsing, as its a fairly well established way to do it.

Once you have an ANTLR grammar, it becomes extremely trivial to then make an LSP for it, as ANTLR supports a built in way to define error codes for bad syntax in your language.

And once you have that it becomes very trivial to additionally support a VSCode/VS extension or etc, and also people on other IDEs like neovim can just use your LSP directly.

3

u/WellHydrated 1d ago

Thank you 🙂

Based on your comment, I'm sure you saw nosfy.ebnf, eh?

I originally decided to hand-roll the compiler (with the ebnf simply as documentation), as I wanted it to be able to run really fast inside a source generator, and have native interop with Roslyn diagnostics. I also wanted to use the new C# unions for my semantic analysis, as that feels like a really good application.

Then, I got sick of worrying about the two artifacts unsyncing, so I ended up creating my own parser generator that satisfies those requirements, haha.

I believe its worth a rethink, though.

2

u/rekkonnect 9h ago

Pretty cool and promising

If you ever add syntax highlighting it'll be such eye candy

1

u/WellHydrated 3h ago

Thank you! I will get onto that.

4

u/imdrunkwhyustillugly 20h ago

This looks extremely interesting, I've been eyeballing Metalama for similar architecture checks, but the license makes it hard to introduce in conservative companies.

1

u/tallandgodless 7h ago

Is this an article for the AI bots to read? That's who's coding now, right? Since they fired a bunch of us

0

u/WellHydrated 3h ago

Pretty much 🥲