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

quotemark: Add 'no-template' option #2766

Merged
merged 2 commits into from May 14, 2017
Merged

Conversation

andy-hanson
Copy link
Contributor

@andy-hanson andy-hanson commented May 14, 2017

PR checklist

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

Overview of change:

Adds the no-template option, which forbids single-line template literals with no interpolation.
Still allows tagged tempates and templates with interpolation.
Allows them if they contain both " and ', otherwise corrects to some kind of quote.

CHANGELOG.md entry:

[new-rule-option] quotemark: Add avoid-template option

true,
"double",
"avoid-escape",
"no-template",
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to avoid-template since some templates are allowed

@@ -44,6 +47,7 @@ export class Rule extends Lint.Rules.AbstractRule {
* \`"${OPTION_DOUBLE}"\` enforces double quotes.
* \`"${OPTION_JSX_SINGLE}"\` enforces single quotes for JSX attributes.
* \`"${OPTION_JSX_DOUBLE}"\` enforces double quotes for JSX attributes.
* \`"${OPTION_NO_TEMPLATE}"\` forbids single-line template strings that do not contain string interpolations.
Copy link
Contributor

Choose a reason for hiding this comment

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

also "untagged"

});
}

function isMultiLine(node: ts.Node, sourceFile: ts.SourceFile): boolean {
return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line !==
Copy link
Contributor

Choose a reason for hiding this comment

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

you can avoid that boilerplate code by using tsutils.isSameLine

return !isSameLine(sourceFile, node.getStart(sourceFile), node.end);

const { sourceFile, options } = ctx;
ts.forEachChild(sourceFile, function cb(node) {
if (isStringLiteral(node)
|| isNoSubstitutionTemplateLiteral(node)
Copy link
Contributor

Choose a reason for hiding this comment

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

needs to check if the option is set

@nchen63 nchen63 merged commit 13cf172 into palantir:master May 14, 2017
@andy-hanson andy-hanson deleted the no-template branch May 14, 2017 20:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants