Repository navigation
Expand file tree
/
Copy patheslint.config.js
More file actions
419 lines (409 loc) · 13.1 KB
/
Copy patheslint.config.js
File metadata and controls
419 lines (409 loc) · 13.1 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
const jsdoc = require('eslint-plugin-jsdoc')
const lintImports = require('eslint-plugin-import')
const neostandard = require('neostandard')
const globals = require('globals');
const prebid = require('./plugins/eslint/index.js');
const chaiFriendly = require('eslint-plugin-chai-friendly');
const mochaPlugin = require('eslint-plugin-mocha').default;
const {includeIgnoreFile} = require('@eslint/compat');
const path = require('path');
const _ = require('lodash');
const tseslint = require('typescript-eslint');
const {getSourceFolders} = require('./gulpHelpers.js');
const APPROVED_LOAD_EXTERNAL_SCRIPT_PATHS = require('./plugins/eslint/approvedLoadExternalScriptPaths.js');
function jsPattern(name) {
return [`${name}/**/*.js`, `${name}/**/*.mjs`]
}
function tsPattern(name) {
return [`${name}/**/*.ts`, `${name}/**/*.mts`]
}
function sourcePattern(name) {
return jsPattern(name).concat(tsPattern(name));
}
const allowedImports = {
modules: [
'live-connect' // Maintained by LiveIntent : https://github.com/liveintent-berlin/live-connect/
],
src: [
'fun-hooks/no-eval',
'klona',
'dlv',
'dset'
],
// [false] means disallow ANY import outside of modules/debugging
// this is because debugging also gets built as a standalone module,
// and importing global state does not work as expected.
// in theory imports that do not involve global state are fine, but
// even innocuous imports can become problematic if the source changes,
// and it's too easy to forget this is a problem for debugging-standalone.
'modules/debugging': [false],
libraries: [
// ponyfill for the fetch family, injected by plugins/polyfillFetch.js and only
// for build targets that lack AbortController - see libraries/fetchPonyfill
'whatwg-fetch'
],
creative: [],
}
const restrictedLogFunctions = [
{
selector: "FunctionDeclaration[id.name=/^log(Message|Info|Warn|Error|Result)$/]",
message: "Defining a function named 'logResult', 'logMessage', 'logInfo', 'logWarn', or 'logError' is not allowed."
},
{
selector: "VariableDeclarator[id.name=/^log(Message|Info|Warn|Error|Result)$/][init.type=/FunctionExpression|ArrowFunctionExpression/]",
message: "Assigning a function to 'logResult', 'logMessage', 'logInfo', 'logWarn', or 'logError' is not allowed."
},
];
function noGlobals(names) {
return {
globals: Object.entries(names).map(([name, message]) => ({
name,
message
})),
props: Object.entries(names).map(([name, message]) => ({
object: 'window',
property: name,
message
}))
}
}
module.exports = [
includeIgnoreFile(path.resolve(__dirname, '.gitignore')),
{
ignores: [
'integrationExamples/**/*',
// do not lint worktrees created by claude/gemini
'.claude/**',
'.gemini/**',
// do not lint build-related stuff
'*.js',
'*.mjs',
'metadata/**/*',
'customize/**/*',
// inputs for tests that run linter rules themselves, and not all of them are meant to pass
'test/build-logic/fixtures/**/*',
...jsPattern('plugins'),
...jsPattern('.github'),
'web-bundler',
],
},
jsdoc.configs['flat/recommended'],
...tseslint.configs.recommended,
...neostandard({
files: getSourceFolders().flatMap(jsPattern),
ts: true,
filesTs: getSourceFolders().flatMap(tsPattern)
}),
{
files: getSourceFolders().flatMap(sourcePattern),
plugins: {
jsdoc,
import: lintImports,
prebid
},
settings: {
jsdoc: {
tagNamePreference: {
return: 'return'
}
},
'import/resolver': {
[path.resolve('./plugins/eslint/resolver')]: true,
node: true,
typescript: {
alwaysTryTypes: true,
project: './tsconfig.json',
},
}
},
languageOptions: {
sourceType: 'module',
ecmaVersion: 2018,
globals: {
BROWSERSTACK_USERNAME: false,
BROWSERSTACK_KEY: false,
FEATURES: 'readonly',
...globals.browser
},
},
rules: {
'comma-dangle': 'off',
'@stylistic/comma-dangle': 'off',
'@stylistic/semi': ['error', 'always'],
'no-undef': 2,
'no-constant-binary-expression': 'error',
'no-useless-assignment': 'error',
'prebid/no-redundant-validated-condition': 'error',
'no-console': 'error',
'prebid/no-extra-function-args': 'error',
'prebid/no-deep-access-import': 'warn',
'space-before-function-paren': 'off',
'@stylistic/space-before-function-paren': 'off',
'import/no-unresolved': 'error',
'import/named': 'error',
'import/default': 'error',
'import/export': 'error',
'import/no-named-as-default': 'warn',
'import/no-named-as-default-member': 'warn',
'import/no-duplicates': 'warn',
'import/no-extraneous-dependencies': ['error', {
// flag imports that are not runtime or peer dependencies;
// except for tests, which are allowed devDependencies
devDependencies: sourcePattern('test'),
peerDependencies: true,
optionalDependencies: false,
includeTypes: true,
}],
'prebid/no-implicit-operand-conversion': 'error',
'no-restricted-syntax': ['error', ...restrictedLogFunctions],
'no-restricted-imports': [
'error', {
patterns: [
'**/src/adloader.js'
]
}
],
// Exceptions below this line are temporary (TM), so that eslint can be added into the CI process.
// Violations of these styles should be fixed, and the exceptions removed over time.
//
// See Issue #1111.
// also see: reality. These are here to stay.
// we're working on them though :)
// @augmentationOptional is read by prebid/augmentation-reachable, and by the same check
// after declaration emit
'jsdoc/check-tag-names': ['warn', {definedTags: ['augmentationOptional']}],
'jsdoc/check-types': 'off',
'jsdoc/no-defaults': 'off',
'jsdoc/newline-after-description': 'off',
'jsdoc/require-jsdoc': 'off',
'jsdoc/require-param': 'off',
'jsdoc/require-param-description': 'off',
'jsdoc/require-param-name': 'off',
'jsdoc/require-param-type': 'off',
'jsdoc/require-property': 'off',
'jsdoc/require-property-description': 'off',
'jsdoc/require-property-name': 'off',
'jsdoc/require-property-type': 'off',
'jsdoc/require-returns': 'off',
'jsdoc/require-returns-check': 'off',
'jsdoc/require-returns-description': 'off',
'jsdoc/require-returns-type': 'off',
'jsdoc/require-yields': 'off',
'jsdoc/require-yields-check': 'off',
'jsdoc/tag-lines': 'off',
'no-var': 'off',
'no-void': 'off',
'prefer-const': 'off',
'no-prototype-builtins': 'off',
'object-shorthand': 'off',
'prefer-regex-literals': 'off',
'no-case-declarations': 'off',
'@stylistic/quotes': 'off',
'@stylistic/quote-props': 'off',
'@stylistic/multiline-ternary': 'off',
}
},
{
files: getSourceFolders().map(dir => `${dir}/**/*.d.ts`),
ignores: [
'src/types/**/*'
],
rules: {
'prebid/declaration-filename': 'error'
}
},
{
files: getSourceFolders().flatMap(tsPattern),
plugins: {
prebid
},
rules: {
'prebid/augmentation-reachable': ['error', {
// core's entry point as it is before precompilation, when this runs
coreEntry: 'src/prebid.public.ts',
// an augmentation in test code reaches no consumer either way
ignore: ['test'],
project: 'tsconfig.json'
}]
}
},
...Object.entries(allowedImports).map(([path, allowed]) => {
const {globals, props} = noGlobals({
require: 'use import instead',
...Object.fromEntries(['localStorage', 'sessionStorage'].map(k => [k, 'use storageManager instead'])),
XMLHttpRequest: 'use ajax.js instead',
fetch: 'use fetch from ajax.js instead'
})
return {
files: sourcePattern(path),
plugins: {
prebid,
},
rules: {
'prebid/validate-imports': ['error', allowed],
'no-restricted-globals': [
'error',
...globals
],
'no-restricted-properties': [
'error',
...props,
...['globalThis', 'self'].map(object => ({
object,
property: 'fetch',
message: 'use fetch from ajax.js instead'
})),
{
property: 'cookie',
object: 'document',
message: 'use storageManager instead'
},
{
property: 'sendBeacon',
object: 'navigator',
message: 'use ajax.js instead'
},
{
property: 'doNotTrack',
object: 'navigator',
message: 'DNT was deprecated by W3C; Prebid no longer supports DNT signals'
},
{
property: 'msDoNotTrack',
object: 'navigator',
message: 'DNT was deprecated by W3C; Prebid no longer supports DNT signals'
},
{
property: 'doNotTrack',
object: 'window',
message: 'DNT was deprecated by W3C; Prebid no longer supports DNT signals'
},
...['outerText', 'innerText'].map(property => ({
property,
message: 'use .textContent instead'
})),
{
property: 'getBoundingClientRect',
message: 'use libraries/boundingClientRect instead'
},
...['scrollTop', 'scrollLeft', 'innerHeight', 'innerWidth', 'visualViewport'].map((property) => ({
object: 'window',
property,
message: 'use utils/getWinDimensions instead'
}))
]
}
}
}),
{
files: [
'**/*BidAdapter.{js,mjs,ts,mts}',
'**/*BidAdapter/**/*.{js,mjs,ts,mts}'
],
ignores: [
'modules/prebidServerBidAdapter/**/*'
],
rules: {
'no-restricted-imports': [
'error', {
patterns: [
'**/src/events.js',
'**/src/adloader.js'
]
}
]
}
},
{
files: [
'modules/**/*BidAdapter.{js,mjs,ts,mts}',
'modules/**/*RtdProvider.{js,mjs,ts,mts}',
'modules/**/*AnalyticsAdapter.{js,mjs,ts,mts}'
],
ignores: [
'modules/adagioRtdProvider.js',
'modules/contxtfulRtdProvider.js'
],
plugins: {
prebid
},
rules: {
'prebid/no-synchronous-layout-read': 'error',
}
},
{
files: sourcePattern('test'),
plugins: {
'chai-friendly': chaiFriendly,
'mocha': mochaPlugin
},
languageOptions: {
globals: {
...globals.mocha,
...globals.chai,
'sinon': false
}
},
rules: {
'no-template-curly-in-string': 'off',
'no-unused-expressions': 'off',
'chai-friendly/no-unused-expressions': 'error',
// Mocha silently ignores it()/describe()/hooks called while a test or hook is running: their
// assertions never run, and the spec still passes (#16043). This rule doesn't report a hook
// (e.g. after()) registered inside a test; see AGENTS.md.
'mocha/no-nested-tests': 'error',
// overrides the source folders' list rather than extending it
'no-restricted-syntax': [
'error',
...restrictedLogFunctions,
...['Literal[value=/localhost:9876/]', 'TemplateElement[value.raw=/localhost:9876/]'].map(selector => ({
selector,
message: 'The test page is not always localhost:9876; take it from window.location or getRefererInfo(), or use another URL for fixtures.'
}))
],
// tests were not subject to many rules and they are now a nightmare. rules below this line should be removed over time
'no-undef': 'off',
'no-useless-escape': 'off',
'no-return-assign': 'off',
'camelcase': 'off'
}
},
{
files: getSourceFolders().flatMap(tsPattern),
rules: {
// turn off no-undef for TS files - type checker does better
'no-undef': 'off',
'@typescript-eslint/no-explicit-any': 'off'
}
},
{
files: getSourceFolders().flatMap(jsPattern),
rules: {
// turn off typescript rules on js files - just too many violations
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-this-alias': 'off',
'@typescript-eslint/no-require-imports': 'off'
}
},
// Override: allow loadExternalScript import in approved files (excluding BidAdapters)
{
files: APPROVED_LOAD_EXTERNAL_SCRIPT_PATHS.filter(p => !p.includes('BidAdapter')).map(p => {
// If path doesn't end with .js/.ts/.mjs/.mts, treat as folder pattern
if (!p.match(/\.(js|ts|mjs|mts)$/)) {
return `${p}/**/*.{js,ts,mjs,mts}`;
}
return p;
}),
rules: {
'no-restricted-imports': [
'error',
{
// Approved files intentionally clear inherited no-restricted-imports patterns.
// The BidAdapter restriction above is the authoritative block for events.js/adloader.js.
patterns: []
}
],
}
},
]