Revert "Upgraded eslint & eslint-config-airbnb"

This commit is contained in:
David
2016-12-12 16:06:13 +01:00
committed by GitHub
parent 0921af04d5
commit 99bfab89b7
71 changed files with 506 additions and 640 deletions
@@ -1,4 +1,4 @@
import { range } from 'lodash';
import _ from 'lodash';
describe('ArrayUtils', () => {
const ArrayUtils = require('../array-utils');
@@ -7,42 +7,34 @@ describe('ArrayUtils', () => {
const f = ArrayUtils.uniformSelect;
it('it should select the array elements uniformly, including the endpoints', () => {
{
const arr = ['x', 'y'];
expect(f(arr, 3)).toEqual(['x', 'y']);
expect(f(arr, 2)).toEqual(['x', 'y']);
}
expect(f(['x', 'y'], 3)).toEqual(['x', 'y']);
expect(f(['x', 'y'], 2)).toEqual(['x', 'y']);
{
const arr = ['A', 'B', 'C', 'D', 'E'];
expect(f(arr, 6)).toEqual(['A', 'B', 'C', 'D', 'E']);
expect(f(arr, 5)).toEqual(['A', 'B', 'C', 'D', 'E']);
expect(f(arr, 4)).toEqual(['A', 'B', 'D', 'E']);
expect(f(arr, 3)).toEqual(['A', 'C', 'E']);
expect(f(arr, 2)).toEqual(['A', 'E']);
}
expect(f(['A', 'B', 'C', 'D', 'E'], 6)).toEqual(['A', 'B', 'C', 'D', 'E']);
expect(f(['A', 'B', 'C', 'D', 'E'], 5)).toEqual(['A', 'B', 'C', 'D', 'E']);
expect(f(['A', 'B', 'C', 'D', 'E'], 4)).toEqual(['A', 'B', 'D', 'E']);
expect(f(['A', 'B', 'C', 'D', 'E'], 3)).toEqual(['A', 'C', 'E']);
expect(f(['A', 'B', 'C', 'D', 'E'], 2)).toEqual(['A', 'E']);
{
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
expect(f(arr, 12)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
expect(f(arr, 11)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
expect(f(arr, 10)).toEqual([1, 2, 3, 4, 5, 7, 8, 9, 10, 11]);
expect(f(arr, 9)).toEqual([1, 2, 3, 5, 6, 7, 9, 10, 11]);
expect(f(arr, 8)).toEqual([1, 2, 4, 5, 7, 8, 10, 11]);
expect(f(arr, 7)).toEqual([1, 2, 4, 6, 8, 10, 11]);
expect(f(arr, 6)).toEqual([1, 3, 5, 7, 9, 11]);
expect(f(arr, 5)).toEqual([1, 3, 6, 9, 11]);
expect(f(arr, 4)).toEqual([1, 4, 8, 11]);
expect(f(arr, 3)).toEqual([1, 6, 11]);
expect(f(arr, 2)).toEqual([1, 11]);
}
expect(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 12)).toEqual(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
);
expect(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 11)).toEqual(
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]);
expect(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 10)).toEqual([1, 2, 3, 4, 5, 7, 8, 9, 10, 11]
);
expect(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 9)).toEqual([1, 2, 3, 5, 6, 7, 9, 10, 11]);
expect(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 8)).toEqual([1, 2, 4, 5, 7, 8, 10, 11]);
expect(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 7)).toEqual([1, 2, 4, 6, 8, 10, 11]);
expect(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 6)).toEqual([1, 3, 5, 7, 9, 11]);
expect(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 5)).toEqual([1, 3, 6, 9, 11]);
expect(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 4)).toEqual([1, 4, 8, 11]);
expect(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 3)).toEqual([1, 6, 11]);
expect(f([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 2)).toEqual([1, 11]);
{
const arr = range(1, 10001);
expect(f(arr, 4)).toEqual([1, 3334, 6667, 10000]);
expect(f(arr, 3)).toEqual([1, 5000, 10000]);
expect(f(arr, 2)).toEqual([1, 10000]);
}
expect(f(_.range(1, 10001), 4)).toEqual([1, 3334, 6667, 10000]);
expect(f(_.range(1, 10001), 3)).toEqual([1, 5000, 10000]);
expect(f(_.range(1, 10001), 2)).toEqual([1, 10000]);
});
});
});
@@ -154,7 +154,7 @@ describe('SearchUtils', () => {
const fun = SearchUtils.makeRegExp;
it('should make a regexp from any string', () => {
expect(fun().source).toEqual((new RegExp()).source);
expect(fun().source).toEqual((new RegExp).source);
expect(fun('que').source).toEqual((new RegExp('que')).source);
// invalid string
expect(fun('que[').source).toEqual((new RegExp('que\\[')).source);
+3 -3
View File
@@ -1,11 +1,11 @@
import { range } from 'lodash';
import _ from 'lodash';
export function uniformSelect(array, size) {
if (size > array.length) {
return array;
}
return range(size).map(index =>
array[parseInt(index * (array.length / (size - (1 - 1e-9))), 10)]
return _.range(size).map(index =>
array[parseInt(index * array.length / (size - 1 + 1e-9), 10)]
);
}
+1 -1
View File
@@ -17,7 +17,7 @@ const letterRange = endLetterRange - startLetterRange;
export function text2degree(text) {
const input = text.substr(0, 2).toUpperCase();
let num = 0;
for (let i = 0; i < input.length; i += 1) {
for (let i = 0; i < input.length; i++) {
const charCode = Math.max(Math.min(input[i].charCodeAt(), endLetterRange), startLetterRange);
num += Math.pow(letterRange, input.length - i - 1) * (charCode - startLetterRange);
}
@@ -1,4 +1,4 @@
import { zipObject } from 'lodash';
import _ from 'lodash';
import { scaleLinear } from 'd3-scale';
import { extent } from 'd3-array';
@@ -104,9 +104,10 @@ function mergeMetrics(node) {
return node;
}
return Object.assign({}, node, {
metrics: (metrics[node.shape] || [])
metrics: _(metrics[node.shape])
.map((fn, name) => [name, fn(node)])
.fromPairs()
.value()
});
}
@@ -120,7 +121,7 @@ function handleAdd(nodes) {
function handleUpdated(updatedNodes, prevNodes) {
const modifiedNodesIndex = zipObject((updatedNodes || []).map(n => [n.id, n]));
const modifiedNodesIndex = _.zipObject((updatedNodes || []).map(n => [n.id, n]));
return prevNodes.toIndexedSeq().toJS().map(n => (
Object.assign({}, mergeMetrics(n), modifiedNodesIndex[n.id])
));
+1 -1
View File
@@ -1,7 +1,7 @@
import React from 'react';
export default class DelayedShow extends React.Component {
export class DelayedShow extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
+5 -4
View File
@@ -18,7 +18,7 @@ function setInlineStyles(svg, target, emptySvgDeclarationComputed) {
function explicitlySetStyle(element, targetEl) {
const cSSStyleDeclarationComputed = getComputedStyle(element);
let computedStyleStr = '';
each(cSSStyleDeclarationComputed, (key) => {
each(cSSStyleDeclarationComputed, key => {
const value = cSSStyleDeclarationComputed.getPropertyValue(key);
if (value !== emptySvgDeclarationComputed.getPropertyValue(key) && !cssSkipValues[value]) {
computedStyleStr += `${key}:${value};`;
@@ -55,7 +55,8 @@ function setInlineStyles(svg, target, emptySvgDeclarationComputed) {
// hardcode computed css styles inside svg
const allElements = traverse(svg);
const allTargetElements = traverse(target);
for (let i = allElements.length - 1; i >= 0; i -= 1) {
let i = allElements.length;
while (i--) {
explicitlySetStyle(allElements[i], allTargetElements[i]);
}
@@ -73,11 +74,11 @@ function download(source, name) {
if (name) {
filename = name;
} else if (window.document.title) {
filename = `${window.document.title.replace(/[^a-z0-9]/gi, '-').toLowerCase()}-${(+new Date())}`;
filename = `${window.document.title.replace(/[^a-z0-9]/gi, '-').toLowerCase()}-${(+new Date)}`;
}
const url = window.URL.createObjectURL(new Blob(source,
{ type: 'text/xml' }
{type: 'text\/xml'}
));
const a = document.createElement('a');
+4 -4
View File
@@ -1,12 +1,12 @@
import { includes } from 'lodash';
import { scaleLog } from 'd3-scale';
import React from 'react';
import { formatMetricSvg } from './string-utils';
import { colors } from './color-utils';
import React from 'react';
export function getClipPathDefinition(clipId, size, height,
x = -size * 0.5, y = (size * 0.5) - height) {
x = -size * 0.5, y = size * 0.5 - height) {
return (
<defs>
<clipPath id={clipId}>
@@ -44,7 +44,7 @@ export function getMetricValue(metric, size) {
let displayedValue = Number(value).toFixed(1);
if (displayedValue > 0 && (!max || displayedValue < max)) {
const baseline = 0.1;
displayedValue = (valuePercentage * (1 - (baseline * 2))) + baseline;
displayedValue = valuePercentage * (1 - baseline * 2) + baseline;
} else if (displayedValue >= m.max && displayedValue > 0) {
displayedValue = 1;
}
@@ -2,7 +2,7 @@ import { fromJS, List as makeList } from 'immutable';
export function getNetworkNodes(nodes) {
const networks = {};
nodes.forEach(node => (node.get('networks') || makeList()).forEach((n) => {
nodes.forEach(node => (node.get('networks') || makeList()).forEach(n => {
const networkId = n.get('id');
networks[networkId] = (networks[networkId] || []).concat([node.get('id')]);
}));
+5 -5
View File
@@ -132,7 +132,7 @@ export function searchTopology(nodes, { prefix, query, metric, comp, value }) {
// metadata
if (node.get('metadata')) {
node.get('metadata').forEach((field) => {
node.get('metadata').forEach(field => {
const keyPath = [nodeId, 'metadata', field.get('id')];
nodeMatches = findNodeMatch(nodeMatches, keyPath, field.get('value'),
query, prefix, field.get('label'), field.get('truncate'));
@@ -141,7 +141,7 @@ export function searchTopology(nodes, { prefix, query, metric, comp, value }) {
// parents and relatives
if (node.get('parents')) {
node.get('parents').forEach((parent) => {
node.get('parents').forEach(parent => {
const keyPath = [nodeId, 'parents', parent.get('id')];
nodeMatches = findNodeMatch(nodeMatches, keyPath, parent.get('label'),
query, prefix, parent.get('topologyId'));
@@ -153,7 +153,7 @@ export function searchTopology(nodes, { prefix, query, metric, comp, value }) {
if (tables) {
tables.forEach((table) => {
if (table.get('rows')) {
table.get('rows').forEach((field) => {
table.get('rows').forEach(field => {
const keyPath = [nodeId, 'tables', field.get('id')];
nodeMatches = findNodeMatch(nodeMatches, keyPath, field.get('value'),
query, prefix, field.get('label'));
@@ -164,7 +164,7 @@ export function searchTopology(nodes, { prefix, query, metric, comp, value }) {
} else if (metric) {
const metrics = node.get('metrics');
if (metrics) {
metrics.forEach((field) => {
metrics.forEach(field => {
const keyPath = [nodeId, 'metrics', field.get('id')];
nodeMatches = findNodeMatchMetric(nodeMatches, keyPath, field.get('value'),
field.get('label'), metric, comp, value);
@@ -291,7 +291,7 @@ export function applyPinnedSearches(state) {
const pinnedSearches = state.get('pinnedSearches');
if (pinnedSearches.size > 0) {
state.get('pinnedSearches').forEach((query) => {
state.get('pinnedSearches').forEach(query => {
const parsed = parseQuery(query);
if (parsed) {
const nodeMatches = searchTopology(state.get('nodes'), parsed);
+1 -1
View File
@@ -3,7 +3,7 @@ import debug from 'debug';
const log = debug('scope:storage-utils');
// localStorage detection
const storage = (typeof Storage) !== 'undefined' ? window.localStorage : null;
const storage = typeof(Storage) !== 'undefined' ? window.localStorage : null;
export function storageGet(key, defaultValue) {
if (storage && storage.getItem(key) !== undefined) {
+7 -7
View File
@@ -19,7 +19,7 @@ export function getDefaultTopology(topologies) {
.flatMap(t => makeList([t]).concat(t.get('sub_topologies', makeList())));
return flatTopologies
.sortBy((t) => {
.sortBy(t => {
const index = TOPOLOGY_DISPLAY_PRIORITY.indexOf(t.get('id'));
return index === -1 ? Infinity : index;
})
@@ -53,7 +53,7 @@ export function buildTopologyCacheId(topologyId, topologyOptions) {
export function findTopologyById(subTree, topologyId) {
let foundTopology;
subTree.forEach((topology) => {
subTree.forEach(topology => {
if (endsWith(topology.get('url'), topologyId)) {
foundTopology = topology;
}
@@ -66,7 +66,7 @@ export function findTopologyById(subTree, topologyId) {
}
export function updateNodeDegrees(nodes, edges) {
return nodes.map((node) => {
return nodes.map(node => {
const nodeId = node.get('id');
const degree = edges.count(edge => edge.get('source') === nodeId
|| edge.get('target') === nodeId);
@@ -76,7 +76,7 @@ export function updateNodeDegrees(nodes, edges) {
/* set topology.id and parentId for sub-topologies in place */
export function updateTopologyIds(topologies, parentId) {
return topologies.map((topology) => {
return topologies.map(topology => {
const result = Object.assign({}, topology);
result.id = topology.url.split('/').pop();
if (parentId) {
@@ -90,7 +90,7 @@ export function updateTopologyIds(topologies, parentId) {
}
export function addTopologyFullname(topologies) {
return topologies.map((t) => {
return topologies.map(t => {
if (!t.sub_topologies) {
return Object.assign({}, t, {fullName: t.name});
}
@@ -108,10 +108,10 @@ export function addTopologyFullname(topologies) {
export function setTopologyUrlsById(topologyUrlsById, topologies) {
let urlMap = topologyUrlsById;
if (topologies) {
topologies.forEach((topology) => {
topologies.forEach(topology => {
urlMap = urlMap.set(topology.id, topology.url);
if (topology.sub_topologies) {
topology.sub_topologies.forEach((subTopology) => {
topology.sub_topologies.forEach(subTopology => {
urlMap = urlMap.set(subTopology.id, subTopology.url);
});
}
@@ -49,7 +49,7 @@ function consolidateBuffer() {
size(toUpdate), 'remove', size(toRemove));
// check if an added node in first was updated in second -> add second update
toAdd = map(toAdd, (node) => {
toAdd = map(toAdd, node => {
const updateNode = find(second.update, {id: node.id});
if (updateNode) {
toUpdate = reject(toUpdate, {id: node.id});
@@ -62,7 +62,7 @@ function consolidateBuffer() {
// no action needed, successive updates are fine
// check if an added node in first was removed in second -> dont add, dont remove
each(first.add, (node) => {
each(first.add, node => {
const removedNode = find(second.remove, {id: node.id});
if (removedNode) {
toAdd = reject(toAdd, {id: node.id});
@@ -71,7 +71,7 @@ function consolidateBuffer() {
});
// check if an updated node in first was removed in second -> remove
each(first.update, (node) => {
each(first.update, node => {
const removedNode = find(second.remove, {id: node.id});
if (removedNode) {
toUpdate = reject(toUpdate, {id: node.id});