Skip to content

Conversation

@Enricoza
Copy link
Contributor

@Enricoza Enricoza commented Aug 28, 2025

Hi, I was seeing that #688 was still open and that a PR was welcome for that, so I've tried to have a go at it.
Hopefully this can be merged as I think it could be a good addition and it would be very useful to me (and to others apparently).

Thank you guys for all your work on this!


A custom category can now specify a regex for each of its children by using an object with a regex key instead of just a string to find all of the declaration matching that regex.

For example:

custom_categories:
  - name: some_category_name
    children:
    - some_exact_name
    - regex: some_regex

Will create a category containing:

  • the declaration "some_exact_name" (if it's found)
  • all the declaration that match the "some_regex" regex. (e.g. "some_regex", "some_regex1", ...)

… child

A custom category can now specify a regex for each of its children
by using an object with a regex key instead of just a string
to find all of the declaration matching that regex.

For example:
```
custom_categories:
  - name: some_category_name
    children:
    - some_exact_name
    - regex: some_regex
```

Will create a category containing:
- the declaration "some_exact_name" (if it's found)
- all the declaration that match the "some_regex" regex. (e.g. "some_regex", "some_regex1", ...)
@Enricoza Enricoza force-pushed the custom_categories_regex branch from 00d231a to f783f9f Compare August 28, 2025 16:49
Handle the received string to match just as a string
CHANGELOG.md Outdated
##### Enhancements

* None.
* Allow `custom_categories` to specify a regex for a child.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need two spaces at the end of the line (markdown linebreak)

end
else
doc_index.lookup_regex(selector['regex'])
.sort_by { |doc| doc.name.downcase }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking behind the downcase here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not enough thinking I would say 😄. I'll remove it.

selected = if selector.is_a?(String)
unless doc = doc_index.lookup(selector)
warn 'WARNING: No documented top-level declarations match ' \
"name \"#{name}\" specified in categories file"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name is wrong here, cut + paste error - is causing the swift_spec test to fail

@johnfairh
Copy link
Collaborator

Thanks for the PR, looks basically good! I like the approach of using the yaml structure to do this.

You should be able to run bundle exec rake rubocop locally (or just rake rubocop depending on your setup) and work through the linter.

Please also add a change to the README to document this -- I realise the docs of custom_categories are 'minimal', not asking you to fix that, just to add a few lines explaining the addition.

(I expect to have some solid open source time in a few weeks and will be doing an Xcode26-ish release then, should be able to pull in this too.)

Add custom_categories documentation in readme
@Enricoza
Copy link
Contributor Author

Enricoza commented Sep 1, 2025

@johnfairh Thanks for the quick review, had missed the linter as I'm pretty new to this repo. Now all warnings should be fixed.
I've added some generic custom_categories documentation as well as some lines specific to my enhancements since I was there. Let me know if I need to change anything else.

And thanks again for looking into this and for the time you'll dedicate to the new release in a few weeks time.

@johnfairh
Copy link
Collaborator

Thanks this is great. Don't worry about the Danger failure, just one refactoring left to tidy up.

[] without return was a no op and [single_doc] was returned
which was [nil] therefore causing a crash.
@johnfairh
Copy link
Collaborator

Looks like this will go cleanly on top of Xcode26...

@johnfairh johnfairh merged commit b6365b4 into realm:master Oct 16, 2025
3 of 4 checks passed
@Enricoza Enricoza deleted the custom_categories_regex branch October 16, 2025 13:35
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.

2 participants