<commit_before>import { reducer } from 'redux-form'
import {
  CLEAR_SCHOOL_FIELD,
  CLEAR_JOB_FIELD,
  CLEAR_JOB_DUTY_FIELD,
  CLEAR_PROJECT_FIELD,
  CLEAR_SKILL_FIELD
} from '../constants'

const form = reducer.plugin({
  resume: (state, action) => {
    switch (action.type) {
      case CLEAR_SCHOOL_FIELD:
        if (
          !state.values ||
          !state.values.schools ||
          state.values.schools.length <= 1 ||
          state.values.schools.length !== action.schoolCount
        ) {
          return state
        }

        return {
          ...state,
          values: {
            ...state.values,
            schools: state.values.schools.slice(0, -1)
          }
        }

      case CLEAR_JOB_FIELD:
        if (
          !state.values ||
          !state.values.jobs ||
          state.values.jobs.length <= 1 ||
          state.values.jobs.length !== action.jobCount
        ) {
          return state
        }

        return {
          ...state,
          values: {
            ...state.values,
            jobs: state.values.jobs.slice(0, -1)
          }
        }

      case CLEAR_JOB_DUTY_FIELD:
        if (
          !state.values ||
          !state.values.jobs ||
          !state.values.jobs[action.index] ||
          !state.values.jobs[action.index].duties ||
          state.values.jobs[action.index].duties.length <= 1 ||
          action.jobDutyCount !== state.values.jobs[action.index].duties.length
        ) {
          return state
        }

        return {
          ...state,
          values: {
            ...state.values,
            jobs: [
              ...state.values.jobs.slice(0, action.index),
              {
                ...state.values.jobs[action.index],
                duties: state.values.jobs[action.index].duties.slice(0, -1)
              },
              ...state.values.jobs.slice(action.index + 1)
            ]
          }
        }

      case CLEAR_PROJECT_FIELD:
        if (
          !state.values ||
          !state.values.projects ||
          state.values.projects.length <= 1 ||
          state.values.projects.length !== action.projectCount
        ) {
          return state
        }

        return {
          ...state,
          values: {
            ...state.values,
            projects: state.values.projects.slice(0, -1)
          }
        }

      case CLEAR_SKILL_FIELD:
        if (
          !state.values ||
          !state.values.skills ||
          state.values.skills.length <= 1 ||
          state.values.skills.length !== action.skillCount
        ) {
          return state
        }

        return {
          ...state,
          values: {
            ...state.values,
            skills: state.values.skills.slice(0, -1)
          }
        }

      default:
        return state
    }
  }
})

export default form<commit_msg>separate form reducer from redux-form for testing purposes<commit_after>import { reducer } from 'redux-form'
import {
  CLEAR_SCHOOL_FIELD,
  CLEAR_JOB_FIELD,
  CLEAR_JOB_DUTY_FIELD,
  CLEAR_PROJECT_FIELD,
  CLEAR_SKILL_FIELD
} from '../constants'

function form(state = {}, action) {
  switch (action.type) {
    case CLEAR_SCHOOL_FIELD:
      if (
        !state.values ||
        !state.values.schools ||
        state.values.schools.length <= 1 ||
        state.values.schools.length !== action.schoolCount
      ) {
        return state
      }

      return {
        ...state,
        values: {
          ...state.values,
          schools: state.values.schools.slice(0, -1)
        }
      }

    case CLEAR_JOB_FIELD:
      if (
        !state.values ||
        !state.values.jobs ||
        state.values.jobs.length <= 1 ||
        state.values.jobs.length !== action.jobCount
      ) {
        return state
      }

      return {
        ...state,
        values: {
          ...state.values,
          jobs: state.values.jobs.slice(0, -1)
        }
      }

    case CLEAR_JOB_DUTY_FIELD:
      if (
        !state.values ||
        !state.values.jobs ||
        !state.values.jobs[action.index] ||
        !state.values.jobs[action.index].duties ||
        state.values.jobs[action.index].duties.length <= 1 ||
        action.jobDutyCount !== state.values.jobs[action.index].duties.length
      ) {
        return state
      }

      return {
        ...state,
        values: {
          ...state.values,
          jobs: [
            ...state.values.jobs.slice(0, action.index),
            {
              ...state.values.jobs[action.index],
              duties: state.values.jobs[action.index].duties.slice(0, -1)
            },
            ...state.values.jobs.slice(action.index + 1)
          ]
        }
      }

    case CLEAR_PROJECT_FIELD:
      if (
        !state.values ||
        !state.values.projects ||
        state.values.projects.length <= 1 ||
        state.values.projects.length !== action.projectCount
      ) {
        return state
      }

      return {
        ...state,
        values: {
          ...state.values,
          projects: state.values.projects.slice(0, -1)
        }
      }

    case CLEAR_SKILL_FIELD:
      if (
        !state.values ||
        !state.values.skills ||
        state.values.skills.length <= 1 ||
        state.values.skills.length !== action.skillCount
      ) {
        return state
      }

      return {
        ...state,
        values: {
          ...state.values,
          skills: state.values.skills.slice(0, -1)
        }
      }

    default:
      return state
  }
}

export { form }
export default reducer.plugin({ resume: form })
{'fraction_non_alphanumeric': 0.12767103609265576, 'fraction_numerical': 0.006105225354641767, 'mean_word_length': 1.3621713316369806, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 4, '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': '7565145', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1665, 'n_words': 255}