Skip to content
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

Not working with ESLint 9. #5

Open
dannyniu opened this issue Jan 14, 2025 · 2 comments
Open

Not working with ESLint 9. #5

dannyniu opened this issue Jan 14, 2025 · 2 comments

Comments

@dannyniu
Copy link

dannyniu commented Jan 14, 2025

I've configured this plugin with the following configuration file in ESLint 9:

import globals from "globals";
import pluginJs from "@eslint/js";

import html from "eslint-plugin-html";
import php from "eslint-plugin-php-markup"

/** @type {import('eslint').Linter.Config[]} */
export default [
  {languageOptions: { globals: globals.browser }},
  pluginJs.configs.recommended,
  {files: ["**/*.js"], languageOptions: {sourceType: "script"}},
  {files: ["**/*.php", "**/*.html"], plugins: { html, php }, 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
  }},
  {
    "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"
    },
  },
];

And try to lint this PHP file:

<script>
foo = 2;
console.log(bar);
var v = "<?php echo "123"; ?>";
</script>

And I got this on my command line:

$ npx eslint sandbox/eslint.php

/Users/dannyniu/sandbox/eslint.php
  4:22  error  Parsing error: Unexpected token 123

✖ 1 problem (1 error, 0 warnings)

Environment:

$ node --version ; npm --version ; npm list
v20.18.1
9.9.3
dannyniu@ /Users/dannyniu
├── @eslint/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
@dannyniu
Copy link
Author

A pull request had been made: #6

@justingolden21
Copy link

Same problem here.

I still get error Parsing error: Unexpected token < in many php files where it's perfectly valid.

My eslint.config.mjs:

import { includeIgnoreFile } from '@eslint/compat'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import html from 'eslint-plugin-html'
import php from 'eslint-plugin-php-markup'
import prettier from 'eslint-plugin-prettier'

// https://eslint.org/docs/latest/use/configure/ignore#including-gitignore-files
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const gitignorePath = path.resolve(__dirname, '.gitignore')

export default [
  includeIgnoreFile(gitignorePath),
  {
    ignores: ['acf-json/'],
    files: ['**/*.{js,html,php}'],
    languageOptions: {
      sourceType: 'module', // Ensures JS is recognized
      globals: { window: 'readonly', document: 'readonly' } // Adds browser globals
    },
    plugins: { html, php },
    // plugins: { prettier, html, php },
    rules: {
      //   'prettier/prettier': 'error', // Enforce Prettier formatting
      'no-console': 'warn' // Warn on console usage
    }
  }
]

Deps:

"devDependencies": {
    "@eslint/compat": "^1.2.5",
    "@jeffreyvr/tailwindcss-tailpress": "^2.0.0",
    "@prettier/plugin-php": "^0.22.4",
    "autoprefixer": "^10.4.13",
    "browser-sync": "^2.26.14",
    "cross-env": "^6.0.3",
    "cypress": "^13.7.0",
    "eslint": "^9.19.0",
    "eslint-config-prettier": "^10.0.1",
    "eslint-plugin-html": "^8.1.2",
    "eslint-plugin-php-markup": "^6.0.0",
    "eslint-plugin-prettier": "^5.2.3",
    "glob": "^11.0.0",
    "laravel-mix": "^6.0.29",
    "postcss": "^8.4.4",
    "postcss-import": "^14.0.0",
    "prettier": "^3.4.2",
    "resolve-url-loader": "^3.1.2",
    "tailwindcss": "^3.4.0"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants