Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/personalyisus/eslint-plugin-unnecessary-abstractions
This is a simple ESLint plugin which includes rules to help detect the unnecessary use of certain code abstractions.
https://github.com/personalyisus/eslint-plugin-unnecessary-abstractions
eslint eslint-plugin eslintplugin
Last synced: about 1 month ago
JSON representation
This is a simple ESLint plugin which includes rules to help detect the unnecessary use of certain code abstractions.
- Host: GitHub
- URL: https://github.com/personalyisus/eslint-plugin-unnecessary-abstractions
- Owner: personalyisus
- Created: 2024-07-16T23:03:44.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-07-26T02:51:03.000Z (4 months ago)
- Last Synced: 2024-09-29T01:04:12.641Z (about 2 months ago)
- Topics: eslint, eslint-plugin, eslintplugin
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/eslint-plugin-unnecessary-abstractions
- Size: 60.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# eslint-plugin-unnecessary-abstractions
This is a simple ESLint plugin which includes rules to help detect the unnecessary use of certain code abstractions.
## Rules
### no-ternary-wrappers```javascript
// Incorrect ❌
function isUserRightHanded(rightHanded, rightHand, leftHand) {
return rightHanded ? rightHand : leftHand; // Don't create a function just to wrap a ternary
}useHand(isUserRightHanded(isRightHandedUser, user.rightHand, user.leftHand));
// Correct ✅
useHand(isRightHandedUser ? user.rightHand : user.leftHand); // Use the ternary directly```
## Installation
Install it as part of your devDependencies
```sh
npm i --save-dev eslint-plugin-unnecessary-abstractions
```### ESLint 9
Import the plugin and add it as a configuration object to the array of configurations on your ESLint configuration file, including the rules you want to use
```js
// eslint.config.js
import unnecessaryAbstractions from "eslint-plugin-unnecessary-abstractions";export default [
// ... other configurations
{
plugins: { "unnecessary-abstractions": unnecessaryAbstractions },
rules: {
// Add the desired rule
"unnecessary-abstractions/no-ternary-wrappers": "warn" // or "error",
},
},
];
```### ESLint 8
Add `"unnecessary-abstractions"` to the plugins array of your ESLint configuration and include the rules you want to use
```js
// .eslintrc.jsmodule.exports = {
// Add the plugin to the list
plugins: [/* ... */ , "unnecessary-abstractions"],
rules: {
// Add the rules you want
"unnecessary-abstractions/no-ternary-wrappers": "warn" // or "error
},
};```