Skip to content

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

Merged
merged 2 commits into from
Aug 15, 2017

Conversation

armano2
Copy link
Contributor

@armano2 armano2 commented Aug 13, 2017

This PR implements rule proposed in #150.

@armano2 armano2 force-pushed the curly-bracket-spacing branch from 587a32f to 435e9d0 Compare August 13, 2017 22:22
@armano2 armano2 changed the title Add rule curly-bracket-spacing. Add curly-bracket-spacing rule. Aug 13, 2017
Copy link
Member

@mysticatea mysticatea left a 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.

@@ -0,0 +1,67 @@
# Enforce spacing on the style of curly brackets. (curly-bracket-spacing)
Copy link
Member

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?

Copy link
Contributor Author

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.


```html
<template>
<div>{{ text }}</div>
Copy link
Member

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>',
Copy link
Member

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.

Copy link
Contributor Author

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']
}
Copy link
Member

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?

Copy link
Contributor Author

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

@armano2
Copy link
Contributor Author

armano2 commented Aug 14, 2017

@mysticatea suggestion requested in code review applied,
i also renamed this rule to mustache-curly-spacing

@armano2 armano2 changed the title Add curly-bracket-spacing rule. Add mustache-curly-spacing rule. Aug 14, 2017

Unverified

This user has not yet uploaded their public signing key.
fixes vuejs#150
@armano2 armano2 force-pushed the curly-bracket-spacing branch from cf083cb to 48107fb Compare August 14, 2017 09:56
Copy link
Member

@mysticatea mysticatea left a 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!

@@ -0,0 +1,67 @@
# Enforce spacing on the style of mustache curly brackets. (mustache-curly-spacing)
Copy link
Member

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 ?

Copy link
Contributor Author

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.


## :book: Rule Details

This rule aims to enforce unified spacing of curly brackets.
Copy link
Member

Choose a reason for hiding this comment

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

in mustache interpolations

module.exports = {
meta: {
docs: {
description: 'Enforce spacing on the style of mustache curly brackets.',
Copy link
Member

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

filter: token => token.type !== 'HTMLWhitespace' // When there is only whitespace between ignore it
})

const startToken = tokens.shift()
Copy link
Member

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.

Copy link
Contributor Author

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

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)) {
Copy link
Member

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) {

Unverified

This user has not yet uploaded their public signing key.
@armano2
Copy link
Contributor Author

armano2 commented Aug 15, 2017

@michalsnik suggestions applied, thank you for code review.

@michalsnik michalsnik merged commit 4c97f17 into vuejs:master Aug 15, 2017
@armano2 armano2 deleted the curly-bracket-spacing branch August 15, 2017 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants