eslint-plugin-mongo-projection

0.0.3 • Public • Published

Build Status

eslint-plugin-mongo-projection

eslint rule to catch incorrect use of mongo projections

// 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:

$ 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:

{
    "plugins": [
        "mongo-projection"
    ]
}

Then configure the rules you want to use under the rules section.

{
    "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

{
    "rules": {
        "mongo-projection/mongo-projection": [
            "warn",
            {
                "excludedParentNames": ["lodash"],
            },
        ],
    }
}

Development

See dev.md

Package Sidebar

Install

npm i eslint-plugin-mongo-projection

Weekly Downloads

2

Version

0.0.3

License

MIT

Unpacked Size

11.1 kB

Total Files

10

Last publish

Collaborators

  • kaizendorks
  • conorsheehan1