Skip to content

Commit

Permalink
Use tabs to make the code more accessible (#183)
Browse files Browse the repository at this point in the history
* Change config to tabs
* Convert 4 spaces to tabs with prettier and eslint
  • Loading branch information
rick-nu committed Oct 7, 2022
1 parent 18cf6e3 commit 783fc7a
Show file tree
Hide file tree
Showing 119 changed files with 3,561 additions and 3,555 deletions.
7 changes: 2 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_style = tab
indent_size = 4
trim_trailing_whitespace = true

# Taskfiles should have tabs
[Taskfile]
indent_style = tab

# Yaml files indent with 2 spaces due to their weird array syntax
[*.{yaml,yml,md}]
indent_style = spaces
indent_size = 2
103 changes: 51 additions & 52 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:react/recommended", "plugin:prettier/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint", "simple-import-sort"],
"rules": {
"max-len": [
"error",
{
"code": 120,
"tabWidth": 4
}
],
"react/react-in-jsx-scope": "off",
"simple-import-sort/imports": [
"error",
{
"groups": [
// other packages. Node packages first
["^@?\\w"],
// Sub components of current component
["^.+\\.style$"],
["^.+\\.svg$"],
// Own modules
["^(/frontend|backend|types)(/.*|$)"],
// Shared modules
["^types(/.*|$)"],
// Wrong imports (should be replaced)
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
// Sub components of current component
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"]
]
}
],
"simple-import-sort/exports": "error"
},
"ignorePatterns": ["node_modules/", "./dashboard/", "./app/", ".parcel-cache/", "./cypress/"],
"settings": {
"react": {
"version": "detect"
}
}
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:react/recommended", "plugin:prettier/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint", "simple-import-sort"],
"rules": {
"max-len": [
"error",
{
"code": 120
}
],
"react/react-in-jsx-scope": "off",
"simple-import-sort/imports": [
"error",
{
"groups": [
// other packages. Node packages first
["^@?\\w"],
// Sub components of current component
["^.+\\.style$"],
["^.+\\.svg$"],
// Own modules
["^(/frontend|backend|types)(/.*|$)"],
// Shared modules
["^types(/.*|$)"],
// Wrong imports (should be replaced)
["^\\.\\.(?!/?$)", "^\\.\\./?$"],
// Sub components of current component
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"]
]
}
],
"simple-import-sort/exports": "error"
},
"ignorePatterns": ["node_modules/", "./dashboard/", "./app/", ".parcel-cache/", "./cypress/"],
"settings": {
"react": {
"version": "detect"
}
}
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generally ignoring

.idea/
.husky/_/
yarn-error.log
/.env

Expand Down
3 changes: 1 addition & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"printWidth": 120,
"tabWidth": 4,
"semi": true,
"useTabs": false,
"useTabs": true,
"singleQuote": true,
"bracketSpacing": true,
"trailingComma": "es5"
Expand Down
12 changes: 12 additions & 0 deletions Taskfile
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ function task:commit { ## Clean up code before committing
title "Comitting"
}

function task:clean { ## Clean up the codestyle in all files
title "Running eslint"
echo "Cleaning typescript files..."
eslint --fix --ext ts,tsx .
echo "Done."
title "Running prettier"
echo "Cleaning other files..."
prettier --write --list-different *.{json,js}
prettier --write --list-different **/*.{json,css,html,js}
echo "Done."
}

# =========================================================
## Taskfile
# =========================================================
Expand Down
14 changes: 7 additions & 7 deletions backend/api/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ export { getContributors } from './github/contributors';
export { getLatestRelease } from './github/release';

const GitHubApi = () =>
axios.create({
headers: {
'User-Agent': 'github.com/FuturePortal/CIMonitor',
accept: 'application/json',
},
baseURL: 'https://api.github.com',
});
axios.create({
headers: {
'User-Agent': 'github.com/FuturePortal/CIMonitor',
accept: 'application/json',
},
baseURL: 'https://api.github.com',
});

export default GitHubApi;
68 changes: 34 additions & 34 deletions backend/api/github/contributors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,54 @@ import { Contributor } from 'types/cimonitor';
import { GitHubContributor, GitHubUser } from 'types/github';

export const getContributors = async (): Promise<Contributor[]> => {
const response = await GitHubApi().get('repos/FuturePortal/CIMonitor/stats/contributors');
const response = await GitHubApi().get('repos/FuturePortal/CIMonitor/stats/contributors');

const contributors: GitHubContributor[] = response.data;
const contributors: GitHubContributor[] = response.data;

const cleanContributors = cleanResponse(contributors);
const cleanContributors = cleanResponse(contributors);

const enrichedContributors = await enrichContributors(cleanContributors);
const enrichedContributors = await enrichContributors(cleanContributors);

return enrichedContributors.sort(byCommits);
return enrichedContributors.sort(byCommits);
};

const cleanResponse = (contributors: GitHubContributor[]): Contributor[] =>
contributors
.map((contributor) => ({
commits: contributor.total,
username: contributor.author.login,
profile: contributor.author.html_url,
image: contributor.author.avatar_url,
}))
.filter((contributor) => !['T-888', 'dependabot'].includes(contributor.username));
contributors
.map((contributor) => ({
commits: contributor.total,
username: contributor.author.login,
profile: contributor.author.html_url,
image: contributor.author.avatar_url,
}))
.filter((contributor) => !['T-888', 'dependabot'].includes(contributor.username));

const byCommits = (contributorA: Contributor, contributorB: Contributor): number =>
contributorB.commits - contributorA.commits;
contributorB.commits - contributorA.commits;

const enrichContributors = async (contributors: Contributor[]): Promise<Contributor[]> => {
const enrichedContributors: Contributor[] = [];
const enrichedContributors: Contributor[] = [];

for (let contributor of contributors) {
enrichedContributors.push(await enrichContributor(contributor));
}
for (let contributor of contributors) {
enrichedContributors.push(await enrichContributor(contributor));
}

return enrichedContributors;
return enrichedContributors;
};

const enrichContributor = async (contributor: Contributor): Promise<Contributor> => {
try {
const response = await GitHubApi().get(`users/${contributor.username}`);

const user: GitHubUser = response.data;

return {
...contributor,
site: user.blog,
location: user.location,
name: user.name,
company: user.company,
};
} catch (error) {
return contributor;
}
try {
const response = await GitHubApi().get(`users/${contributor.username}`);

const user: GitHubUser = response.data;

return {
...contributor,
site: user.blog,
location: user.location,
name: user.name,
company: user.company,
};
} catch (error) {
return contributor;
}
};
4 changes: 2 additions & 2 deletions backend/api/github/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import GitHubApi from 'backend/api/github';
import { GitHubRelease } from 'types/github';

export const getLatestRelease = async (): Promise<GitHubRelease> => {
const response = await GitHubApi().get('/repos/FuturePortal/CIMonitor/releases/latest');
const response = await GitHubApi().get('/repos/FuturePortal/CIMonitor/releases/latest');

return response.data;
return response.data;
};
20 changes: 10 additions & 10 deletions backend/module-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import StorageManager from 'backend/storage/manager';
import 'dotenv/config';

(async () => {
console.log('[module-client] Starting...');
console.log('[module-client] Starting...');

await StorageManager.init();
await StorageManager.init();

const { events, triggers } = await StorageManager.loadModules();
const { events, triggers } = await StorageManager.loadModules();

const hasModules = ModuleManager.init(triggers, events);
const hasModules = ModuleManager.init(triggers, events);

if (!hasModules) {
console.log('[module-client] Without modules, the module client has no purpose.');
process.exit(1);
}
if (!hasModules) {
console.log('[module-client] Without modules, the module client has no purpose.');
process.exit(1);
}

SocketClient.init();
SocketClient.init();

SocketClient.listen();
SocketClient.listen();
})();
Loading

0 comments on commit 783fc7a

Please sign in to comment.