You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enhancement / Request / Wish
Provide a possibility to adjust the settings of code formats through the cli of cds2types and its used dependency "ts-morph". We would like to enable the trailing comma feature to avoid unnecessary warnings/errors and afterwards manual fixes of the outputted typescript file.
export enum Entity {
CodeList = "sap.common.CodeList",
Countries = "sap.common.Countries",
Currencies = "sap.common.Currencies",
Languages = "sap.common.Languages" <-- missing
}
Assumption
You are using ESLint with active rule "require trailing comma" in objects. See https://eslint.org/docs/rules/comma-dangle
The "researched" change is related to ts-morph and supports the feature request.
const project = new Project({
// these are the defaults
manipulationSettings: {
...
// Whether to use trailing commas in multi-line scenarios where trailing
// commas would be used.
useTrailingCommas: false,
},
});
Coding from /src/program.ts, function "run":
public async run(options: IOptions): Promise<void> {
this.interfacePrefix = options.prefix;
...
const project = new morph.Project();
...
}
Solution
Either add a new option "useTrailingComma" to your cli and pass it to the ts-morph project. cds2types -c ./src/services.cds -o ./db/entities.ts -p I -usetrailingcomma
Or a more generic version, to pass multiple settings/options for ts-morph in a appropriate way.
Disclaimer
Even if my research is wrong, the feature requests remains the same 👍
The text was updated successfully, but these errors were encountered:
I just published a new version (v2.6.0) which allows you to pass a -f, --format flag to the CLI.
@ul1sbrt thank you for your research, it helped a lot, sadly the useTrailingCommas setting on the ts-morph project has no effect, I am still looking into it and will open an issue on their repo.
@iDschepe thank you for the suggestions! This is something I am planning to add in the currently planned version 2 re-write.
Which will include this issue aswell.
After the initial idea didn't work I tried to add ESLint with auto-fix support after I generate the source code, here the real trouble started.
ESLint has the comma-dangle rule which works and is auto-fixable but it doesn't affect Typescript code like enums (which in our case are the important code parts). typescript-eslint extended the comma-dangle rule to accommodate for enums, generic type lists, and tuples, although for it to work you have to disable the core rule and suddenly it's no longer auto-fixable.
{
// note you must disable the base rule as it can report incorrect errors"comma-dangle": "off",
"@typescript-eslint/comma-dangle": ["error"]
}
So, to make a long story short, if you'd like to format the resulting source I'd recommend setting up Prettier in your project (if you did not already) as the CLI now reads the projects Prettier configuration and applies it upon file creation.
Enhancement / Request / Wish
Provide a possibility to adjust the settings of code formats through the cli of cds2types and its used dependency "ts-morph". We would like to enable the trailing comma feature to avoid unnecessary warnings/errors and afterwards manual fixes of the outputted typescript file.
Assumption
You are using ESLint with active rule "require trailing comma" in objects. See https://eslint.org/docs/rules/comma-dangle
The "researched" change is related to ts-morph and supports the feature request.
Codeing
Via ts-morph it is possible to active the option "useTrailingCommas", stated here: https://ts-morph.com/manipulation/settings
Coding from
/src/program.ts
, function "run":Solution
Either add a new option "useTrailingComma" to your cli and pass it to the ts-morph project.
cds2types -c ./src/services.cds -o ./db/entities.ts -p I -usetrailingcomma
Or a more generic version, to pass multiple settings/options for ts-morph in a appropriate way.
Disclaimer
Even if my research is wrong, the feature requests remains the same 👍
The text was updated successfully, but these errors were encountered: