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

Add support for controlled trailing semi-colons and injecting custom properties #1059

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

manikandan-ravikumar
Copy link

In this PR, I would like to introduced the following two new settings,

  1. disableTrailingSemiColon - A boolean flag indicating if the generator should append every line with a semi-colon
  2. injectCustomProperties - A map of class to string property lists. Similar to importDeclarations but instead injects additional properties into the given type. This is useful for when we try to be backward-compatible in the FE API and update the backend logic to have the newer property names. Also avoids adding these properties manually every time after running the typscript-generator.

This PR also includes some minor improvements in other parts of the code.

@manikandan-ravikumar manikandan-ravikumar changed the title Semi colon custom properties Add support for controlled trailing semi-colons and injecting custom properties Apr 22, 2024
@panchenko
Copy link
Contributor

@manikandan-ravikumar Could you please elaborate on the reasons for disableTrailingSemiColon?

@manikandan-ravikumar
Copy link
Author

@panchenko I am not disabling semi-colons. I am just introducing an option to disable it. The default value for disabling semi-colon is false.
The reason behind this is, not all typescript projects use the trailing semi-colon pattern as with JavaScript/Typescript semi-colons are optional. Providing an option to disable it will avoid unnecessary manual work.

@@ -129,6 +130,8 @@ public class GenerateTask extends DefaultTask {
public boolean jackson2ModuleDiscovery;
public List<String> jackson2Modules;
public Logger.Level loggingLevel;
public boolean disableTrailingSemiColon;
public Map<Class<?>, List<String>> injectCustomProperties;
Copy link
Contributor

Choose a reason for hiding this comment

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

This task is setup in build.gradle, but the corresponding user-defined classes are not accessible there.
Should be class name as string - similar to other fields.

Choose a reason for hiding this comment

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

Addressed this comment

@panchenko
Copy link
Contributor

The reason behind this is, not all typescript projects use the trailing semi-colon pattern as with JavaScript/Typescript semi-colons are optional. Providing an option to disable it will avoid unnecessary manual work.

I am trying to understand why it matters. Code analysis should be just disabled for the generated file. For example, in the file header there are comments to disable tslint/eslint.

@manikandan-ravikumar
Copy link
Author

The reason behind this is, not all typescript projects use the trailing semi-colon pattern as with JavaScript/Typescript semi-colons are optional. Providing an option to disable it will avoid unnecessary manual work.

I am trying to understand why it matters. Code analysis should be just disabled for the generated file. For example, in the file header there are comments to disable tslint/eslint.

I agree from the functional POV. But from code maintenance POV, it makes this file stand-out. I am working in a project where we maintain a common standard across the code base and it involves no semi-colon usage. So, we had to generate.ts and make manual changes on top of it every time. This breaks the concept of having a "generated" file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants