Skip to content
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

Rule Proposal: New-lines between multi-line properties #391

Closed
justincscott16 opened this issue Feb 16, 2018 · 4 comments
Closed

Rule Proposal: New-lines between multi-line properties #391

justincscott16 opened this issue Feb 16, 2018 · 4 comments

Comments

@justincscott16
Copy link

justincscott16 commented Feb 16, 2018

Please describe what the rule should do:

Enforce new lines between multi-line properties in Vue components.

What category of rule is this? (place an "X" next to just one item)

[x] Enforces code style
[ ] Warns about a potential error
[ ] Suggests an alternate way of doing something
[ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

// Good! - easy to find where new properties begin.

name: 'component-name',
props: {
  value: {
    type: String,
    required: true
  },

  focused: {
    type: Boolean,
    default: false
  },

  label: String,
  icon: String
},

computed: {
  formattedValue: function () {
    // ...
    // ...
    // ...
    // ...
  },

  inputClasses: function () {
    // ...
    // ...
    // ...
    // ...
  }
},

methods: {
  methodA: function () {
    // ...
    // ...
    // ...
  },

  methodB: function () {
    // ...
    // ...
    // ...
  }
}

// Bad - hard to read when they are long properties and all crammed together.

name: 'component-name',
props: {
  value: {
    type: String,
    required: true
  },

  focused: {
    type: Boolean,
    default: false
  },

  label: String,
  icon: String
},
computed: {
  formattedValue: function () {
    // ...
    // ...
    // ...
    // ...
  },

  inputClasses: function () {
    // ...
    // ...
    // ...
    // ...
  }
},
methods: {
  methodA: function () {
    // ...
    // ...
    // ...
  },

  methodB: function () {
    // ...
    // ...
    // ...
  }
}

Why should this rule be included in ESLint (instead of a plugin)?

The Vue docs suggest to add new lines between multi-line properties to help readability (and navigation in some cases) of the code. It is flagged in the docs as recommended, and I believe as a code style and way to make components consistent, it would make sense to be in Priority C - Recommended ruleset.

@justincscott16 justincscott16 changed the title Rule Proposal: Rule Proposal: New-lines between multi-line properties Feb 16, 2018
@chrisvfritz
Copy link
Contributor

Only note to add here is that I think autofix is an important feature so that the rule doesn't become very annoying. 😄

@IWANABETHATGUY
Copy link
Contributor

if a multiline property next to a singleline property, need this rule to report anything?
e.g.

export default {
  data() {
  },
  methods: {}
}

@silencerspirit
Copy link

Someone found a solution? In particular interested methods...

@IWANABETHATGUY
Copy link
Contributor

Someone found a solution? In particular interested methods...
#1080 this pull request is during the final step to merge into master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants