Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change to impactmarket linter #572

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ jobs:
steps:
- checkout
- run: yarn
- run: yarn prettier
- run: yarn eslint:dryrun
- run: yarn build

workflows:
version: 2
test:
jobs:
- coverage
- lint
- coverage
36 changes: 31 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
// .eslintrc.js
module.exports = {
extends: ['universe/node', 'prettier', 'prettier/@typescript-eslint'],
env: {
mocha: true,
node: true,
es2020: true,
extends: ['impact-market/node', 'prettier'],
rules: {
'no-bitwise': 'off',
'no-loop-func': 'off',
'sort-keys': 'off',
'new-cap': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'require-await': 'off',
'no-inline-comments': 'off',
'prefer-destructuring': 'off',
'@typescript-eslint/no-redeclare': 'off',
'valid-jsdoc': 'off',
'no-underscore-dangle': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'sort-class-members/sort-class-members': 'off',
'no-process-env': 'off',
'prefer-const': 'off',
'max-params': 'off',
'padding-line-between-statements': 'off',
'prettier/prettier': 'off',
'sort-imports-es6-autofix/sort-imports-es6': 'off',
'spaced-comment': 'off',
'no-undef-init': 'off',
'prefer-template': 'off',
'no-else-return': 'off',
'no-nested-ternary': 'off',
'no-var': 'off',
'no-lonely-if': 'off',
'max-depth': 'off',
'vars-on-top': 'off',
'@typescript-eslint/no-unused-vars': 'off',
},
};
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
"test": "lerna exec --concurrency 1 yarn test",
"precoverage:ci": "NODE_ENV=test sequelize db:migrate --env ci",
"coverage:ci": "nyc --reporter=lcov lerna exec --concurrency 1 yarn test",
"prettier": "prettier --write \"./**/*.ts\"",
"eslint": "eslint --fix \"./**/*.ts\"",
"prettier-no-fix": "prettier --write \"./**/*.ts\"",
"eslint-no-fix": "eslint --fix \"./**/*.ts\""
"prettier:dryrun": "lerna exec --scope @impactmarket/api --scope @impactmarket/core yarn prettier:dryrun",
"eslint:dryrun": "lerna exec --scope @impactmarket/api --scope @impactmarket/core yarn eslint:dryrun",
"prettier": "lerna exec --scope @impactmarket/api --scope @impactmarket/core yarn prettier",
"eslint": "lerna exec --scope @impactmarket/api --scope @impactmarket/core yarn eslint"
}
}
14 changes: 12 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
"build": "tsc -p .",
"build:watch": "tsc -p . --watch",
"climem": "climem 8999",
"test:load": "autocannon -c 100 -d 120 -p 10 http://localhost:5002/api/v2/stories"
"test:load": "autocannon -c 100 -d 120 -p 10 http://localhost:5002/api/v2/stories",
"prettier:dryrun": "prettier -l \"./**/*.ts\"",
"eslint:dryrun": "eslint \"./**/*.ts\" --max-warnings=0",
"prettier": "prettier --write \"./**/*.ts\"",
"eslint": "eslint --fix \"./**/*.ts\" --max-warnings=0"
},
"devDependencies": {
"@types/cors": "2.8.12",
Expand All @@ -28,9 +32,15 @@
"@types/rate-limit-redis": "1.7.4",
"autocannon": "7.10.0",
"climem": "1.0.3",
"eslint": "7.3.1",
"eslint-config-impact-market": "2.0.3",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-sort-class-members": "1.14.1",
"eslint-plugin-sort-imports-es6-autofix": "0.6.0",
"express-status-monitor": "1.3.4",
"mocha": "9.1.3",
"nodemon": "2.0.15"
"nodemon": "2.0.15",
"prettier": "2.4.1"
},
"dependencies": {
"@appsignal/nodejs": "3.0.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/controllers/v2/community/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CommunityController {
} = req.body;

