Search code examples
eslintabstract-syntax-treeeslintrc

eslint no-restricted-syntax selector for private methodDefinition


I use eslint on a TypeScript project and have some rule in no-restricted-syntax config that check naming for async method, like :

{
  "selector": "MethodDefinition[value.async=true][key.name!=/Async$/]",
  "message": "Async method name must end in 'Async'"
}

I'm searching for something to verify private function naming. But I can't find a selector to select all private MethodDefinition.


Solution

  • So, I found what I was searching for.

    My answer was in this documentation inside AST Playground part.

    The playground allow me to see all the node information usable in eslint.

    enter image description here

    And then I made my own rule to test private function naming (in my case, the name must start with an underscore) :

    {
      "selector": "MethodDefinition[accessibility=private][key.name!=/^_/]",
      "message": "Private function name must start with _"
    }