Skip to content

Comments / formatting #84

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

Merged
merged 5 commits into from
May 17, 2021

Conversation

JBBianchi
Copy link
Member

@JBBianchi JBBianchi commented May 14, 2021

What this PR does / why we need it:
Improves code quality and consistancy with linting and prettifying.
Adds comments & file headers.
Fixes builder problems.

Linked to #79
Linked to #94

Closes #89
Closes #90
Closes #91
Closes #92
Closes #93

JBBianchi added 4 commits May 14, 2021 09:34
- refactored WorkflowValidator.validationErrors as errors to keep
  consistancy with the underlying validator and other validators
- added missing comments
- fixed README `Add as dependency to your project`, used the scoped name
- added imports in README examples
- added 'validate parts of a workflow' example in README

Signed-off-by: JBBianchi <jb.bianchi@neuroglia.io>
- added prettier & eslint
- fixed eslint errors/warnings

Signed-off-by: JBBianchi <jb.bianchi@neuroglia.io>
- formatted code with prettier

Signed-off-by: JBBianchi <jb.bianchi@neuroglia.io>
- added husky for pre commit formatting/pre push test
- fixed prettier commands
- formatted code

Signed-off-by: JBBianchi <jb.bianchi@neuroglia.io>
@JBBianchi
Copy link
Member Author

Not sure husky/lint-staged work as expected...

@JBBianchi
Copy link
Member Author

@antmendoza @tsurdilo are you ok with merging this ? I'm not a 100% sure about the husky/lint-staged config but it's a step forward anyways and shouldn't break anything :)

@antmendoza
Copy link
Contributor

I will review it today, thank you @JBBianchi

@antmendoza
Copy link
Contributor

Hi @JBBianchi

I think that husky is not working for me if I am getting it right.

The pre-commit hook will run "npx lint-staged", which run "npm run format" for all the staged files, isn't it?

In my case nothing happen

any suggestions ?

@JBBianchi
Copy link
Member Author

Hi @JBBianchi

I think that husky is not working for me if I am getting it right.

The pre-commit hook will run "npx lint-staged", which run "npm run format" for all the staged files, isn't it?

In my case nothing happen

any suggestions ?

lint-staged will run "npm run format" if there is any .ts staged if I understood well but I must admit I don't think it's working.

- fixed builder for union types
- rename "validatorFn" by "buildingFn" in builder(s)
- fixed default kind/type for Subflowstate, Function, Eventdef
- added file header
- "installed" husky
- updated lint-staged config

Signed-off-by: JBBianchi <jb.bianchi@neuroglia.io>
@JBBianchi
Copy link
Member Author

I fixed lint-staged/husky I think. 1st, I forgot to install husky properly, 2nd I didn't use the proper command to format (npm run format is formatting all the files, with lint-staged we want to only format the staged ones. So in the end, I just used prettier --write).

I also added file header and some fixes:
#89
#90
#91
#92
#93
#94

Copy link
Contributor

@antmendoza antmendoza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

husky is not working for me, no idea why.

Instead it works adding the pre-commit hook like it shows the documentation here https://www.npmjs.com/package/husky
npx husky add .husky/pre-commit "npm test"

Could you check if this is working also for you?

I am gonna merge this anyway, we can fix it in another pr.

Thank you @JBBianchi


**Anything else we need to know?**:

---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the md files are been formatting, cool !!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier supports MD indeed but I don't really understand why they have been formatted... I thought I specified .ts only...

import { validators, Specification } from '@severlessworkflow/sdk-typescript';

const injectionState: Specification.Injectstate = workflow.states[0];
const injectionStateValidator: ValidateFunction<Specification.Injectstate> = validators.get('Injectstate');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we create a wrapper (like workflowValidator) to validate individual elements?

(not now, just wondering)

Functions, retries, and event can be defined in different files, so I think at least for those element we have to.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ if I where a user of the sdk, I don't want to learn the keys for each element to retrieve the validator from validators

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'keys' are the type names of Specification but I agree with you, it could be improved. I need to double check but I don't think we can use the type directly in TS like validator.get(Specification.Injectstate) because the type doens't exist at runtime. Anyhow, good idea, there is room for improvement here.

One side note though, more regarding the schema, I think Events/Retries/Functions cannot be used by themselves because they are based on custom properties that don't exist in the JSON Schema specification. So they can be "pointed at" but not used alone. I might be wrong though. (See little chat in the JSON Schema Slack)

@@ -0,0 +1,21 @@
export const fileHeader = `/*
* Copyright 2021-Present The Serverless Workflow Specification Authors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -0,0 +1 @@
_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just curious, what this is supposing to do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's added by husky. When doing husky install, it creates .husky/ with that .gitignore and a _/ with a .sh in it.

@antmendoza antmendoza merged commit 41a4e8a into serverlessworkflow:main May 17, 2021
@JBBianchi
Copy link
Member Author

husky is not working for me, no idea why.

Instead it works adding the pre-commit hook like it shows the documentation here https://www.npmjs.com/package/husky
npx husky add .husky/pre-commit "npm test"

Could you check if this is working also for you?

I am gonna merge this anyway, we can fix it in another pr.

Thank you @JBBianchi

Maybe you need to run the husky install ? It creates .husky/_/ containing a husky.sh. I'll double check tomorrow, I'm not familiar with husky/lint-staged.

@tsurdilo
Copy link
Contributor

is there anything I can help with this? if you have some steps i can follow can try on a clean box

@JBBianchi
Copy link
Member Author

@tsurdilo I would be nice if you could get the project, run npm install, create a new dummy .ts file with something like export const foo = "bar"; and commit locally.

Huksy should kick in and, in the end, the file should be prettyfied as export const foo = 'bar'; (with single quotes)

@JBBianchi JBBianchi deleted the comments-formatting branch May 18, 2021 09:09
@JBBianchi
Copy link
Member Author

I think @antmendoza is right, they changed the way to handle hooks. The js/json/package method has been replaced by the .husky directory thing (https://blog.typicode.com/husky-git-hooks-javascript-config/). I'll fix that.

@JBBianchi JBBianchi mentioned this pull request May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants