├── .gitignore ├── CONTRIBUTING.md ├── ascii.md ├── package.json ├── README.md ├── index.js ├── LICENSE └── .eslintrc /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | *.log 4 | *.swp 5 | *.bak 6 | credentials*.json 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We want to make contributing to `tumblr-repl` as easy and transparent as possible. If you run into problems, please open an issue. We also actively welcome pull requests. 4 | 5 | ## Contributor License Agreement ("CLA") 6 | 7 | In order to accept your contribution, we need you to submit a CLA. If you open 8 | a pull request, a bot will automatically check if you have already submitted 9 | one. If not it will ask you to do so by visiting a link and signing in with 10 | GitHub. 11 | 12 | The CLA, contact information, and GitHub sign-in can be found here: 13 | [https://yahoocla.herokuapp.com](https://yahoocla.herokuapp.com). 14 | 15 | ## License 16 | 17 | By contributing to tumblr.js you agree that your contributions will be licensed under its Apache 2.0 license. 18 | 19 | -------------------------------------------------------------------------------- /ascii.md: -------------------------------------------------------------------------------- 1 | ``` 2 | 3 | .o .o88 .o88 4 | .88 "888 "888 5 | o8888oo ooo oooo ooo. .oo. .oo. 888oooo. 888 oooo d8b 6 | ""888"" 888 "888 "888P"Y88bP"Y88b d88' `88b 888 "888""8P 7 | 888 888 888 888 888 888 888 888 888 888 8 | 888 . 888 888 888 888 888 888. 888 888 888 .o. 9 | "888Y `V88V"V8P' o888o o888o o888o 88`bod8P' o888o d888b Y8P 10 | 11 | ``` 12 | tumblr-repl v0.0.0 13 | tumblr.js v0.0.0 14 | 15 | Type `help` to get a list of cool things I can do. 16 | 17 | For more information, check out the API docs here: 18 | `https://www.tumblr.com/api` 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tumblr-repl", 3 | "version": "1.0.1", 4 | "description": "REPL for the Tumblr API, built on tumblr.js", 5 | "main": "index.js", 6 | "bin": { 7 | "tumblr": "index.js" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://www.github.com/tumblr/tumblr-repl.git" 15 | }, 16 | "keywords": [ 17 | "tumblr", 18 | "tumblr.js", 19 | "repl", 20 | "api" 21 | ], 22 | "author": "Keith McKnight", 23 | "license": "Apache-2.0", 24 | "dependencies": { 25 | "chalk": "^1.1.3", 26 | "json5": "^0.5.0", 27 | "lodash": "^4.11.1", 28 | "minimist": "^1.2.0", 29 | "os-homedir": "^1.0.1", 30 | "query-string": "^4.1.0", 31 | "repl.history": "^0.1.3", 32 | "tumblr.js": "latest" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tumblr.js REPL 2 | 3 | An interactive [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop) for the [tumblr.js](https://www.github.com/tumblr/tumblr.js) that you can use to make calls to the Tumblr API. 4 | 5 | ## Installation 6 | 7 | npm install -g tumblr-repl 8 | 9 | ## Usage 10 | 11 | You can enter the interactive console like this: 12 | 13 | $ tumblr 14 | 15 | ### Authentication 16 | 17 | You'll need a credentials file that defines `consumer_key`, `consumer_secret`, `token`, and `token_secret` in order to authenticate requests. You can specify the path to it directly: 18 | 19 | $ tumblr --credentials=path/to/credentials.json 20 | 21 | Otherwise, it will look for `tumblr-credentials.json` or `credentials.json` in the current directory. Failing that, it will look for `tumblr-credentials.json` in your home directory. 22 | 23 | ### Client Methods 24 | 25 | In the REPL console, the `tumblr` object holds the instance of the Tumblr client with the credentials you supplied. For convenience, we automatically supply a callback if you omit one, so you can do things like this: 26 | 27 | tumblr.js > tumblr.blogInfo('staff') 28 | 29 | ...and the response will print right before your eyes. What a time to be alive! 30 | 31 | Type `help` to get a list of methods on the client. 32 | 33 | --- 34 | 35 | # Copyright and license 36 | 37 | Copyright 2016-2019 Tumblr, Inc. 38 | 39 | Licensed under the Apache License, Version 2.0 (the "License"); you may not 40 | use this work except in compliance with the License. You may obtain a copy of 41 | the License in the [LICENSE](LICENSE) file, or at: 42 | 43 | http://www.apache.org/licenses/LICENSE-2.0 44 | 45 | Unless required by applicable law or agreed to in writing, software 46 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 47 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 48 | License for the specific language governing permissions and limitations. 49 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env node 2 | 3 | var fs = require('fs'); 4 | var repl = require('repl'); 5 | var replHistory = require('repl.history'); 6 | var util = require('util'); 7 | var path = require('path'); 8 | var osHomedir = require('os-homedir'); 9 | var qs = require('query-string'); 10 | var JSON5 = require('json5'); 11 | 12 | var _ = require('lodash'); 13 | var chalk = require('chalk'); 14 | var argv = require('minimist')(process.argv.slice(2)); 15 | 16 | var tumblr = require('tumblr.js'); 17 | 18 | // Style output with ANSI color codes 19 | function print(object) { 20 | console.log(util.inspect(object, null, null, true)); 21 | } 22 | 23 | // Load credentials 24 | var credentials = (function() { 25 | var credsFile = argv.credentials || _.find([ 26 | 'tumblr-credentials.json', 27 | 'credentials.json', 28 | path.join(osHomedir(), 'tumblr-credentials.json'), 29 | ], function(credsFile) { 30 | return fs.existsSync(credsFile); 31 | }) || 'credentials.json'; 32 | 33 | try { 34 | var credentials = JSON5.parse(fs.readFileSync(credsFile).toString()); 35 | } catch (e) { 36 | console.error(chalk.red('Error loading credentials!')); 37 | console.error('Make sure %s exists or specify %s', chalk.cyan(credsFile || 'credentials.json'), chalk.cyan('--credentials=path/to/credentials.json')); 38 | process.exit(); 39 | } 40 | 41 | console.log('\nUsing OAuth creds from %s\n', chalk.magenta(path.resolve(credsFile))); 42 | 43 | var missingCredentials = _.remove(['consumer_key', 'consumer_secret', 'token', 'token_secret'], _.partial(_.negate(_.has), credentials)); 44 | if (!_.isEmpty(missingCredentials)) { 45 | console.warn(chalk.yellow('Credentials is missing keys:')); 46 | missingCredentials.forEach(function(key) { 47 | console.warn(chalk.yellow(' * %s'), key); 48 | }); 49 | 50 | if (credentials.consumer_key && credentials.consumer_secret) { 51 | console.log('\nYou can generate user tokens by going to the API console:\n'); 52 | console.log(chalk.magenta([ 53 | 'https://api.tumblr.com/console/auth', 54 | '?consumer_key=', credentials.consumer_key, 55 | '&consumer_secret=', credentials.consumer_secret, 56 | ].join(''))); 57 | } 58 | } 59 | 60 | return credentials; 61 | })(); 62 | 63 | // Print intro message 64 | (function printIntro() { 65 | var ascii = fs.readFileSync(path.join(__dirname, 'ascii.md')).toString(); 66 | // Logo: Blue 67 | ascii = ascii.replace(/```\n?([\s\S]*?)```\n?/m, chalk.blue('$1')); 68 | // Version numbers: White 69 | ascii = ascii.replace(/^(.* |)(tumblr-repl v)(0\.0\.0)(.*)/m, chalk.white('$1$2' + require('./package.json').version, '$4')); 70 | ascii = ascii.replace(/^(.* |)(tumblr.js v)(0\.0\.0)(.*)/m, chalk.white('$1$2' + require('tumblr.js/package.json').version, '$4')); 71 | // Indented text: Gray 72 | ascii = ascii.replace(/^(\s{4}\S.*)/gm, chalk.gray('$1')); 73 | // Highlights: Green 74 | ascii = ascii.replace(/(^|\s)`([^`]+)`(\s|$)/g, chalk.green('$1$2$3')); 75 | 76 | console.log(ascii); 77 | })(); 78 | 79 | // Start REPL server 80 | var server = repl.start({ 81 | prompt: argv.prompt || 'tumblr.js > ', 82 | source: null, 83 | eval: null, 84 | useGlobal: false, 85 | useColors: true, 86 | ignoreUndefined: true, 87 | }); 88 | 89 | // Save REPL history 90 | replHistory(server, path.join(osHomedir(), '.tumblrjs_repl_history')); 91 | 92 | // Save the last response 93 | var _resp; 94 | 95 | // Create the Tumblr API Client 96 | var client = (function createTumblrClient() { 97 | var client = new tumblr.Client(credentials); 98 | 99 | // Provide a default callback for inspection 100 | var getRequest = client.getRequest; 101 | client.getRequest = function(apiPath, params, callback) { 102 | if (callback) { 103 | return getRequest.call(this, apiPath, params, callback); 104 | } 105 | 106 | var queryString = qs.stringify(params); 107 | var requestMessage = 'GET ' + apiPath + (queryString ? '?' + queryString : ''); 108 | 109 | getRequest.call(this, apiPath, params, function(err, resp) { 110 | _resp = err || resp; 111 | if (err) { 112 | console.error('\n', chalk.red(requestMessage)); 113 | console.error(chalk.red(err)); 114 | } else { 115 | console.log('\n', chalk.green(requestMessage)); 116 | print(resp, null, null, true); 117 | } 118 | server.displayPrompt(true); 119 | }); 120 | }; 121 | 122 | var postRequest = client.postRequest; 123 | client.postRequest = function(apiPath, params, callback) { 124 | if (callback) { 125 | return postRequest.call(this, apiPath, params, callback); 126 | } 127 | 128 | var requestMessage = 'POST ' + apiPath; 129 | 130 | postRequest.call(this, apiPath, params, function(err, resp) { 131 | _resp = err || resp; 132 | if (err) { 133 | console.error('\n', chalk.red(requestMessage)); 134 | console.error(chalk.red(err)); 135 | } else { 136 | console.log('\n', chalk.green(requestMessage)); 137 | print(resp, null, null, true); 138 | } 139 | server.displayPrompt(true); 140 | }); 141 | }; 142 | 143 | return client; 144 | })(); 145 | 146 | // Set REPL context variables 147 | (function(context) { 148 | context.lodash = _; 149 | context.tumblr = client; 150 | context.print = print; 151 | 152 | // Callback function that can be used to store an API response object in the REPL context 153 | context.set = function(err, object) { 154 | if (err) { 155 | return console.log(err); 156 | } 157 | 158 | context.result = object; 159 | print(object); 160 | console.log('Stored in variable: \'result\''); 161 | }; 162 | 163 | Object.defineProperty(context, '_response', { 164 | get: function() { 165 | return _resp; 166 | }, 167 | }); 168 | 169 | Object.defineProperty(context, 'help', { 170 | get: function() { 171 | console.log('\n%s has the following methods:\n', chalk.blue('tumblr')); 172 | Object.keys(client).forEach(function(method) { 173 | if (method === 'postRequest' || method === 'getRequest' || typeof client[method] !== 'function') { 174 | return; 175 | } 176 | if (typeof client[method] === 'function') { 177 | var methodName = chalk.cyan(method); 178 | var methodArgs = (client[method].toString().match(/\([^\)]*\)/) || [])[0] 179 | .replace(/[\s\(\)]/gm, '') 180 | .split(',') 181 | .map(function(arg) { 182 | if (arg === 'params' || arg === 'callback') { 183 | return chalk.yellow(arg); 184 | } else { 185 | return chalk.green(arg); 186 | } 187 | }) 188 | .join(', '); 189 | 190 | console.log(' %s(%s)', methodName, methodArgs); 191 | } 192 | }); 193 | console.log(''); 194 | console.log('%s stores the response from the last API request response.', chalk.magenta('_response')); 195 | console.log(''); 196 | }, 197 | }); 198 | })(server.context); 199 | 200 | // Control + L should clear the REPL 201 | process.stdin.on('keypress', function(s, key) { 202 | if (key && key.ctrl && key.name == 'l') { 203 | process.stdout.write('\u001B[2J\u001B[0;0f'); 204 | } 205 | }); 206 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2016 Tumblr, Inc. 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint:recommended", 3 | "env": { 4 | "node": true 5 | }, 6 | 7 | "parser": "espree", 8 | "ecmaFeatures": {}, 9 | 10 | // 11 | // http://eslint.org/docs/rules/ 12 | // 13 | 14 | "rules": { 15 | // 16 | // 17 | // Rules 18 | // 19 | // 20 | // Rules in ESLint are divided into several categories to help you better understand their value. All rules are 21 | // disabled by default. ESLint recommends some rules to catch common problems, and you can use these recommended 22 | // rules by including `extends: "eslint:recommended"` in your configuration file. The rules that will be enabled 23 | // when you inherit from `eslint:recommended` are indicated below as "(recommended)". For more information on how to 24 | // configure rules and use `extends`, please see the [configuration documentation](../user-guide/configuring.md). 25 | // 26 | // Some rules are fixable using the `--fix` command line flag. Those rules are marked as "(fixable)" below. 27 | // Currently these fixes are mostly limited only to whitespace fixes. 28 | // 29 | 30 | // 31 | // Possible Errors 32 | // 33 | // The following rules point out areas where you might have made mistakes. 34 | // 35 | 36 | "comma-dangle": ["error", "always-multiline"], // disallow or enforce trailing commas (recommended) 37 | "no-cond-assign": "error", // disallow assignment in conditional expressions (recommended) 38 | "no-console": "off", // disallow use of `console` (recommended) 39 | "no-constant-condition": "error", // disallow use of constant expressions in conditions (recommended) 40 | "no-control-regex": "error", // disallow control characters in regular expressions (recommended) 41 | "no-debugger": "error", // disallow use of `debugger` (recommended) 42 | "no-dupe-args": "error", // disallow duplicate arguments in functions (recommended) 43 | "no-dupe-keys": "error", // disallow duplicate keys when creating object literals (recommended) 44 | "no-duplicate-case": "error", // disallow a duplicate case label. (recommended) 45 | "no-empty": "error", // disallow empty block statements (recommended) 46 | "no-empty-character-class": "error", // disallow the use of empty character classes in regular expressions (recommended) 47 | "no-ex-assign": "error", // disallow assigning to the exception in a `catch` block (recommended) 48 | "no-extra-boolean-cast": "error", // disallow double-negation boolean casts in a boolean context (recommended) 49 | "no-extra-parens": "off", // disallow unnecessary parentheses 50 | "no-extra-semi": "error", // disallow unnecessary semicolons (recommended) (fixable) 51 | "no-func-assign": "error", // disallow overwriting functions written as function declarations (recommended) 52 | "no-inner-declarations": "error", // disallow function or variable declarations in nested blocks (recommended) 53 | "no-invalid-regexp": "error", // disallow invalid regular expression strings in the `RegExp` constructor (recommended) 54 | "no-irregular-whitespace": "error", // disallow irregular whitespace outside of strings and comments (recommended) 55 | "no-negated-in-lhs": "error", // disallow negation of the left operand of an `in` expression (recommended) 56 | "no-obj-calls": "error", // disallow the use of object properties of the global object (`Math` and `JSON`) as functions (recommended) 57 | "no-regex-spaces": "error", // disallow multiple spaces in a regular expression literal (recommended) 58 | "no-sparse-arrays": "error", // disallow sparse arrays (recommended) 59 | "no-unexpected-multiline": "error", // disallow code that looks like two expressions but is actually one (recommended) 60 | "no-unreachable": "error", // disallow unreachable statements after a return, throw, continue, or break statement (recommended) 61 | "use-isnan": "error", // disallow comparisons with the value `NaN` (recommended) 62 | "valid-jsdoc": ["error", {"requireReturn": false}], // ensure JSDoc comments are valid 63 | "valid-typeof": "error", // ensure results of typeof are compared against a valid string (recommended) 64 | 65 | // 66 | // Best Practices 67 | // 68 | // These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing 69 | // something or help you avoid footguns. 70 | // 71 | 72 | "accessor-pairs": "off", // enforce getter/setter pairs in objects 73 | "array-callback-return": "off", // enforce return statements in callbacks of array's methods 74 | "block-scoped-var": "off", // treat `var` statements as if they were block scoped 75 | "complexity": ["off", 11], // specify the maximum cyclomatic complexity allowed in a program 76 | "consistent-return": "off", // require `return` statements to either always or never specify values 77 | "curly": "off", // specify curly brace conventions for all control statements 78 | "default-case": "off", // require `default` case in `switch` statements 79 | "dot-location": "off", // enforce consistent newlines before or after dots 80 | "dot-notation": "off", // encourage use of dot notation whenever possible 81 | "eqeqeq": "off", // require use of `===` and `!==` 82 | "guard-for-in": "off", // ensure `for-in` loops have an `if` statement 83 | "no-alert": "off", // disallow use of `alert`, `confirm`, and `prompt` 84 | "no-caller": "off", // disallow use of `arguments.caller` or `arguments.callee` 85 | "no-case-declarations": "error", // disallow lexical declarations in case clauses (recommended) 86 | "no-div-regex": "off", // disallow division operators explicitly at beginning of regular expression 87 | "no-else-return": "off", // disallow `else` after a `return` in an `if` 88 | "no-empty-function": "off", // disallow use of empty functions 89 | "no-empty-pattern": "error", // disallow use of empty destructuring patterns (recommended) 90 | "no-eq-null": "off", // disallow comparisons to null without a type-checking operator 91 | "no-eval": "off", // disallow use of `eval()` 92 | "no-extend-native": "off", // disallow adding to native types 93 | "no-extra-bind": "off", // disallow unnecessary function binding 94 | "no-extra-label": "off", // disallow unnecessary labels 95 | "no-fallthrough": "error", // disallow fallthrough of `case` statements (recommended) 96 | "no-floating-decimal": "off", // disallow the use of leading or trailing decimal points in numeric literals 97 | "no-implicit-coercion": "off", // disallow the type conversions with shorter notations 98 | "no-implicit-globals": "off", // disallow `var` and named functions in global scope 99 | "no-implied-eval": "off", // disallow use of `eval()`-like methods 100 | "no-invalid-this": "off", // disallow `this` keywords outside of classes or class-like objects 101 | "no-iterator": "off", // disallow usage of `__iterator__` property 102 | "no-labels": "off", // disallow use of labeled statements 103 | "no-lone-blocks": "off", // disallow unnecessary nested blocks 104 | "no-loop-func": "off", // disallow creation of functions within loops 105 | "no-magic-numbers": "off", // disallow the use of magic numbers 106 | "no-multi-spaces": "off", // disallow use of multiple spaces (fixable) 107 | "no-multi-str": "off", // disallow use of multiline strings 108 | "no-native-reassign": "off", // disallow reassignments of native objects 109 | "no-new": "off", // disallow use of the `new` operator when not part of an assignment or comparison 110 | "no-new-func": "off", // disallow use of new operator for `Function` object 111 | "no-new-wrappers": "off", // disallow creating new instances of `String`,`Number`, and `Boolean` 112 | "no-octal": "error", // disallow use of octal literals (recommended) 113 | "no-octal-escape": "off", // disallow use of octal escape sequences in string literals, such as `var foo = "Copyright \251";` 114 | "no-param-reassign": "off", // disallow reassignment of function parameters 115 | "no-proto": "off", // disallow usage of `__proto__` property 116 | "no-redeclare": "error", // disallow declaring the same variable more than once (recommended) 117 | "no-return-assign": "off", // disallow use of assignment in `return` statement 118 | "no-script-url": "off", // disallow use of `javascript:` urls. 119 | "no-self-assign": "error", // disallow assignments where both sides are exactly the same (recommended) 120 | "no-self-compare": "off", // disallow comparisons where both sides are exactly the same 121 | "no-sequences": "off", // disallow use of the comma operator 122 | "no-throw-literal": "off", // restrict what can be thrown as an exception 123 | "no-unmodified-loop-condition": "off", // disallow unmodified conditions of loops 124 | "no-unused-expressions": "off", // disallow usage of expressions in statement position 125 | "no-unused-labels": "error", // disallow unused labels (recommended) 126 | "no-useless-call": "off", // disallow unnecessary `.call()` and `.apply()` 127 | "no-useless-concat": "off", // disallow unnecessary concatenation of literals or template literals 128 | "no-useless-escape": "off", // disallow unnecessary usage of escape character 129 | "no-void": "off", // disallow use of the `void` operator 130 | "no-warning-comments": "off", // disallow usage of configurable warning terms in comments: e.g. `TODO` or `FIXME` 131 | "no-with": "off", // disallow use of the `with` statement 132 | "radix": "off", // require use of the second argument for `parseInt()` 133 | "vars-on-top": "off", // require declaration of all vars at the top of their containing scope 134 | "wrap-iife": "off", // require immediate function invocation to be wrapped in parentheses 135 | "yoda": "off", // require or disallow Yoda conditions 136 | 137 | // 138 | // Strict Mode 139 | // 140 | // These rules relate to using strict mode and strict mode directives. 141 | // 142 | 143 | "strict": "off", // require effective use of strict mode directives 144 | 145 | // 146 | // Variables 147 | // 148 | // These rules have to do with variable declarations. 149 | // 150 | 151 | "init-declarations": "off", // enforce or disallow variable initializations at definition 152 | "no-catch-shadow": "off", // disallow the catch clause parameter name being the same as a variable in the outer scope 153 | "no-delete-var": "error", // disallow deletion of variables (recommended) 154 | "no-label-var": "off", // disallow labels that share a name with a variable 155 | "no-restricted-globals": "off", // restrict usage of specified global variables 156 | "no-shadow": "off", // disallow declaration of variables already declared in the outer scope 157 | "no-shadow-restricted-names": "off", // disallow shadowing of names such as `arguments` 158 | "no-undef": "error", // disallow use of undeclared variables unless mentioned in a `/*global */` block (recommended) 159 | "no-undef-init": "off", // disallow use of undefined when initializing variables 160 | "no-undefined": "off", // disallow use of `undefined` variable 161 | "no-unused-vars": ["error", {"vars": "all", "args": "none"}], // disallow declaration of variables that are not used in the code (recommended) 162 | "no-use-before-define": "off", // disallow use of variables before they are defined 163 | 164 | // 165 | // Node.js and CommonJS 166 | // 167 | // These rules are specific to JavaScript running on Node.js or using CommonJS in the browser. 168 | // 169 | 170 | "callback-return": "off", // enforce `return` after a callback 171 | "global-require": "off", // enforce `require()` on top-level module scope 172 | "handle-callback-err": "off", // enforce error handling in callbacks 173 | "no-mixed-requires": "off", // disallow mixing regular variable and require declarations 174 | "no-new-require": "off", // disallow use of `new` operator with the `require` function 175 | "no-path-concat": "off", // disallow string concatenation with `__dirname` and `__filename` 176 | "no-process-env": "off", // disallow use of `process.env` 177 | "no-process-exit": "off", // disallow `process.exit()` 178 | "no-restricted-modules": "off", // restrict usage of specified modules when loaded by `require` function 179 | "no-sync": "off", // disallow use of synchronous methods 180 | 181 | // 182 | // Stylistic Issues 183 | // 184 | // These rules are purely matters of style and are quite subjective. 185 | // 186 | 187 | "array-bracket-spacing": ["error", "never"], // enforce spacing inside array brackets (fixable) 188 | "block-spacing": "off", // disallow or enforce spaces inside of single line blocks (fixable) 189 | "brace-style": ["error", "1tbs", {"allowSingleLine": false}], // enforce one true brace style 190 | "camelcase": "off", // require camel case names 191 | "comma-spacing": ["error", {"before": false, "after": true}], // enforce spacing before and after comma (fixable) 192 | "comma-style": "off", // enforce one true comma style 193 | "computed-property-spacing": "off", // require or disallow padding inside computed properties (fixable) 194 | "consistent-this": "off", // enforce consistent naming when capturing the current execution context 195 | "eol-last": "off", // enforce newline at the end of file, with no multiple empty lines (fixable) 196 | "func-names": "off", // require function expressions to have a name 197 | "func-style": "off", // enforce use of function declarations or expressions 198 | "id-blacklist": "off", // disallow certain identifiers to prevent them being used 199 | "id-length": "off", // enforce minimum and maximum identifier lengths (variable names, property names etc.) 200 | "id-match": "off", // require identifiers to match the provided regular expression 201 | "indent": ["error", 4, {"SwitchCase": 1}], // specify tab or space width for your code (fixable) 202 | "jsx-quotes": "off", // specify whether double or single quotes should be used in JSX attributes (fixable) 203 | "key-spacing": ["error", {"beforeColon": false, "afterColon": true}], // enforce spacing between keys and values in object literal properties 204 | "keyword-spacing": "off", // enforce spacing before and after keywords (fixable) 205 | "linebreak-style": "off", // enforce linebreak style (fixable) 206 | "lines-around-comment": "off", // enforce empty lines around comments 207 | "max-depth": "off", // specify the maximum depth that blocks can be nested 208 | "max-len": "off", // specify the maximum length of a line in your program 209 | "max-nested-callbacks": "off", // specify the maximum depth callbacks can be nested 210 | "max-params": "off", // specify the number of parameters that can be used in the function declaration 211 | "max-statements": "off", // specify the maximum number of statement allowed in a function 212 | "max-statements-per-line": "off", // specify the maximum number of statements allowed per line 213 | "new-cap": "off", // require a capital letter for constructors 214 | "new-parens": "error", // disallow the omission of parentheses when invoking a constructor with no arguments 215 | "newline-after-var": "off", // require or disallow an empty newline after variable declarations 216 | "newline-before-return": "off", // require newline before `return` statement 217 | "newline-per-chained-call": "off", // enforce newline after each call when chaining the calls 218 | "no-array-constructor": "off", // disallow use of the `Array` constructor 219 | "no-bitwise": "off", // disallow use of bitwise operators 220 | "no-continue": "off", // disallow use of the `continue` statement 221 | "no-inline-comments": "off", // disallow comments inline after code 222 | "no-lonely-if": "off", // disallow `if` as the only statement in an `else` block 223 | "no-mixed-spaces-and-tabs": "error", // disallow mixed spaces and tabs for indentation (recommended) 224 | "no-multiple-empty-lines": "off", // disallow multiple empty lines 225 | "no-negated-condition": "off", // disallow negated conditions 226 | "no-nested-ternary": "off", // disallow nested ternary expressions 227 | "no-new-object": "off", // disallow the use of the `Object` constructor 228 | "no-plusplus": "off", // disallow use of unary operators, `++` and `--` 229 | "no-restricted-syntax": "off", // disallow use of certain syntax in code 230 | "no-spaced-func": "off", // disallow space between function identifier and application (fixable) 231 | "no-ternary": "off", // disallow the use of ternary operators 232 | "no-trailing-spaces": "off", // disallow trailing whitespace at the end of lines (fixable) 233 | "no-underscore-dangle": "off", // disallow dangling underscores in identifiers 234 | "no-unneeded-ternary": "off", // disallow the use of ternary operators when a simpler alternative exists 235 | "no-whitespace-before-property": "off", // disallow whitespace before properties 236 | "object-curly-spacing": ["off", "never"], // require or disallow padding inside curly braces (fixable) 237 | "one-var": "off", // require or disallow one variable declaration per function 238 | "one-var-declaration-per-line": "off", // require or disallow an newline around variable declarations 239 | "operator-assignment": "off", // require assignment operator shorthand where possible or prohibit it entirely 240 | "operator-linebreak": "off", // enforce operators to be placed before or after line breaks 241 | "padded-blocks": "off", // enforce padding within blocks 242 | "quote-props": ["error", "as-needed", {"keywords": true}], // require quotes around object literal property names 243 | "quotes": ["error", "single", "avoid-escape"], // specify whether backticks, double or single quotes should be used (fixable) 244 | "require-jsdoc": "off", // require JSDoc comment 245 | "semi": ["error", "always"], // require or disallow use of semicolons instead of ASI (fixable) 246 | "semi-spacing": "off", // enforce spacing before and after semicolons (fixable) 247 | "sort-imports": "off", // enforce sorting import declarations within module 248 | "sort-vars": "off", // enforce sorting variables within the same declaration block 249 | "space-before-blocks": ["error", "always"], // require or disallow a space before blocks (fixable) 250 | "space-before-function-paren": ["error", "never"], // require or disallow a space before function opening parenthesis (fixable) 251 | "space-in-parens": "off", // require or disallow spaces inside parentheses (fixable) 252 | "space-infix-ops": "off", // require spaces around operators (fixable) 253 | "space-unary-ops": ["error", {"words": true, "nonwords": false}], // require or disallow spaces before/after unary operators (fixable) 254 | "spaced-comment": ["error", "always", {"markers": ["!"]}], // require or disallow a space immediately following the `//` or `/*` in a comment (fixable) 255 | "wrap-regex": "off", // require regex literals to be wrapped in parentheses 256 | 257 | // 258 | // ECMAScript 6 259 | // 260 | // These rules are only relevant to ES6 environments. 261 | // 262 | 263 | "arrow-body-style": "off", // require braces in arrow function body 264 | "arrow-parens": "off", // require parens in arrow function arguments 265 | "arrow-spacing": "off", // require space before/after arrow function's arrow (fixable) 266 | "constructor-super": "error", // ensure calling of `super()` in constructors (recommended) 267 | "generator-star-spacing": "off", // enforce spacing around the `*` in generator functions (fixable) 268 | "no-class-assign": "error", // disallow modifying variables of class declarations (recommended) 269 | "no-confusing-arrow": "off", // disallow arrow functions where they could be confused with comparisons 270 | "no-const-assign": "error", // disallow modifying variables that are declared using `const` (recommended) 271 | "no-dupe-class-members": "error", // disallow duplicate name in class members (recommended) 272 | "no-duplicate-imports": "off", // disallow duplicate module imports 273 | "no-new-symbol": "error", // disallow use of the `new` operator with the `Symbol` object (recommended) 274 | "no-restricted-imports": "off", // restrict usage of specified modules when loaded by `import` declaration 275 | "no-this-before-super": "error", // disallow use of `this`/`super` before calling `super()` in constructors (recommended) 276 | "no-useless-constructor": "off", // disallow unnecessary constructor 277 | "no-var": "off", // require `let` or `const` instead of `var` 278 | "object-shorthand": "off", // require method and property shorthand syntax for object literals 279 | "prefer-arrow-callback": "off", // suggest using arrow functions as callbacks 280 | "prefer-const": "off", // suggest using `const` declaration for variables that are never reassigned after declared 281 | "prefer-reflect": "off", // suggest using Reflect methods where applicable 282 | "prefer-rest-params": "off", // suggest using the rest parameters instead of `arguments` 283 | "prefer-spread": "off", // suggest using the spread operator instead of `.apply()` 284 | "prefer-template": "off", // suggest using template literals instead of strings concatenation 285 | "require-yield": "off", // disallow generator functions that do not have `yield` 286 | "template-curly-spacing": "off", // enforce spacing around embedded expressions of template strings (fixable) 287 | "yield-star-spacing": "off", // enforce spacing around the `*` in `yield*` expressions (fixable) 288 | // 289 | 290 | // 291 | // Removed 292 | // 293 | // These rules existed in a previous version of ESLint but have since been replaced by newer rules. 294 | // 295 | 296 | "generator-star": 0, // enforce the position of the `*` in generator functions (replaced by [generator-star-spacing](generator-star-spacing.md)) 297 | "global-strict": 0, // require or disallow the `"use strict"` pragma in the global scope (replaced by [strict](strict.md)) 298 | "no-arrow-condition": 0, // disallow arrow functions where a condition is expected (replaced by [no-confusing-arrow](no-confusing-arrow.md) and [no-constant-condition](no-constant-condition.md)) 299 | "no-comma-dangle": 0, // disallow trailing commas in object literals (replaced by [comma-dangle](comma-dangle.md)) 300 | "no-empty-class": 0, // disallow the use of empty character classes in regular expressions (replaced by [no-empty-character-class](no-empty-character-class.md)) 301 | "no-empty-label": 0, // disallow use of labels for anything other than loops and switches (replaced by [no-labels](no-labels.md)) 302 | "no-extra-strict": 0, // disallow unnecessary use of `"use strict";` when already in strict mode (replaced by [strict](strict.md)) 303 | "no-reserved-keys": 0, // disallow reserved words being used as object literal keys (replaced by [quote-props](quote-props.md)) 304 | "no-space-before-semi": 0, // disallow space before semicolon (replaced by [semi-spacing](semi-spacing.md)) 305 | "no-wrap-func": 0, // disallow wrapping of non-IIFE statements in parens (replaced by [no-extra-parens](no-extra-parens.md)) 306 | "space-after-function-name": 0, // require a space after function names (replaced by [space-before-function-paren](space-before-function-paren.md)) 307 | "space-after-keywords": 0, // require a space after certain keywords (fixable) (replaced by [keyword-spacing](keyword-spacing.md)) 308 | "space-before-function-parentheses": 0, // require or disallow space before function parentheses (replaced by [space-before-function-paren](space-before-function-paren.md)) 309 | "space-before-keywords": 0, // require a space before certain keywords (fixable) (replaced by [keyword-spacing](keyword-spacing.md)) 310 | "space-in-brackets": 0, // require or disallow spaces inside brackets (replaced by [object-curly-spacing](object-curly-spacing.md) and [array-bracket-spacing](array-bracket-spacing.md)) 311 | "space-return-throw-case": 0, // require a space after `return`, `throw`, and `case` (fixable) (replaced by [keyword-spacing](keyword-spacing.md)) 312 | "space-unary-word-ops": 0, // require or disallow spaces before/after unary operators (replaced by [space-unary-ops](space-unary-ops.md)) 313 | "spaced-line-comment": 0 // require or disallow a space immediately following the `//` in a line comment (replaced by [spaced-comment](spaced-comment.md)) 314 | } 315 | } 316 | --------------------------------------------------------------------------------