microsoft / tslint-microsoft-contrib

A set of TSLint rules used on some Microsoft projects.
MIT License
702 stars 198 forks source link

React UNSAFE_ methods not passing #887

Closed JohnPhamous closed 5 years ago

JohnPhamous commented 5 years ago

Bug Report

TypeScript code being linted

public UNSAFE_componentWillReceiveProps(nextProps: IOnboardReleaseFormProps): void {
   ...
  }

Actual behavior

Throws this error: Method name does not match /^[a-z][\w\d]+$/: UNSAFE_componentWillReceiveProps (function-name)

Expected behavior

React 16.9.0 added UNSAFE_* methods. The regex currently being used doesn't allow for the UNSAFE_ prefix.

Proposed Changes

Not sure how yall want to handle this since it's a library dependent change. What do yall think of changing the regex to ([a-z]|UNSAFE)[\w\d]+?

JoshuaKGoldberg commented 5 years ago

👋 @JohnPhamous good idea! Fortunately, the function-name rule supports overriding the regular expressions used already:

https://github.com/microsoft/tslint-microsoft-contrib/blob/bfc28e95dde1fab92aa457e79d338fb03b81d7cc/src/functionNameRule.ts#L73