/peggyjs-eslint-plugin

eslint plugin for Peggy

Primary LanguageTypeScriptMIT LicenseMIT

@peggyjs/eslint-plugin

An eslint plugin to check peggy grammars.

Usage

Install with:

npm install --save-dev @peggyjs/eslint-plugin @peggyjs/eslint-parser eslint

(update this when we publish!)

Add to your .eslintrc.js file:

module.exports = {
  extends: ["plugin:@peggyjs/recommended"],
};

You can also use "plugin:@peggyjs/all" to get ALL of the rules. If you'd like more control:

module.exports = {
  plugins: ["@peggyjs"],
  overrides: [
    {
      files: ["*.peggy", "*.pegjs"],
      parser: "@peggyjs/eslint-parser",
      settings: {
        "@peggyjs/indent": 2,
        "@peggyjs/newline": "\n",
      }
      rules: {
        "@peggyjs/equal-next-line": "error",
        ...
      },
    },
    {
      files: ["**/*.peggy/*.js", "**/*.pegjs/*.js"],
      rules: {
        // Even if you normally want BOMs (which you shouldn't.  Always use
        // UTF-8.), you're not getting one this time.
        "unicode-bom": "off",
      },
    },
  ],
};

Rules

  • ✒️ - Fixable rules.
  • ⭐️ - Recommended rules.
Rule ID Description
@peggyjs/camelCase Rule names should be UpperCamelCase and label names should be lowerCamelCase. ✒️ ⭐️
@peggyjs/equal-next-line Ensure that the equals sign in a rule is in a consistent location. ✒️ ⭐️
@peggyjs/no-empty-code-blocks Code blocks in actions and semantic predicates should not be empty. ✒️ ⭐️
@peggyjs/no-empty-initializers Top-level and per-instance initializers should not be empty. ✒️ ⭐️
@peggyjs/no-unused-labels Labels may not be used without either an action or a semantic predicate to reference them. ✒️ ⭐️
@peggyjs/no-unused-rules All rules except for the first one must be referenced by another rule. ⭐️
@peggyjs/quotes Enforce the consistent use of double or single quotes. ✒️ ⭐️
@peggyjs/rule-order Rule definitions should come after all references to that rule, unless there is a rule loop.
@peggyjs/semi Enforce consistent semicolon usage. ✒️ ⭐️
@peggyjs/semantic-predicate-must-return Semantic predicates must have a return statement. ⭐️
@peggyjs/separate-choices Ensure that each top-level choice in a rule is on a new line. ✒️ ⭐️
@peggyjs/space-ops Consistent spacing around operators and other punctuation. ✒️ ⭐️

Settings

There are several plugin-wide settings that control whitespace insertion.

Other Features

  • Checks the Javascript code embedded in your grammar according to your existing ESlint rules for JS.

Using with Visual Studio Code

Add the following to your project's .vscode/settings.json file:

{
  "eslint.validate": [
    "javascript",
    "peggy"
  ]
}

Tests codecov