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.
npm i -D eslint-plugin-phpAdd 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,
},
]);π§ - 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 | π‘ | β |
Contributions are welcome! Please read the contributing guidelines for more information.