Skip to content

Commit f707934

Browse files
committed
fix code for eslint (attempt 1)
1 parent 550a7f2 commit f707934

File tree

9 files changed

+37
-35
lines changed

9 files changed

+37
-35
lines changed

__test__/diffFiles.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/* eslint-disable no-undef */
22
import fs from 'fs';
3-
import path from 'path';
3+
import path, { dirname } from 'path';
44
import { fileURLToPath } from 'url';
5-
import { dirname } from 'path';
65
import genDiff from '../src/formatters/index.js';
76

87
const __filename = fileURLToPath(import.meta.url);
98
const __dirname = dirname(__filename);
109

1110
const getFixturePath = (filename) =>
1211
path.join(__dirname, '..', '__fixtures__', filename);
12+
1313
const readFile = (filename) =>
1414
fs.readFileSync(getFixturePath(filename), 'utf-8');
1515

bin/gendiff.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { program } from 'commander';
44
import genDiff from '../src/formatters/index.js';
5+
56
program
67
.name('gendiff')
78
.description('Compares two configuration files and shows a difference.')

coverage/lcov-report/block-navigation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable */
1+
22
var jumpToCode = (function init() {
33
// Classes of code we would like to highlight in the file view
44
var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];

coverage/lcov-report/sorter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable */
1+
22
var addSorting = (function() {
33
'use strict';
44
var cols,

eslint.config.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import globals from "globals";
2-
import pluginJs from "@eslint/js";
3-
1+
import globals from 'globals';
2+
import pluginJs from '@eslint/js';
43

54
/** @type {import('eslint').Linter.Config[]} */
65
export default [
7-
{languageOptions: { globals: globals.browser }},
6+
{ languageOptions: { globals: globals.browser } },
87
pluginJs.configs.recommended,
9-
];
8+
];

src/formatters/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import formatStylish from './styllish.js';
44
import formatPlain from './plain.js';
55
import formatJson from './json.js';
66

7-
const genDiff = (filePath1, filePath2, format = 'stylish') => {
7+
const genDiff = (filePath1, filePath2, format = 'stylish') => {
88
const file1 = fileParser(filePath1);
99
const file2 = fileParser(filePath2);
1010
const getDIffFiles = diffFiles(file1, file2);
@@ -23,4 +23,4 @@ import formatJson from './json.js';
2323
return output;
2424
};
2525

26-
export default genDiff;
26+
export default genDiff;

src/formatters/json.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
import _ from 'lodash';
22
import getPath from '../getPath.js';
33

4-
const getValue = (elem) => {
5-
if (elem.keyOld || elem.keyNew) {
6-
return `"oldValue": ${formatValue(elem.keyOld)}, "newValue": ${formatValue(elem.keyNew)}`;
7-
}
8-
return `"value": ${formatValue(elem.value)}`;
9-
};
10-
114
const formatValue = (value) => {
125
if (_.isNull(value) || _.isBoolean(value) || _.isNumber(value)) {
136
return value;
14-
}else if (_.isPlainObject(value)) {
7+
} else if (_.isPlainObject(value)) {
158
return JSON.stringify(value);
169
}
1710
return `"${value}"`;
1811
};
1912

13+
const getValue = (elem) => {
14+
if (elem.keyOld || elem.keyNew) {
15+
return `"oldValue": ${formatValue(elem.keyOld)}, "newValue": ${formatValue(
16+
elem.keyNew
17+
)}`;
18+
}
19+
return `"value": ${formatValue(elem.value)}`;
20+
};
21+
2022
const formatJson = (data, parentPath = '') => {
21-
const iner = (data, parentPath) => data
22-
.filter((elem) => elem.condition !== 'dash')
23-
.map((elem) => {
24-
const { condition, children } = elem;
25-
const currentPath = getPath(elem, parentPath);
26-
if (condition === 'unchanged') {
27-
return `${iner(children, currentPath)}`;
28-
}
29-
return `{"name": "${currentPath}", ${getValue(elem)}, "condition": "${condition}"}`;
30-
});
23+
const iner = (data, parentPath) =>
24+
data
25+
.filter((elem) => elem.condition !== 'dash')
26+
.map((elem) => {
27+
const { condition, children } = elem;
28+
const currentPath = getPath(elem, parentPath);
29+
if (condition === 'unchanged') {
30+
return `${iner(children, currentPath)}`;
31+
}
32+
return `{"name": "${currentPath}", ${getValue(
33+
elem
34+
)}, "condition": "${condition}"}`;
35+
});
3136
const result = iner(data, parentPath).join(',');
3237
return `[${result}]`;
3338
};
3439

35-
export default formatJson;
40+
export default formatJson;

src/formatters/styllish.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import _ from 'lodash';
22

3-
const createIndent = (depth, shiftingLeft = -2) =>
4-
' '.repeat(depth * 4 + shiftingLeft);
3+
const createIndent = (depth, shiftingLeft = -2) => ' '.repeat(depth * 4 + shiftingLeft);
54

65
const stringify = (data, depth) => {
76
const indent = createIndent(depth);

src/getPath.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export default (data, parentPath = '') => {
2-
return parentPath ? `${parentPath}.${data.name}` : data.name;
3-
};
1+
export default (data, parentPath = '') => parentPath ? `${parentPath}.${data.name}` : data.name;

0 commit comments

Comments
 (0)