An ESLint plugin that makes your TypeScript code safer
This plugin requires TypeScript and typescript-eslint. If you haven't installed them in your project, follow the guide on typescript-eslint's Getting Started page.
Once you're ready, install this plugin:
# npm
npm i --save-dev @susisu/eslint-plugin-safe-typescript
# yarn
yarn add -D @susisu/eslint-plugin-safe-typescript
# pnpm
pnpm add -D @susisu/eslint-plugin-safe-typescript- Enable typescript-eslint parser
- Add
@susisu/eslint-plugin-safe-typescriptto plugins - (Optional) Add
parserOptions.projectif you enable rules that use type information.
// eslint.config.js
import tsEslint from "typescript-eslint";
import safeTsPlugin from "@susisu/eslint-plugin-safe-typescript";
export default [
{
languageOptions: {
parser: tsEslint.parser, // (1)
parserOptions: {
project: true, // (3)
},
},
plugins: {
"@susisu/safe-typescript": safeTsPlugin, // (2)
},
rules: {
"@susisu/safe-typescript/no-object-assign": "error",
},
},
];This plugin also provides a configuration set for the recommended rules (see Rules for which rules are recommended).
Since some rules in the recommended configuration require type information, parserOptions.project must be set in your config.
// eslint.config.js
export default [
safeTsPlugin.configs.recommended,
// or extend in `rules`
// {
// rules: {
// ...safeTsPlugin.configs.recommended.rules,
// },
// },
];✅ = recommended, 🔧 = fixable, 💡 = has suggestions, 💭 = requires type information
| Name | Description | ✅ | 🔧 | 💭 |
|---|---|---|---|---|
no-object-assign-mutation |
Disallow mutations using Object.assign(). |
✅ | ||
no-type-assertion |
Disallow type assertions like x as T. |
✅ | ||
no-unsafe-object-enum-method |
Disallow possibly unsafe property enumeration methods of Object. |
✅ | 💭 | |
no-unsafe-object-property-check |
Disallow possibly unsafe property checks of object. | ✅ | 💭 | |
no-unsafe-object-property-overwrite |
Disallow possibly unsafe overwrites of object properties. | ✅ | 💡 | 💭 |
Issues and PRs are welcome! Feel free to open issues if you have any problems or ideas.