Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Add rule: strict-string-expressions #4807

Merged
merged 27 commits into from
Aug 12, 2019

Conversation

ColCh
Copy link
Contributor

@ColCh ColCh commented Jul 22, 2019

PR checklist

Overview of change:

adds implementation for rule discussed in #4512

Is there anything you'd like reviewers to focus on?

CHANGELOG.md entry:

[new-rule] strict-string-expressions reports errors on type coercions found in string expressions

@ColCh ColCh changed the title Add rule: strict-string-expressions [DO NOT REVIEW] Add rule: strict-string-expressions Jul 22, 2019
@ColCh ColCh changed the title [DO NOT REVIEW] Add rule: strict-string-expressions Add rule: strict-string-expressions Jul 22, 2019
@JoshuaKGoldberg
Copy link
Contributor

@ColCh looks like you've got some lint failures from CI running this rule on TSLint itself. https://circleci.com/gh/palantir/tslint/16921?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

That looks like it's exposed an edge case or two. Should | null and | undefined be allowed in string expressions? I think so; it's common for error logging to have strings like:

function complain(error?: Error | null) {
    console.error(`Oh dear: ${error}`);
}

new Error().stack being string | undefined is also pretty annoying.

If you really wanted, you could make an issue to add an option to disallow this, or file a followup issue after this PR... but IMO it's fine to just always allow these.

@ColCh
Copy link
Contributor Author

ColCh commented Jul 28, 2019

Yes, I agree with you. That undefined in union as well as other empty-in-runtime values like never or null creates so much problems :D

I think that better option is make those as configurable thing

@@ -187,7 +187,7 @@ export class Linter {
this.options.formatter !== undefined ? this.options.formatter : "prose";
const Formatter = findFormatter(formatterName, this.options.formattersDirectory);
if (Formatter === undefined) {
throw new Error(`formatter '${formatterName}' not found`);
throw new Error(`formatter '${String(formatterName)}' not found`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

real case here 🎉
image

@ColCh
Copy link
Contributor Author

ColCh commented Jul 28, 2019

@JoshuaKGoldberg seems to pass now

I don't understand why ci/circleci: testNext is failing but it's failing in master branch too

Screenshot 2019-07-28 at 22 09 03

so... please review :)

Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for pushing this through @ColCh! (and the helpful PR comments!)

@JoshuaKGoldberg JoshuaKGoldberg merged commit 05cfde7 into palantir:master Aug 12, 2019
@ColCh
Copy link
Contributor Author

ColCh commented Aug 12, 2019

Thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule suggestion: strict-string-expressions (no implicit function to string)
2 participants