Skip to content

Commit b7ff425

Browse files
committed
build: apply linter to samples
1 parent 2e4a1fd commit b7ff425

29 files changed

+194
-192
lines changed

packages/csv-stringify/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@
6464
"build": "npm run build:rollup && npm run build:ts",
6565
"build:rollup": "npx rollup -c",
6666
"build:ts": "cp lib/*.ts dist/cjs && cp lib/*.ts dist/esm",
67-
"lint": "npm run lint:coffee && npm run lint:js",
68-
"lint:coffee": "coffeelint test/*.coffee",
69-
"lint:js": "eslint lib/*.js",
67+
"lint": "npm run lint:test && npm run lint:lib && npm run lint:samples",
68+
"lint:test": "coffeelint test/*.coffee",
69+
"lint:lib": "eslint lib/*.js",
70+
"lint:samples": "eslint samples/*.js",
7071
"preversion": "npm run build && git add dist",
7172
"pretest": "npm run build",
7273
"test": "mocha 'test/**/*.{coffee,ts}'"
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

55
stringify([
66
[ '1', '2', '3', '4' ],
77
[ 'a', 'b', 'c', 'd' ]
88
], function(err, output){
9-
assert.equal(output, '1,2,3,4\na,b,c,d\n')
10-
})
9+
assert.equal(output, '1,2,3,4\na,b,c,d\n');
10+
});
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import { generate } from 'csv-generate'
2+
import { stringify } from 'csv-stringify';
3+
import { generate } from 'csv-generate';
44

55
generate({
66
objectMode: true,
77
seed: 1,
88
headers: 2,
99
duration: 400
1010
})
11-
.pipe(stringify({
12-
header: true,
13-
columns: {
14-
year: 'birthYear',
15-
phone: 'phone'
16-
}
17-
}))
18-
.pipe(process.stdout)
11+
.pipe(stringify({
12+
header: true,
13+
columns: {
14+
year: 'birthYear',
15+
phone: 'phone'
16+
}
17+
}))
18+
.pipe(process.stdout);
+14-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

5-
const data = []
5+
const data = [];
66
const stringifier = stringify({
77
delimiter: ':'
8-
})
8+
});
99
stringifier.on('readable', function(){
1010
let row;
11-
while(row = stringifier.read()){
12-
data.push(row)
11+
while((row = stringifier.read()) !== null){
12+
data.push(row);
1313
}
14-
})
14+
});
1515
stringifier.on('error', function(err){
16-
console.error(err.message)
17-
})
16+
console.error(err.message);
17+
});
1818
stringifier.on('finish', function(){
1919
assert.equal(
2020
data.join(''),
2121
"root:x:0:0:root:/root:/bin/bash\n" +
2222
"someone:x:1022:1022::/home/someone:/bin/bash\n"
23-
)
24-
})
25-
stringifier.write([ 'root','x','0','0','root','/root','/bin/bash' ])
26-
stringifier.write([ 'someone','x','1022','1022','','/home/someone','/bin/bash' ])
27-
stringifier.end()
23+
);
24+
});
25+
stringifier.write([ 'root','x','0','0','root','/root','/bin/bash' ]);
26+
stringifier.write([ 'someone','x','1022','1022','','/home/someone','/bin/bash' ]);
27+
stringifier.end();

packages/csv-stringify/samples/api.sync.memory.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
import { stringify } from 'csv-stringify/sync'
2+
import { stringify } from 'csv-stringify/sync';
33

44
const r = v => (v / 1024 / 1024).toFixed(2);
55
const printMemoryUsage = () => {
66
const { rss, heapTotal, heapUsed } = process.memoryUsage();
77
console.log(`Memory usage: rss ${r(rss)}, heap ${r(heapUsed)} / ${r(heapTotal)}`);
88
};
99

10-
const attempts = 3 // Increase if necessary
10+
const attempts = 3; // Increase if necessary
1111

1212
const record = []; for (let i = 0; i < 100; i += 1) { record.push(`field-${i}`); }
1313
const records = []; for (let i = 0; i < 100000; i += 1) { records.push([...record]); }
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

55
stringify([{
66
name: 'foo',
@@ -11,13 +11,13 @@ stringify([{
1111
}],{
1212
cast: {
1313
date: function(value) {
14-
return value.toISOString()
14+
return value.toISOString();
1515
}
1616
}
1717
}, function(err, data) {
1818
assert.equal(
1919
data,
2020
"foo,1969-12-31T23:00:00.000Z\n" +
2121
"bar,1970-12-31T23:00:00.000Z\n"
22-
)
23-
})
22+
);
23+
});
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

5-
stringify( [
5+
stringify([
66
{ a: '1', b: '2' }
77
], {
88
columns: [ { key: 'a' }, { key: 'b' } ]
99
}, function(err, data){
10-
assert.equal(data, '1,2\n')
11-
})
10+
assert.equal(data, '1,2\n');
11+
});
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

5-
stringify( [
5+
stringify([
66
{ a: '1', b: '2' }
77
], {
88
columns: [ 'a', 'b' ]
99
}, function(err, data){
10-
assert.equal(data, '1,2\n')
11-
})
10+
assert.equal(data, '1,2\n');
11+
});
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

55
stringify([
66
{ year: 'XXXX', phone: 'XXX XXXX', nocolumn: 'XXX' },
@@ -12,5 +12,5 @@ stringify([
1212
data,
1313
"XXX XXXX,XXXX,\n" +
1414
"YYY YYYY,YYYY,\n"
15-
)
16-
})
15+
);
16+
});
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

