Skip to content

Latest commit

 

History

History
132 lines (106 loc) · 4.31 KB

README.md

File metadata and controls

132 lines (106 loc) · 4.31 KB

@peggyjs/eslint-plugin

An eslint plugin to check peggy grammars.

Usage

Install with:

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

Add to your .eslintrc.js file:

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

You can also use "plugin:@peggyjs/all" or 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",
      },
    },
  ],
};

Or, if you are using ESLint Flat configs, add this to your eslint.config.js file:

// ESM
import peggylint from "@peggyjs/eslint-plugin/lib/flat/recommended.js"
export default [
  peggyLint,
];

Or:

// CommonJS
module.exports = [
  ...require("@peggyjs/eslint-plugin/lib/flat/recommended.js"),
];

VSCode

If you are using VSCode, you might be interested in these for your .vscode/settings.json file:

{
  "eslint.validate": [
    "javascript",
    "peggy",
    "typescript"
  ],
  "eslint.experimental.useFlatConfig": true
}

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/semantic-predicate-must-return Semantic predicates must have a return statement. ⭐️
@peggyjs/semi Enforce consistent semicolon usage. ✒️ ⭐️
@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. ✒️ ⭐️
@peggyjs/valid-imports All imports must point to correct JS files, compiled by Peggy 4.0.0 or later, which export the expected rule name as an allowedStartRule. ⭐️

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