this.communityService
.editSubmission(parseInt(id), {
.editSubmission(parseInt(id, 10), {
requestByAddress: req.user.address,
name,
description,
Expand Down Expand Up @@ -113,7 +113,7 @@ class CommunityController {
}

this.communityService
.review(parseInt(id), review, req.user.address)
.review(parseInt(id, 10), review, req.user.address)
.then((r) => standardResponse(res, 201, true, r))
.catch((e) => standardResponse(res, 400, false, '', { error: e }));
};
Expand All @@ -134,7 +134,7 @@ class CommunityController {
this.communityService
.edit(
req.user.address,
parseInt(id),
parseInt(id, 10),
{
name,
description,
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/controllers/v2/community/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CommunityController {
parseInt(offset, 10),
parseInt(limit, 10),
{
state: state ? parseInt(state) : undefined,
state: state ? parseInt(state, 10) : undefined,
},
search !== undefined && typeof search === 'string'
? search
Expand Down Expand Up @@ -83,11 +83,11 @@ class CommunityController {
this.detailsService
.listBeneficiaries(
req.user.address,
parseInt(req.params.id),
parseInt(req.params.id, 10),
parseInt(offset, 10),
parseInt(limit, 10),
{
state: state ? parseInt(state) : undefined,
state: state ? parseInt(state, 10) : undefined,
suspect: suspect ? suspect === 'true' : undefined,
inactivity: inactivity ? inactivity === 'true' : undefined,
unidentified: unidentified
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/middlewares/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function authenticateToken(
// Gather the jwt access token from the request header
const authHeader = req.headers['authorization'];
const token = authHeader && authHeader.split(' ')[1];
if (token == null) {
if (token === null || token === undefined) {
if ((req as any).authTokenIsOptional) {
next();
return;
Expand Down Expand Up @@ -97,7 +97,7 @@ export function adminAuthentication(
// Gather the jwt access token from the request header
const authHeader = req.headers['authorization'];
const token = authHeader && authHeader.split(' ')[1];
if (token == null) {
if (token === null || token === undefined) {
res.sendStatus(401); // if there isn't any token
return;
}
Expand Down
10 changes: 8 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"scripts": {
"test": "NODE_ENV=test mocha",
"coverage": "NODE_ENV=test nyc --reporter=lcov mocha",
"build": "tsc -p ."
"build": "tsc -p .",
"prettier:dryrun": "prettier -l \"./**/*.ts\"",
"eslint:dryrun": "eslint \"./**/*.ts\" --max-warnings=0",
"prettier": "prettier --write \"./**/*.ts\"",
"eslint": "eslint --fix \"./**/*.ts\" --max-warnings=0"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "1.0.1",
Expand All @@ -30,8 +34,10 @@
"chai-subset": "1.6.0",
"coveralls": "3.1.1",
"eslint": "7.3.1",
"eslint-config-impact-market": "2.0.3",
"eslint-config-prettier": "6.11.0",
"eslint-config-universe": "4.0.0",
"eslint-plugin-sort-class-members": "1.14.1",
"eslint-plugin-sort-imports-es6-autofix": "0.6.0",
"fake": "0.2.2",
"mocha": "9.1.3",
"nyc": "15.1.0",
Expand Down
25 changes: 11 additions & 14 deletions packages/core/src/services/app/cashoutProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import { ExchangeRegistry } from '../../database/models/exchange/exchangeRegistr
import { MerchantRegistry } from '../../database/models/merchant/merchantRegistry';

export default class CashoutProviderService {
public async get(
query: {
country?: string;
lat?: string;
lng?: string;
distance?: string;
}
) {
public async get(query: {
country?: string;
lat?: string;
lng?: string;
distance?: string;
}) {
let merchants: MerchantRegistry[] | null = null,
exchanges: ExchangeRegistry[] | null = null;

Expand All @@ -31,9 +29,8 @@ export default class CashoutProviderService {
return {
merchants,
exchanges,
}
};

};
}

if (query.country) {
const where: any = {
Expand All @@ -57,8 +54,8 @@ export default class CashoutProviderService {

if (query.lat && query.lng) {
const userLocation = point([
parseInt(query.lng),
parseInt(query.lat),
parseInt(query.lng, 10),
parseInt(query.lat, 10),
]);

if (!merchants) {
Expand All @@ -71,7 +68,7 @@ export default class CashoutProviderService {
merchant.gps.latitude,
]);
const dist = distance(userLocation, merchantLocation);
if (dist < (query.distance || 100)) {
if (dist < parseInt(query.distance || '100', 10)) {
merchant['distance'] = dist;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/app/user/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class UserLogService {
const community = await models.community.findOne({
attributes: ['id'],
where: {
id: parseInt(entity),
id: parseInt(entity, 10),
ambassadorAddress,
},
});
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/learnAndEarn/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export async function listLessons(userId: number, levelId: number) {
completionDate: {
[Op.gte]: daysAgo.setHours(0, 0, 0, 0),
},
userId: userId,
userId,
},
});

Expand Down
33 changes: 19 additions & 14 deletions packages/core/src/services/learnAndEarn/syncRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ async function getPrismicLearnAndEarn() {
>;

if (prismicLevel.id) {
let reward = 0
let reward = 0;
if (typeof prismicLevel.data.reward === 'number') {
reward = prismicLevel.data.reward
reward = prismicLevel.data.reward;
} else {
reward = parseInt(prismicLevel.data.reward.split(' ')[0])
reward = parseInt(
prismicLevel.data.reward.split(' ')[0],
10
);
}
// INSERT LEVEL
const [level] = await models.learnAndEarnLevel.findOrCreate(
Expand Down Expand Up @@ -166,8 +169,7 @@ async function getPrismicLearnAndEarn() {
await models.learnAndEarnLesson.update(
{
active: true,
isLive:
prismicLesson.data.is_live || false,
isLive: prismicLesson.data.is_live || false,
languages:
findLessonLanguages.alternate_languages
.map(({ lang }) => {
Expand Down Expand Up @@ -218,16 +220,19 @@ async function getPrismicLearnAndEarn() {
transaction: t,
});
quizIds.push(quiz.id);
await models.learnAndEarnQuiz.update({
active: true,
answer,
}, {
where: {
order: quizIndex,
lessonId: lesson.id,
await models.learnAndEarnQuiz.update(
{
active: true,
answer,
},
transaction: t,
})
{
where: {
order: quizIndex,
lessonId: lesson.id,
},
transaction: t,
}
);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/ubi/community/details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ export class CommunityDetailsService {
}

// validate yearOfBirth
const year = parseInt(user.yearOfBirth);
const year = parseInt(user.yearOfBirth, 10);
if (!year) {
return {
valid: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/ubi/community/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ export class CommunityListService {
// TODO: review validation
if (returnState) {
const batch = config.cronJobBatchSize;
for (let i = 0; ; i = i + batch) {
for (let i = 0; ; i += batch) {
const communities = communitiesId.slice(i, i + batch);
const promises = communities.map(async (id) => {
let baseState: any = {},
Expand Down
Loading