diff --git a/package.json b/package.json index e1494e00ed..bedaff562e 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ }, "description": "Liferay's Frontend Infrastructure Team monorepo", "devDependencies": { - "@typescript-eslint/parser": "4.2.0", + "@typescript-eslint/parser": "4.3.0", "babel-eslint": "10.1.0", "eslint": "7.9.0", "jest": "26.4.2", @@ -19,10 +19,10 @@ "repository": "https://github.com/liferay/liferay-frontend-projects", "scripts": { "ci": "yarn format:check && yarn lint && yarn test", - "format": "prettier --write \"**/*.{js,json,md,yml}\" \"**/.*.{js,yml}\"", - "format:check": "prettier --list-different \"**/*.{js,json,md,yml}\" \"**/.*.{js,yml}\"", - "lint": "eslint \"**/*.js\" \"**/.*.js\"", - "lint:fix": "eslint --fix \"**/*.js\" \"**/.*.js\"", + "format": "prettier --write \"**/*.{js,json,md,ts,yml}\" \"**/.*.{js,ts,yml}\"", + "format:check": "prettier --list-different \"**/*.{js,json,md,ts,yml}\" \"**/.*.{js,ts,yml}\"", + "lint": "eslint \"**/*.{js,ts}\" \"**/.*.{js,ts}\"", + "lint:fix": "eslint --fix \"**/*.{js,ts}\" \"**/.*.{js,ts}\"", "test": "jest" }, "version": "0.0.1", diff --git a/projects/eslint-config/fixtures/sample.ts b/projects/eslint-config/fixtures/sample.ts new file mode 100644 index 0000000000..07025e8958 --- /dev/null +++ b/projects/eslint-config/fixtures/sample.ts @@ -0,0 +1,10 @@ +/** + * SPDX-FileCopyrightText: © 2020 Liferay, Inc. + * SPDX-License-Identifier: MIT + */ + +/** + * This file exists to show that we can format and lint TypeScript files. + */ + +const x = 1; // eslint-disable-line @typescript-eslint/no-unused-vars diff --git a/projects/eslint-config/index.js b/projects/eslint-config/index.js index a8822006a3..baa7066f4f 100644 --- a/projects/eslint-config/index.js +++ b/projects/eslint-config/index.js @@ -12,12 +12,43 @@ const config = { es6: true, }, extends: ['eslint:recommended', require.resolve('eslint-config-prettier')], + overrides: [ + { + files: ['*.{ts,tsx}'], + parser: '@typescript-eslint/parser', + rules: { + '@typescript-eslint/no-unused-vars': [ + 'error', + { + argsIgnorePattern: '^_|^this$', + varsIgnorePattern: '^_', + }, + ], + + // These rules can be turned off because the corresponding + // errors are caught by the TypeScript compiler itself. + + 'no-redeclare': 'off', + 'no-undef': 'off', + 'no-unused-expressions': 'off', + 'no-unused-vars': 'off', + }, + }, + { + files: ['*.d.ts'], + rules: { + '@typescript-eslint/no-unused-vars': 'off', + }, + }, + ], + parser: 'babel-eslint', parserOptions: { ecmaVersion: 2018, sourceType: 'module', }, plugins: [ local('@liferay/liferay'), + '@typescript-eslint/eslint-plugin', 'no-for-of-loops', 'no-only-tests', 'notice', diff --git a/projects/eslint-config/metal.js b/projects/eslint-config/metal.js index 0f34b26823..a14bf30bf3 100644 --- a/projects/eslint-config/metal.js +++ b/projects/eslint-config/metal.js @@ -7,11 +7,6 @@ const config = { extends: [require.resolve('./react')], - parserOptions: { - ecmaFeatures: { - jsx: true, - }, - }, plugins: ['react'], rules: { /** diff --git a/projects/eslint-config/package.json b/projects/eslint-config/package.json index 39411450a6..7e8d70521b 100644 --- a/projects/eslint-config/package.json +++ b/projects/eslint-config/package.json @@ -1,6 +1,8 @@ { "author": "Liferay Frontend Infrastructure Team ", "dependencies": { + "@typescript-eslint/eslint-plugin": "4.3.0", + "@typescript-eslint/parser": "4.3.0", "eslint-config-prettier": "^6.5.0", "eslint-plugin-no-for-of-loops": "^1.0.0", "eslint-plugin-no-only-tests": "^2.1.0", diff --git a/projects/eslint-config/portal.js b/projects/eslint-config/portal.js index 1ac0a2a299..03d7b64d46 100644 --- a/projects/eslint-config/portal.js +++ b/projects/eslint-config/portal.js @@ -9,11 +9,6 @@ const local = require('./utils/local'); const config = { extends: [require.resolve('./react')], - parserOptions: { - ecmaFeatures: { - jsx: true, - }, - }, plugins: [local('@liferay/portal')], rules: { '@liferay/portal/deprecation': 'error', diff --git a/projects/npm-tools/packages/npm-scripts/src/config/eslint.config.js b/projects/npm-tools/packages/npm-scripts/src/config/eslint.config.js index 69490bc4ea..0941e28764 100644 --- a/projects/npm-tools/packages/npm-scripts/src/config/eslint.config.js +++ b/projects/npm-tools/packages/npm-scripts/src/config/eslint.config.js @@ -42,10 +42,9 @@ module.exports = { jest: true, node: true, }, - files: ['**/test/**/*.js'], + files: ['**/test/**/*.{js,ts}'], }, ], - parser: 'babel-eslint', parserOptions: { ecmaFeatures: { jsx: true, diff --git a/projects/npm-tools/packages/npm-scripts/src/presets/standard/index.js b/projects/npm-tools/packages/npm-scripts/src/presets/standard/index.js index 883e06f864..7bc1508f60 100644 --- a/projects/npm-tools/packages/npm-scripts/src/presets/standard/index.js +++ b/projects/npm-tools/packages/npm-scripts/src/presets/standard/index.js @@ -8,8 +8,8 @@ const liferay = require('./dependencies/liferay'); const metal = require('./dependencies/metal'); const CHECK_AND_FIX_GLOBS = [ - '/*.{js,json}', - '/{src,test}/**/*.{js,scss}', + '/*.{js,json,ts}', + '/{src,test}/**/*.{js,scss,ts,tsx}', '/src/**/*.{jsp,jspf}', ]; diff --git a/projects/npm-tools/packages/npm-scripts/src/scripts/format.js b/projects/npm-tools/packages/npm-scripts/src/scripts/format.js index f0cf78b95e..8f263bf39b 100644 --- a/projects/npm-tools/packages/npm-scripts/src/scripts/format.js +++ b/projects/npm-tools/packages/npm-scripts/src/scripts/format.js @@ -20,7 +20,7 @@ const DEFAULT_OPTIONS = { /** * File extensions that we want Prettier to process. */ -const EXTENSIONS = ['.js', '.json', '.jsp', '.jspf', '.scss']; +const EXTENSIONS = ['.js', '.json', '.jsp', '.jspf', '.scss', '.ts', '.tsx']; const IGNORE_FILE = '.prettierignore'; diff --git a/yarn.lock b/yarn.lock index afb816f743..bcea120fda 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2594,7 +2594,7 @@ dependencies: "@types/istanbul-lib-report" "*" -"@types/json-schema@^7.0.5": +"@types/json-schema@^7.0.3", "@types/json-schema@^7.0.5": version "7.0.6" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0" integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw== @@ -2787,36 +2787,61 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/parser@4.2.0": - version "4.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.2.0.tgz#1879ef400abd73d972e20f14c3522e5b343d1d1b" - integrity sha512-54jJ6MwkOtowpE48C0QJF9iTz2/NZxfKVJzv1ha5imigzHbNSLN9yvbxFFH1KdlRPQrlR8qxqyOvLHHxd397VA== +"@typescript-eslint/eslint-plugin@4.3.0": + version "4.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.3.0.tgz#1a23d904bf8ea248d09dc3761af530d90f39c8fa" + integrity sha512-RqEcaHuEKnn3oPFislZ6TNzsBLqpZjN93G69SS+laav/I8w/iGMuMq97P0D2/2/kW4SCebHggqhbcCfbDaaX+g== dependencies: - "@typescript-eslint/scope-manager" "4.2.0" - "@typescript-eslint/types" "4.2.0" - "@typescript-eslint/typescript-estree" "4.2.0" + "@typescript-eslint/experimental-utils" "4.3.0" + "@typescript-eslint/scope-manager" "4.3.0" debug "^4.1.1" + functional-red-black-tree "^1.0.1" + regexpp "^3.0.0" + semver "^7.3.2" + tsutils "^3.17.1" -"@typescript-eslint/scope-manager@4.2.0": - version "4.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.2.0.tgz#d10e6854a65e175b22a28265d372a97c8cce4bfc" - integrity sha512-Tb402cxxObSxWIVT+PnBp5ruT2V/36yj6gG4C9AjkgRlZpxrLAzWDk3neen6ToMBGeGdxtnfFLoJRUecGz9mYQ== +"@typescript-eslint/experimental-utils@4.3.0": + version "4.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.3.0.tgz#3f3c6c508e01b8050d51b016e7f7da0e3aefcb87" + integrity sha512-cmmIK8shn3mxmhpKfzMMywqiEheyfXLV/+yPDnOTvQX/ztngx7Lg/OD26J8gTZfkLKUmaEBxO2jYP3keV7h2OQ== dependencies: - "@typescript-eslint/types" "4.2.0" - "@typescript-eslint/visitor-keys" "4.2.0" + "@types/json-schema" "^7.0.3" + "@typescript-eslint/scope-manager" "4.3.0" + "@typescript-eslint/types" "4.3.0" + "@typescript-eslint/typescript-estree" "4.3.0" + eslint-scope "^5.0.0" + eslint-utils "^2.0.0" -"@typescript-eslint/types@4.2.0": - version "4.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.2.0.tgz#6f6b094329e72040f173123832397c7c0b910fc8" - integrity sha512-xkv5nIsxfI/Di9eVwN+G9reWl7Me9R5jpzmZUch58uQ7g0/hHVuGUbbn4NcxcM5y/R4wuJIIEPKPDb5l4Fdmwg== +"@typescript-eslint/parser@4.3.0": + version "4.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.3.0.tgz#684fc0be6551a2bfcb253991eec3c786a8c063a3" + integrity sha512-JyfRnd72qRuUwItDZ00JNowsSlpQGeKfl9jxwO0FHK1qQ7FbYdoy5S7P+5wh1ISkT2QyAvr2pc9dAemDxzt75g== + dependencies: + "@typescript-eslint/scope-manager" "4.3.0" + "@typescript-eslint/types" "4.3.0" + "@typescript-eslint/typescript-estree" "4.3.0" + debug "^4.1.1" -"@typescript-eslint/typescript-estree@4.2.0": - version "4.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.2.0.tgz#9d746240991c305bf225ad5e96cbf57e7fea0551" - integrity sha512-iWDLCB7z4MGkLipduF6EOotdHNtgxuNKnYD54nMS/oitFnsk4S3S/TE/UYXQTra550lHtlv9eGmp+dvN9pUDtA== +"@typescript-eslint/scope-manager@4.3.0": + version "4.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.3.0.tgz#c743227e087545968080d2362cfb1273842cb6a7" + integrity sha512-cTeyP5SCNE8QBRfc+Lgh4Xpzje46kNUhXYfc3pQWmJif92sjrFuHT9hH4rtOkDTo/si9Klw53yIr+djqGZS1ig== + dependencies: + "@typescript-eslint/types" "4.3.0" + "@typescript-eslint/visitor-keys" "4.3.0" + +"@typescript-eslint/types@4.3.0": + version "4.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.3.0.tgz#1f0b2d5e140543e2614f06d48fb3ae95193c6ddf" + integrity sha512-Cx9TpRvlRjOppGsU6Y6KcJnUDOelja2NNCX6AZwtVHRzaJkdytJWMuYiqi8mS35MRNA3cJSwDzXePfmhU6TANw== + +"@typescript-eslint/typescript-estree@4.3.0": + version "4.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.3.0.tgz#0edc1068e6b2e4c7fdc54d61e329fce76241cee8" + integrity sha512-ZAI7xjkl+oFdLV/COEz2tAbQbR3XfgqHEGy0rlUXzfGQic6EBCR4s2+WS3cmTPG69aaZckEucBoTxW9PhzHxxw== dependencies: - "@typescript-eslint/types" "4.2.0" - "@typescript-eslint/visitor-keys" "4.2.0" + "@typescript-eslint/types" "4.3.0" + "@typescript-eslint/visitor-keys" "4.3.0" debug "^4.1.1" globby "^11.0.1" is-glob "^4.0.1" @@ -2824,12 +2849,12 @@ semver "^7.3.2" tsutils "^3.17.1" -"@typescript-eslint/visitor-keys@4.2.0": - version "4.2.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.2.0.tgz#ae13838e3a260b63ae51021ecaf1d0cdea8dbba5" - integrity sha512-WIf4BNOlFOH2W+YqGWa6YKLcK/EB3gEj2apCrqLw6mme1RzBy0jtJ9ewJgnrZDB640zfnv8L+/gwGH5sYp/rGw== +"@typescript-eslint/visitor-keys@4.3.0": + version "4.3.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.3.0.tgz#0e5ab0a09552903edeae205982e8521e17635ae0" + integrity sha512-xZxkuR7XLM6RhvLkgv9yYlTcBHnTULzfnw4i6+z2TGBLy9yljAypQaZl9c3zFvy7PNI7fYWyvKYtohyF8au3cw== dependencies: - "@typescript-eslint/types" "4.2.0" + "@typescript-eslint/types" "4.3.0" eslint-visitor-keys "^2.0.0" "@webassemblyjs/ast@1.9.0": @@ -6566,7 +6591,7 @@ eslint-utils@^1.4.3: dependencies: eslint-visitor-keys "^1.1.0" -eslint-utils@^2.1.0: +eslint-utils@^2.0.0, eslint-utils@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-2.1.0.tgz#d2de5e03424e707dc10c74068ddedae708741b27" integrity sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg== @@ -13921,7 +13946,7 @@ regexpp@^2.0.1: resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f" integrity sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw== -regexpp@^3.1.0: +regexpp@^3.0.0, regexpp@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.1.0.tgz#206d0ad0a5648cffbdb8ae46438f3dc51c9f78e2" integrity sha512-ZOIzd8yVsQQA7j8GCSlPGXwg5PfmA1mrq0JP4nGhh54LaKN3xdai/vHUDu74pKwV8OxseMS65u2NImosQcSD0Q==