├── .travis.yml
├── test
├── mockSQSClient.js
├── mockSendMessageBatchCommand.js
├── tenMessages.json
├── index.test.js
└── bulkLoader.test.js
├── .gitignore
├── src
├── chunk.js
├── index.js
└── bulkLoader.js
├── .github
└── workflows
│ ├── main.yml
│ └── npm-publish.yml
├── LICENSE
├── package.json
├── README.md
└── .eslintrc
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "10"
4 | - "12"
5 | - "14"
6 | script: "npm run travis"
--------------------------------------------------------------------------------
/test/mockSQSClient.js:
--------------------------------------------------------------------------------
1 | class MockSQSClient {
2 |
3 | send(command) {
4 | return Promise.resolve(command.params.Entries);
5 | }
6 | }
7 |
8 | module.exports = MockSQSClient;
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | integration
2 | node_modules
3 | .tmp
4 | .idea
5 | .sass-cache
6 | .eslintcache
7 | npm-debug.log
8 | coverage.html
9 | .vscode
10 | .history
11 | .npmrc
12 | coverage
13 | .coveralls.yml
--------------------------------------------------------------------------------
/src/chunk.js:
--------------------------------------------------------------------------------
1 | function chunk(arr, size) {
2 | return Array.from({"length": Math.ceil(arr.length / size)}, (value, index) => arr.slice(index * size, index * size + size));
3 | }
4 |
5 | module.exports = {
6 | chunk
7 | };
8 |
9 |
--------------------------------------------------------------------------------
/test/mockSendMessageBatchCommand.js:
--------------------------------------------------------------------------------
1 | class MockSendMessageBatchCommand {
2 |
3 | constructor(params) {
4 | this.params_ = params;
5 | }
6 |
7 | get params() {
8 | return this.params_;
9 | }
10 | }
11 |
12 | module.exports = MockSendMessageBatchCommand;
13 |
--------------------------------------------------------------------------------
/test/tenMessages.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "msg1": "val1"
4 | },
5 | {
6 | "msg2": "val2"
7 | },
8 | {
9 | "msg3": "val3"
10 | },
11 | {
12 | "msg4": "val4"
13 | },
14 | {
15 | "msg5": "val5"
16 | },
17 | {
18 | "msg6": "val6"
19 | },
20 | {
21 | "msg7": "val7"
22 | },
23 | {
24 | "msg8": "val8"
25 | },
26 | {
27 | "msg9": "val9"
28 | },
29 | {
30 | "msg10": "val10"
31 | }
32 | ]
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | const {SQSClient, SendMessageBatchCommand} = require("@aws-sdk/client-sqs");
2 | const BulkLoader = require("./bulkLoader");
3 |
4 | function getSqsBulkUploader(client) {
5 | const sqsClient = client || new SQSClient();
6 | const bulkLoader = new BulkLoader(sqsClient, SendMessageBatchCommand);
7 |
8 | return {
9 | "sendBatchedMessages": bulkLoader.sendBatchedMessages.bind(bulkLoader),
10 | "sendBatchedMessagesInParallel": bulkLoader.sendBatchedMessagesInParallel.bind(bulkLoader)
11 | };
12 | }
13 |
14 | module.exports = getSqsBulkUploader;
15 |
16 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: Only Publish Minor
2 | permissions:
3 | contents: read
4 |
5 | on:
6 | workflow_dispatch:
7 | inputs:
8 | npm_otp:
9 | description: enter npm otp
10 | required: true
11 |
12 | jobs:
13 | publish-npm:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - uses: actions/checkout@v1
17 | with:
18 | persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
19 | fetch-depth: 0 # otherwise, you will failed to push refs to dest repo:
20 | - uses: actions/setup-node@v1
21 | with:
22 | node-version: 18
23 | registry-url: https://registry.npmjs.org/
24 | - run: npm update
25 | - run: npm install
26 | - run: npm test
27 | - run: npm publish --otp ${{github.event.inputs.npm_otp}}
28 | env:
29 | NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
30 |
--------------------------------------------------------------------------------
/test/index.test.js:
--------------------------------------------------------------------------------
1 | const {describe, it} = exports.lab = require("@hapi/lab").script();
2 | const {expect} = require("@hapi/code");
3 | const getSqsBulkLoader = require("../src/index");
4 |
5 | describe("Index file", () => {
6 |
7 | describe("When getSqsBulkLoader is called without injecting client", () => {
8 | it("should expose methods", () => {
9 | const {sendBatchedMessages, sendBatchedMessagesInParallel} = getSqsBulkLoader();
10 | expect(sendBatchedMessages).to.be.function();
11 | expect(sendBatchedMessagesInParallel).to.be.function();
12 | });
13 | });
14 |
15 | describe("When getSqsBulkLoader is called with injecting client", () => {
16 | it("should expose methods", () => {
17 | const {sendBatchedMessages, sendBatchedMessagesInParallel} = getSqsBulkLoader({"dummy": "client"});
18 | expect(sendBatchedMessages).to.be.function();
19 | expect(sendBatchedMessagesInParallel).to.be.function();
20 | });
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Ashish Modi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/bulkLoader.js:
--------------------------------------------------------------------------------
1 | const {chunk} = require("./chunk");
2 | const batchPromises = require("batch-promises");
3 |
4 | class BulkLoader {
5 | constructor(sqsClient, SendMessageBatchCommand) {
6 | this.sqsClient_ = sqsClient;
7 | this.sendMessageBatchCommand_ = SendMessageBatchCommand;
8 | }
9 |
10 | async sendBatchedMessages(queueUrl, messages) {
11 | const splittedArray = chunk(messages, 10);
12 | const responses = [];
13 | const params = {
14 | "QueueUrl": queueUrl
15 | };
16 | for (const messageArray of splittedArray) {
17 | params.Entries = messageArray;
18 | const command = new this.sendMessageBatchCommand_(params);
19 | // eslint-disable-next-line no-await-in-loop
20 | const response = await this.sqsClient_.send(command);
21 | responses.push(response);
22 | }
23 | return responses;
24 | }
25 |
26 | async sendBatchedMessagesInParallel(queueUrl, messages, options) {
27 |
28 | const defaultParams = {
29 | "batchSize": 10
30 | };
31 | const customOptions = Object.assign({}, defaultParams, options);
32 |
33 | const splittedArray = chunk(messages, 10);
34 | const responses = await batchPromises(customOptions.batchSize, splittedArray, messageArray => {
35 | const params = {
36 | "QueueUrl": queueUrl
37 | };
38 | params.Entries = messageArray;
39 | const command = new this.sendMessageBatchCommand_(params);
40 | return this.sqsClient_.send(command);
41 | });
42 | return responses;
43 | }
44 | }
45 |
46 | module.exports = BulkLoader;
47 |
--------------------------------------------------------------------------------
/.github/workflows/npm-publish.yml:
--------------------------------------------------------------------------------
1 | name: Node.js Package
2 | permissions:
3 | contents: write
4 |
5 | on:
6 | workflow_dispatch:
7 |
8 | jobs:
9 | build:
10 | runs-on: ubuntu-latest
11 | strategy:
12 | matrix:
13 | node: [ 14, 16, 18 ]
14 | name: Node ${{ matrix.node }} sample
15 | steps:
16 | - uses: actions/checkout@v3
17 | - name: Setup node
18 | uses: actions/setup-node@v3
19 | with:
20 | node-version: ${{ matrix.node }}
21 | - run: npm install
22 | - run: npm test
23 | publish-npm:
24 | needs: build
25 | runs-on: ubuntu-latest
26 | steps:
27 | - uses: actions/checkout@v1
28 | with:
29 | persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
30 | fetch-depth: 0 # otherwise, you will failed to push refs to dest repo:
31 | - uses: actions/setup-node@v1
32 | with:
33 | node-version: 14
34 | registry-url: https://registry.npmjs.org/
35 | - run: npm update
36 | - run: npm install
37 | - run: npm audit fix
38 | - run: npm test
39 | - run: git config --global user.email "montumodi@gmail.com"
40 | - run: git config --global user.name "Ashish Modi"
41 | - run: git commit -m "Add changes" -a
42 | env:
43 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
44 | - name: Push changes
45 | uses: ad-m/github-push-action@master
46 | with:
47 | github_token: ${{ secrets.GITHUB_TOKEN }}
48 | branch: ${{ github.ref }}
49 | - run: npm version minor
50 | - name: Push changes
51 | uses: ad-m/github-push-action@master
52 | with:
53 | github_token: ${{ secrets.GITHUB_TOKEN }}
54 | branch: ${{ github.ref }}
55 | - run: npm publish
56 | env:
57 | NODE_AUTH_TOKEN: ${{secrets.npm_token}}
58 |
--------------------------------------------------------------------------------
/test/bulkLoader.test.js:
--------------------------------------------------------------------------------
1 | const {describe, it} = exports.lab = require("@hapi/lab").script();
2 | const {expect} = require("@hapi/code");
3 | const tenMessages = require("./tenMessages");
4 | const BulkLoader = require("../src/bulkLoader");
5 | const {cloneDeep} = require("lodash");
6 | const MockSQSClient = require("./mockSQSClient");
7 | const MockSendMessageBatchCommand = require("./mockSendMessageBatchCommand");
8 |
9 | describe("bulkSequence method", () => {
10 |
11 | describe("When called with 10 items", () => {
12 | it("should return success", async () => {
13 | const bulkLoader = new BulkLoader(new MockSQSClient(), MockSendMessageBatchCommand);
14 | const response = await bulkLoader.sendBatchedMessages("url", tenMessages);
15 | expect(response).to.equal([tenMessages]);
16 | });
17 | });
18 |
19 | describe("When called with more than 10 items", () => {
20 | it("should return success", async () => {
21 | const moreThanTenItems = cloneDeep(tenMessages);
22 | moreThanTenItems.push({"msg11": "val11"});
23 | const bulkLoader = new BulkLoader(new MockSQSClient(), MockSendMessageBatchCommand);
24 | const response = await bulkLoader.sendBatchedMessages("url", moreThanTenItems);
25 | expect(response).to.equal([tenMessages, [{"msg11": "val11"}]]);
26 | });
27 | });
28 | });
29 |
30 | describe("bulkParallel method", () => {
31 |
32 | describe("When called with 10 items", () => {
33 | it("should return success", async () => {
34 | const bulkLoader = new BulkLoader(new MockSQSClient(), MockSendMessageBatchCommand);
35 | const response = await bulkLoader.sendBatchedMessagesInParallel("url", tenMessages);
36 | expect(response).to.equal([tenMessages]);
37 | });
38 | });
39 |
40 | describe("When called with more than 10 items", () => {
41 | it("should return success", async () => {
42 | const moreThanTenItems = cloneDeep(tenMessages);
43 | moreThanTenItems.push({"msg11": "val11"});
44 | const bulkLoader = new BulkLoader(new MockSQSClient(), MockSendMessageBatchCommand);
45 | const response = await bulkLoader.sendBatchedMessagesInParallel("url", moreThanTenItems, {"batchSize": 2});
46 | expect(response).to.equal([tenMessages, [{"msg11": "val11"}]]);
47 | });
48 | });
49 | });
50 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sqs-bulk-loader",
3 | "version": "4.8.0",
4 | "description": "A set of functions to help sending bulk messages in sequence or parallel to AWS SQS",
5 | "main": "src/index.js",
6 | "scripts": {
7 | "pretest": "eslint --cache \"src/**/*.js\" \"test/**/*.js\"",
8 | "coveralls": "cat ./coverage/lcov.info | node ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",
9 | "test": "./node_modules/@hapi/lab/bin/lab -I '__rewriteRelativeImportExtension,__extends,__assign,__rest,__addDisposableResource,__disposeResources,__decorate,__param,__esDecorate,__runInitializers,__propKey,__setFunctionName,__metadata,__awaiter,__generator,__exportStar,__createBinding,__values,__read,__spread,__spreadArrays,__spreadArray,__await,__asyncGenerator,__asyncDelegator,__asyncValues,__makeTemplateObject,__importStar,__importDefault,__classPrivateFieldGet,__classPrivateFieldSet,__classPrivateFieldIn' ./test/ -v -S --assert @hapi/code --threshold 100 -p 1",
10 | "lint": "./node_modules/.bin/eslint ./src --fix",
11 | "travis": "npm run test",
12 | "premajor": "npm run test",
13 | "major": "npm version major -m \"published to npm as v%s\" && git push --follow-tags && npm publish",
14 | "preminor": "npm run test",
15 | "minor": "npm version minor -m \"published to npm as v%s\" && git push --follow-tags && npm publish",
16 | "prepatch": "npm run test",
17 | "patch": "npm version patch -m \"published to npm as v%s\" && git push --follow-tags && npm publish"
18 | },
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/montumodi/sqs-bulk-loader.git"
22 | },
23 | "files": [
24 | "src",
25 | "README.md"
26 | ],
27 | "keywords": [
28 | "aws",
29 | "sqs",
30 | "bulk",
31 | "batch",
32 | "parallel",
33 | "sequence",
34 | "nodejs",
35 | "node",
36 | "send"
37 | ],
38 | "author": "Ashish Modi",
39 | "license": "ISC",
40 | "bugs": {
41 | "url": "https://github.com/montumodi/sqs-bulk-loader/issues"
42 | },
43 | "homepage": "https://github.com/montumodi/sqs-bulk-loader#readme",
44 | "devDependencies": {
45 | "@aws-sdk/client-sqs": "^3.377.0",
46 | "@hapi/code": "^9.0.3",
47 | "@hapi/lab": "^25.1.2",
48 | "eslint": "^8.34.0",
49 | "lodash": "^4.17.21"
50 | },
51 | "dependencies": {
52 | "batch-promises": "0.0.3"
53 | },
54 | "peerDependencies": {
55 | "@aws-sdk/client-sqs": "^3.0.0"
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AWS SQS Bulk Loader
2 |
3 | A set of functions to help sending bulk messages in sequence or parallel to AWS SQS.
4 |
5 | ## Migration steps from Version 3 to Version 4
6 |
7 | - Add `@aws-sdk/client-sqs` as peer dependency instead of `aws-sdk`
8 | - Rest of the code should work as it is. The response structure has changed slightly.
9 | More information can be found [here](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sqs/interfaces/sendmessagebatchcommandoutput.html)
10 |
11 | [](https://snyk.io/test/github/montumodi/sqs-bulk-loader)
12 | [](https://coveralls.io/github/montumodi/sqs-bulk-loader?branch=master)
13 | [](https://travis-ci.com/montumodi/sqs-bulk-loader)
14 |
15 | [](https://www.npmjs.com/package/sqs-bulk-loader/)
16 |
17 | ## How to install
18 |
19 | ```
20 | npm install sqs-bulk-loader
21 | ```
22 |
23 | `@aws-sdk/client-sqs` is peer dependency for this package. Make sure it is installed.
24 |
25 | To use `aws-sdk` version 2, please use [version 3](https://www.npmjs.com/package/sqs-bulk-loader/v/3.5.0) of this package.
26 |
27 | ```
28 | npm install sqs-bulk-loader@3
29 | ```
30 |
31 | ## Running the tests
32 |
33 | `npm test`
34 |
35 | ### Getting started
36 |
37 | Basic syntax is:
38 |
39 | ```js
40 | const {sendBatchedMessages, sendBatchedMessagesInParallel} = require("sqs-bulk-loader")();
41 |
42 | const messages = [
43 | {
44 | "Id": "1",
45 | "MessageBody": '{"key1": "value1"}'
46 | },
47 | {
48 | "Id": "2",
49 | "MessageBody": '{"key2": "value2"}'
50 | }
51 | ];
52 |
53 | // this needs to be in async function
54 | const response = await sendBatchedMessages("someQueueUrl", messages);
55 | console.log(response)
56 |
57 | // OR you can use normal promise style as well.
58 | sendBatchedMessages("someQueueUrl", messages)
59 | .then(response => console.log(response));
60 |
61 | ```
62 |
63 | In case you need to inject the `@aws-sdk/client-sqs` with custom settings. It can be done like this
64 |
65 | ```js
66 | const {SQSClient} = require("@aws-sdk/client-sqs");
67 | const sqsClient = new SQSClient({"region": "eu-west-2"});
68 | const {sendBatchedMessages, sendBatchedMessagesInParallel} = require("sqs-bulk-loader")(sqsClient);
69 | ```
70 |
71 | ### API
72 |
73 | ### sendBatchedMessages
74 |
75 | ### sendBatchedMessages(queueUrl, messages) ⇒ Promise
76 | Function - Sends the messages passed in batch of 10 sequentially
77 |
78 | **Returns**: Promise - - promise which resolves on success and rejects on error
79 |
80 | | Param | Type | Default | Description |
81 | | --- | --- | --- | --- |
82 | | queueUrl | String | | SQS queue url |
83 | | messages | Array | | Array of messages as per `sendMessageBatch`'s params |
84 |
85 | More details - https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sqs/interfaces/sendmessagebatchcommandinput.html
86 |
87 | ### sendBatchedMessagesInParallel
88 |
89 | ### sendBatchedMessagesInParallel(queueUrl, messages) ⇒ Promise
90 | Function - Sends the messages passed in batch of 10 parallely
91 |
92 | **Returns**: Promise - - promise which resolves on success and rejects on error
93 |
94 | | Param | Type | Default | Description |
95 | | --- | --- | --- | --- |
96 | | queueUrl | String | | SQS queue url |
97 | | messages | Array | | Array of messages as per `sendMessageBatch`'s params |
98 | | [options] | Object | {"batchSize": 10} | Optional object containing extra properties which will be passed to function. Currently it supports `batchSize` integer to control how many parallel requests to spawn. Default is 10 |
99 |
100 | More details - https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sqs/interfaces/sendmessagebatchcommandinput.html
101 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "env": {
3 | "node": true,
4 | "es6": true
5 | },
6 | "parserOptions": {
7 | "ecmaVersion": 2018,
8 | "sourceType": "module"
9 | },
10 | "rules": {
11 | // Possible Errors
12 | // The following rules point out areas where you might have made mistakes.
13 |
14 | "comma-dangle": [2, "never"], // - disallow or enforce trailing commas (recommended)
15 | "getter-return": 2, // - enforces that a return statement is present in property getters
16 | "no-async-promise-executor": 2, // - disallow using an async function as a Promise executor
17 | "no-await-in-loop": 2, // - disallow await inside of loops
18 | "no-compare-neg-zero": 2, // - disallow checking for equality against negative zero
19 | "no-cond-assign": 2, // - disallow assignment in conditional expressions (recommended)
20 | "no-console": 2, // - disallow use of console in the node environment (recommended)
21 | "no-constant-condition": 2, // - disallow use of constant expressions in conditions (recommended)
22 | "no-control-regex": 2, // - disallow control characters in regular expressions (recommended)
23 | "no-debugger": 2, // - disallow use of debugger (recommended)
24 | "no-dupe-args": 2, // - disallow duplicate arguments in functions (recommended)
25 | "no-dupe-keys": 2, // - disallow duplicate keys when creating object literals (recommended)
26 | "no-duplicate-case": 2, // - disallow a duplicate case label. (recommended)
27 | "no-empty-character-class": 2, // - disallow the use of empty character classes in regular expressions (recommended)
28 | "no-empty": 2, // - disallow empty statements (recommended)
29 | "no-ex-assign": 2, // - disallow assigning to the exception in a catch block (recommended)
30 | "no-extra-boolean-cast": 2, // - disallow double-negation boolean casts in a boolean context (recommended)
31 | "no-extra-parens": 0, // - disallow unnecessary parentheses
32 | "no-extra-semi": 2, // - disallow unnecessary semicolons (recommended)
33 | "no-func-assign": 2, // - disallow overwriting functions written as function declarations (recommended)
34 | "no-inner-declarations": [2, "functions"], // - disallow function or variable declarations in nested blocks (recommended)
35 | "no-invalid-regexp": 2, // - disallow invalid regular expression strings in the RegExp constructor (recommended)
36 | "no-irregular-whitespace": 2, // - disallow irregular whitespace outside of strings and comments (recommended)
37 | "no-negated-in-lhs": 2, // - disallow negation of the left operand of an in expression (recommended)
38 | "no-obj-calls": 2, // - disallow the use of object properties of the global object (Math and JSON) as functions (recommended)
39 | "no-regex-spaces": 2, // - disallow multiple spaces in a regular expression literal (recommended)
40 | "no-sparse-arrays": 0, // - disallow sparse arrays (recommended) Note: set to false because array destructuring in ES6
41 | "no-unreachable": 2, // - disallow unreachable statements after a return, throw, continue, or break statement (recommended)
42 | "use-isnan": 2, // - disallow comparisons with the value NaN (recommended)
43 | "valid-jsdoc": 2, // - Ensure JSDoc comments are valid
44 | "valid-typeof": 2, // - Ensure that the results of typeof are compared against a valid string (recommended)
45 | "no-unexpected-multiline": 2, // - Avoid code that looks like two expressions but is actually one
46 |
47 | // Best Practices
48 | // These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid footguns.
49 |
50 | "accessor-pairs": 2, // - Enforces getter/setter pairs in objects
51 | "block-scoped-var": 0, // - treat var statements as if they were block scoped
52 | "complexity": [1, 9], // - specify the maximum cyclomatic complexity allowed in a program
53 | "consistent-return": 1, // - require return statements to either always or never specify values
54 | "curly": [2, "all"], // - specify curly brace conventions for all control statements
55 | "default-case": 0, // - require default case in switch statements
56 | "dot-notation": 2, // - encourages use of dot notation whenever possible
57 | "dot-location": [2, "property"], // - enforces consistent newlines before or after dots
58 | "eqeqeq": 2, // - require the use of === and !==
59 | "guard-for-in": 2, // - make sure for-in loops have an if statement
60 | "no-alert": 2, // - disallow the use of alert, confirm, and prompt
61 | "no-caller": 2, // - disallow use of arguments.caller or arguments.callee
62 | "no-div-regex": 2, // - disallow division operators explicitly at beginning of regular expression
63 | "no-else-return": 2, // - disallow else after a return in an if
64 | "no-eq-null": 2, // - disallow comparisons to null without a type-checking operator
65 | "no-eval": 2, // - disallow use of eval()
66 | "no-extend-native": 2, // - disallow adding to native types
67 | "no-extra-bind": 2, // - disallow unnecessary function binding
68 | "no-fallthrough": 2, // - disallow fallthrough of case statements (recommended)
69 | "no-floating-decimal": 2, // - disallow the use of leading or trailing decimal points in numeric literals
70 | "no-implicit-coercion": 2, // - disallow the type conversions with shorter notations
71 | "no-implied-eval": 2, // - disallow use of eval()-like methods
72 | "no-invalid-this": 2, // - disallow this keywords outside of classes or class-like objects
73 | "no-iterator": 2, // - disallow usage of __iterator__ property
74 | "no-labels": 2, // - disallow use of labeled statements
75 | "no-lone-blocks": 2, // - disallow unnecessary nested blocks
76 | "no-loop-func": 2, // - disallow creation of functions within loops
77 | "no-multi-spaces": [
78 | 2,
79 | {
80 | "ignoreEOLComments": true
81 | }
82 | ], // - disallow use of multiple spaces
83 | "no-multi-str": 2, // - disallow use of multiline strings
84 | "no-native-reassign": 2, // - disallow reassignments of native objects
85 | "no-new-func": 2, // - disallow use of new operator for Function object
86 | "no-new-wrappers": 2, // - disallows creating new instances of String,Number, and Boolean
87 | "no-new": 2, // - disallow use of the new operator when not part of an assignment or comparison
88 | "no-octal-escape": 2, // - disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251";
89 | "no-octal": 2, // - disallow use of octal literals (recommended)
90 | "no-param-reassign": 2, // - disallow reassignment of function parameters
91 | "no-process-env": 2, // - disallow use of process.env
92 | "no-proto": 2, // - disallow usage of __proto__ property
93 | "no-redeclare": 2, // - disallow declaring the same variable more than once (recommended)
94 | "no-return-assign": 2, // - disallow use of assignment in return statement
95 | "no-return-await": 2, // - disallows unnecessary return await
96 | "no-script-url": 2, // - disallow use of javascript: urls.
97 | "no-self-assign": 2, // - disallow Self Assignment
98 | "no-self-compare": 2, // - disallow comparisons where both sides are exactly the same
99 | "no-sequences": 2, // - disallow use of the comma operator
100 | "no-throw-literal": 2, // - restrict what can be thrown as an exception
101 | "no-unused-expressions": 0, // - disallow usage of expressions in statement position
102 | "no-useless-call": 2, // - disallow unnecessary .call() and .apply()
103 | "no-void": 2, // - disallow use of the void operator
104 | "no-warning-comments": 0, // - disallow usage of configurable warning terms in comments - e.g. TODO or FIXME
105 | "no-with": 2, // - disallow use of the with statement
106 | "radix": 2, // - require use of the second argument for parseInt()
107 | "vars-on-top": 2, // - require declaration of all vars at the top of their containing scope
108 | "wrap-iife": 2, // - require immediate function invocation to be wrapped in parentheses
109 | "yoda": 2, // - require or disallow Yoda conditions
110 |
111 | // Strict Mode
112 | // These rules relate to using strict mode.
113 |
114 | "strict": [2, "global"], // - controls location of Use Strict Directives
115 |
116 | // Variables
117 | // These rules have to do with variable declarations.
118 |
119 | "init-declarations": 0, // - enforce or disallow variable initializations at definition
120 | "no-catch-shadow": 2, // - disallow the catch clause parameter name being the same as a variable in the outer scope
121 | "no-delete-var": 2, // - disallow deletion of variables (recommended)
122 | "no-label-var": 2, // - disallow labels that share a name with a variable
123 | "no-shadow-restricted-names": 2, // - disallow shadowing of names such as arguments
124 | "no-shadow": 2, // - disallow declaration of variables already declared in the outer scope
125 | "no-undef-init": 2, // - disallow use of undefined when initializing variables
126 | "no-undef": 2, // - disallow use of undeclared variables unless mentioned in a /*global */ block (recommended)
127 | "no-undefined": 0, // - disallow use of undefined variable
128 | "no-unused-vars": 2, // - disallow declaration of variables that are not used in the code (recommended)
129 | "no-use-before-define": 2, // - disallow use of variables before they are defined
130 |
131 | // Node.js
132 | // These rules are specific to JavaScript running on Node.js.
133 |
134 | "callback-return": 2, // - enforce return after a callback
135 | "global-require": 2, // - enforce require() on the top-level module scope
136 | "handle-callback-err": 2, // - enforce error handling in callbacks
137 | "no-mixed-requires": 2, // - disallow mixing regular variable and require declarations
138 | "no-new-require": 2, // - disallow use of new operator with the require function
139 | "no-path-concat": 2, // - disallow string concatenation with __dirname and __filename
140 | "no-process-exit": 2, // - disallow process.exit()
141 | "no-restricted-modules": 2, // - restrict usage of specified node modules
142 | "no-sync": 2, // - disallow use of synchronous methods
143 | "no-buffer-constructor": 2, // - disallow use of the deprecated Buffer() constructor
144 |
145 | // Stylistic Issues
146 | // These rules are purely matters of style and are quite subjective.
147 |
148 | "array-bracket-spacing": 2, // - enforce spacing inside array brackets
149 | "brace-style": 2, // - enforce one true brace style
150 | "camelcase": 2, // - require camel case names
151 | "comma-spacing": 2, // - enforce spacing before and after comma
152 | "comma-style": 2, // - enforce one true comma style
153 | "computed-property-spacing": 2, // - require or disallow padding inside computed properties
154 | "consistent-this": 2, // - enforce consistent naming when capturing the current execution context
155 | "eol-last": 2, // - enforce newline at the end of file, with no multiple empty lines
156 | "func-names": 0, // - require function expressions to have a name
157 | "func-style": [2, "declaration"], // - enforce use of function declarations or expressions
158 | "id-length": [2,
159 | {
160 | "min": 2,
161 | "max": 70,
162 | "exceptions": ["i", "j", "k", "n", "Q", "_"]
163 | }
164 | ], // - this option enforces minimum and maximum identifier lengths (variable names, property names etc.) (off by default)
165 | "id-match": 0, // - require identifiers to match the provided regular expression
166 | "indent": [2, 2, // - specify tab or space width for your code
167 | {
168 | "SwitchCase": 1
169 | }
170 | ],
171 | "key-spacing": 2, // - enforce spacing between keys and values in object literal properties
172 | "lines-around-comment": [2,
173 | {
174 | "beforeBlockComment": true,
175 | "afterBlockComment": false,
176 | "beforeLineComment": false,
177 | "afterLineComment": false,
178 | "allowBlockStart": true,
179 | "allowBlockEnd": true
180 | }
181 | ], // - enforce empty lines around comments
182 | "linebreak-style": 2, // - disallow mixed 'LF' and 'CRLF' as linebreaks
183 | "max-nested-callbacks": [2, 6], // - specify the maximum depth callbacks can be nested
184 | "max-statements-per-line": [
185 | 2,
186 | {
187 | "max": 1
188 | }
189 | ], // - enforce a maximum number of statements per line
190 | "new-cap": 0, // - require a capital letter for constructors
191 | "new-parens": 2, // - disallow the omission of parentheses when invoking a constructor with no arguments
192 | "newline-after-var": 0, // - require or disallow an empty newline after variable declarations
193 | "no-array-constructor": 2, // - disallow use of the Array constructor
194 | "no-continue": 2, // - disallow use of the continue statement
195 | "no-inline-comments": 0, // - disallow comments inline after code
196 | "no-lonely-if": 2, // - disallow if as the only statement in an else block
197 | "no-mixed-spaces-and-tabs": 2, // - disallow mixed spaces and tabs for indentation (recommended)
198 | "no-multiple-empty-lines": [
199 | 2,
200 | {
201 | "max": 2,
202 | "maxEOF": 1,
203 | "maxBOF": 0
204 | }
205 | ], // - disallow multiple empty lines
206 | "no-nested-ternary": 2, // - disallow nested ternary expressions
207 | "no-new-object": 2, // - disallow the use of the Object constructor
208 | "no-spaced-func": 2, // - disallow space between function identifier and application
209 | "no-ternary": 0, // - disallow the use of ternary operators
210 | "no-trailing-spaces": 2, // - disallow trailing whitespace at the end of lines
211 | "no-underscore-dangle": 0, // - disallow dangling underscores in identifiers
212 | "no-unneeded-ternary": 2, // - disallow the use of Boolean literals in conditional expressions
213 | "object-curly-spacing": 2, // - require or disallow padding inside curly braces
214 | "one-var": [1, "never"], // - require or disallow one variable declaration per function
215 | "operator-assignment": [2, "always"], // - require assignment operator shorthand where possible or prohibit it entirely
216 | "operator-linebreak": 2, // - enforce operators to be placed before or after line breaks
217 | "padded-blocks": 0, // - enforce padding within blocks
218 | "quote-props": 2, // - require quotes around object literal property names
219 | "quotes": [2, "double"], // - specify whether backticks, double or single quotes should be used
220 | "semi-spacing": 2, // - enforce spacing before and after semicolons
221 | "semi": 2, // - require or disallow use of semicolons instead of ASI
222 | "sort-vars": 0, // - sort variables within the same declaration block
223 | "keyword-spacing": 2, // - require a space after certain keywords
224 | "space-before-blocks": 2, // - require or disallow a space before blocks
225 | "space-before-function-paren": [2,
226 | {
227 | "anonymous": "always",
228 | "named": "never"
229 | }
230 | ], // - require or disallow a space before function opening parenthesis
231 | "space-in-parens": 2, // - require or disallow spaces inside parentheses
232 | "space-infix-ops": 2, // - require spaces around operators
233 | "space-unary-ops": 2, // - require or disallow spaces before/after unary operators
234 | "spaced-comment": 2, // - require or disallow a space immediately following the // or /* in a comment
235 | "wrap-regex": 2, // - require regex literals to be wrapped in parentheses
236 |
237 | // ECMAScript 6
238 | // These rules are only relevant to ES6 environments.
239 |
240 | "arrow-parens": [2, "as-needed"], // - require parens in arrow function arguments
241 | "arrow-spacing": 2, // - require space before/after arrow function's arrow
242 | "constructor-super": 2, // - verify calls of super() in constructors
243 | "generator-star-spacing": 2, // - enforce spacing around the * in generator functions
244 | "no-class-assign": 2, // - disallow modifying variables of class declarations
245 | "no-const-assign": 2, // - disallow modifying variables that are declared using const
246 | "no-this-before-super": 2, // - disallow use of this/super before calling super() in constructors.
247 | "no-var": 2, // - require let or const instead of var
248 | "object-shorthand": [2, "methods"], // - require method and property shorthand syntax for object literals
249 | "prefer-const": 2, // - suggest using const declaration for variables that are never modified after declared
250 | "prefer-spread": 2, // - suggest using the spread operator instead of .apply().
251 | "require-yield": 2, // - disallow generator functions that do not have yield
252 | "prefer-template": 2
253 | }
254 | }
--------------------------------------------------------------------------------