Skip to content

Commit fb8bcb8

Browse files
committed
Add prettier integration.
Also formatted files. Dude `types/barrage.ts` is fuggin gnarly just ignore it.
1 parent 35c00f0 commit fb8bcb8

21 files changed

+1211
-521
lines changed

.eslintrc.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"extends": "@augu/eslint-config/ts.js"
2+
"plugins": ["prettier"],
3+
"extends": ["@augu/eslint-config/ts.js", "plugin:prettier/recommended"]
34
}

.prettierignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.github
2+
build
3+
bundles
4+
docs
5+
node_modules

.prettierrc.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"printWidth": 100,
4+
"semi": true
5+
}

CONTRIBUTING.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Contributing
2+
3+
## Formatting & Style 👨‍🎨
4+
5+
### Explanation for using both `eslint` and `prettier`
6+
7+
Code style is handled with `eslint`, but _formatting_ is handled with `prettier`.
8+
9+
\<opinion>&nbsp;
10+
Though `eslint` can format code, `prettier` is easier to configure for the sole purpose of formatting code _and_ is already assigned as a keyboard shortcut in VS Code for me _and_ it's muscle-memory for me to format before saving.
11+
12+
So that's why there's two formatters.
13+
\</opinion>
14+
15+
Two packages are crucial in this rigamarole:
16+
17+
- `eslint-plugin-prettier`
18+
- `eslint-config-prettier` (notice **config** in the name)
19+
20+
The `eslint-plugin-prettier` is an `eslint` plugin that runs `prettier` after fixing code style. `eslint-**config**-prettier` is an `eslint` config that overules and ignores any `eslint` formatting rules, leaving it all up to `prettier` for how the code should look.
21+
22+
Apparently, `eslint-config-prettier` is necessary to prevent `eslint` and `prettier` from bickering; more on [the repo page](https://github.com/prettier/eslint-plugin-prettier#recommended-configuration)

package-lock.json

+106
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@
4747
"@typescript-eslint/eslint-plugin": "^5.30.5",
4848
"@typescript-eslint/parser": "^5.30.5",
4949
"eslint": "^8.19.0",
50+
"eslint-config-prettier": "^8.5.0",
51+
"eslint-plugin-prettier": "^4.2.1",
5052
"jest": "^26.4.2",
5153
"jest-teamcity": "^1.9.0",
54+
"prettier": "^2.7.1",
5255
"ts-jest": "^26.4.0",
5356
"typedoc": "^0.22.10",
5457
"typescript": "^4.1.5"

src/core/CacheUpdater.ts

+60-52
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@ import { check, fetch } from './UpdateChecker';
99
import { AzurAPI } from './Client';
1010

1111
export default class Updater {
12-
public cron?: NodeJS.Timeout;
13-
private client: AzurAPI;
12+
public cron?: NodeJS.Timeout;
13+
private client: AzurAPI;
1414

15-
/**
16-
* Constructor
17-
* @param client AzurAPI instance
18-
*/
19-
constructor(client: AzurAPI) {
20-
this.client = client;
21-
}
22-
23-
/**
24-
* Check for updates then update and load cache
25-
*/
26-
async update() {
27-
const updates = await check();
28-
if (updates.length > 0) {
29-
this.client.emit('updateAvalible', updates);
30-
return Promise.all(updates.map(async (type) => {
15+
/**
16+
* Constructor
17+
* @param client AzurAPI instance
18+
*/
19+
constructor(client: AzurAPI) {
20+
this.client = client;
21+
}
3122

23+
/**
24+
* Check for updates then update and load cache
25+
*/
26+
async update() {
27+
const updates = await check();
28+
if (updates.length > 0) {
29+
this.client.emit('updateAvalible', updates);
30+
return Promise.all(
31+
updates.map(async (type) => {
3232
const raw = JSON.parse(await fetch(data[type])) ?? [];
3333

3434
if (type === 'voicelines') {
@@ -49,44 +49,52 @@ export default class Updater {
4949
this.client.set(type, raw);
5050
}
5151
fs.writeFileSync(local[type], JSON.stringify(raw));
52-
}));
53-
}
52+
})
53+
);
5454
}
55+
}
5556

56-
/**
57-
* Start cron job
58-
*/
59-
start() {
60-
if (!this.cron) this.client.emit('debug', 'Notify for new data updates enabled. AzurAPI Client will check for data updates every hour.');
61-
if (this.cron) clearInterval(this.cron);
62-
this.cron = setInterval(() => this.update(), this.client.rate);
63-
}
57+
/**
58+
* Start cron job
59+
*/
60+
start() {
61+
if (!this.cron)
62+
this.client.emit(
63+
'debug',
64+
'Notify for new data updates enabled. AzurAPI Client will check for data updates every hour.'
65+
);
66+
if (this.cron) clearInterval(this.cron);
67+
this.cron = setInterval(() => this.update(), this.client.rate);
68+
}
6469

65-
/**
66-
* Stop cron job
67-
*/
68-
stop() {
69-
if (this.cron) clearInterval(this.cron);
70-
this.cron = undefined;
71-
}
70+
/**
71+
* Stop cron job
72+
*/
73+
stop() {
74+
if (this.cron) clearInterval(this.cron);
75+
this.cron = undefined;
76+
}
7277

73-
/**
74-
* Check if folder and JSON files exist then load cache
75-
*/
76-
async init() {
77-
if (!fs.existsSync(baseFolder)) fs.mkdirSync(baseFolder);
78-
await this.load();
79-
this.client.emit('ready');
80-
}
78+
/**
79+
* Check if folder and JSON files exist then load cache
80+
*/
81+
async init() {
82+
if (!fs.existsSync(baseFolder)) fs.mkdirSync(baseFolder);
83+
await this.load();
84+
this.client.emit('ready');
85+
}
8186

82-
/**
83-
* Load the cache
84-
*/
85-
load() {
86-
for (let i = 0; i < Object.keys(local).length; i++) {
87-
let key = Object.keys(local)[i];
88-
if (!fs.existsSync(local[key])) return this.update();
89-
this.client.set(key as datatype, Object.values(JSON.parse(fs.readFileSync(local[key]).toString()) || []));
90-
}
87+
/**
88+
* Load the cache
89+
*/
90+
load() {
91+
for (let i = 0; i < Object.keys(local).length; i++) {
92+
let key = Object.keys(local)[i];
93+
if (!fs.existsSync(local[key])) return this.update();
94+
this.client.set(
95+
key as datatype,
96+
Object.values(JSON.parse(fs.readFileSync(local[key]).toString()) || [])
97+
);
9198
}
99+
}
92100
}

src/core/Client.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Chapters } from './api/api_chapter';
77
import { Voicelines } from './api/api_voiceline';
88
import { datatype } from './Data';
99

10-
export type Source = 'uncached' | 'local'
10+
export type Source = 'uncached' | 'local';
1111

1212
export interface CacheOptions {
1313
source?: Source;
@@ -36,7 +36,7 @@ export class AzurAPI extends EventEmitter {
3636
equipments: this.equipments,
3737
chapters: this.chapters,
3838
voicelines: this.voicelines,
39-
barrages: this.barrages
39+
barrages: this.barrages,
4040
};
4141

4242
/**
@@ -46,7 +46,10 @@ export class AzurAPI extends EventEmitter {
4646
constructor(options?: CacheOptions) {
4747
super();
4848
//Make sure people are using Node <=14
49-
if (parseFloat(process.version.replace('v', '')) <= 14) throw new Error('AzurAPI requires Node v14 or above, if you would like to use an older Node version, please use any version of this package below v0.2.13 (Not Recommended)');
49+
if (parseFloat(process.version.replace('v', '')) <= 14)
50+
throw new Error(
51+
'AzurAPI requires Node v14 or above, if you would like to use an older Node version, please use any version of this package below v0.2.13 (Not Recommended)'
52+
);
5053
this.options = options ? options : { source: 'local', autoupdate: true, rate: 3600000 };
5154
this.source = this.options.source ? this.options.source : 'local';
5255
this.autoupdate = true;
@@ -59,13 +62,12 @@ export class AzurAPI extends EventEmitter {
5962
equipments: this.equipments,
6063
chapters: this.chapters,
6164
voicelines: this.voicelines,
62-
barrages: this.barrages
65+
barrages: this.barrages,
6366
};
6467
this.updater = new Updater(this);
6568
this.updater.init();
6669
if (this.autoupdate && this.source === 'local') this.updater.start();
6770
this.emit('ready');
68-
6971
}
7072

7173
/**
@@ -89,7 +91,7 @@ export class AzurAPI extends EventEmitter {
8991
/**
9092
* Another bodge...
9193
*/
92-
getShipIdByName(name: string){
94+
getShipIdByName(name: string) {
9395
return this.ships.getShipIdByName(name);
9496
}
9597
}

0 commit comments

Comments
 (0)