| 1 |
const fs = require('fs'); |
| 2 |
const globals = require('globals'); |
| 3 |
const htmlParser = require('@html-eslint/parser'); |
| 4 |
const htmlPlugin = require('@html-eslint/eslint-plugin'); |
| 5 |
const pluginJs = require('@eslint/js'); |
| 6 |
const pluginReference = require('eslint-plugin-html'); |
| 7 |
const stylistic = require('@stylistic/eslint-plugin'); |
| 8 |
|
| 9 |
if (process && process.env && process.env.npm_command && !fs.existsSync('./platform/web/eslint.config.cjs')) { |
| 10 |
throw Error('eslint must be run from the Godot project root folder'); |
| 11 |
} |
| 12 |
|
| 13 |
const emscriptenGlobals = { |
| 14 |
'ERRNO_CODES': true, |
| 15 |
'FS': true, |
| 16 |
'GL': true, |
| 17 |
'HEAP32': true, |
| 18 |
'HEAP8': true, |
| 19 |
'HEAPF32': true, |
| 20 |
'HEAPU8': true, |
| 21 |
'HEAPU32': true, |
| 22 |
'IDBFS': true, |
| 23 |
'LibraryManager': true, |
| 24 |
'MainLoop': true, |
| 25 |
'Module': true, |
| 26 |
'UTF8ToString': true, |
| 27 |
'UTF8Decoder': true, |
| 28 |
'_emscripten_webgl_get_current_context': true, |
| 29 |
'_free': true, |
| 30 |
'_malloc': true, |
| 31 |
'autoAddDeps': true, |
| 32 |
'addToLibrary': true, |
| 33 |
'addOnPostRun': true, |
| 34 |
'getValue': true, |
| 35 |
'lengthBytesUTF8': true, |
| 36 |
'mergeInto': true, |
| 37 |
'runtimeKeepalivePop': true, |
| 38 |
'runtimeKeepalivePush': true, |
| 39 |
'setValue': true, |
| 40 |
'stringToUTF8': true, |
| 41 |
'stringToUTF8Array': true, |
| 42 |
'wasmTable': true, |
| 43 |
}; |
| 44 |
|
| 45 |
module.exports = [ |
| 46 |
pluginJs.configs.all, |
| 47 |
stylistic.configs.customize({ jsx: false }), |
| 48 |
|
| 49 |
{ |
| 50 |
rules: { |
| 51 |
'consistent-this': ['error', 'me'], |
| 52 |
'curly': ['error', 'all'], |
| 53 |
'no-else-return': ['error', { 'allowElseIf': true }], |
| 54 |
'no-param-reassign': ['error', { 'props': false }], |
| 55 |
'no-unused-vars': ['error', { 'args': 'none', 'caughtErrors': 'none' }], |
| 56 |
|
| 57 |
'@stylistic/arrow-parens': ['error', 'always'], |
| 58 |
'@stylistic/brace-style': ['error', '1tbs', { 'allowSingleLine': false }], |
| 59 |
'@stylistic/comma-dangle': ['error', { |
| 60 |
'arrays': 'always-multiline', |
| 61 |
'objects': 'always-multiline', |
| 62 |
'imports': 'always-multiline', |
| 63 |
'exports': 'always-multiline', |
| 64 |
'functions': 'never', |
| 65 |
}], |
| 66 |
'@stylistic/indent': ['error', 'tab', { 'SwitchCase': 0 }], |
| 67 |
'@stylistic/indent-binary-ops': ['error', 'tab'], |
| 68 |
'@stylistic/multiline-ternary': ['error', 'always-multiline'], |
| 69 |
'@stylistic/no-tabs': ['error', { 'allowIndentationTabs': true }], |
| 70 |
'@stylistic/quote-props': ['error', 'consistent'], |
| 71 |
'@stylistic/quotes': ['error', 'single'], |
| 72 |
'@stylistic/semi': ['error', 'always'], |
| 73 |
'@stylistic/spaced-comment': ['error', 'always', { 'block': { 'exceptions': ['*'] } }], |
| 74 |
|
| 75 |
'camelcase': 'off', |
| 76 |
'capitalized-comments': 'off', |
| 77 |
'complexity': 'off', |
| 78 |
'dot-notation': 'off', |
| 79 |
'eqeqeq': 'off', |
| 80 |
'func-name-matching': 'off', |
| 81 |
'func-names': 'off', |
| 82 |
'func-style': 'off', |
| 83 |
'id-length': 'off', |
| 84 |
'init-declarations': 'off', |
| 85 |
'line-comment-position': 'off', |
| 86 |
'max-classes-per-file': 'off', |
| 87 |
'max-lines': 'off', |
| 88 |
'max-lines-per-function': 'off', |
| 89 |
'max-params': 'off', |
| 90 |
'max-statements': 'off', |
| 91 |
'multiline-comment-style': 'off', |
| 92 |
'new-cap': 'off', |
| 93 |
'no-bitwise': 'off', |
| 94 |
'no-continue': 'off', |
| 95 |
'no-empty-function': 'off', |
| 96 |
'no-eq-null': 'off', |
| 97 |
'no-implicit-coercion': 'off', |
| 98 |
'no-inline-comments': 'off', |
| 99 |
'no-magic-numbers': 'off', |
| 100 |
'no-negated-condition': 'off', |
| 101 |
'no-plusplus': 'off', |
| 102 |
'no-self-assign': 'off', |
| 103 |
'no-ternary': 'off', |
| 104 |
'no-undefined': 'off', |
| 105 |
'no-underscore-dangle': 'off', |
| 106 |
'no-useless-assignment': 'off', |
| 107 |
'no-warning-comments': 'off', |
| 108 |
'object-shorthand': 'off', |
| 109 |
'one-var': 'off', |
| 110 |
'prefer-arrow-callback': 'off', |
| 111 |
'prefer-destructuring': 'off', |
| 112 |
'prefer-named-capture-group': 'off', |
| 113 |
'prefer-promise-reject-errors': 'off', |
| 114 |
'prefer-rest-params': 'off', |
| 115 |
'prefer-spread': 'off', |
| 116 |
'require-unicode-regexp': 'off', |
| 117 |
'sort-keys': 'off', |
| 118 |
}, |
| 119 |
}, |
| 120 |
|
| 121 |
|
| 122 |
{ |
| 123 |
files: ['js/jsdoc2rst/**/*.js', 'platform/web/js/jsdoc2rst/**/*.js'], |
| 124 |
languageOptions: { |
| 125 |
globals: globals.node, |
| 126 |
}, |
| 127 |
}, |
| 128 |
|
| 129 |
|
| 130 |
{ |
| 131 |
files: ['js/engine/**/*.js', 'platform/web/js/engine/**/*.js'], |
| 132 |
languageOptions: { |
| 133 |
globals: { |
| 134 |
...globals.browser, |
| 135 |
'Features': true, |
| 136 |
'Godot': true, |
| 137 |
'InternalConfig': true, |
| 138 |
'Preloader': true, |
| 139 |
}, |
| 140 |
}, |
| 141 |
}, |
| 142 |
|
| 143 |
|
| 144 |
{ |
| 145 |
files: [ |
| 146 |
'js/libs/**/*.js', |
| 147 |
'platform/web/js/libs/**/*.js', |
| 148 |
'platform/web/js/patches/**/*.js', |
| 149 |
'modules/**/*.js' |
| 150 |
], |
| 151 |
languageOptions: { |
| 152 |
globals: { |
| 153 |
...globals.browser, |
| 154 |
...emscriptenGlobals, |
| 155 |
'GodotConfig': true, |
| 156 |
'GodotEventListeners': true, |
| 157 |
'GodotFS': true, |
| 158 |
'GodotOS': true, |
| 159 |
'GodotAudio': true, |
| 160 |
'GodotInput': true, |
| 161 |
'GodotRuntime': true, |
| 162 |
'IDHandler': true, |
| 163 |
'XRWebGLLayer': true, |
| 164 |
}, |
| 165 |
}, |
| 166 |
}, |
| 167 |
|
| 168 |
|
| 169 |
{ |
| 170 |
files: ['misc/dist/html/**/*.js'], |
| 171 |
languageOptions: { |
| 172 |
globals: { |
| 173 |
...globals.browser, |
| 174 |
'___GODOT_CACHE___': true, |
| 175 |
'___GODOT_ENSURE_CROSSORIGIN_ISOLATION_HEADERS___': true, |
| 176 |
'___GODOT_OPT_CACHE___': true, |
| 177 |
}, |
| 178 |
}, |
| 179 |
}, |
| 180 |
|
| 181 |
|
| 182 |
{ |
| 183 |
files: ['misc/dist/html/**/*.html'], |
| 184 |
plugins: { |
| 185 |
'@html-eslint': htmlPlugin, |
| 186 |
'eslint-plugin-html': pluginReference, |
| 187 |
}, |
| 188 |
languageOptions: { |
| 189 |
parser: htmlParser, |
| 190 |
globals: { |
| 191 |
...globals.browser, |
| 192 |
'Engine': true, |
| 193 |
'$GODOT_CONFIG': true, |
| 194 |
'$GODOT_PROJECT_NAME': true, |
| 195 |
'$GODOT_THREADS_ENABLED': true, |
| 196 |
'___GODOT_THREADS_ENABLED___': true, |
| 197 |
}, |
| 198 |
}, |
| 199 |
rules: { |
| 200 |
...htmlPlugin.configs.recommended.rules, |
| 201 |
'@html-eslint/indent': ['error', 'tab'], |
| 202 |
'@html-eslint/require-closing-tags': ['error', { 'selfClosing': 'never' }], |
| 203 |
'no-alert': 'off', |
| 204 |
'no-console': 'off', |
| 205 |
}, |
| 206 |
}, |
| 207 |
|
| 208 |
{ |
| 209 |
ignores: [ |
| 210 |
'**/eslint.config.cjs', |
| 211 |
'**/.eslintrc*.js', |
| 212 |
'**/*.externs.js', |
| 213 |
], |
| 214 |
}, |
| 215 |
]; |