Coder Social home page Coder Social logo

eslint-plugin-esquery's Introduction

eslint-plugin-esquery

This ESLint plugin lets users write simple ESLint rules right in their config by leveraging the power of ESQuery, which is a CSS-selector-like library for ASTs.

Installation

npm install --save-dev eslint-plugin-esquery

Usage

Add "esquery" to your eslint config's "plugins" array, then enable the "eslint/eslint" rule:

{
  "plugins": ["esquery"],
  "rules": {
    "esquery/esquery": "error"
  }
}

This won't do anything unless you specify a config for the rule, though. Give the rule an object where each key is an ESQuery pattern string, and each value is the message to report when that pattern is matched:

{
  "plugins": ["esquery"],
  "rules": {
    "esquery/esquery": ["error", {
      "VariableDeclarator[kind='var']": "Please don't use var.",
      "Identifier[name.length=1]": "Please use a longer identifier name."
    }]
  }
}

If you want a mix of errors and warnings, use the two rules "esquery/esquery-warn" and "esquery/esquery-error" instead:

{
  "plugins": ["esquery"],
  "rules": {
    "esquery/esquery-warn": ["warn", {
      "VariableDeclarator[kind='var']": "Please don't use var."
    }],
    "esquery/esquery-error": ["error", {
      "Identifier[name.length=1]": "Please use a longer identifier name."
    }]
  }
}

If you want the message to be dynamic, use a function that returns a string as the value, instead of a string. You have to use a JS config (.eslintrc.js) instead of a JSON/YAML config to do this.

module.exports = {
  "plugins": ["esquery"],
  "rules": {
    "esquery/esquery": ["error", {
      "Identifier[name.length=1]": (node) =>
        `Please use a longer identifier name, instead of '${node.name}'.`
    }]
  }
}

License

MIT

eslint-plugin-esquery's People

Contributors

dependabot[bot] avatar suchipi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

karlhorky

eslint-plugin-esquery's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.