function checkSorted(declarations) {
      // Declarations will be `undefined` if the `shape` is not a literal. For
      // example, if it is a propType imported from another file.
      if (!declarations) {
        return;
      }

      function fix(fixer) {
        return propTypesSortUtil.fixPropTypesSort(
          context,
          fixer,
          declarations,
          ignoreCase,
          requiredFirst,
          callbacksLast,
          noSortAlphabetically,
          sortShapeProp,
          checkTypes
        );
      }

      const callbackPropsLastSeen = new WeakSet();
      const requiredPropsFirstSeen = new WeakSet();
      const propsNotSortedSeen = new WeakSet();

      declarations.reduce((prev, curr, idx, decls) => {
        if (curr.type === 'ExperimentalSpreadProperty' || curr.type === 'SpreadElement') {
          return decls[idx + 1];
        }

        let prevPropName = getKey(context, prev);
        let currentPropName = getKey(context, curr);
        const previousIsRequired = propTypesSortUtil.isRequiredProp(prev);
        const currentIsRequired = propTypesSortUtil.isRequiredProp(curr);
        const previousIsCallback = propTypesSortUtil.isCallbackPropName(prevPropName);
        const currentIsCallback = propTypesSortUtil.isCallbackPropName(currentPropName);

        if (ignoreCase) {
          prevPropName = String(prevPropName).toLowerCase();
          currentPropName = String(currentPropName).toLowerCase();
        }

        if (requiredFirst) {
          if (previousIsRequired && !currentIsRequired) {
            // Transition between required and non-required. Don't compare for alphabetical.
            return curr;
          }
          if (!previousIsRequired && currentIsRequired) {
            // Encountered a non-required prop after a required prop
            if (!requiredPropsFirstSeen.has(curr)) {
              requiredPropsFirstSeen.add(curr);
              report(context, messages.requiredPropsFirst, 'requiredPropsFirst', {
                node: curr,
                fix,
              });
            }
            return curr;
          }
        }

        if (callbacksLast) {
          if (!previousIsCallback && currentIsCallback) {
            // Entering the callback prop section
            return curr;
          }
          if (previousIsCallback && !currentIsCallback) {
            // Encountered a non-callback prop after a callback prop
            if (!callbackPropsLastSeen.has(prev)) {
              callbackPropsLastSeen.add(prev);
              report(context, messages.callbackPropsLast, 'callbackPropsLast', {
                node: prev,
                fix,
              });
            }
            return prev;
          }
        }

        if (!noSortAlphabetically && currentPropName < prevPropName) {
          if (!propsNotSortedSeen.has(curr)) {
            propsNotSortedSeen.add(curr);
            report(context, messages.propsNotSorted, 'propsNotSorted', {
              node: curr,
              fix,
            });
          }
          return prev;
        }

        return curr;
      }, declarations[0]);
    }
Checks if propTypes declarations are sorted
@param {Array} declarations The array of AST nodes being checked.
@returns {void}