Skip to content

Commit

Permalink
Add @godot/eslint-plugin-ignore-c-preprocessors
Browse files Browse the repository at this point in the history
  • Loading branch information
adamscott committed Dec 17, 2024
1 parent 5a18b0f commit 97382da
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 30 deletions.
111 changes: 111 additions & 0 deletions misc/node/eslint-plugin-ignore-c-preprocessors/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// DO NOT EDIT BY HAND. Use `npm run build` to create this file.
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// index.mjs
var eslint_plugin_ignore_c_preprocessors_exports = {};
__export(eslint_plugin_ignore_c_preprocessors_exports, {
default: () => eslint_plugin_ignore_c_preprocessors_default
});
module.exports = __toCommonJS(eslint_plugin_ignore_c_preprocessors_exports);
var plugin = {
meta: {
name: "@godot/eslint-plugin-ignore-c-preprocessors",
version: "0.1.0"
},
processors: {
"ignore-c-preprocessors": {
meta: {
name: "ignore-c-preprocessors",
version: "0.1.0"
},
/**
* @param {string} text
* @param {string} filename
* @returns {[{ text: string, filename: string }]}
*/
preprocess(text, filename) {
const SKIP_TOKENS = [
"include",
"if",
"elif",
"else",
"endif",
"ifdef",
"ifndef",
"define",
"undef",
"line",
"error",
"embed",
"pragma"
];
const skipSymbol = Symbol("skip");
const isString = (x) => {
return typeof x === "string";
};
const textLines = text.split("\n").map(
/** @type {(string): string | unique symbol} */
(line) => {
for (const skipToken of SKIP_TOKENS) {
if (line.replaceAll(" ", "").startsWith(`#${skipToken}`)) {
return skipSymbol;
}
}
return line;
}
).filter(isString).join("\n");
return [
{ text: textLines, filename }
];
},
/**
* @typedef {{
* range: [number, number]
* text: string
* }} Fix
* @typedef {{
* desc?: string
* messageId?: string
* fix: Fix
* }} Suggestion
* @typedef {{
* line?: number
* column?: number
* endLine?: number
* endColumn?: number
* fatal?: boolean
* fix: Fix
* ruleId: string | null
* severity: 0 | 1 | 2
* suggestions?: Suggestion[]
* }} LintMessage
*/
/**
* @param {LintMessage[]} messages
* @param {string} filename
* @returns {LintMessage[]}
*/
postprocess(messages, filename) {
return [].concat(...messages);
},
supportsAutofix: false
}
}
};
var eslint_plugin_ignore_c_preprocessors_default = plugin;
93 changes: 93 additions & 0 deletions misc/node/eslint-plugin-ignore-c-preprocessors/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const plugin = {
meta: {
name: "@godot/eslint-plugin-ignore-c-preprocessors",
version: "0.1.0"
},
processors: {
"ignore-c-preprocessors": {
meta: {
name: "ignore-c-preprocessors",
version: "0.1.0"
},
/**
* @param {string} text
* @param {string} filename
* @returns {[{ text: string, filename: string }]}
*/
preprocess(text, filename) {
const SKIP_TOKENS = [
"include",
"if",
"elif",
"else",
"endif",
"ifdef",
"ifndef",
"define",
"undef",
"line",
"error",
"embed",
"pragma",
]
const skipSymbol = Symbol("skip");
/**
* @param {unknown} x
* @returns {x is string}
*/
const isString = (x) => {
return typeof x === "string";
};
const textLines = text
.split("\n")
.map(/** @type {(string): string | unique symbol} */(line) => {
for (const skipToken of SKIP_TOKENS) {
if (line.replaceAll(" ", "").startsWith(`#${skipToken}`)) {
return skipSymbol;
}
}
return line;
})
.filter(isString)
.join("\n");

return [
{ text: textLines, filename }
];
},
/**
* @typedef {{
* range: [number, number]
* text: string
* }} Fix
* @typedef {{
* desc?: string
* messageId?: string
* fix: Fix
* }} Suggestion
* @typedef {{
* line?: number
* column?: number
* endLine?: number
* endColumn?: number
* fatal?: boolean
* fix: Fix
* ruleId: string | null
* severity: 0 | 1 | 2
* suggestions?: Suggestion[]
* }} LintMessage
*/
/**
* @param {LintMessage[]} messages
* @param {string} filename
* @returns {LintMessage[]}
*/
postprocess(messages, filename) {
return [].concat(...messages);
},
supportsAutofix: false,
}
}
};

export default plugin;
19 changes: 19 additions & 0 deletions misc/node/eslint-plugin-ignore-c-preprocessors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": true,
"name": "@godot/eslint-plugin-ignore-c-preprocessors",
"description": "eslint plugin which skips C preprocessors.",
"version": "0.1.0",
"type": "module",
"module": "index.mjs",
"author": "Godot contributors",
"license": "MIT",
"scripts": {
"build": "npx --yes esbuild index.mjs --bundle --platform=node --target=node16 --banner:js='// DO NOT EDIT BY HAND. Use `npm run build` to create this file.' --outfile=index.cjs"
},
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.cjs"
}
}
}
3 changes: 3 additions & 0 deletions modules/webxr/native/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from "../../../platform/web/eslint.config.cjs";

