Skip to content

Commit

Permalink
Merge pull request #258 from codex-team/eslint-update
Browse files Browse the repository at this point in the history
chore(eslint): changed config and fixed eslint problems
  • Loading branch information
e11sy authored Jun 8, 2024
2 parents 3555d34 + 7b8a580 commit 9615a41
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 31 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ app-config.local.yaml
.idea
dist
database
s3

# Logs
logs
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20
v22.1.0
83 changes: 78 additions & 5 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,98 @@
import CodeX from 'eslint-config-codex';
import { plugin as TsPlugin, parser as TsParser } from 'typescript-eslint';
/**
* @todo connect architecture config
*/
export default [
...CodeX,
/**
* Override only for config files
*/
{
name: 'notex.api',
name: 'codex/codestyle/configs',
files: ['eslint.config.mjs', 'vitest.config.js'],
rules: {
'n/no-unpublished-import': ['off'],
'@typescript-eslint/naming-convention': ['off'],
},
},
/**
* Override for dev files that are not in source code (logically)
*/
{
name: 'codex/codestyle/dev-files',
files: ['src/tests/**/*', '**/*.test.ts'],
languageOptions: {
parser: TsParser,
parserOptions: {
project: 'tsconfig.test.json',
tsconfigRootDir: './',
sourceType: 'module',
},
},
rules: {
/**
* Current eslint version (9.2.0) has no alias resolver so this error is unfixable
*/
'n/no-missing-import': ['off'],
'n/no-unpublished-import': ['error', {
allowModules: ['vitest', 'postgres-migrations', 'eslint-import-resolver-alias', 'eslint-config-codex'],
allowModules: ['vitest', 'postgres-migrations', '@testcontainers/localstack'],
ignoreTypeImport: true,
}],
/**
* @todo get rid of this rule ignores and solve all eslint errors occured
*/
'@typescript-eslint/no-unsafe-member-access': ['off'],
'@typescript-eslint/no-unsafe-call': ['off'],
'@typescript-eslint/no-unsafe-assignment': ['off'],
'@typescript-eslint/no-magic-numbers': ['off'],
'@typescript-eslint/no-unsafe-return': ['off'],
'@typescript-eslint/restrict-template-expressions': ['off'],
'jsdoc/require-jsdoc': ['off'],
},
},
/**
* Override for sourve code files
*/
{
name: 'notex.api',
ignores: ['vitest.config.js', 'eslint.config.mjs', 'src/tests/**/*', '**/*.test.ts'],
plugins: {
'@typescript-eslint': TsPlugin,
},

languageOptions: {
parser: TsParser,
parserOptions: {
project: 'tsconfig.json', // Автоматически находить tsconfig.json в рабочей директории
project: 'tsconfig.eslint.json',
tsconfigRootDir: './',
sourceType: 'module', // Allows for the use of imports
sourceType: 'module',
},
},
rules: {
/**
* Current eslint version (9.2.0) has no alias resolver so this error is unfixable
*/
'n/no-missing-import': ['off'],
'n/no-unpublished-import': ['error'],
'n/no-unsupported-features/es-builtins': ['error', {
version: '>=22.1.0',
}],
'@typescript-eslint/naming-convention': ['error', {
selector: 'property',
format: ['camelCase', 'PascalCase'],

filter: {
regex: '^(?!(2xx|2[0-9][0-9]|application/json)$).*',
match: true,
},
}],
/**
* @todo get rid of this rule ignores and solve all eslint errors occured
*/
'@typescript-eslint/no-misused-promises': ['off'],
'jsdoc/require-jsdoc': ['off'],
'jsdoc/informative-docs': ['off'],
'jsdoc/require-returns-description': ['off'],
},
},
];
7 changes: 5 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import API from '@presentation/index.js';
import runMetricsServer from '@infrastructure/metrics/index.js';
import { init as initDomainServices } from '@domain/index.js';
import { initORM, init as initRepositories } from '@repository/index.js';
import process from 'process';

/**
* Application entry point
Expand All @@ -24,14 +25,16 @@ const start = async (): Promise<void> => {

logger.info('Application launched successfully');
} catch (err) {
logger.fatal('Failed to start application ' + err);
logger.fatal('Failed to start application ' + (err as Error).toString());
/* eslint-disable-next-line n/no-process-exit */
process.exit(1);
}
};

try {
await start();
} catch (err) {
logger.fatal('Failed to start application ' + err);
logger.fatal('Failed to start application ' + (err as Error).toString());
/* eslint-disable-next-line n/no-process-exit */
process.exit(1);
}
1 change: 1 addition & 0 deletions src/infrastructure/metrics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import promClient from 'prom-client';
import { getLogger } from '@infrastructure/logging/index.js';
import config from '@infrastructure/config/index.js';
import { StatusCodes } from 'http-status-codes';
import process from 'process';

const collectDefaultMetrics = promClient.collectDefaultMetrics;
const Registry = promClient.Registry;
Expand Down
1 change: 1 addition & 0 deletions src/presentation/api.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { DomainServices } from '@domain/index.js';
import type * as http from 'http';
import type { Buffer } from 'buffer';

