Skip to content

Commit

Permalink
Chore: Update eslint kibana rules (elastic#286)
Browse files Browse the repository at this point in the history
* chore: replace gulp-util, it is deprecated

see https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5

* chore: fix eslint config extends priority

* chore: update the eslint dependencies

* chore: fix lint-fix task

return the stream so it completes, and fail the task if there are unresolved errors

* chore: tweak eslint config, add config for paths

override some rules, and set env for specific paths

* chore: bump gulp-eslint

* chore: fix code issues caught by linter

these were all the issue found after running the eslint auto-fix

* chore: eslint auto-fix, with hand edits

manually reviewed all changes, hand edited some, fixed a couple it got wrong, and excluded the object.assign rule since it gets the output on that one completely wrong

* chore: prefer object spread fix

replace Object.assign use with object spread, per the eslint rules

* chore: add import order lint rule

* chore: remove offending setState in componentWillUpdate

the code was doing nothing anyway, and was likely a holdover from some changes
  • Loading branch information
w33ble authored Jan 10, 2018
1 parent d4300fc commit 69d7546
Show file tree
Hide file tree
Showing 158 changed files with 813 additions and 794 deletions.
3 changes: 2 additions & 1 deletion common/functions/alterColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export const alterColumn = {
column.name = destination;
column.type = type;

context.rows = context.rows.map(row => Object.assign(omit(row, args.column), {
context.rows = context.rows.map(row => ({
...omit(row, args.column),
[destination]: handler(row[args.column]),
}));

Expand Down
10 changes: 5 additions & 5 deletions common/functions/filterrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export const filterrows = {
}));

return Promise.all(checks)
.then(results => context.rows.filter((row, i) => results[i]))
.then(rows => ({
...context,
rows,
}));
.then(results => context.rows.filter((row, i) => results[i]))
.then(rows => ({
...context,
rows,
}));
},
};
4 changes: 2 additions & 2 deletions common/functions/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ export function Fn(config) {
this.help = config.help || ''; // A short help text
this.args = {};
each(config.args, (arg, name) => {
this.args[name] = new Arg(Object.assign({ name: name }, arg));
this.args[name] = new Arg({ name, ...arg });
each(arg.aliases, alias => {
this.args[alias] = new Arg(Object.assign({ name: name, isAlias: true }, arg));
this.args[alias] = new Arg({ name, ...arg, isAlias: true });
});
});

Expand Down
10 changes: 6 additions & 4 deletions common/functions/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ export const grid = {
if (row.x === column) {
const seriesStyle = seriesStyles[row.color];

acc.push(Object.assign({}, row, {
acc.push({
...row,
style: {
color: get(seriesStyle, 'color'),
},
}));
});
}

return acc;
Expand Down Expand Up @@ -86,9 +87,10 @@ export const grid = {

const summary = mapValues(context.columns, (val, name) => {
if (!val) return;
return Object.assign({}, val, {
return {
...val,
values: getResultValues(context.rows, name, val => val),
});
};
});

return {
Expand Down
2 changes: 1 addition & 1 deletion common/functions/image/image.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { includes } from 'lodash';
import { elasticLogo } from './elastic_logo';
import { fetchImage } from '../../lib/fetch_image';
import { elasticLogo } from './elastic_logo';

export const image = {
name: 'image',
Expand Down
28 changes: 15 additions & 13 deletions common/functions/mapColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,24 @@ export const mapColumn = {
fn: (context, args) => {
const rowPromises = context.rows.map(row => {
return args.expression(!args.context ? null :
{
type: 'datatable',
columns: context.columns,
rows: [row],
})
.then(val => {
if (typeof val === 'object' && val !== null) {
throw new Error ('Expression must return a literal, eg a string, number, boolean, null');
}
return Object.assign({}, row, { [args._]: val });
});
{
type: 'datatable',
columns: context.columns,
rows: [row],
})
.then(val => {
if (typeof val === 'object' && val !== null) {
throw new Error ('Expression must return a literal, eg a string, number, boolean, null');
}

return {
...row,
[args._]: val,
};
});
});

return Promise.all(rowPromises).then(rows => {
Object.assign({}, context, { rows: rows });

if (!context.columns.find(column => column.name === args._)) {
context.columns.push({ name: args._, type: getType(rows[0][args._]) });
}
Expand Down
5 changes: 3 additions & 2 deletions common/functions/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ export const markdown = {
},
fn: (context, args) => {
const compileFunctions = args._.map(str => Handlebars.compile(String(str)));
const ctx = Object.assign({
const ctx = {
columns: [],
rows: [],
type: null,
}, context);
...context,
};

return {
type: 'render',
Expand Down
6 changes: 4 additions & 2 deletions common/functions/pie.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ export const pie = {

// append series style, if there is a match
if (seriesStyle) {
Object.assign(item, { color: get(seriesStyle, 'color') });
item.color = get(seriesStyle, 'color');
}

return item;
});

const colors = args.palette.gradient ? chroma.scale(args.palette.colors).colors(data.length) : args.palette.colors;
const colors = args.palette.gradient
? chroma.scale(args.palette.colors).colors(data.length)
: args.palette.colors;

return {
type: 'render',
Expand Down
17 changes: 7 additions & 10 deletions common/functions/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,10 @@ export const plot = {
const data = map(groupBy(context.rows, 'color'), (series, label) => {
const seriesStyle = seriesStyles[label] || args.defaultStyle;

const result = {};
if (seriesStyle) {
Object.assign(result, seriesStyleToFlot(seriesStyle));
}
const result = seriesStyle ? seriesStyleToFlot(seriesStyle) : {};

Object.assign(result, {
return {
...result,
label: label,
data: series.map(point => {
const attrs = {};
Expand All @@ -143,9 +141,7 @@ export const plot = {

return [x, y, attrs];
}),
});

return result;
};
});

const colors = args.palette.gradient ? chroma.scale(args.palette.colors).colors(data.length) : args.palette.colors;
Expand Down Expand Up @@ -193,13 +189,14 @@ export const plot = {
ticks: get(context.columns, 'y.type') === 'string' ? map(ticks.y.hash, (position, name) => [position, name]) : undefined,
mode: get(context.columns, 'y.type') === 'date' ? 'time' : undefined,
},
series: Object.assign({
series: {
bubbles: {
active: true,
show: true,
},
shadowSize: 0,
}, seriesStyleToFlot(args.defaultStyle)),
...seriesStyleToFlot(args.defaultStyle),
},
},
},
};
Expand Down
6 changes: 3 additions & 3 deletions common/functions/ply.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { groupBy, flatten, pick, map } from 'lodash';
import { getType } from '../lib/get_type';


function checkDatatableType(datatable) {
if (getType(datatable) !== 'datatable') {
throw new Error ('All ply expressions must return a datatable. Use `as` to turn a literal (eg string, number) into a datatable');
Expand Down Expand Up @@ -39,7 +38,8 @@ function combineAcross(datatableArray) {
for (let i = 0; i < targetRowLength; i++) {
const rowsAcross = map(arrayOfRowsArrays, i);

// The reason for the Object.assign is that rowsAcross is an array and those rows need to be applied as arguments to Object.assign
// The reason for the Object.assign is that rowsAcross is an array
// and those rows need to be applied as arguments to Object.assign
rows.push(Object.assign({}, ...rowsAcross));
}

Expand Down Expand Up @@ -102,7 +102,7 @@ export const ply = {

// Here we're just merging each for the by splits, so it doesn't actually matter if the rows are the same length
const columns = combineColumns([byColumns].concat(map(newDatatables, 'columns')));
const rows = flatten(newDatatables.map((dt, i) => {
const rows = flatten(newDatatables.map((dt, i) => {
const byColumnValues = pick(originalDatatables[i].rows[0], args.by);
return dt.rows.map(row => ({
...byColumnValues,
Expand Down
2 changes: 1 addition & 1 deletion common/interpreter/interpret.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { each, keys, last, mapValues, values, zipObject } from 'lodash';
import clone from 'lodash.clone';
import omitBy from 'lodash.omitby';
import { castProvider } from './cast';
import { getType } from '../lib/get_type';
import { fromExpression } from '../lib/ast';
import { typesRegistry } from '../lib/types_registry';
import { castProvider } from './cast';

const createError = (err, { name, context, args }) => ({
type: 'error',
Expand Down
3 changes: 1 addition & 2 deletions common/lib/__tests__/find_in_object.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { findInObject } from '../find_in_object';
import expect from 'expect.js';
import { findInObject } from '../find_in_object';

const findMe = {
foo: {
Expand Down Expand Up @@ -45,6 +45,5 @@ describe('findInObject', () => {
expect(findInObject(findMe, (obj) => obj.id === 4).length).to.eql(1);
expect(findInObject(findMe, (obj) => obj.id === 10000).length).to.eql(0);


});
});
2 changes: 1 addition & 1 deletion common/lib/__tests__/latest_change.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { latestChange } from '../latest_change';
import expect from 'expect.js';
import { latestChange } from '../latest_change';

describe('latestChange', () => {
it('returns a function', () => {
Expand Down
5 changes: 4 additions & 1 deletion common/lib/__tests__/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ describe('Registry', () => {
class CustomRegistry extends Registry {
wrapper(obj) {
// append custom prop to shallow cloned object, with index as a value
return Object.assign({}, obj, { __CUSTOM_PROP__: idx += 1 });
return {
...obj,
__CUSTOM_PROP__: idx += 1,
};
}
}

Expand Down
2 changes: 1 addition & 1 deletion common/lib/ast.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse } from './grammar';
import { getType } from '../lib/get_type';
import { parse } from './grammar';

function getArgumentString(arg, argKey) {
const type = getType(arg);
Expand Down
5 changes: 4 additions & 1 deletion common/lib/datatable/query.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export function queryDatatable(datatable, query) {
if (query.size) {
datatable = Object.assign({}, datatable, { rows: datatable.rows.slice(0, query.size) });
datatable = {
...datatable,
rows: datatable.rows.slice(0, query.size),
};
}

if (query.and) {
Expand Down
14 changes: 7 additions & 7 deletions common/lib/fetch_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export const fetchRawImage = (url) => {
method: 'GET',
responseType,
})
.then((res) => {
const type = res.headers['content-type'];
.then((res) => {
const type = res.headers['content-type'];

if (imageTypes.indexOf(type) < 0) {
return Promise.reject(new Error(`Invalid image type: ${type}`));
}
if (imageTypes.indexOf(type) < 0) {
return Promise.reject(new Error(`Invalid image type: ${type}`));
}

return { data: res.data, type };
});
return { data: res.data, type };
});
};

export const fetchImage = (url) => {
Expand Down
8 changes: 4 additions & 4 deletions common/lib/palettes.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ export const palettes = {
gradient: true,
},
green_blue_red: {
colors: ['#D3FB71','#7ECAE3','#f03b20'],
colors: ['#D3FB71', '#7ECAE3', '#f03b20'],
gradient: true,
},
yellow_green: {
colors: ['#f7fcb9','#addd8e','#31a354'],
colors: ['#f7fcb9', '#addd8e', '#31a354'],
gradient: true,
},
yellow_blue: {
colors: ['#edf8b1','#7fcdbb','#2c7fb8'],
colors: ['#edf8b1', '#7fcdbb', '#2c7fb8'],
gradient: true,
},
yellow_red: {
colors: ['#ffeda0','#feb24c','#f03b20'],
colors: ['#ffeda0', '#feb24c', '#f03b20'],
gradient: true,
},
instagram: {
Expand Down
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,34 +72,36 @@
"uuid": "^3.0.1"
},
"devDependencies": {
"@elastic/eslint-config-kibana": "^0.5.0",
"@elastic/eslint-config-kibana": "^0.15.0",
"@elastic/eslint-import-resolver-kibana": "^1.0.0",
"@elastic/eslint-plugin-kibana-custom": "^1.0.3",
"@elastic/plugin-helpers": "^8.0.0",
"ansi-colors": "^1.0.1",
"aws-sdk": "^2.141.0",
"babel-core": "^6.24.1",
"babel-eslint": "6.1.2",
"babel-eslint": "^8.0.0",
"babel-plugin-mock-imports": "^0.0.4",
"babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.26.0",
"del": "^2.2.2",
"eslint": "3.11.1",
"eslint-plugin-babel": "4.0.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-mocha": "4.7.0",
"eslint-plugin-react": "^6.10.3",
"eslint": "^4.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-import": "^2.6.0",
"eslint-plugin-jest": "^21.0.0",
"eslint-plugin-mocha": "^4.9.0",
"eslint-plugin-prefer-object-spread": "^1.2.1",
"eslint-plugin-react": "^7.1.0",
"expect.js": "^0.3.1",
"fancy-log": "^1.3.2",
"gulp": "^3.9.1",
"gulp-debug": "^3.1.0",
"gulp-eslint": "3.0.1",
"gulp-eslint": "^4.0.1",
"gulp-if": "^2.0.2",
"gulp-load-plugins": "^1.5.0",
"gulp-mocha": "^4.3.1",
"gulp-pegjs": "^0.1.0",
"gulp-util": "3.0.8",
"husky": "^0.13.3",
"just-compose": "^1.0.6",
"markdown-it-named-headers": "^0.0.4",
Expand All @@ -119,4 +121,4 @@
"sinon": "^2.3.2",
"through2": "^2.0.3"
}
}
}
2 changes: 2 additions & 0 deletions public/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env:
browser: true
2 changes: 1 addition & 1 deletion public/apps/workpad/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uiRoutes from 'ui/routes';
import { uiModules } from 'ui/modules';
import template from './index.html';
import { App } from '../../components/app';
import template from './index.html';

uiRoutes.when('/', { template });

Expand Down
Loading

0 comments on commit 69d7546

Please sign in to comment.