summaryrefslogtreecommitdiff
path: root/tools/eslint/lib/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/lib/util.js')
-rw-r--r--tools/eslint/lib/util.js60
1 files changed, 12 insertions, 48 deletions
diff --git a/tools/eslint/lib/util.js b/tools/eslint/lib/util.js
index 9fe594a4ae..fb1a7a33d5 100644
--- a/tools/eslint/lib/util.js
+++ b/tools/eslint/lib/util.js
@@ -14,72 +14,36 @@ var PLUGIN_NAME_PREFIX = "eslint-plugin-",
// Public Interface
//------------------------------------------------------------------------------
-/**
- * Merges two config objects. This will not only add missing keys, but will also modify values to match.
- * @param {Object} base config object
- * @param {Object} custom config object. Overrides in this config object will take priority over base.
- * @returns {Object} merged config object.
- */
-exports.mergeConfigs = function mergeConfigs(base, custom) {
-
- Object.keys(custom).forEach(function (key) {
- var property = custom[key];
-
- if (key === "plugins") {
- if (!base[key]) {
- base[key] = [];
- }
-
- property.forEach(function (plugin) {
- // skip duplicates
- if (base[key].indexOf(plugin) === -1) {
- base[key].push(plugin);
- }
- });
- return;
- }
-
- if (Array.isArray(base[key]) && !Array.isArray(property) && typeof property === "number") {
- // assume that we are just overriding first attribute
- base[key][0] = custom[key];
- return;
- }
-
- if (typeof property === "object" && !Array.isArray(property) && property !== null) {
- // base[key] might not exist, so be careful with recursion here
- base[key] = mergeConfigs(base[key] || {}, custom[key]);
- } else {
- base[key] = custom[key];
- }
- });
-
- return base;
-};
/**
* Removes the prefix `eslint-plugin-` from a plugin name.
* @param {string} pluginName The name of the plugin which may have the prefix.
* @returns {string} The name of the plugin without prefix.
*/
-exports.removePluginPrefix = function removePluginPrefix(pluginName) {
+function removePluginPrefix(pluginName) {
return pluginName.indexOf(PLUGIN_NAME_PREFIX) === 0 ? pluginName.substring(PLUGIN_NAME_PREFIX.length) : pluginName;
-};
+}
/**
* @param {string} pluginName The name of the plugin which may have the prefix.
* @returns {string} The name of the plugins namepace if it has one.
*/
-exports.getNamespace = function getNamespace(pluginName) {
+function getNamespace(pluginName) {
return pluginName.match(NAMESPACE_REGEX) ? pluginName.match(NAMESPACE_REGEX)[0] : "";
-};
+}
/**
* Removes the namespace from a plugin name.
* @param {string} pluginName The name of the plugin which may have the prefix.
* @returns {string} The name of the plugin without the namespace.
*/
-exports.removeNameSpace = function removeNameSpace(pluginName) {
+function removeNameSpace(pluginName) {
return pluginName.replace(NAMESPACE_REGEX, "");
-};
+}
-exports.PLUGIN_NAME_PREFIX = PLUGIN_NAME_PREFIX;
+module.exports = {
+ removePluginPrefix: removePluginPrefix,
+ getNamespace: getNamespace,
+ removeNameSpace: removeNameSpace,
+ "PLUGIN_NAME_PREFIX": PLUGIN_NAME_PREFIX
+};