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

Testing with Flow Static Analysis Tool #52

Merged
merged 10 commits into from
Oct 30, 2024
Merged

Testing with Flow Static Analysis Tool #52

merged 10 commits into from
Oct 30, 2024

Conversation

karengc27
Copy link

@karengc27 karengc27 commented Oct 23, 2024

The Flow static testing tool was added to the repository and was used to run tests on the /src folder. The output of the tests were put into nodebb-f24-team-sweepers/flow-output.txt. A screenshot of what the output of the test looks like can be seen below:
Screenshot 2024-10-22 at 9 21 14 PM

To be able to run the tests the following commands work:
npm run flow (runs tests on files with "// @ flow" at the top of file)
npx flow check --all (runs test on all files based on restrictions in .flowconfig)

The following files were added:
.flowconfig
flow-output.txt (to show outputs from tests)

The following changes were made to the package.json:
Screenshot 2024-10-23 at 9 48 33 PM

WHY WE DID NOT FIX ALL THE ERRORS:
NOTE: Despite passing the "Lint and Test" workflow, the PR for Flow integration did not clear the type checks due to the sheer volume of errors. However, we opted to merge the PR, based on the belief that many errors reported by Flow were false positives. For example, the first couple of errors given by Flow are “cannot-resolve-module” for modules such as sanitize-html. However, when one goes to the file, modules like sanitize-html were initialized in another file such as "node_modules/@types/ sanitize-html/index". A similar error given by Flow was the prop-missing error which is often caused by properties being defined in other files. For example, Flow marked “file.walk” as an error since “.walk” was not defined in the search.js file, however this property was defined in file.js. Additionally, there are also many signature-verification-failure and missing-local-annot errors that would require us to add type annotations to all the files that Flow is checking. This would require a large amount of time and effort since there are 19471 errors. After discussing this with Professor Hilton, we have decided to prioritize integrating Flow without resolving all identified errors, allowing us to continue development while gradually improving type coverage over time.

Tool Evaluation:
What types of problems are you hoping your tooling will catch? What types of problems does this particular tool catch?
I was hoping that the tool would help catch type errors since it is a static type checker for Javascript which can help with refactoring code cautiously without having to worry about causing the code to break. This in turn would help to safely merge branches into main when major code changes are made. The tool checks for various type errors and the error message often involve missing annotations, can't resolve module messages, property missing and more. These errors look like prop-missing, missing-local-annot, incompatible-use, invalid-export, cannot-resolve-module, and more. Overall, Flow tries to ensure that changes made work as intended without having any type errors occurred based on the logic.

What types of customization are possible or necessary?
For customizations, it's possible to choose which files to test. For example you can test every file by running npx flow check --all. In the .flowconfig, you can include which files or folder you want to be ignored when running"npx flow check --all" if you don't actually want to test each file. If you want to test individual file, you can run the comman "npm run flow" which would test each individual file that has "// @ flow" at the beginning of the file. You can also have flow running in the background to offer incremental feedback as you code through flow's watch mode by running the command "npx flow start". The "[options]" part of .flowconfig also allows for customization by enabling or disabling certain features such as being able to set include_warnings to true. Other parts of the .flowconfig file that allow for customization are [untyped], [declarations], [libs], [lints], and [strict].

How can/should this tool be integrated into a development process?
To integrate this tool, you have to run npm install --save-dev flow-remove-types to install flow-remove-types. This has to be added to scripts in the package.json: "build": "flow-remove-types src/ -d lib/", "prepublish": "npm run build". Then flow bin has to be installed: npm install --save-dev flow-bin. This has to be added to scripts in package.json: "flow": "flow". The first time you run flow this command has to be used: npm run flow init. After to run flow this command can be used: npm run flow. Changes can be made to .flowconfig to choose which files should be tested or ignored.

Are there many false positives? False negatives? True positive reports about things you don’t care about?
I think that there are not many false positives or negatives, however it points out a lot of true positive reports about things we don't care about. For example, when running the tests there were a lot of errors about missing annotations, however the code still runs as intended and the error acts as more of a warning. It is true that the errors that it gives could pose a potential issue in the future. For example, for nodebb-f24-team-sweepers/src/topics/tools.js it gave 50 errors which most were "missing-local-annot"

@coveralls
Copy link

coveralls commented Oct 23, 2024

Pull Request Test Coverage Report for Build 11580216013

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 82.69%

Totals Coverage Status
Change from base Build 11467018223: 0.0%
Covered Lines: 22331
Relevant Lines: 25587

💛 - Coveralls

@karengc27 karengc27 changed the title Flow Static Testing Tool Testing with Flow Static Analysis Tool Oct 23, 2024
@karengc27 karengc27 requested a review from Alanna-Cao October 30, 2024 19:52
Copy link

@Alanna-Cao Alanna-Cao left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@karengc27 karengc27 assigned karengc27 and unassigned karengc27 Oct 30, 2024
@karengc27 karengc27 merged commit 56f67b0 into f24 Oct 30, 2024
2 of 3 checks passed
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.

3 participants