[chore] Eslint fixes (#5988)

* lint fixes: frontend

* lint fixes: marketplace

* lint fixes: plugins-client js files

* typo fix

* eslint updates/fixes for marketplace

* eslint updates/fixes for plugins

* removing "@typescript-eslint/no-floating-promises for plugins"

* ignore client.js and server.js

* ignore client.js and server.js

* ignore client.js and server.tss

* Delete client.js

* ignore cypress-test/**
This commit is contained in:
Arpit 2023-04-11 15:34:58 +05:30 committed by GitHub
parent 6d2e2046cf
commit 636c4a62c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 108 additions and 138 deletions

View file

@ -1 +1,2 @@
node_modules/**
cypress-tests/**

View file

@ -31,7 +31,9 @@ export const ViewerNavigation = ({ isMobileDevice, pages, currentPageId, switchP
>
<div className={`card mb-1 ${id === currentPageId ? 'active' : ''}`}>
<div className="card-body">
<span data-cy={`pages-name-${String(page.name).toLowerCase()}`} className="mx-3 text-wrap">{_.truncate(page.name, { length: 18 })}</span>
<span data-cy={`pages-name-${String(page.name).toLowerCase()}`} className="mx-3 text-wrap">
{_.truncate(page.name, { length: 18 })}
</span>
</div>
</div>
</div>

View file

@ -54,7 +54,7 @@ export const GlobalDataSourcesPage = ({ darkMode }) => {
}
};
const environmentChanged = (env, dataSourceId) => {
const environmentChanged = (env) => {
setCurrentEnvironment(env);
};

View file

@ -1,5 +1,5 @@
import React from 'react';
import { authenticationService, groupPermissionService } from '@/_services';
import { groupPermissionService } from '@/_services';
import { ConfirmDialog } from '@/_components';
import { toast } from 'react-hot-toast';
import { Link } from 'react-router-dom';

View file

@ -6,6 +6,7 @@ import { MarketplacePlugins } from './MarketplacePlugins';
import { marketplaceService, pluginsService, authenticationService } from '@/_services';
import { toast } from 'react-hot-toast';
import { useNavigate } from 'react-router-dom';
import config from 'config';
const MarketplacePage = ({ darkMode, switchDarkMode }) => {
const [active, setActive] = React.useState('installed');
@ -14,7 +15,7 @@ const MarketplacePage = ({ darkMode, switchDarkMode }) => {
const [fetchingInstalledPlugins, setFetching] = React.useState(false);
const { admin } = authenticationService.currentSessionValue;
const ENABLE_MARKETPLACE_DEV_MODE = window.public_config?.ENABLE_MARKETPLACE_DEV_MODE == 'true';
const ENABLE_MARKETPLACE_DEV_MODE = config.ENABLE_MARKETPLACE_DEV_MODE == 'true';
const navigate = useNavigate();

View file

@ -6,8 +6,8 @@ import Layout from '@/_ui/Layout';
function SettingsPage(props) {
const currentSession = authenticationService.currentSessionValue;
const email = currentSession?.current_user.email;
const [firstName, setFirstName] = React.useState(currentSession?.current_user.first_name);
const [email, setEmail] = React.useState(currentSession?.current_user.email);
const [lastName, setLastName] = React.useState(currentSession?.current_user.last_name);
const [currentpassword, setCurrentPassword] = React.useState('');
const [newPassword, setNewPassword] = React.useState('');

View file

@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { authenticationService, organizationService } from '@/_services';
import { organizationService } from '@/_services';
import AlertDialog from '@/_ui/AlertDialog';
import { toast } from 'react-hot-toast';
import { useTranslation } from 'react-i18next';

46
marketplace/.eslintrc Normal file
View file

@ -0,0 +1,46 @@
{
"env": {
"node": true,
"jest": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
"ignorePatterns": [".eslintrc"],
"parser": "@typescript-eslint/parser",
"overrides": [
{
"files": ["*.ts"],
"parserOptions": {
"project": ["./tsconfig.json"],
"tsconfigRootDir": "."
}
}
],
"plugins": ["@typescript-eslint", "jest", "prettier"],
"rules": {
"prettier/prettier": [
"error",
{
"semi": true,
"trailingComma": "es5",
"printWidth": 120,
"singleQuote": true
}
],
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "none" }],
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"object": false
},
"extendDefaults": true
}
]
}
}

View file

@ -1,56 +0,0 @@
module.exports = {
env: {
node: true,
jest: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
ignorePatterns: ['.eslintrc.js'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
project: ['./tsconfig.json'],
},
overrides: [
{
files: ['*.ts'],
parserOptions: {
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
},
},
],
plugins: ['@typescript-eslint', 'jest', 'prettier'],
rules: {
'prettier/prettier': [
'error',
{
semi: true,
trailingComma: 'es5',
printWidth: 120,
singleQuote: true,
},
],
'@typescript-eslint/no-floating-promises': ['error'],
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': ['error', { vars: 'all', args: 'none' }],
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-empty-function': 0,
'@typescript-eslint/ban-types': [
'error',
{
types: {
object: false,
},
extendDefaults: true,
},
],
},
};

View file

@ -14,6 +14,4 @@ dist
*.tsbuildinfo
*.tabl.json
*.swp
*.snk
client.js
server.ts
*.snk

View file

@ -1,14 +1,12 @@
import { QueryError, QueryResult, QueryService, ConnectionTestResult } from '@tooljet-marketplace/common';
import { SourceOptions, QueryOptions, Operation } from './types';
import { Octokit } from 'octokit'
import { getUserInfo, getRepo, getRepoIssues, getRepoPullRequests} from './query_operations'
import { Octokit } from 'octokit';
import { getUserInfo, getRepo, getRepoIssues, getRepoPullRequests } from './query_operations';
export default class Github implements QueryService {
async run(sourceOptions: SourceOptions, queryOptions: QueryOptions, dataSourceId: string): Promise<QueryResult> {
const operation: Operation = queryOptions.operation;
const octokit:Octokit = await this.getConnection(sourceOptions);
const octokit: Octokit = await this.getConnection(sourceOptions);
let result = {};
try {
@ -16,11 +14,11 @@ export default class Github implements QueryService {
case Operation.GetUserInfo:
result = await getUserInfo(octokit, queryOptions);
break;
case Operation.GetRepo:
result = await getRepo(octokit, queryOptions);
break;
case Operation.GetRepoIssues:
result = await getRepoIssues(octokit, queryOptions);
break;
@ -29,14 +27,13 @@ export default class Github implements QueryService {
result = await getRepoPullRequests(octokit, queryOptions);
break;
default:
default:
throw new QueryError('Query could not be completed', 'Invalid operation', {});
}
} catch (error) {
throw new QueryError('Query could not be completed', error.message, {});
}
return {
status: 'ok',
data: result,
@ -47,18 +44,16 @@ export default class Github implements QueryService {
const octokit = await this.getConnection(sourceOptions);
try {
const { status } = await octokit.rest.users.getAuthenticated();
if(status) {
const { status } = await octokit.rest.users.getAuthenticated();
if (status) {
return {
status: 'ok',
}
};
}
} catch (error) {
return {
status: 'failed',
message: 'Invalid credentials'
message: 'Invalid credentials',
};
}
}

View file

@ -1,49 +1,35 @@
import { Octokit } from 'octokit'
import { QueryOptions } from './types'
import { Octokit } from 'octokit';
import { QueryOptions } from './types';
export async function getUserInfo(octokit: Octokit, options: QueryOptions): Promise<object> {
const { data } = await octokit.request(
'GET /users/{username}',
{
username: options.username
}
);
const { data } = await octokit.request('GET /users/{username}', {
username: options.username,
});
return data;
}
export async function getRepo(octokit: Octokit, options: QueryOptions): Promise<object> {
const { data } = await octokit.request(
'GET /repos/{owner}/{repo}',
{
owner: options.owner,
repo: options.repo
}
);
return data;
const { data } = await octokit.request('GET /repos/{owner}/{repo}', {
owner: options.owner,
repo: options.repo,
});
return data;
}
export async function getRepoIssues(octokit: Octokit, options: QueryOptions): Promise<object> {
const { data } = await octokit.request(
'GET /repos/{owner}/{repo}/issues',
{
owner: options.owner,
repo: options.repo,
state: options.state || 'all'
}
);
return data;
const { data } = await octokit.request('GET /repos/{owner}/{repo}/issues', {
owner: options.owner,
repo: options.repo,
state: options.state || 'all',
});
return data;
}
export async function getRepoPullRequests(octokit: Octokit, options: QueryOptions): Promise<object> {
const { data } = await octokit.request(
'GET /repos/{owner}/{repo}/pulls',
{
owner: options.owner,
repo: options.repo,
state: options.state || 'all'
}
);
return data;
}
const { data } = await octokit.request('GET /repos/{owner}/{repo}/pulls', {
owner: options.owner,
repo: options.repo,
state: options.state || 'all',
});
return data;
}

View file

@ -16,4 +16,4 @@ export enum Operation {
GetRepo = 'get_repo',
GetRepoIssues = 'get_repo_issues',
GetRepoPullRequests = 'get_repo_pull_requests',
}
}

View file

@ -9,7 +9,7 @@ export async function getCompletion(
try {
const { data } = await openai.createCompletion({
model: 'me',
model: 'text-davinci-003',
prompt: prompt,
temperature: typeof temperature === 'string' ? parseFloat(temperature) : temperature || 0,
max_tokens: typeof max_tokens === 'string' ? parseInt(max_tokens) : max_tokens || 67,
@ -19,6 +19,8 @@ export async function getCompletion(
return data.choices[0]['text'];
} catch (error) {
console.log('error openapi ===============', error);
return {
error: error?.message,
statusCode: error?.response?.status,

View file

@ -14,8 +14,6 @@ export default class PlivoService implements QueryService {
if (queryOptions.operation === 'send_sms') {
result = await client.messages.create(queryOptions.from, queryOptions.to, queryOptions.body);
}
} catch (error) {
throw new QueryError('Query could not be completed', error.message, {});
@ -26,4 +24,4 @@ export default class PlivoService implements QueryService {
data: result,
};
}
}
}

View file

@ -1,4 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-types
export type SourceOptions = {};
export type QueryOptions = {
operation: string;
};
};

View file

@ -11,7 +11,7 @@ config.update({
region: process.env.AWS_REGION || 'us-west-1',
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.SECRET_ACCESS_KEY,
maxRetries: 3
maxRetries: 3,
});
const directoryPath = _resolve(__dirname, 'plugins');
@ -22,7 +22,7 @@ const getDirectoryFilesRecursive = (dir, ignores = []) => {
});
};
const generateFileKey = fileName => {
const generateFileKey = (fileName) => {
const S3objectPath = fileName.split('/marketplace/plugins/')[1];
return `marketplace-assets/${S3objectPath}`;
};
@ -40,10 +40,10 @@ const uploadToS3 = async () => {
'README.md',
'package-lock.json',
'package.json',
'tsconfig.json'
'tsconfig.json',
]);
fileArray.map(file => {
fileArray.map((file) => {
// Configuring parameters for S3 Object
const S3params = {
Bucket: process.env.AWS_BUCKET,
@ -51,9 +51,9 @@ const uploadToS3 = async () => {
Key: generateFileKey(file),
ContentType: lookup(file),
ContentEncoding: 'utf-8',
CacheControl: 'immutable,max-age=31536000,public'
CacheControl: 'immutable,max-age=31536000,public',
};
s3.upload(S3params, function(err, data) {
s3.upload(S3params, function (err, data) {
if (err) {
// Set the exit code while letting
// the process exit gracefully.
@ -69,4 +69,4 @@ const uploadToS3 = async () => {
}
};
uploadToS3();
uploadToS3();

View file

@ -14,5 +14,5 @@
"composite": true,
"resolveJsonModule": true
},
"exclude": ["plugins/*/lib/*.json", "<rootDir>/__tests__/*", "dist"]
"exclude": ["plugins/*/lib/*.json", "<rootDir>/__tests__/*", "<rootDir>/scripts/*","dist"]
}

View file

@ -2,3 +2,5 @@ dist
.eslintrc.js
packages/*/__tests__/*.js
packages/*/dist/*
client.js
server.ts

View file

@ -10,11 +10,6 @@ module.exports = {
],
ignorePatterns: ['.eslintrc.js'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
project: ['./tsconfig.json'],
},
overrides: [
{
files: ['*.ts'],
@ -35,7 +30,6 @@ module.exports = {
singleQuote: true,
},
],
'@typescript-eslint/no-floating-promises': ['error'],
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',