Skip to content

Commit

Permalink
Merge pull request #8 from johngluckmdsol/feature/custom_linters
Browse files Browse the repository at this point in the history
Feature/custom linters
  • Loading branch information
lindt authored Aug 24, 2017
2 parents a54108a + a924023 commit 073c604
Show file tree
Hide file tree
Showing 57 changed files with 757 additions and 122 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Gemfile.lock
.bundle
.idea
tmp
20 changes: 19 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Metrics/ClassLength:
# URISchemes: http, https
Metrics/LineLength:
Max: 116

Exclude:
- "**/*_spec.rb"
# Offense count: 1
# Configuration parameters: CountComments.
Metrics/MethodLength:
Expand All @@ -33,3 +34,20 @@ Metrics/MethodLength:
Style/NumericPredicate:
Exclude:
- 'lib/gherkin_lint/linter/file_name_differs_feature_name.rb'

Metrics/ModuleLength:
Exclude:
- "**/*_spec.rb"

Metrics/BlockLength:
Exclude:
- "**/*_spec.rb"

Layout/IndentationWidth:
Exclude:
- "**/*_spec.rb"

Layout/IndentHeredoc:
Exclude:
- "**/*_spec.rb"

1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ gem 'gherkin', '>=4.0.0'
# TODO: update to gherkin4 gem 'gherkin_format'
# TODO: update to gherkin4 gem 'gherkin_language'
gem 'rake'
gem 'rspec'
gem 'rubocop'
gem 'term-ansicolor'
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ This tool lints gherkin files.

run `gherkin_lint` on a list of files

gherkin_lint FEATURE_FILES
gherkin_lint -f '<wild_card_path>' #default is `features/**/*.feature`

With `--disable CHECK` or `--enable CHECK` it's possible to disable respectivly enable program wide checks.
With `--disable CHECK` or `--enable CHECK` it's possible to disable respectivly enable program wide checks except when a linter requires additional values to be set in order to be valid. Currently only RequiredTagStartsWith meets this criteria.

