diff --git a/.github/linters/.eslintrc.yml b/.github/linters/.eslintrc.yml deleted file mode 100644 index cac6dc1..0000000 --- a/.github/linters/.eslintrc.yml +++ /dev/null @@ -1,102 +0,0 @@ ---- -env: - browser: true - es6: true - jest: true - node: true - -extends: - - "eslint:recommended" - -globals: - $WPT_ACCESSIBILITY_TREE: readonly - $WPT_BODIES: readonly - $WPT_COOKIES: readonly - $WPT_DNS: readonly - $WPT_REQUESTS: readonly - $WPT_TEST_URL: readonly - httparchive_enable_observations: writable - __REACT_DEVTOOLS_GLOBAL_HOOK__: writable - CSSUnparsedValue: readonly - LaunchParams: readonly - -ignorePatterns: - - "!.*" - - "**/node_modules/.*" - - "/dist/third-parties.js" - -plugins: - - n - - prettier - -rules: - no-inner-declarations: off - -overrides: - # JSON files - - files: - - "*.json" - extends: - - plugin:jsonc/recommended-with-json - parser: jsonc-eslint-parser - parserOptions: - jsonSyntax: JSON - - # JSONC files - - files: - - "*.jsonc" - extends: - - plugin:jsonc/recommended-with-jsonc - parser: jsonc-eslint-parser - parserOptions: - jsonSyntax: JSONC - - # JSON5 files - - files: - - "*.json5" - extends: - - plugin:jsonc/recommended-with-json5 - parser: jsonc-eslint-parser - parserOptions: - jsonSyntax: JSON5 - - # Javascript files - - files: - - "**/*.js" - extends: - - "plugin:react/recommended" - parserOptions: - ecmaVersion: latest - ecmaFeatures: - globalReturn: true - - - files: - - "**/*.mjs" - - "**/*.cjs" - - "**/*.jsx" - extends: - - "plugin:react/recommended" - parserOptions: - sourceType: module - ecmaVersion: latest - ecmaFeatures: - jsx: true - modules: true - - # TypeScript files - - files: - - "**/*.ts" - - "**/*.cts" - - "**/*.mts" - - "**/*.tsx" - extends: - - "plugin:@typescript-eslint/recommended" - - plugin:n/recommended - - plugin:react/recommended - - prettier - parser: "@typescript-eslint/parser" - plugins: - - "@typescript-eslint" - parserOptions: - ecmaVersion: latest - sourceType: module diff --git a/.github/linters/eslint.config.mjs b/.github/linters/eslint.config.mjs new file mode 100644 index 0000000..922ae72 --- /dev/null +++ b/.github/linters/eslint.config.mjs @@ -0,0 +1,98 @@ +import { defineConfig, globalIgnores } from "eslint/config"; +import js from "@eslint/js"; +import globals from "globals"; +import n from "eslint-plugin-n"; +import prettier from "eslint-plugin-prettier"; +import eslintPluginJsonc from "eslint-plugin-jsonc"; + +export default defineConfig([ + globalIgnores(["!**/.*", "**/node_modules/.*", "dist/third-parties.js"]), + + // Base configuration: ESLint recommended, Node plugin, and Prettier integration + { + plugins: { + n, + prettier, + }, + rules: { + ...js.configs.recommended.rules, + "no-inner-declarations": "off", + "no-unused-vars": [ + "error", + { + caughtErrors: "none", + }, + ], + }, + }, + + // JSON files + ...eslintPluginJsonc.configs["recommended-with-json"].map((config) => ({ + ...config, + files: ["**/*.json"], + })), + + // Custom metrics (Browser / WebPageTest context) + { + files: ["dist/**/*.js", "inject-dist/**/*.js"], + languageOptions: { + ecmaVersion: "latest", + sourceType: "script", + parserOptions: { + ecmaFeatures: { + globalReturn: true, + }, + }, + globals: { + ...globals.browser, + $WPT_ACCESSIBILITY_TREE: "readonly", + $WPT_BODIES: "readonly", + $WPT_COOKIES: "readonly", + $WPT_DNS: "readonly", + $WPT_REQUESTS: "readonly", + $WPT_TEST_URL: "readonly", + httparchive_enable_observations: "writable", + __REACT_DEVTOOLS_GLOBAL_HOOK__: "writable", + CSSUnparsedValue: "readonly", + LaunchParams: "readonly", + }, + }, + }, + + // CLI and tooling scripts (Node.js context) + { + files: ["bin/**/*.js"], + languageOptions: { + ecmaVersion: "latest", + sourceType: "commonjs", + globals: { + ...globals.node, + }, + }, + }, + + // Tests (Node.js + Jest context) + { + files: ["tests/**/*.js"], + languageOptions: { + ecmaVersion: "latest", + sourceType: "commonjs", + globals: { + ...globals.node, + ...globals.jest, + }, + }, + }, + + // Root configuration files (ESM context) + { + files: ["*.mjs", ".github/**/*.mjs"], + languageOptions: { + ecmaVersion: "latest", + sourceType: "module", + globals: { + ...globals.node, + }, + }, + }, +]); diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index d1feeb1..367188f 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -30,6 +30,9 @@ jobs: name: Lint Code Base # Set the agent to run on runs-on: ubuntu-latest + permissions: + contents: read + statuses: write ################## # Load all steps # @@ -51,8 +54,9 @@ jobs: - name: Set VALIDATE_ALL_CODEBASE variable to false # Only run the full workflow for manual runs or if upgrading the super linter if: | - github.event_name != 'workflow_dispatch' && - startsWith(github.event.pull_request.title,'Bump github/super-linter') != true + github.event_name != 'workflow_dispatch' && + !contains(github.event.pull_request.title, 'super-linter') && + !contains(github.event.pull_request.body, 'super-linter') run: | echo "VALIDATE_ALL_CODEBASE=false" >> $GITHUB_ENV @@ -64,6 +68,7 @@ jobs: env: DEFAULT_BRANCH: main GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ENABLE_GITHUB_PULL_REQUEST_SUMMARY_COMMENT: false VALIDATE_JAVASCRIPT_ES: true VALIDATE_EDITORCONFIG: true VALIDATE_MARKDOWN: true