forked from godotengine/godot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @godot/eslint-plugin-ignore-c-preprocessors
- Loading branch information
Showing
10 changed files
with
282 additions
and
30 deletions.
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
misc/node/eslint-plugin-ignore-c-preprocessors/index.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
misc/node/eslint-plugin-ignore-c-preprocessors/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"include": [ | ||
"./*.js", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.