-
Notifications
You must be signed in to change notification settings - Fork 887
Conversation
Thanks for your interest in palantir/tslint, @ericferreiralife! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericferreiralife thanks! this is a sweet feature 👏
a few requests to tighten up the code and we're g2g.
src/rules/quotemarkRule.ts
Outdated
@@ -37,13 +43,14 @@ export class Rule extends Lint.Rules.AbstractRule { | |||
/* tslint:disable:object-literal-sort-keys */ | |||
public static metadata: Lint.IRuleMetadata = { | |||
ruleName: "quotemark", | |||
description: "Requires single or double quotes for string literals.", | |||
description: "Requires single or double quotes or backticks for string literals.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Enforces quote character for string literals."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
src/rules/quotemarkRule.ts
Outdated
jsxQuoteFromOption[jsxPref] as JSX_QUOTE_MARK : | ||
quoteMark !== "`" ? | ||
quoteMark : | ||
'"', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can all of this logic be moved inside getQuotemarkPreference
and getJSXQuotemarkPreference?
may need another argument, but it will be much more legible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, doing that
src/rules/quotemarkRule.ts
Outdated
const quoteMark = getQuotemarkPreference(args) === OPTION_SINGLE ? "'" : '"'; | ||
const pref = getQuotemarkPreference(args); | ||
const jsxPref = getJSXQuotemarkPreference(args); | ||
const quoteMark = quoteFromOption[pref != undefined ? pref : OPTION_DOUBLE] as QUOTE_MARK; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactor this logic. aiming for simply const quoteMark = getQuotemark(args);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup
src/rules/quotemarkRule.ts
Outdated
} | ||
} | ||
|
||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return the default value instead of nothing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already doing that as part of the refactor
src/rules/quotemarkRule.ts
Outdated
const jsxQuoteFromOption = { | ||
[OPTION_JSX_SINGLE]: "'", | ||
[OPTION_JSX_DOUBLE]: '"', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move these out to static scope
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing that as part of the refactor.
Any updates here? |
Hey @giladgray I pushed those changes you requested. Any follow up? |
This lets users enforce only backtick "`" strings for everywhere that it's permissible. This also simplifies some logic in the preferred quote determination, combining some disparate logic into the nice self-packaged functions. > See #539 > The corresponding option in eslint is called "backtick": http://eslint.org/docs/rules/quotes > See https://ponyfoo.com/articles/template-literals-strictly-better-strings
Any new changes requested here? |
@giladgray @adidahiya can anyone take a look here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Any reason setting the option to EDIT: Nvm the rule just doesn't work at all, not listed as an option on the docs, seems this merged PR didn't actually stay in effect |
@ShayBox let me look into that. This code was committed after the latest release, so it's not included in v5.11.0 |
@ericbf Any idea on next release? Its been while. |
@Jas99 I'm wondering the same thing... @johnwiseheart? |
Likely next week, I’ll try to make a release if I have time.
…On Mon, 10 Dec 2018 at 21:26, Eric Ferreira ***@***.***> wrote:
@Jas99 <https://github.com/jas99> I'm wondering the same thing...
@johnwiseheart <https://github.com/johnwiseheart>?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#4029 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AEEo1LllMJYpEQqDJfbljdpqRwh6FdCgks5u3tF5gaJpZM4VMBoT>
.
|
Still ignores the |
I tried you believe there's a bug in the backtick option (haven't tried it yet myself), opening a new issue would be your best bet. |
In fact, #4402 might be the issue to follow for that one. |
@alexeymrkn I'm not seeing that issue in 5.12.0, backtick works as intended for me. Please file a new issue with more details if your problem persists. |
Actually, I found some issues and confusing behavior with avoid-template and backticks, will try to fix them in #4408 |
I've been using the option with great success in my projects, not in webstorm. Does just putting the option in work for you? Does it just not show up as an option? |
@ericbf It kinda works - it does this to a tsx file for example: It changed my imports, but it did not change my props on components, instead it made them double quotes. Now my imports can't be read lol. (the other backticks were already present) |
Yes, I've seen the behavior on imports. Apparently ECMA only allows single or double quoted strings in imports, not no template literals. I've been putting |
@spencersmb perhaps your editor's TSLint version isn't up-to-date? The dropdown/autocompletion options are auto-generated from the metadata in the rule. Re your imports: that looks like a bug in the rule 😢; would you mind filing a new issue as a bug report? I'm curious about your source code, etc. |
@JoshuaKGoldberg @spencersmb I'll open another issue to refer to the situations where typescript/ecma doesn't like backticks at all. |
Opened #4514 |
@JoshuaKGoldberg @ericbf Thanks for starting that ticket, I added on to it my info. I have to tell webstorm the path to Ts-lint module after I install it via npm so it should be running the latest version. |
This lets users enforce only backtick "`" strings for everywhere that it’s permissible.
PR checklist
Overview of change:
Adds an option "backtick" to "quotemark" rule, which would allow users to enforce "`" only strings where permissible.
CHANGELOG.md entry:
[rule-change], [enhancement]