<commit_before>import transformProperties from './helpers/transformProperties';
import createTypeAlias from './helpers/createTypeAlias';
import findParentBody from './helpers/findParentBody';
import annotateConstructor from './helpers/annotateConstructor';
import findIndex from './helpers/findIndex';

export default function transformer(file, api) {
  const j = api.jscodeshift;
  const {expression, statement, statements} = j.template;
  let root = j(file.source);

  const isStaticPropType = (p) => {
    return p.type === 'ClassProperty' &&
      p.static &&
      p.key.type === 'Identifier' &&
      p.key.name === 'propTypes';
  };

  // find classes
  return root.find(j.ClassDeclaration)
    .forEach(p => {
      // find classes with propType static class property
      if (p.value.body && p.value.body.body) {
         const index = findIndex(p.value.body.body, isStaticPropType)
         if (typeof index !== 'undefined') {
           const classProperty = p.value.body.body.splice(index, 1).pop();
           const typeAlias = createTypeAlias(
             j, transformProperties(j, classProperty.value.properties), {
               shouldExport: true
           });

           // find parent
           const {
             child,
             body,
           } = findParentBody(p);
           if (body && child) {
             const bodyIndex = findIndex(body.value, (b) => b === child);
             if (bodyIndex) {
               body.value.splice(bodyIndex, 0, typeAlias);
             }
           }
           return p;
         }
      }
    })
    .map(p => {
      return p;
    }).toSource();
};<commit_msg>Fix indents<commit_after>import transformProperties from './helpers/transformProperties';
import createTypeAlias from './helpers/createTypeAlias';
import findParentBody from './helpers/findParentBody';
import annotateConstructor from './helpers/annotateConstructor';
import findIndex from './helpers/findIndex';

export default function transformer(file, api) {
  const j = api.jscodeshift;
  const {expression, statement, statements} = j.template;
  let root = j(file.source);

  const isStaticPropType = (p) => {
    return p.type === 'ClassProperty' &&
      p.static &&
      p.key.type === 'Identifier' &&
      p.key.name === 'propTypes';
  };

  // find classes
  return root.find(j.ClassDeclaration)
    .forEach(p => {
      // find classes with propType static class property
      if (p.value.body && p.value.body.body) {
        const index = findIndex(p.value.body.body, isStaticPropType)
        if (typeof index !== 'undefined') {
          const classProperty = p.value.body.body.splice(index, 1).pop();
          const typeAlias = createTypeAlias(
            j, transformProperties(j, classProperty.value.properties), {
              shouldExport: true
            }
          );

          // find parent
          const {
            child,
            body,
          } = findParentBody(p);
          if (body && child) {
            const bodyIndex = findIndex(body.value, (b) => b === child);
            if (bodyIndex) {
              body.value.splice(bodyIndex, 0, typeAlias);
            }
          }
          return p;
        }
      }
    })
    .map(p => {
      return p;
    }).toSource();
};
{'fraction_non_alphanumeric': 0.1293288384921851, 'fraction_numerical': 0.001225865767698437, 'mean_word_length': 2.15972894482091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '7281688', 'n_tokens_mistral': 912, 'n_tokens_neox': 905, 'n_words': 217}