Skip to content

Commit 5212c5f

Browse files
committed
prettier
1 parent 6e00315 commit 5212c5f

36 files changed

+287
-110
lines changed

src/api/api.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ export const downloadInput = async (year, day, authenticationToken) => {
2727
logger.debug('downloading input file for year: %s, day: %s', year, day);
2828

2929
if (!authenticationToken) {
30-
throw new Error('Authentication Token is required to query advent of code.');
30+
throw new Error(
31+
'Authentication Token is required to query advent of code.'
32+
);
3133
}
3234

3335
// query api
@@ -72,11 +74,19 @@ export const downloadInput = async (year, day, authenticationToken) => {
7274
* @param {String|Number} solution - The solution to test.
7375
* @param {String} authenticationToken - Token to authenticate with aoc.
7476
*/
75-
export const submitSolution = async (year, day, level, solution, authenticationToken) => {
77+
export const submitSolution = async (
78+
year,
79+
day,
80+
level,
81+
solution,
82+
authenticationToken
83+
) => {
7684
logger.debug('submitting solution to advent of code', { year, day, level });
7785

7886
if (!authenticationToken) {
79-
throw new Error('Authentication Token is required to query advent of code.');
87+
throw new Error(
88+
'Authentication Token is required to query advent of code.'
89+
);
8090
}
8191

8292
// post to api

src/api/parseHtml.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ export const getElementByTagName = (html, name) => {
1313
(element) => element.type === 'tag' && element.name === name,
1414
parseDocument(html, { decodeEntities: false }).children
1515
);
16-
return found ? render(found, { decodeEntities: false, encodeEntities: false }) : null;
16+
return found
17+
? render(found, { decodeEntities: false, encodeEntities: false })
18+
: null;
1719
};
1820

1921
/**
2022
* Returns the text content of the html string.
2123
* @param {String} html - The html to parse
2224
* @returns {String} The textContent of the parsed Node
2325
*/
24-
export const getTextContent = (html) => textContent(parseDocument(html))?.trim();
26+
export const getTextContent = (html) =>
27+
textContent(parseDocument(html))?.trim();

src/api/parseSubmissionResponse.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { getConfigValue } from '../config.js';
22
import { logger } from '../logger.js';
33
import { getElementByTagName, getTextContent } from './parseHtml.js';
4-
import { RateLimitExceededError, SolvingWrongLevelError } from '../errors/apiErrors.js';
4+
import {
5+
RateLimitExceededError,
6+
SolvingWrongLevelError,
7+
} from '../errors/apiErrors.js';
58

69
/**
710
* Parses the response html, finds the <main> element and then extracts its text content.

src/api/rateLimit.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { addMilliseconds, isFuture, isValid } from 'date-fns';
22
import { getConfigValue } from '../config.js';
33
import { logger } from '../logger.js';
4-
import { getRateLimit, setRateLimit } from '../persistence/rateLimitRepository.js';
4+
import {
5+
getRateLimit,
6+
setRateLimit,
7+
} from '../persistence/rateLimitRepository.js';
58

69
/**
710
* The type of aoc api requests that support rate limiting.

src/api/rateLimitDecorator.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ export const rateLimitDecorator =
1717
exceededMessage = 'You have made too many requests to advent of code.'
1818
) =>
1919
async (...args) => {
20-
logger.debug('checking rate limit before performing action: %s', actionType);
20+
logger.debug(
21+
'checking rate limit before performing action: %s',
22+
actionType
23+
);
2124

2225
const { limited, expiration } = await isRateLimited(actionType);
2326

2427
if (limited) {
25-
throw new RateLimitExceededError(exceededMessage, formatDistanceToNow(expiration));
28+
throw new RateLimitExceededError(
29+
exceededMessage,
30+
formatDistanceToNow(expiration)
31+
);
2632
}
2733

2834
try {

src/api/urls.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ export const puzzleBaseUrl = (year, day) => {
2020
* @param {Number} year
2121
* @param {Number} day
2222
*/
23-
export const puzzleInputUrl = (year, day) => `${puzzleBaseUrl(year, day)}/input`;
23+
export const puzzleInputUrl = (year, day) =>
24+
`${puzzleBaseUrl(year, day)}/input`;
2425

2526
/**
2627
* Returns the url for submitting the puzzle answer.
2728
* @param {Number} year
2829
* @param {Number} day
2930
*/
30-
export const puzzleAnswerUrl = (year, day) => `${puzzleBaseUrl(year, day)}/answer`;
31+
export const puzzleAnswerUrl = (year, day) =>
32+
`${puzzleBaseUrl(year, day)}/answer`;

src/config.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ const CONFIG = {
6767
aoc: {
6868
authenticationToken: process.env[envOptions.authenticationToken] || null,
6969
baseUrl: 'https://adventofcode.com',
70-
userAgent: 'https://github.com/beakerandjake/advent-of-code-runner by beakerandjake',
70+
userAgent:
71+
'https://github.com/beakerandjake/advent-of-code-runner by beakerandjake',
7172
responseParsing: {
7273
correctSolution: /that's the right answer/gim,
7374
incorrectSolution: /that's not the right answer/gim,
@@ -153,7 +154,12 @@ const CONFIG = {
153154
source: join(__dirname, '..', 'templates', 'template-dataFile.json'),
154155
dest: join(cwd, 'aocr-data.json'),
155156
},
156-
solutionDefault: join(__dirname, '..', 'templates', 'template-solution.js'),
157+
solutionDefault: join(
158+
__dirname,
159+
'..',
160+
'templates',
161+
'template-solution.js'
162+
),
157163
solutionLastDay: join(
158164
__dirname,
159165
'..',

src/errors/solutionWorkerErrors.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ export class UserSolutionAnswerInvalidError extends Error {
5252
export class UserSolutionFileNotFoundError extends Error {
5353
constructor(fileName, ...args) {
5454
super(
55-
`Could not load your solution file, ensure file exits (${pathToFileURL(fileName)})`,
55+
`Could not load your solution file, ensure file exits (${pathToFileURL(
56+
fileName
57+
)})`,
5658
...args
5759
);
5860
this.name = 'UserSolutionFileNotFoundError';
@@ -66,7 +68,10 @@ export class UserSolutionFileNotFoundError extends Error {
6668
* @param {Error} originalError
6769
*/
6870
const withOriginalErrorStack = (message, originalError) =>
69-
[message, `↳ ${originalError?.stack ? originalError.stack : originalError}`].join('\n');
71+
[
72+
message,
73+
`↳ ${originalError?.stack ? originalError.stack : originalError}`,
74+
].join('\n');
7075

7176
/**
7277
* Error raised if a users solution function raises an error.

src/logger.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ try {
5656

5757
loggerInstance = createLogger({
5858
levels: customLevels,
59-
format: format.combine(format.errors({ stack: true }), format.splat(), format.json()),
59+
format: format.combine(
60+
format.errors({ stack: true }),
61+
format.splat(),
62+
format.json()
63+
),
6064
transports: [
6165
new transports.Console({
6266
level,

src/persistence/puzzleRepository.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export const translateToPuzzleFromData = (data) => {
4949
} = data;
5050

5151
if (!id || typeof id !== 'string' || !idRegex.test(id)) {
52-
throw new TypeError(`Puzzle ${id} not expected format of YYYYDDLL (year day level)`);
52+
throw new TypeError(
53+
`Puzzle ${id} not expected format of YYYYDDLL (year day level)`
54+
);
5355
}
5456

5557
if (!Array.isArray(incorrectAnswers)) {
@@ -88,7 +90,9 @@ export const translateToDataFromPuzzle = (puzzle) => {
8890
} = puzzle;
8991

9092
if (!id || typeof id !== 'string' || !idRegex.test(id)) {
91-
throw new TypeError('Puzzle "id" not expected format of YYYYDDLL (year day level)');
93+
throw new TypeError(
94+
'Puzzle "id" not expected format of YYYYDDLL (year day level)'
95+
);
9296
}
9397

9498
if (!Array.isArray(incorrectAnswers)) {

0 commit comments

Comments
 (0)