Skip to content

Commit a00f057

Browse files
committed
[Tests] add linting
1 parent 27527bb commit a00f057

20 files changed

+153
-82
lines changed

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# eslintignore
2+
3+
# TODO: fix
4+
index.js

.eslintrc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"root": true,
3+
"extends": "@ljharb",
4+
"rules": {
5+
"indent": [2, 4],
6+
"strict": 1,
7+
"no-octal-escape": 1,
8+
},
9+
"globals": {
10+
"BigInt": false,
11+
},
12+
"overrides": [
13+
{
14+
"files": ["test/**", "test-*", "example/**"],
15+
"rules": {
16+
"array-bracket-newline": 0,
17+
"max-params": 0,
18+
"max-statements": 0,
19+
"max-statements-per-line": 0,
20+
"no-magic-numbers": 0,
21+
"object-curly-newline": 0,
22+
"sort-keys": 0,
23+
},
24+
},
25+
{
26+
"files": ["example/**"],
27+
"rules": {
28+
"no-console": 0,
29+
},
30+
},
31+
{
32+
"files": ["test/browser/**"],
33+
"env": {
34+
"browser": true,
35+
},
36+
},
37+
{
38+
"files": ["test/bigint*"],
39+
"rules": {
40+
"new-cap": [2, { "capIsNewExceptions": ["BigInt"] }],
41+
},
42+
},
43+
],
44+
}

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ matrix:
3535
include:
3636
- node_js: "10.0"
3737
env: BIGINT=true
38+
- node_js: "lts/*"
39+
env: PRETEST=true
3840
- node_js: "node"
3941
env: COVERAGE=true
4042
- node_js: "9.10"

example/all.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
'use strict';
2+
13
var inspect = require('../');
24
var Buffer = require('safer-buffer').Buffer;
35

4-
var holes = [ 'a', 'b' ];
5-
holes[4] = 'e', holes[6] = 'g';
6+
var holes = ['a', 'b'];
7+
holes[4] = 'e';
8+
holes[6] = 'g';
9+
610
var obj = {
711
a: 1,
8-
b: [ 3, 4, undefined, null ],
12+
b: [3, 4, undefined, null],
913
c: undefined,
1014
d: null,
1115
e: {
1216
regex: /^x/i,
1317
buf: Buffer.from('abc'),
1418
holes: holes
1519
},
16-
now: new Date
20+
now: new Date()
1721
};
1822
obj.self = obj;
1923
console.log(inspect(obj));

example/circular.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
'use strict';
2+
13
var inspect = require('../');
2-
var obj = { a: 1, b: [3,4] };
4+
var obj = { a: 1, b: [3, 4] };
35
obj.c = obj;
46
console.log(inspect(obj));

example/fn.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
var inspect = require('../');
2-
var obj = [ 1, 2, function f (n) { return n + 5 }, 4 ];
4+
var obj = [1, 2, function f(n) { return n + 5; }, 4];
35
console.log(inspect(obj));

example/inspect.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
'use strict';
2+
3+
/* eslint-env browser */
14
var inspect = require('../');
25

36
var d = document.createElement('div');
47
d.setAttribute('id', 'beep');
58
d.innerHTML = '<b>wooo</b><i>iiiii</i>';
69

7-
console.log(inspect([ d, { a: 3, b : 4, c: [5,6,[7,[8,[9]]]] } ]));
10+
console.log(inspect([d, { a: 3, b: 4, c: [5, 6, [7, [8, [9]]]] }]));

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
"description": "string representations of objects in node and the browser",
55
"main": "index.js",
66
"devDependencies": {
7+
"@ljharb/eslint-config": "^13.1.1",
78
"core-js": "^2.5.5",
9+
"eslint": "^5.16.0",
810
"nyc": "^10.3.2",
911
"tape": "^4.9.0"
1012
},
1113
"scripts": {
14+
"pretest": "npm run lint",
15+
"lint": "eslint .",
1216
"test": "npm run tests-only",
1317
"posttest": "npm run test:bigint",
1418
"pretests-only": "node test-core-js",

test/bigint.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@ var inspect = require('../');
22
var test = require('tape');
33

44
test('bigint', { skip: typeof BigInt === 'undefined' }, function (t) {
5-
t.test('primitives', function (st) {
6-
st.plan(3);
5+
t.test('primitives', function (st) {
6+
st.plan(3);
77

8-
st.equal(inspect(BigInt(-256)), '-256n');
9-
st.equal(inspect(BigInt(0)), '0n');
10-
st.equal(inspect(BigInt(256)), '256n');
11-
});
8+
st.equal(inspect(BigInt(-256)), '-256n');
9+
st.equal(inspect(BigInt(0)), '0n');
10+
st.equal(inspect(BigInt(256)), '256n');
11+
});
1212

13-
t.test('objects', function (st) {
14-
st.plan(3);
13+
t.test('objects', function (st) {
14+
st.plan(3);
1515

16-
st.equal(inspect(Object(BigInt(-256))), 'Object(-256n)');
17-
st.equal(inspect(Object(BigInt(0))), 'Object(0n)');
18-
st.equal(inspect(Object(BigInt(256))), 'Object(256n)');
19-
});
16+
st.equal(inspect(Object(BigInt(-256))), 'Object(-256n)');
17+
st.equal(inspect(Object(BigInt(0))), 'Object(0n)');
18+
st.equal(inspect(Object(BigInt(256))), 'Object(256n)');
19+
});
2020

21-
t.test('syntactic primitives', function (st) {
22-
st.plan(3);
21+
t.test('syntactic primitives', function (st) {
22+
st.plan(3);
2323

24-
st.equal(inspect(Function('return -256n')()), '-256n');
25-
st.equal(inspect(Function('return 0n')()), '0n');
26-
st.equal(inspect(Function('return 256n')()), '256n');
27-
});
24+
/* eslint-disable no-new-func */
25+
st.equal(inspect(Function('return -256n')()), '-256n');
26+
st.equal(inspect(Function('return 0n')()), '0n');
27+
st.equal(inspect(Function('return 256n')()), '256n');
28+
});
2829

29-
t.end();
30+
t.end();
3031
});

test/browser/dom.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ var test = require('tape');
33

44
test('dom element', function (t) {
55
t.plan(1);
6-
6+
77
var d = document.createElement('div');
88
d.setAttribute('id', 'beep');
99
d.innerHTML = '<b>wooo</b><i>iiiii</i>';
10-
10+
1111
t.equal(
12-
inspect([ d, { a: 3, b : 4, c: [5,6,[7,[8,[9]]]] } ]),
12+
inspect([d, { a: 3, b: 4, c: [5, 6, [7, [8, [9]]]] }]),
1313
'[ <div id="beep">...</div>, { a: 3, b: 4, c: [ 5, 6, [ 7, [ 8, [Object] ] ] ] } ]'
1414
);
1515
});

0 commit comments

Comments
 (0)