enkessler / cuke_linter

A linting tool for Cucumber
MIT License
32 stars 8 forks source link

Add multiple language support #13

Closed thiagotrentin closed 4 years ago

thiagotrentin commented 4 years ago

Subject of the issue The cuke_linter only works in English language to validate the Cucumber keywords (Given, When, Then).

This make it hard to use linter for Gherkin scenarios written in other language, in my case pt-BR.

Your environment cuke_linter (0.12.0) cuke_modeler (2.0.0)

Steps to reproduce Execute cuke_linter against the following feature_file

# language:pt

Funcionalidade: lint
  description

  Cenário: Scenario Outline name
    Dado given step
    Quando when step
    Então then step

Expected behavior No issues detected.

Actual behavior

TestWithNoActionStepLinter
  Test does not have a 'When' step.
    C:/dev/workspace/linter/cuke_linter_validation/features/gherkins/lint.feature:6
TestWithNoVerificationStepLinter
  Test does not have a 'Then' step.
    C:/dev/workspace/linter/cuke_linter_validation/features/gherkins/lint.feature:6

I'd be glad helping to improve this feature

thiagotrentin commented 4 years ago

@enkessler what do you think in something like this? https://github.com/enkessler/cuke_linter/compare/master...thiagotrentin:add_multiple_language_support

enkessler commented 4 years ago

I had thought about that before but left as 'something to do later' https://github.com/enkessler/cuke_linter/blob/dc2c2e522b5d20ae89f13d0bad18c5997a27b514/testing/cucumber/features/linters/test_with_no_action_step.feature#L30

Your approach of configuring keywords globally instead of on a per linter basis is a good idea. I'll look at it more over the weekend.

enkessler commented 4 years ago

My two main thoughts are

  1. If we're going to be dynamic about it and get the relevant keywords from Gherkin itself, I'd rather do it indirectly via CukeModeler because that gem is meant to be an abstraction layer so that other gems (like this one) don't have to worry about API changes in gherkin, which we would be susceptible to if we were to get the dialects directly from it. And, yes, how gherkin exposes its dialects, if it does at all, has changed from version to version.

  2. While inline configuration using Ruby code is an option, I definitely want language/keyword configuration to also be able to be done via the configuration files. Yes, this gem require Ruby to run the executable but it is otherwise language independent and can be used on any feature files, even if the flavor of Cucumber used to run them (e.g. Java, Pythin, C#) differs from user to user. So I want users to be able to use any configurable option via the config files so that they don't need to know Ruby to get use out of the gem.

thiagotrentin commented 4 years ago
  1. If we're going to be dynamic about it and get the relevant keywords from Gherkin itself, I'd rather do it indirectly via CukeModeler because that gem is meant to be an abstraction layer so that other gems (like this one) don't have to worry about API changes in gherkin, which we would be susceptible to if we were to get the dialects directly from it. And, yes, how gherkin exposes its dialects, if it does at all, has changed from version to version.

make sense, what do you suggest in this case?

2. While inline configuration using Ruby code is an option, I definitely want language/keyword configuration to also be able to be done via the configuration files. Yes, this gem require Ruby to run the executable but it is otherwise language independent and can be used on any feature files, even if the flavor of Cucumber used to run them (e.g. Java, Pythin, C#) differs from user to user. So I want users to be able to use any configurable option via the config files so that they don't need to know Ruby to get use out of the gem.

@enkessler what do you think about a global language/dialect configuration for all linters?

would you considering something like this?

AllLinters:
  GherkinLanguage: 'pt'
thiagotrentin commented 4 years ago

@enkessler what do you think about this approach: https://github.com/enkessler/cuke_linter/compare/master...thiagotrentin:gherkin_dialect_config

enkessler commented 4 years ago

would you considering something like this?

AllLinters:
 GherkinLanguage: 'pt'

That's the idea. Alternatively, if we wanted to kick the can down the road regarding how to get at the Gherkin dialects, we could just have the keywords be directly configurable. Something like

AllLinters:
  Given: 
    - Foo
    - Bar
  When:
    - Baz
  Then:
    - Then
thiagotrentin commented 4 years ago

That's the idea. Alternatively, if we wanted to kick the can down the road regarding how to get at the Gherkin dialects, we could just have the keywords be directly configurable. Something like

AllLinters:
  Given: 
    - Foo
    - Bar
  When:
    - Baz
  Then:
    - Then

Great, I'll open a PR with it, thanks!

enkessler commented 4 years ago

@thiagotrentin 0.13.0 is now out, which should solve this issue.

enkessler commented 4 years ago

Closing this in a few days, unless I hear otherwise.