From 3d0a778ea94223e2457a57b9de61178f6b153b4e Mon Sep 17 00:00:00 2001 From: Devon Powell Date: Tue, 29 Oct 2024 15:55:35 -0400 Subject: [PATCH] Update eslint config and remove legacy mode set-up (#366) --- .eslintrc.json | 7 --- .github/dependabot.yml | 1 + .github/workflows/ci.yml | 2 +- eslint.config.js | 61 +++++++++++++++++++ package-lock.json | 60 +++++++++--------- package.json | 6 +- test/.eslintrc.json | 18 ------ test/integration/data/tests/.eslintrc.json | 5 -- .../data/tests/playwright/.eslintrc.json | 14 ----- .../data/tests/playwright/reporter-1.test.js | 1 - .../data/tests/playwright/reporter-2.test.js | 1 - .../data/tests/playwright/reporter-3.test.js | 1 - .../data/validation/test-report-playwright.js | 20 +++--- 13 files changed, 107 insertions(+), 90 deletions(-) delete mode 100644 .eslintrc.json create mode 100644 eslint.config.js delete mode 100644 test/.eslintrc.json delete mode 100644 test/integration/data/tests/.eslintrc.json delete mode 100644 test/integration/data/tests/playwright/.eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index fcaf6f1..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "root": true, - "extends": "brightspace/node-config", - "rules": { - "comma-dangle": "error" - } -} diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3868ae5..95b8742 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -19,6 +19,7 @@ updates: patterns: - eslint - eslint-* + - '@eslint/*' chai: dependency-type: development patterns: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a1bb32..0a9bd38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: cache: npm - name: Install dependencies run: npm ci - - name: Lint (JavaScript) + - name: Lint (ESLint) run: npm run lint:eslint licenses: name: Check Licenses diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..1ca483f --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,61 @@ +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import js from '@eslint/js'; +import { FlatCompat } from '@eslint/eslintrc'; +import { includeIgnoreFile } from '@eslint/compat'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const gitignorePath = path.resolve(__dirname, '.gitignore'); +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all +}); + +export default [ + includeIgnoreFile(gitignorePath), + ...compat.extends('brightspace/node-config').map((config) => ({ + ...config, + files: ['**/*.js', '**/*.cjs'], + rules: { + ...config.rules, + 'comma-dangle': 'error' + } + })), + ...compat.extends( + 'brightspace/testing-config', + 'plugin:mocha/recommended' + ).map((config) => ({ + ...config, + files: ['test/**/*.test.js'], + rules: { + ...config.rules, + 'mocha/no-exclusive-tests': 'error', + 'mocha/no-mocha-arrows': 'off' + } + })), + ...compat.extends( + 'brightspace/testing-config', + 'plugin:mocha/recommended' + ).map((config) => ({ + ...config, + files: ['test/integration/data/tests/**/*.test.js'], + rules: { + ...config.rules, + 'mocha/no-mocha-arrows': 'off', + 'mocha/no-skipped-tests': 'off', + 'no-console': 'off' + } + })), + ...compat.extends('plugin:playwright/recommended').map((config) => ({ + ...config, + files: ['test/integration/data/tests/playwright/*.js'], + rules: { + ...config.rules, + 'playwright/expect-expect': 'off', + 'playwright/no-conditional-in-test': 'off', + 'playwright/no-skipped-test': 'off' + } + })) +]; diff --git a/package-lock.json b/package-lock.json index 6c9d46a..7386869 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,9 @@ "playwright-core": "^1.48" }, "devDependencies": { + "@eslint/compat": "^1", + "@eslint/eslintrc": "^3", + "@eslint/js": "^9", "@playwright/test": "^1", "@web/test-runner": "^0.19", "@web/test-runner-playwright": "^0.11", @@ -26,7 +29,6 @@ "c8": "^10", "chai": "^5", "chai-subset": "^1", - "cross-env": "^7", "d2l-license-checker": "^4", "eslint": "^9", "eslint-config-brightspace": "^1", @@ -301,6 +303,16 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/traverse/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "dev": true, + "peer": true, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/types": { "version": "7.26.0", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.0.tgz", @@ -365,6 +377,23 @@ "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } }, + "node_modules/@eslint/compat": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@eslint/compat/-/compat-1.2.2.tgz", + "integrity": "sha512-jhgiIrsw+tRfcBQ4BFl2C3vCrIUw2trCY0cnDvGZpwTtKCEDmZhAtMfrEUP/KpnwM6PrO0T+Ltm+ccW74olG3Q==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "peerDependencies": { + "eslint": "^9.10.0" + }, + "peerDependenciesMeta": { + "eslint": { + "optional": true + } + } + }, "node_modules/@eslint/config-array": { "version": "0.18.0", "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.18.0.tgz", @@ -2921,24 +2950,6 @@ } } }, - "node_modules/cross-env": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", - "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", - "dev": true, - "dependencies": { - "cross-spawn": "^7.0.1" - }, - "bin": { - "cross-env": "src/bin/cross-env.js", - "cross-env-shell": "src/bin/cross-env-shell.js" - }, - "engines": { - "node": ">=10.14", - "npm": ">=6", - "yarn": ">=1" - } - }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -4767,17 +4778,6 @@ "node": ">=10" } }, - "node_modules/globals": { - "version": "11.12.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", - "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", - "dev": true, - "license": "MIT", - "peer": true, - "engines": { - "node": ">=4" - } - }, "node_modules/globalthis": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.4.tgz", diff --git a/package.json b/package.json index 8fa7159..ed66e43 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "scripts": { "license-check": "d2l-license-checker -p", "lint": "npm run lint:eslint", - "lint:eslint": "cross-env ESLINT_USE_FLAT_CONFIG=false eslint . --ext .js,.cjs", + "lint:eslint": "eslint", "fix": "npm run fix:eslint", "fix:eslint": "npm run lint:eslint -- --fix", "test": "run-s lint test:all", @@ -55,6 +55,9 @@ "playwright-core": "^1.48" }, "devDependencies": { + "@eslint/compat": "^1", + "@eslint/eslintrc": "^3", + "@eslint/js": "^9", "@playwright/test": "^1", "@web/test-runner": "^0.19", "@web/test-runner-playwright": "^0.11", @@ -62,7 +65,6 @@ "c8": "^10", "chai": "^5", "chai-subset": "^1", - "cross-env": "^7", "d2l-license-checker": "^4", "eslint": "^9", "eslint-config-brightspace": "^1", diff --git a/test/.eslintrc.json b/test/.eslintrc.json deleted file mode 100644 index 3334896..0000000 --- a/test/.eslintrc.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "plugins": [ - "mocha" - ], - "extends": [ - "brightspace/testing-config", - "plugin:mocha/recommended" - ], - "env": { - "mocha": true - }, - "rules": { - // fails if `.only` is used - "mocha/no-exclusive-tests": "error", - "mocha/no-mocha-arrows": "off", - "no-console": "off" - } -} diff --git a/test/integration/data/tests/.eslintrc.json b/test/integration/data/tests/.eslintrc.json deleted file mode 100644 index b2d80b8..0000000 --- a/test/integration/data/tests/.eslintrc.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "rules": { - "mocha/no-skipped-tests": "off" - } -} diff --git a/test/integration/data/tests/playwright/.eslintrc.json b/test/integration/data/tests/playwright/.eslintrc.json deleted file mode 100644 index 3fa79d8..0000000 --- a/test/integration/data/tests/playwright/.eslintrc.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "root": true, - "extends": [ - "../../../../../.eslintrc.json", - "brightspace/testing-config", - "plugin:playwright/recommended" - ], - "rules": { - "playwright/expect-expect": "off", - "playwright/no-conditional-in-test": "off", - "playwright/no-skipped-test": "off", - "no-console": "off" - } -} diff --git a/test/integration/data/tests/playwright/reporter-1.test.js b/test/integration/data/tests/playwright/reporter-1.test.js index 3e36c90..d72d932 100644 --- a/test/integration/data/tests/playwright/reporter-1.test.js +++ b/test/integration/data/tests/playwright/reporter-1.test.js @@ -13,7 +13,6 @@ test.describe('reporter 1', () => { test.skip('skipped', () => {}); - // eslint-disable-next-line no-empty-pattern test('flaky', async({}, testInfo) => { if (testInfo.retry < 2) { await delay(); diff --git a/test/integration/data/tests/playwright/reporter-2.test.js b/test/integration/data/tests/playwright/reporter-2.test.js index 157ee6b..7d12984 100644 --- a/test/integration/data/tests/playwright/reporter-2.test.js +++ b/test/integration/data/tests/playwright/reporter-2.test.js @@ -13,7 +13,6 @@ test.describe('reporter 2', () => { test.skip('skipped', () => {}); - // eslint-disable-next-line no-empty-pattern test('flaky', async({}, testInfo) => { if (testInfo.retry < 2) { await delay(); diff --git a/test/integration/data/tests/playwright/reporter-3.test.js b/test/integration/data/tests/playwright/reporter-3.test.js index 5541263..83da8b9 100644 --- a/test/integration/data/tests/playwright/reporter-3.test.js +++ b/test/integration/data/tests/playwright/reporter-3.test.js @@ -13,7 +13,6 @@ test.describe('reporter 3', () => { test.skip('skipped', () => {}); - // eslint-disable-next-line no-empty-pattern test('flaky', async({}, testInfo) => { if (testInfo.retry < 2) { await delay(); diff --git a/test/integration/data/validation/test-report-playwright.js b/test/integration/data/validation/test-report-playwright.js index 7d8e950..3946f25 100644 --- a/test/integration/data/validation/test-report-playwright.js +++ b/test/integration/data/validation/test-report-playwright.js @@ -277,7 +277,7 @@ export const testReportV2Partial = { status: 'failed', location: { file: 'test/integration/data/tests/playwright/reporter-1.test.js', - line: 27, + line: 26, column: 2 }, browser: 'chromium', @@ -319,7 +319,7 @@ export const testReportV2Partial = { status: 'failed', location: { file: 'test/integration/data/tests/playwright/reporter-2.test.js', - line: 27, + line: 26, column: 2 }, browser: 'chromium', @@ -333,7 +333,7 @@ export const testReportV2Partial = { status: 'failed', location: { file: 'test/integration/data/tests/playwright/reporter-2.test.js', - line: 27, + line: 26, column: 2 }, browser: 'firefox', @@ -361,7 +361,7 @@ export const testReportV2Partial = { status: 'failed', location: { file: 'test/integration/data/tests/playwright/reporter-1.test.js', - line: 27, + line: 26, column: 2 }, browser: 'webkit', @@ -375,7 +375,7 @@ export const testReportV2Partial = { status: 'passed', location: { file: 'test/integration/data/tests/playwright/reporter-1.test.js', - line: 17, + line: 16, column: 2 }, browser: 'chromium', @@ -389,7 +389,7 @@ export const testReportV2Partial = { status: 'passed', location: { file: 'test/integration/data/tests/playwright/reporter-2.test.js', - line: 17, + line: 16, column: 2 }, browser: 'chromium', @@ -403,7 +403,7 @@ export const testReportV2Partial = { status: 'passed', location: { file: 'test/integration/data/tests/playwright/reporter-1.test.js', - line: 17, + line: 16, column: 2 }, browser: 'webkit', @@ -431,7 +431,7 @@ export const testReportV2Partial = { status: 'passed', location: { file: 'test/integration/data/tests/playwright/reporter-2.test.js', - line: 17, + line: 16, column: 2 }, browser: 'firefox', @@ -459,7 +459,7 @@ export const testReportV2Partial = { status: 'failed', location: { file: 'test/integration/data/tests/playwright/reporter-2.test.js', - line: 27, + line: 26, column: 2 }, browser: 'webkit', @@ -473,7 +473,7 @@ export const testReportV2Partial = { status: 'passed', location: { file: 'test/integration/data/tests/playwright/reporter-2.test.js', - line: 17, + line: 16, column: 2 }, browser: 'webkit',