Skip to content

Commit

Permalink
factor out phetSimBrowserGlobals.eslint.config.mjs, phetsims/chipper#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Oct 22, 2024
1 parent cd816a4 commit 84cbf8e
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 143 deletions.
162 changes: 162 additions & 0 deletions eslint/phetSimBrowserGlobals.eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Copyright 2024, University of Colorado Boulder

/**
* @author Michael Kauzmann (PhET Interactive Simulations)
* @author Sam Reid (PhET Interactive Simulations)
*/
const phetSimBrowserGlobals = {
languageOptions: {
globals: {

//=============================================================================================
// globals that should never be accessed
//=============================================================================================

// TODO: Does this work if they are overridden later? https://github.com/phetsims/chipper/issues/1451
// TODO: Is this still needed? https://github.com/phetsims/chipper/issues/1451
// Using window.event is most likely a bug, instead the event should be passed through via a parameter,
// discovered in https://github.com/phetsims/scenery/issues/1053
event: 'off',

//=============================================================================================
// read-only globals
//=============================================================================================

phet: 'readonly',

// allow assertions
assert: 'readonly',

// allow slow assertions
assertSlow: 'readonly',

phetio: 'readonly',

// underscore, lodash
_: 'readonly',

// jQuery
$: 'readonly',

// jQuery for type documentation
JQuery: 'readonly',

// JSON diffs
jsondiffpatch: 'readonly',

document: 'readonly',

// for linting Node.js code
global: 'readonly',

// QUnit
QUnit: 'readonly',

// as used in Gruntfile.js
// TODO: not a browser global, only for Node https://github.com/phetsims/chipper/issues/1451
module: 'readonly',

// Misc
QueryStringMachine: 'readonly',
QueryStringMachineSchema: 'readonly',
QSMParsedParameters: 'readonly',

// Prism is a syntax highlighter that renders code in the browser. It is used for PhET-iO wrappers and for a11y.
// TODO: define only where needed https://github.com/phetsims/chipper/issues/1451
Prism: 'readonly',

// sole/tween.js
TWEEN: 'readonly',

// TODO: redundant right? https://github.com/phetsims/chipper/issues/1451
window: 'readonly',

// TODO: old and unused right? Otherwise define only where needed https://github.com/phetsims/chipper/issues/1451
handlePlaybackEvent: 'readonly',

// TODO: define only where needed. https://github.com/phetsims/chipper/issues/1451
paper: 'readonly',

// TODO: define only where needed https://github.com/phetsims/chipper/issues/1451
pako: 'readonly',

// define globals for missing Web Audio types, see https://github.com/phetsims/chipper/issues/1214
// TODO: define only where needed https://github.com/phetsims/chipper/issues/1451
OscillatorType: 'readonly',
AudioContextState: 'readonly',

// type for QUnit assert
// TODO: define only where needed https://github.com/phetsims/chipper/issues/1451
Assert: 'readonly',

// TODO: redundant right? https://github.com/phetsims/chipper/issues/1451
fetch: 'readonly',

// TODO: define only where needed https://github.com/phetsims/chipper/issues/1451
// React
React: 'readonly',
ReactDOM: 'readonly',

BigInt: 'readonly',

FlatQueue: 'readonly',

// TODO: define only where needed https://github.com/phetsims/chipper/issues/1451
// WebGPU
GPUShaderModule: 'readonly',
GPUBindGroupLayout: 'readonly',
GPUDevice: 'readonly',
GPUShaderStage: 'readonly',
GPUBindGroupLayoutEntry: 'readonly',
GPUComputePipeline: 'readonly',
GPUBuffer: 'readonly',
GPUTextureView: 'readonly',
GPUCommandEncoder: 'readonly',
GPUBindGroupEntry: 'readonly',
GPUBufferUsage: 'readonly',
GPUTextureUsage: 'readonly',
GPUTexture: 'readonly',
GPUCanvasContext: 'readonly',
GPUTextureFormat: 'readonly',
GPUImageCopyExternalImageSource: 'readonly',
GPUPipelineLayout: 'readonly',
GPURenderPipeline: 'readonly',
GPUBindGroup: 'readonly',
GPUMapMode: 'readonly',
GPUFeatureName: 'readonly',
GPUQuerySet: 'readonly',
GPUComputePassDescriptor: 'readonly',
GPUComputePassTimestampWrites: 'readonly',
GPUComputePipelineDescriptor: 'readonly',
GPUComputePassEncoder: 'readonly',
GPUTextureViewDimension: 'readonly',
GPUStorageTextureAccess: 'readonly',
GPUBufferBindingType: 'readonly',
GPUTextureSampleType: 'readonly',
GPUBufferBinding: 'readonly',
GPURequestAdapterOptions: 'readonly',
GPUDeviceDescriptor: 'readonly',
GPUBufferDescriptor: 'readonly',
GPUQueue: 'readonly',
GPUQuerySetDescriptor: 'readonly',
GPUAdapter: 'readonly',
GPUMapModeFlags: 'readonly',
GPUPipelineLayoutDescriptor: 'readonly',
GPUCommandEncoderDescriptor: 'readonly',
GPUCommandBuffer: 'readonly',
GPUBindGroupDescriptor: 'readonly',
GPUBindGroupLayoutDescriptor: 'readonly',
GPUShaderModuleDescriptor: 'readonly',
GPURenderPassDescriptor: 'readonly',
GPURenderPassEncoder: 'readonly',
GPUCommandBufferDescriptor: 'readonly',
GPUImageCopyBuffer: 'readonly',
GPUImageCopyTexture: 'readonly',
GPUExtent3DStrict: 'readonly',
GPUSampler: 'readonly',
GPUExternalTexture: 'readonly'
}
}
};

