Skip to content

Commit e558481

Browse files
committed
Change eslint rule arrow-parens to always
1 parent cd0b79d commit e558481

File tree

7 files changed

+46
-46
lines changed

7 files changed

+46
-46
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@
211211
],
212212
"arrow-parens": [
213213
"error",
214-
"as-needed"
214+
"always"
215215
],
216216
"arrow-body-style": [
217217
"error",

JavaScript/2-imperative-good.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
const fs = require('fs');
1212

13-
const loadFile = fileName => {
13+
const loadFile = (fileName) => {
1414
let data = null;
1515
try {
1616
data = fs.readFileSync(fileName, 'utf8');
@@ -20,7 +20,7 @@ const loadFile = fileName => {
2020
return data;
2121
};
2222

23-
const parseFile = data => {
23+
const parseFile = (data) => {
2424
const lines = data.split('\n');
2525
lines.shift();
2626
const cities = [];
@@ -38,15 +38,15 @@ const parseFile = data => {
3838
return cities;
3939
};
4040

41-
const calculateDensityColumn = cities => {
41+
const calculateDensityColumn = (cities) => {
4242
cities.sort((city1, city2) => city2.density - city1.density);
4343
const maxDensity = cities[0].density;
4444
for (const city of cities) {
4545
city.relative = Math.round(city.density * 100 / maxDensity);
4646
}
4747
};
4848

49-
const showTable = cities => {
49+
const showTable = (cities) => {
5050
for (const city of cities) {
5151
const line = (
5252
city.name.padEnd(18) +

JavaScript/3-functional-bad.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ const width = [18, 10, 8, 8, 18, 6];
2020

2121
let maxDensity = 0;
2222

23-
const format = file => (
23+
const format = (file) => (
2424
fs.readFileSync(file, 'utf8').split('\n')
2525
.filter((s, i) => i && s)
26-
.map(line => line.split(',').map((cell, i, arr) => (
26+
.map((line) => line.split(',').map((cell, i, arr) => (
2727
(i < 1 || i > 3) || (cell = parseInt(cell), arr[i] = cell),
2828
(i - 3) || (maxDensity = maxDensity > cell ? maxDensity : cell), cell
2929
)))
30-
.map(row => (
30+
.map((row) => (
3131
row.push(Math.round(row[3] * 100 / maxDensity).toString()), row
3232
))
3333
.sort((r1, r2) => (r2[5] - r1[5]))
34-
.map(row => (
34+
.map((row) => (
3535
row.map((cell, i) => padding[i](cell + '', width[i])).join('')
3636
))
3737
.join('\n')

JavaScript/4-functional-good.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212
const fs = require('fs');
1313

1414
const proportion = (max, val) => Math.round(val * 100 / max);
15-
const compose = (...funcs) => x => funcs.reduce((x, fn) => fn(x), x);
15+
const compose = (...funcs) => (x) => funcs.reduce((x, fn) => fn(x), x);
1616

1717
const cellPad = (i, s, width) => (i ? s.padStart(width) : s.padEnd(width));
18-
const cellWidth = i => [18, 10, 8, 8, 18, 6][i];
18+
const cellWidth = (i) => [18, 10, 8, 8, 18, 6][i];
1919

2020
const renderCell = (cell, i) => cellPad(i, cell + '', cellWidth(i));
21-
const renderRow = row => row.map(renderCell).join('');
22-
const renderTable = table => table.map(renderRow).join('\n');
21+
const renderRow = (row) => row.map(renderCell).join('');
22+
const renderTable = (table) => table.map(renderRow).join('\n');
2323

2424
const densityCol = () => 3;
25-
const sortByDensity = table => table.sort(
25+
const sortByDensity = (table) => table.sort(
2626
(row1, row2) => (row2[densityCol()] - row1[densityCol()])
2727
);
2828
const calcColumn = (table, max) => table.map(
29-
row => (row.push(proportion(max, row[densityCol()])), row)
29+
(row) => (row.push(proportion(max, row[densityCol()])), row)
3030
);
31-
const calcProportion = table => calcColumn(table, table[0][densityCol()]);
31+
const calcProportion = (table) => calcColumn(table, table[0][densityCol()]);
3232

33-
const parseTable = lines => lines.map(line => line.split(','));
34-
const toLines = data => data.split('\n').filter((s, i) => i && s);
35-
const readFile = file => fs.readFileSync(file, 'utf8');
33+
const parseTable = (lines) => lines.map((line) => line.split(','));
34+
const toLines = (data) => data.split('\n').filter((s, i) => i && s);
35+
const readFile = (file) => fs.readFileSync(file, 'utf8');
3636
const getDataset = compose(readFile, toLines, parseTable);
3737

3838
const main = compose(getDataset, sortByDensity, calcProportion, renderTable);

JavaScript/5-functional-alternative.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ const fs = require('fs');
44

55
const proportion = (max, val) => Math.round(val * 100 / max);
66

7-
const compose = (...funcs) => x => funcs.reduce((x, fn) => fn(x), x);
7+
const compose = (...funcs) => (x) => funcs.reduce((x, fn) => fn(x), x);
88

99
const densityCol = 3;
1010
const cellWidth = [18, 10, 8, 8, 18, 6];
1111

12-
const renderTable = table => table
13-
.map(row => row
12+
const renderTable = (table) => table
13+
.map((row) => row
1414
.map((cell, i) => cell
1515
.toString()[(i ? 'padStart' : 'padEnd')](cellWidth[i]))
1616
.join(''))
1717
.join('\n');
1818

19-
const calcProportion = table => (
19+
const calcProportion = (table) => (
2020
table.sort((row1, row2) => (row2[densityCol] - row1[densityCol])),
21-
table.map(row => (
21+
table.map((row) => (
2222
row.push(proportion(table[0][densityCol], row[densityCol])), row
2323
))
2424
);
2525

26-
const getDataset = file => fs.readFileSync(file, 'utf8')
26+
const getDataset = (file) => fs.readFileSync(file, 'utf8')
2727
.split('\n')
2828
.filter((s, i) => i && s)
29-
.map(line => line.split(','));
29+
.map((line) => line.split(','));
3030

3131
const main = compose(getDataset, calcProportion, renderTable);
3232

JavaScript/6-functional-pure.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33
const fs = require('fs');
44

55
/* fp */
6-
const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x);
7-
const curry = fn => (...args) => fn.bind(null, ...args);
6+
const pipe = (...fns) => (x) => fns.reduce((v, f) => f(v), x);
7+
const curry = (fn) => (...args) => fn.bind(null, ...args);
88
const map = curry((fn, arr) => arr.map(fn));
99
const join = curry((str, arr) => arr.join(str));
1010
const split = curry((splitOn, str) => str.split(splitOn));
1111
const sort = curry((compareFn, arr) => arr.sort(compareFn));
1212
const filter = curry((filterFn, arr) => arr.filter(filterFn));
1313

1414
/* utility */
15-
const first = arr => arr[0];
16-
const skipFirst = arr => arr.slice(1);
17-
const hasValue = val => !!val;
18-
const toStr = val => val.toString();
15+
const first = (arr) => arr[0];
16+
const skipFirst = (arr) => arr.slice(1);
17+
const hasValue = (val) => !!val;
18+
const toStr = (val) => val.toString();
1919
const appendCell = (row, value) => row.concat(value);
2020
const cellPad = (index, str, width) => (
2121
index ? str.padStart(width) : str.padEnd(width)
2222
);
23-
const cellWidth = index => [18, 10, 8, 8, 18, 6][index];
23+
const cellWidth = (index) => [18, 10, 8, 8, 18, 6][index];
2424

2525
const renderCell = (cell, index) => (
2626
cellPad(index, toStr(cell), cellWidth(index))
2727
);
2828
const renderRow = pipe(map(renderCell), join(''));
2929
const renderTable = pipe(map(renderRow), join('\n'));
3030

31-
const getDensityCell = row => parseInt(row[3], 10);
31+
const getDensityCell = (row) => parseInt(row[3], 10);
3232
const proportion = (max, val) => Math.round(parseInt(val, 10) * 100 / max);
3333
const sortRowsByDensity = sort(
3434
(row1, row2) => getDensityCell(row2) - getDensityCell(row1)
@@ -40,16 +40,16 @@ const calcMaxDensity = pipe(
4040
getDensityCell
4141
);
4242

43-
const calcRowsProportionToMax = rows => max => rows.map(pipe(
43+
const calcRowsProportionToMax = (rows) => (max) => rows.map(pipe(
4444
getDensityCell,
45-
densityCell => proportion(max, densityCell)
45+
(densityCell) => proportion(max, densityCell)
4646
));
4747

48-
const appendProportionCell = rows => proportions => rows.map(
48+
const appendProportionCell = (rows) => (proportions) => rows.map(
4949
(row, index) => appendCell(row, proportions[index])
5050
);
5151

52-
const appendTableProportionCol = rows => pipe(
52+
const appendTableProportionCol = (rows) => pipe(
5353
calcMaxDensity,
5454
calcRowsProportionToMax(rows),
5555
appendProportionCell(rows)
@@ -63,7 +63,7 @@ const toLines = pipe(
6363
filter(hasValue)
6464
);
6565

66-
const readFile = file => fs.readFileSync(file, 'utf8');
66+
const readFile = (file) => fs.readFileSync(file, 'utf8');
6767

6868
const getDataset = pipe(
6969
readFile,

JavaScript/7-mixed.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
const fs = require('fs');
44

5-
const compose = (...funcs) => x => funcs.reduce((x, fn) => fn(x), x);
5+
const compose = (...funcs) => (x) => funcs.reduce((x, fn) => fn(x), x);
66

77
const DENSITY_COL = 3;
88

9-
const renderTable = table => {
9+
const renderTable = (table) => {
1010
const cellWidth = [18, 10, 8, 8, 18, 6];
11-
return table.map(row => (
11+
return table.map((row) => (
1212
row.map((cell, i) => {
1313
const width = cellWidth[i];
1414
return i ? cell.toString().padStart(width) : cell.padEnd(width);
@@ -18,20 +18,20 @@ const renderTable = table => {
1818

1919
const proportion = (max, val) => Math.round(val * 100 / max);
2020

21-
const calcProportion = table => {
21+
const calcProportion = (table) => {
2222
table.sort((row1, row2) => row2[DENSITY_COL] - row1[DENSITY_COL]);
2323
const maxDensity = table[0][DENSITY_COL];
24-
table.forEach(row => {
24+
table.forEach((row) => {
2525
row.push(proportion(maxDensity, row[DENSITY_COL]));
2626
});
2727
return table;
2828
};
2929

30-
const getDataset = file => {
30+
const getDataset = (file) => {
3131
const lines = fs.readFileSync(file, 'utf8').split('\n');
3232
lines.shift();
3333
lines.pop();
34-
return lines.map(line => line.split(','));
34+
return lines.map((line) => line.split(','));
3535
};
3636

3737
const main = compose(getDataset, calcProportion, renderTable);

0 commit comments

Comments
 (0)