Skip to content
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 quick fix for S3696 ('no-throw-literal') #3050

Merged
merged 2 commits into from
Mar 17, 2022
Merged

Conversation

yassin-kammoun-sonarsource
Copy link
Contributor

Fixes #3017

const thrownText = context.getSourceCode().getText(thrown);
suggest.push({
desc: 'Throw an error object',
fix: fixer => fixer.replaceText(thrown, `new Error(${thrownText})`),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's more reliable to use insertTextAfter and insertTextBefore instead of context.getSourceCode().getText(). WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to say... I propose we keep it like this for now. If we manage to break the fix during validation, depending on the problem, we can then try those methods.

@sonarsource-next
Copy link

@vilchik-elena vilchik-elena merged commit 9b43dfb into master Mar 17, 2022
@vilchik-elena vilchik-elena deleted the issue-3017 branch March 17, 2022 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add quick fix for S3696: Literals should not be thrown
2 participants