File size: 2,933 Bytes
6778ee0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import globals from 'globals'
import { globalIgnores } from 'eslint/config'
import eslint from '@eslint/js'
import pluginPlaywright from 'eslint-plugin-playwright'
import prettierEslintInteroperabilityConfig from 'eslint-config-prettier/flat'
import tseslint from 'typescript-eslint'
import { DEFAULT_GLOBALS } from './compiler/index.js'

const DEFAULT_BOOLEAN_SETTINGS = Object.fromEntries(
  Object.entries(DEFAULT_GLOBALS).map(([global]) => [global, 'readonly'])
)

export default tseslint.config([
  globalIgnores(['./npm_package/plausible.js']),
  // shared config for all files
  eslint.configs.recommended,
  tseslint.configs.recommended,
  {
    rules: {
      '@typescript-eslint/no-unused-vars': [
        'error',
        {
          argsIgnorePattern: '^_',
          varsIgnorePattern: '^_',
          caughtErrorsIgnorePattern: '^_'
        }
      ],
      '@typescript-eslint/no-unused-expressions': [
        'error',
        {
          allowShortCircuit: true
        }
      ]
    }
  },
  // config for build scripts
  {
    files: [
      'compile.js',
      'compiler/**/*.js',
      'playwright.config.js',
      'eslint.config.mjs',
      'playwright.config.ts',
      'test/support/server.js'
    ],
    languageOptions: { ecmaVersion: 'latest', globals: globals.node }
  },
  // config for tracker script
  {
    files: ['src/**/*.js'],
    languageOptions: {
      ecmaVersion: 5, // must work also in older browsers
      globals: {
        ...globals.browser,
        ...DEFAULT_BOOLEAN_SETTINGS,
        plausible: 'writeable'
      },
      sourceType: 'commonjs'
    }
  },
  // config for installation support scripts
  {
    files: ['installation_support/**/*.js'],
    languageOptions: {
      ecmaVersion: 'latest', // must work only in modern browsers
      globals: {
        ...globals.browser,
        plausible: 'readable'
      }
    }
  },
  // config for tests of tracker scripts and installation support scripts
  {
    files: ['test/**/*.js', 'test/**/*.ts'],
    ...pluginPlaywright.configs['flat/recommended'],
    languageOptions: {
      ecmaVersion: 'latest',
      globals: {
        // available in test runner:
        ...globals.node,
        // available within the Page under test:
        ...globals.browser,
        plausible: 'readable'
      }
    },
    rules: {
      ...pluginPlaywright.configs['flat/recommended'].rules,
      'playwright/expect-expect': [
        'error',
        {
          assertFunctionNames: ['expectPlausibleInAction']
        }
      ],
      'playwright/no-wait-for-timeout': 'off', // justification: it's necessary for engagement and scroll depth tests
      'playwright/no-conditional-in-test': 'off', // justification: it's necessary for generated tests
      'playwright/no-skipped-test': 'off' // justification: test skips are intentional, usually for flakiness on specific browsers
    }
  },
  prettierEslintInteroperabilityConfig
])