<commit_before>import * as React from 'react';
import { List } from 'rc-field-form';
import { StoreValue } from 'rc-field-form/lib/interface';
import devWarning from '../_util/devWarning';
import { ConfigContext } from '../config-provider';
import { FormItemPrefixContext } from './context';

export interface FormListFieldData {
  name: number;
  key: number;
  fieldKey: number;
}

export interface FormListOperation {
  add: (defaultValue?: StoreValue, insertIndex?: number) => void;
  remove: (index: number | number[]) => void;
  move: (from: number, to: number) => void;
}

export interface FormListProps {
  prefixCls?: string;
  name: string | number | (string | number)[];
  children: (
    fields: FormListFieldData[],
    operation: FormListOperation,
    meta: { errors: React.ReactNode[] },
  ) => React.ReactNode;
}

const FormList: React.FC<FormListProps> = ({
  prefixCls: customizePrefixCls,
  children,
  ...props
}) => {
  devWarning(!!props.name, 'Form.List', 'Miss `name` prop.');

  const { getPrefixCls } = React.useContext(ConfigContext);
  const prefixCls = getPrefixCls('form', customizePrefixCls);

  return (
    <List {...props}>
      {(fields, operation, meta) => {
        return (
          <FormItemPrefixContext.Provider value={{ prefixCls, status: 'error' }}>
            {children(
              fields.map(field => ({ ...field, fieldKey: field.key })),
              operation,
              {
                errors: meta.errors,
              },
            )}
          </FormItemPrefixContext.Provider>
        );
      }}
    </List>
  );
};

export default FormList;
<commit_msg>fix: add optional rules property (#27164)<commit_after>import * as React from 'react';
import { List } from 'rc-field-form';
import { ValidatorRule, StoreValue } from 'rc-field-form/lib/interface';
import devWarning from '../_util/devWarning';
import { ConfigContext } from '../config-provider';
import { FormItemPrefixContext } from './context';

export interface FormListFieldData {
  name: number;
  key: number;
  fieldKey: number;
}

export interface FormListOperation {
  add: (defaultValue?: StoreValue, insertIndex?: number) => void;
  remove: (index: number | number[]) => void;
  move: (from: number, to: number) => void;
}

export interface FormListProps {
  prefixCls?: string;
  name: string | number | (string | number)[];
  rules?: ValidatorRule[];
  children: (
    fields: FormListFieldData[],
    operation: FormListOperation,
    meta: { errors: React.ReactNode[] },
  ) => React.ReactNode;
}

const FormList: React.FC<FormListProps> = ({
  prefixCls: customizePrefixCls,
  children,
  ...props
}) => {
  devWarning(!!props.name, 'Form.List', 'Miss `name` prop.');

  const { getPrefixCls } = React.useContext(ConfigContext);
  const prefixCls = getPrefixCls('form', customizePrefixCls);

  return (
    <List {...props}>
      {(fields, operation, meta) => {
        return (
          <FormItemPrefixContext.Provider value={{ prefixCls, status: 'error' }}>
            {children(
              fields.map(field => ({ ...field, fieldKey: field.key })),
              operation,
              {
                errors: meta.errors,
              },
            )}
          </FormItemPrefixContext.Provider>
        );
      }}
    </List>
  );
};

export default FormList;

{'fraction_non_alphanumeric': 0.14837153196622438, 'fraction_numerical': 0.0015078407720144752, 'mean_word_length': 2.9535160905840288, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4199737', 'n_tokens_mistral': 990, 'n_tokens_neox': 981, 'n_words': 242}