Skip to content

Commit

Permalink
style: switch to shared eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik committed Oct 23, 2024
1 parent e13fbd3 commit 001f959
Show file tree
Hide file tree
Showing 53 changed files with 4,773 additions and 4,799 deletions.
75 changes: 67 additions & 8 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,76 @@
require('@ayuhito/eslint-config/patch');

module.exports = {
extends: ['@ayuhito/eslint-config/profile/node'],
extends: [ '@martin-kolarik/eslint-config/typescript' ],
parserOptions: {
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true,
project: 'packages/*/tsconfig.json',
},
rules: {
'no-console': 'off',
'unicorn/prefer-top-level-await': 'off',
'unicorn/no-null': 'off',
'unicorn/prefer-module': 'off',
'unicorn/filename-case': 'off',
'unicorn/consistent-destructuring': 'off',
},
overrides: [
{
files: [
'**',
],
rules: {
'camelcase': 'off',
'n/no-extraneous-import': [
'error',
{ allowModules: [ 'msw', 'vitest' ] },
],
},
},
{
files: [
'**/tsconfig.json',
],
rules: {
'jsonc/no-comments': 'off',
},
},
{
files: [
'**/tests/**',
],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'no-restricted-properties': [
'error',
{
object: 'sinon',
property: 'spy',
},
{
object: 'sinon',
property: 'stub',
},
{
object: 'sinon',
property: 'mock',
},
{
object: 'sinon',
property: 'fake',
},
{
object: 'sinon',
property: 'restore',
},
{
object: 'sinon',
property: 'reset',
},
{
object: 'sinon',
property: 'resetHistory',
},
{
object: 'sinon',
property: 'resetBehavior',
},
],
},
},
],
};
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
"typescript": "^4.9.5"
},
"devDependencies": {
"@ayuhito/eslint-config": "^0.2.4",
"eslint": "^8.38.0",
"prettier": "^2.8.7",
"@martin-kolarik/eslint-config": "^7.3.2",
"eslint": "^8.57.1",
"vitest": "^2.1.2"
}
}
22 changes: 13 additions & 9 deletions packages/bot-utils/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,48 @@ export class PostError extends Error {

location: string;

constructor(response: Response<unknown>, location: string, message = '') {
constructor (response: Response<unknown>, location: string, message = '') {
super(message);
this.message = message;
this.response = response;
this.location = location;
}
}

export function getAPIErrorMessage(error: unknown): string {
// @ts-ignore Discord error format
if (error.code === 50_001)
return 'Missing access! Please add the Globalping bot to this channel!';
export function getAPIErrorMessage (error: unknown): string {
// @ts-expect-error Discord error format
if (error.code === 50_001) { return 'Missing access! Please add the Globalping bot to this channel!'; }

if (error instanceof PostError) {
const { location, response } = error;
const { body } = response;
const errObj: APIError = JSON.parse(body as string) as APIError;
if (errObj.error.type === 'validation_error')

if (errObj.error.type === 'validation_error') {
return `${errObj.error.message}\n${
errObj.error.params
? Object.keys(errObj.error.params)
.map((key) => `${errObj.error.params?.[key]}`)
.join('\n')
.map(key => `${errObj.error.params?.[key]}`)
.join('\n')
: 'Unknown validation error.'
}`;
}

if (errObj.error.type === 'no_probes_found') {
return `${errObj.error.message} at location ${location}`;
}

if (errObj.error.type === 'api_error') {
return errObj.error.message;
}
} else if (error instanceof Error || error instanceof TypeError) {
return error.message;
}

return `${error}`;
}

export function formatAPIError(error: unknown): string {
export function formatAPIError (error: unknown): string {
return `\`\`\`
${getAPIErrorMessage(error)}
\`\`\`
Expand Down
Loading

0 comments on commit 001f959

Please sign in to comment.