Make Filter methods static to avoid the need for instantiation #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Tyler,
This PR is a little opinionated, and is a breaking change, so I'll understand if you'd rather not merge it. But I couldn't resist sending it your way.
The current library requires users to create a
Filter
object before they can use theisProfane
orclean
methods. ButFilter
has are no class variables, and there is no work performed by theFilter
constructor. So there's no need or benefit from creating an instance ofFilter
before accessing those methods.If we make the
isProfane
andclean
methods static, users can callisProfane
andclean
without first instantiatingFilter
. I don't see any downside to this. Even if you plan to add configuration options in the future, you could handle those options much likeLogger
andLogger.root
inpackage:log/log.dart
— no need for instantiation.Making these methods static is a breaking change, and would probably warrant a bump to version 0.3.0.
If existing users of the library upgrade, they would need to make some very minor changes. For example, they would replace this:
with this:
Like I said, feel free to ignore this PR if you'd rather not make breaking changes. But I think this improves the ergonomics of the library hugely, so I am in favour. 👍
Cheers,
Ben