npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gherklin

v1.0.1

Published

A linter for Gherkin syntax

Downloads

572

Readme

Contents

Installation

Gherklin can be installed either via NPM or Yarn

npm install gherklin
yarn add gherklin

Usage

Bin script

Gherklin includes a bin file, which can be ran with the following

npx tsx ./node_modules/.bin/gherklin

API

Gherklin also has an API that can be invoked. A simple example of which is:

import { Runner } from 'gherklin'

;(async () => {
  const runner = new Runner()
  const init = await runner.init()
  if (!init.success) {
    throw init.schemaErrors
  }
  const result = await runner.run()
  if (!result.success) {
    process.exit(1)
  }
  process.exit(0)
})()

Configuration

Gherklin will look for a gherklin.config.ts file in the same directory as your package.json file.

This file should default export an object, which contains the parameters for Gherklin.

Example

export default {
  featureDirectory: './features',
  customRulesDirectory: './custom-rules',
  rules: {
    'allowed-tags': 'off',
  },
}

| Parameter | Type | Description | |-------------------------------|----------|--------------------------------------------| | featureDirectory (required) | string | The folder where your Gherkin features are | | customRulesDirectory | string | The directory where your custom rules are | | rules | object | Configuration per rule |

rules contains the configuration for each rule, whether built in or custom. Check rules for a list of built in rules.

Disabling Rules

Gherklin rules can be disabled on a per line or per file basis.

Adding gherklin-disable at the top of a file in a comment will disable Gherklin rules for that file.

Example

# gherklin-disable
Feature: All disabled

  Scenario: Nothing here will be linted

Adding gherklin-disable-next-line will disable Gherklin for the next line.

Example

Feature: The below tag is invalid
  # gherklin-disable-next-line
  @invalid-tag
  Scenario: The above tag is invalid

While gherklin-disable works for every rule, gherklin-disable-next-line only works for rules where it makes sense. For example, using gherklin-disable-next-line does not make sense for the no-empty-file rule.

You can also disable specific rules for the file, using the # gherklin-disable rule-name.

Example

# gherklin-disable allowed-tags, no-unnamed-scenario
Feature: The below tag is invalid
  @invalid-tag
  Scenario:

Automatic Fixing

Gherklin supports automatic fixing for a small set of rules, usually those to do with whitespace.

To allow Gherklin to automatically fix rules that can be fixed, pass the fix option to your gherklin.config.ts file:

Example

export default {
  ...
  fix: true,
}

Gherklin fixes files before the rules are ran against the file. This is so you can be sure that the fix actually worked.

Custom Rule Fixing

In order to support custom rule fixes, your rule class needs to have a fix method.

This method takes the Document as a parameter.

This method must call document.regenerate() to save the document.

An example can be found with the no-trailing-spaces rule.

Custom Rules

Custom rules can be loaded by setting the customRulesDirectory parameter in your config file.

There are a few things needed to consider for rules:

  • Each file in the directory contains one rule.
  • Each file exports a default class that implements Rule

Schema for rules uses Zod. There are a few different schemas specified in the schemas file, but if you want to create something different, you can use Zod directly. When the rule is loaded, this schema is used to verify the configuration value for the rule.

Generating Custom Rules

Gherklin comes with a generator script that you can use. Running the following will generate the skeleton for a new Rule class:

npx tsx ./node_modules/.bin/gherklin-rule

Reporting

By default, Gherklin outputs to STDOUT. You can change this by specifying the reporter in your gherklin.config.ts file or inline configuration. If no reporter is specified, the STDOUT Reporter will be used.

Currently, the available reporters are STDOUT, HTML and JSON.

Reporter Configuration

| key | description | |---------|-------------------------------------------| | type | The type of reporter (html, json, stdout) | | outFile | The file the report is written to |

Contributing

If you are adding new rules, they must follow the same format as existing rules ( see Custom Rules). Each new rule must have acceptance tests (see testing) and be added to the Rules README.

Testing

Tests use the Mocha Test Framework and live in the tests directory.

Tests can be ran with npm test.