Skip to content

armadacore/eslint-plugin-essentials

Repository files navigation

@armadacore/eslint-plugin-essentials

npm version license node

ESLint plugin that enforces patterns from @armadacore/essentials:

  • result-must-handle-errIResult<T> values must have their error path handled.
  • optional-must-have-default — Optional function/method parameters and return types must not leak undefined/null.

Install

npm install -D @armadacore/eslint-plugin-essentials

Peer dependencies: eslint >=9, typescript >=5.

Usage (flat config)

// eslint.config.js
import essentials from '@armadacore/eslint-plugin-essentials';
import tseslint from 'typescript-eslint';

export default [
	...tseslint.configs.recommendedTypeChecked,
	...essentials.configs.recommended,
	{
		languageOptions: {
			parserOptions: {
				project: './tsconfig.json',
			},
		},
	},
];

Both rules require parserServices (i.e. a TypeScript program). Without parserOptions.project, the rules will silently no-op.

Rules

result-must-handle-err

Reports any IResult<T> value whose Err branch is never handled.

Accepted as handling: onErr, match, unwrapOr, unwrapOrElse, err, expectErr, orElse, ignoreErr.

Delegation also counts: return result, passing as argument, assignment to a container.

See the wiki page.

optional-must-have-default

Reports function/method signatures that introduce undefined/null into the function body or its return value.

See the wiki page.

Example

The example/ directory contains a real workspace using @armadacore/essentials with both valid and invalid code samples. Run:

npm install
npm run build
npm run example:lint

License

MIT

About

ESLint plugin for @armadacore/essentials: enforce Err-path handling on IResult and non-nullish defaults on optional parameters

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Contributors