New eslint rules auto fix (#3058)

* no-implicit-coercion and no-unneeded-ternary

* End every line with a semicolon

* Spacing and formatting

* Enabled semi-spacing

* Applies npm run lint:fix to code after master merge

* Fix merge issues

* Switched operator-linebreak to 'before'

Co-authored-by: Joshi <simplyrender@gmail.com>
This commit is contained in:
Andrew Henry
2020-07-31 12:11:03 -07:00
committed by GitHub
parent 573a63d359
commit a09da30768
739 changed files with 4660 additions and 2339 deletions

View File

@@ -76,7 +76,7 @@ define(
// but additionally adds a domainObject field.
var baseContext;
if (typeof context === 'string') {
baseContext = { key: context };
baseContext = { key: context };
} else {
baseContext = context || {};
}
@@ -108,13 +108,12 @@ define(
var actions = this.getActions(context);
return this.$q.when(
(actions && actions.length > 0) ?
actions[0].perform(flag) :
undefined
(actions && actions.length > 0)
? actions[0].perform(flag)
: undefined
);
};
return ActionCapability;
}
);

View File

@@ -51,8 +51,8 @@ define(
var categories = Action.category || [];
// Convert to an array if necessary
categories = Array.isArray(categories) ?
categories : [categories];
categories = Array.isArray(categories)
? categories : [categories];
// Store action under all relevant categories
categories.forEach(function (category) {
@@ -118,6 +118,7 @@ define(
"due to:",
e.message
].join(" "));
return undefined;
}
}

View File

@@ -62,6 +62,7 @@ define(
" upon ",
domainObject && domainObject.getId()
].join(""));
return action.perform.apply(action, arguments);
};

View File

