Skip to content

Updated for ESLint 9.x #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)!
Expand All @@ -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
6 changes: 6 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -362,3 +364,7 @@ function patch(Linter) {
return messages
}
}

module.exports = {
processor,
}
1 change: 1 addition & 0 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down