export default phetSimBrowserGlobals;
150 changes: 7 additions & 143 deletions eslint/root.eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import typescriptEslintPlugin from '@typescript-eslint/eslint-plugin';
import typescriptEslintParser from '@typescript-eslint/parser';
import html from 'eslint-plugin-html';
import globals from 'globals';
import phetSimBrowserGlobalsEslintConfig from './phetSimBrowserGlobals.eslint.config.mjs';

import additionalBadText from './rules/additional-bad-text.js';
import authorAnnotation from './rules/author-annotation.js';
Expand Down Expand Up @@ -166,9 +167,7 @@ export default [
'phet-io-object-options-should-not-pick-from-phet-io-object': phetIoObjectOptionsShouldNotPickFromPhetIoObject
}
}
}
},
{
},

linterOptions: {
reportUnusedDisableDirectives: true
Expand All @@ -178,6 +177,8 @@ export default [

// TODO: upgrade version: Maybe 2022? https://github.com/phetsims/chipper/issues/1451
ecmaVersion: 2022,

// TODO: Does all code use sourceType module?, see https://github.com/phetsims/chipper/issues/1451
sourceType: 'module',

// Without a parser, .js files are linted without es6 transpilation. Use the same parser that we use for TypeScript.
Expand Down Expand Up @@ -1748,148 +1749,11 @@ export default [
}, {
languageOptions: {
globals: {
...globals.es2018,

//=============================================================================================
// globals that should never be accessed
//=============================================================================================

// Using window.event is most likely a bug, instead the event should be passed through via a parameter,
// discovered in https://github.com/phetsims/scenery/issues/1053
event: 'off',

//=============================================================================================
// read-only globals
//=============================================================================================

phet: 'readonly',

// allow assertions
assert: 'readonly',

// allow slow assertions
assertSlow: 'readonly',

// decimal.js library
Decimal: 'readonly',

phetio: 'readonly',

// underscore, lodash
_: 'readonly',

// jQuery
$: 'readonly',

// jQuery for type documentation
JQuery: 'readonly',

// JSON diffs
jsondiffpatch: 'readonly',

document: 'readonly',

// for linting Node.js code
global: 'readonly',

// QUnit
QUnit: 'readonly',

// as used in Gruntfile.js
module: 'readonly',

// Misc
QueryStringMachine: 'readonly',
QueryStringMachineSchema: 'readonly',
QSMParsedParameters: 'readonly',

// Prism is a syntax highlighter that renders code in the browser. It is used for PhET-iO wrappers and for a11y.
Prism: 'readonly',

// sole/tween.js
TWEEN: 'readonly',

window: 'readonly',

handlePlaybackEvent: 'readonly',

paper: 'readonly',

pako: 'readonly',

// define globals for missing Web Audio types, see https://github.com/phetsims/chipper/issues/1214
OscillatorType: 'readonly',
AudioContextState: 'readonly',

// type for QUnit assert
Assert: 'readonly',

fetch: 'readonly',

// React
React: 'readonly',
ReactDOM: 'readonly',

BigInt: 'readonly',

FlatQueue: 'readonly',

// WebGPU
GPUShaderModule: 'readonly',
GPUBindGroupLayout: 'readonly',
GPUDevice: 'readonly',
GPUShaderStage: 'readonly',
GPUBindGroupLayoutEntry: 'readonly',
GPUComputePipeline: 'readonly',
GPUBuffer: 'readonly',
GPUTextureView: 'readonly',
GPUCommandEncoder: 'readonly',
GPUBindGroupEntry: 'readonly',
GPUBufferUsage: 'readonly',
GPUTextureUsage: 'readonly',
GPUTexture: 'readonly',
GPUCanvasContext: 'readonly',
GPUTextureFormat: 'readonly',
GPUImageCopyExternalImageSource: 'readonly',
GPUPipelineLayout: 'readonly',
GPURenderPipeline: 'readonly',
GPUBindGroup: 'readonly',
GPUMapMode: 'readonly',
GPUFeatureName: 'readonly',
GPUQuerySet: 'readonly',
GPUComputePassDescriptor: 'readonly',
GPUComputePassTimestampWrites: 'readonly',
GPUComputePipelineDescriptor: 'readonly',
GPUComputePassEncoder: 'readonly',
GPUTextureViewDimension: 'readonly',
GPUStorageTextureAccess: 'readonly',
GPUBufferBindingType: 'readonly',
GPUTextureSampleType: 'readonly',
GPUBufferBinding: 'readonly',
GPURequestAdapterOptions: 'readonly',
GPUDeviceDescriptor: 'readonly',
GPUBufferDescriptor: 'readonly',
GPUQueue: 'readonly',
GPUQuerySetDescriptor: 'readonly',
GPUAdapter: 'readonly',
GPUMapModeFlags: 'readonly',
GPUPipelineLayoutDescriptor: 'readonly',
GPUCommandEncoderDescriptor: 'readonly',
GPUCommandBuffer: 'readonly',
GPUBindGroupDescriptor: 'readonly',
GPUBindGroupLayoutDescriptor: 'readonly',
GPUShaderModuleDescriptor: 'readonly',
GPURenderPassDescriptor: 'readonly',
GPURenderPassEncoder: 'readonly',
GPUCommandBufferDescriptor: 'readonly',
GPUImageCopyBuffer: 'readonly',
GPUImageCopyTexture: 'readonly',
GPUExtent3DStrict: 'readonly',
GPUSampler: 'readonly',
GPUExternalTexture: 'readonly'
...globals.es2018
}
}
}
},
phetSimBrowserGlobalsEslintConfig
];

export const browserGlobals = {
Expand Down

0 comments on commit 84cbf8e

Please sign in to comment.