1.0.3 • Published 11 months ago

@okee-tech/eslint-plugin-neverthrow v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

eslint-plugin-neverthrow

ESLint plugin to enforce proper handling of Result types from the neverthrow package. Plugin NPM

Installation

npm install -D @okee-tech/eslint-plugin-neverthrow
# or
yarn add -D @okee-tech/eslint-plugin-neverthrow

Configuration (flat config)

import neverthrowPlugin from "@okee-tech/eslint-plugin-neverthrow";
import TSESLint from "typescript-eslint";

export default [
  // Use default config
  neverthrowPlugin.configs.recomended,
  // Or have custom config
  {
    plugins: { neverthrowPlugin },
    languageOptions: {
      parser: TSESLint.parser,
      parserOptions: {
        ecmaVersion: "latest",
        sourceType: "module",
        projectService: {
          allowDefaultProject: ["*.ts"],
        },
      },
    },
    rules: {
      "@okee-tech/eslint-plugin-neverthrow/must-consume-result": "error",
    },
  },
];

Ensures that Result objects returned from functions are properly handled.

✅ Valid:

// Direct method calls
genResult().unwrapOr("default");
genResult().isOk();

// Assigned and consumed
const result = genResult();
result._unsafeUnwrap();

// Chained references
const r1 = genResult();
const r2 = r1;
r2.isOk();

// Returned from functions
function example() {
  return genResult();
}

❌ Invalid:

// Result not consumed
genResult();

// Result assigned but not used
const result = genResult();

Rules

🔧 Automatically fixable by the --fix CLI option.\ 💡 Manually fixable by editor suggestions.\ 💭 Requires type information.

Name               Description🔧💡💭
must-consume-resultEnforce proper handling of Result objects returned from neverthrow operations🔧💡💭

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago