From 5a8f00c4ba6bab95b7c395bf2b2b8294365986f5 Mon Sep 17 00:00:00 2001 From: Ben Zhang Date: Tue, 7 May 2024 15:56:39 -0700 Subject: [PATCH] convert anything to ts --- .eslintrc | 11 +- jest.config.js | 5 +- lib/configs/{base.js => base.ts} | 4 +- .../{recommended.js => recommended.ts} | 4 +- lib/{index.js => index.ts} | 12 +- package-lock.json | 111 +++++++++++++++++- package.json | 12 +- test/lib/rules/shared.js | 26 ---- tsconfig.json | 1 - 9 files changed, 129 insertions(+), 57 deletions(-) rename lib/configs/{base.js => base.ts} (88%) rename lib/configs/{recommended.js => recommended.ts} (90%) rename lib/{index.js => index.ts} (63%) delete mode 100644 test/lib/rules/shared.js diff --git a/.eslintrc b/.eslintrc index 4ceeea1..18733ff 100644 --- a/.eslintrc +++ b/.eslintrc @@ -2,14 +2,19 @@ "root": true, "extends": [ "eslint:recommended", - "plugin:node/recommended" + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/stylistic" ], "env": { "jest": true, "node": true }, "rules": { - "strict": ["error", "global"] + "strict": ["error", "global"], + "@typescript-eslint/no-extra-non-null-assertion": "off" }, - "ignorePatterns": ["test/**/test.js"] + "parserOptions": { + "ecmaVersion": 2016, + "sourceType": "module" + } } diff --git a/jest.config.js b/jest.config.js index 628fa3f..97ad9af 100644 --- a/jest.config.js +++ b/jest.config.js @@ -5,9 +5,7 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ -'use strict'; - -module.exports = { +export default { displayName: 'Unit Tests', setupFilesAfterEnv: ['jest-extended', 'jest-chain'], preset: 'ts-jest', @@ -17,6 +15,7 @@ module.exports = { '!**/test/lib/rules/shared.ts' ], moduleFileExtensions: ['ts', 'js', 'json'], + testResultsProcessor: 'jest-sonar-reporter', testPathIgnorePatterns: ['/node_modules/', '/lib/'], moduleDirectories: ['node_modules'], diff --git a/lib/configs/base.js b/lib/configs/base.ts similarity index 88% rename from lib/configs/base.js rename to lib/configs/base.ts index d93fa9a..0748921 100644 --- a/lib/configs/base.js +++ b/lib/configs/base.ts @@ -5,8 +5,6 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ -'use strict'; - -module.exports = { +export default { plugins: ['@salesforce/lwc-mobile'] }; diff --git a/lib/configs/recommended.js b/lib/configs/recommended.ts similarity index 90% rename from lib/configs/recommended.js rename to lib/configs/recommended.ts index bd5db36..3747f4a 100644 --- a/lib/configs/recommended.js +++ b/lib/configs/recommended.ts @@ -5,9 +5,7 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ -'use strict'; - -module.exports = { +export default { extends: ['./configs/base'], rules: { '@salesforce/lwc-mobile/enforce-foo-bar': 'warn' diff --git a/lib/index.js b/lib/index.ts similarity index 63% rename from lib/index.js rename to lib/index.ts index 30ead2f..933501f 100644 --- a/lib/index.js +++ b/lib/index.ts @@ -5,14 +5,10 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ -'use strict'; - -const base = require('./configs/base'); -const recommended = require('./configs/recommended'); - -const enforceFooBar = require('./rules/enforce-foo-bar'); - -module.exports = { +import base from './configs/base'; +import recommended from './configs/recommended'; +import enforceFooBar from './rules/enforce-foo-bar'; +export default { rules: { 'enforce-foo-bar': enforceFooBar }, diff --git a/package-lock.json b/package-lock.json index 4e6f9e3..901a657 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "eslint-plugin-node": "^11.1.0" }, "devDependencies": { + "@eslint/js": "^9.2.0", "@jest/globals": "^29.7.0", "@typescript-eslint/rule-tester": "^7.8.0", "jest": "^29.7.0", @@ -24,7 +25,9 @@ "jest-junit": "^16.0.0", "jest-sonar-reporter": "^2.0.0", "prettier": "^3.0.2", - "ts-jest": "^29.1.2" + "ts-jest": "^29.1.2", + "typescript": "^5.4.5", + "typescript-eslint": "^7.8.0" }, "engines": { "node": ">=18" @@ -672,11 +675,12 @@ } }, "node_modules/@eslint/js": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", - "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", + "version": "9.2.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.2.0.tgz", + "integrity": "sha512-ESiIudvhoYni+MdsI8oD7skpprZ89qKocwRM2KEvhhBJ9nl5MRh7BXU5GTod7Mdygq+AUl+QzId6iWJKR/wABA==", + "dev": true, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, "node_modules/@humanwhocodes/config-array": { @@ -1313,6 +1317,41 @@ "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==", "dev": true }, + "node_modules/@typescript-eslint/eslint-plugin": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.8.0.tgz", + "integrity": "sha512-gFTT+ezJmkwutUPmB0skOj3GZJtlEGnlssems4AjkVweUPGj7jRwwqg0Hhg7++kPGJqKtTYx+R05Ftww372aIg==", + "dev": true, + "dependencies": { + "@eslint-community/regexpp": "^4.10.0", + "@typescript-eslint/scope-manager": "7.8.0", + "@typescript-eslint/type-utils": "7.8.0", + "@typescript-eslint/utils": "7.8.0", + "@typescript-eslint/visitor-keys": "7.8.0", + "debug": "^4.3.4", + "graphemer": "^1.4.0", + "ignore": "^5.3.1", + "natural-compare": "^1.4.0", + "semver": "^7.6.0", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^7.0.0", + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/@typescript-eslint/parser": { "version": "7.8.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.8.0.tgz", @@ -1380,6 +1419,33 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@typescript-eslint/type-utils": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.8.0.tgz", + "integrity": "sha512-H70R3AefQDQpz9mGv13Uhi121FNMh+WEaRqcXTX09YEDky21km4dV1ZXJIp8QjXc4ZaVkXVdohvWDzbnbHDS+A==", + "dev": true, + "dependencies": { + "@typescript-eslint/typescript-estree": "7.8.0", + "@typescript-eslint/utils": "7.8.0", + "debug": "^4.3.4", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/@typescript-eslint/types": { "version": "7.8.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.8.0.tgz", @@ -2324,6 +2390,14 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/eslint/node_modules/@eslint/js": { + "version": "8.57.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", + "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, "node_modules/eslint/node_modules/espree": { "version": "9.6.1", "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", @@ -4660,7 +4734,6 @@ "version": "5.4.5", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -4669,6 +4742,32 @@ "node": ">=14.17" } }, + "node_modules/typescript-eslint": { + "version": "7.8.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-7.8.0.tgz", + "integrity": "sha512-sheFG+/D8N/L7gC3WT0Q8sB97Nm573Yfr+vZFzl/4nBdYcmviBPtwGSX9TJ7wpVg28ocerKVOt+k2eGmHzcgVA==", + "dev": true, + "dependencies": { + "@typescript-eslint/eslint-plugin": "7.8.0", + "@typescript-eslint/parser": "7.8.0", + "@typescript-eslint/utils": "7.8.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/undici-types": { "version": "5.26.5", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", diff --git a/package.json b/package.json index 0eed90e..f57f5f4 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "engines": { "node": ">=18" }, + "type": "module", "main": "lib/index.js", "directories": { "lib": "lib", @@ -62,13 +63,14 @@ "!**/test/" ], "dependencies": { - "@typescript-eslint/utils": "^7.8.0", "@typescript-eslint/parser": "^7.8.0", - "eslint": "^8.57.0", + "@typescript-eslint/utils": "^7.8.0", "eslint-plugin-eslint-plugin": "^6.1.0", - "eslint-plugin-node": "^11.1.0" + "eslint-plugin-node": "^11.1.0", + "eslint": "^8.57.0" }, "devDependencies": { + "@eslint/js": "^9.2.0", "@jest/globals": "^29.7.0", "@typescript-eslint/rule-tester": "^7.8.0", "jest": "^29.7.0", @@ -77,7 +79,9 @@ "jest-junit": "^16.0.0", "jest-sonar-reporter": "^2.0.0", "prettier": "^3.0.2", - "ts-jest": "^29.1.2" + "ts-jest": "^29.1.2", + "typescript": "^5.4.5", + "typescript-eslint": "^7.8.0" }, "peerDependencies": { "eslint": ">=7" diff --git a/test/lib/rules/shared.js b/test/lib/rules/shared.js deleted file mode 100644 index e1d783c..0000000 --- a/test/lib/rules/shared.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2024, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ - -'use strict'; - -const RULE_TESTER_CONFIG = { - parser: require.resolve('@babel/eslint-parser'), - parserOptions: { - requireConfigFile: false, - sourceType: 'module', - babelOptions: { - parserOpts: { - plugins: [['decorators', { decoratorsBeforeExport: false }]] - } - } - }, - plugins: ['@salesforce/lwc-mobile'] -}; - -module.exports = { - RULE_TESTER_CONFIG -}; diff --git a/tsconfig.json b/tsconfig.json index 5030918..eed4ddb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,6 @@ "composite": true /* Enable constraints that allow a TypeScript project to be used with project references. */, "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, "module": "Node16" /* Specify what module code is generated. */, - "rootDir": "src" /* Specify the root folder within your source files. */, "moduleResolution": "Node16" /* Specify how TypeScript looks up a file from a given module specifier. */, "types": [] /* Specify type package names to be included without being referenced in a source file. */, "outDir": "dist" /* Specify an output folder for all emitted files. */,