-
Notifications
You must be signed in to change notification settings - Fork 42
Conversation
fixes hhvm#86 In order to make this change backwards compatible, allowYesToAll() defaults to true. Unsafe linters may override this to false. I also considered a default of false, but that would entail altering all safe linters (including third-party). Unsafe linters may need to suppress `must use override` linter if they wish to remain compatible with previous versions of hhast.
Some linters look like they might be unsafe, but aren't on close inspection. I added allowYesToAll(): bool { return true; } on those. I checked every autofixing linter. If I could not find a bad autofix, I left the linter untouched.
I changed this during testing and forgot to flip it back.
The example first used `$a` as a meta syntactic variable. I later changed to `$k` and `$v` for key and value. I didn't update every use of `$_a`.
Trigger CI |
Thank you for the fix. I just wonder why do you define Did you consider creating two traits |
Good catch! I could move this method to
If I did that, every autofixing linter written before the commit would need to be changed to use one of these traits. There must be a default for backwards compatibility. I chose I could add a <<__Override>>
public function allowYesToAll(): bool { return false; } This saves two lines of code in each unsafe linter. |
The idea of |
Suggested in a code review. This only makes sense for autofixing linters.
namespace Facebook\HHAST; | ||
|
||
<<__Sealed(AutoFixingLinter::class)>> | ||
interface AutoFixable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AutoFixingLinter takes a generic, which means UnsafeBulkAutoFixes
can't require implements AutoFixingLinter<Terror>
without being generic itself.
It doesn't use the generic either, so this small marker interface is used instead.
By the way, technically we could avoid the
|
💭 I am not so sure. Autofixing linters don't know about the CLI at all right now. They do know about LSP though... 🤔 Maybe adding CLI knowledge isn't that bad. Feels like the responsibility of something else though. |
I prefer adding a virtual method over adding a new base class. The gain of not having to use AutoFixingASTLinter is not the only autofix linter around. AutoFixingLinter has three children: AutoFixingASTLinter, AutoFixingLineLinter, (final class) NewlineAtEndOfFileLinter. So we would need to add |
77b987f
to
c63e6d5
Compare
If I understand correctly, c63e6d5 creates two traits and breaks backward compatibility. Did you change your mind? |
The creation of the second trait doesn't break bc. Linters that are unchanged still inherit the default
I could have been more clear with my response here. I (mis)read your question as, "Why not create two traits and all autofixing linters use either one or the other?". We can create two traits just fine (hhast owns the namespace). We just can't require all linters to use one of these traits. I am sorry for any confusion I may have caused. I was answering a different question than the one you had asked me (probably). |
Looks good to me! Thank you! |
fixes #86
In order to make this change backwards compatible, allowYesToAll() defaults to true.
Unsafe linters may override this to false.
I also considered a default of false,
but that would entail altering all safe linters (including third-party). Unsafe linters may need to suppress
must use override
linter if they wish to remain compatible with previous versions of hhast.