Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Commit

Permalink
Refine migration approach slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Jan 28, 2018
1 parent ca5ccb0 commit 3f254d9
Showing 1 changed file with 91 additions and 62 deletions.
153 changes: 91 additions & 62 deletions src/migrate-config-options.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,102 @@
'use babel'

// These are cases where the old setting should be directly moved to the new setting.
const directMoveMigrations = [
/* Added January, 2018 */
/*
* These migrations can take one of two forms, a direct move or a general function.
*
* Direct move:
* These objects have a `type` of `direct-move`, and an array of `moves`, which
* are objects containing an `old` setting name and a `new` setting name.
* Any existing config found in the `old` name will be moved over to (and overwrite)
* the `new` key.
*
* Functions:
* These have a `type` of `function`, and a `migrationFunc`, which takes the
* current linter-eslint atom config as an argument, and can act on it however
* it needs to.
*/
const migrations = [
{
old: 'disableWhenNoEslintConfig',
new: 'disabling.disableWhenNoEslintConfig',
}, {
old: 'fixOnSave',
new: 'autofix.fixOnSave'
}, {
old: 'ignoreFixableRulesWhileTyping',
new: 'autofix.ignoreFixableRulesWhileTyping'
}, {
old: 'rulesToDisableWhileFixing',
new: 'autofix.rulesToDisableWhileFixing'
}, {
old: 'rulesToSilenceWhileTyping',
new: 'disabling.rulesToSilenceWhileTyping'
}, {
old: 'disableEslintIgnore',
new: 'advanced.disableEslintIgnore'
}, {
old: 'disableFSCache',
new: 'advanced.disableFSCache'
}, {
old: 'showRuleIdInMessage',
new: 'advanced.showRuleIdInMessage'
}, {
old: 'eslintrcPath',
new: 'global.eslintrcPath'
}, {
old: 'advancedLocalNodeModules',
new: 'advanced.advancedLocalNodeModules'
}, {
old: 'eslintRulesDirs',
new: 'advanced.eslintRulesDirs'
}, {
old: 'useGlobalEslint',
new: 'global.useGlobalEslint'
}, {
old: 'globalNodePath',
new: 'global.globalNodePath'
type: 'direct-move',
added: 'January, 2018',
description: 'Organized config settings into sections',
moves: [
{
old: 'disableWhenNoEslintConfig',
new: 'disabling.disableWhenNoEslintConfig',
}, {
old: 'fixOnSave',
new: 'autofix.fixOnSave'
}, {
old: 'ignoreFixableRulesWhileTyping',
new: 'autofix.ignoreFixableRulesWhileTyping'
}, {
old: 'rulesToDisableWhileFixing',
new: 'autofix.rulesToDisableWhileFixing'
}, {
old: 'rulesToSilenceWhileTyping',
new: 'disabling.rulesToSilenceWhileTyping'
}, {
old: 'disableEslintIgnore',
new: 'advanced.disableEslintIgnore'
}, {
old: 'disableFSCache',
new: 'advanced.disableFSCache'
}, {
old: 'showRuleIdInMessage',
new: 'advanced.showRuleIdInMessage'
}, {
old: 'eslintrcPath',
new: 'global.eslintrcPath'
}, {
old: 'advancedLocalNodeModules',
new: 'advanced.advancedLocalNodeModules'
}, {
old: 'eslintRulesDirs',
new: 'advanced.eslintRulesDirs'
}, {
old: 'useGlobalEslint',
new: 'global.useGlobalEslint'
}, {
old: 'globalNodePath',
new: 'global.globalNodePath'
}
]
},
{
type: 'function',
added: 'September, 2017',
description: 'Deprecated eslintRulesDir{String} option in favor of eslintRulesDirs{Array<String>}',
migrationFunc(config) {
const oldRulesdir = config.eslintRulesDir
if (oldRulesdir) {
const newRulesDirs = config.eslintRulesDirs
if (newRulesDirs.length === 0) {
atom.config.set('linter-eslint.eslintRulesDirs', [oldRulesdir])
}
atom.config.unset('linter-eslint.eslintRulesDir')
}
}
}
]

/*
* This function can be called when linter-eslint first activates in order to
* ensure that the user's settings are up-to-date with the current version of
* linter-eslint. Ideally, we would call this only when upgrading to a new
* version.
*/
function migrateConfigOptions() {
const linterEslintConfig = atom.config.get('linter-eslint')

/**
* FIXME: Deprecated eslintRulesDir{String} option in favor of
* eslintRulesDirs{Array<String>}. Remove in the next major release,
* in v8.5.0, or after 2018-04.
*/
const oldRulesdir = linterEslintConfig.eslintRulesDir
if (oldRulesdir) {
const newRulesDirs = linterEslintConfig.eslintRulesDirs
if (newRulesDirs.length === 0) {
atom.config.set('linter-eslint.eslintRulesDirs', [oldRulesdir])
}
atom.config.unset('linter-eslint.eslintRulesDir')
}

// Copy old settings over to the new ones, then unset the old setting keys
directMoveMigrations.forEach((migration) => {
const oldSetting = linterEslintConfig[migration.old]
if (oldSetting !== undefined) {
atom.config.set(migration.new, oldSetting)
atom.config.unset(migration.old)
migrations.forEach((migration) => {
if (migration.type === 'direct-move') {
// Copy old settings over to the new ones, then unset the old setting keys
const oldSetting = linterEslintConfig[migration.old]
if (oldSetting !== undefined) {
atom.config.set(migration.new, oldSetting)
atom.config.unset(migration.old)
}
} else if (migration.type === 'function') {
migration.migrationFunc(linterEslintConfig)
}
})
}
Expand Down

0 comments on commit 3f254d9

Please sign in to comment.