Skip to content

Commit 1d77385

Browse files
authored
Merge pull request #733 from snyk/RUN-1520
chore: introduce code formatter and style
2 parents 23b635c + f293907 commit 1d77385

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1706
-701
lines changed

.circleci/config.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,25 @@ jobs:
9797
name: Notify Slack on failure
9898
when: on_fail
9999
working_directory: ~/kubernetes-monitor
100+
code_formatter:
101+
machine:
102+
docker_layer_caching: true
103+
enabled: true
104+
image: ubuntu-2004:202010-01
105+
steps:
106+
- checkout
107+
- setup_node12
108+
- install_python_requests
109+
- run:
110+
command: |
111+
npm run format:check
112+
name: code formatter check
113+
- run:
114+
command: |
115+
./scripts/slack/notify_failure_on_branch.py "${CIRCLE_BRANCH}" "${CIRCLE_JOB}" "${CIRCLE_BUILD_URL}" "${CIRCLE_PULL_REQUEST}" "${SLACK_WEBHOOK}"
116+
name: Notify Slack on failure
117+
when: on_fail
118+
working_directory: ~/kubernetes-monitor
100119
deploy_dev:
101120
docker:
102121
- auth:
@@ -273,6 +292,25 @@ jobs:
273292
- store_artifacts:
274293
path: /tmp/logs/test/integration/proxy
275294
working_directory: ~/kubernetes-monitor
295+
lint:
296+
machine:
297+
docker_layer_caching: true
298+
enabled: true
299+
image: ubuntu-2004:202010-01
300+
steps:
301+
- checkout
302+
- setup_node12
303+
- install_python_requests
304+
- run:
305+
command: |
306+
npm run lint
307+
name: lint
308+
- run:
309+
command: |
310+
./scripts/slack/notify_failure_on_branch.py "${CIRCLE_BRANCH}" "${CIRCLE_JOB}" "${CIRCLE_BUILD_URL}" "${CIRCLE_PULL_REQUEST}" "${SLACK_WEBHOOK}"
311+
name: Notify Slack on failure
312+
when: on_fail
313+
working_directory: ~/kubernetes-monitor
276314
openshift3_integration_tests:
277315
machine:
278316
docker_layer_caching: true
@@ -778,7 +816,6 @@ jobs:
778816
- install_python_requests
779817
- run:
780818
command: |
781-
npm run lint &&
782819
npm run build &&
783820
npm run test:unit:tap &&
784821
npm run test:unit:jest
@@ -991,6 +1028,18 @@ workflows:
9911028
ignore:
9921029
- staging
9931030
- master
1031+
- lint:
1032+
filters:
1033+
branches:
1034+
ignore:
1035+
- staging
1036+
- master
1037+
- code_formatter:
1038+
filters:
1039+
branches:
1040+
ignore:
1041+
- staging
1042+
- master
9941043
- system_tests:
9951044
filters:
9961045
branches:

.circleci/config/@config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ workflows:
2828
<<: *main_branches_filter
2929
- unit_tests:
3030
<<: *main_branches_filter
31+
- lint:
32+
<<: *main_branches_filter
33+
- code_formatter:
34+
<<: *main_branches_filter
3135
- system_tests:
3236
<<: *main_branches_filter
3337
- integration_tests:

.circleci/config/jobs/@jobs.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,44 @@ build_and_upload_operator:
6565
./scripts/slack/notify_failure_on_branch.py "${CIRCLE_BRANCH}" "${CIRCLE_JOB}" "${CIRCLE_BUILD_URL}" "${CIRCLE_PULL_REQUEST}" "${SLACK_WEBHOOK}"
6666
when: on_fail
6767

