Skip to content
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

[Fix #10515] Add --json-schema generator #12323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dleavitt
Copy link

Per #10515, adds a --json-schema flag to output a JSON Schema for your project's RuboCop configuration file.

This allows your IDE to autocomplete/validate the cop, department and global settings in your .rubocop.yml, including those of any extensions you've added via require.

Next Steps

There are examples for vscode and intellij in the docs, but it's still sort of DIY to get this set up.

What we want to do next is register it in the JSON Schema Store so that editors pick it up automatically.

For that we need a permanent URL where the schema can live. I added some code to generate a schema in the assets dir that includes rules for most of the extensions listed in the documentation. The URL in this case would be something like this:
https://raw.githubusercontent.com/rubocop/rubocop/master/assets/schema.json

If we like this approach I can commit the generated schema as part of this PR and open a PR at the schema store repo.

Alternatively we could host it with the docs or in a separate repo or something. In any case we'll probably want to incorporate schema generation into the build or release process so it stays current as cops are added/removed.

Notes

  • The test and config-related code are kludgy, as discussed on the original PR here: [Fix #10515] Add --json-schema generator #10523.
  • In addition to the tests I've got a rake task that validates rubocop configs from some popular ruby projects. That said there are probably still some valid configs that will get flagged as invalid - should be easy to fix if we find any.

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@dleavitt dleavitt force-pushed the json-schema-generator branch 3 times, most recently from 3a0ef60 to 0ae5eb3 Compare October 31, 2023 03:52
@bbatsov
Copy link
Collaborator

bbatsov commented Nov 1, 2023

The proposal seems reasonable to me, but I'm not using VS Code or IntelliJ, so it's hard for me to provide particularly meaningful feedback. @rubocop/rubocop-core Any volunteer to review this PR?

Adds a --json-schema flag to output a JSON Schema for your project's RuboCop configuration file.

This allows autocompletion and validation of cop, department and global options in your RuboCop config file, including any extensions you've added via `require`.
@dleavitt
Copy link
Author

dleavitt commented Nov 1, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants