sgb-io / fta

Rust-based static analysis for TypeScript projects
https://ftaproject.dev
MIT License
100 stars 6 forks source link

Incorrect halstead formulas #97

Closed ugniusramanauskas closed 8 months ago

ugniusramanauskas commented 8 months ago

Your documentation (as well as other Halstead documentations) clearly states:

Measure Name Description
Program Length (N) The total count of operators and operands.
Program Vocabulary (n) The total count of unique operators and operands.

However, your code does the opposite -- i.e. adds unique values in program_length, and totals in vocabulary_size:

        let program_length = uniq_operators + uniq_operands;
        let vocabulary_size = total_operators + total_operands;

As a result, all the other derivative measures - Volume, Difficulty, Effort, etc. - are also incorrectly calculated.

p.s. Let me know if I can help with correcting this.

sgb-io commented 8 months ago

Thanks for raising this! You're quite right, these numbers are erroneously flipped.

Fix coming via #98

sgb-io commented 8 months ago

This fix is now available in v2.0.0. Thanks!

ugniusramanauskas commented 8 months ago

@sgb-io -- thanks so much for fixing it so quickly! I can see the new "v2.0.0" tag, but no release yet. When do you plan on marking it as an official release? Just curious.

sgb-io commented 8 months ago

@ugniusramanauskas the Rust crate and npm package have been available for a few days, but I forgot to publish the Github release. I have now done so. Thanks!