Skip to content

Commit

Permalink
feat(#9): clean for eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Oct 2, 2024
1 parent 1bf4dda commit 1cfe989
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

const fs = require('fs');
const graph = (path) => {
return fs.readFileSync(path, "utf-8");
return fs.readFileSync(path, 'utf-8');
};

module.exports = graph;
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const path = require('path');
const filed = require('./tokens.js');
const query = require('./graph.js');
const pkg = require('../package.json');
let fs = require('fs');
const nestedProp = require("./nested-prop.js");
const fs = require('fs');
const nestedProp = require('./nested-prop.js');

Check warning on line 35 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L34-L35

Added lines #L34 - L35 were not covered by tests

console.log(`Running ghminer@${pkg.version}`);
const argv = minimist(process.argv.slice(2));
Expand All @@ -43,8 +43,8 @@ const startDate = argv.start || '2008-01-01';
const endDate = argv.end || now;
const dateType = argv.date || 'created';
const print = argv.json || false;
const gpath = argv.graphql || "ghminer.graphql";
const schema = argv.schema || "ghminer.json";
const gpath = argv.graphql || 'ghminer.graphql';
const schema = argv.schema || 'ghminer.json';

Check warning on line 47 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L46-L47

Added lines #L46 - L47 were not covered by tests

let tokens;
if (argv.tokens) {
Expand Down Expand Up @@ -231,7 +231,7 @@ async function fetchAllResults() {
* @param {Object} json Json objects
*/
function writeFiles(json) {
let format = JSON.parse(fs.readFileSync(schema, "utf-8"));
const format = JSON.parse(fs.readFileSync(schema, 'utf-8'));

Check warning on line 234 in src/index.js

View check run for this annotation

Codecov / codecov/patch

src/index.js#L234

Added line #L234 was not covered by tests
const formattedResults = json.map((result) => {
const data = {};
for (const [key, path] of Object.entries(format)) {
Expand Down
10 changes: 7 additions & 3 deletions src/nested-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ const nestedProp = (obj, path) => {
return acc[arrayKey] && Array.isArray(acc[arrayKey]) ? acc[arrayKey] : [];
}
}
return Array.isArray(acc)
? acc.map(item => item[key] !== undefined ? item[key] : null)
: acc[key] !== undefined ? acc[key] : null;
if (Array.isArray(acc)) {
return acc.map((item) => item[key] !== undefined ? item[key] : null);
} else if (acc[key] !== undefined) {
return acc[key];
} else {
return null;

Check warning on line 43 in src/nested-prop.js

View check run for this annotation

Codecov / codecov/patch

src/nested-prop.js#L42-L43

Added lines #L42 - L43 were not covered by tests
}
}, obj);
};

Expand Down
30 changes: 15 additions & 15 deletions test/nested-prop.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,42 @@
const assert = require('assert');
const nested = require('../src/nested-prop');

describe('Test case for nested-prop.js', function () {
it('returns prop', function () {
describe('Test case for nested-prop.js', function() {
it('returns prop', function() {
const obj = {
test: "aaa"
test: 'aaa'
};
const prop = nested(obj, "test")
const prop = nested(obj, 'test')
const expected = 'aaa';
assert.equal(
prop,
expected,
`parsed ${prop} does not match with expected ${expected}`
);
});
it('returns nested prop', function () {
it('returns nested prop', function() {
const obj = {
test: {
aaa: "bbb"
aaa: 'bbb'
}
};
const prop = nested(obj, "test.aaa")
const prop = nested(obj, 'test.aaa')
const expected = 'bbb';
assert.equal(
prop,
expected,
`parsed ${prop} does not match with expected ${expected}`
);
});
it('returns first nested prop from array', function () {
it('returns first nested prop from array', function() {
const obj = {
defaultBranchRef: {
target: {
history: {
edges: [
{
node: {
committedDate: "2024-10-01"
committedDate: '2024-10-01'
}
}
]
Expand All @@ -69,7 +69,7 @@ describe('Test case for nested-prop.js', function () {
};
const prop = nested(
obj,
"defaultBranchRef.target.history.edges[0].node.committedDate"
'defaultBranchRef.target.history.edges[0].node.committedDate'
);
const expected = '2024-10-01';
assert.equal(
Expand All @@ -78,28 +78,28 @@ describe('Test case for nested-prop.js', function () {
`parsed ${prop} does not match with expected ${expected}`
);
});
it('returns array of nested props', function () {
it('returns array of nested props', function() {
const obj = {
repositoryTopics: {
edges: [
{
node: {
topic: {
name: "java"
name: 'java'
}
}
},
{
node: {
topic: {
name: "jvm"
name: 'jvm'
}
}
},
{
node: {
topic: {
name: "compilers"
name: 'compilers'
}
}
}
Expand All @@ -108,7 +108,7 @@ describe('Test case for nested-prop.js', function () {
};
const prop = nested(
obj,
"repositoryTopics.edges[].node.topic.name"
'repositoryTopics.edges[].node.topic.name'
);
const expected = 'java,jvm,compilers';
assert.equal(
Expand Down

0 comments on commit 1cfe989

Please sign in to comment.