Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
eslint-plugin-flowtype
Advanced tools
eslint-plugin-flowtype is an ESLint plugin that provides linting rules for Flow type annotations. It helps ensure that your Flow type annotations are correct and consistent, improving the reliability and maintainability of your code.
Type Annotations
This rule ensures that every file has a valid Flow file annotation. The code sample demonstrates a simple function with Flow type annotations for the parameters and return type.
/* eslint flowtype/require-valid-file-annotation: [2, "always"] */
// @flow
function add(a: number, b: number): number {
return a + b;
}
Type Definitions
This rule ensures that all Flow type definitions are defined correctly. The code sample shows a type definition for a User object and an instance of that type.
/* eslint flowtype/define-flow-type: 2 */
// @flow
type User = {
name: string,
age: number
};
const user: User = { name: 'John', age: 30 };
Type Casting
This rule enforces a naming convention for type identifiers. The code sample demonstrates a type definition that follows the specified naming convention.
/* eslint flowtype/type-id-match: [2, "^([A-Z][a-z0-9]+)+Type$"] */
// @flow
type UserType = {
name: string,
age: number
};
const user: UserType = { name: 'John', age: 30 };
eslint-plugin-typescript is an ESLint plugin that provides linting rules for TypeScript code. It offers similar functionality to eslint-plugin-flowtype but is designed for TypeScript instead of Flow. It helps ensure that your TypeScript code is correct and consistent.
typescript-eslint is a set of tools that allows ESLint to lint TypeScript code. It includes an ESLint plugin and a parser that can handle TypeScript syntax. Like eslint-plugin-flowtype, it helps maintain code quality and consistency, but it is tailored for TypeScript.
/**
const formatCodeSnippet = (setup) => { const paragraphs = [];
if (setup.options) {
paragraphs.push('// Options: ' + JSON.stringify(setup.options));
}
paragraphs.push(setup.code);
if (setup.errors) {
paragraphs.push('// Message: ' + setup.errors[0].message);
}
return paragraphs.join('\n');
};
const getAssertions = () => { const assertionFiles = glob.sync(path.resolve(__dirname, './../tests/rules/assertions/*.js'));
const assertionNames = _.map(assertionFiles, (filePath) => {
return path.basename(filePath, '.js');
});
const assertionCodes = _.map(assertionFiles, (filePath) => {
const codes = require(filePath).default;
return {
valid: _.map(codes.valid, formatCodeSnippet),
invalid: _.map(codes.invalid, formatCodeSnippet)
};
});
return _.zipObject(assertionNames, assertionCodes);
};
const updateDocuments = (assertions) => { const readmeDocumentPath = path.join(__dirname, './../README.md');
let documentBody = fs.readFileSync(readmeDocumentPath, 'utf8');
documentBody = documentBody.replace(/<!-- assertions ([a-z]+?) -->/ig, (assertionsBlock) => {
let ruleName,
ruleAssertions;
ruleName = assertionsBlock.match(/assertions ([a-z]+)/i)[1];
ruleAssertions = assertions[ruleName];
if (!ruleAssertions) {
throw new Error('No assertions available for rule "' + ruleName + '".');
return assertionsBlock;
}
return 'The following patterns are considered problems:\n\n```js\n' + ruleAssertions.invalid.join('\n\n') + '\n```\n\nThe following patterns are not considered problems:\n\n```js\n' + ruleAssertions.valid.join('\n\n') + '\n```\n';
});
fs.writeFileSync(readmeDocumentPath, documentBody);
};
updateDocuments(getAssertions());
FAQs
Flowtype linting rules for ESLint.
The npm package eslint-plugin-flowtype receives a total of 3,559,665 weekly downloads. As such, eslint-plugin-flowtype popularity was classified as popular.
We found that eslint-plugin-flowtype demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.