no-sanitizer-with-danger: Add fixer function #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.
Add fixer function - wrap in wrapperName[0]
Wraps the value of
__html: <value>
to__html: sanitizer(<value>)
. Uses wrapperName[0] as the preferred sanitizer function.Assume the repo has wrapperName[0] (e.g.
sanitizer
) available as a function.Does not auto-import the sanitizer function.
What kind of change does this PR introduce? (check at least one)
Does this PR introduce a breaking change? (check one)
Did you test your solution?
Unit tests written. Problem: tests for the other two rules failing - possibly a node or npm version issue on my end?
Problem Description
Problem: the helper messages are nice but the library does not provide an auto-fixer for developers. We see some value in this as it will disambiguate the error messages by simply solving the issue.
1:
"Dangerous property '{{name}}' without sanitizer found."
This not specify the name of the sanitizer - for a large org or codebase how does the developer know which sanitizer to use? There is potential confusion here.
2:
"Wrapper name is not one of '{{wrapperName}}'.",
While this does help, a developer might take this as a signal to replace the current outermost wrapper instead of wrapping it with the sanitizer (the intended behaviour).
Here is the scenario:
Developer thinks he should replace
__html: textFormatterFunctionNotRelatedToSanitization(<value>)
with__html: sanitizer(<value>)
.Solution Description
Replaces this:
with this:
Side Effects, Risks, Impact
This is my first FOSS PR.