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 rule: strict-string-expressions #4807

Merged
merged 27 commits into from Aug 12, 2019

Conversation

@ColCh
Copy link
Contributor

commented Jul 22, 2019

PR checklist

  • Addresses an existing issue: fixes #4512
  • New feature, bugfix, or enhancement
    • Includes tests
  • Documentation update ???

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

This comment has been minimized.

Copy link
Collaborator

commented Jul 27, 2019

@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

This comment has been minimized.

Copy link
Contributor Author

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`);

This comment has been minimized.

Copy link
@ColCh

ColCh Jul 28, 2019

Author Contributor

real case here 🎉
image

@ColCh

This comment has been minimized.

Copy link
Contributor Author

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
Collaborator

left a comment

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

@JoshuaKGoldberg JoshuaKGoldberg merged commit 05cfde7 into palantir:master Aug 12, 2019
13 of 14 checks passed
13 of 14 checks passed
ci/circleci: testNext Your tests failed on CircleCI
Details
ci/circleci: build Your tests passed on CircleCI!
Details
ci/circleci: checkout-code Your tests passed on CircleCI!
Details
ci/circleci: clean-lockfile Your tests passed on CircleCI!
Details
ci/circleci: lint Your tests passed on CircleCI!
Details
ci/circleci: test Your tests passed on CircleCI!
Details
ci/circleci: test2.1 Your tests passed on CircleCI!
Details
ci/circleci: test2.4 Your tests passed on CircleCI!
Details
ci/circleci: test2.7 Your tests passed on CircleCI!
Details
ci/circleci: test2.8 Your tests passed on CircleCI!
Details
ci/circleci: test2.9 Your tests passed on CircleCI!
Details
ci/circleci: test3.0 Your tests passed on CircleCI!
Details
ci/circleci: testRc Your tests passed on CircleCI!
Details
cla/palantir CLA signed on 2019-02-03 09:26 UTC+00:00
Details
@ColCh

This comment has been minimized.

Copy link
Contributor Author

commented Aug 12, 2019

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.