close

static-property-placement

Unreleased

Configuration

rslint.config.ts
import { defineConfig, reactPlugin } from '@rslint/core';

export default defineConfig([
  reactPlugin.configs.recommended,
  {
    rules: {
      'react/static-property-placement': 'error',
    },
  },
]);

Enforce where React component static properties are declared in an ES6 class.

The rule checks childContextTypes, contextTypes, contextType, defaultProps (including legacy getDefaultProps), displayName, and propTypes. The default placement is static public field.

Component detection follows eslint-plugin-react, including settings.react.pragma, file-level @jsx comments, and adjacent JSDoc @extends React.Component or @augments React.PureComponent markers. For class expressions assigned to a variable, put the JSDoc before the variable declaration:

/** @extends React.Component */
const Component = class {
  static propTypes = {};
};

Options

The first option selects the default placement:

  • static public fieldstatic propTypes = {...}
  • static getterstatic get propTypes() {...}
  • property assignmentMyComponent.propTypes = {...} outside the class

The second option is an object that overrides the placement for individual properties. Unspecified properties use the first option.

["property assignment", {"displayName": "static public field"}]

Original Documentation