Skip to content

Commit 3f238a0

Browse files
committed
src: add eslint configuration and npm script
Automatically fixed > 2000 issues. The remaining 200+ issues need to be fixed by hand. Additionally, all strings are double quotes which is not typically standard and I wonder about fixing that too. Signed-off-by: Lance Ball <lball@redhat.com>
1 parent b03a243 commit 3f238a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+3601
-2267
lines changed

.eslintrc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"env": {
4+
"es6": true,
5+
"node": true,
6+
"mocha": true
7+
},
8+
"rules": {
9+
"space-before-function-paren": ["error", "never"],
10+
"standard/no-callback-literal": "off",
11+
"arrow-spacing": "error",
12+
"arrow-parens": ["error", "always"],
13+
"arrow-body-style": ["error", "as-needed"],
14+
"prefer-template": "error",
15+
"max-len": ["warn", { "code": 80 }],
16+
"no-unused-vars": ["warn", {
17+
"argsIgnorePattern": "^_$|^e$|^reject$|^resolve$"
18+
}],
19+
"no-console": ["error", {
20+
"allow": ["warn", "error"]
21+
}],
22+
"valid-jsdoc": "error",
23+
"semi": ["error", "always"],
24+
"quotes": ["error", "double", { "allowTemplateLiterals": true }]
25+
}
26+
}

examples/express-ex/index.js

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-console */
2+
13
const express = require("express");
24
const app = express();
35

@@ -12,103 +14,101 @@ const structured1 = new v1.StructuredHTTPReceiver();
1214
const binary1 = new v1.BinaryHTTPReceiver();
1315

1416
app.use((req, res, next) => {
15-
let data="";
17+
let data = "";
1618

17-
req.setEncoding("utf8");
18-
req.on("data", function(chunk) {
19-
data += chunk;
20-
});
19+
req.setEncoding("utf8");
20+
req.on("data", function(chunk) {
21+
data += chunk;
22+
});
2123

22-
req.on("end", function() {
23-
req.body = data;
24-
next();
25-
});
24+
req.on("end", function() {
25+
req.body = data;
26+
next();
27+
});
2628
});
2729

