eslint-plugin-php
v0.1.0
Published
An ESLint plugin to lint PHP files
Maintainers
Readme
ESLint Plugin PHP
An ESLint plugin to lint PHP files.
[!NOTE]
This is basically a POC for PHP linter using ESLint's new Languages API. It aims to provide a better linting experience than PHP CodeSniffer.
Installation
npm i -D eslint-plugin-phpUsage
Add php as a plugin in your ESLint configuration file,
specify the language for the files you want to lint,
and configure the rules you want to use:
// eslint.config.mjs
import php from 'eslint-plugin-php';
import { defineConfig } from 'eslint/config';
export default defineConfig([
{
files: ['**/*.php'],
plugins: {
php,
},
language: 'php/php',
rules: {
'php/eqeqeq': 'error',
'php/no-array-keyword': 'error',
},
},
]);You can also use the recommended configuration to enable all recommended rules:
// eslint.config.mjs
import php from 'eslint-plugin-php';
import { defineConfig } from 'eslint/config';
export default defineConfig([
{
files: ['./**/*.php'],
...php.configs.recommended,
},
]);Available Rules
🔧 - Automatically fixable by the --fix CLI option.
💡 - Manually fixable by editor suggestions.
✅ - Enabled in the recommended configuration.
| Rule ID | Description | 🔧 | 💡 | ✅ |
| ------------------------- | --------------------------------------------------- | --- | --- | --- |
| php/disallow-references | Disallow the use of references | | 💡 | ✅ |
| php/eqeqeq | Require the use of === and !== | | | ✅ |
| php/no-array-keyword | Disallow the use of the array keyword | 🔧 | | ✅ |
| php/no-final | Disallow using the final keyword | | 💡 | ✅ |
| php/require-visibility | Require visibility for class methods and properties | | 💡 | ✅ |
Contributing
Contributions are welcome! Please read the contributing guidelines for more information.