@@ -61,8 +61,8 @@ define(
*/
CompositionCapability.prototype.add = function (domainObject, index) {
var self = this,
id = typeof domainObject === 'string' ?
domainObject : domainObject.getId(),
id = typeof domainObject === 'string'
? domainObject : domainObject.getId(),
model = self.domainObject.getModel(),
composition = model.composition,
oldIndex = composition.indexOf(id);

View File

@@ -81,8 +81,8 @@ define(
var parentObject = this.parentObject,
parentContext =
parentObject && parentObject.getCapability('context'),
parentPath = parentContext ?
parentContext.getPath() : [this.parentObject];
parentPath = parentContext
? parentContext.getPath() : [this.parentObject];
return parentPath.concat([this.domainObject]);
};
@@ -98,12 +98,12 @@ define(
* object which exposed this capability.
*/
ContextCapability.prototype.getRoot = function () {
var parentContext = this.parentObject &&
this.parentObject.getCapability('context');
var parentContext = this.parentObject
&& this.parentObject.getCapability('context');
return parentContext ?
parentContext.getRoot() :
(this.parentObject || this.domainObject);
return parentContext
? parentContext.getRoot()
: (this.parentObject || this.domainObject);
};
return ContextCapability;

View File

@@ -53,9 +53,9 @@ define(
// Intercept requests for a context capability.
contextualObject.getCapability = function (name) {
return name === "context" ?
contextCapability :
domainObject.getCapability.apply(this, arguments);
return name === "context"
? contextCapability
: domainObject.getCapability.apply(this, arguments);
};
return contextualObject;

View File

@@ -55,9 +55,9 @@ define(
// Filter by invoking the capability's appliesTo method
function filterCapabilities(model, id) {
return capabilities.filter(function (capability) {
return capability.appliesTo ?
capability.appliesTo(model, id) :
true;
return capability.appliesTo
? capability.appliesTo(model, id)
: true;
});
}
@@ -72,6 +72,7 @@ define(
$log.warn("No key defined for capability; skipping.");
}
});
return result;
}

View File

@@ -27,7 +27,6 @@ define(
[],
function () {
/**
* The `delegation` capability allows a domain object to indicate
* that it wishes to delegate responsibility for some other
@@ -65,7 +64,6 @@ define(
}
}
/**
* Get the domain objects which are intended to be delegated
* responsibility for some specific capability.
@@ -90,11 +88,11 @@ define(
return domainObject.useCapability('composition');
}
return this.doesDelegateCapability(key) ?
promiseChildren().then(
return this.doesDelegateCapability(key)
? promiseChildren().then(
filterObjectsWithCapability(key)
) :
this.$q.when([]);
)
: this.$q.when([]);
};
/**
@@ -105,7 +103,7 @@ define(
* @returns {boolean} true if the capability is delegated
*/
DelegationCapability.prototype.doesDelegateCapability = function (key) {
return !!(this.delegateCapabilities[key]);
return Boolean(this.delegateCapabilities[key]);
};
/**

View File

@@ -65,8 +65,8 @@ define(
// Lazily initialize; instantiate depends on capabilityService,
// which depends on all capabilities, including this one.
this.instantiateFn = this.instantiateFn ||
this.$injector.get("instantiate");
this.instantiateFn = this.instantiateFn
|| this.$injector.get("instantiate");
var newObject = this.instantiateFn(model, id);

View File

@@ -43,13 +43,14 @@ define(
function hasDisplayableValue(metadataProperty) {
var t = typeof metadataProperty.value;
return (t === 'string' || t === 'number');
}
function formatTimestamp(timestamp) {
return typeof timestamp === 'number' ?
(moment.utc(timestamp).format(TIME_FORMAT) + " UTC") :
undefined;
return typeof timestamp === 'number'
? (moment.utc(timestamp).format(TIME_FORMAT) + " UTC")
: undefined;
}
function getProperties() {
@@ -67,6 +68,7 @@ define(
function getCommonMetadata() {
var type = domainObject.getCapability('type');
// Note that invalid values will be filtered out later
return [
{

View File

@@ -144,6 +144,7 @@ define(
if (model !== result) {
copyValues(model, result);
}
model.modified = useTimestamp ? timestamp : now();
notifyListeners(model);
}

View File

@@ -115,6 +115,7 @@ define(["objectUtils"],
domainObject = this.domainObject;
let newStyleObject = objectUtils.toNewFormat(domainObject.getModel(), domainObject.getId());
return this.openmct.objects
.save(newStyleObject)
.then(function (result) {
@@ -141,6 +142,7 @@ define(["objectUtils"],
return $q.reject('Got empty object model');
} else {
var modified = model.modified;
return domainObject.useCapability("mutation", function () {
return model;
}, modified);
@@ -169,10 +171,10 @@ define(["objectUtils"],
*/
PersistenceCapability.prototype.getSpace = function () {
var id = this.domainObject.getId();
return this.identifierService.parse(id).getSpace();
};
/**
* Check if this domain object has been persisted at some
* point.
@@ -189,6 +191,7 @@ define(["objectUtils"],
*/
PersistenceCapability.prototype.getKey = function () {
var id = this.domainObject.getId();
return this.identifierService.parse(id).getKey();
};

View File

@@ -103,6 +103,7 @@ define(
if (!this.objectService) {
this.injectObjectService();
}
// Load from the underlying object service
this.lastPromise[key] = this.objectService.getObjects(ids)
.then(packageObject);
@@ -111,7 +112,6 @@ define(
return this.lastPromise[key];
};
/**
* Test to determine whether or not this capability should be exposed
* by a domain object based on its model. Checks for the presence of
@@ -120,7 +120,7 @@ define(
* @returns {boolean} true if this object has relationships
*/
RelationshipCapability.appliesTo = function (model) {
return !!(model || {}).relationships;
return Boolean((model || {}).relationships);
};
return RelationshipCapability;

View File

@@ -47,6 +47,7 @@ define(
if (space !== undefined) {
id = space + ":" + id;
}
return id;
};

View File

@@ -55,6 +55,7 @@ define(
loadFromCache.forEach(function (id) {
modelResults[id] = this.cacheService.get(id);
}, this);
return modelResults;
}.bind(this));
};

View File

@@ -49,6 +49,7 @@ define(
ids.forEach(function (id) {
result[id] = models[id] || missingModel(id);
});
return result;
}

View File

@@ -67,6 +67,7 @@ define(
function pick(a, b) {
var aModified = (a || {}).modified || Number.NEGATIVE_INFINITY,
bModified = (b || {}).modified || Number.NEGATIVE_INFINITY;
return (aModified > bModified) ? a : (b || a);
}
@@ -81,6 +82,7 @@ define(
}
});
});
return result;
}

View File

