riscv-software-src / riscv-unified-db

Machine-readable database of the RISC-V specification, and tools to generate various views
Other
20 stars 15 forks source link

add automation for consistent formatting and linting #260

Open kbroch-rivosinc opened 1 week ago

kbroch-rivosinc commented 1 week ago

Consistently formatted yaml, json, etc makes it easier for multiple developers and reduces git diffs.

Formatting and linting that can be run on at git commit time with a git hook, reduces the need for this later in PRs (Github action can be used to confirms that it was done)

There are tools to manage pre-commit hooks like:

Since this project is a multilingual project:

❯ tokei -C --sort lines
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 HTML                  136        94823        55057            0        39766
 YAML                 1146        93645        81165         2961         9519
 Ruby                   34        16690        11701         2340         2649
 JSON                   12         5883         5855            0           28
 JavaScript              7         4158         4096            9           53
 Ruby HTML              20         3001         2668            0          333
 Rakefile               10         1914         1582           38          294
 AsciiDoc                7         1816         1397            0          419
 CSS                     3          556          512            7           37
 BASH                    9          219          165           16           38
 Module-Definition       1           37           25            0           12
 Markdown                1            1            0            1            0
===============================================================================
 Total                1386       222743       164223         5372        53148
===============================================================================

I would suggest using pre-commit to manage the hooks but I'm open to exploring other tooling. (I do realize that since pre-commit is python based I'd be adding another language to the dev dependencies)

I'm happy to put in a PR once the discussion done.

dhower-qc commented 1 week ago

Love that idea. As mentioned in Issue #246, it might also be nice to have the keys sorted in YAML files to ensure scripted changes produce reasonable diffs (Since different YAML libraries will likely emit in different orders).

kbroch-rivosinc commented 1 week ago

I did some exploration of yaml formatting with following tools:

Here's my findings:

My recommendation based on this would be to move ahead with prettier formatting and writing a custom script to enforce keyword sorting with a specific ordering for some keyword if needed.

kbroch-rivosinc commented 5 days ago

Discussed this more with maintainers and going to reduce the number of hooks in this initial PR to just very simple:

The other hooks in this initial can then be put in later PRs.