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

Not support groupByDecorator for method type #69

Open
lordantonelli opened this issue Sep 6, 2021 · 4 comments
Open

Not support groupByDecorator for method type #69

lordantonelli opened this issue Sep 6, 2021 · 4 comments

Comments

@lordantonelli
Copy link

The groupByDecorator is only available to property type, but I can define decorator on method too:

class Sample {
  
   @HostListener('window:resize', ['$event'])
   onResize(): void {
      ...
   }

  @Input() set class(value: string) {
    ....
  }
}

Is it possible to configure lint for this case?

@charles-allen
Copy link

charles-allen commented Oct 2, 2021

Firstly, thanks to Bryan for making this plugin!

I'm sharing another example use case for this issue & my work-around... I'm trying to use this rule with vue-class-component. Goal:

export default class MyComponent extends Vue {
  // Interface
  @Prop() propExample!: number
  @Emit() emitExample (): number { return 123 }

  // State
  localExample = 123
  get getterExample (): number { return 123 }

  // Lifecycle
  mounted (): void { ... }
  @Watch('localExample') onLocalChange (): void { ... }

  // Methods
  methodExample (...): number { ... }

Currently the @Emit & @Watch cases aren't possible. I am using the following convention as a work-around:

  • All @Emit methods are prefixed emit
  • All @Watch methods are prefixed on

...then use this configuration:

    'sort-class-members/sort-class-members': [
      'error',
      {
        order: [
          '[static-properties]',
          '[static-methods]',
          '[injects]',
          '[provides]',
          '[props]',
          '[emits]',
          '[properties]',
          '[getters]',
          '[setters]',
          'constructor',
          '[vue-before-create]',
          '[vue-created]',
          '[vue-before-mount]',
          '[vue-mounted]',
          '[vue-before-update]',
          '[vue-updated]',
          '[vue-before-unmount]',
          '[vue-unmounted]',
          '[vue-error-captured]',
          '[vue-render-tracked]',
          '[vue-render-triggered]',
          '[vue-activated]',
          '[watches]',
          '[methods]'
        ],
        groups: {
          injects: [{ groupByDecorator: 'Inject', type: 'property' }],
          provides: [{ groupByDecorator: 'Provide', type: 'property' }],
          props: [{ groupByDecorator: 'Prop', type: 'property' }],
          emits: [{ name: '/emit.+/', type: 'method' }],
          getters: [{ type: 'method', kind: 'get' }],
          setters: [{ type: 'method', kind: 'set' }],
          watches: [{ name: '/on.+/', type: 'method' }],
          'vue-before-create': [{ name: 'beforeCreate', type: 'method' }],
          'vue-created': [{ name: 'created', type: 'method' }],
          'vue-before-mount': [{ name: 'beforeMount', type: 'method' }],
          'vue-mounted': [{ name: 'mounted', type: 'method' }],
          'vue-before-update': [{ name: 'beforeUpdate', type: 'method' }],
          'vue-updated': [{ name: 'updated', type: 'method' }],
          'vue-activated': [{ name: 'activated', type: 'method' }],
          'vue-deactivated': [{ name: 'deactivated', type: 'method' }],
          'vue-before-unmount': [{ name: 'beforeUnmount', type: 'method' }],
          'vue-unmounted': [{ name: 'unmounted', type: 'method' }],
          'vue-error-captured': [{ name: 'errorCaptured', type: 'method' }],
          'vue-render-tracked': [{ name: 'renderTracked', type: 'method' }],
          'vue-render-triggered': [{ name: 'renderTriggered', type: 'method' }]
        },
        accessorPairPositioning: 'getThenSet'
      }
    ]

Hope it helps or inspires someone :)

@charles-allen
Copy link

charles-allen commented Oct 2, 2021

@lordantonelli - Probably not perfect, but you can get somewhere with this:

groups: {
  setters: [{ type: 'method', kind: 'set' }], // @Input
  [lifecycle-events]: [{ name: '/on.+/', type: 'method' }], // @HostListener
},

@ArnaudWeyts
Copy link
Contributor

Hi, I've opened a PR here to support both types: #80

@dospunk
Copy link
Contributor

dospunk commented Apr 19, 2023

Since #80 has been merged and published, can this issue be closed?

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

No branches or pull requests

4 participants