-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Define style guide as data interchange format #57155
Comments
unit testable style guides. Love it! :) |
So many good ideas here! +1000 across the board. Specifically, to @sethladd 's point, the good and bad examples could easily be translated into test data which would be cool. When I did the first cut of the formatter I did just this only manually. I'm not sure how flexible markdown is to be honest... If we wanted to embed metadata maybe we'd need to look into MMD or some other MD superset? More generally, I think tying the style guide and linter rules and tool output would be great. Defining it in one place would be a win for all. |
Interesting, so for those rules in the style guide that are actually lintable (violations are machine detectable), the bad example could be used as the text case against a lint being produced, and the good example could be used as the expected output when testing a quick fix corresponding to that rule. Looks like the current style guide has the good and bad examples in separate dart files. That seems nice because you would get syntax highlighting in editors, could run the analyzer on them, etc. Alternatively could use the same format as dart_style does. One tricky thing will be defining the rule ids. Naming conventions will need to be defined. I think it is best not to include DO/DONT/PREFER/AVOID in the rule id. That way you can change the type without changing the rule id. Maybe just a Another question: Would it make sense to move the style guide to its own repo to ease consumption from this repo, the dartlang.org repo, and potentially dart_style? Maybe the |
Good points @seaneagan. Rule ids and naming conventions are tricky. I did a little surveying and it seems like there's little consensus in related tools. As for moving the style guide and building a package around it, that's an interesting idea. I'd be curious how @munificent and @sethladd weigh in. In the meantime, looking at the markup, it appears to be using a superset of MD so that's cool as far as potentially embedding metadata. Regardless of how we achieve it, I think having a nice linking here would be awesome. Maybe crazy but for lints associated with style guide entries we could even emit (in some kind of uber verbose mode) URLs for added rationale... |
As long as it's easy to generate a markdown file that contains all the rules and the text, I'm flexible on where the canonical version of the style guide lives. |
FWIW I did some experimenting with generating rule docs. In the long run, I'd love to share definitions with the style guide. In the meantime, the process is a little manual at first (you need to harvest the text from the guide), but once it's done, the docs get auto generated. For example:
Lots of details to hammer out but as a jumping off point not too bad. Needless to say, comments/feedback most welcome! |
Way cool! I guess a next step would be pulling out the description, details, kind, etc. into a separate yaml file (for starters, could switch to markdown embedding later) since that will allow reading/writing the rules without touching any actual dart files. That may bump up against http://dartbug.com/21020, but there are workarounds such as a transformer which produces a dart file with a string variable with the yaml file's contents (or just start with that). Could also potentially parse the "kind" (DO, DONT, etc.) from the description (or keep it separate and concatenate). |
I love this idea (still) but since it's not on any short-term roadmaps, closing out for now. 😢 |
Currently the style guide is just a markdown doc. So there is no metadata about the style guide rules for the linter to consume, so it will have to define its own. It would be much nicer if the lints produced by the linter were associated back to a style guide rule via a rule id. The rule metadata could then be looked up in the style guide by that id. Would probably be either JSON or YAML. That would allow:
I filed the issue here instead of at https://github.com/dart-lang/www.dartlang.org since this seems like a logical place for the discussion, but I can move it there if desired.
@pq @munificent thoughts?
The text was updated successfully, but these errors were encountered: