microsoft / typespec

https://typespec.io/
MIT License
4.56k stars 223 forks source link

Built-in linter system #1785

Closed timotheeguerin closed 1 year ago

timotheeguerin commented 1 year ago

Bring this back on the table. We are currently using @typespec/linter a library to make linter rules that plug in the onValidate step of the typescript compilation.

The problem with this approach:

Idea with a built-in linter system is that the compiler would be aware of the various linting rules and allow better customization from other libraries and spec author.

Ideas

This is just some idea but could have something like this in a spec

#enable no-inline-models warn
#disable no-unions

this could even be the way libraries decide which rules they enable themself.

Other related issues

Proposal https://gist.github.com/timotheeguerin/9d665c82f89d3a07a406a8928fb1e2bd

nguerrera commented 1 year ago

I like this idea a lot.

timotheeguerin commented 1 year ago

Items to consider for built-in system:

timotheeguerin commented 1 year ago

Another thing we might want to consider is the scope of a linter rule. Lets say you have 2 services defined in the same spec. Each service is using a different library with different set of rules. We probably want to make sure only the relevant linter rules are enabled per service. This would mean having some kind of scope for where the rules can run.

timotheeguerin commented 1 year ago

Proposal https://gist.github.com/timotheeguerin/9d665c82f89d3a07a406a8928fb1e2bd

timotheeguerin commented 1 year ago

implementation here https://github.com/microsoft/typespec/issues/1996