/**
* API interface
Expand Down
6 changes: 3 additions & 3 deletions src/presentation/http/router/note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe('Note API', () => {

const canEdit = (intermidiateTeamDefined === true && roleInIntermidiateTeam === MemberRole.Write) || (intermidiateTeamDefined === false && roleInRootTeam === MemberRole.Write);

const accessToken = await global.auth(randomGuy.id);
const accessToken = global.auth(randomGuy.id);

const response = await global.api?.fakeRequest({
method: 'GET',
Expand Down Expand Up @@ -1436,7 +1436,7 @@ describe('Note API', () => {
});
});

describe('PATCH /note/:notePublicId', async () => {
describe('PATCH /note/:notePublicId', () => {
const tools = [headerTool, listTool];

test.each([
Expand Down Expand Up @@ -1525,7 +1525,7 @@ describe('Note API', () => {
('Should patch note tools on note update', async ({ noteTools, noteContent, expectedStatusCode, expectedMessage }) => {
const user = await global.db.insertUser();

const accessToken = await global.auth(user.id);
const accessToken = global.auth(user.id);

const note = await global.db.insertNote({ creatorId: user.id });

Expand Down
2 changes: 1 addition & 1 deletion src/presentation/http/router/noteList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('GET /notes?page', () => {
const randomGuy = await global.db.insertUser();

if (isAuthorized) {
accessToken = await global.auth(randomGuy.id);
accessToken = global.auth(randomGuy.id);
}

for (let i = 0; i < portionSize; i++) {
Expand Down
12 changes: 6 additions & 6 deletions src/presentation/http/router/noteSettings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ describe('NoteSettings API', () => {
});
}

const accessToken = await global.auth(randomGuy.id);
const accessToken = global.auth(randomGuy.id);

const response = await global.api?.fakeRequest({
method: 'GET',
Expand Down Expand Up @@ -766,7 +766,7 @@ describe('NoteSettings API', () => {
role: MemberRole.Write,
});

const accessToken = await global.auth(user.id);
const accessToken = global.auth(user.id);

const response = await global.api?.fakeRequest({
method: 'PATCH',
Expand All @@ -791,7 +791,7 @@ describe('NoteSettings API', () => {
creatorId: creator.id,
});

const accessToker = await global.auth(creator.id);
const accessToker = global.auth(creator.id);

const response = await global.api?.fakeRequest({
method: 'PATCH',
Expand Down Expand Up @@ -923,7 +923,7 @@ describe('NoteSettings API', () => {
creatorId: creator.id,
});

const accessToken = await global.auth(creator.id);
const accessToken = global.auth(creator.id);

const response = await global.api?.fakeRequest({
method: 'DELETE',
Expand Down Expand Up @@ -961,7 +961,7 @@ describe('NoteSettings API', () => {
role: MemberRole.Write,
});

const accessToken = await global.auth(creator.id);
const accessToken = global.auth(creator.id);

let response = await global.api?.fakeRequest({
method: 'DELETE',
Expand Down Expand Up @@ -1002,7 +1002,7 @@ describe('NoteSettings API', () => {
creatorId: creator.id,
});

const accessToken = await global.auth(creator.id);
const accessToken = global.auth(creator.id);

const response = await global.api?.fakeRequest({
method: 'DELETE',
Expand Down
1 change: 1 addition & 0 deletions src/repository/storage/postgres/migrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path';
import config from './../../../../infrastructure/config/index.js';
import { runTenantMigrations } from './migrate.js';
import process from 'process';

/**
* Path to migration files
Expand Down
1 change: 1 addition & 0 deletions src/repository/storage/postgres/migrations/migrate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pg, { type ClientConfig } from 'pg';
/* eslint-disable-next-line n/no-unpublished-import */
import { migrate } from 'postgres-migrations';
import logger from './../../../../infrastructure/logging/index.js';

Expand Down
4 changes: 0 additions & 4 deletions src/repository/storage/s3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class S3Storage {

/**
* Constructor for S3Bucket
*
* @param accessKeyId - AWS access key
* @param secretAccessKey - AWS secret access key
* @param region - AWS region
Expand All @@ -35,7 +34,6 @@ export class S3Storage {

/**
* Method to upload a file to S3
*
* @param bucket - S3 bucket name
* @param key - Key to store the file in S3
* @param file - file data to upload
Expand Down Expand Up @@ -66,7 +64,6 @@ export class S3Storage {

/**
* Method to get a file from S3
*
* @param bucket - S3 bucket name
* @param key - Key of the file in S3
*/
Expand All @@ -89,7 +86,6 @@ export class S3Storage {

/**
* Method to create bucket in object storage, return its location
*
* @param name - bucket name
*/
public async createBucket(name: string): Promise<string | null> {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/utils/s3-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export default class S3Helpers {

/**
* Constructor for s3 helpers
*
* @param s3 - s3 client instance
*/
constructor(s3: S3Storage) {
this.s3 = s3;
}

/**
* Create buckets in s3 storage for testing
*/
Expand Down
3 changes: 2 additions & 1 deletion src/tests/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type Api from '@presentation/api.interface.js';
import DatabaseHelpers from './database-helpers.js';
import { S3Storage } from '@repository/storage/s3/index.js';
import S3Helpers from './s3-helpers.js';
import process from 'process';

/**
* Tests setup maximum duration.
Expand Down Expand Up @@ -48,7 +49,7 @@ declare global {
/**
* S3Helpers class that contains methods for work with s3
*/
/* eslint-disable-next-line no-var */

var s3: S3Helpers;
}

Expand Down
8 changes: 8 additions & 0 deletions tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"include": [
"src/**/*.ts",
"eslint.config.mjs",
"vitest.config.js",
],
}
6 changes: 0 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
"@tests/*": ["tests/*"]
},
},
"include": [
"src/**/*.ts",
"vitest.config.js",
".eslint.config.mjs",
"fastify.d.ts",
],
"ts-node": {
// Tell ts-node CLI to install the --loader automatically
"esm": true
Expand Down
7 changes: 7 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": [
"src/tests/**/*",
"**/*.test.ts",
],
}

0 comments on commit 9615a41

Please sign in to comment.