55
stringify([
66
['1', '2'],
77
['3', '4']
88
], {
99
delimiter: ':)'
1010
}, function(err, records){
11-
assert.equal(records, '1:)2\n3:)4\n')
12-
})
11+
assert.equal(records, '1:)2\n3:)4\n');
12+
});
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

55
stringify([
66
['1', '2'],
77
['3', '4']
88
], function(err, records){
9-
assert.equal(records, '1,2\n3,4\n')
10-
})
9+
assert.equal(records, '1,2\n3,4\n');
10+
});

packages/csv-stringify/samples/option.header.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// birthYear,phone
44
// OMH,ONKCHhJmjadoA
55

6-
import { stringify } from 'csv-stringify'
7-
import assert from 'assert'
6+
import { stringify } from 'csv-stringify';
7+
import assert from 'assert';
88

99
stringify([
1010
{ year: 'XXXX', phone: 'XXX XXXX' },
@@ -17,5 +17,5 @@ stringify([
1717
"year,phone\n" +
1818
"XXXX,XXX XXXX\n" +
1919
"YYYY,YYY YYYY\n"
20-
)
21-
})
20+
);
21+
});
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

5-
stringify( [
5+
stringify([
66
{ a: '1', b: '2' }
77
], {
88
header: true,
99
columns: { 'a': 'col_a', 'b': 'col_b' }
1010
}, function(err, data){
11-
assert.equal(data, 'col_a,col_b\n1,2\n')
12-
})
11+
assert.equal(data, 'col_a,col_b\n1,2\n');
12+
});
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

5-
stringify( [
5+
stringify([
66
{ a: '1', b: '2' }
77
], {
88
header: true,
99
columns: [ { key: 'a', header: 'col_a' }, { key: 'b', header: 'col_b' } ]
1010
}, function(err, data){
11-
assert.equal(data, 'col_a,col_b\n1,2\n')
12-
})
11+
assert.equal(data, 'col_a,col_b\n1,2\n');
12+
});
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

55
stringify([
66
['1', ''],
@@ -10,5 +10,5 @@ stringify([
1010
], {
1111
quoted: true
1212
}, function(err, records){
13-
assert.equal(records, '"1",\n,"2"\n"3",\n,"4"\n')
14-
})
13+
assert.equal(records, '"1",\n,"2"\n"3",\n,"4"\n');
14+
});
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

55
stringify([
66
['1', ''],
@@ -10,5 +10,5 @@ stringify([
1010
], {
1111
quoted_empty: true
1212
}, function(err, records){
13-
assert.equal(records, '1,""\n"",2\n3,""\n"",4\n')
14-
})
13+
assert.equal(records, '1,""\n"",2\n3,""\n"",4\n');
14+
});
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

55
stringify([
66
['a value', '.', 'value.with.dot'],
77
], {
88
quoted_match: /\./
99
}, function(err, records){
10-
assert.equal(records, 'a value,".","value.with.dot"\n')
11-
})
10+
assert.equal(records, 'a value,".","value.with.dot"\n');
11+
});
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

55
stringify([
66
['a value', '.', 'value.with.dot'],
77
], {
88
quoted_match: '.'
99
}, function(err, records){
10-
assert.equal(records, 'a value,".","value.with.dot"\n')
11-
})
10+
assert.equal(records, 'a value,".","value.with.dot"\n');
11+
});
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
import { stringify } from 'csv-stringify'
3-
import assert from 'assert'
2+
import { stringify } from 'csv-stringify';
3+
import assert from 'assert';
44

55
stringify([
66
['1', '', true, 2],
77
], {
88
quoted_string: true
99
}, function(err, records){
10-
assert.equal(records, '"1","",1,2\n')
11-
})
10+
assert.equal(records, '"1","",1,2\n');
11+
});

packages/stream-transform/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@
6464
"build": "npm run build:rollup && npm run build:ts",
6565
"build:rollup": "npx rollup -c",
6666
"build:ts": "cp lib/*.ts dist/cjs && cp lib/*.ts dist/esm",
67-
"lint": "npm run lint:coffee && npm run lint:js",
68-
"lint:coffee": "coffeelint test/*.coffee",
69-
"lint:js": "eslint lib/*.js",
67+
"lint": "npm run lint:test && npm run lint:lib && npm run lint:samples",
68+
"lint:test": "coffeelint test/*.coffee",
69+
"lint:lib": "eslint lib/*.js",
70+
"lint:samples": "eslint samples/*.js",
7071
"preversion": "npm run build && git add dist",
7172
"pretest": "npm run build",
7273
"test": "mocha 'test/**/*.{coffee,ts}'"
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11

2-
import { transform } from 'stream-transform'
3-
import assert from 'assert'
2+
import { transform } from 'stream-transform';
3+
import assert from 'assert';
44

55
transform([
66
['1','2','3','4'],
77
['a','b','c','d']
88
], function(record){
9-
record.push(record.shift())
10-
return record
9+
record.push(record.shift());
10+
return record;
1111
}, function(err, output){
1212
assert.deepEqual(output, [
1313
[ '2', '3', '4', '1' ],
1414
[ 'b', 'c', 'd', 'a' ]
15-
])
16-
})
15+
]);
16+
});

0 commit comments

Comments
 (0)