-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Carl Markham
committed
Sep 25, 2024
1 parent
1c4d0bc
commit be5f5c0
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { switchOrSeveritySchema } from '../schemas' | ||
import Schema from '../schema' | ||
import Rule from '../rule' | ||
import { RawSchema, AcceptedSchema } from '../types' | ||
import Document from '../document' | ||
import Line from '../line' | ||
|
||
export default class NoFullStop implements Rule { | ||
public readonly name: string = 'no-full-stop' | ||
|
||
public readonly acceptedSchema: AcceptedSchema = switchOrSeveritySchema | ||
|
||
public readonly schema: Schema | ||
|
||
public constructor(rawSchema: RawSchema) { | ||
this.schema = new Schema(rawSchema) | ||
} | ||
|
||
public async run(document: Document): Promise<void> { | ||
document.lines.forEach((line: Line, index: number): void => { | ||
const trimmed = line.text.trimEnd() | ||
if (trimmed[trimmed.length - 1] === '.') { | ||
document.addError(this.name, `Line ends with a full stop.`, { | ||
line: index + 1, | ||
column: (line.keyword + trimmed).length, | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
public async fix(document: Document): Promise<void> { | ||
document.lines.forEach((line: Line, index: number): void => { | ||
const trimmed = line.text.trimEnd() | ||
if (trimmed[trimmed.length - 1] === '.') { | ||
document.lines[index].text = trimmed.substring(0, trimmed.length - 1) | ||
} | ||
}) | ||
|
||
await document.regenerate() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Feature: No Full Stop | ||
|
||
Scenario: Contains Full Stop | ||
Given the following feature file | ||
""" | ||
Feature: Some feature | ||
When I do something | ||
Then something has happened. | ||
""" | ||
When Gherklin is ran with the following configuration | ||
| rules | | ||
| {"no-full-stop": "error"} | | ||
Then there is 1 files with errors | ||
And the errors are | ||
| location | severity | rule | message | | ||
| {"line": 3, "column": 28} | error | no-full-stop | Line ends with a full stop. | | ||
|
||
Scenario: Contains Full Stop with Trailing Spaces | ||
|
||
If editing this file, be aware that line 26 is supposed to have 3 trailing spaces | ||
|
||
Given the following feature file | ||
""" | ||
Feature: Some feature | ||
When I do something | ||
Then something has happened. | ||
""" | ||
When Gherklin is ran with the following configuration | ||
| rules | | ||
| {"no-full-stop": "error"} | | ||
Then there is 1 files with errors | ||
And the errors are | ||
| location | severity | rule | message | | ||
| {"line": 3, "column": 28} | error | no-full-stop | Line ends with a full stop. | | ||
|
||
Scenario: Auto fix | ||
Given the following feature file | ||
""" | ||
Feature: Some feature | ||
When I do something | ||
Then something has happened. | ||
""" | ||
When Gherklin is ran with the following configuration | ||
| rules | fix | | ||
| {"no-full-stop": "error"} | true | | ||
Then there are 0 files with errors |