2.1.2 • Published 2 months ago

@peggyjs/eslint-plugin v2.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

@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 IDDescription
@peggyjs/camelCaseRule names should be UpperCamelCase and label names should be lowerCamelCase.✒️ ⭐️
@peggyjs/equal-next-lineEnsure that the equals sign in a rule is in a consistent location.✒️ ⭐️
@peggyjs/no-empty-code-blocksCode blocks in actions and semantic predicates should not be empty.✒️ ⭐️
@peggyjs/no-empty-initializersTop-level and per-instance initializers should not be empty.✒️ ⭐️
@peggyjs/no-unused-labelsLabels may not be used without either an action or a semantic predicate to reference them.✒️ ⭐️
@peggyjs/no-unused-rulesAll rules except for the first one must be referenced by another rule.⭐️
@peggyjs/quotesEnforce the consistent use of double or single quotes.✒️ ⭐️
@peggyjs/rule-orderRule definitions should come after all references to that rule, unless there is a rule loop.
@peggyjs/semantic-predicate-must-returnSemantic predicates must have a return statement.⭐️
@peggyjs/semiEnforce consistent semicolon usage.✒️ ⭐️
@peggyjs/separate-choicesEnsure that each top-level choice in a rule is on a new line.✒️ ⭐️
@peggyjs/space-opsConsistent spacing around operators and other punctuation.✒️ ⭐️
@peggyjs/valid-importsAll 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

2.1.2

2 months ago

2.1.1

2 months ago

2.1.0

2 months ago

2.0.2

2 months ago

2.0.1

3 months ago

2.0.0

3 months ago

1.1.0

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago