Skip to content

Commit

Permalink
renamed ERR_MODULE_NOT_ENABLED and apply bitwise op
Browse files Browse the repository at this point in the history
  • Loading branch information
vutran committed Oct 9, 2016
1 parent 491d39f commit 8c7cfd5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions __tests__/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ERR_MODULE_DOWNLOAD_ERROR,
ERR_MODULE_ENABLED,
ERR_MODULE_NOT_FOUND,
ERR_MODULE_NOT_ENABLED,
ERR_MODULE_DISABLED,
ERR_MODULE_REMOVE_FAILED,
ERR_THEME_ALREADY_ACTIVE,
} from '../../src/errors';
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('plugins', () => {
try {
await api.uninstall('INVALID_MODULE', '/jest/test');
} catch (err) {
expect(err).toBe(ERR_MODULE_NOT_ENABLED);
expect(err).toBe(ERR_MODULE_DISABLED);
}
});
});
Expand Down Expand Up @@ -144,7 +144,7 @@ describe('themes', () => {
try {
await api.setTheme('foobar');
} catch (err) {
expect(err).toBe(ERR_MODULE_NOT_ENABLED);
expect(err).toBe(ERR_MODULE_DISABLED);
}
});

Expand Down
8 changes: 4 additions & 4 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
ERR_MODULE_DOWNLOAD_ERROR,
ERR_MODULE_ENABLED,
ERR_MODULE_NOT_FOUND,
ERR_MODULE_NOT_ENABLED,
ERR_MODULE_DISABLED,
ERR_MODULE_REMOVE_FAILED,
ERR_THEME_ALREADY_ACTIVE,
} = require('../errors');
Expand Down Expand Up @@ -71,7 +71,7 @@ const install = (plugin, outputDir) => new Promise((resolve, reject) => {
*/
const uninstall = (plugin, srcDir) => new Promise((resolve, reject) => {
if (!plugins.isEnabled(plugin)) {
reject(ERR_MODULE_NOT_ENABLED);
reject(ERR_MODULE_DISABLED);
return;
}

Expand Down Expand Up @@ -138,9 +138,9 @@ const setTheme = theme => new Promise((resolve, reject) => {
reject(ERR_THEME_ALREADY_ACTIVE);
}

// if theme plugin is not enabled
// if theme plugin is disabled
if (!plugins.isEnabled(theme)) {
reject(ERR_MODULE_NOT_ENABLED);
reject(ERR_MODULE_DISABLED);
}

config.set('theme', theme);
Expand Down
3 changes: 2 additions & 1 deletion src/api/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const getAll = () => config.get('plugins') || [];
* @param {String} plugin - The plugin name
* @return {Boolean}
*/
const isEnabled = plugin => getAll().indexOf(plugin) > -1;
// eslint-disable-next-line no-bitwise
const isEnabled = plugin => ~getAll().indexOf(plugin);

/**
* Enables the plugin by adding it to the config
Expand Down
2 changes: 1 addition & 1 deletion src/errors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exports.ERR_MODULE_DOWNLOAD_ERROR = 'ERR_MODULE_DOWNLOAD_ERROR';
exports.ERR_MODULE_INSTALLED = 'ERR_MODULE_INSTALLED';
exports.ERR_MODULE_ENABLED = 'ERR_MODULE_ENABLED';
exports.ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
exports.ERR_MODULE_NOT_ENABLED = 'ERR_MODULE_NOT_ENABLED';
exports.ERR_MODULE_DISABLED = 'ERR_MODULE_DISABLED';
exports.ERR_MODULE_NOT_INSTALLED = 'ERR_MODULE_NOT_INSTALLED';
exports.ERR_MODULE_REMOVE_FAILED = 'ERR_MODULE_REMOVE_FAILED';
exports.ERR_THEME_ALREADY_ACTIVE = 'ERR_THEME_ALREADY_ACTIVE';

0 comments on commit 8c7cfd5

Please sign in to comment.