hmil/tslint-override

Angular like syntax - @Override()

wSedlacek opened this issue · 2 comments

In Angular, and NestJS (which is Angular like) decorators use the syntax of @Decorator() instead of @decorator and is on it's own line above the class member it is modifying. From my research this is the legacy es7 proposal decorator styling, never the less Angular is still using this styling so it would be nice if tslint-ovrride would offer an option for this styling.

I have made a modified version of register.ts to allow this when parsing without issue however in addition to this I would like the option to fix any errors using this same styling rather then in a comment.

I do see #18 added support for @Override, I presume adding support for this Angular like syntax would just be an extension of the changes made in that pull request.

angular-register.ts

declare var global: any;
declare global {
  /**
   * Specifies that this member must override a parent member.
   */
  const Override: () => (
    _target: any,
    _propertyKey: string,
    _descriptor?: PropertyDescriptor
  ) => void;

  interface Window {
    Override: (_target: any, _propertyKey: string, _descriptor?: PropertyDescriptor) => void;
  }

  namespace NodeJS {
    interface Global {
      Override: () => (
        _target: any,
        _propertyKey: string,
        _descriptor?: PropertyDescriptor
      ) => void;
    }
  }
}

export const ctx = typeof window !== 'undefined' ? window : global;

/**
 * Specifies that this member must override a parent member.
 */
export function Override(_target: any, _propertyKey: string, _descriptor?: PropertyDescriptor) {
  // noop
}

ctx.Override = () => Override;

Usage:

@Override()
public ngOnInit() {}
hmil commented

Good idea. Would you like to submit a PR to add angular-register.ts?

You can get the fixer pretty close to where you want to go with this config:

"explicit-override": [ true, "decorator", "pascal-case-fixer", "new-line-after-decorators-and-tags" ]

However, there are currently no options to automatically add the parenthesis after the decorator but it could easily be added.

Had a busy holiday, but I got this PR created for angular-register.ts