From d6fbfe2b4544fe525a535407f11a3ce44502dc5e Mon Sep 17 00:00:00 2001 From: Gert Date: Sun, 19 May 2019 21:05:11 +0200 Subject: [PATCH] Clean up AtomConfig after decaffeinate References #460 --- lib/AtomConfig.js | 180 +++++++++++++++++++--------------------------- 1 file changed, 74 insertions(+), 106 deletions(-) diff --git a/lib/AtomConfig.js b/lib/AtomConfig.js index 4e39c6a7..adc71f11 100644 --- a/lib/AtomConfig.js +++ b/lib/AtomConfig.js @@ -1,13 +1,7 @@ /* global atom */ -/* - * decaffeinate suggestions: - * DS102: Remove unnecessary code created because of implicit returns - * DS205: Consider reworking code to avoid use of IIFEs - * DS206: Consider reworking classes to avoid initClass - * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md - */ -let AtomConfig; +'use strict'; + const path = require('path'); const process = require('process'); const mkdirp = require('mkdirp'); @@ -16,106 +10,80 @@ const Config = require('./Config'); module.exports = -//#* -// Config that retrieves its settings from Atom's config. -//# -(AtomConfig = (function() { - AtomConfig = class AtomConfig extends Config { - static initClass() { - /** - * The name of the package to use when searching for settings. - */ - this.prototype.packageName = null; - - /** - * @var {Array} - */ - this.prototype.configurableProperties = null; - } - - /** - * @inheritdoc - */ - constructor(packageName) { - super(); - - this.packageName = packageName; - this.configurableProperties = [ - 'core.phpExecutionType', - 'core.phpCommand', - 'core.memoryLimit', - 'core.additionalDockerVolumes', - 'general.doNotAskForSupport', - 'general.projectOpenCount', - 'annotations.enable', - 'refactoring.enable', - ]; - - this.attachListeners(); - } - - /** - * @inheritdoc - */ - load() { - this.set('storagePath', this.getPathToStorageFolderInRidiculousWay()); - - return this.configurableProperties.map((property) => { - this.set(property, atom.config.get(`${this.packageName}.${property}`)); +class AtomConfig extends Config +{ + /** + * @inheritdoc + */ + constructor(packageName) { + super(); + + this.packageName = packageName; + this.configurableProperties = [ + 'core.phpExecutionType', + 'core.phpCommand', + 'core.memoryLimit', + 'core.additionalDockerVolumes', + 'general.doNotAskForSupport', + 'general.projectOpenCount', + 'annotations.enable', + 'refactoring.enable', + ]; + + this.attachListeners(); + } + + /** + * @inheritdoc + */ + load() { + this.set('storagePath', this.getPathToStorageFolderInRidiculousWay()); + + this.configurableProperties.forEach((property) => { + this.set(property, atom.config.get(`${this.packageName}.${property}`)); + }); + } + + /** + * @inheritdoc + */ + set(name, value) { + super.set(name, value); + + atom.config.set(`${this.packageName}.${name}`, value); + } + + /** + * Attaches listeners to listen to Atom configuration changes. + */ + attachListeners() { + this.configurableProperties.forEach((property) => { + atom.config.onDidChange(`${this.packageName}.${property}`, (data) => { + this.set(property, data.newValue); }); + }); + } + + /** + * @return {String} + */ + getPathToStorageFolderInRidiculousWay() { + // NOTE: Apparently process.env.ATOM_HOME is not always set for whatever reason and this ridiculous workaround + // is needed to fetch an OS-compliant location to store application data. + let baseFolder = null; + + if (process.env.APPDATA) { + baseFolder = process.env.APPDATA; + } else if (process.platform === 'darwin') { + baseFolder = process.env.HOME + '/Library/Preferences'; + } else { + baseFolder = process.env.HOME + '/.cache'; } - /** - * @inheritdoc - */ - set(name, value) { - super.set(name, value); - - atom.config.set(`${this.packageName}.${name}`, value); - } - - /** - * Attaches listeners to listen to Atom configuration changes. - */ - attachListeners() { - return (() => { - const result = []; - - for (const property of this.configurableProperties) { - result.push(atom.config.onDidChange(`${this.packageName}.${property}`, (data) => { - return this.set(property, data.newValue); - })); - } - - return result; - })(); - } - - /** - * @return {String} - */ - getPathToStorageFolderInRidiculousWay() { - // NOTE: Apparently process.env.ATOM_HOME is not always set for whatever reason and this ridiculous - // workaround is needed to fetch an OS-compliant location to store application data. - let baseFolder = null; - - if (process.env.APPDATA) { - baseFolder = process.env.APPDATA; + const packageFolder = baseFolder + path.sep + this.packageName; - } else if (process.platform === 'darwin') { - baseFolder = process.env.HOME + '/Library/Preferences'; + mkdirp.sync(packageFolder); - } else { - baseFolder = process.env.HOME + '/.cache'; - } - - const packageFolder = baseFolder + path.sep + this.packageName; - - mkdirp.sync(packageFolder); - - return packageFolder; - } - }; - AtomConfig.initClass(); - return AtomConfig; -})()); + return packageFolder; + } +};