-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add warning diagnostic when using V2 api #33
Conversation
microbit-robert
commented
May 3, 2024
•
edited by microbit-matt-hillsdon
Loading
edited by microbit-matt-hillsdon
- Translation sync required before merge and use (or at least addition of new strings in all simplified language files in English for now). Keeping in draft until this is done.
maybeAddMicrobitVersionWarningBinderWrapper(importResult.importName, () => | ||
this._addDiagnostic( | ||
this._fileInfo.diagnosticRuleSet.reportMicrobitV2ApiUse, | ||
DiagnosticRule.reportMicrobitV2ApiUse, | ||
Localizer.Diagnostic.microbitV2ModuleUse().format({ | ||
moduleName: importResult.importName, | ||
device, | ||
}), | ||
node | ||
) | ||
); |
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.
This is setup with a callback so we can track micro:bit specific diagnostics in one file, microbitUtils.ts
. Useful if we only want to warn on the first use of a V2 API call in the future. We can't directly pass in this_.addDiagnostic
as this causes errors.
return ( | ||
['log', 'microbit.microphone', 'microbit.speaker', 'power'].includes(moduleName) || | ||
(moduleName === 'microbit' && | ||
['run_every', 'set_volume', 'Sound', 'pin_logo', 'pin_speaker'].includes(name ?? '')) || | ||
(moduleName === 'microbit.audio' && name === 'SoundEffect') || | ||
(moduleName === 'neopixel' && ['fill', 'write'].includes(name ?? '')) | ||
); |
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.
Hardcoded, but only in one place. Are any missing?
"microbitV2ClassMethodUse": "The \"{methodName}\" method on the \"{className}\" class cannot be used with a {device}", | ||
"microbitV2ModuleMemberUse": "\"{name}\" from the \"{moduleName}\" module cannot be used with a {device}", | ||
"microbitV2ModuleUse": "\"{moduleName}\" cannot be used with a {device}", |
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.
Highlighting for review as these will be tweaked based on prior discussion.
I've tried for an alternative on #35 Mainly focussed on the layer we do this at but I've also made some incidental changes to the error code/text. |
Merged the alternative on #35 |