Fix linting for in loops and others

This commit is contained in:
Robert Long 2020-01-07 15:07:17 -08:00
Родитель e8fd4e056f
Коммит 79ac7a5c19
17 изменённых файлов: 95 добавлений и 25 удалений

Просмотреть файл

@ -31,8 +31,9 @@ module.exports = {
"no-unused-vars": ["error", { varsIgnorePattern: "^_", argsIgnorePattern: "^_", ignoreRestSiblings: true }],
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"require-atomic-updates": "warn",
"no-prototype-builtins": "warn"
"require-atomic-updates": "off",
"no-prototype-builtins": "warn",
"guard-for-in": "warn"
},
extends: ["prettier", "plugin:react/recommended", "eslint:recommended"],
settings: {

Просмотреть файл

@ -25,7 +25,7 @@
"precommit": "lint-staged",
"lint": "yarn lint:js && yarn lint:css",
"lint:js": "eslint ./src",
"lint:css": "stylelint './src/**/*.js'",
"lint:css": "stylelint ./src/**/*.js",
"pretest": "yarn lint",
"test": "concurrently --success \"first\" --kill-others \"yarn test-all\" \"yarn test-server\"",
"test-server": "cross-env NODE_ENV=test webpack-dev-server --mode development --port 9091 --content-base ./test/fixtures",

Просмотреть файл

@ -439,9 +439,13 @@ export default class Editor extends EventEmitter {
if (nodeDef.extensions && nodeDef.extensions.MOZ_hubs_components) {
const components = nodeDef.extensions.MOZ_hubs_components;
for (const componentName in components) {
if (!Object.prototype.hasOwnProperty.call(components, componentName)) continue;
const component = components[componentName];
for (const propertyName in component) {
if (!Object.prototype.hasOwnProperty.call(component, propertyName)) continue;
const property = component[propertyName];
if (
@ -1736,6 +1740,8 @@ export default class Editor extends EventEmitter {
}
for (const propertyName in properties) {
if (!Object.prototype.hasOwnProperty.call(properties, propertyName)) continue;
const value = properties[propertyName];
if (value && value.copy) {

Просмотреть файл

@ -10,6 +10,8 @@ export default class SetPropertiesCommand extends Command {
this.oldProperties = {};
for (const propertyName in properties) {
if (!Object.prototype.hasOwnProperty.call(properties, propertyName)) continue;
const value = properties[propertyName];
if (value && value.clone) {

Просмотреть файл

@ -10,6 +10,8 @@ export default class SetPropertiesMultipleCommand extends Command {
this.objectsOldProperties = [];
for (const propertyName in properties) {
if (!Object.prototype.hasOwnProperty.call(properties, propertyName)) continue;
const value = properties[propertyName];
if (value && value.clone) {
@ -24,6 +26,8 @@ export default class SetPropertiesMultipleCommand extends Command {
const objectOldProperties = {};
for (const propertyName in properties) {
if (!Object.prototype.hasOwnProperty.call(properties, propertyName)) continue;
const oldValue = object[propertyName];
if (oldValue && oldValue.clone) {

Просмотреть файл

@ -52,7 +52,7 @@ function initializeValue(source, initialState, state, resetKeys, value, reset, r
if (!source) return;
for (const sourceKey in source) {
if (source.hasOwnProperty(sourceKey)) {
if (Object.prototype.hasOwnProperty.call(source, sourceKey)) {
const targetKey = source[sourceKey];
if (sourceKey === "event") {
@ -149,6 +149,7 @@ function mergeMappings(mappings) {
function deleteValues(state, mappingObj) {
for (const key in mappingObj) {
if (!Object.prototype.hasOwnProperty.call(mappingObj, key)) continue;
const action = mappingObj[key];
delete state[action];
}
@ -207,14 +208,22 @@ export default class InputManager {
if (keyboard.pressed) deleteValues(state, keyboard.pressed);
if (keyboard.keyup) deleteValues(state, keyboard.keyup);
if (keyboard.keydown) deleteValues(state, keyboard.keydown);
if (keyboard.hotkeys) {
for (const binding in keyboard.hotkeys) {
const hotkeys = keyboard.hotkeys;
if (hotkeys) {
for (const binding in hotkeys) {
if (!Object.prototype.hasOwnProperty.call(hotkeys, binding)) continue;
Mousetrap.unbind(binding);
}
deleteValues(state, keyboard.hotkeys);
}
if (keyboard.globalHotkeys) {
for (const binding in keyboard.globalHotkeys) {
const globalHotkeys = keyboard.globalHotkeys;
if (globalHotkeys) {
for (const binding in globalHotkeys) {
if (!Object.prototype.hasOwnProperty.call(globalHotkeys, binding)) continue;
Mousetrap.unbindGlobal(binding);
}
deleteValues(state, keyboard.globalHotkeys);
@ -260,6 +269,8 @@ export default class InputManager {
if (hotkeys) {
for (const binding in hotkeys) {
if (!Object.prototype.hasOwnProperty.call(hotkeys, binding)) continue;
const action = hotkeys[binding];
Mousetrap.bind(binding, () => {
state[action] = true;
@ -275,6 +286,8 @@ export default class InputManager {
if (globalHotkeys) {
for (const binding in globalHotkeys) {
if (!Object.prototype.hasOwnProperty.call(globalHotkeys, binding)) continue;
const action = globalHotkeys[binding];
Mousetrap.bindGlobal(binding, () => {
state[action] = true;
@ -339,6 +352,8 @@ export default class InputManager {
let preventDefault = false;
for (const key in keyMappings) {
if (!Object.prototype.hasOwnProperty.call(keyMappings, key)) continue;
const action = keyMappings[key];
if (eventKey === key) {
@ -531,7 +546,7 @@ export default class InputManager {
if (!moveMapping) return;
for (const key in moveMapping) {
if (moveMapping.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(moveMapping, key)) {
if (key === "event") {
this.handleEventMappings(moveMapping.event, event);
} else if (key === "movementX" || key === "movementY") {
@ -559,7 +574,7 @@ export default class InputManager {
if (!wheelMapping) return;
for (const key in wheelMapping) {
if (wheelMapping.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(wheelMapping, key)) {
if (key === "event") {
this.handleEventMappings(wheelMapping.event, event);
} else if (key === "deltaX" || key === "deltaY") {
@ -620,8 +635,12 @@ export default class InputManager {
};
onWindowBlur = () => {
for (const key in this.initialState) {
this.state[key] = this.initialState[key];
const initialState = this.initialState;
for (const key in initialState) {
if (Object.prototype.hasOwnProperty.call(initialState, key)) {
this.state[key] = initialState[key];
}
}
};

Просмотреть файл

@ -263,7 +263,10 @@ class GLTFExporter {
gltfProperty.extensions = {};
}
for (const extensionName in serializedUserData.gltfExtensions) {
const gltfExtensions = serializedUserData.gltfExtensions;
for (const extensionName in gltfExtensions) {
if (!Object.prototype.hasOwnProperty.call(gltfExtensions, extensionName)) continue;
gltfProperty.extensions[extensionName] = serializedUserData.gltfExtensions[extensionName];
this.extensionsUsed[extensionName] = true;
}
@ -300,7 +303,7 @@ class GLTFExporter {
const obj = {};
for (const key in value) {
if (value.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(value, key)) {
obj[key] = this.serializeUserDataProperty(value[key]);
}
}
@ -977,9 +980,13 @@ class GLTFExporter {
const targetNames = [];
const reverseDictionary = {};
if (mesh.morphTargetDictionary !== undefined) {
for (const key in mesh.morphTargetDictionary) {
reverseDictionary[mesh.morphTargetDictionary[key]] = key;
const morphTargetDictionary = mesh.morphTargetDictionary;
if (morphTargetDictionary !== undefined) {
for (const key in morphTargetDictionary) {
if (Object.prototype.hasOwnProperty.call(morphTargetDictionary, key)) {
reverseDictionary[morphTargetDictionary[key]] = key;
}
}
}
@ -989,6 +996,8 @@ class GLTFExporter {
let warned = false;
for (const attributeName in geometry.morphAttributes) {
if (!Object.prototype.hasOwnProperty.call(geometry.morphAttributes, attributeName)) continue;
// glTF 2.0 morph supports only POSITION/NORMAL/TANGENT.
// Three.js doesn't support TANGENT yet.

Просмотреть файл

@ -1161,6 +1161,8 @@ class GLTFLoader {
};
for (const gltfAttributeName in attributes) {
if (!Object.prototype.hasOwnProperty.call(attributes, gltfAttributeName)) continue;
const threeAttributeName = ATTRIBUTES[gltfAttributeName] || gltfAttributeName.toLowerCase();
// Skip attributes already provided by e.g. Draco extension.

Просмотреть файл

@ -66,7 +66,9 @@ function generateHeightfield(geometry, params) {
const heightfieldMesh = new THREE.Mesh(geometry);
const maxSide = Math.max(size.x, size.z);
const distance = params.hasOwnProperty("distance") ? params.distance : Math.max(0.25, Math.pow(maxSide, 1 / 2) / 10);
const distance = Object.prototype.hasOwnProperty.call(params, "distance")
? params.distance
: Math.max(0.25, Math.pow(maxSide, 1 / 2) / 10);
const resolution = Math.ceil(maxSide / distance);
const data = [];

Просмотреть файл

@ -159,10 +159,14 @@ export default function EditorNodeMixin(Object3DClass) {
if (components) {
for (const componentName in components) {
if (!Object.prototype.hasOwnProperty.call(components, componentName)) continue;
const serializedProps = {};
const componentProps = components[componentName];
for (const propName in componentProps) {
if (!Object.prototype.hasOwnProperty.call(componentProps, propName)) continue;
const propValue = componentProps[propName];
if (propValue instanceof Color) {
@ -208,6 +212,8 @@ export default function EditorNodeMixin(Object3DClass) {
const componentProps = {};
for (const key in props) {
if (!Object.prototype.hasOwnProperty.call(props, key)) continue;
const value = props[key];
if (value instanceof Color) {

Просмотреть файл

@ -331,7 +331,9 @@ export default class KitPieceNode extends EditorNodeMixin(Model) {
if (files) {
// Revoke any object urls from the SketchfabZipLoader.
for (const key in files) {
URL.revokeObjectURL(files[key]);
if (Object.prototype.hasOwnProperty.call(files, key)) {
URL.revokeObjectURL(files[key]);
}
}
}
} catch (e) {

Просмотреть файл

@ -14,7 +14,9 @@ function migrateV1ToV2(json) {
const rootUUID = _Math.generateUUID();
const nameToUUID = { [root]: rootUUID };
for (const name in entities) {
nameToUUID[name] = _Math.generateUUID();
if (Object.prototype.hasOwnProperty.call(entities, name)) {
nameToUUID[name] = _Math.generateUUID();
}
}
// Replace names with uuids in entities and add the name property.
@ -39,6 +41,8 @@ function migrateV2ToV3(json) {
json.version = 3;
for (const entityId in json.entities) {
if (!Object.prototype.hasOwnProperty.call(json.entities, entityId)) continue;
const entity = json.entities[entityId];
if (!entity.components) {
@ -102,6 +106,8 @@ function migrateV3ToV4(json) {
json.version = 4;
for (const entityId in json.entities) {
if (!Object.prototype.hasOwnProperty.call(json.entities, entityId)) continue;
const entity = json.entities[entityId];
if (!entity.components) {
@ -311,7 +317,7 @@ export default class SceneNode extends EditorNodeMixin(Scene) {
function hasExtrasOrExtensions(object) {
const userData = object.userData;
for (const key in userData) {
if (userData.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(userData, key)) {
return true;
}
}

Просмотреть файл

@ -119,7 +119,9 @@ export default class SpawnerNode extends EditorNodeMixin(Model) {
if (files) {
// Revoke any object urls from the SketchfabZipLoader.
for (const key in files) {
URL.revokeObjectURL(files[key]);
if (Object.prototype.hasOwnProperty.call(files, key)) {
URL.revokeObjectURL(files[key]);
}
}
}
} catch (e) {

Просмотреть файл

@ -60,7 +60,9 @@ export function serializeProperties(properties) {
const debugProperties = {};
for (const propertyName in properties) {
debugProperties[propertyName] = serializeProperty(properties[propertyName]);
if (Object.prototype.hasOwnProperty.call(properties, propertyName)) {
debugProperties[propertyName] = serializeProperty(properties[propertyName]);
}
}
return debugProperties;

Просмотреть файл

@ -1,6 +1,6 @@
export default function isEmptyObject(object) {
for (const key in object) {
if (object.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(object, key)) {
return false;
}
}

Просмотреть файл

@ -3,14 +3,17 @@ export default function keysEqual(a, b) {
let bKeyCount = 0;
for (const key in a) {
if (!Object.prototype.hasOwnProperty.call(a, key)) continue;
aKeyCount++;
if (!b.hasOwnProperty(key)) {
if (!Object.prototype.hasOwnProperty.call(b, key)) {
return false;
}
}
for (const _bKey in b) {
if (!Object.prototype.hasOwnProperty.call(b, _bKey)) continue;
bKeyCount++;
}

Просмотреть файл

@ -5,6 +5,8 @@ export default function sortEntities(entitiesObj) {
// First add entities without parents
for (const entityId in entitiesObj) {
if (!Object.prototype.hasOwnProperty.call(entitiesObj, entityId)) continue;
const entity = entitiesObj[entityId];
if (!entity.parent || !entitiesObj[entity.parent]) {
@ -29,6 +31,8 @@ export default function sortEntities(entitiesObj) {
// Then sort child entities by their index
for (const parentName in entitiesByParent) {
if (!Object.prototype.hasOwnProperty.call(entitiesByParent, parentName)) continue;
entitiesByParent[parentName].sort((a, b) => {
const entityA = entitiesObj[a];
const entityB = entitiesObj[b];