From ba48a861bc5a652ce67bca7ac8bfe5eca66101e2 Mon Sep 17 00:00:00 2001 From: Quincy Morgan <2046746+quincylvania@users.noreply.github.com> Date: Tue, 10 Nov 2020 14:19:11 -0500 Subject: [PATCH] Enable curly and block-spacing eslint rules --- .eslintrc | 2 ++ modules/actions/delete_member.js | 3 ++- modules/actions/disconnect.js | 6 ++--- modules/behavior/select.js | 12 +++++---- modules/core/difference.js | 3 ++- modules/core/graph.js | 3 +-- modules/geo/geom.js | 12 ++++++--- modules/osm/entity.js | 3 +-- modules/osm/intersection.js | 21 +++++++++------ modules/osm/lanes.js | 30 ++++++++++++--------- modules/osm/multipolygon.js | 43 ++++++++++++++++++------------- modules/osm/relation.js | 6 +++-- modules/osm/way.js | 10 +++---- modules/svg/labels.js | 3 +-- modules/svg/lines.js | 5 ++-- modules/svg/midpoints.js | 3 +-- modules/ui/fields/address.js | 12 +++------ modules/ui/fields/restrictions.js | 4 ++- modules/ui/intro/helper.js | 13 ++++++---- modules/ui/intro/line.js | 7 ++--- modules/ui/preset_icon.js | 18 +++++-------- modules/util/keybinding.js | 8 ++++-- modules/util/util.js | 3 +-- modules/util/zoom_pan.js | 15 ++++++++--- 24 files changed, 138 insertions(+), 107 deletions(-) diff --git a/.eslintrc b/.eslintrc index a99c83f4c..2e16fb51f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,9 +19,11 @@ "array-callback-return": "warn", "arrow-spacing": "warn", "block-scoped-var": "error", + "block-spacing": ["warn", "always"], "brace-style": ["warn", "1tbs", { "allowSingleLine": true }], "class-methods-use-this": "error", "complexity": ["warn", 50], + "curly": ["warn", "multi-line"], "default-case-last": "error", "default-param-last": "error", "dot-notation": "error", diff --git a/modules/actions/delete_member.js b/modules/actions/delete_member.js index 0404508d1..81715eae4 100644 --- a/modules/actions/delete_member.js +++ b/modules/actions/delete_member.js @@ -8,8 +8,9 @@ export function actionDeleteMember(relationId, memberIndex) { graph = graph.replace(relation); - if (relation.isDegenerate()) + if (relation.isDegenerate()) { graph = actionDeleteRelation(relation.id)(graph); + } return graph; }; diff --git a/modules/actions/disconnect.js b/modules/actions/disconnect.js index 262a02826..1324cad03 100644 --- a/modules/actions/disconnect.js +++ b/modules/actions/disconnect.js @@ -80,8 +80,7 @@ export function actionDisconnect(nodeId, newNodeId) { action.disabled = function(graph) { var connections = action.connections(graph); - if (connections.length === 0) - return 'not_connected'; + if (connections.length === 0) return 'not_connected'; var parentWays = graph.parentWays(graph.entity(nodeId)); var seenRelationIds = {}; @@ -105,8 +104,7 @@ export function actionDisconnect(nodeId, newNodeId) { }); }); - if (sharedRelation) - return 'relation'; + if (sharedRelation) return 'relation'; }; diff --git a/modules/behavior/select.js b/modules/behavior/select.js index b4f347114..67312da97 100644 --- a/modules/behavior/select.js +++ b/modules/behavior/select.js @@ -256,11 +256,13 @@ export function behaviorSelect(context) { var datum = pointerInfo.firstEvent.target.__data__; var entity = (datum && datum.properties && datum.properties.entity) || datum; - if (context.graph().hasEntity(entity.id)) return { - pointerId: pointerId, - entityId: entity.id, - selected: selectedIDs.indexOf(entity.id) !== -1 - }; + if (context.graph().hasEntity(entity.id)) { + return { + pointerId: pointerId, + entityId: entity.id, + selected: selectedIDs.indexOf(entity.id) !== -1 + }; + } } return null; } diff --git a/modules/core/difference.js b/modules/core/difference.js index 21c8778f2..073fef207 100644 --- a/modules/core/difference.js +++ b/modules/core/difference.js @@ -213,8 +213,9 @@ export function coreDifference(base, head) { if (extent && (!h || !h.intersects(extent, head)) && - (!b || !b.intersects(extent, base))) + (!b || !b.intersects(extent, base))) { continue; + } result[id] = h; diff --git a/modules/core/graph.js b/modules/core/graph.js index 2d426b323..9bfbd42f9 100644 --- a/modules/core/graph.js +++ b/modules/core/graph.js @@ -143,8 +143,7 @@ coreGraph.prototype = { for (i = 0; i < entities.length; i++) { var entity = entities[i]; - if (!entity.visible || (!force && base.entities[entity.id])) - continue; + if (!entity.visible || (!force && base.entities[entity.id])) continue; // Merging data into the base graph base.entities[entity.id] = entity; diff --git a/modules/geo/geom.js b/modules/geo/geom.js index ec5ccb576..53d87457a 100644 --- a/modules/geo/geom.js +++ b/modules/geo/geom.js @@ -326,14 +326,18 @@ export function geoViewportEdge(point, dimensions) { var x = 0; var y = 0; - if (point[0] > dimensions[0] - pad[1]) + if (point[0] > dimensions[0] - pad[1]) { x = -10; - if (point[0] < pad[3]) + } + if (point[0] < pad[3]) { x = 10; - if (point[1] > dimensions[1] - pad[2]) + } + if (point[1] > dimensions[1] - pad[2]) { y = -10; - if (point[1] < pad[0]) + } + if (point[1] < pad[0]) { y = 10; + } if (x || y) { return [x, y]; diff --git a/modules/osm/entity.js b/modules/osm/entity.js index 46e3b261b..406673332 100644 --- a/modules/osm/entity.js +++ b/modules/osm/entity.js @@ -114,8 +114,7 @@ osmEntity.prototype = { copy: function(resolver, copies) { - if (copies[this.id]) - return copies[this.id]; + if (copies[this.id]) return copies[this.id]; var copy = osmEntity(this, { id: undefined, user: undefined, version: undefined }); copies[this.id] = copy; diff --git a/modules/osm/intersection.js b/modules/osm/intersection.js index e1dfbb707..5b69fbc0b 100644 --- a/modules/osm/intersection.js +++ b/modules/osm/intersection.js @@ -441,8 +441,7 @@ export function osmIntersection(graph, startVertexId, maxDistance) { } // stop looking if we find a "direct" restriction (matching FROM, VIA, TO) - if (restrict && restrict.direct) - break; + if (restrict && restrict.direct) break; } nextWays.push({ way: way, restrict: restrict }); @@ -607,19 +606,25 @@ export function osmInferRestriction(graph, turn, projection) { var angle = (geoAngle(fromVertex, fromNode, projection) - geoAngle(toVertex, toNode, projection)) * 180 / Math.PI; - while (angle < 0) + while (angle < 0) { angle += 360; + } - if (fromNode === toNode) + if (fromNode === toNode) { return 'no_u_turn'; - if ((angle < 23 || angle > 336) && fromOneWay && toOneWay) + } + if ((angle < 23 || angle > 336) && fromOneWay && toOneWay) { return 'no_u_turn'; // wider tolerance for u-turn if both ways are oneway - if ((angle < 40 || angle > 319) && fromOneWay && toOneWay && turn.from.vertex !== turn.to.vertex) + } + if ((angle < 40 || angle > 319) && fromOneWay && toOneWay && turn.from.vertex !== turn.to.vertex) { return 'no_u_turn'; // even wider tolerance for u-turn if there is a via way (from !== to) - if (angle < 158) + } + if (angle < 158) { return 'no_right_turn'; - if (angle > 202) + } + if (angle > 202) { return 'no_left_turn'; + } return 'no_straight_on'; } diff --git a/modules/osm/lanes.js b/modules/osm/lanes.js index cecf09f2a..8f103ecb2 100644 --- a/modules/osm/lanes.js +++ b/modules/osm/lanes.js @@ -225,16 +225,22 @@ function parseBicycleWay(tag) { function mapToLanesObj(lanesObj, data, key) { - if (data.forward) data.forward.forEach(function(l, i) { - if (!lanesObj.forward[i]) lanesObj.forward[i] = {}; - lanesObj.forward[i][key] = l; - }); - if (data.backward) data.backward.forEach(function(l, i) { - if (!lanesObj.backward[i]) lanesObj.backward[i] = {}; - lanesObj.backward[i][key] = l; - }); - if (data.unspecified) data.unspecified.forEach(function(l, i) { - if (!lanesObj.unspecified[i]) lanesObj.unspecified[i] = {}; - lanesObj.unspecified[i][key] = l; - }); + if (data.forward) { + data.forward.forEach(function(l, i) { + if (!lanesObj.forward[i]) lanesObj.forward[i] = {}; + lanesObj.forward[i][key] = l; + }); + } + if (data.backward) { + data.backward.forEach(function(l, i) { + if (!lanesObj.backward[i]) lanesObj.backward[i] = {}; + lanesObj.backward[i][key] = l; + }); + } + if (data.unspecified) { + data.unspecified.forEach(function(l, i) { + if (!lanesObj.unspecified[i]) lanesObj.unspecified[i] = {}; + lanesObj.unspecified[i][key] = l; + }); + } } diff --git a/modules/osm/multipolygon.js b/modules/osm/multipolygon.js index bb1860c3b..bbbb6b337 100644 --- a/modules/osm/multipolygon.js +++ b/modules/osm/multipolygon.js @@ -40,24 +40,31 @@ export function osmOldMultipolygonOuterMemberOfRelation(entity, graph) { // For fixing up rendering of multipolygons with tags on the outer member. // https://github.com/openstreetmap/iD/issues/613 export function osmIsOldMultipolygonOuterMember(entity, graph) { - if (entity.type !== 'way' || Object.keys(entity.tags).filter(osmIsInterestingTag).length === 0) + if (entity.type !== 'way' || + Object.keys(entity.tags).filter(osmIsInterestingTag).length === 0) { return false; + } var parents = graph.parentRelations(entity); - if (parents.length !== 1) - return false; + if (parents.length !== 1) return false; var parent = parents[0]; - if (!parent.isMultipolygon() || Object.keys(parent.tags).filter(osmIsInterestingTag).length > 1) + if (!parent.isMultipolygon() || + Object.keys(parent.tags).filter(osmIsInterestingTag).length > 1) { return false; + } var members = parent.members, member; for (var i = 0; i < members.length; i++) { member = members[i]; - if (member.id === entity.id && member.role && member.role !== 'outer') - return false; // Not outer member - if (member.id !== entity.id && (!member.role || member.role === 'outer')) - return false; // Not a simple multipolygon + if (member.id === entity.id && member.role && member.role !== 'outer') { + // Not outer member + return false; + } + if (member.id !== entity.id && (!member.role || member.role === 'outer')) { + // Not a simple multipolygon + return false; + } } return parent; @@ -65,33 +72,33 @@ export function osmIsOldMultipolygonOuterMember(entity, graph) { export function osmOldMultipolygonOuterMember(entity, graph) { - if (entity.type !== 'way') - return false; + if (entity.type !== 'way') return false; var parents = graph.parentRelations(entity); - if (parents.length !== 1) - return false; + if (parents.length !== 1) return false; var parent = parents[0]; - if (!parent.isMultipolygon() || Object.keys(parent.tags).filter(osmIsInterestingTag).length > 1) + if (!parent.isMultipolygon() || + Object.keys(parent.tags).filter(osmIsInterestingTag).length > 1) { return false; + } var members = parent.members, member, outerMember; for (var i = 0; i < members.length; i++) { member = members[i]; if (!member.role || member.role === 'outer') { - if (outerMember) - return false; // Not a simple multipolygon + if (outerMember) return false; // Not a simple multipolygon outerMember = member; } } - if (!outerMember) - return false; + if (!outerMember) return false; var outerEntity = graph.hasEntity(outerMember.id); - if (!outerEntity || !Object.keys(outerEntity.tags).filter(osmIsInterestingTag).length) + if (!outerEntity || + !Object.keys(outerEntity.tags).filter(osmIsInterestingTag).length) { return false; + } return outerEntity; } diff --git a/modules/osm/relation.js b/modules/osm/relation.js index 2c33b7b0c..f2c94d3b8 100644 --- a/modules/osm/relation.js +++ b/modules/osm/relation.js @@ -330,14 +330,16 @@ Object.assign(osmRelation.prototype, { for (o = 0; o < outers.length; o++) { outer = outers[o]; - if (geoPolygonContainsPolygon(outer, inner)) + if (geoPolygonContainsPolygon(outer, inner)) { return o; + } } for (o = 0; o < outers.length; o++) { outer = outers[o]; - if (geoPolygonIntersectsPolygon(outer, inner, false)) + if (geoPolygonIntersectsPolygon(outer, inner, false)) { return o; + } } } diff --git a/modules/osm/way.js b/modules/osm/way.js index 741621de3..881ad5d84 100644 --- a/modules/osm/way.js +++ b/modules/osm/way.js @@ -155,8 +155,10 @@ Object.assign(osmWay.prototype, { // implied oneway tag.. for (var key in this.tags) { - if (key in osmOneWayTags && (this.tags[key] in osmOneWayTags[key])) + if (key in osmOneWayTags && + (this.tags[key] in osmOneWayTags[key])) { return true; + } } return false; }, @@ -232,10 +234,8 @@ Object.assign(osmWay.prototype, { }, isArea: function() { - if (this.tags.area === 'yes') - return true; - if (!this.isClosed() || this.tags.area === 'no') - return false; + if (this.tags.area === 'yes') return true; + if (!this.isClosed() || this.tags.area === 'no') return false; return this.tagSuggestingArea() !== null; }, diff --git a/modules/svg/labels.js b/modules/svg/labels.js index 60832d7cf..f151631e1 100644 --- a/modules/svg/labels.js +++ b/modules/svg/labels.js @@ -315,8 +315,7 @@ export function svgLabels(projection, context) { var preset = geometry === 'area' && presetManager.match(entity, graph); var icon = preset && !shouldSkipIcon(preset) && preset.icon; - if (!icon && !utilDisplayName(entity)) - continue; + if (!icon && !utilDisplayName(entity)) continue; for (k = 0; k < labelStack.length; k++) { var matchGeom = labelStack[k][0]; diff --git a/modules/svg/lines.js b/modules/svg/lines.js index 3b326a1b8..3d19b8e60 100644 --- a/modules/svg/lines.js +++ b/modules/svg/lines.js @@ -185,10 +185,11 @@ export function svgLines(projection, context) { var layer = this.parentNode.__data__; var data = pathdata[layer] || []; return data.filter(function(d) { - if (isSelected) + if (isSelected) { return context.selectedIDs().indexOf(d.id) !== -1; - else + } else { return context.selectedIDs().indexOf(d.id) === -1; + } }); }; } diff --git a/modules/svg/midpoints.js b/modules/svg/midpoints.js index 9e33ddfc5..91c5150ad 100644 --- a/modules/svg/midpoints.js +++ b/modules/svg/midpoints.js @@ -105,8 +105,7 @@ export function svgMidpoints(projection, context) { function midpointFilter(d) { - if (midpoints[d.id]) - return true; + if (midpoints[d.id]) return true; for (var i = 0; i < d.parents.length; i++) { if (filter(d.parents[i])) { diff --git a/modules/ui/fields/address.js b/modules/ui/fields/address.js index 6564e1f2b..7abefddc8 100644 --- a/modules/ui/fields/address.js +++ b/modules/ui/fields/address.js @@ -91,16 +91,12 @@ export function uiFieldAddress(field, context) { function isAddressable(d) { if (d.tags.name) { - if (d.tags.admin_level === '8' && d.tags.boundary === 'administrative') - return true; - if (d.tags.border_type === 'city') - return true; - if (d.tags.place === 'city' || d.tags.place === 'town' || d.tags.place === 'village') - return true; + if (d.tags.admin_level === '8' && d.tags.boundary === 'administrative') return true; + if (d.tags.border_type === 'city') return true; + if (d.tags.place === 'city' || d.tags.place === 'town' || d.tags.place === 'village') return true; } - if (d.tags['addr:city']) - return true; + if (d.tags['addr:city']) return true; return false; } diff --git a/modules/ui/fields/restrictions.js b/modules/ui/fields/restrictions.js index d3a82e0f6..3d2c0b7bd 100644 --- a/modules/ui/fields/restrictions.js +++ b/modules/ui/fields/restrictions.js @@ -534,8 +534,10 @@ export function uiFieldRestrictions(field, context) { for (var i = 0; i < datum.via.ways.length; i++) { var prev = names[names.length - 1]; var curr = displayName(datum.via.ways[i], vgraph); - if (!prev || curr !== prev) // collapse identical names + if (!prev || curr !== prev) { + // collapse identical names names.push(curr); + } } help diff --git a/modules/ui/intro/helper.js b/modules/ui/intro/helper.js index 9e1f72e2b..7c565d7be 100644 --- a/modules/ui/intro/helper.js +++ b/modules/ui/intro/helper.js @@ -49,7 +49,8 @@ var helpStringReplacements; // with custom `replacements` export function helpHtml(id, replacements) { // only load these the first time - if (!helpStringReplacements) helpStringReplacements = { + if (!helpStringReplacements) { + helpStringReplacements = { // insert icons corresponding to various UI elements point_icon: icon('#iD-icon-point', 'inline'), line_icon: icon('#iD-icon-line', 'inline'), @@ -144,7 +145,8 @@ export function helpHtml(id, replacements) { start_the_walkthrough: t.html('splash.walkthrough'), help: t.html('help.title'), ok: t.html('intro.ok') - }; + }; + } var reps; if (replacements) { @@ -255,10 +257,11 @@ export function selectMenuItem(context, operation) { export function transitionTime(point1, point2) { var distance = geoSphericalDistance(point1, point2); - if (distance === 0) + if (distance === 0) { return 0; - else if (distance < 80) + } else if (distance < 80) { return 500; - else + } else { return 1000; + } } diff --git a/modules/ui/intro/line.js b/modules/ui/intro/line.js index 2ab2543b9..b5143bfcc 100644 --- a/modules/ui/intro/line.js +++ b/modules/ui/intro/line.js @@ -211,12 +211,13 @@ export function uiIntroLine(context, reveal) { reveal('.surface', continueLineText); context.on('enter.intro', function(mode) { - if (mode.id === 'draw-line') + if (mode.id === 'draw-line') { return; - else if (mode.id === 'select') + } else if (mode.id === 'select') { return continueTo(chooseCategoryRoad); - else + } else { return chapter.restart(); + } }); function continueTo(nextStep) { diff --git a/modules/ui/preset_icon.js b/modules/ui/preset_icon.js index dbdfcad87..044150be5 100644 --- a/modules/ui/preset_icon.js +++ b/modules/ui/preset_icon.js @@ -23,18 +23,12 @@ export function uiPresetIcon() { function getIcon(p, geom) { - if (isSmall() && p.isFallback && p.isFallback()) - return 'iD-icon-' + p.id; - else if (p.icon) - return p.icon; - else if (geom === 'line') - return 'iD-other-line'; - else if (geom === 'vertex') - return p.isFallback() ? '' : 'temaki-vertex'; - else if (isSmall() && geom === 'point') - return ''; - else - return 'maki-marker-stroked'; + if (isSmall() && p.isFallback && p.isFallback()) return 'iD-icon-' + p.id; + if (p.icon) return p.icon; + if (geom === 'line') return 'iD-other-line'; + if (geom === 'vertex') return p.isFallback() ? '' : 'temaki-vertex'; + if (isSmall() && geom === 'point') return ''; + return 'maki-marker-stroked'; } diff --git a/modules/util/keybinding.js b/modules/util/keybinding.js index 16ded2fe5..67c3dd68e 100644 --- a/modules/util/keybinding.js +++ b/modules/util/keybinding.js @@ -60,11 +60,15 @@ export function utilKeybinding(namespace) { if (binding.event.key === undefined) { isMatch = false; } else if (Array.isArray(binding.event.key)) { - if (binding.event.key.map(function(s) { return s.toLowerCase(); }).indexOf(event.key.toLowerCase()) === -1) + if (binding.event.key.map(function(s) { + return s.toLowerCase(); + }).indexOf(event.key.toLowerCase()) === -1) { isMatch = false; + } } else { - if (event.key.toLowerCase() !== binding.event.key.toLowerCase()) + if (event.key.toLowerCase() !== binding.event.key.toLowerCase()) { isMatch = false; + } } } diff --git a/modules/util/util.js b/modules/util/util.js index 37f7f5777..7131a4d3f 100644 --- a/modules/util/util.js +++ b/modules/util/util.js @@ -365,8 +365,7 @@ export function utilPrefixDOMProperty(property) { var n = prefixes.length; var s = document.body; - if (property in s) - return property; + if (property in s) return property; property = property.substr(0, 1).toUpperCase() + property.substr(1); diff --git a/modules/util/zoom_pan.js b/modules/util/zoom_pan.js index ccfefd114..465b6db40 100644 --- a/modules/util/zoom_pan.js +++ b/modules/util/zoom_pan.js @@ -152,8 +152,14 @@ export function utilZoomPan() { b = typeof transform === 'function' ? transform.apply(that, args) : transform, i = interpolate(a.invert(p).concat(w / a.k), b.invert(p).concat(w / b.k)); return function(t) { - if (t === 1) t = b; // Avoid rounding error on end. - else { var l = i(t), k = w / l[2]; t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); } + if (t === 1) { + // Avoid rounding error on end. + t = b; + } else { + var l = i(t); + var k = w / l[2]; + t = new Transform(k, p[0] - l[0] * k, p[1] - l[1] * k); + } g.zoom(null, null, t); }; }); @@ -321,8 +327,9 @@ export function utilZoomPan() { g.pointer0 = g.pointer1; delete g.pointer1; } - if (g.pointer0) g.pointer0[1] = _transform.invert(g.pointer0[0]); - else { + if (g.pointer0) { + g.pointer0[1] = _transform.invert(g.pointer0[0]); + } else { g.end(d3_event); } }