Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/platform/web/eslint.config.cjs
10277 views
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'], // enforce consistent naming when capturing the current execution context
52
'curly': ['error', 'all'], // enforce consistent brace style for all control statements
53
'no-else-return': ['error', { 'allowElseIf': true }], // disallow else blocks after return statements in if statements
54
'no-param-reassign': ['error', { 'props': false }], // disallow reassigning function parameters
55
'no-unused-vars': ['error', { 'args': 'none', 'caughtErrors': 'none' }], // disallow unused variables
56
57
'@stylistic/arrow-parens': ['error', 'always'], // enforces the consistent use of parentheses in arrow functions
58
'@stylistic/brace-style': ['error', '1tbs', { 'allowSingleLine': false }], // describes the placement of braces relative to their control statement and body
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
}], // enforces consistent use of trailing commas in object and array literals
66
'@stylistic/indent': ['error', 'tab', { 'SwitchCase': 0 }], // enforces a consistent indentation style
67
'@stylistic/indent-binary-ops': ['error', 'tab'], // indentation for binary operators in multiline expressions
68
'@stylistic/multiline-ternary': ['error', 'always-multiline'], // enforces or disallows newlines between operands of a ternary expression
69
'@stylistic/no-tabs': ['error', { 'allowIndentationTabs': true }], // looks for tabs anywhere inside a file: code, comments or anything else
70
'@stylistic/quote-props': ['error', 'consistent'], // requires quotes around object literal property names
71
'@stylistic/quotes': ['error', 'single'], // enforces the consistent use of either backticks, double, or single quotes
72
'@stylistic/semi': ['error', 'always'], // enforces consistent use of semicolons
73
'@stylistic/spaced-comment': ['error', 'always', { 'block': { 'exceptions': ['*'] } }], // enforce consistency of spacing after the start of a comment
74
75
'camelcase': 'off', // disable: camelcase naming convention
76
'capitalized-comments': 'off', // disable: enforce or disallow capitalization of the first letter of a comment
77
'complexity': 'off', // disable: enforce a maximum cyclomatic complexity allowed in a program
78
'dot-notation': 'off', // disable: enforce dot notation whenever possible
79
'eqeqeq': 'off', // disable: require the use of === and !==
80
'func-name-matching': 'off', // disable: require function names to match the name of the variable or property to which they are assigned
81
'func-names': 'off', // disable: checking named function expressions
82
'func-style': 'off', // disable: consistent use of either function declarations or expressions
83
'id-length': 'off', // disable: enforce minimum and maximum identifier lengths
84
'init-declarations': 'off', // disable: require or disallow initialization in variable declarations
85
'line-comment-position': 'off', // disable: enforce position of line comments
86
'max-classes-per-file': 'off', // disable: maximum number of classes per file
87
'max-lines': 'off', // disable: maximum number of lines per file
88
'max-lines-per-function': 'off', // disable: maximum number of lines of code in a function
89
'max-params': 'off', // disable: enforce a maximum number of parameters in function definitions
90
'max-statements': 'off', // disable: maximum number of statements allowed in function blocks
91
'multiline-comment-style': 'off', // disable: enforce a particular style for multiline comments
92
'new-cap': 'off', // disable: require constructor names to begin with a capital letter
93
'no-bitwise': 'off', // disable: disallow bitwise operators
94
'no-continue': 'off', // disable: disallow continue statements
95
'no-empty-function': 'off', // disable: disallow empty functions
96
'no-eq-null': 'off', // disable: disallow null comparisons without type-checking operators
97
'no-implicit-coercion': 'off', // disable: disallow shorthand type conversions
98
'no-inline-comments': 'off', // disable: disallow inline comments after code
99
'no-magic-numbers': 'off', // disable: disallow magic numbers
100
'no-negated-condition': 'off', // disable: disallow negated conditions
101
'no-plusplus': 'off', // disable: disallow the unary operators ++ and --
102
'no-self-assign': 'off', // disable: disallow assignments where both sides are exactly the same
103
'no-ternary': 'off', // disable: disallow ternary operators
104
'no-undefined': 'off', // disable: disallow the use of undefined as an identifier
105
'no-underscore-dangle': 'off', // disable: disallow dangling underscores in identifiers
106
'no-useless-assignment': 'off', // disable: disallow variable assignments when the value is not used
107
'no-warning-comments': 'off', // disable: disallow specified warning terms in comments
108
'object-shorthand': 'off', // disable: require or disallow method and property shorthand syntax for object literals
109
'one-var': 'off', // disable: enforce variables to be declared either together or separately in functions
110
'prefer-arrow-callback': 'off', // disable: require using arrow functions for callbacks
111
'prefer-destructuring': 'off', // disable: require destructuring from arrays and/or objects
112
'prefer-named-capture-group': 'off', // disable: enforce using named capture group in regular expression
113
'prefer-promise-reject-errors': 'off', // disable: require using Error objects as Promise rejection reasons
114
'prefer-rest-params': 'off', // disable: require rest parameters instead of arguments
115
'prefer-spread': 'off', // disable: require spread operators instead of .apply()
116
'require-unicode-regexp': 'off', // disable: enforce the use of u or v flag on RegExp
117
'sort-keys': 'off', // disable: require object keys to be sorted
118
},
119
},
120
121
// jsdoc2rst (node)
122
{
123
files: ['js/jsdoc2rst/**/*.js', 'platform/web/js/jsdoc2rst/**/*.js'],
124
languageOptions: {
125
globals: globals.node,
126
},
127
},
128
129
// engine files (browser)
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
// libraries and modules (browser)
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
'GodotRuntime': true,
161
'IDHandler': true,
162
'XRWebGLLayer': true,
163
},
164
},
165
},
166
167
// javascript templates (service workers)
168
{
169
files: ['misc/dist/html/**/*.js'],
170
languageOptions: {
171
globals: {
172
...globals.browser,
173
'___GODOT_CACHE___': true,
174
'___GODOT_ENSURE_CROSSORIGIN_ISOLATION_HEADERS___': true,
175
'___GODOT_OPT_CACHE___': true,
176
},
177
},
178
},
179
180
// html templates
181
{
182
files: ['misc/dist/html/**/*.html'],
183
plugins: {
184
'@html-eslint': htmlPlugin,
185
'eslint-plugin-html': pluginReference,
186
},
187
languageOptions: {
188
parser: htmlParser,
189
globals: {
190
...globals.browser,
191
'Engine': true,
192
'$GODOT_CONFIG': true,
193
'$GODOT_PROJECT_NAME': true,
194
'$GODOT_THREADS_ENABLED': true,
195
'___GODOT_THREADS_ENABLED___': true,
196
},
197
},
198
rules: {
199
...htmlPlugin.configs.recommended.rules,
200
'@html-eslint/indent': ['error', 'tab'],
201
'@html-eslint/require-closing-tags': ['error', { 'selfClosing': 'never' }],
202
'no-alert': 'off',
203
'no-console': 'off',
204
},
205
},
206
207
{
208
ignores: [
209
'**/eslint.config.cjs',
210
'**/.eslintrc*.js',
211
'**/*.externs.js',
212
],
213
},
214
];
215
216