Skip to content

Commit 06ff4be

Browse files
Added eslint config. Formatted code base
1 parent 5421ae5 commit 06ff4be

28 files changed

+2784
-2028
lines changed

.babelrc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
2-
"presets": [
3-
['@babel/preset-env', {targets: {node: 'current'}}],
4-
'@babel/preset-typescript',
5-
],
6-
"plugins": []
2+
"presets": [
3+
[
4+
"@babel/preset-env", {
5+
"targets": {
6+
"node": "current"
7+
}
8+
}
9+
],
10+
"@babel/preset-typescript"
11+
],
12+
"plugins": []
713
}

.eslintrc.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

.eslintrc.json

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": "plugin:@typescript-eslint/recommended",
7+
"overrides": [
8+
],
9+
"parserOptions": {
10+
"ecmaVersion": "latest",
11+
"sourceType": "module"
12+
},
13+
"rules": {
14+
"no-unused-vars": "off",
15+
"react/prop-types": "off",
16+
"import/prefer-default-export": "off",
17+
"no-shadow": "off",
18+
"@typescript-eslint/no-shadow": ["error"],
19+
"no-explicit-any": "off",
20+
"@typescript-eslint/no-unused-vars": ["warn"],
21+
"semi": ["error", "always"],
22+
"quotes": [
23+
"error",
24+
"double",
25+
{
26+
"avoidEscape": true,
27+
"allowTemplateLiterals": true
28+
}
29+
],
30+
"@typescript-eslint/semi": ["warn"],
31+
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
32+
"function-paren-newline": [
33+
"error",
34+
{
35+
"minItems": 2
36+
}
37+
],
38+
"no-unsafe-optional-chaining": "error",
39+
"indent": [
40+
"error",
41+
"tab",
42+
{
43+
"VariableDeclarator": {
44+
"var": 2,
45+
"let": 2,
46+
"const": 3
47+
},
48+
"MemberExpression": 1,
49+
"FunctionExpression": {
50+
"parameters": "first"
51+
},
52+
"FunctionDeclaration": {
53+
"body": 2,
54+
"parameters": "first"
55+
},
56+
"ArrayExpression": 1,
57+
"ObjectExpression": 1,
58+
"ImportDeclaration": 1,
59+
"ignoreComments": true,
60+
"ignoredNodes": [
61+
"JSXElement *",
62+
"JSXElement",
63+
"JSXSpreadAttribute",
64+
"JSXAttribute"
65+
],
66+
"SwitchCase": 1
67+
}
68+
],
69+
"function-call-argument-newline": ["error", "always"],
70+
"object-curly-newline": [
71+
"error",
72+
{
73+
"ImportDeclaration": {
74+
"multiline": true,
75+
"minProperties": 3
76+
},
77+
"ExportDeclaration": "never"
78+
}
79+
],
80+
"sort-imports": [
81+
"error",
82+
{
83+
"ignoreCase": false,
84+
"ignoreDeclarationSort": true,
85+
"ignoreMemberSort": true,
86+
"memberSyntaxSortOrder": [
87+
"none",
88+
"all",
89+
"multiple",
90+
"single"
91+
],
92+
"allowSeparatedGroups": false
93+
}
94+
],
95+
"no-use-before-define": "off",
96+
"@typescript-eslint/no-use-before-define": "off",
97+
"no-multiple-empty-lines": [
98+
"error",
99+
{
100+
"max": 1,
101+
"maxEOF": 0
102+
}
103+
]
104+
}
105+
}

examples/CentralSystemSecure.ts

Lines changed: 64 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,69 @@
1-
import { IncomingMessage } from 'http';
2-
import fs from 'fs';
1+
import { IncomingMessage } from "http";
2+
import fs from "fs";
33
import {
4-
OcppServer, OcppClientConnection
5-
} from '../src/';
6-
import {BootNotificationRequest} from '../src/index'
7-
import {BootNotificationResponse} from '../src/index'
4+
OcppServer,
5+
OcppClientConnection,
6+
BootNotificationRequest,
7+
BootNotificationResponse
8+
} from "../src";
89

910
const cs = new OcppServer();
10-
cs.on('connection', (client: OcppClientConnection) => {
11-
console.log(`Client ${client.getCpId()} connected`);
12-
client.on('close', (code: number, reason: Buffer) => {
13-
console.log(`Client ${client.getCpId()} closed connection`, code, reason.toString());
14-
});
1511

16-
client.on('BootNotification', (request: BootNotificationRequest, cb: (response: BootNotificationResponse) => void) => {
17-
const response: BootNotificationResponse = {
18-
status: 'Accepted',
19-
currentTime: new Date().toISOString(),
20-
interval: 60,
21-
};
22-
cb(response);
23-
});
24-
});
12+
cs.on(
13+
"connection",
14+
(client: OcppClientConnection) => {
15+
console.log(`Client ${client.getCpId()} connected`);
2516

26-
cs.on('authorization', (cbId: string, req: IncomingMessage, cb: (err?: Error) => void) => {
27-
console.log('authorization', cbId, req.headers.authorization);
28-
// validate authorization header
29-
// cb(new Error('Unathorized')); // Deny
30-
cb(); // Accept
31-
});
32-
cs.listen(9220, {
33-
cert: fs.readFileSync('cert.pem'),
34-
key: fs.readFileSync('key.pem'),
35-
});
17+
client.on(
18+
"close",
19+
(
20+
code: number, reason: Buffer
21+
) => {
22+
console.log(
23+
`Client ${client.getCpId()} closed connection`,
24+
code,
25+
reason.toString()
26+
);
27+
}
28+
);
29+
30+
client.on(
31+
"BootNotification",
32+
(
33+
request: BootNotificationRequest,
34+
cb: (response: BootNotificationResponse) => void
35+
) => {
36+
const response: BootNotificationResponse = {
37+
status: "Accepted",
38+
currentTime: new Date().toISOString(),
39+
interval: 60,
40+
};
41+
cb(response);
42+
}
43+
);
44+
}
45+
);
46+
47+
cs.on(
48+
"authorization",
49+
(
50+
cbId: string, req: IncomingMessage, cb: (err?: Error) => void
51+
) => {
52+
console.log(
53+
"authorization",
54+
cbId,
55+
req.headers.authorization
56+
);
57+
// validate authorization header
58+
// cb(new Error('Unathorized')); // Deny
59+
cb(); // Accept
60+
}
61+
);
62+
63+
cs.listen(
64+
9220,
65+
{
66+
cert: fs.readFileSync("cert.pem"),
67+
key: fs.readFileSync("key.pem"),
68+
}
69+
);

examples/CentralSystemSimple.ts

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
11
import {
2-
OcppServer, OcppClientConnection
3-
} from '../src';
4-
import {BootNotificationRequest} from '../src/index'
5-
import {BootNotificationResponse} from '../src/index'
2+
OcppServer,
3+
OcppClientConnection,
4+
BootNotificationRequest,
5+
BootNotificationResponse
6+
} from "../src";
67

78
const centralSystemSimple = new OcppServer();
9+
810
centralSystemSimple.listen(9220);
9-
centralSystemSimple.on('connection', (client: OcppClientConnection) => {
10-
console.log(`Client ${client.getCpId()} connected`);
11-
client.on('close', (code: number, reason: Buffer) => {
12-
console.log(`Client ${client.getCpId()} closed connection`, code, reason.toString());
13-
});
1411

15-
client.on('BootNotification', (request: BootNotificationRequest, cb: (response: BootNotificationResponse) => void) => {
16-
const response: BootNotificationResponse = {
17-
status: 'Accepted',
18-
currentTime: new Date().toISOString(),
19-
interval: 60,
20-
};
21-
cb(response);
22-
});
23-
});
12+
centralSystemSimple.on(
13+
"connection",
14+
(client: OcppClientConnection) => {
15+
console.log(`Client ${client.getCpId()} connected`);
16+
17+
client.on(
18+
"close",
19+
(
20+
code: number, reason: Buffer
21+
) => {
22+
console.log(
23+
`Client ${client.getCpId()} closed connection`,
24+
code,
25+
reason.toString()
26+
);
27+
}
28+
);
29+
30+
client.on(
31+
"BootNotification",
32+
(
33+
request: BootNotificationRequest,
34+
cb: (response: BootNotificationResponse) => void
35+
) => {
36+
const response: BootNotificationResponse = {
37+
status: "Accepted",
38+
currentTime: new Date().toISOString(),
39+
interval: 60,
40+
};
41+
cb(response);
42+
}
43+
);
44+
}
45+
);

0 commit comments

Comments
 (0)