Tool written in Node.js that connects to your mongodb database and runs eslint on all stored JavaScript functions. Helps developers detect potential issues and avoid head-scratching trying to figure out which stored js function is causing db.loadServerScripts() to fail -- mongo shell error messages do not tell you which function is the culprit. For example:
> db.loadServerScripts();
2015-05-08T14:59:28.094+0000 SyntaxError: Unexpected token ;
2015-05-08T14:59:28.099+0000 Error: 16722 SyntaxError: Unexpected token ; at src/mongo/shell/db.js:895
>
git clone https://github.com/dacgrouplabs/mongo-linter.git
Optionally, you can run npm update
to grab the latest dependencies:
cd mongo-linter
npm update
First, copy the provided config.json.sample
to config.json
and provide a valid databaseUrl
value.
{
"databaseUrl" : "mongodb://username:password@serverip:port/database?options"
}
The connection string should follow the format described in the mongo connection string docs.
Copy the provided rules.json.sample
to rules.json
and update the rules entry with the rules you'd like applied to your Javascript functions.
For example:
{
"rules": {
"eqeqeq": 0,
"no-bitwise": 1,
"curly": [2, "multi"],
"quotes": [2, "double"]
}
}
Since ESLint is being used as the internal linter, please refer to the ESLint Rules page for all available options.
node mongo-linter.js
or:
node mongo-linter.js --url=mongodb://username:password@serverip:port/database?options
Output example:
PS C:\dev\mongo-linter> node .\mongo-linter.js
trying to connect...
connected.
retrieving all documents from system.js collection
documents returned: 1
start linting...
aggregateAllTheThings : 1 issues
================================================================================
function (sourceCollection, targetColleciton){
[...]
}
================================================================================
[ { fatal: true,
message: 'Unexpected token }',
line: 13,
column: 42 } ]
finished linting.
found 1 issues in 1 documents. :(
goodbye.
PS C:\dev\mongo-linter>
Command line support for connection string as argument, fallback to config.json if no argument givenDoneReplaceDonemongojs
and use mongodb native node driver insteadHack away at writing jshint support for mongodb stored js env- Embed mongo-linter into shell or possibly hooked into mongodb system.js.save() event itself
The test suite can be run using mocha.
$ mocha
Configuration
databaseUrl
✓ should contain a databaseUrl key
✓ should match the format of username:password@serverip:port/database
2 passing (14ms)
see LICENSE.
Want to contribute? Great!
- Fork it.
- Create a branch (
git checkout -b my_branch
) - Commit your changes (
git commit -am "Added funktastic feature!"
) - Push to the branch (
git push origin my_branch
) - Open a Pull Request