Skip to content
Permalink
Browse files

Lint

Lint everything to meet current standards.
  • Loading branch information
evanplaice committed Dec 13, 2019
1 parent 4d454f9 commit f2b1a93c3d631bc88db5e18b8b8e5f562c38348f
@@ -1,7 +1,7 @@
import * as csv from 'jquery-csv';
import * as fs from 'fs';

let sample = './data/sample.csv';
const sample = './data/sample.csv';
fs.readFile(sample, 'UTF-8', (err, fileContent) => {
if (err) { console.log(err); }
csv.toArrays(fileContent, {}, (err, data) => {
@@ -1,3 +1,4 @@
/* eslint no-prototype-builtins: 0 */
/**
* jQuery-csv (jQuery Plugin)
*
@@ -3,16 +3,16 @@ const csv = require('../src/jquery.csv.js');
const fixtures = require('./fixtures/fixtures.js');

test('$.csv.fromArrays() - should be able to format multi-entry/multi-cell data set', (t) => {
let result = csv.fromArrays(fixtures.arrays1_obj);
let expect = fixtures.arrays1_csv;
const result = csv.fromArrays(fixtures.arrays1_obj);
const expect = fixtures.arrays1_csv;
t.deepEqual(result, expect);
t.end();
});

test('$.csv.fromArrays() - should be able to format multi-entry/multi-cell data set with escaped delimiters', (t) => {
let result = csv.fromArrays(fixtures.arrays2_obj);
const result = csv.fromArrays(fixtures.arrays2_obj);
console.dir(result);
let expect = fixtures.arrays2_csv;
const expect = fixtures.arrays2_csv;
t.deepEqual(result, expect);
t.end();
});
@@ -5,11 +5,13 @@ const fixtures = require('./fixtures/fixtures.js');
test('$.csv.toObjects onParseEntry hook callback - should be passed the data and state', (t) => {
let passedData, passedState;

csv.toObjects(fixtures.objects_csv, { onParseEntry: (data, state) => {
passedData = data;
passedState = state;
return data;
} });
csv.toObjects(fixtures.objects_csv, {
onParseEntry: (data, state) => {
passedData = data;
passedState = state;
return data;
}
});

t.isNot(passedData, null, 'data argument should not be null');
t.isNot(passedState, null, 'state argument should not be null');
@@ -19,11 +21,13 @@ test('$.csv.toObjects onParseEntry hook callback - should be passed the data and
test('$.csv.toArrays onParseEntry hook callback - should be passed the data and state', (t) => {
let passedData, passedState;

csv.toArrays(fixtures.arrays1_csv, { onParseEntry: (data, state) => {
passedData = data;
passedState = state;
return data;
} });
csv.toArrays(fixtures.arrays1_csv, {
onParseEntry: (data, state) => {
passedData = data;
passedState = state;
return data;
}
});

t.isNot(passedData, null, 'data argument should not be null');
t.isNot(passedState, null, 'state argument should not be null');
@@ -5,11 +5,13 @@ const fixtures = require('./fixtures/fixtures.js');
test('$.csv.toObjects onParseValue hook callback - should be passed the data and state', (t) => {
let passedData, passedState;

csv.toObjects(fixtures.objects_csv, { onParseValue: (data, state) => {
passedData = data;
passedState = state;
return data;
} });
csv.toObjects(fixtures.objects_csv, {
onParseValue: (data, state) => {
passedData = data;
passedState = state;
return data;
}
});

t.isNot(passedData, null, 'data argument should not be null');
t.isNot(passedState, null, 'state argument should not be null');
@@ -19,11 +21,13 @@ test('$.csv.toObjects onParseValue hook callback - should be passed the data and
test('$.csv.toArrays onParseValue hook callback - should be passed the data and state', (t) => {
let passedData, passedState;

csv.toArrays(fixtures.arrays1_csv, { onParseValue: (data, state) => {
passedData = data;
passedState = state;
return data;
} });
csv.toArrays(fixtures.arrays1_csv, {
onParseValue: (data, state) => {
passedData = data;
passedState = state;
return data;
}
});

t.isNot(passedData, null, 'data argument should not be null');
t.isNot(passedState, null, 'state argument should not be null');
@@ -5,10 +5,12 @@ const fixtures = require('./fixtures/fixtures.js');
test('$.csv.toObjects onPostParse hook callback - should be passed the data and state', (t) => {
let passedData, passedState;

csv.toObjects(fixtures.objects_csv, { onPostParse: (data, state) => {
passedData = data;
passedState = state;
} });
csv.toObjects(fixtures.objects_csv, {
onPostParse: (data, state) => {
passedData = data;
passedState = state;
}
});

t.isNot(passedData, null, 'data argument should not be null');
t.isNot(passedState, null, 'state argument should not be null');
@@ -18,10 +20,12 @@ test('$.csv.toObjects onPostParse hook callback - should be passed the data and
test('$.csv.toArrays onPostParse hook callback - should be passed the data and state', (t) => {
let passedData, passedState;

csv.toArrays(fixtures.arrays1_csv, { onPostParse: (data, state) => {
passedData = data;
passedState = state;
} });
csv.toArrays(fixtures.arrays1_csv, {
onPostParse: (data, state) => {
passedData = data;
passedState = state;
}
});

t.isNot(passedData, null, 'data argument should not be null');
t.isNot(passedState, null, 'state argument should not be null');
@@ -5,11 +5,13 @@ const fixtures = require('./fixtures/fixtures.js');
test('$.csv.toObjects onPreParse hook callback - should be passed the raw csv and state', (t) => {
let passedCSV, passedState;

csv.toObjects(fixtures.objects_csv, { onPreParse: (csv, state) => {
passedCSV = csv;
passedState = state;
return csv;
} });
csv.toObjects(fixtures.objects_csv, {
onPreParse: (csv, state) => {
passedCSV = csv;
passedState = state;
return csv;
}
});

t.isNot(passedCSV, null, 'data argument should not be null');
t.isNot(passedState, null, 'state argument should not be null');
@@ -19,11 +21,13 @@ test('$.csv.toObjects onPreParse hook callback - should be passed the raw csv an
test('$.csv.toArrays onPreParse hook callback - should be passed the raw csv and state', (t) => {
let passedCSV, passedState;

csv.toArrays(fixtures.arrays1_csv, { onPreParse: (csv, state) => {
passedCSV = csv;
passedState = state;
return csv;
} });
csv.toArrays(fixtures.arrays1_csv, {
onPreParse: (csv, state) => {
passedCSV = csv;
passedState = state;
return csv;
}
});

t.isNot(passedCSV, null, 'data argument should not be null');
t.isNot(passedState, null, 'state argument should not be null');
@@ -3,27 +3,27 @@ const csv = require('../src/jquery.csv.js');
const fixtures = require('./fixtures/fixtures.js');

test('$.csv.parsers.splitLines() - should correctly split lines with default options', (t) => {
let result = csv.parsers.splitLines(fixtures.defaults_fivelines_csv);
const result = csv.parsers.splitLines(fixtures.defaults_fivelines_csv);
t.equal(typeof (result), 'object', 'the returned object should be an array');
t.true(Array.isArray(result), 'the returned object should be an array');
t.equal(result.length, 5, 'the returned array should contain 5 lines');
t.end();
});

test('$.csv.parsers.splitLines() - should correctly split lines with custom separator', (t) => {
let options = {
const options = {
separator: ';'
};

let result = csv.parsers.splitLines(fixtures.separator_fivelines_csv, options);
const result = csv.parsers.splitLines(fixtures.separator_fivelines_csv, options);
t.equal(typeof (result), 'object', 'the returned object should be an array');
t.true(Array.isArray(result), 'the returned object should be an array');
t.equal(result.length, 5, 'the returned array should contain 5 lines');
t.end();
});

test('$.csv.parsers.splitLines() - should throw an error for using the wrong separator', (t) => {
let options = {
const options = {
separator: ';'
};

@@ -36,19 +36,19 @@ test('$.csv.parsers.splitLines() - should throw an error for using the wrong sep
});

test('$.csv.parsers.splitLines() - should correctly split lines with custom delimiter', (t) => {
let options = {
const options = {
delimiter: "'"
};

let result = csv.parsers.splitLines(fixtures.delimiter_fivelines_csv, options);
const result = csv.parsers.splitLines(fixtures.delimiter_fivelines_csv, options);
t.equal(typeof (result), 'object', 'the returned object should be an array');
t.true(Array.isArray(result), 'the returned object should be an array');
t.equal(result.length, 5, 'the returned array should contain 5 lines');
t.end();
});

test('$.csv.parsers.splitLines() - should return undefined when csv is undefined', (t) => {
let result = csv.parsers.splitLines();
const result = csv.parsers.splitLines();
t.equal(typeof (result), 'undefined');
t.end();
});
@@ -3,20 +3,20 @@ const csv = require('../src/jquery.csv.js');
const fixtures = require('./fixtures/fixtures.js');

test('$.csv.toArray() - should be able to parse an entry containing multiple cells', (t) => {
let result = csv.toArray(fixtures.array_csv);
let expect = fixtures.array_obj;
const result = csv.toArray(fixtures.array_csv);
const expect = fixtures.array_obj;
t.deepEqual(result, expect);
t.end();
});

test('$.csv.toArray() - should return [""] when input is empty', (t) => {
let result = csv.toArray('');
const result = csv.toArray('');
t.equal(result.length, 1);
t.end();
});

test('$.csv.toArray() - should return ["a1"] when input is "a1"', (t) => {
let result = csv.toArray('a1');
const result = csv.toArray('a1');
t.equal(result.length, 1);
t.equal(result[0], 'a1');
t.end();
@@ -3,15 +3,15 @@ const csv = require('../src/jquery.csv.js');
const fixtures = require('./fixtures/fixtures.js');

test('$.csv.toArrays() - should be able to parse multi-entry/multi-cell input', (t) => {
let result = csv.toArrays(fixtures.arrays1_csv);
let expect = fixtures.arrays1_obj;
const result = csv.toArrays(fixtures.arrays1_csv);
const expect = fixtures.arrays1_obj;
t.deepEqual(result, expect);
t.end();
});

test('$.csv.toArrays() - should be able to parse multi-entry/multi-cell input with escaped delimiters', (t) => {
let result = csv.toArrays(fixtures.arrays2_csv);
let expect = fixtures.arrays2_obj;
const result = csv.toArrays(fixtures.arrays2_csv);
const expect = fixtures.arrays2_obj;
t.deepEqual(result, expect);
t.end();
});
@@ -3,26 +3,26 @@ const csv = require('../src/jquery.csv.js');
const fixtures = require('./fixtures/fixtures.js');

test('Edge Case - should properly escape backslashes', (t) => {
let result = csv.toObjects(fixtures.backslash_csv);
let expect = fixtures.backslash_obj;
const result = csv.toObjects(fixtures.backslash_csv);
const expect = fixtures.backslash_obj;
t.deepEqual(result, expect);
t.end();
});

test('Edge Case - should support \\n (unix) line endings', (t) => {
let result = csv.toArrays(fixtures.newline_unix);
const result = csv.toArrays(fixtures.newline_unix);
t.equal(result.length, 2);
t.end();
});

test('Edge Case - should support \\r (mac) line endings', (t) => {
let result = csv.toArrays(fixtures.newline_mac);
const result = csv.toArrays(fixtures.newline_mac);
t.equal(result.length, 2);
t.end();
});

test('Edge Case - should support \\r\\n (dos) line endings', (t) => {
let result = csv.toArrays(fixtures.newline_dos);
const result = csv.toArrays(fixtures.newline_dos);
t.equal(result.length, 2);
t.end();
});

0 comments on commit f2b1a93

Please sign in to comment.
You can’t perform that action at this time.