From 2529ee6508335ca864dde1d1b741a65b462671cb Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Tue, 14 Apr 2020 12:08:52 +0100 Subject: [PATCH] chore(eslint): add eslint typescript linting (#5635) This commit adds linting for `*.ts` files and loads up the recommended list of TS rules from the ESLint TypeScript plugin. We can adjust the exact rules overtime, but starting with the recommended list seems sensible. --- .eslintignore | 6 ++++++ .eslintrc.js | 34 ++++++++++++++-------------------- package.json | 4 +++- src/DeviceDescriptors.ts | 6 +++--- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/.eslintignore b/.eslintignore index 6e6149f2c22fc..54c6043ef961a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,3 +6,9 @@ node6/* node6-test/* experimental/ lib/ +src/externs.d.ts +src/protocol.d.ts +/index.d.ts +# We ignore this file because it uses ES imports which we don't yet use +# in the Puppeteer src, so it trips up the ESLint-TypeScript parser. +utils/doclint/generate_types/test/test.ts diff --git a/.eslintrc.js b/.eslintrc.js index 49c970c4b6b7f..a0bf98660eb0e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,34 +1,18 @@ module.exports = { "root": true, - "env": { "node": true, "es6": true }, - "parserOptions": { - "ecmaVersion": 9 - }, + "parser": "@typescript-eslint/parser", "plugins": [ - "mocha" + "mocha", + "@typescript-eslint" ], - /** - * ESLint rules - * - * All available rules: http://eslint.org/docs/rules/ - * - * Rules take the following form: - * "rule-name", [severity, { opts }] - * Severity: 2 == error, 1 == warning, 0 == off. - */ "rules": { - /** - * Enforced rules - */ - - // syntax preferences "quotes": [2, "single", { "avoidEscape": true, @@ -115,5 +99,15 @@ module.exports = { // ensure we don't have any it.only or describe.only in prod "mocha/no-exclusive-tests": "error" - } + }, + "overrides": [ + { + // apply TypeScript linting to the TS files in src/ + "files": ["src/*.ts"], + "extends": [ + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + ] + } + ] }; diff --git a/package.json b/package.json index 7048a6156a464..aaf363351b24d 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "prepublishOnly": "npm run tsc", "dev-install": "npm run tsc && node install.js", "install": "node install.js", - "lint": "([ \"$CI\" = true ] && eslint --quiet -f codeframe . || eslint .) && npm run tsc && npm run doc", + "lint": "([ \"$CI\" = true ] && eslint --ext js --ext ts --quiet -f codeframe . || eslint --ext js --ext ts .) && npm run tsc && npm run doc", "doc": "node utils/doclint/cli.js", "tsc": "tsc --version && tsc -p . && cp src/protocol.d.ts lib/ && cp src/externs.d.ts lib/", "apply-next-version": "node utils/apply_next_version.js", @@ -53,6 +53,8 @@ "@types/rimraf": "^2.0.2", "@types/tar-fs": "^1.16.2", "@types/ws": "^6.0.1", + "@typescript-eslint/eslint-plugin": "^2.28.0", + "@typescript-eslint/parser": "^2.28.0", "commonmark": "^0.28.1", "cross-env": "^5.0.5", "eslint": "^6.8.0", diff --git a/src/DeviceDescriptors.ts b/src/DeviceDescriptors.ts index 945e5cadf7f47..2db6452de57e3 100644 --- a/src/DeviceDescriptors.ts +++ b/src/DeviceDescriptors.ts @@ -25,7 +25,7 @@ interface Device { hasTouch: boolean; isLandscape: boolean; }; -}; +} const devices: Device[] = [ { @@ -888,8 +888,8 @@ type DevicesMap = { const devicesMap: DevicesMap = {}; -for (const device of devices) { +for (const device of devices) devicesMap[device.name] = device; -} + export = devicesMap;