Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-mongodb

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-mongodb

Lint your MongoDB queries.

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

eslint-plugin-mongodb

Eslint rules for MongoDB best practices.

NPM version Build status Dependency Status devDependency Status Coverage Status Code Climate

Disclaimer: This is a work in progress. Use it only if you wish to be involved in this project evolution by reporting bugs or even sending PRs.

The first stable release will be 1.0.0.

Usage

  1. Install eslint as a dev-dependency:
npm install --save-dev eslint
  1. Install eslint-plugin-mongodb as a dev-dependency:
npm install --save-dev eslint-plugin-mongodb
  1. Enable the plugin by adding it to your .eslintrc:
plugins:
  - mongodb
  1. You can also configure these rules in your .eslintrc. All rules defined in this plugin have to be prefixed by 'mongodb/'

    plugins:
      - mongodb
    rules:
      - mongodb/no-replace: 0
    

Settings

In order to recognize MongoDB native driver queries, this plugin check for function calls. By using shared settings you can specify your own patterns, here are the defaults:

{
    "settings": {
        "mongodb": {
          "callPatterns": {
            "query": [
              "(\\.|^)db\\.collection\\([^\\)]+\\)\\.(find|findOne|)",
            ],
            "update": [
              "(\\.|^)db\\.collection\\([^\\)]+\\)\\.(update|findAndModify)",
            ],
            "insert": [
              "(\\.|^)db\\.collection\\([^\\)]+\\)\\.insert",
            ],
            "remove": [
              "(\\.|^)db\\.collection\\([^\\)]+\\)\\.remove",
            ],
          }
        }
    }
})

Note that the above are strings representing regular expressions. It will be cast with the RegExp constructor so you have to escape your escapes ;).

Rules

no-replace

Default: 'no_replace': 1

Check update queries to ensure no raw replace is done.

check-numeric-updates

Default: 'check-numeric-updates': 2

Check update queries to ensure numeric operators like $mul and $inc contain numeric values.

check-updates-calls

Default: 'check-updates-calls': 2

Check update queries to ensure their arguments are well formed.

check-rename-updates

Default: 'check-rename-updates': 2

Check $rename update operator usage.

check-unset-updates

Default: 'check-unset-updates': 2

Check $unset update operator usage.

check-current-date-updates

Default: 'check-current-date-updates': 2

Check $currentDate update operator usage.

check-minmax-updates

Default: 'check-minmax-updates': 2

Check $min and $max update operator usage.

Contributing

Feel free to push your code if you agree with publishing under the MIT license.

How to create a new rule

Avoid wasting your time and follow those steps to suggest a new rule:

  • create and issue prefixed by [rule] and followed by it's name
  • OR create the rule tests file in the src/lib/rules directory directly, create a branch whose name is the proposed rule name. Finally create a pull request.
  • let's discuss about the feature and its implementation details.
  • implement the feature.

Changing a specific rule behavior

Create and issue prefixed by [rule] and let us know what should change.

Stats

NPM NPM

Keywords

FAQs

Package last updated on 28 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc