From 34f5d7f30fe4d768ed85ce17fce22230b44c51dd Mon Sep 17 00:00:00 2001 From: DannyNiu/NJF Date: Thu, 16 Jan 2025 15:45:09 +0800 Subject: [PATCH] Updated for ESLint 9.x --- README.md | 30 +++++++++++++++++++++++++++++- lib/index.js | 6 ++++++ lib/settings.js | 1 + package.json | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 544b916..71a71f4 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ npm install --save-dev eslint-plugin-php-markup ## Usage +ESLint 8 and before: + Add `php-markup` to the `plugins` section of your `.eslintrc` configuration file. BTW, it works like a charm together with [`eslint-plugin-html`](https://github.com/BenoitZugmeyer/eslint-plugin-html)! @@ -39,6 +41,32 @@ BTW, it works like a charm together with [`eslint-plugin-html`](https://github.c } ``` -License +ESLint 9 and onward. + +Adapt the following to your `eslint.config.*js` file. + +Note for some reason, custom settings currently doesn't work, and a default setting is applied. + +```js +... +import html from "eslint-plugin-html"; +import php from "eslint-plugin-php-markup"; +... +... { files: ["**/*.php"], + plugins: { html, php }, + processor: php.processor, + settings: { + "php/php-extensions": [".php"], + "php/markup-replacement": {"php": "", "=": "0"}, + "php/keep-eol": false, + "php/remove-whitespace": false, + "php/remove-empty-line": false, + "php/remove-php-lint": false + }, +} ... +... +``` + +# License MIT diff --git a/lib/index.js b/lib/index.js index 541a9dc..f568ca7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -136,6 +136,7 @@ var PHP_MARKUP_EOL = /<\?[\s\S]*?\?>(\r?\n)?/g var ctxIndex = -1 var processor = { preprocess: (text, filename, settings) => { + settings = getSettings(settings); if (typeof text === 'string') { var m, found = false, ms = [] var filteredText = '' @@ -207,6 +208,7 @@ var processor = { } }, postprocess: (messages, filename, settings, hasBOM) => { + settings = getSettings(settings); if (ctxIndex >= 0 && _messages[ctxIndex].filtered.length > 0) { var m = _messages[ctxIndex] remapMessages(m, messages, m.code, settings) @@ -362,3 +364,7 @@ function patch(Linter) { return messages } } + +module.exports = { + processor, +} diff --git a/lib/settings.js b/lib/settings.js index 96107a2..236ff4f 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -7,6 +7,7 @@ const defaultPHPExtensions = [ const defaultPHPMarkupReplacement = { "php": "", "=": "0" } function getSetting(settings, name) { + if (typeof settings !== "object") return null; if (typeof settings.html === "object" && name in settings.html) { return settings.html[name] } diff --git a/package.json b/package.json index b783ec2..985d3f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-php-markup", - "version": "6.0.0", + "version": "6.0.1", "description": "A eslint plugin to process PHP markup", "main": "lib/index.js", "directories": {