Checks could be disabled using tags within Feature Files. To do so, add @disableCHECK.
Detailed usage within the [disable_tags](https://github.com/funkwerk/gherkin_lint/blob/master/features/disable_tags.feature) feature.
Expand Down Expand Up @@ -45,6 +45,7 @@ This will mount the current directory within the Gherkin Lint Docker Container a
- [missing scenario name](https://github.com/funkwerk/gherkin_lint/blob/master/features/missing_scenario_name.feature)
- [missing test action](https://github.com/funkwerk/gherkin_lint/blob/master/features/missing_test_action.feature)
- [missing verification](https://github.com/funkwerk/gherkin_lint/blob/master/features/missing_verification.feature)
- [required tag starts with](https://github.com/funkwerk/gherkin_lint/blob/master/features/required_tag_starts_with.feature) - disabled by default
- [same tag for all scenarios](https://github.com/funkwerk/gherkin_lint/blob/master/features/same_tag_for_all_scenarios.feature)
- [tag used multiple times](https://github.com/funkwerk/gherkin_lint/blob/master/features/tag_used_multiple_times.feature)
- [too clumsy](https://github.com/funkwerk/gherkin_lint/blob/master/features/too_clumsy.feature)
Expand Down Expand Up @@ -77,3 +78,6 @@ Install it with:
`sudo gem install gherkin_lint`

After that `gherkin_lint` executable is available.

## Configuration
If you have a custom configuration you'd like to run on a regular basis instead of passing enable and disable flags through the CLI on every run, you can configure a ```.gherkin_lint.yml``` file that will be loaded on execution. The format and available linters are in [```config/default.yml```](config/default.yml)
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ task :language do
end

task :self_check do
disabled_checks = %w(
disabled_checks = %w[
UnknownVariable
BadScenarioName
)
]
sh "RUBYLIB=lib ./bin/gherkin_lint --disable #{disabled_checks.join ','} features/*.feature"
end
12 changes: 10 additions & 2 deletions bin/gherkin_lint
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ OptionParser.new do |opts|
opts.on('--disable [CHECKS]', 'Disabled checks. Separated by ","') do |checks|
options[:disable] = checks.split(',')
end
opts.on('-f', '--filepath [file/s]', 'File path where features are located') do |file|
options[:files] = file
end
end.parse!

linter = GherkinLint::GherkinLint.new

linter.disable options[:disable] if options.key? :disable
linter.enable options[:enable] if options.key? :enable
linter.set_linter

options[:files] = 'features/**/*.feature' if options[:files].nil?
files = Dir.glob(options[:files])

ARGV.each { |file| linter.analyze file }
files.each do |file|
linter.analyze file
end

exit linter.report
58 changes: 58 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
AvoidOutlineForSingleExample:
Enabled: true
AvoidPeriod:
Enabled: true
AvoidScripting:
Enabled: true
BackgroundDoesMoreThanSetup:
Enabled: true
BackgroundRequiresMultipleScenarios:
Enabled: true
BadScenarioName:
Enabled: true
BeDeclarative:
Enabled: true
FileNameDiffersFeatureName:
Enabled: true
MissingExampleName:
Enabled: true
MissingFeatureDescription:
Enabled: true
MissingFeatureName:
Enabled: true
MissingScenarioName:
Enabled: true
MissingTestAction:
Enabled: true
MissingVerification:
Enabled: true
InvalidFileName:
Enabled: true
InvalidStepFlow:
Enabled: true
RequiredTagsStartsWith:
Enabled: false
SameTagForAllScenarios:
Enabled: true
TagUsedMultipleTimes:
Enabled: true
TooClumsy:
Enabled: true
TooManyDifferentTags:
Enabled: true
TooManySteps:
Enabled: true
TooManyTags:
Enabled: true
TooLongStep:
Enabled: true
UniqueScenarioNames:
Enabled: true
UnknownVariable:
Enabled: true
UnusedVariable:
Enabled: true
UseBackground:
Enabled: true
UseOutline:
Enabled: true
3 changes: 2 additions & 1 deletion features/avoid_outline_for_single_example.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ Feature: Avoid Outline for single Example
so that it's easier to reuse verification steps

Background: Prepare Testee

Given a file named "lint.rb" with:
"""
$LOAD_PATH << '../../lib'
require 'gherkin_lint'
linter = GherkinLint::GherkinLint.new
linter.enable %w(AvoidOutlineForSingleExample)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand Down Expand Up @@ -52,5 +54,4 @@ Feature: Avoid Outline for single Example
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""
2 changes: 1 addition & 1 deletion features/avoid_period.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Avoid Period
linter = GherkinLint::GherkinLint.new
linter.enable %w(AvoidPeriod)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand Down Expand Up @@ -45,5 +46,4 @@ Feature: Avoid Period
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""
2 changes: 1 addition & 1 deletion features/avoid_scripting.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Avoid Scripting
linter = GherkinLint::GherkinLint.new
linter.enable %w(AvoidScripting)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand Down Expand Up @@ -65,5 +66,4 @@ Feature: Avoid Scripting
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""
2 changes: 1 addition & 1 deletion features/background_does_more_than_setup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Background Does More Than Setup
linter = GherkinLint::GherkinLint.new
linter.enable %w(BackgroundDoesMoreThanSetup)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand Down Expand Up @@ -42,5 +43,4 @@ Feature: Background Does More Than Setup
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""
2 changes: 1 addition & 1 deletion features/background_requires_scenario.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Background Requires Scenario
linter = GherkinLint::GherkinLint.new
linter.enable %w(BackgroundRequiresMultipleScenarios)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand Down Expand Up @@ -53,5 +54,4 @@ Feature: Background Requires Scenario
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""
2 changes: 1 addition & 1 deletion features/bad_scenario_name.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Bad Scenario Name
linter = GherkinLint::GherkinLint.new
linter.enable %w(BadScenarioName)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand Down Expand Up @@ -49,5 +50,4 @@ Feature: Bad Scenario Name
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""
2 changes: 1 addition & 1 deletion features/be_declarative.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Be Declarative
linter = GherkinLint::GherkinLint.new
linter.enable %w(BeDeclarative)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand Down Expand Up @@ -49,5 +50,4 @@ Feature: Be Declarative
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""
3 changes: 1 addition & 2 deletions features/disable_tags.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Disable Tags
linter = GherkinLint::GherkinLint.new
linter.enable %w(InvalidStepFlow)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand Down Expand Up @@ -54,7 +55,6 @@ Feature: Disable Tags
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""

Scenario: Disable on Feature Level
Expand All @@ -73,5 +73,4 @@ Feature: Disable Tags
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""
4 changes: 2 additions & 2 deletions features/file_name_differs_feature_name.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: File Name Differs Feature Name
linter = GherkinLint::GherkinLint.new
linter.enable %w(FileNameDiffersFeatureName)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand All @@ -37,7 +38,6 @@ Feature: File Name Differs Feature Name
When I run `ruby lint.rb lint.feature`
Then it should pass with exactly:
"""
"""

Examples: Valid Names
Expand All @@ -54,6 +54,7 @@ Feature: File Name Differs Feature Name
linter = GherkinLint::GherkinLint.new
linter.enable %w(FileNameDiffersFeatureName)
linter.set_linter
linter.analyze 'lint_test.feature'
exit linter.report
Expand All @@ -65,7 +66,6 @@ Feature: File Name Differs Feature Name
When I run `ruby lint.rb lint_test.feature`
Then it should pass with exactly:
"""
"""

Examples: Valid Names
Expand Down
2 changes: 1 addition & 1 deletion features/invalid_file_name.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Feature: Invalid File Name
linter = GherkinLint::GherkinLint.new
linter.enable %w(InvalidFileName)
linter.set_linter
ARGV.each { |file| linter.analyze file }
exit linter.report
Expand Down Expand Up @@ -46,5 +47,4 @@ Feature: Invalid File Name
When I run `ruby lint.rb lint.feature`
Then it should pass with exactly:
"""
"""
2 changes: 1 addition & 1 deletion features/invalid_step_flow.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Invalid Step Flow
linter = GherkinLint::GherkinLint.new
linter.enable %w(InvalidStepFlow)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand Down Expand Up @@ -81,5 +82,4 @@ Feature: Invalid Step Flow
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""
3 changes: 1 addition & 2 deletions features/missing_example_name.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Missing Example Name
linter = GherkinLint::GherkinLint.new
linter.enable %w(MissingExampleName)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand Down Expand Up @@ -57,7 +58,6 @@ Feature: Missing Example Name
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""

Scenario: Valid Example
Expand All @@ -83,5 +83,4 @@ Feature: Missing Example Name
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""
2 changes: 1 addition & 1 deletion features/missing_feature_description.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Feature: Missing Feature Description
linter = GherkinLint::GherkinLint.new
linter.enable %w(MissingFeatureDescription)
linter.set_linter
linter.analyze 'lint.feature'
exit linter.report
Expand Down Expand Up @@ -40,5 +41,4 @@ Feature: Missing Feature Description
When I run `ruby lint.rb`
Then it should pass with exactly:
"""
"""
Loading

0 comments on commit 073c604

Please sign in to comment.