From 100b0a6c9afcd875c768fa7f4e654fdd5f607593 Mon Sep 17 00:00:00 2001 From: Akinsola Lawanson <106528085+akinsola-guardian@users.noreply.github.com> Date: Fri, 12 Jan 2024 11:50:34 +0100 Subject: [PATCH] chore: Add @guardian/eslint-config and update eslint (#845) * Installed @guardian/eslint-config * Update .eslintrc.js * Installed @guardian/eslint-config * Update tsconfig.json * Update .eslintrc.js * Recommendations by eslint in monitoring directory * Update .eslintignore * Update .eslintrc.js * Updated files due to eslint * Update .eslintrc.js * Install "@guardian/eslint-config" * Install eslint * Update to playwright-core * Update common-functions.ts * Update package.json * Update package.json * Update yarn.lock * Update common-functions.ts * Update common-functions.ts * Update tsconfig.eslint.json * Updated @guardian/eslint-config-typescript and removed @guardian/eslint-config * Update package.json * Update package.json * Update .eslintrc.js * Updated tsconfig.json * Update tsconfig.json * Update yarn.lock * Update .eslintrc.js * Update .eslintrc.js * Added extends: ['@guardian/eslint-config-typescript'], * Revert back * extending '@guardian/eslint-config-typescript' * Removed lgnore paths * Update .eslintrc.js * Update .eslintrc.js * Create great-oranges-sing.md * Extending base configs * Remove padding * Update common-functions.ts * Delete great-oranges-sing.md --- .eslintrc.js | 15 ++++++++-- cdk/.eslintrc.js | 10 +++++-- cdk/package.json | 2 +- cdk/tsconfig.eslint.json | 2 +- cdk/tsconfig.json | 3 +- monitoring/.eslintrc.js | 10 +++++-- monitoring/localRun.ts | 2 +- monitoring/package.json | 2 +- monitoring/src/check-page/common-functions.ts | 7 +++-- monitoring/src/config.test.ts | 4 +-- monitoring/tsconfig.eslint.json | 2 +- monitoring/tsconfig.json | 2 +- package.json | 3 +- src/aus/api.test.js | 2 +- src/aus/getConsentState.test.js | 4 +-- src/ccpa/api.test.js | 2 +- src/ccpa/getConsentState.test.js | 4 +-- src/disable.test.js | 2 +- src/getConsentFor.test.js | 2 +- src/getFramework.test.js | 2 +- src/index.test.js | 12 ++++---- src/onConsentChange.test.js | 4 +-- src/sourcepoint.test.js | 4 +-- src/tcfv2/api.test.js | 2 +- src/tcfv2/getConsentState.test.js | 4 +-- src/vendors.test.js | 2 +- yarn.lock | 28 +++++++++---------- 27 files changed, 78 insertions(+), 60 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 5c332d89d..2476ef804 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -4,17 +4,26 @@ module.exports = { jest: true, browser: true, }, - extends: ['@guardian/eslint-config-typescript'], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + '@guardian/eslint-config-typescript', + ], globals: { __PACKAGE_VERSION__: 'readonly' }, ignorePatterns: ['dist', 'coverage', 'cdk', 'monitoring', '*.ts', '*.*.ts'], rules: { // a lot of the 3rd party code uses these 'no-underscore-dangle': 0, }, - + parser: '@typescript-eslint/parser', + parserOptions: { + ecmaVersion: 6, + project: 'tsconfig.json', + sourceType: 'module', + }, overrides: [ { - // tests and config files sometimes do unorthodox things, and that's ok files: ['**/*.test.*', '*.config.js'], rules: { '@typescript-eslint/no-unsafe-return': 0, diff --git a/cdk/.eslintrc.js b/cdk/.eslintrc.js index 0f6a54c2a..aa2faf318 100644 --- a/cdk/.eslintrc.js +++ b/cdk/.eslintrc.js @@ -4,17 +4,21 @@ module.exports = { node: true, jest: true, }, - extends: ['@guardian/eslint-config-typescript'], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + '@guardian/eslint-config-typescript', + ], parserOptions: { ecmaVersion: 2020, tsconfigRootDir: __dirname, sourceType: 'module', project: ['./tsconfig.eslint.json'], }, - plugins: ['@typescript-eslint'], rules: { '@typescript-eslint/no-inferrable-types': 0, 'import/no-namespace': 2, }, - ignorePatterns: ['**/*.js', 'node_modules'], + ignorePatterns: ['node_modules'], }; diff --git a/cdk/package.json b/cdk/package.json index 683158f7e..823894389 100644 --- a/cdk/package.json +++ b/cdk/package.json @@ -19,7 +19,7 @@ "devDependencies": { "@guardian/eslint-config-typescript": "^7.0.0", "@guardian/prettier": "^5.0.0", - "@guardian/tsconfig": "^0.2.0", + "@guardian/tsconfig": "^0.2.0", "@types/jest": "^29.5.5", "@types/node": "20.8.2", "aws-cdk": "2.95.1", diff --git a/cdk/tsconfig.eslint.json b/cdk/tsconfig.eslint.json index d7ea9c098..db6a3ee2b 100644 --- a/cdk/tsconfig.eslint.json +++ b/cdk/tsconfig.eslint.json @@ -1,5 +1,5 @@ { "extends": "./tsconfig.json", - "include": ["lib/**/*", "bin/**/*"], + "include": ["lib/**/*", "bin/**/*", ".eslintrc.js"], "exclude": ["node_modules"] } diff --git a/cdk/tsconfig.json b/cdk/tsconfig.json index 375da6f7f..7c5806c45 100644 --- a/cdk/tsconfig.json +++ b/cdk/tsconfig.json @@ -30,6 +30,7 @@ "node_modules", "cdk.out", "lib/**/*.test.ts", - "lib/**/__snapshots__/**" + "lib/**/__snapshots__/**", + "**/*.d.ts" ] } diff --git a/monitoring/.eslintrc.js b/monitoring/.eslintrc.js index 0f6a54c2a..568ac4af1 100644 --- a/monitoring/.eslintrc.js +++ b/monitoring/.eslintrc.js @@ -4,17 +4,21 @@ module.exports = { node: true, jest: true, }, - extends: ['@guardian/eslint-config-typescript'], + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + '@guardian/eslint-config-typescript', + ], parserOptions: { ecmaVersion: 2020, tsconfigRootDir: __dirname, sourceType: 'module', project: ['./tsconfig.eslint.json'], }, - plugins: ['@typescript-eslint'], rules: { '@typescript-eslint/no-inferrable-types': 0, 'import/no-namespace': 2, }, - ignorePatterns: ['**/*.js', 'node_modules'], + ignorePatterns: ['node_modules', 'dist'], }; diff --git a/monitoring/localRun.ts b/monitoring/localRun.ts index 151c190ae..dec929b7b 100644 --- a/monitoring/localRun.ts +++ b/monitoring/localRun.ts @@ -14,7 +14,7 @@ type LocalRunCliArguments = { class NoArgumentsError extends Error { constructor( - message: string = 'Arguments provided are missing or incorrect', + message = 'Arguments provided are missing or incorrect', ) { super(message); this.name = 'NoArgumentsError'; diff --git a/monitoring/package.json b/monitoring/package.json index 1dd57bb8b..c26b1dfa9 100644 --- a/monitoring/package.json +++ b/monitoring/package.json @@ -47,4 +47,4 @@ "overrides": { "clone-deep": "4.0.1" } -} +} \ No newline at end of file diff --git a/monitoring/src/check-page/common-functions.ts b/monitoring/src/check-page/common-functions.ts index 6726e0fc7..bb7c71d44 100644 --- a/monitoring/src/check-page/common-functions.ts +++ b/monitoring/src/check-page/common-functions.ts @@ -1,5 +1,6 @@ import type { - PutMetricDataCommandInput} from '@aws-sdk/client-cloudwatch'; + PutMetricDataCommandInput +} from '@aws-sdk/client-cloudwatch'; import { CloudWatchClient, PutMetricDataCommand @@ -365,7 +366,7 @@ export const sendMetricData = async ( log_info(`config.platform.toUpperCase() ${config.platform.toUpperCase()})`); const region = config.region; const client = new CloudWatchClient({ region: region }); - const params: PutMetricDataCommandInput = { + const params = { MetricData: [ { MetricName: 'CmpLoadingTime', @@ -399,7 +400,7 @@ export const sendMetricData = async ( }, ], Namespace: 'Application', - }; + } satisfies PutMetricDataCommandInput; const command = new PutMetricDataCommand(params); diff --git a/monitoring/src/config.test.ts b/monitoring/src/config.test.ts index b5b700199..e4cb97582 100644 --- a/monitoring/src/config.test.ts +++ b/monitoring/src/config.test.ts @@ -24,7 +24,7 @@ describe('ConfigWrapper', () => { describe('generateConfig', () => { let awsRegion: AwsRegionOpt = AWS_REGIONS.US_WEST_1; let jurisdiction: JurisdictionOpt = JURISDICTIONS.CCPA; - const stage: string = 'code'; + const stage = 'code'; it('should assign jurisdiction if there is an awsRegion and no jurisdiction ', () => { jurisdiction = undefined; awsRegion = AWS_REGIONS.US_WEST_1; @@ -88,7 +88,7 @@ describe('ConfigWrapper', () => { describe('run', () => { const awsRegion: AwsRegionOpt = AWS_REGIONS.US_WEST_1; const jurisdiction: JurisdictionOpt = JURISDICTIONS.CCPA; - const stage: string = 'code'; + const stage = 'code'; it('should call config.checkFunction if config is defined', async () => { const configWrapper = new ConfigWrapper( diff --git a/monitoring/tsconfig.eslint.json b/monitoring/tsconfig.eslint.json index 40fe196c6..ff2e29474 100644 --- a/monitoring/tsconfig.eslint.json +++ b/monitoring/tsconfig.eslint.json @@ -1,5 +1,5 @@ { "extends": "./tsconfig.json", - "include": ["src/**/*", "*.ts", "node_modules/puppeteer-core/**/*"], + "include": ["src/**/*", "*.ts", ".eslintrc.js"], "exclude": ["node_modules"] } diff --git a/monitoring/tsconfig.json b/monitoring/tsconfig.json index 489c2e81e..c0be86f8d 100644 --- a/monitoring/tsconfig.json +++ b/monitoring/tsconfig.json @@ -1,6 +1,6 @@ { "extends": "@guardian/tsconfig", - "include": ["./*.ts"], + "include": ["./**/*.ts"], "compilerOptions": { "moduleResolution": "node", "module": "commonjs", diff --git a/package.json b/package.json index f60372fc8..da1f0b08a 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,7 @@ "@babel/preset-typescript": "^7.23.2", "@babel/runtime": "^7.23.2", "@changesets/cli": "^2.26.2", - "@guardian/eslint-config": "^4.0.0", - "@guardian/eslint-config-typescript": "^6.0.0", + "@guardian/eslint-config-typescript": "^7.0.0", "@guardian/libs": "15.0.0", "@guardian/prettier": "^4.0.0", "@guardian/tsconfig": "^0.2.0", diff --git a/src/aus/api.test.js b/src/aus/api.test.js index 92b4af0d3..4b181f925 100644 --- a/src/aus/api.test.js +++ b/src/aus/api.test.js @@ -1,4 +1,4 @@ -import { getUSPData } from './api'; +import { getUSPData } from './api.ts'; jest.mock('../sourcepoint', () => ({ sourcepointLibraryLoaded: Promise.resolve(), diff --git a/src/aus/getConsentState.test.js b/src/aus/getConsentState.test.js index b7fc498d4..8af845938 100644 --- a/src/aus/getConsentState.test.js +++ b/src/aus/getConsentState.test.js @@ -1,6 +1,6 @@ import ausData from './__fixtures__/api.getUSPData.json'; -import { getUSPData } from './api'; -import { getConsentState } from './getConsentState'; +import { getUSPData } from './api.ts'; +import { getConsentState } from './getConsentState.ts'; jest.mock('./api'); getUSPData.mockResolvedValue(ausData); diff --git a/src/ccpa/api.test.js b/src/ccpa/api.test.js index 65fba379d..9af36b2db 100644 --- a/src/ccpa/api.test.js +++ b/src/ccpa/api.test.js @@ -1,4 +1,4 @@ -import { getUSPData } from './api'; +import { getUSPData } from './api.ts'; it('calls the correct IAB api with the correct methods', async () => { expect(getUSPData()).rejects.toThrow(); diff --git a/src/ccpa/getConsentState.test.js b/src/ccpa/getConsentState.test.js index e1778ed9c..675704ea4 100644 --- a/src/ccpa/getConsentState.test.js +++ b/src/ccpa/getConsentState.test.js @@ -1,6 +1,6 @@ import uspData from './__fixtures__/api.getUSPData.json'; -import { getUSPData } from './api'; -import { getConsentState } from './getConsentState'; +import { getUSPData } from './api.ts'; +import { getConsentState } from './getConsentState.ts'; jest.mock('./api'); getUSPData.mockResolvedValue(uspData); diff --git a/src/disable.test.js b/src/disable.test.js index dfb0dd202..c292739a4 100644 --- a/src/disable.test.js +++ b/src/disable.test.js @@ -1,4 +1,4 @@ -import { disable, enable, isDisabled } from './disable'; +import { disable, enable, isDisabled } from './disable.ts'; describe('Disabling consent management', () => { it('should be enabled by default', () => { diff --git a/src/getConsentFor.test.js b/src/getConsentFor.test.js index b0e2a2440..daf7b64dc 100644 --- a/src/getConsentFor.test.js +++ b/src/getConsentFor.test.js @@ -1,6 +1,6 @@ // cSpell:ignore doesnotexist -import { getConsentFor } from './getConsentFor'; +import { getConsentFor } from './getConsentFor.ts'; const vendorOne = 'd3b07384d113edec49eaa623'; const vendorAlt = 'c157a79031e1c40f85931829'; diff --git a/src/getFramework.test.js b/src/getFramework.test.js index c00d5cc64..b7f82af01 100644 --- a/src/getFramework.test.js +++ b/src/getFramework.test.js @@ -1,4 +1,4 @@ -import { getFramework } from './getFramework'; +import { getFramework } from './getFramework.ts'; /* cSpell:disable */ const countries = { diff --git a/src/index.test.js b/src/index.test.js index 66397e24d..3f52e5914 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -1,8 +1,8 @@ import waitForExpect from 'wait-for-expect'; -import { CMP as actualCMP } from './cmp'; -import { disable, enable } from './disable'; -import { getCurrentFramework } from './getCurrentFramework'; -import { cmp } from '.'; +import { CMP as actualCMP } from './cmp.ts'; +import { disable, enable } from './disable.ts'; +import { getCurrentFramework } from './getCurrentFramework.ts'; +import { cmp } from './index.ts'; const CMP = { init: jest.spyOn(actualCMP, 'init'), @@ -102,12 +102,12 @@ describe('hotfix cmp.init', () => { }; jest.resetModules(); - import('.').then((module) => { + import('./index.ts').then((module) => { expect(module.cmp).toEqual(mockCmp); delete window.guCmpHotFix; jest.resetModules(); - import('.'); + import('./index.ts'); }); }); }); diff --git a/src/onConsentChange.test.js b/src/onConsentChange.test.js index db083af53..c8fda7a99 100644 --- a/src/onConsentChange.test.js +++ b/src/onConsentChange.test.js @@ -1,8 +1,8 @@ import waitForExpect from 'wait-for-expect'; import ausData from './aus/__fixtures__/api.getUSPData.json'; import uspData from './ccpa/__fixtures__/api.getUSPData.json'; -import { setCurrentFramework } from './getCurrentFramework'; -import { _, invokeCallbacks, onConsentChange } from './onConsentChange'; +import { setCurrentFramework } from './getCurrentFramework.ts'; +import { _, invokeCallbacks, onConsentChange } from './onConsentChange.ts'; import customVendorConsents from './tcfv2/__fixtures__/api.getCustomVendorConsents.json'; import tcData from './tcfv2/__fixtures__/api.getTCData.json'; diff --git a/src/sourcepoint.test.js b/src/sourcepoint.test.js index 870bd1d85..25ebdce3e 100644 --- a/src/sourcepoint.test.js +++ b/src/sourcepoint.test.js @@ -1,7 +1,7 @@ import http from 'http'; import url from 'url'; -import { ACCOUNT_ID, ENDPOINT } from './lib/sourcepointConfig'; -import { init } from './sourcepoint'; +import { ACCOUNT_ID, ENDPOINT } from './lib/sourcepointConfig.ts'; +import { init } from './sourcepoint.ts'; const frameworks = ['tcfv2', 'ccpa', 'aus']; diff --git a/src/tcfv2/api.test.js b/src/tcfv2/api.test.js index 56b5867ff..f449d8fdb 100644 --- a/src/tcfv2/api.test.js +++ b/src/tcfv2/api.test.js @@ -1,4 +1,4 @@ -import { getCustomVendorConsents, getTCData } from './api'; +import { getCustomVendorConsents, getTCData } from './api.ts'; it('calls the correct IAB api with the correct methods', async () => { expect(getTCData()).rejects.toThrow(); diff --git a/src/tcfv2/getConsentState.test.js b/src/tcfv2/getConsentState.test.js index a46025e26..e3bc2929a 100644 --- a/src/tcfv2/getConsentState.test.js +++ b/src/tcfv2/getConsentState.test.js @@ -1,7 +1,7 @@ import customVendorConsents from './__fixtures__/api.getCustomVendorConsents.json'; import tcData from './__fixtures__/api.getTCData.json'; -import { getCustomVendorConsents, getTCData } from './api'; -import { getConsentState } from './getConsentState'; +import { getCustomVendorConsents, getTCData } from './api.ts'; +import { getConsentState } from './getConsentState.ts'; jest.mock('./api'); getTCData.mockReturnValue(Promise.resolve(tcData)); diff --git a/src/vendors.test.js b/src/vendors.test.js index 5022e37cd..6e7602093 100644 --- a/src/vendors.test.js +++ b/src/vendors.test.js @@ -1,5 +1,5 @@ import axios from 'axios'; -import { TCFV2VendorIDs } from './vendors'; +import { TCFV2VendorIDs } from './vendors.ts'; const cmpBaseUrl = 'cdn.privacy-mgmt.com'; const guardianId = '5ec67f5bb8e05c4a1160fda1'; diff --git a/yarn.lock b/yarn.lock index 1abc504a5..86e7e5ed5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1491,23 +1491,23 @@ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.44.0.tgz#961a5903c74139390478bdc808bcde3fc45ab7af" integrity sha512-Ag+9YM4ocKQx9AarydN0KY2j0ErMHNIocPDrVo8zAE44xLTjEtz81OdR68/cydGtk6m6jDb5Za3r2useMzYmSw== -"@guardian/eslint-config-typescript@^6.0.0": - version "6.0.0" - resolved "https://registry.yarnpkg.com/@guardian/eslint-config-typescript/-/eslint-config-typescript-6.0.0.tgz#a2080acca102f7d77e5173dcc9a751209a695ff1" - integrity sha512-L1KpAnxLw9fX5YW0PrMRdirZVkb/IK5s/JBIE61Gx8AxIa3PNTnVS/v6xS/okbBb1nXa30xV2ty0RX6CG78t8A== +"@guardian/eslint-config-typescript@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/@guardian/eslint-config-typescript/-/eslint-config-typescript-7.0.0.tgz#b16fab129fb6e7fe9343143d9bdcbe1867117ab8" + integrity sha512-2XsjhVRmIK0nvjGHDcvTjMd4DNHsSHIkqDRc4cGEAUcKdPgXEtuWyxQeWEdBBvqLo0aNj6PH3ekyWpPsgZKo8g== dependencies: - "@guardian/eslint-config" "4.0.0" + "@guardian/eslint-config" "5.0.0" "@typescript-eslint/eslint-plugin" "5.59.9" "@typescript-eslint/parser" "5.59.9" eslint-import-resolver-typescript "3.5.5" eslint-plugin-import "2.27.5" -"@guardian/eslint-config@4.0.0", "@guardian/eslint-config@^4.0.0": - version "4.0.0" - resolved "https://registry.yarnpkg.com/@guardian/eslint-config/-/eslint-config-4.0.0.tgz#6beb3ae4eec73418ee18a83160d87565a2ae3d0a" - integrity sha512-OAazxlXgYjggVNE7scoSgb1g+CIz/yfhPenEKGSTM5fejeTRZNwfFPDcVl4h4jY5/17aCUxaLxG+Nc0r4V94kQ== +"@guardian/eslint-config@5.0.0": + version "5.0.0" + resolved "https://registry.yarnpkg.com/@guardian/eslint-config/-/eslint-config-5.0.0.tgz#a9652f78f057fa4f35420fea8f8e807737ae15d1" + integrity sha512-llm15aCWBFJQbMg/Douqf+fjvMC9qrcc2AfievoAoiHD/VGQf8ouR4ss2/X1i+2r3gcwYDZlvCOarXeXnIbZ+w== dependencies: - eslint-config-prettier "8.5.0" + eslint-config-prettier "8.8.0" eslint-plugin-eslint-comments "3.2.0" eslint-plugin-import "2.27.5" @@ -4171,10 +4171,10 @@ escodegen@^2.0.0: optionalDependencies: source-map "~0.6.1" -eslint-config-prettier@8.5.0: - version "8.5.0" - resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz#5a81680ec934beca02c7b1a61cf8ca34b66feab1" - integrity sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q== +eslint-config-prettier@8.8.0: + version "8.8.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.8.0.tgz#bfda738d412adc917fd7b038857110efe98c9348" + integrity sha512-wLbQiFre3tdGgpDv67NQKnJuTlcUVYHas3k+DZCc2U2BadthoEY4B7hLPvAxaqdyOGCzuLfii2fqGph10va7oA== eslint-import-resolver-node@^0.3.7: version "0.3.7"