diff --git a/index.cjs b/index.cjs new file mode 100644 index 0000000..34ea78b --- /dev/null +++ b/index.cjs @@ -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; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..fe7384a --- /dev/null +++ b/index.mjs @@ -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; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..b7a1e66 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "@godot/eslint-plugin-ignore-c-preprocessors", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@godot/eslint-plugin-ignore-c-preprocessors", + "version": "0.1.0", + "license": "MIT" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..3e9e7aa --- /dev/null +++ b/package.json @@ -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" + } + } +}