@elmenov-softworks/eslint-plugin-between
v1.0.1
Published
ESLint plugin that checks inclusive TypeScript numeric ranges, arithmetic, and function contracts.
Maintainers
Readme
ESLint Plugin Between
Check inclusive numeric ranges in TypeScript with ESLint.
Assignments, arithmetic, function arguments, and return values are checked against
Between<Min, Max> and aliases such as Byte.
let opacity: Between<0, 1> = 0.5;
opacity = 1.5; // Error: outside [0, 1]Setup
npm install --save-dev eslint @elmenov-softworks/eslint-plugin-between @typescript-eslint/parser typescriptCreate eslint.config.mjs:
import parser from '@typescript-eslint/parser';
import between from '@elmenov-softworks/eslint-plugin-between';
export default [
{
...between.configs.recommended,
files: ['**/*.ts', '**/*.tsx'],
languageOptions: { parser },
},
];Add the declarations to tsconfig.json, keeping any existing types entries:
{
"compilerOptions": {
"types": ["@elmenov-softworks/eslint-plugin-between/types"]
}
}Run npx eslint .. For editor diagnostics, enable the ESLint extension for
TypeScript files. No parserOptions.project setting is required.
Examples
Function contracts:
function setChannel(value: Byte): Byte {
return value;
}
setChannel(128); // Valid
setChannel(256); // Error: outside [0, 255]Arithmetic and narrowing:
function brighten(channel: Byte): Byte {
if (channel <= 245) {
return channel + 10; // Valid: result is within [10, 255]
}
return 255;
}Ranges are inclusive and allow fractions. Unknown values are errors by default.
Types erase to ordinary numbers: there is no runtime validation, clamping, or
wrapping. tsc alone does not check ranges; run ESLint alongside the compiler.
Compatibility and documentation
ESLint 9 or 10 with flat config, TypeScript >=5.0.0 <6.1.0, and
Node.js ^20.19.0 || ^22.13.0 || >=24.0.0. The package exports ESM JavaScript.
- Rule options and limitations
- Range behavior and numeric aliases
- Development, tests, and performance
- CI and npm releases
For development: npm ci, npm run build, and npm run check.
npm pack creates a checked, installable archive.
MIT license. See LICENSE.
