const fs = require('fs');
const globals = require('globals');
const htmlParser = require('@html-eslint/parser');
const htmlPlugin = require('@html-eslint/eslint-plugin');
const pluginJs = require('@eslint/js');
const pluginReference = require('eslint-plugin-html');
const stylistic = require('@stylistic/eslint-plugin');
if (process && process.env && process.env.npm_command && !fs.existsSync('./platform/web/eslint.config.cjs')) {
throw Error('eslint must be run from the Godot project root folder');
}
const emscriptenGlobals = {
'ERRNO_CODES': true,
'FS': true,
'GL': true,
'HEAP32': true,
'HEAP8': true,
'HEAPF32': true,
'HEAPU8': true,
'HEAPU32': true,
'IDBFS': true,
'LibraryManager': true,
'MainLoop': true,
'Module': true,
'UTF8ToString': true,
'UTF8Decoder': true,
'_emscripten_webgl_get_current_context': true,
'_free': true,
'_malloc': true,
'autoAddDeps': true,
'addToLibrary': true,
'addOnPostRun': true,
'getValue': true,
'lengthBytesUTF8': true,
'mergeInto': true,
'runtimeKeepalivePop': true,
'runtimeKeepalivePush': true,
'setValue': true,
'stringToUTF8': true,
'stringToUTF8Array': true,
'wasmTable': true,
};
module.exports = [
pluginJs.configs.all,
stylistic.configs.customize({ jsx: false }),
{
rules: {
'consistent-this': ['error', 'me'],
'curly': ['error', 'all'],
'no-else-return': ['error', { 'allowElseIf': true }],
'no-param-reassign': ['error', { 'props': false }],
'no-unused-vars': ['error', { 'args': 'none', 'caughtErrors': 'none' }],
'@stylistic/arrow-parens': ['error', 'always'],
'@stylistic/brace-style': ['error', '1tbs', { 'allowSingleLine': false }],
'@stylistic/comma-dangle': ['error', {
'arrays': 'always-multiline',
'objects': 'always-multiline',
'imports': 'always-multiline',
'exports': 'always-multiline',
'functions': 'never',
}],
'@stylistic/indent': ['error', 'tab', { 'SwitchCase': 0 }],
'@stylistic/indent-binary-ops': ['error', 'tab'],
'@stylistic/multiline-ternary': ['error', 'always-multiline'],
'@stylistic/no-tabs': ['error', { 'allowIndentationTabs': true }],
'@stylistic/quote-props': ['error', 'consistent'],
'@stylistic/quotes': ['error', 'single'],
'@stylistic/semi': ['error', 'always'],
'@stylistic/spaced-comment': ['error', 'always', { 'block': { 'exceptions': ['*'] } }],
'camelcase': 'off',
'capitalized-comments': 'off',
'complexity': 'off',
'dot-notation': 'off',
'eqeqeq': 'off',
'func-name-matching': 'off',
'func-names': 'off',
'func-style': 'off',
'id-length': 'off',
'init-declarations': 'off',
'line-comment-position': 'off',
'max-classes-per-file': 'off',
'max-lines': 'off',
'max-lines-per-function': 'off',
'max-params': 'off',
'max-statements': 'off',
'multiline-comment-style': 'off',
'new-cap': 'off',
'no-bitwise': 'off',
'no-continue': 'off',
'no-empty-function': 'off',
'no-eq-null': 'off',
'no-implicit-coercion': 'off',
'no-inline-comments': 'off',
'no-magic-numbers': 'off',
'no-negated-condition': 'off',
'no-plusplus': 'off',
'no-self-assign': 'off',
'no-ternary': 'off',
'no-undefined': 'off',
'no-underscore-dangle': 'off',
'no-useless-assignment': 'off',
'no-warning-comments': 'off',
'object-shorthand': 'off',
'one-var': 'off',
'prefer-arrow-callback': 'off',
'prefer-destructuring': 'off',
'prefer-named-capture-group': 'off',
'prefer-promise-reject-errors': 'off',
'prefer-rest-params': 'off',
'prefer-spread': 'off',
'require-unicode-regexp': 'off',
'sort-keys': 'off',
},
},
{
files: ['js/jsdoc2rst/**/*.js', 'platform/web/js/jsdoc2rst/**/*.js'],
languageOptions: {
globals: globals.node,
},
},
{
files: ['js/engine/**/*.js', 'platform/web/js/engine/**/*.js'],
languageOptions: {
globals: {
...globals.browser,
'Features': true,
'Godot': true,
'InternalConfig': true,
'Preloader': true,
},
},
},
{
files: [
'js/libs/**/*.js',
'platform/web/js/libs/**/*.js',
'platform/web/js/patches/**/*.js',
'modules/**/*.js'
],
languageOptions: {
globals: {
...globals.browser,
...emscriptenGlobals,
'GodotConfig': true,
'GodotEventListeners': true,
'GodotFS': true,
'GodotOS': true,
'GodotAudio': true,
'GodotRuntime': true,
'IDHandler': true,
'XRWebGLLayer': true,
},
},
},
{
files: ['misc/dist/html/**/*.js'],
languageOptions: {
globals: {
...globals.browser,
'___GODOT_CACHE___': true,
'___GODOT_ENSURE_CROSSORIGIN_ISOLATION_HEADERS___': true,
'___GODOT_OPT_CACHE___': true,
},
},
},
{
files: ['misc/dist/html/**/*.html'],
plugins: {
'@html-eslint': htmlPlugin,
'eslint-plugin-html': pluginReference,
},
languageOptions: {
parser: htmlParser,
globals: {
...globals.browser,
'Engine': true,
'$GODOT_CONFIG': true,
'$GODOT_PROJECT_NAME': true,
'$GODOT_THREADS_ENABLED': true,
'___GODOT_THREADS_ENABLED___': true,
},
},
rules: {
...htmlPlugin.configs.recommended.rules,
'@html-eslint/indent': ['error', 'tab'],
'@html-eslint/require-closing-tags': ['error', { 'selfClosing': 'never' }],
'no-alert': 'off',
'no-console': 'off',
},
},
{
ignores: [
'**/eslint.config.cjs',
'**/.eslintrc*.js',
'**/*.externs.js',
],
},
];