Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kaizendorks/eslint-plugin-mongo-projection
eslint rule to catch incorrect use of mongo projections
https://github.com/kaizendorks/eslint-plugin-mongo-projection
eslint mongo-projections mongodb
Last synced: about 15 hours ago
JSON representation
eslint rule to catch incorrect use of mongo projections
- Host: GitHub
- URL: https://github.com/kaizendorks/eslint-plugin-mongo-projection
- Owner: kaizendorks
- License: mit
- Created: 2021-04-30T15:54:29.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T18:46:04.000Z (almost 2 years ago)
- Last Synced: 2024-10-30T07:59:20.093Z (20 days ago)
- Topics: eslint, mongo-projections, mongodb
- Language: JavaScript
- Homepage:
- Size: 236 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Build Status](https://github.com/kaizendorks/eslint-plugin-mongo-projection/workflows/ci/badge.svg)](https://github.com/kaizendorks/eslint-plugin-mongo-projection/actions/)
# eslint-plugin-mongo-projectioneslint rule to catch incorrect use of mongo projections
```javascript
// good
db.collection('foo').find().project({bar: 1})// bad (works in mongo shell but not node)
db.collection('foo').find({}, {bar: 1})
```## Installation
You'll first need to install [ESLint](http://eslint.org):
```
$ npm i eslint --save-dev
```Next, install `eslint-plugin-mongo-projection`:
```
$ npm install eslint-plugin-mongo-projection --save-dev
```## Usage
Add `mongo-projection` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:
```json
{
"plugins": [
"mongo-projection"
]
}
```Then configure the rules you want to use under the rules section.
```json
{
"rules": {
"mongo-projection/mongo-projection": 1
}
}
```## Important Note
This rule relies on checking for all `memberExpressions` named `find`.
There may be cases you want to ignore.
By default `'_'` is ignored. e.g. `_.find(foo, {bar: 1})`.
You can pass the `excludedParentNames` option to alter what is excluded.
e.g. if you use `lodash.find` instead of `_.find`
```json
{
"rules": {
"mongo-projection/mongo-projection": [
"warn",
{
"excludedParentNames": ["lodash"],
},
],
}
}
```## Development
See [dev.md](./dev.md)