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

Some characters are missing in generated output #37

Closed
abenhamdine opened this issue Jan 24, 2017 · 21 comments
Closed

Some characters are missing in generated output #37

abenhamdine opened this issue Jan 24, 2017 · 21 comments

Comments

@abenhamdine
Copy link
Contributor

abenhamdine commented Jan 24, 2017

Nodejs : 7.4.0
Postgres : 9.6.1
schemats : 1.0.1

While using last version 1.0.1 of this module, I run into a strange bug : in the generated file, some characters are missing, always in the third line of first interface declaration.

Eg, in the following example, the file contains export type sal_matriculetring; instead of export type sal_matricule = string;
4 characters = s are missing

Excerpt of output :

/**
 * AUTO-GENERATED FILE @ 2017-01-24 13:27:02 - DO NOT EDIT!
 *
 * This file was generated with schemats node package:
 * $ schemats generate -c postgres://username:password@localhost:5432/testpayroll -t pay_salarie_sal -o schema.ts
 *
 * Re-run the command above.
 *
 */

    
export namespace pay_salarie_salFields {
    export type sal_id = number;
    export type sal_matriculetring;

With another table, the missing characters are in nearly the same place :

/**
 * AUTO-GENERATED FILE @ 2017-01-24 13:33:18 - DO NOT EDIT!
 *
 * This file was generated with schemats node package:
 * $ schemats generate -c postgres://username:password@localhost:5432/testpayroll -t pay_contrat_cnt -o schema.ts
 *
 * Re-run the command above.
 *
 */

    
export namespace pay_contrat_cntFields {
    export type cnt_soldetc_mdp_id = number | null;
    exporte tex_id = number | null;

Of course, expected : export type tex_id instead of exporte tex_id
4 characters typ are missing

It's the only issue in the output file : all other lines are correct.

I don't reproduce the issue with osm artifact test file, which is weird.

@xiamx
Copy link
Contributor

xiamx commented Jan 24, 2017

I've also seen this before.. and it's frustrating. So far I believe the issue is either with the fs.saveFile function or typescript-formatter.

@abenhamdine
Copy link
Contributor Author

Thx for your quick answer and for the clue.
I will investigate when I have some time.

@xiamx
Copy link
Contributor

xiamx commented Jan 24, 2017

No problem. I've seen it happening for one day [1] but I'm unable to reproduce it now for some reason.

@xiamx
Copy link
Contributor

xiamx commented Jan 24, 2017

Removed a potential culprit with #38 .

@abenhamdine
Copy link
Contributor Author

Thanks !
But after have merged #38 locally, I still have the issue. No difference at all.

@xiamx
Copy link
Contributor

xiamx commented Jan 26, 2017

I will probably have to look into typescript-formatter then..

@vitaly-t
Copy link
Contributor

vitaly-t commented Jan 26, 2017

@xiamx how good are your tests? You don't really know that without code coverage. Check out - all my modules have it, you can use them as an example ;)

Setting up code coverage is easy, and if you get stuck - just ask ;)

@xiamx
Copy link
Contributor

xiamx commented Jan 27, 2017

@vitaly-t tests are admittedly not comprehensive at the moment 😂 . We only have end to end tests as of now. I should start adding some unit tests

@Jujunol
Copy link

Jujunol commented Feb 3, 2017

I'm experiencing the same problem with export type password = string being generated as expoype password = string

@xiamx
Copy link
Contributor

xiamx commented Feb 3, 2017

I will take another look at this over the weekend

@vitaly-t
Copy link
Contributor

vitaly-t commented Feb 8, 2017

Anything? It's a killer bug, you know, very critical 😉

@xiamx
Copy link
Contributor

xiamx commented Feb 8, 2017

@vitaly-t 😂 I can't reproduce it, neither locally nor on CI.. even though code coverage report by Istanbul is at 100% line covered

@xiamx
Copy link
Contributor

xiamx commented Feb 8, 2017

Bumping the version of typescript-formatter to 4.1.0. @abenhamdine @Jujunol can you guys please paste the content of your tsconfig.json and tslintrc (if any)? It should help me reproduce this bug locally.

@abenhamdine
Copy link
Contributor Author

abenhamdine commented Feb 8, 2017

Bug still present in 1.1.0 for me, unfortunately.
I reproduce every time with a schema with a single table

Here's the dump of the db :
dump.txt

And the output file :

/**
 * AUTO-GENERATED FILE @ 2017-02-08 16:14:07 - DO NOT EDIT!
 *
 * This file was generated with schemats node package:
 * $ schemats generate -c postgres://username:password@localhost:5432/test_schemats_2 -o schema.ts -t cta_situationcompte_sco
 *
 * Re-run the command above.
 *
 */

    
export namespace cta_situationcompte_scoFields {
    export type sco_id = number;
    export type sco_t_debit = number;
    export type sco_total_credit = number;
    export type sco_nb_ecritures = number;
    export type pst_id = number;
    export type cpt_id = number;

}

export interface cta_situationcompte_sco {
    sco_id: cta_situationcompte_scoFields.sco_id;
    sco_total_debit: cta_situationcompte_scoFields.sco_total_debit;
    sco_total_credit: cta_situationcompte_scoFields.sco_total_credit;
    sco_nb_ecritures: cta_situationcompte_scoFields.sco_nb_ecritures;
    pst_id: cta_situationcompte_scoFields.pst_id;
    cpt_id: cta_situationcompte_scoFields.cpt_id;

}

@xiamx
Copy link
Contributor

xiamx commented Feb 8, 2017

@abenhamdine Thanks. This is very helpful in reproducing it.

I can confirm If I disable typescript-formatter, by replacing index.ts

    let formatterOption = {
        replace: false,
        verify: false,
        tsconfig: true,
        tslint: true,
        editorconfig: true,
        tsfmt: false
    }

    const processedResult = await processString('schema.ts', output, formatterOption)
    return processedResult.dest

with simply return output

The generated file will have export type sco_total_debit = number; generated correctly. This is a weird issue and certainly suggests a bug in typescript-formatter (or a misusage of it in my part.) We use typescript-formatter to (mainly) generate files with correct indentation levels specified by the project's tslintrc or editorconfig.

@xiamx
Copy link
Contributor

xiamx commented Feb 8, 2017

Maybe we can receive some help of its author @vvakame I've created an issue there vvakame/typescript-formatter#74

@xiamx
Copy link
Contributor

xiamx commented Feb 8, 2017

Interestingly, by removing the comment header from the input, the issue disappeared. So maybe the temporal solution is to feed only the output without the comment header to typescript-formatter, and then add the header afterward.

@xiamx
Copy link
Contributor

xiamx commented Feb 8, 2017

After some lengthy debug on typescript-formatter, I proposed a fix here vvakame/typescript-formatter#75. I'll release a fix for schemats quickly by pointing the typescript-fromatter version to our fork.

xiamx added a commit that referenced this issue Feb 8, 2017
xiamx added a commit that referenced this issue Feb 8, 2017
@abenhamdine
Copy link
Contributor Author

1.1.1 solved the pb for me. Thx a lot @xiamx ! 💃 😄 🎉
@Jujunol could you confirm if it's the case for you too ?

@xiamx
Copy link
Contributor

xiamx commented Feb 8, 2017

@abenhamdine awesome, glad to know it fixed it !

Let's keep this tracking issue open until patches are merged in the upstream typescript-formatter project.

@xiamx
Copy link
Contributor

xiamx commented Feb 10, 2017

Thank you everyone, the patch is merged to typescript-formatter. Closing this issue with the release v1.1.2

@xiamx xiamx closed this as completed Feb 10, 2017
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

No branches or pull requests

4 participants