-
-
Notifications
You must be signed in to change notification settings - Fork 452
Improve Warning Suppression #8832
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
Open
APickledWalrus
wants to merge
3
commits into
dev/feature
Choose a base branch
from
feature/better-warning-suppression
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
62 changes: 0 additions & 62 deletions
62
src/main/java/ch/njol/skript/effects/EffSuppressTypeHints.java
This file was deleted.
Oops, something went wrong.
61 changes: 0 additions & 61 deletions
61
src/main/java/ch/njol/skript/effects/EffSuppressWarnings.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/org/skriptlang/skript/common/elements/effects/EffSecSuppressTypeHints.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package org.skriptlang.skript.common.elements.effects; | ||
|
|
||
| import ch.njol.skript.config.SectionNode; | ||
| import ch.njol.skript.doc.Description; | ||
| import ch.njol.skript.doc.Example; | ||
| import ch.njol.skript.doc.Name; | ||
| import ch.njol.skript.doc.Since; | ||
| import ch.njol.skript.lang.EffectSection; | ||
| import ch.njol.skript.lang.Expression; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.skript.lang.TriggerItem; | ||
| import ch.njol.skript.registrations.Feature; | ||
| import ch.njol.skript.variables.HintManager; | ||
| import ch.njol.util.Kleenean; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.skriptlang.skript.lang.experiment.ExperimentData; | ||
| import org.skriptlang.skript.lang.experiment.SimpleExperimentalSyntax; | ||
| import org.skriptlang.skript.registration.SyntaxInfo; | ||
| import org.skriptlang.skript.registration.SyntaxRegistry; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Name("Suppress Type Hints (Experimental)") | ||
| @Description(""" | ||
| An effect to suppress local variable type hint errors for the syntax lines that follow this effect. | ||
| NOTE: Suppressing type hints also prevents syntax from providing new type hints. \ | ||
| For example, with type hints suppressed, 'set {_x} to true' would not provide 'boolean' as a type hint for '{_x}' | ||
| """) | ||
| @Example(""" | ||
| start suppressing local variable type hints | ||
| # potentially unsafe code goes here | ||
| stop suppressing local variable type hints | ||
| """) | ||
| @Since({"2.12", "INSERT VERSION (suppressing in a section)"}) | ||
| public class EffSecSuppressTypeHints extends EffectSection implements SimpleExperimentalSyntax { | ||
|
|
||
| private static final ExperimentData EXPERIMENT_DATA = ExperimentData.createSingularData(Feature.TYPE_HINTS); | ||
|
|
||
| public static void register(SyntaxRegistry syntaxRegistry) { | ||
| syntaxRegistry.register(SyntaxRegistry.SECTION, SyntaxInfo.simple(EffSecSuppressTypeHints.class, EffSecSuppressTypeHints::new, | ||
| "[stop:un]suppress [local variable] type hints", | ||
| "(start|:stop) suppressing [local variable] type hints")); | ||
| } | ||
|
|
||
| private boolean stopSuppression; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult, | ||
| @Nullable SectionNode sectionNode, @Nullable List<TriggerItem> triggerItems) { | ||
| stopSuppression = parseResult.hasTag("stop"); | ||
| HintManager hintManager = getParser().getHintManager(); | ||
| boolean wasActive = hintManager.isActive(); | ||
| hintManager.setActive(stopSuppression); | ||
| if (sectionNode != null) { | ||
| loadCode(sectionNode); | ||
| hintManager.setActive(wasActive); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected @Nullable TriggerItem walk(Event event) { | ||
| return walk(event, true); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return (stopSuppression ? "stop" : "start") + " suppressing type hints"; | ||
| } | ||
|
|
||
| @Override | ||
| public ExperimentData getExperimentData() { | ||
| return EXPERIMENT_DATA; | ||
| } | ||
|
|
||
| } | ||
94 changes: 94 additions & 0 deletions
94
src/main/java/org/skriptlang/skript/common/elements/effects/EffSecSuppressWarnings.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package org.skriptlang.skript.common.elements.effects; | ||
|
|
||
| import ch.njol.skript.Skript; | ||
| import ch.njol.skript.config.SectionNode; | ||
| import ch.njol.skript.doc.Description; | ||
| import ch.njol.skript.doc.Example; | ||
| import ch.njol.skript.doc.Name; | ||
| import ch.njol.skript.doc.Since; | ||
| import ch.njol.skript.lang.EffectSection; | ||
| import ch.njol.skript.lang.Expression; | ||
| import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
| import ch.njol.skript.lang.TriggerItem; | ||
| import ch.njol.skript.lang.parser.ParserInstance; | ||
| import ch.njol.util.Kleenean; | ||
| import org.bukkit.event.Event; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.skriptlang.skript.lang.script.Script; | ||
| import org.skriptlang.skript.lang.script.ScriptWarning; | ||
| import org.skriptlang.skript.registration.SyntaxInfo; | ||
| import org.skriptlang.skript.registration.SyntaxRegistry; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Name("Locally Suppress Warning") | ||
| @Description("Suppresses target warnings from the current script.") | ||
| @Example("locally suppress missing conjunction warnings") | ||
| @Example("suppress the variable save warnings") | ||
| @Since({"2.3", "INSERT VERSION (suppressing in a section)"}) | ||
| public class EffSecSuppressWarnings extends EffectSection { | ||
|
|
||
| public static void register(SyntaxRegistry syntaxRegistry) { | ||
| StringBuilder warnings = new StringBuilder(); | ||
| ScriptWarning[] values = ScriptWarning.values(); | ||
| for (int i = 0; i < values.length; i++) { | ||
| if (i != 0) { | ||
| warnings.append('|'); | ||
| } | ||
| warnings.append(values[i].ordinal()) | ||
| .append(':') | ||
| .append(values[i].getPattern()); | ||
| } | ||
| syntaxRegistry.register(SyntaxRegistry.SECTION, SyntaxInfo.simple(EffSecSuppressWarnings.class, EffSecSuppressWarnings::new, | ||
| "[local[ly]] [stop:un]suppress [the] (" + warnings + ") warning[s]", | ||
| "[start|:stop] [local[ly]] suppressing [the] (" + warnings + ") warning[s]")); | ||
| } | ||
|
|
||
| private ScriptWarning warning; | ||
| private boolean stop; | ||
|
|
||
| @Override | ||
| public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult, | ||
| @Nullable SectionNode sectionNode, @Nullable List<TriggerItem> triggerItems) { | ||
| ParserInstance parser = getParser(); | ||
| if (!parser.isActive()) { | ||
| Skript.error("You can't suppress warnings outside of a script!"); | ||
| return false; | ||
| } | ||
|
|
||
| warning = ScriptWarning.values()[parseResult.mark]; | ||
| stop = parseResult.hasTag("stop"); | ||
| if (warning.isDeprecated()) { | ||
| Skript.warning(warning.getDeprecationMessage()); | ||
| } | ||
|
|
||
| Script script = parser.getCurrentScript(); | ||
| boolean wasSuppressed = script.suppressesWarning(warning); | ||
| if (stop) { | ||
| script.allowWarning(warning); | ||
| } else { | ||
| script.suppressWarning(warning); | ||
| } | ||
| if (sectionNode != null) { | ||
| loadCode(sectionNode); | ||
| if (wasSuppressed) { | ||
| script.suppressWarning(warning); | ||
| } else { | ||
| script.allowWarning(warning); | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected @Nullable TriggerItem walk(Event event) { | ||
| return walk(event, true); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString(@Nullable Event event, boolean debug) { | ||
| return (stop ? "un" : "") + "suppress " + warning.getWarningName() + " warnings"; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| test "EffSuppressWarnings": | ||
|
|
||
| parse: | ||
| stop | ||
| stop | ||
| assert last parse logs is "Unreachable code. The previous statement stops further execution." | ||
|
|
||
| suppress unreachable code warnings | ||
| parse: | ||
| stop | ||
| stop | ||
| assert last parse logs is not set | ||
| unsuppress unreachable code warnings | ||
|
|
||
| parse: | ||
| stop | ||
| stop | ||
| assert last parse logs is "Unreachable code. The previous statement stops further execution." | ||
|
|
||
| suppress unreachable code warnings: | ||
| parse: | ||
| stop | ||
| stop | ||
| assert last parse logs is not set | ||
|
|
||
| parse: | ||
| stop | ||
| stop | ||
| assert last parse logs is "Unreachable code. The previous statement stops further execution." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.