export default config;
5 changes: 5 additions & 0 deletions modules/webxr/native/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"include": [
"./*.js",
]
}
8 changes: 4 additions & 4 deletions modules/webxr/native/library_godot_webxr.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@

const GodotWebXR = {
$GodotWebXR__deps: [
#if EMSCRIPTEN_VERSION_IS_SMALLER_THAN(3,1,71)
#if EMSCRIPTEN_VERSION_IS_LESS_THAN(3,1,71)
'$Browser',
#else
'$MainLoop',
#endif
'$GL',
'$GodotRuntime',
'$runtimeKeepalivePush',
'$runtimeKeepalivePop'
'$runtimeKeepalivePop',
],
$GodotWebXR: {
gl: null,
Expand Down Expand Up @@ -73,7 +73,7 @@ const GodotWebXR = {
}
},
monkeyPatchRequestAnimationFrame: (enable) => {
#if EMSCRIPTEN_VERSION_IS_SMALLER_THAN(3,1,71)
#if EMSCRIPTEN_VERSION_IS_LESS_THAN(3,1,71)
const MainLoop = Browser;
#endif
if (GodotWebXR.orig_requestAnimationFrame === null) {
Expand All @@ -84,7 +84,7 @@ const GodotWebXR = {
: GodotWebXR.orig_requestAnimationFrame;
},
pauseResumeMainLoop: () => {
#if EMSCRIPTEN_VERSION_IS_SMALLER_THAN(3,1,71)
#if EMSCRIPTEN_VERSION_IS_LESS_THAN(3,1,71)
const MainLoop = Browser.mainLoop;
#endif
// Once both GodotWebXR.session and GodotWebXR.space are set or
Expand Down
5 changes: 5 additions & 0 deletions platform/web/eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const htmlPlugin = require('@html-eslint/eslint-plugin');
const pluginJs = require('@eslint/js');
const pluginReference = require('eslint-plugin-html');
const stylistic = require('@stylistic/eslint-plugin');
const pluginIgnoreCPreprocessors = require("@godot/eslint-plugin-ignore-c-preprocessors").default;

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');
Expand Down Expand Up @@ -140,6 +141,10 @@ module.exports = [
// libraries and modules (browser)
{
files: ['js/libs/**/*.js', 'platform/web/js/libs/**/*.js', 'modules/**/*.js'],
plugins: {
"ignore-c-preprocessors": pluginIgnoreCPreprocessors
},
processor: "ignore-c-preprocessors/ignore-c-preprocessors",
languageOptions: {
globals: {
...globals.browser,
Expand Down
12 changes: 8 additions & 4 deletions platform/web/js/libs/library_godot_macros.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable */
{{{
globalThis.___EMSCRIPTEN_VERSION_PARSED = globalThis.EMSCRIPTEN_VERSION.split(".").map((n) => parseInt(n));
/* eslint-enable */
globalThis.___EMSCRIPTEN_VERSION_PARSED = globalThis.EMSCRIPTEN_VERSION.split('.').map((n) => parseInt(n, 10));

globalThis.___SEMVER_IS_GREATER_THAN = (a, b, { orEqual = false } = {}) => {
const [aMajor, aMinor, aPatch] = a;
Expand All @@ -15,7 +17,7 @@
};

globalThis.EMSCRIPTEN_VERSION_IS_GREATER_THAN = (major, minor, patch) => {
const isGreater = globalThis.___SEMVER_IS_GREATER_THAN(globalThis.___EMSCRIPTEN_VERSION_PARSED, [major, minor, patch]);
const isGreater = globalThis.___SEMVER_IS_GREATER_THAN(globalThis.___EMSCRIPTEN_VERSION_PARSED, [major, minor, patch]);
return isGreater;
};

Expand All @@ -24,13 +26,15 @@
return isGreaterOrEqual;
};

globalThis.EMSCRIPTEN_VERSION_IS_SMALLER_THAN = (major, minor, patch) => {
globalThis.EMSCRIPTEN_VERSION_IS_LESS_THAN = (major, minor, patch) => {
const isGreaterOrEqual = globalThis.___SEMVER_IS_GREATER_THAN(globalThis.___EMSCRIPTEN_VERSION_PARSED, [major, minor, patch], { orEqual: true });
return !isGreaterOrEqual;
};

globalThis.EMSCRIPTEN_VERSION_IS_SMALLER_THAN_OR_EQUAL = (major, minor, patch) => {
globalThis.EMSCRIPTEN_VERSION_IS_LESS_THAN_OR_EQUAL = (major, minor, patch) => {
const isGreater = globalThis.___SEMVER_IS_GREATER_THAN(globalThis.___EMSCRIPTEN_VERSION_PARSED, [major, minor, patch]);
return !isGreater;
};
/* eslint-disable */
}}}
/* eslint-enable */
11 changes: 11 additions & 0 deletions platform/web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 97382da

Please sign in to comment.