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

[quotemark: backtick] Incorrectly flags string literals in export line #4588

Closed
ericbf opened this issue Mar 20, 2019 · 2 comments · Fixed by #4618
Closed

[quotemark: backtick] Incorrectly flags string literals in export line #4588

ericbf opened this issue Mar 20, 2019 · 2 comments · Fixed by #4618

Comments

@ericbf
Copy link
Contributor

ericbf commented Mar 20, 2019

Bug Report

TypeScript code being linted

export * from "./some-module"

with tslint.json configuration:

{
    "rules": {
        "quotemark": "backtick"
    }
}

Actual behavior

The quotes get flagged (and changed to backticks if fix is enabled).

Expected behavior

The quotes should remain as double/single quotes, as typescript/ecma doesn't allow backticks here.

@ericbf
Copy link
Contributor Author

ericbf commented Mar 29, 2019

Here's another example:

Code being linted

const array: SomeType<string, "hello"> = []
const obj: {
	"kebab-case": string
} = {
	"kebab-case": "value"
}

Actual behavior

const array: SomeType<string, "hello"> = []
//                            ~~~~~~~ [" should be `]
const obj: {
	"kebab-case": string
//      ~~~~~~~~~~~~ [" should be `]
} = {
	"kebab-case": "value"
}

Expected behavior

const array: SomeType<string, "hello"> = []
const obj: {
	"kebab-case": string
} = {
	"kebab-case": "value"
//                    ~~~~~~~ [" should be `]
}

Problem summary

  1. The fixing/flagging here flags some things that when changed breaks typescript syntax and doesn't flag other instances where it should be flagged.
  2. Typescript required that the string literal type passed to the generic type be single/double, but the implementation of the backtick rule does not make that distinction. Seems that node doesn't have a clear-cut type though to exclude it.
  3. For the type definition, the kebab case property name has to remain single/double quotes, or typescript breaks as well. What is the associated node type there? Mucking in the code trying to PR for this, seems that the type definition property name here doesn't have a clean-cut node type either.
  4. The string literal in the property value assignment is not flagged, but it should. Seems that looking at the parent node ("kebab-case": "value") gives you "PropertyAssignment" for both the property key and the property value, while the key should be ignored in this case, the value should not. How would one implement this part when they don't have their own node types?

@ericbf
Copy link
Contributor Author

ericbf commented Mar 29, 2019

Actually, I think I got something. PR soon.

JoshuaKGoldberg pushed a commit that referenced this issue Mar 31, 2019
This commit fixes the cases where export statements, string literal type as generic type parameter, and string literals in object literal property assignments were incorrectly flagged. This also fixes a small lint error (specifying a type parameter same as default).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants