Skip to content

Commit

Permalink
Merge pull request #100 from e-flux-platform/formatting
Browse files Browse the repository at this point in the history
Apply prettier and enforce formatting via CI
  • Loading branch information
nick-jones authored Sep 13, 2024
2 parents fac026d + 327f880 commit a47566a
Show file tree
Hide file tree
Showing 33 changed files with 455 additions and 349 deletions.
6 changes: 5 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"presets": ["@babel/preset-env", "@babel/preset-react", "@babel/preset-typescript"],
"presets": [
"@babel/preset-env",
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": [
["lodash"],
["react-hot-loader/babel"],
Expand Down
4 changes: 1 addition & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ module.exports = {
globals: {
__ENV__: 'readonly',
},
ignorePatterns: [
'.eslintrc.js'
]
ignorePatterns: ['.eslintrc.js'],
};
24 changes: 24 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Check pull request

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
timeout-minutes: 5

- name: Install node
uses: actions/setup-node@v4
with:
node-version-file: package.json

- name: Install dependencies
run: yarn install

- name: Run lint
run: yarn lint
8 changes: 7 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
src/components/RichTextEditor/utils/draft/__fixtures__/example.md
**/*.md
**/*.html
src/schemas
.webpack-cache
dist
**/.yarn
src/semantic/
23 changes: 18 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"build": "NODE_ENV=production NODE_OPTIONS=\"--max-old-space-size=4096\" webpack",
"start": "node ./serve/dev",
"static": "node ./serve/static",
"lint": "eslint",
"lint": "eslint && yarn prettier --check .",
"test": "jest",
"generate": "cd ../../generator && yarn install && yarn generate",
"postinstall": "cd serve && yarn install"
"postinstall": "cd serve && yarn install",
"format": "yarn prettier --write ."
},
"dependencies": {
"@babel/core": "^7.24.6",
Expand Down Expand Up @@ -88,7 +89,6 @@
},
"devDependencies": {
"@babel/eslint-parser": "^7.24.6",
"@bedrockio/prettier-config": "^1.0.1",
"@testing-library/dom": "^7.30.3",
"@testing-library/react": "^11.2.5",
"@testing-library/user-event": "^13.1.1",
Expand All @@ -102,14 +102,27 @@
"eslint-plugin-bedrock": "^1.0.9",
"jest": "^28.0.0",
"node-mocks-http": "^1.8.1",
"prettier": "^2.4.1",
"prettier": "^3.3.3",
"typescript": "^5.0.3",
"webpack-bundle-analyzer": "^4.5.0"
},
"volta": {
"node": "20.9.0",
"yarn": "1.22.17"
},
"prettier": "@bedrockio/prettier-config",
"prettier": {
"singleQuote": true,
"bracketSameLine": true,
"trailingComma": "es5",
"proseWrap": "always",
"overrides": [
{
"files": "*.json",
"options": {
"parser": "json-stringify"
}
}
]
},
"packageManager": "yarn@1.22.22"
}
2 changes: 1 addition & 1 deletion src/components/SearchDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default class SearchDropdown extends React.Component {
});

