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

Commit

Permalink
Fix #4514: [quotemark: backtick] Incorrectly flags string literals th…
Browse files Browse the repository at this point in the history
…at must use single/double quotes (#4535)

* Fix #4514

* make comment more specific

* lint fixes
  • Loading branch information
rrogowski authored and Josh Goldberg committed Feb 24, 2019
1 parent 1c400fb commit 7100fe9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/rules/quotemarkRule.ts
Expand Up @@ -14,8 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { isNoSubstitutionTemplateLiteral, isSameLine, isStringLiteral } from "tsutils";
import {
isImportDeclaration,
isNoSubstitutionTemplateLiteral,
isPropertyAssignment,
isSameLine,
isStringLiteral,
} from "tsutils";
import * as ts from "typescript";

import * as Lint from "../index";
Expand Down Expand Up @@ -122,6 +127,14 @@ function walk(ctx: Lint.WalkContext<Options>) {
: options.quotemark;
const actualQuotemark = sourceFile.text[node.end - 1];

// Don't use backticks instead of single/double quotes when it breaks TypeScript syntax.
if (
expectedQuotemark === "`" &&
(isImportDeclaration(node.parent) || isPropertyAssignment(node.parent))
) {
return;
}

if (actualQuotemark === expectedQuotemark) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions test/rules/quotemark/backtick/test.ts.fix
@@ -1,3 +1,5 @@
import { Something } from "some-package"

var single = `single`;
var double = `married`;
var singleWithinDouble = `'singleWithinDouble'`;
Expand All @@ -7,3 +9,5 @@ var tabNewlineWithinSingle = `tab\tNewline\nWithinSingle`;

// "avoid-template" option is not set.
`foo`;

const object = { "kebab-case": 3 }
4 changes: 4 additions & 0 deletions test/rules/quotemark/backtick/test.ts.lint
@@ -1,3 +1,5 @@
import { Something } from "some-package"

var single = 'single';
~~~~~~~~ [' should be `]
var double = "married";
Expand All @@ -13,3 +15,5 @@ var tabNewlineWithinSingle = 'tab\tNewline\nWithinSingle';

// "avoid-template" option is not set.
`foo`;

const object = { "kebab-case": 3 }

0 comments on commit 7100fe9

Please sign in to comment.