Tool: Added flow - #37
Open
aaronlockhartdev wants to merge 3 commits into
Open
Conversation
- Add Flow type checking to CI/CD pipeline - Add Flow scripts and dependencies to install/package.json - Configure ESLint to ignore Flow-specific files - Update .gitignore with Flow patterns
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces Flow static type checking to the NodeBB codebase, adding an additional layer of type safety to catch potential runtime errors before code is deployed.
Changes Made
CI/CD Pipeline (
.github/workflows/test.yaml)Dependencies (
install/package.json)flow-bin(v0.304.0) for type checkingflow-coverage-report(v0.8.0) for coverage reportingflow: runsflow checkfor type validationflow-coverage: generates HTML coverage reportConfiguration Files
.gitignore: Added Flow-specific patterns (.flowconfig,.flow*,flow-coverage-report/)eslint.config.mjs: Configured ESLint to ignore Flow files and output directories (.flowconfig,flow-coverage-report/)Benefits
Testing
The Flow check will run automatically in CI/CD as part of the test pipeline.
P3B Questions
Flow is a static type checker for Javascript that enables the use of type annotations to reduce type-related bugs.
The tool is used for static analysis.
This tool catches type related errors. Javascript is a dynamically and weakly typed language, which can lead to unexpected behavior when unintended type conversions occur. Flow attempts to mitigate these errors by allowing developers to express the intended type for a variable.
Little customization of the tool itself is possible or necessary; however, it is necessary to choose the tool for stripping flow types (
babelorflow-remove-types) in the build process.This tool must be integrated into the build process, as type annotations must be stripped prior to building. Flow can be run through npm scripts in a CI/CD pipeline, allowing automatic type checking. Flow must be activated on a file-by-file basis by adding
// @flowat the beginning. Developers should use type annotations wherever possible, especially for new code.Flow can result in false positives, as some complex cases can not be adequately represented by type annotations or understood by Flow. False negatives are rare, though the necessity to opt in for each individual file means that some files can be overlooked entirely.