28-
app.post("/v1", function (req, res) {
30+
app.post("/v1", function(req, res) {
2931
console.log(req.headers);
3032
console.log(req.body);
3133

3234
try {
33-
let myevent = structured1.parse(req.body, req.headers);
35+
const myevent = structured1.parse(req.body, req.headers);
3436
// pretty print
3537
console.log("Accepted event:");
3638
console.log(JSON.stringify(myevent.format(), null, 2));
3739

3840
res.status(201)
39-
.json(myevent.format());
40-
41+
.json(myevent.format());
4142
} catch (err) {
4243
console.error(err);
4344
res.status(415)
44-
.header("Content-Type", "application/json")
45-
.send(JSON.stringify(err));
45+
.header("Content-Type", "application/json")
46+
.send(JSON.stringify(err));
4647
}
4748
});
4849

49-
app.post("/v1/binary", function (req, res) {
50+
app.post("/v1/binary", function(req, res) {
5051
console.log(req.headers);
5152
console.log(req.body);
5253

5354
try {
54-
let myevent = binary1.parse(req.body, req.headers);
55+
const myevent = binary1.parse(req.body, req.headers);
5556
// pretty print
5657
console.log("Accepted event:");
5758
console.log(JSON.stringify(myevent.format(), null, 2));
5859

5960
res.status(201)
60-
.json(myevent.format());
61-
61+
.json(myevent.format());
6262
} catch (err) {
6363
console.error(err);
6464
res.status(415)
65-
.header("Content-Type", "application/json")
66-
.send(JSON.stringify(err));
65+
.header("Content-Type", "application/json")
66+
.send(JSON.stringify(err));
6767
}
6868
});
6969

70-
app.post("/v03", function (req, res) {
70+
app.post("/v03", function(req, res) {
7171
console.log(req.headers);
7272
console.log(req.body);
7373

7474
unmarshaller03.unmarshall(req.body, req.headers)
75-
.then(cloudevent => {
75+
.then((cloudevent) => {
7676
// pretty print
7777
console.log("Accepted event:");
7878
console.log(JSON.stringify(cloudevent.format(), null, 2));
7979

8080
res.status(201)
81-
.json(cloudevent.format());
82-
})
83-
.catch(err => {
84-
console.error(err);
85-
res.status(415)
86-
.header("Content-Type", "application/json")
87-
.send(JSON.stringify(err));
88-
});
81+
.json(cloudevent.format());
82+
})
83+
.catch((err) => {
84+
console.error(err);
85+
res.status(415)
86+
.header("Content-Type", "application/json")
87+
.send(JSON.stringify(err));
88+
});
8989
});
9090

91-
app.post("/v02", function (req, res) {
91+
app.post("/v02", function(req, res) {
9292
console.log(req.headers);
9393
console.log(req.body);
9494

9595
unmarshaller02.unmarshall(req.body, req.headers)
96-
.then(cloudevent => {
96+
.then((cloudevent) => {
9797
// pretty print
9898
console.log("Accepted event:");
9999
console.log(JSON.stringify(cloudevent.format(), null, 2));
100100

101101
res.status(201)
102-
.json(cloudevent.format());
103-
})
104-
.catch(err => {
105-
console.error(err);
106-
res.status(415)
107-
.header("Content-Type", "application/json")
108-
.send(JSON.stringify(err));
109-
});
102+
.json(cloudevent.format());
103+
})
104+
.catch((err) => {
105+
console.error(err);
106+
res.status(415)
107+
.header("Content-Type", "application/json")
108+
.send(JSON.stringify(err));
109+
});
110110
});
111111

112-
app.listen(3000, function () {
112+
app.listen(3000, function() {
113113
console.log("Example app listening on port 3000!");
114114
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
singleQuote: true,
3-
trailingComma: 'es5',
3+
trailingComma: "es5"
44
};

lib/bindings/http/commons.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@ const Constants = require("./constants.js");
22

33
// Specific sanity for content-type header
44
function sanityContentType(contentType) {
5-
if(contentType) {
5+
if (contentType) {
66
return Array.of(contentType)
7-
.map((c) => c.split(";"))
8-
.map((c) => c.shift())
9-
.shift();
7+
.map((c) => c.split(";"))
8+
.map((c) => c.shift())
9+
.shift();
1010
}
1111

1212
return contentType;
1313
}
1414

1515
function sanityAndClone(headers) {
16-
1716
const sanityHeaders = {};
1817

1918
Array.from(Object.keys(headers))

lib/bindings/http/constants.js

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,92 @@
11
// Commons
22
module.exports = {
3-
HEADERS : "headers",
4-
CHARSET_DEFAULT : "utf-8",
3+
HEADERS: "headers",
4+
CHARSET_DEFAULT: "utf-8",
55

6-
SPEC_V02 : "0.2",
7-
SPEC_V03 : "0.3",
8-
SPEC_V1 : "1.0",
6+
SPEC_V02: "0.2",
7+
SPEC_V03: "0.3",
8+
SPEC_V1: "1.0",
99

10-
DEFAULT_SPEC_VERSION_HEADER : "ce-specversion",
10+
DEFAULT_SPEC_VERSION_HEADER: "ce-specversion",
1111

12-
ENCODING_BASE64 : "base64",
12+
ENCODING_BASE64: "base64",
1313

14-
DATA_ATTRIBUTE : "data",
14+
DATA_ATTRIBUTE: "data",
1515

16-
MIME_JSON : "application/json",
17-
MIME_OCTET_STREAM : "application/octet-stream",
18-
MIME_CE : "application/cloudevents",
19-
MIME_CE_JSON : "application/cloudevents+json",
16+
MIME_JSON: "application/json",
17+
MIME_OCTET_STREAM: "application/octet-stream",
18+
MIME_CE: "application/cloudevents",
19+
MIME_CE_JSON: "application/cloudevents+json",
2020

21-
HEADER_CONTENT_TYPE : "content-type",
21+
HEADER_CONTENT_TYPE: "content-type",
2222

23-
DEFAULT_CONTENT_TYPE : "application/json; charset=utf-8",
24-
DEFAULT_CE_CONTENT_TYPE : "application/cloudevents+json; charset=utf-8",
23+
DEFAULT_CONTENT_TYPE: "application/json; charset=utf-8",
24+
DEFAULT_CE_CONTENT_TYPE: "application/cloudevents+json; charset=utf-8",
2525

26-
BINARY_HEADERS_02 : {
27-
TYPE : "ce-type",
28-
SPEC_VERSION : "ce-specversion",
29-
SOURCE : "ce-source",
30-
ID : "ce-id",
31-
TIME : "ce-time",
32-
SCHEMA_URL : "ce-schemaurl",
33-
EXTENSIONS_PREFIX : "ce-"
26+
BINARY_HEADERS_02: {
27+
TYPE: "ce-type",
28+
SPEC_VERSION: "ce-specversion",
29+
SOURCE: "ce-source",
30+
ID: "ce-id",
31+
TIME: "ce-time",
32+
SCHEMA_URL: "ce-schemaurl",
33+
EXTENSIONS_PREFIX: "ce-"
3434
},
35-
STRUCTURED_ATTRS_02 : {
36-
TYPE : "type",
37-
SPEC_VERSION : "specversion",
38-
SOURCE : "source",
39-
ID : "id",
40-
TIME : "time",
41-
SCHEMA_URL : "schemaurl",
42-
CONTENT_TYPE : "contenttype",
43-
DATA : "data"
35+
STRUCTURED_ATTRS_02: {
36+
TYPE: "type",
37+
SPEC_VERSION: "specversion",
38+
SOURCE: "source",
39+
ID: "id",
40+
TIME: "time",
41+
SCHEMA_URL: "schemaurl",
42+
CONTENT_TYPE: "contenttype",
43+
DATA: "data"
4444
},
4545

46-
BINARY_HEADERS_03 : {
47-
TYPE : "ce-type",
48-
SPEC_VERSION : "ce-specversion",
49-
SOURCE : "ce-source",
50-
ID : "ce-id",
51-
TIME : "ce-time",
52-
SCHEMA_URL : "ce-schemaurl",
53-
CONTENT_ENCONDING : "ce-datacontentencoding",
54-
SUBJECT : "ce-subject",
55-
EXTENSIONS_PREFIX : "ce-"
46+
BINARY_HEADERS_03: {
47+
TYPE: "ce-type",
48+
SPEC_VERSION: "ce-specversion",
49+
SOURCE: "ce-source",
50+
ID: "ce-id",
51+
TIME: "ce-time",
52+
SCHEMA_URL: "ce-schemaurl",
53+
CONTENT_ENCONDING: "ce-datacontentencoding",
54+
SUBJECT: "ce-subject",
55+
EXTENSIONS_PREFIX: "ce-"
5656
},
57-
STRUCTURED_ATTRS_03 : {
58-
TYPE : "type",
59-
SPEC_VERSION : "specversion",
60-
SOURCE : "source",
61-
ID : "id",
62-
TIME : "time",
63-
SCHEMA_URL : "schemaurl",
64-
CONTENT_ENCONDING : "datacontentencoding",
65-
CONTENT_TYPE : "datacontenttype",
66-
SUBJECT : "subject",
67-
DATA : "data"
57+
STRUCTURED_ATTRS_03: {
58+
TYPE: "type",
59+
SPEC_VERSION: "specversion",
60+
SOURCE: "source",
61+
ID: "id",
62+
TIME: "time",
63+
SCHEMA_URL: "schemaurl",
64+
CONTENT_ENCONDING: "datacontentencoding",
65+
CONTENT_TYPE: "datacontenttype",
66+
SUBJECT: "subject",
67+
DATA: "data"
6868
},
6969

70-
BINARY_HEADERS_1 : {
71-
TYPE : "ce-type",
72-
SPEC_VERSION : "ce-specversion",
73-
SOURCE : "ce-source",
74-
ID : "ce-id",
75-
TIME : "ce-time",
76-
DATA_SCHEMA : "ce-dataschema",
77-
SUBJECT : "ce-subject",
78-
EXTENSIONS_PREFIX : "ce-"
70+
BINARY_HEADERS_1: {
71+
TYPE: "ce-type",
72+
SPEC_VERSION: "ce-specversion",
73+
SOURCE: "ce-source",
74+
ID: "ce-id",
75+
TIME: "ce-time",
76+
DATA_SCHEMA: "ce-dataschema",
77+
SUBJECT: "ce-subject",
78+
EXTENSIONS_PREFIX: "ce-"
7979
},
80-
STRUCTURED_ATTRS_1 : {
81-
TYPE : "type",
82-
SPEC_VERSION : "specversion",
83-
SOURCE : "source",
84-
ID : "id",
85-
TIME : "time",
86-
DATA_SCHEMA : "dataschema",
87-
CONTENT_TYPE : "datacontenttype",
88-
SUBJECT : "subject",
89-
DATA : "data",
90-
DATA_BASE64 : "data_base64"
80+
STRUCTURED_ATTRS_1: {
81+
TYPE: "type",
82+
SPEC_VERSION: "specversion",
83+
SOURCE: "source",
84+
ID: "id",
85+
TIME: "time",
86+
DATA_SCHEMA: "dataschema",
87+
CONTENT_TYPE: "datacontenttype",
88+
SUBJECT: "subject",
89+
DATA: "data",
90+
DATA_BASE64: "data_base64"
9191
}
9292
};

0 commit comments

Comments
 (0)