Skip to content

Commit

Permalink
Issue 2525: Fix lint errors (#2532)
Browse files Browse the repository at this point in the history
* reconfigure eslint

* fix lint errors 

* run lint pre-commit
  • Loading branch information
DukeManh authored Nov 28, 2021
1 parent 0089c81 commit d8a7f33
Show file tree
Hide file tree
Showing 51 changed files with 234 additions and 191 deletions.
31 changes: 24 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@ module.exports = {
},
extends: [
'airbnb',
'plugin:react/recommended',
'plugin:prettier/recommended',
'plugin:promise/recommended',
'plugin:react-hooks/recommended',
'plugin:import/typescript',
'plugin:jest-playwright/recommended',
'plugin:import/recommended',
],
plugins: ['prettier', 'promise', 'react', 'react-hooks', 'jest'],
plugins: ['prettier', 'promise', 'jest'],
settings: {
'importer/resolver': {
'import/resolver': {
node: {},
},
react: {
version: 'detect',
version: '17.0',
},
},
overrides: [
// TypeScript for Next.js
{
files: ['src/web/**/*.ts', 'src/web/**/*.tsx'],
plugins: ['@typescript-eslint'],
extends: [
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:import/typescript',
],
plugins: ['@typescript-eslint', 'react', 'react-hooks'],
env: {
browser: true,
},
Expand Down Expand Up @@ -69,6 +72,12 @@ module.exports = {
},
},

// Static dashboard
{
files: ['src/api/status/public/**/*.js'],
rules: { 'import/extensions': ['error', 'always'] },
},

// Jest Test files
{
files: ['test/**/*.js', '*.test.js', '*.test.ts', '*.test.tsx', '**/__mocks__/**/*.js'],
Expand Down Expand Up @@ -156,5 +165,13 @@ module.exports = {
* difficult to configure properly. Disabling for now.
*/
'import/no-extraneous-dependencies': ['off'],
'no-new': 'off',

/**
* False positive of no-shadow rule with ENUMs
* https://github.com/typescript-eslint/typescript-eslint/issues/2483
*/
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
},
};
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
"install:users-service": "cd src/api/users && npm install",
"install:posts-service": "cd src/api/posts && npm install",
"install:search-service": "cd src/api/search && npm install",
"install:planet-service": "cd src/api/planet && npm install",
"install:status-service": "cd src/api/status && npm install",
"install:feed-discovery-service": "cd src/api/feed-discovery && npm install",
"install:parser-service": "cd src/api/parser && npm install",
"install:autodeployment": "cd tools/autodeployment && npm install",
"install:next": "cd src/web && npm install",
"build": "npm run build --prefix src/web --",
"dev": "npm run dev --prefix src/web --",
"develop": "npm run dev",
"eslint": "eslint --config .eslintrc.js",
"eslint-fix": "eslint --config .eslintrc.js --fix",
"eslint": "eslint --config .eslintrc.js \"**/*.{jsx,tsx,ts,js}\"",
"eslint-fix": "eslint --config .eslintrc.js \"**/*.{jsx,tsx,ts,js}\" --fix",
"lint": "npm run eslint",
"postinstall": "run-s install:*",
"prettier": "prettier --write \"./**/*.{md,jsx,json,html,css,js,yml}\"",
Expand All @@ -36,7 +38,7 @@
"start": "node src/backend",
"server": "node src/backend/web/server",
"test-ci": "run-s prettier-check test",
"pre-commit": "pretty-quick --staged",
"pre-commit": "pretty-quick --staged && npm run lint",
"postversion": "git push upstream master --tags",
"services:start": "node bin/services-start.js --",
"services:stop": "node bin/services-stop.js",
Expand Down Expand Up @@ -106,6 +108,7 @@
"eslint-config-airbnb": "18.2.1",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jest": "25.3.0",
"eslint-plugin-jest-playwright": "0.2.1",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-prettier": "3.4.0",
Expand Down
3 changes: 2 additions & 1 deletion src/api/auth/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ const passport = require('passport');
const session = require('express-session');
const RedisStore = require('connect-redis')(session);

const routes = require('./routes');
// Setup SAML SSO-based Authentication
require('./authentication');

const service = new Satellite({
router: require('./routes'),
router: routes,
beforeRouter(app) {
// Initialize and use Session and Passport middleware on the app. In production
// we use Redis for session storage, and in-memory otherwise.
Expand Down
2 changes: 2 additions & 0 deletions src/api/auth/test/e2e/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const createTelescopeUsers = (users) =>
if (!(res.status === 201 || res.status === 400)) {
throw new Error(`got unexpected status ${res.status}`);
}
return res;
})
.catch((err) => {
console.error('Unable to create user with Users service', { err });
Expand Down Expand Up @@ -109,6 +110,7 @@ const ensureUsers = (users, result = 200) =>
},
}).then((res) => {
expect(res.status).toEqual(result);
return res;
})
)
);
Expand Down
3 changes: 3 additions & 0 deletions src/api/parser/src/feed/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const path = require('path');

const { logger } = require('@senecacdot/satellite');
const feedQueue = require('./queue');

// The parser service isn't ready, disabling for now
// eslint-disable-next-line import/no-unresolved
const { waitOnReady } = require('../utils/indexer');

/**
Expand Down
2 changes: 1 addition & 1 deletion src/api/parser/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { Satellite, isAuthenticated, isAuthorized } = require('@senecacdot/satellite');
const { Satellite } = require('@senecacdot/satellite');
// TODO: https://github.com/Seneca-CDOT/telescope/issues/2345
// const { router } = require('bull-board');
// const startParserQueue = require('./parser-queue');
Expand Down
4 changes: 2 additions & 2 deletions src/api/planet/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { static } = require('express');
const { static: serveStatic } = require('express');
const expressHandlebars = require('express-handlebars');
const { Satellite } = require('@senecacdot/satellite');
const path = require('path');
Expand Down Expand Up @@ -28,7 +28,7 @@ const service = new Satellite({
});

// Legacy CDOT Planet static assets
service.router.use('/legacy', static(path.join(__dirname, '../static')));
service.router.use('/legacy', serveStatic(path.join(__dirname, '../static')));
service.router.use('/planet', planet);

module.exports = service;
4 changes: 2 additions & 2 deletions src/api/planet/src/planet.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Router, logger, fetch } = require('@senecacdot/satellite');

const router = Router();

const { POSTS_URL } = process.env;
Expand Down Expand Up @@ -59,9 +60,8 @@ const fetchData = async (dataUrl) => {
const data = await response.json();
return Promise.all(data.map((item) => fetch(`${dataUrl}/${item.id}`).then((r) => r.json())));
} catch (e) {
logger.error(e);
return logger.error(e);
}
return;
};

router.get('/', async (req, res, next) => {
Expand Down
18 changes: 6 additions & 12 deletions src/api/posts/src/routes/feeds.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
const {
Router,
logger,
createError,
isAuthenticated,
isAuthorized,
} = require('@senecacdot/satellite');
const { Router, logger, isAuthenticated, isAuthorized } = require('@senecacdot/satellite');
const Feed = require('../data/feed');
const { getFeeds } = require('../storage');
const { validateNewFeed, validateFeedsIdParam } = require('../validation');
Expand Down Expand Up @@ -76,7 +70,7 @@ feeds.put(
});
} catch (error) {
logger.error({ error }, 'Unable to flag feed in Redis');
next(error);
return next(error);
}
}
);
Expand Down Expand Up @@ -107,7 +101,7 @@ feeds.post(
.json({ message: `Feed was successfully added.`, id: feedId, url: `/feeds/${feedId}` });
} catch (error) {
logger.error({ error }, 'Unable to add feed to Redis');
next(error);
return next(error);
}
}
);
Expand All @@ -125,7 +119,7 @@ feeds.delete(
return res.status(204).send();
} catch (error) {
logger.error({ error }, 'Unable to reset Feed data in Redis');
next(error);
return next(error);
}
}
);
Expand Down Expand Up @@ -154,7 +148,7 @@ feeds.delete(
return res.status(204).json({ message: `Feed ${id} was successfully deleted.` });
} catch (error) {
logger.error({ error }, 'Unable to delete feed to Redis');
next(error);
return next(error);
}
}
);
Expand All @@ -178,7 +172,7 @@ feeds.delete(
return res.status(204).json({ message: `Feed ${id} was successfully unflagged.` });
} catch (error) {
logger.error({ error }, 'Unable to unflag feed in Redis');
next(error);
return next(error);
}
}
);
Expand Down
1 change: 1 addition & 0 deletions src/api/posts/src/text-parser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// polyfill global text encoder/decoder from node if necessary
const { TextEncoder, TextDecoder } = require('util');

global.TextEncoder = global.TextEncoder || TextEncoder;
global.TextDecoder = global.TextDecoder || TextDecoder;

Expand Down
2 changes: 1 addition & 1 deletion src/api/status/public/js/build-log/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// http://localhost:1111/pages/build.html -> http://localhost:4000/:path
const autodeploymentUrl = (path) => `//${location.hostname}:4000/${path}`;
const autodeploymentUrl = (path) => `//${window.location.hostname}:4000/${path}`;

export const checkBuildStatus = async () => {
try {
Expand Down
10 changes: 7 additions & 3 deletions src/api/status/public/js/build-log/check-for-build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint-disable consistent-return */
import { checkBuildStatus, getBuildLog } from './api.js';
import terminal from './terminal.js';
let build, reader;

let build;
let reader;

async function finish() {
try {
Expand All @@ -16,11 +19,11 @@ function processLog({ done, value }) {
}

if (terminal) {
terminal.write(value);
return terminal.write(value);
}
}

export async function checkForBuild() {
export default async function checkForBuild() {
// If we're already building, skip this check
if (build) {
return;
Expand All @@ -31,6 +34,7 @@ export async function checkForBuild() {
terminal.clear();
reader = await getBuildLog();
if (reader) {
// eslint-disable-next-line require-atomic-updates
build = { reader, title: status.title, startedAt: status.startedAt };
reader.read().then(processLog).catch(finish);
}
Expand Down
1 change: 1 addition & 0 deletions src/api/status/public/js/build-log/terminal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
const theme = {
background: '#252525',
cursor: '#A0A0A0',
Expand Down
4 changes: 2 additions & 2 deletions src/api/status/public/js/feed/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const apiHost = new URL(location).origin;
const apiHost = new URL(window.location).origin;

export async function getFeedCount() {
export default async function getFeedCount() {
try {
const data = await fetch(`${apiHost}/v1/posts/feeds`, {
method: 'HEAD',
Expand Down
13 changes: 9 additions & 4 deletions src/api/status/public/js/github-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fetchGitHubApi = (owner, repo, path) =>
headers: { Accept: 'application/vnd.github.v3+json' },
});

export const getGitHubData = (owner, repo) => {
export default function getGitHubData(owner, repo) {
let weeklyCommits = 0;

// get weekly commits for last year: https://docs.github.com/en/rest/reference/repos#get-the-weekly-commit-count
Expand All @@ -16,6 +16,7 @@ export const getGitHubData = (owner, repo) => {
document.getElementById(`yearly-commits-${repo}`).innerHTML = data.all.reduce(
(a, b) => a + b
);
return data;
})
.catch((error) => console.log(error));

Expand All @@ -24,12 +25,14 @@ export const getGitHubData = (owner, repo) => {
.then((res) => res.json())
.then((data) => {
if (weeklyCommits) {
document.getElementById(`lines-added-${repo}`).innerHTML = data[data.length - 1][1];
document.getElementById(`lines-removed-${repo}`).innerHTML = data[data.length - 1][2];
const [, linesAdded, linesRemoved] = data[data.length - 1];
document.getElementById(`lines-added-${repo}`).innerHTML = linesAdded;
document.getElementById(`lines-removed-${repo}`).innerHTML = linesRemoved;
} else {
document.getElementById(`new-lines-${repo}`).innerHTML =
'<p class="mb-0">No commits this week<p/>';
}
return data;
})
.catch((error) => console.log(error));

Expand All @@ -52,6 +55,7 @@ export const getGitHubData = (owner, repo) => {
document.getElementById(`latest-author-commit-${repo}`).innerHTML = shortSha;
document.getElementById(`latest-author-commit-${repo}`).title = shortSha;
document.getElementById(`latest-author-commit-${repo}`).href = commitURL;
return data;
})
.catch((error) => console.log(error));

Expand All @@ -61,6 +65,7 @@ export const getGitHubData = (owner, repo) => {
.then((data) => {
const contributors = data.match(/.*"next".*&page=([0-9]*).*"last".*/)[1];
document.getElementById(`total-contributors-${repo}`).innerHTML = contributors;
return data;
})
.catch((error) => console.log(error));
};
}
2 changes: 1 addition & 1 deletion src/api/status/public/js/pages/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { checkForBuild } from '../build-log/check-for-build.js';
import checkForBuild from '../build-log/check-for-build.js';

window.addEventListener('load', () => {
checkForBuild();
Expand Down
8 changes: 4 additions & 4 deletions src/api/status/public/js/pages/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getPostsCount } from '../post/index.js';
import { getFeedCount } from '../feed/index.js';
import { getGitHubData } from '../github-stats.js';
import getPostsCount from '../post/index.js';
import getFeedCount from '../feed/index.js';
import getGitHubData from '../github-stats.js';

window.addEventListener('load', (event) => {
window.addEventListener('load', () => {
getGitHubData('Seneca-CDOT', 'telescope');
getGitHubData('Seneca-CDOT', 'satellite');
getFeedCount();
Expand Down
4 changes: 2 additions & 2 deletions src/api/status/public/js/post/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const apiUrl = new URL(location).origin;
const apiUrl = new URL(window.location).origin;

const fetchPostsCount = () =>
fetch(`${apiUrl}/v1/posts`, { method: 'HEAD' }).then((res) => res.headers.get('x-total-count'));

export const getPostsCount = async () => {
export default async () => {
try {
const numberOfPosts = await fetchPostsCount();
const totalPostsEl = document.getElementById('totalPosts');
Expand Down
Loading

0 comments on commit d8a7f33

Please sign in to comment.