Sfoglia il codice sorgente

add ELINT_FAST environment variable in pre-commit hook (#34396)

* add ELINT_FAST environment variable in pre-commit hook

skips slow type-aware linting in pre-commit hook, full lint still runs in CI

GitOrigin-RevId: d4b6fde1c5010ba0f61aed03972b745af0f55b9b
Brian Gough 2 mesi fa
parent
commit
19b040fc69
1 ha cambiato i file con 20 aggiunte e 10 eliminazioni
  1. 20 10
      services/web/eslint.config.mjs

+ 20 - 10
services/web/eslint.config.mjs

@@ -43,6 +43,12 @@ const reactFlatRecommended = {
 import _ from 'lodash'
 import _ from 'lodash'
 import confusingBrowserGlobals from 'confusing-browser-globals'
 import confusingBrowserGlobals from 'confusing-browser-globals'
 
 
+// Type-aware linting is expensive: setting `parserOptions.project` makes
+// @typescript-eslint build a full TypeScript program from tsconfig.backend.json
+// on every ESLint invocation, even when linting a single file.
+// Set ESLINT_FAST=1 to skip type-aware checks; the full lint still runs in CI.
+const TYPE_AWARE = process.env.ESLINT_FAST !== '1'
+
 export default defineConfig([
 export default defineConfig([
   // Declare which file extensions ESLint should consider in this workspace.
   // Declare which file extensions ESLint should consider in this workspace.
   // Replaces the previous `--ext .js,.jsx,.mjs,.ts,.tsx` CLI flag, which is
   // Replaces the previous `--ext .js,.jsx,.mjs,.ts,.tsx` CLI flag, which is
@@ -302,10 +308,12 @@ export default defineConfig([
     files: ['**/app/src/**/*.{js,mjs}', 'app.{js,mjs}'],
     files: ['**/app/src/**/*.{js,mjs}', 'app.{js,mjs}'],
 
 
     languageOptions: {
     languageOptions: {
-      parserOptions: {
-        tsconfigRootDir: import.meta.dirname,
-        project: './tsconfig.backend.json',
-      },
+      parserOptions: TYPE_AWARE
+        ? {
+            tsconfigRootDir: import.meta.dirname,
+            project: './tsconfig.backend.json',
+          }
+        : {},
     },
     },
 
 
     rules: {
     rules: {
@@ -357,12 +365,14 @@ export default defineConfig([
         },
         },
       ],
       ],
 
 
-      '@typescript-eslint/no-floating-promises': [
-        'error',
-        {
-          checkThenables: true,
-        },
-      ],
+      '@typescript-eslint/no-floating-promises': TYPE_AWARE
+        ? [
+            'error',
+            {
+              checkThenables: true,
+            },
+          ]
+        : 'off',
     },
     },
   },
   },
   {
   {