Skip to content

Latest commit

 

History

History
676 lines (549 loc) · 11.5 KB

rules.md

File metadata and controls

676 lines (549 loc) · 11.5 KB

Rules

allowed-tags

Only permit specified tags

Good: Feature has allowed tags

{
    "allowed-tags": {
        "allow": [
            "@foo",
            "@bar"
        ]
    }
}
# example.feature
@foo @bar
Feature: Some feature

Bad: Feature has not allowed tags

{
    "allowed-tags": {
        "allow": [
            "@baz"
        ]
    }
}
# example.feature
@this-is-not-allowed
Feature: Some feature

filename

Filenames must conform to the specified stype

Good: Snake case

{
    "filename": {
        "style": "snake_case"
    }
}
# this_is_fine.feature
Feature: Some feature

Good: Pascal case

{
    "filename": {
        "style": "PascalCase"
    }
}
# ThisIsFine.feature
Feature: Some feature

Good: Kebab Case

{
    "filename": {
        "style": "kebab-case"
    }
}
# this-is-fine.feature
Feature: Some feature

Good: Camel case

{
    "filename": {
        "style": "camelCase"
    }
}
# thisIsFine.feature
Feature: Some feature

indentation

Ensure consistent indentation

Good: Valid indentation

{
    "indentation": {
        "width": 4,
        "feature": 0,
        "rule": 1,
        "backgroud": 1,
        "scenario": 1,
        "step": 2,
        "table": 3,
        "literalBlock": 2,
        "examples": 2,
        "examplesTable": 3
    }
}
# example.feature
Feature: Foobar
    Scenario: This is a scenario
        Given this is a scenario
        And the indentation is correct
        When I run the linter
        Then it should be fine

Bad: Invalid indentation

{
    "indentation": {
        "width": 4,
        "feature": 0,
        "rule": 1,
        "backgroud": 1,
        "scenario": 1,
        "step": 2,
        "table": 3,
        "literalBlock": 2,
        "examples": 2,
        "examplesTable": 3
    }
}
# example.feature
 Feature: Foobar
   Scenario: This is a scenario
       Given this is a scenario
       And the indentation is incorrect
        When I run the linter
       Then things will not be good

keyword-order

Ensure that keywords are in the correct order

Good: Keywords in correct order

# example.feature
Feature: Foobar
    Scenario: This is a scenario
        Given this is a scenario
        And the indentation is incorrect
        When I run the linter
        Then things will not be good

Bad: Extra when is not allowed

# example.feature
Feature: Foobar
    Scenario: This is a scenario
        Given this is a scenario
        And the indentation is incorrect
        When I run the linter
        Then things will not be good
        When I do something else

Bad: Scenarios cannot start with Then

# example.feature
Feature: Foobar
    Scenario: This is a scenario
        Then things will not be good

Bad: Scenarios cannot start with And

# example.feature
Feature: Foobar
    Scenario: This is a scenario
        And things will not be good

Good: Tolerate then before when with config option

{
    "keyword-order": {
        "tolerateThenBeforeWhen": true
    }
}
# example.feature
Feature: Foobar
    Scenario: This is a scenario
        Given something
        Then an exception should be thrown
        When I do this

no-background-with-single-scenario

Backgrounds are only allowed when there is more than one scenario

Good: Background with more than one scenario

# example.feature
Feature: Foobar
    Background:
        Given I have stuff

    Scenario: One
    Scenario: Two

Bad: Background with one scenario

# example.feature
Feature: Foobar
    Background:
        Given I have stuff

    Scenario: One

no-consecutive-empty-lines

Do not permit consecutive empty lines

Good: No consecutive empty lines

# example.feature
Feature: Foo

    Scenario: One

    Scenario: Two

    Scenario: Three

Bad: Consecutive empty lines

# example.feature
Feature: Foo


    Scenario: One

    Scenario: Two


    Scenario: Three

no-restricted-patterns

Dissallow text matching any of the given patterns

Bad: Disallow the term "Client"

{
    "no-restricted-patterns": {
        "patterns": [
            "\/client\/i"
        ]
    }
}
# example.feature
Feature: Client

no-duplicate-tags

Disallow duplicate tags

Good: No duplicate tags

# example.feature
@foo @bar
Feature: Some feature

Bad: Duplicated tags