if (!this.state.objectMode) {
return this.props.onChange(evt, {
return this.props.onChange(evt, {
...rest,
value,
item: this.props.multiple ? selected : selected[0],
Expand Down
114 changes: 61 additions & 53 deletions src/lib/ChargeStation/clock.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,83 @@
// Class representing clock, used to enable 'time travel' in the simulation
class Clock {
protected nowDate: Date
protected clockInterval
constructor(protected speed = 1) {
this.nowDate = new Date();
this.clockInterval = setInterval(() => {
this.nowDate.setTime(this.nowDate.getTime() + (1000 * this.speed))
}, 1000)
}
protected nowDate: Date;
protected clockInterval;
constructor(protected speed = 1) {
this.nowDate = new Date();
this.clockInterval = setInterval(() => {
this.nowDate.setTime(this.nowDate.getTime() + 1000 * this.speed);
}, 1000);
}

public setSpeed(speed: number) {
this.speed = speed;
}
public setSpeed(speed: number) {
this.speed = speed;
}

public getSpeed() {
return this.speed;
}
public getSpeed() {
return this.speed;
}

public secondsSince(since: Date) {
return Math.round((this.nowDate.getTime() - since.getTime()) / 1000);
}
public secondsSince(since: Date) {
return Math.round((this.nowDate.getTime() - since.getTime()) / 1000);
}

public reset() {
this.nowDate = new Date();
}
public reset() {
this.nowDate = new Date();
}

public now() {
return new Date(this.nowDate);
}
public now() {
return new Date(this.nowDate);
}

public setInterval(callback: Function, interval: number, name: string = ""): Interval {
return new Interval(this, callback, interval, name);
}
public setInterval(
callback: Function,
interval: number,
name: string = ''
): Interval {
return new Interval(this, callback, interval, name);
}

public adjustBySpeed(input: number): number {
return Math.floor(input / this.speed);
}
public adjustBySpeed(input: number): number {
return Math.floor(input / this.speed);
}
}

class Interval {
protected timeoutHandle: NodeJS.Timeout | undefined;
protected continue: boolean = false;
constructor(
protected readonly clock: Clock,
protected readonly callback: Function,
protected readonly interval: number,
protected readonly name: string
) {
this.start();
}

protected timeoutHandle: NodeJS.Timeout | undefined;
protected continue: boolean = false;
constructor(protected readonly clock: Clock, protected readonly callback: Function, protected readonly interval: number, protected readonly name: string) {
this.start();
}
public start() {
this.continue = true;
this.tick();
}

public start() {
this.continue = true;
this.tick();
}
public stop() {
this.continue = false;
clearTimeout(this.timeoutHandle);
}

public stop() {
this.continue = false;
clearTimeout(this.timeoutHandle);
}

protected tick() {
if (this.continue) {
this.timeoutHandle = setTimeout(() => {
if (!this.continue) {
return;
}
this.callback();
this.tick();
}, this.interval / this.clock.getSpeed())
protected tick() {
if (this.continue) {
this.timeoutHandle = setTimeout(() => {
if (!this.continue) {
return;
}
this.callback();
this.tick();
}, this.interval / this.clock.getSpeed());
}
}
}

const clock = new Clock();

export default clock;
export {Interval};
export { Interval };
6 changes: 4 additions & 2 deletions src/lib/ChargeStation/configurations/ads-tec-ocpp-16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import { AuthorizationType } from 'lib/settings';
const initiateSession: ChargeStationEventHandler = async (params) => {
const { session, chargepoint } = params;
if (session.options.authorizationType === AuthorizationType.CreditCard) {
session.options.uid = chargepoint.configuration.getVariableValue('CreditIdToken') as string;
session.options.uid = chargepoint.configuration.getVariableValue(
'CreditIdToken'
) as string;
await sendStartTransaction(params);
} else {
await sendAuthorize(params);
}
}
};

export default {
...DefaultOCPP16,
Expand Down
13 changes: 11 additions & 2 deletions src/lib/ChargeStation/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ class Connection {

onReceiveCall = (method: string, payload: unknown, messageId: string) => {};
onReceiveCallResult = (messageId: string, payload: string) => {};
onReceiveCallError = (messageId: string, errorCode: string, errorDescription: string, errorDetails: string) => {};
onReceiveCallError = (
messageId: string,
errorCode: string,
errorDescription: string,
errorDetails: string
) => {};

constructor(ocppBaseUrl: string, ocppIdentity: string, version: string) {
this.ocppBaseUrl = ocppBaseUrl;
Expand Down Expand Up @@ -135,7 +140,11 @@ class Connection {
const promise = new Promise<void>((resolve, reject) => {
const timeoutId = setTimeout(() => {
this.inflight = undefined;
reject(new Error(`Call with message id ${messageId} timed out after ${this.inflightTimeoutMs / 1000} seconds`));
reject(
new Error(
`Call with message id ${messageId} timed out after ${this.inflightTimeoutMs / 1000} seconds`
)
);
}, this.inflightTimeoutMs);

this.inflight = {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ChargeStation/eventHandlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface ChargeStationEventHandlerParams<CallBodyType, CallResultBodyType> {

export type ChargeStationEventHandler<
CallBodyType = unknown,
CallResultBodyType = unknown
CallResultBodyType = unknown,
> = (
params: ChargeStationEventHandlerParams<CallBodyType, CallResultBodyType>
) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers';
import { ChangeConfigurationRequest } from 'schemas/ocpp/1.6/ChangeConfiguration';

const handleChangeConfigurationHandler: ChargeStationEventHandler<ChangeConfigurationRequest> =
({ chargepoint, callMessageId, callMessageBody }) => {
const { key } = callMessageBody;
const handleChangeConfigurationHandler: ChargeStationEventHandler<
ChangeConfigurationRequest
> = ({ chargepoint, callMessageId, callMessageBody }) => {
const { key } = callMessageBody;

chargepoint.configuration.setVariable(key, callMessageBody);
chargepoint.configuration.setVariable(key, callMessageBody);

const response = {
status: 'Accepted',
};

chargepoint.writeCallResult(callMessageId, response);
chargepoint.save();
const response = {
status: 'Accepted',
};

chargepoint.writeCallResult(callMessageId, response);
chargepoint.save();
};

export default handleChangeConfigurationHandler;
14 changes: 8 additions & 6 deletions src/lib/ChargeStation/eventHandlers/ocpp-16/handle-reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers';
import { ResetRequest } from 'schemas/ocpp/1.6/Reset';
import { ResetResponse } from 'schemas/ocpp/1.6/ResetResponse';

const handleReset: ChargeStationEventHandler<ResetRequest> =
({ chargepoint, callMessageId }) => {
const response: ResetResponse = {status: 'Accepted',};
const handleReset: ChargeStationEventHandler<ResetRequest> = ({
chargepoint,
callMessageId,
}) => {
const response: ResetResponse = { status: 'Accepted' };

chargepoint.writeCallResult(callMessageId, response);
chargepoint.reboot();
};
chargepoint.writeCallResult(callMessageId, response);
chargepoint.reboot();
};

export default handleReset;
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { ChargeStationEventHandler } from 'lib/ChargeStation/eventHandlers';
import { SetChargingProfileRequest } from 'schemas/ocpp/1.6/SetChargingProfile';
import { SetChargingProfileResponse } from 'schemas/ocpp/1.6/SetChargingProfileResponse';

const handleSetChargingProfile: ChargeStationEventHandler<SetChargingProfileRequest> =
({ chargepoint, callMessageId }) => {
const response: SetChargingProfileResponse = {status: 'Accepted'};
const handleSetChargingProfile: ChargeStationEventHandler<
SetChargingProfileRequest
> = ({ chargepoint, callMessageId }) => {
const response: SetChargingProfileResponse = { status: 'Accepted' };

chargepoint.writeCallResult(callMessageId, response);
};
chargepoint.writeCallResult(callMessageId, response);
};

export default handleSetChargingProfile;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default async function handleStartCharging({ emitter, session }) {
session.tickInterval = clock.setInterval(() => {
session.tick(clock.secondsSince(timeSince));
timeSince = clock.now();
}, 5000)
}, 5000);

await sleep(500);
session.tick(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import clock from 'lib/ChargeStation/clock';
const sendHeartbeatDelayed: ChargeStationEventHandler = async ({
chargepoint,
}) => {

await sleep(clock.adjustBySpeed(chargepoint.configuration.getHeartbeatInterval()));
await sleep(
clock.adjustBySpeed(chargepoint.configuration.getHeartbeatInterval())
);
if (!chargepoint.connected) {
return;
}
Expand Down
Loading

0 comments on commit a47566a

Please sign in to comment.