Skip to content

Commit

Permalink
added no-empty-file rule (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmarkham authored Sep 13, 2024
1 parent 5aa901a commit 21a6de4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
27 changes: 27 additions & 0 deletions src/rules/no-empty-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { GherkinDocument } from '@cucumber/messages'

import { LintError } from '../error'
import { switchOrSeveritySchema } from '../schemas'
import Rule from '../rule'

/**
* Allowed:
* off | on | error | warn
*/
export const schema = switchOrSeveritySchema

export const run = (rule: Rule, document: GherkinDocument): Array<LintError> => {
const errors: Array<LintError> = []

if (!document) {
errors.push({
message: 'Feature file is empty',
location: {
line: 0,
column: 0,
},
} as LintError)
}

return errors
}
3 changes: 0 additions & 3 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ export default class Runner {

const document = parser.parse(content.toString())
const walk = walker.walkGherkinDocument(document)
if (!document || (document && !document.feature)) {
continue
}

for (const rule of this.rules) {
if (!rule.schema.enabled) {
Expand Down
Empty file.
18 changes: 18 additions & 0 deletions tests/acceptance/features/no-empty-file/valid.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Feature: No Empty File

Scenario: This is valid
Given I do something
When I do something else
Then I should have done something
And I should have done something else
But I shouldn't have done nothing

Scenario Outline: Valid Indentation
When I do each of these things
| <THING> |
Then I should have done something

Examples:
| THING |
| sleep |
| eat |
28 changes: 28 additions & 0 deletions tests/acceptance/no-empty-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import path from 'node:path'
import { Runner, Severity } from '../../src'
import { expect } from 'chai'

describe('No Empty File', () => {
it('returns errors if the rule fails', async () => {
const featureDirectory = path.join(import.meta.dirname, './features/no-empty-file')

const runner = new Runner({
configDirectory: '.',
featureDirectory,
rules: {
'no-empty-file': Severity.warn,
},
})

await runner.init()
const result = await runner.run()

expect(result.success).to.eq(false)
expect(result.errors.size).to.eq(1)
expect(result.errors.has(`${featureDirectory}/valid.feature`)).to.eq(false)

const errors = result.errors.get(`${featureDirectory}/invalid.feature`)
expect(errors.length).to.eq(1)
expect(errors[0].message).to.eq('Feature file is empty')
})
})

0 comments on commit 21a6de4

Please sign in to comment.