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

Entire switch case missed if testing string literal #47

Closed
nator opened this issue May 24, 2021 · 2 comments · Fixed by #56
Closed

Entire switch case missed if testing string literal #47

nator opened this issue May 24, 2021 · 2 comments · Fixed by #56

Comments

@nator
Copy link

nator commented May 24, 2021

I think this is caused by the fix for #2 , where switch cases statements with a literal test cause the entire block to be skipped. I have code like this that I'd like to fail the linter, but I don't quite see how to fix it and still keep #2 intact.

e.g. this title assignment shouldn't be allowed:

    switch (task.state) {
        case kTaskState_InProgress:
            style = classes.inProgress;
            title = "In Progress"
            break;

Thanks!

@nator
Copy link
Author

nator commented May 25, 2021

I'm wrong, it's not skipping the body of the case statement. It seems like this test in no-literal-string.js might be ignoring "normal" assignment:

        // var a: 'abc' = 'abc'
        if (typeObj.isStringLiteral()) {
          return;
        }

With that statement this second assignment is allowed, IMO it shouldn't be:

let title: string = i18next.t('common:test')
title = "omg lol"

I'm afraid I don't understand typescript well enough yet to know which is wrong or what the right fix is :(

@edvardchen
Copy link
Owner

@nator it's weird. I will check on it

edvardchen added a commit that referenced this issue Aug 22, 2021
edvardchen added a commit that referenced this issue Aug 22, 2021
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 a pull request may close this issue.

2 participants