@@ -74,8 +74,8 @@ define(
// sensible timestamp indicating they've been persisted.
function addPersistedTimestamp(model) {
if (model && (model.persisted === undefined)) {
model.persisted = model.modified !== undefined ?
model.modified : now();
model.persisted = model.modified !== undefined
? model.modified : now();
}
return model;
@@ -90,6 +90,7 @@ define(
result[id] = models[index];
}
});
return result;
}
@@ -111,9 +112,18 @@ define(
parsedIds = ids.map(function (id) {
var parts = id.split(":");
return (parts.length > 1) ?
{ id: id, space: parts[0], key: parts.slice(1).join(":") } :
{ id: id, space: defaultSpace, key: id };
return (parts.length > 1)
? {
id: id,
space: parts[0],
key: parts.slice(1).join(":")
}
: {
id: id,
space: defaultSpace,
key: id
};
});
return persistenceService.listSpaces()

View File

@@ -37,9 +37,9 @@ define(
function addModelToMap(model) {
// Skip models which don't look right
if (typeof model !== 'object' ||
typeof model.id !== 'string' ||
typeof model.model !== 'object') {
if (typeof model !== 'object'
|| typeof model.id !== 'string'
|| typeof model.model !== 'object') {
$log.warn([
"Skipping malformed domain object model exposed by ",
((model || {}).bundle || {}).path
@@ -62,6 +62,7 @@ define(
ids.forEach(function (id) {
result[id] = modelMap[id];
});
return this.$q.when(result);
};

View File

@@ -118,8 +118,9 @@ define(
DomainObjectImpl.prototype.getCapability = function (name) {
var capability = this.capabilities[name];
return typeof capability === 'function' ?
capability(this) : capability;
return typeof capability === 'function'
? capability(this) : capability;
};
DomainObjectImpl.prototype.hasCapability = function (name) {
@@ -131,9 +132,9 @@ define(
var args = Array.prototype.slice.apply(arguments, [1]),
capability = this.getCapability(name);
return (capability && capability.invoke) ?
capability.invoke.apply(capability, args) :
capability;
return (capability && capability.invoke)
? capability.invoke.apply(capability, args)
: capability;
};
return DomainObjectImpl;

View File

@@ -81,6 +81,7 @@ define(
result[id] = instantiate(models[id], id);
}
});
return result;
}

View File

@@ -37,6 +37,7 @@ define([], function () {
function hasChanged(domainObject) {
var model = domainObject.getModel();
return model.persisted === undefined || model.modified > model.persisted;
}

View File

@@ -51,6 +51,7 @@ define(
var capabilities = capabilityService.getCapabilities(model);
id = id || identifierService.generate();
cacheService.put(id, model);
return new DomainObjectImpl(id, model, capabilities);
};
}

View File

@@ -65,6 +65,7 @@ define(
function invoke() {
// Clear the active timeout so a new one starts next time.
promise = undefined;
// Invoke the function with the latest supplied arguments.
return fn.apply(null, args);
}
@@ -78,6 +79,7 @@ define(
args = Array.prototype.slice.apply(arguments, [0]);
// Start a timeout if needed
promise = promise || $timeout(invoke, delay, apply);
// Return whichever timeout is active (to get
// a promise for the results of fn)
return promise;

View File

@@ -55,6 +55,7 @@ define(
return {
listen: function (listener) {
listeners.push(listener);
return function unlisten() {
listeners = listeners.filter(function (l) {
return l !== listener;
@@ -84,6 +85,7 @@ define(
return createTopic();
} else {
topics[key] = topics[key] || createTopic();
return topics[key];
}
};

View File

@@ -75,9 +75,9 @@ define(
function mergeObjects(a, b) {
var result = {};
Object.keys(a).forEach(function (k) {
result[k] = b.hasOwnProperty(k) ?
mergeModels(a[k], b[k], (merger || {})[k]) :
a[k];
result[k] = b.hasOwnProperty(k)
? mergeModels(a[k], b[k], (merger || {})[k])
: a[k];
});
Object.keys(b).forEach(function (k) {
// Copy any properties not already merged
@@ -85,6 +85,7 @@ define(
result[k] = b[k];
}
});
return result;
}
@@ -92,10 +93,10 @@ define(
return b;
}
mergeFunction = (merger && Function.isFunction(merger)) ? merger :
(Array.isArray(modelA) && Array.isArray(modelB)) ? mergeArrays :
(modelA instanceof Object && modelB instanceof Object) ? mergeObjects :
mergeOther;
mergeFunction = (merger && Function.isFunction(merger)) ? merger
: (Array.isArray(modelA) && Array.isArray(modelB)) ? mergeArrays
: (modelA instanceof Object && modelB instanceof Object) ? mergeObjects
: mergeOther;
return mergeFunction(modelA, modelB);
}

View File

@@ -107,7 +107,6 @@ define(
* @method Type#hasFeature
*/
/**
* Construct a new type. Types describe categories of
* domain objects.

View File

@@ -94,9 +94,10 @@ define(
// Otherwise, look up in the sequence defined in the array
if (propertyPath.length > 0) {
value = object[propertyPath[0]];
return propertyPath.length > 1 ?
lookupValue(value, propertyPath.slice(1)) :
value;
return propertyPath.length > 1
? lookupValue(value, propertyPath.slice(1))
: value;
}
// Fallback; property path was empty
@@ -110,16 +111,16 @@ define(
* @returns {*} the value for this property, as read from the model
*/
TypeProperty.prototype.getValue = function (model) {
var property = this.propertyDefinition.property ||
this.propertyDefinition.key,
var property = this.propertyDefinition.property
|| this.propertyDefinition.key,
initialValue =
property && lookupValue(model, property);
// Provide an empty array if this is a multi-item
// property.
if (Array.isArray(this.propertyDefinition.items)) {
initialValue = initialValue ||
new Array(this.propertyDefinition.items.length);
initialValue = initialValue
|| new Array(this.propertyDefinition.items.length);
}
return this.conversion.toFormValue(initialValue);
@@ -132,8 +133,8 @@ define(
* @param {*} value the new value to set for this property
*/
TypeProperty.prototype.setValue = function (model, value) {
var property = this.propertyDefinition.property ||
this.propertyDefinition.key;
var property = this.propertyDefinition.property
|| this.propertyDefinition.key;
// If an array contains all undefined values, treat it
// as undefined, to filter back out arrays for input
@@ -144,9 +145,9 @@ define(
// domain object's model
value = this.conversion.toModelValue(value);
return property ?
specifyValue(model, property, value) :
undefined;
return property
? specifyValue(model, property, value)
: undefined;
};
/**

View File

@@ -23,13 +23,12 @@
define(
function () {
var conversions = {
number: {
toModelValue: parseFloat,
toFormValue: function (modelValue) {
return (typeof modelValue === 'number') ?
modelValue.toString(10) : undefined;
return (typeof modelValue === 'number')
? modelValue.toString(10) : undefined;
}
},
identity: {
@@ -62,9 +61,9 @@ define(
* @memberof platform/core
*/
function TypePropertyConversion(name) {
if (name &&
name.length > ARRAY_SUFFIX.length &&
name.indexOf(ARRAY_SUFFIX, name.length - ARRAY_SUFFIX.length) !== -1) {
if (name
&& name.length > ARRAY_SUFFIX.length
&& name.indexOf(ARRAY_SUFFIX, name.length - ARRAY_SUFFIX.length) !== -1) {
return new ArrayConversion(
new TypePropertyConversion(
name.substring(0, name.length - ARRAY_SUFFIX.length)
@@ -74,6 +73,7 @@ define(
if (!conversions[name]) {
throw new Error("Unknown conversion type: " + name);
}
return conversions[name];
}
}
@@ -94,7 +94,6 @@ define(
* @returns {*} value to display within a form
*/
return TypePropertyConversion;
}
);

View File

@@ -56,15 +56,16 @@ define(
function removeDuplicates(array) {
var set = {};
return array ? array.filter(function (element) {
// Don't filter objects (e.g. property definitions)
if (element instanceof Object && !(element instanceof String)) {
return true;
}
return set[element] ?
false :
(set[element] = true);
return set[element]
? false
: (set[element] = true);
}) : array;
}
@@ -89,6 +90,7 @@ define(
result[k] = (a[k] || []).concat(b[k] || []);
}
});
return result;
}, {});
@@ -98,6 +100,7 @@ define(
collapsed[k] = removeDuplicates(collapsed[k]);
}
});
return collapsed;
}
@@ -120,10 +123,10 @@ define(
result[k] = (result[k] || []).concat(typeDef);
}
});
return result;
}(rawTypeDefinitions));
this.typeMap = {};
this.typeDefinitions = typeDefinitions;
this.rawTypeDefinitions = types;
@@ -131,6 +134,7 @@ define(
TypeProvider.prototype.listTypes = function () {
var self = this;
return removeDuplicates(
this.rawTypeDefinitions.filter(function (def) {
return def.key;
@@ -174,8 +178,8 @@ define(
// Always provide a default name
def.model = def.model || {};
def.model.name = def.model.name ||
("Unnamed " + (def.name || "Object"));
def.model.name = def.model.name
|| ("Unnamed " + (def.name || "Object"));
return def;
}

View File

@@ -113,8 +113,8 @@ define(
// Check if an object has (or delegates, if allowed) a
// capability.
function hasCapability(c) {
return domainObj.hasCapability(c) ||
(allowDelegation && delegation.doesDelegateCapability(c));
return domainObj.hasCapability(c)
|| (allowDelegation && delegation.doesDelegateCapability(c));
}
// For the reduce step below.