Repository: atom/atom
File: src/config.js (JavaScript)

Code before:
    if (newSettings['*'] != null) {
      const scopedSettings = newSettings
      newSettings = newSettings['*']
      delete scopedSettings['*']
      if (options.resetProject) {
        this.resetUserScopedSettings(scopedSettings, {source: this.projectFile})
      } else {
        this.resetUserScopedSettings(scopedSettings)
      }
    }

    return this.transact(() => {
      if (options.resetProject) {
        this.projectSettings = {}
      } else {
        this.settings = {}
      }
      this.settingsLoaded = true
      for (let key in newSettings) {
        const value = newSettings[key]
        if (options.resetProject) {
          this.set(key, value, {save: false, source: this.projectFile})
        } else {
          this.set(key, value, {save: false})
        }
      }
      if (this.pendingOperations.length) {
        for (let op of this.pendingOperations) { op() }
        this.pendingOperations = []
      }
    })
  }

  resetProjectSettings (newSettings, projectFile) {
    // Sets the scope and source of all project settings to `path`.
    newSettings = Object.assign({}, newSettings)
    const oldProjectFile = this.projectFile
    this.projectFile = projectFile
    if (this.projectFile != null) {
      this.resetUserSettings(newSettings, {resetProject: true})
    } else {
      this.scopedSettingsStore.removePropertiesForSource(oldProjectFile)
      this.projectSettings = {}
    }
  }

  clearProjectSettings () {
    this.resetProjectSettings({}, null)
  }

  getRawValue (keyPath, options = {}) {

Review comment (refactor):
Just naming-wise, it seems a bit confusing to generalize `resetUserSettings` in this way and have `resetProjectSettings` call it. Could you instead extract a third method that they would both call?

Something like:

```js
resetUserSettings (newSettings) {
  this.settings = {}
  this._resetSettings(this.mainSource, newSettings)
}

resetProjectSettings (projectFile, newSettings) {
  this.projectSettings = {}
  this._resetSettings(projectFile, newSettings)
}

_resetSettings (source, newSettings) {
  newSettings = Object.assign({}, newSettings)
  if (newSettings.global != null) {
    newSettings['*'] = newSettings.global
    delete newSettings.global
  }
 
  if (newSettings['*'] != null) {
    const scopedSettings = newSettings
    newSettings = newSettings['*']
    delete scopedSettings['*']
    this.resetUserScopedSettings(scopedSettings, {save: false, source})
  }

  return this.transact(() => {
    for (let key in newSettings) { const value = newSettings[key]; this.set(key, value, {save: false, source}) }
    if (this.pendingOperations.length) {
      for (let op of this.pendingOperations) { op() }
      this.pendingOperations = []
    }
  })
}
```

I'm not sure exactly how the extraction needs to work, but it seems like you don't need all these conditionals *within* the method, since `set` should already do the right thing based on the `source`.

Code after:
    if (newSettings.global != null) {
      newSettings['*'] = newSettings.global
      delete newSettings.global
    }

    if (newSettings['*'] != null) {
      const scopedSettings = newSettings
      newSettings = newSettings['*']
      delete scopedSettings['*']
      this.resetScopedSettings(scopedSettings, {source})
    }

    return this.transact(() => {
      this._clearUnscopedSettingsForSource(source)
      this.settingsLoaded = true
      for (let key in newSettings) {
        const value = newSettings[key]
        this.set(key, value, {save: false, source})
      }
      if (this.pendingOperations.length) {
        for (let op of this.pendingOperations) { op() }
        this.pendingOperations = []
      }
    })
  }

  _clearUnscopedSettingsForSource (source) {
    if (source === this.projectFile) {
      this.projectSettings = {}
    } else {
      this.settings = {}
    }
  }

  resetProjectSettings (newSettings, projectFile) {
    // Sets the scope and source of all project settings to `path`.
    newSettings = Object.assign({}, newSettings)
    const oldProjectFile = this.projectFile
    this.projectFile = projectFile
    if (this.projectFile != null) {
      this._resetSettings(newSettings, {source: this.projectFile})
    } else {
      this.scopedSettingsStore.removePropertiesForSource(oldProjectFile)
      this.projectSettings = {}
    }
  }

  clearProjectSettings () {
    this.resetProjectSettings({}, null)
  }