Previously, I used .eslintrc.json
setting with ESLint, using the eslint-plugin-html
and the eslint-plugin-php-markup
plugins to work through the PHP code. Here’s my previous setting:
{
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"overrides": [
],
"parserOptions": {
"ecmaVersion": "latest"
},
"rules": {
"no-redeclare": "warn",
"no-unused-vars": "warn",
"no-redeclare": "warn",
"no-extra-semi": "off",
"no-empty": "off",
"no-inner-declarations": "off",
"no-useless-escape": "off"
},
"plugins": [ "html", "php-markup" ],
"settings": {
"php": {
"php-extensions": [ ".php" ],
"markup-replacement": { "php": "", "=": "0" },
"keep-eol": false,
"remove-whitespace": false,
"remove-empty-line": false,
"remove-php-lint": false
}
}
}
Now that I’ve upgraded to ESLint 9.11, the setting was automatically migrated to eslint.config.mjs
, here’s my new settings:
import html from "eslint-plugin-html";
import phpMarkup from "eslint-plugin-php-markup";
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});
export default [...compat.extends("eslint:recommended"), {
plugins: {
html,
"php-markup": phpMarkup,
},
files: ["**/*.{php,js,html,htm}"],
languageOptions: {
globals: {
...globals.browser,
},
ecmaVersion: "latest",
sourceType: "script",
},
settings: {
"php-markup": {
"php-extensions": [".php"],
"markup-replacement": {
php: "",
"=": "0",
},
"keep-eol": false,
"remove-whitespace": false,
"remove-empty-line": false,
"remove-php-lint": false,
},
},
rules: {
"no-redeclare": "warn",
"no-unused-vars": "warn",
"no-extra-semi": "off",
"no-empty": "off",
"no-inner-declarations": "off",
"no-useless-escape": "off",
},
}];
However, I can no longer lint my PHP files anymore. With the existing settings, ESLint just throw up valid JS-embedded PHP constructs as syntax errors.
How can I make PHP work with ESLint 9.11?