68+
lint:
69+
machine:
70+
docker_layer_caching: true
71+
enabled: true
72+
image: ubuntu-2004:202010-01
73+
steps:
74+
- checkout
75+
- setup_node12
76+
- install_python_requests
77+
- run:
78+
command: |
79+
npm run lint
80+
name: lint
81+
- run:
82+
command: |
83+
./scripts/slack/notify_failure_on_branch.py "${CIRCLE_BRANCH}" "${CIRCLE_JOB}" "${CIRCLE_BUILD_URL}" "${CIRCLE_PULL_REQUEST}" "${SLACK_WEBHOOK}"
84+
name: Notify Slack on failure
85+
when: on_fail
86+
working_directory: ~/kubernetes-monitor
87+
code_formatter:
88+
machine:
89+
docker_layer_caching: true
90+
enabled: true
91+
image: ubuntu-2004:202010-01
92+
steps:
93+
- checkout
94+
- setup_node12
95+
- install_python_requests
96+
- run:
97+
command: |
98+
npm run format:check
99+
name: code formatter check
100+
- run:
101+
command: |
102+
./scripts/slack/notify_failure_on_branch.py "${CIRCLE_BRANCH}" "${CIRCLE_JOB}" "${CIRCLE_BUILD_URL}" "${CIRCLE_PULL_REQUEST}" "${SLACK_WEBHOOK}"
103+
name: Notify Slack on failure
104+
when: on_fail
105+
working_directory: ~/kubernetes-monitor
68106
unit_tests:
69107
machine:
70108
image: ubuntu-2004:202010-01
@@ -78,7 +116,6 @@ unit_tests:
78116
- run:
79117
name: Unit tests
80118
command: |
81-
npm run lint &&
82119
npm run build &&
83120
npm run test:unit:tap &&
84121
npm run test:unit:jest

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"arrowParens": "always",
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"htmlWhitespaceSensitivity": "ignore"
6+
}

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
"build": "tsc",
3131
"dev": "tsc-watch --project tsconfig.json --onSuccess 'node --inspect .'",
3232
"debug": "tsc-watch --project tsconfig.json --onSuccess 'node --inspect-brk .'",
33-
"lint": "eslint \"src/**/*.ts\" && (cd test && eslint \"**/*.ts\")"
33+
"lint": "eslint \"src/**/*.ts\" && (cd test && eslint \"**/*.ts\")",
34+
"format": "prettier --write '{src,test}/**/*.{js,ts,json,yml}'",
35+
"format:check": "prettier --check '{src,test}/**/*.{js,ts,json,yml}'"
3436
},
3537
"dependencies": {
3638
"@kubernetes/client-node": "^0.14.3",
@@ -66,6 +68,7 @@
6668
"eslint-config-prettier": "^6.10.0",
6769
"jest": "^26.6.3",
6870
"nock": "^11.9.1",
71+
"prettier": "^2.2.1",
6972
"sinon": "^8.1.1",
7073
"tap": "^14.10.6",
7174
"ts-jest": "^26.5.4",

src/common/logger.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { config } from './config';
33

44
try {
55
// Validate if LOG_LEVEL has valid bunyan logging level
6-
config.LOGGING.level = bunyan.resolveLevel(process.env.LOG_LEVEL || config.LOGGING.level);
7-
} catch(e) {
8-
console.error(`Log level "${process.env.LOG_LEVEL}" is not valid logging level. Falling back to "INFO"`);
6+
config.LOGGING.level = bunyan.resolveLevel(
7+
process.env.LOG_LEVEL || config.LOGGING.level,
8+
);
9+
} catch (e) {
10+
console.error(
11+
`Log level "${process.env.LOG_LEVEL}" is not valid logging level. Falling back to "INFO"`,
12+
);
913
}
1014

1115
const logger: bunyan = bunyan.createLogger({

src/common/policy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export async function loadAndSendWorkloadAutoImportPolicy(): Promise<void> {
2525
const payload = constructWorkloadAutoImportPolicy(regoPolicy);
2626
await sendWorkloadAutoImportPolicy(payload);
2727
} catch (err) {
28-
logger.error({ err }, 'Unexpected error occurred while loading workload auto-import policy');
28+
logger.error(
29+
{ err },
30+
'Unexpected error occurred while loading workload auto-import policy',
31+
);
2932
}
3033
}

src/common/process.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ export interface IProcessArgument {
77
sanitise: boolean;
88
}
99

10-
export function exec(bin: string, ...processArgs: IProcessArgument[]):
11-
Promise<SpawnPromiseResult> {
10+
export function exec(
11+
bin: string,
12+
...processArgs: IProcessArgument[]
13+
): Promise<SpawnPromiseResult> {
1214
if (process.env.DEBUG === 'true') {
13-
processArgs.push({body: '--debug', sanitise: false});
15+
processArgs.push({ body: '--debug', sanitise: false });
1416
}
1517

1618
// Ensure we're not passing the whole environment to the shelled out process...
@@ -24,11 +26,14 @@ export function exec(bin: string, ...processArgs: IProcessArgument[]):
2426
};
2527

2628
const allArguments = processArgs.map((arg) => arg.body);
27-
return spawn(bin, allArguments, { env, capture: [ 'stdout', 'stderr' ] })
28-
.catch((error) => {
29+
return spawn(bin, allArguments, { env, capture: ['stdout', 'stderr'] }).catch(
30+
(error) => {
2931
const message = (error && error.stderr) || 'Unknown reason';
30-
const loggableArguments = processArgs.filter((arg) => !arg.sanitise).map((arg) => arg.body);
31-
logger.warn({message, bin, loggableArguments}, 'child process failure');
32+
const loggableArguments = processArgs
33+
.filter((arg) => !arg.sanitise)
34+
.map((arg) => arg.body);
35+
logger.warn({ message, bin, loggableArguments }, 'child process failure');
3236
throw error;
33-
});
37+
},
38+
);
3439
}

0 commit comments

Comments
 (0)