From a6abe8606495dd16108e0b79135199c758ddb941 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Tue, 26 Feb 2019 14:52:42 -0800 Subject: [PATCH] feat(build): add eslint scripts and default configs See https://github.com/typescript-eslint/typescript-eslint --- CODEOWNERS | 1 + docs/site/MONOREPO.md | 1 + greenkeeper.json | 1 + packages/build/bin/run-eslint.js | 49 +++++++ packages/build/config/.eslintignore | 4 + packages/build/config/.eslintrc.js | 3 + packages/build/package-lock.json | 201 ++++++++++++++++++++++++++++ packages/build/package.json | 4 + packages/eslint-config/.npmrc | 1 + packages/eslint-config/LICENSE | 25 ++++ packages/eslint-config/README.md | 48 +++++++ packages/eslint-config/eslintrc.js | 72 ++++++++++ packages/eslint-config/package.json | 27 ++++ 13 files changed, 437 insertions(+) create mode 100755 packages/build/bin/run-eslint.js create mode 100644 packages/build/config/.eslintignore create mode 100644 packages/build/config/.eslintrc.js create mode 100644 packages/eslint-config/.npmrc create mode 100644 packages/eslint-config/LICENSE create mode 100644 packages/eslint-config/README.md create mode 100644 packages/eslint-config/eslintrc.js create mode 100644 packages/eslint-config/package.json diff --git a/CODEOWNERS b/CODEOWNERS index a7ac05214202..c3719e6f698f 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -15,6 +15,7 @@ packages/http-server/* @hacksparrow @bajtos packages/cli/* @raymondfeng @bajtos packages/context/* @bajtos @raymondfeng packages/core/* @bajtos @raymondfeng +packages/eslint-config/* @raymondfeng packages/metadata/* @raymondfeng packages/openapi-spec-builder/* @bajtos @raymondfeng packages/openapi-v3/* @bajtos @jannyHou diff --git a/docs/site/MONOREPO.md b/docs/site/MONOREPO.md index 1ded1dca58ba..daa15801ec23 100644 --- a/docs/site/MONOREPO.md +++ b/docs/site/MONOREPO.md @@ -15,6 +15,7 @@ The [loopback-next](https://github.com/strongloop/loopback-next) repository uses | [context](https://github.com/strongloop/loopback-next/tree/master/packages/context) | @loopback/context | Facilities to manage artifacts and their dependencies in your Node.js applications. The module exposes TypeScript/JavaScript APIs and decorators to register artifacts, declare dependencies, and resolve artifacts by keys. It also serves as an IoC container to support dependency injection. | | [core](https://github.com/strongloop/loopback-next/tree/master/packages/core) | @loopback/core | Define and implement core constructs such as Application and Component | | [docs](https://github.com/strongloop/loopback-next/tree/master/docs) | @loopback/docs | Documentation files rendered at [https://loopback.io](https://loopback.io) | +| [eslint-config](https://github.com/strongloop/loopback-next/tree/master/packages/eslint-config) | @loopback/eslint-config | ESLint configuration for LoopBack projects | | [example-express-composition](https://github.com/strongloop/loopback-next/tree/master/examples/express-composition) | @loopback/example-express-composition | A simple Express application that uses LoopBack 4 REST API | | [example-greeter-extension](https://github.com/strongloop/loopback-next/tree/master/examples/greeter-extension) | @loopback/example-greeter-extension | An example showing how to implement the extension point/extension pattern using LoopBack 4 | | [example-hello-world](https://github.com/strongloop/loopback-next/tree/master/examples/hello-world) | @loopback/example-hello-world | A simple hello-world application using LoopBack 4 | diff --git a/greenkeeper.json b/greenkeeper.json index 217cbb372410..4d90d0017ab1 100644 --- a/greenkeeper.json +++ b/greenkeeper.json @@ -21,6 +21,7 @@ "packages/cli/package.json", "packages/context/package.json", "packages/core/package.json", + "packages/eslint-config/package.json", "packages/http-caching-proxy/package.json", "packages/http-server/package.json", "packages/metadata/package.json", diff --git a/packages/build/bin/run-eslint.js b/packages/build/bin/run-eslint.js new file mode 100755 index 000000000000..e0a0ca904eec --- /dev/null +++ b/packages/build/bin/run-eslint.js @@ -0,0 +1,49 @@ +#!/usr/bin/env node +// Copyright IBM Corp. 2017,2018. All Rights Reserved. +// Node module: @loopback/build +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +/* +======== + +Usage: + node ./bin/run-eslint + +======== +*/ + +'use strict'; + +function run(argv, options) { + const utils = require('./utils'); + + const eslintOpts = argv.slice(2); + + const isConfigSet = utils.isOptionSet(eslintOpts, '-c', '--config'); + const isExtSet = utils.isOptionSet(eslintOpts, '--ext'); + + const eslintConfigFile = isConfigSet + ? null + : utils.getConfigFile('.eslintrc.js', '.eslintrc.json'); + + const eslintIgnoreFile = utils.getConfigFile('.eslintignore'); + + const args = []; + if (eslintConfigFile) { + args.push('-c', eslintConfigFile); + } + if (eslintIgnoreFile) { + args.push('--ignore-path', eslintIgnoreFile); + } + + if (!isExtSet) { + args.push('--ext', '.js,.ts'); + } + args.push(...eslintOpts); + + return utils.runCLI('eslint/bin/eslint', args, options); +} + +module.exports = run; +if (require.main === module) run(process.argv); diff --git a/packages/build/config/.eslintignore b/packages/build/config/.eslintignore new file mode 100644 index 000000000000..dbf8bd7a83d8 --- /dev/null +++ b/packages/build/config/.eslintignore @@ -0,0 +1,4 @@ +node_modules/ +dist/ +coverage/ +api-docs/ diff --git a/packages/build/config/.eslintrc.js b/packages/build/config/.eslintrc.js new file mode 100644 index 000000000000..978b9dcca27f --- /dev/null +++ b/packages/build/config/.eslintrc.js @@ -0,0 +1,3 @@ +module.exports = { + extends: '@loopback/eslint-config', +}; diff --git a/packages/build/package-lock.json b/packages/build/package-lock.json index a2c91dc566e7..e2b2f6f72717 100644 --- a/packages/build/package-lock.json +++ b/packages/build/package-lock.json @@ -185,11 +185,37 @@ "negotiator": "0.6.1" } }, + "acorn": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz", + "integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==" + }, + "acorn-jsx": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.0.1.tgz", + "integrity": "sha512-HJ7CfNHrfJLlNTzIEUTj43LNWGkqpRLxm3YjAlcD0ACydk9XynzYsCBHxut+iqt+1aBXkx9UP/w/ZqMr13XIzg==" + }, + "ajv": { + "version": "6.10.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.0.tgz", + "integrity": "sha512-nffhOpkymDECQyR0mnsUtoCE8RlX38G0rYP+wgLWFyZuUyuuojSSvi/+euOiQBIn63whYwYVIIH1TvE3tu4OEg==", + "requires": { + "fast-deep-equal": "^2.0.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, "ansi-colors": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.3.tgz", "integrity": "sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw==" }, + "ansi-escapes": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", + "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==" + }, "ansi-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", @@ -473,6 +499,14 @@ "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==" }, + "doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "requires": { + "esutils": "^2.0.2" + } + }, "dox": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/dox/-/dox-0.9.0.tgz", @@ -562,11 +596,112 @@ "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, + "eslint": { + "version": "5.15.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.15.1.tgz", + "integrity": "sha512-NTcm6vQ+PTgN3UBsALw5BMhgO6i5EpIjQF/Xb5tIh3sk9QhrFafujUOczGz4J24JBlzWclSB9Vmx8d+9Z6bFCg==", + "requires": { + "@babel/code-frame": "^7.0.0", + "ajv": "^6.9.1", + "chalk": "^2.1.0", + "cross-spawn": "^6.0.5", + "debug": "^4.0.1", + "doctrine": "^3.0.0", + "eslint-scope": "^4.0.2", + "eslint-utils": "^1.3.1", + "eslint-visitor-keys": "^1.0.0", + "espree": "^5.0.1", + "esquery": "^1.0.1", + "esutils": "^2.0.2", + "file-entry-cache": "^5.0.1", + "functional-red-black-tree": "^1.0.1", + "glob": "^7.1.2", + "globals": "^11.7.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "inquirer": "^6.2.2", + "js-yaml": "^3.12.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.3.0", + "lodash": "^4.17.11", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.1", + "natural-compare": "^1.4.0", + "optionator": "^0.8.2", + "path-is-inside": "^1.0.2", + "progress": "^2.0.0", + "regexpp": "^2.0.1", + "semver": "^5.5.1", + "strip-ansi": "^4.0.0", + "strip-json-comments": "^2.0.1", + "table": "^5.2.3", + "text-table": "^0.2.0" + } + }, + "eslint-plugin-mocha": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-5.3.0.tgz", + "integrity": "sha512-3uwlJVLijjEmBeNyH60nzqgA1gacUWLUmcKV8PIGNvj1kwP/CTgAWQHn2ayyJVwziX+KETkr9opNwT1qD/RZ5A==", + "requires": { + "ramda": "^0.26.1" + } + }, + "eslint-scope": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.2.tgz", + "integrity": "sha512-5q1+B/ogmHl8+paxtOKx38Z8LtWkVGuNt3+GQNErqwLl6ViNp/gdJGMCjZNxZ8j/VYjDNZ2Fo+eQc1TAVPIzbg==", + "requires": { + "esrecurse": "^4.1.0", + "estraverse": "^4.1.1" + } + }, + "eslint-utils": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.3.1.tgz", + "integrity": "sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==" + }, + "eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==" + }, + "espree": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-5.0.1.tgz", + "integrity": "sha512-qWAZcWh4XE/RwzLJejfcofscgMc9CamR6Tn1+XRXNzrvUSSbiAjGOI/fggztjIi7y9VLPqnICMIPiGyr8JaZ0A==", + "requires": { + "acorn": "^6.0.7", + "acorn-jsx": "^5.0.0", + "eslint-visitor-keys": "^1.0.0" + } + }, "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" }, + "esquery": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.0.1.tgz", + "integrity": "sha512-SmiyZ5zIWH9VM+SRUReLS5Q8a7GxtRdxEBVZpm98rJM7Sb+A9DVCndXfkeFUd3byderg+EbDkfnevfCwynWaNA==", + "requires": { + "estraverse": "^4.0.0" + } + }, + "esrecurse": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.2.1.tgz", + "integrity": "sha512-64RBB++fIOAXPw3P9cy89qfMlvZEXZkqqJkjqqXIvzP5ezRZjW+lPWjw35UX/3EhUPFYbg5ER4JYgDw4007/DQ==", + "requires": { + "estraverse": "^4.1.0" + } + }, + "estraverse": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.2.0.tgz", + "integrity": "sha1-De4/7TH81GlhjOc0IJn8GvoL2xM=" + }, "esutils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", @@ -748,6 +883,11 @@ "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=" + }, "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -1111,6 +1251,15 @@ "invert-kv": "^2.0.0" } }, + "levn": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", + "integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=", + "requires": { + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2" + } + }, "linkify-it": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.1.0.tgz", @@ -1516,6 +1665,14 @@ "wrappy": "1" } }, + "onetime": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-2.0.1.tgz", + "integrity": "sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ=", + "requires": { + "mimic-fn": "^1.0.0" + } + }, "optimist": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", @@ -1540,6 +1697,11 @@ "mem": "^4.0.0" } }, + "os-tmpdir": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", + "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" + }, "p-defer": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", @@ -1611,6 +1773,11 @@ "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, + "path-is-inside": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/path-is-inside/-/path-is-inside-1.0.2.tgz", + "integrity": "sha1-NlQX3t5EQw0cEa9hAn+s8HS9/FM=" + }, "path-key": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz", @@ -1687,11 +1854,21 @@ "once": "^1.3.1" } }, + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" + }, "qs": { "version": "6.5.2", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" }, + "ramda": { + "version": "0.26.1", + "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.26.1.tgz", + "integrity": "sha512-hLWjpy7EnsDBb0p+Z3B7rPi3GDeRG5ZtiI33kJhTt+ORCd38AbAIjB/9zRIUoeTbE/AVX5ZkU7m6bznsvrf8eQ==" + }, "range-parser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", @@ -1774,6 +1951,22 @@ "glob": "^7.1.3" } }, + "run-async": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz", + "integrity": "sha1-A3GrSuC91yDUFm19/aZP96RFpsA=", + "requires": { + "is-promise": "^2.1.0" + } + }, + "rxjs": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.4.0.tgz", + "integrity": "sha512-Z9Yfa11F6B9Sg/BK9MnqnQ+aQYicPLtilXBp2yUtDt2JRCE0h26d33EnfO3ZxoNxG0T92OUucP3Ct7cpfkdFfw==", + "requires": { + "tslib": "^1.9.0" + } + }, "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", @@ -2096,6 +2289,14 @@ "tslib": "^1.8.1" } }, + "type-check": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", + "integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=", + "requires": { + "prelude-ls": "~1.1.2" + } + }, "type-is": { "version": "1.6.16", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz", diff --git a/packages/build/package.json b/packages/build/package.json index f9a3701cbdcc..148be3d25955 100644 --- a/packages/build/package.json +++ b/packages/build/package.json @@ -14,6 +14,7 @@ "copyright.owner": "IBM Corp.", "license": "MIT", "dependencies": { + "@loopback/eslint-config": "^1.0.0-1", "@loopback/tslint-config": "^2.0.4", "@types/mocha": "^5.0.0", "@types/node": "^10.11.2", @@ -24,6 +25,8 @@ "mocha": "^6.1.4", "nyc": "^14.1.1", "prettier": "^1.17.1", + "eslint": "^5.14.1", + "eslint-plugin-mocha": "^5.3.0", "rimraf": "^2.6.2", "source-map-support": "^0.5.12", "strong-docs": "^4.2.0", @@ -32,6 +35,7 @@ }, "bin": { "lb-tsc": "./bin/compile-package.js", + "lb-eslint": "./bin/run-eslint.js", "lb-tslint": "./bin/run-tslint.js", "lb-prettier": "./bin/run-prettier.js", "lb-mocha": "./bin/run-mocha.js", diff --git a/packages/eslint-config/.npmrc b/packages/eslint-config/.npmrc new file mode 100644 index 000000000000..cafe685a112d --- /dev/null +++ b/packages/eslint-config/.npmrc @@ -0,0 +1 @@ +package-lock=true diff --git a/packages/eslint-config/LICENSE b/packages/eslint-config/LICENSE new file mode 100644 index 000000000000..c943c2a1b71e --- /dev/null +++ b/packages/eslint-config/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) IBM Corp. 2019. All Rights Reserved. +Node module: @loopback/eslint-config +This project is licensed under the MIT License, full text below. + +-------- + +MIT license + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/packages/eslint-config/README.md b/packages/eslint-config/README.md new file mode 100644 index 000000000000..3c15bbe3400f --- /dev/null +++ b/packages/eslint-config/README.md @@ -0,0 +1,48 @@ +# @loopback/eslint-config + +Shared ESLint config to enforce a consistent code style for LoopBack development + +## Installation + +```shell +npm install --save @loopback/eslint-config + +npm install --save-dev \ +eslint \ +@typescript-eslint/eslint-plugin \ +@typescript-eslint/parser \ +eslint-config-prettier \ +eslint-plugin-eslint-plugin \ +eslint-plugin-mocha +``` + +## Basic Use + +Add `.eslintrc.json` file to your project, for example: + +```json +{ + "extends": "@loopback/eslint-config" +} +``` + +**NOTE**: + +Due to +[the limitation of how ESLint plugins are loaded](https://github.com/eslint/rfcs/tree/master/designs/2018-simplified-package-loading), +the [peerDependencies](package.json) of this module should be added to +`devDependencies` of your `package.json`. + +## Contributions + +- [Guidelines](https://github.com/strongloop/loopback-next/blob/master/docs/CONTRIBUTING.md) +- [Join the team](https://github.com/strongloop/loopback-next/issues/110) + +## Contributors + +See +[all contributors](https://github.com/strongloop/loopback-next/graphs/contributors). + +## License + +MIT diff --git a/packages/eslint-config/eslintrc.js b/packages/eslint-config/eslintrc.js new file mode 100644 index 000000000000..bc5f49a2db42 --- /dev/null +++ b/packages/eslint-config/eslintrc.js @@ -0,0 +1,72 @@ +// Copyright IBM Corp. 2019. All Rights Reserved. +// Node module: @loopback/eslint-config +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +/** + * Default ESLint configuration for LoopBack + * + * See https://eslint.org/docs/user-guide/configuring + */ +module.exports = { + root: true, + // Use the typescript-eslint parser + parser: '@typescript-eslint/parser', + // Enable eslint and typescript-eslint + plugins: ['eslint-plugin', '@typescript-eslint', 'mocha'], + env: { + es6: true, + node: true, + mocha: true, + }, + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + /** + * Use `prettier` to override default formatting related rules + * See https://github.com/prettier/eslint-config-prettier + */ + 'prettier', + 'prettier/@typescript-eslint', + ], + rules: { + 'no-mixed-operators': 'off', + 'no-console': 'off', + // 'no-undef': 'off', + 'no-inner-declarations': 'off', + // TypeScript allows method overloading + 'no-dupe-class-members': 'off', + 'no-useless-escape': 'off', + // TypeScript allows the same name for namespace and function + 'no-redeclare': 'off', + + /** + * TypeScript specific rules + * See https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules + */ + '@typescript-eslint/array-type': 'off', + '@typescript-eslint/indent': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/explicit-member-accessibility': 'off', + '@typescript-eslint/no-var-requires': 'off', + '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/no-object-literal-type-assertion': 'off', + '@typescript-eslint/no-parameter-properties': 'off', + '@typescript-eslint/no-angle-bracket-type-assertion': 'off', + '@typescript-eslint/prefer-interface': 'off', + '@typescript-eslint/no-namespace': 'off', + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/ban-types': 'off', + '@typescript-eslint/no-triple-slash-reference': 'off', + '@typescript-eslint/no-empty-interface': 'off', + }, + parserOptions: { + sourceType: 'module', + ecmaFeatures: { + ecmaVersion: 2017, + jsx: false, + }, + }, +}; diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json new file mode 100644 index 000000000000..2c9fed37ed1a --- /dev/null +++ b/packages/eslint-config/package.json @@ -0,0 +1,27 @@ +{ + "name": "@loopback/eslint-config", + "version": "1.0.0-1", + "description": "Shared configuration for ESLint", + "engines": { + "node": ">=8.9" + }, + "main": "eslintrc.js", + "author": "IBM Corp.", + "copyright.owner": "IBM Corp.", + "license": "MIT", + "peerDependencies": { + "@typescript-eslint/eslint-plugin": "^1.4.2", + "@typescript-eslint/parser": "^1.4.2", + "eslint": "^5.14.1", + "eslint-config-prettier": "^4.1.0", + "eslint-plugin-eslint-plugin": "^2.0.1", + "eslint-plugin-mocha": "^5.3.0" + }, + "repository": { + "type": "git", + "url": "https://github.com/strongloop/loopback-next.git" + }, + "publishConfig": { + "access": "public" + } +}