- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 681
Add mustache-curly-spacing
rule.
#153
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
Conversation
587a32f
to
435e9d0
Compare
curly-bracket-spacing
.curly-bracket-spacing
rule.
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.
Thank you for contributing!!
I have some concerns, please check those.
docs/rules/curly-bracket-spacing.md
Outdated
@@ -0,0 +1,67 @@ | |||
# Enforce spacing on the style of curly brackets. (curly-bracket-spacing) |
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.
I think that curly-bracket
has too wide meaning. There are object-curly-spacing
, template-curly-spacing
, and block-spacing
in core. How about mustache-curly-spacing
or embedded-expression-curly-spacing
?
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.
i prefer mustache-curly-spacing
.
docs/rules/curly-bracket-spacing.md
Outdated
|
||
```html | ||
<template> | ||
<div>{{ text }}</div> |
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.
It looks a correct code to me. It should be covered by no-multi-spaces
rule.
invalid: [ | ||
{ | ||
filename: 'test.vue', | ||
code: '<template><div>{{ }}</div></template>', |
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.
I think that this rule should ignore mustaches which have syntax errors. If syntax errors exist, node.expression
is null
.
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.
ok
filename: 'test.vue', | ||
code: '<template><div>{{ text }}</div></template>', | ||
options: ['always'] | ||
} |
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.
Could you add tests which confirm that this rule doesn't warn directives, especially directives with unquoted attributes?
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.
@mysticatea yup there was issue here, i forgot to check types of startToken
and endToken
@mysticatea suggestion requested in code review applied, |
curly-bracket-spacing
rule.mustache-curly-spacing
rule.
cf083cb
to
48107fb
Compare
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, thank you very much!
docs/rules/mustache-curly-spacing.md
Outdated
@@ -0,0 +1,67 @@ | |||
# Enforce spacing on the style of mustache curly brackets. (mustache-curly-spacing) |
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.
Regarding rule name I have another proposition: mustache-interpolation-spacing
. We all know what interpolation is, plus mustache interpolation type is well described in official documentation - this way we should avoid any confusion. What do you think @armano2 @mysticatea ?
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.
@michalsnik I was not sure about the name of this rule, there was many suggestions like: curly-bracket, mustache-curly-spacing, embedded-expression-curly-spacing but i think yours matches at least documentation.
docs/rules/mustache-curly-spacing.md
Outdated
|
||
## :book: Rule Details | ||
|
||
This rule aims to enforce unified spacing of curly brackets. |
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.
in mustache interpolations
lib/rules/mustache-curly-spacing.js
Outdated
module.exports = { | ||
meta: { | ||
docs: { | ||
description: 'Enforce spacing on the style of mustache curly brackets.', |
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.
enforce unified spacing in mustache interpolations
lib/rules/mustache-curly-spacing.js
Outdated
filter: token => token.type !== 'HTMLWhitespace' // When there is only whitespace between ignore it | ||
}) | ||
|
||
const startToken = tokens.shift() |
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.
Do you intentionally mutate tokens
here? Using that kind of methods usually introduce more confusion and may lead to unexpected results.
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.
Yes, i'm taking first and last token from array, checking their types, and i'm using it to compare
lib/rules/mustache-curly-spacing.js
Outdated
function checkTokens (leftToken, rightToken) { | ||
if (leftToken.loc.end.line === rightToken.loc.start.line) { | ||
const spaces = rightToken.loc.start.column - leftToken.loc.end.column | ||
if (optSpaces === (spaces === 0)) { |
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.
Don't you think this expression is hard to read?
Can you please keep it simple stupid?
const noSpacesFound = spaces === 0
if (optSpaces && noSpacesFound) {
@michalsnik suggestions applied, thank you for code review. |
This PR implements rule proposed in #150.