# example.feature
@foo @foo
Feature: Some feature

no-duplicated-feature-names

Dissallow duplicated feature names

Good: Feature with unique title

# example.feature
Feature: this feature title is one of a kind

no-duplicated-scenario-names

Dissallow duplicated scenarios within feature files

Good: No duplicated scenarios

# example.feature
Feature: Foobar
    Scenario: One

    Scenario: Two

Bad: Duplicated scenarios

# example.feature
Feature: Foobar
    Scenario: One

    Scenario: One

no-empty-background

Disallow empty backgrounds

Good: Non-empty background

# example.feature
Feature: Foobar
    Background:
        Given something happened

Bad: Empty background

# example.feature
Feature: Foobar
    Background:

no-empty-file

Disallow empty files

Good: Non-empty file

# example.feature
Feature: Foobar

Bad: Empty file

# example.feature
   

no-empty-scenarios

Disallow empty scenarios

Bad: Scenarios that are empty

# example.feature
Feature: Example
    Scenario: One
    Scenario: Two

Good: Scenarios that are not empty

# example.feature
Feature: Example
    Scenario: One
        When I do this
        Then this should happen

    Scenario: Two
        When I do this
        Then this should happen

no-homogenous-tags

If a tag exists on each scenarion then it should be moved to the feature level

Good: No tags are present on all scenarios

# example.feature
Feature: Good feature
    @one
    Scenario: One
    
    @two
    Scenario: Two
    
    @three
    Scenario: Three

Bad: One tag is present in all scenarios

# example.feature
Feature: Bad feature
    @one
    Scenario: One
    
    @two @one
    Scenario: Two
    
    @three @one
    Scenario: Three

no-superflous-tags

Do not repeat tags in scenarios that are already present at the feature level

Good: No superflous tags

# example.feature
@important
Feature: Foobar

    @this-there @is @no-waste
    Scenario: No waste

Bad: Tag that is repeated in the Feature

# example.feature
@important
Feature: Foobar

    @this-there @is @no-waste @important
    Scenario: No waste

no-trailing-spaces

Do not allow extra spaces at the end of lines

Good: No trailing spaces

# example.feature
Feature: Foobar

There are no trailing spaces on this line

Bad: Trailing spaces

# example.feature
Feature: Foobar

There are trailing spaces on this line    

Bad: Trailing spaces

# example.feature
Feature: Foobar
 
There are trailing spaces above

no-unnamed-features

Do not allow Feature declarations with no name

Good: Feature with a name

# example.feature
Feature: This feature has a name!

Bad: Feature with no name

# example.feature
Feature:

one-space-between-tags

Only allow one space between tags

Good: Tags have one space between them

# example.feature
@tag1 @tag2 @tag3
Feature: Foobar
    @tag4 @tag5
    Scenario: Barfoo

Good: Tags have one space between them

# example.feature
@tag1
@tag2
@tag3
Feature: Foobar

Bad: Tags have more than one space between them

# example.feature
@tag1   @tag2  @tag3
Feature: Foobar

Bad: Tags have more than one space between them

# example.feature
Feature: Foobar
    @tag1    @tag2
    Scenario: Barfoo

scenario-size

Limit the number of steps in a scenario

Good: Valid number of steps

# example.feature
Feature: This is feature
    Scenario: This is scenario
        Given I did this
        When I do that
        Then this should happen

Bad: Too many steps!

{
    "scenario-size": {
        "maxSteps": 3
    }
}
# example.feature
Feature: This is feature
    Scenario: This is scenario
        Given I did this
        And that
        And something else
        When I do that
        Then this should happen

scenarios-per-file

Set a maximum (and/or minimum) number of scenarios allowed per file

Good: Valid quantity of scenarios

{
    "scenarios-per-file": {
        "min": 1,
        "max": 3
    }
}
# example.feature
Feature: One
    Scenario: One
    Scenario: Two
    Scenario: Three

Bad: Too many scenarios

{
    "scenarios-per-file": {
        "min": 0,
        "max": 1
    }
}
# example.feature
Feature: One
    Scenario: First scenario
    Scenario: Two

Bad: Not enough scenarios

{
    "scenarios-per-file": {
        "min": 5,
        "max": 10
    }
}
# example.feature
Feature: One
    Scenario: One