Skip to content

Latest commit

Β 

History

History
74 lines (56 loc) Β· 2.5 KB

File metadata and controls

74 lines (56 loc) Β· 2.5 KB

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-php

Usage

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.