eslint-plugin-ast-grep

raw JSON →
1.0.0 verified Sat Apr 25 auth: no javascript

ESLint plugin leveraging ast-grep for pattern-based syntax restriction. Current stable version: 1.0.0. Released under MIT license. Key differentiator: uses ast-grep's powerful pattern matching instead of ESLint's built-in AST selectors, enabling more flexible and concise rule definitions. Requires ESLint >=9.0.0 and @ast-grep/napi >=0.30.0. Provides a single rule `no-restricted-syntax` that accepts string patterns or objects with custom messages. Adheres to ESLint's flat config and is ESM-only.

error Error: Cannot find module 'eslint-plugin-ast-grep'
cause Plugin not installed or not in node_modules.
fix
Run 'npm install -D eslint-plugin-ast-grep'.
error Error: ESLint configuration in .eslintrc is deprecated: Unable to extend from 'plugin:ast-grep/recommended'
cause Using old .eslintrc format; plugin requires ESLint flat config (eslint.config.js).
fix
Migrate to eslint.config.js flat config (see docs).
breaking ESLint plugin with ast-grep requires ESLint 9.0.0 or higher (flat config only).
fix Upgrade ESLint to >=9.0.0 and migrate to flat config.
breaking Plugin is ESM-only; does not support CommonJS require().
fix Use `import` syntax; if in CommonJS project, use dynamic import or switch to ESM.
deprecated The `no-restricted-syntax` rule does not support ESLint's built-in AST selectors; use ast-grep patterns instead.
fix Replace ESLint selectors with ast-grep pattern syntax.
npm install eslint-plugin-ast-grep
yarn add eslint-plugin-ast-grep
pnpm add eslint-plugin-ast-grep

Basic ESLint flat config using the plugin to ban console.log and console.warn via ast-grep patterns.

import plugin from 'eslint-plugin-ast-grep';

export default [
  {
    plugins: { 'ast-grep': plugin },
    rules: {
      'ast-grep/no-restricted-syntax': ['error', 'console.log', 'console.warn']
    }
  }
];