@susisu/eslint-plugin-safe-typescript
v0.9.2
Published
ESLint plugin that makes your TypeScript code safer
Downloads
21,484
Readme
@susisu/eslint-plugin-safe-typescript
An ESLint plugin that makes your TypeScript code safer
Installation
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
Configuration
- Enable typescript-eslint parser
- Add
@susisu/eslint-plugin-safe-typescript
to plugins - (Optional) Add
parserOptions.project
if you enable rules that use type information.
.eslintrc
:
{
"parser": "@typescript-eslint/parser", // (1)
"parserOptions": {
"project": true // (3)
},
"plugins": ["@susisu/safe-typescript"], // (2)
"rules": {
"@susisu/safe-typescript/no-object-assign": "error"
}
}
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",
},
},
];
Recommended configuration
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.
eslintrc
{
"extends": ["plugin:@susisu/safe-typescript/recommended"]
}
eslint.config.js
export default [
safeTsPlugin.configs.recommended,
// or extend in `rules`
// {
// rules: {
// ...safeTsPlugin.configs.recommended.rules,
// },
// },
];
Rules
✅ = recommended, 🔧 = fixable, 💭 = requires type information
| Name | Description | ✅ | 🔧 | 💭 |
| --- | --- | --- | --- | --- |
| no-object-assign
| Disallow the use of 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. | ✅ | | 💭 |
Contributing
Issues and PRs are welcome! Feel free to open issues if you have any problems or ideas.