cucumber / language-service

Cucumber Language Service
MIT License
12 stars 21 forks source link

Step definitions generated in Python require refactoring #160

Closed kieran-ryan closed 4 months ago

kieran-ryan commented 6 months ago

A step definition generated in Python from a gherkin step, can require the following refactorings:

The unexpected indentation (as flagged by Pylance) prevents execution of Python code; and the remaining errors fail formatters and linters such as black and ruff.

👓 What did you see?

When generating a Python step definition from a gherkin step...

When I eat "<eat>" cucumbers

...the step definition is indented by two spaces and a space is present between the parentheses and the colon of the function declaration.

  @when('I eat {string} cucumbers')
  def step_when(context, string) :
      # This was autogenerated using cucumber syntax.
      # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

Additionally, when generating a Python step definition from a gherkin step containing no parameters...

Then I should have many cucumber

...a trailing comma and space appear after context.

  @then('I should have many cucumber')
  def step_then(context, ) :
      # This was autogenerated using cucumber syntax.
      # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

✅ What did you expect to see?

The step definition is appropriately indented without redundant spaces and commas; as below:

@then('I should have many cucumber')
def step_then(context):
    # This was autogenerated using cucumber syntax.
    # Please convert to use regular expressions, as Behave does not currently support Cucumber Expressions

📦 Which tool/library version are you using?

Version: 1.82.0 (Universal) Commit: 8b617bd08fd9e3fc94d14adb8d358b56e3f72314 Date: 2023-09-06T22:09:41.364Z (2 mos ago) Electron: 25.8.0 ElectronBuildId: 23503258 Chromium: 114.0.5735.289 Node.js: 18.15.0 V8: 11.4.183.29-electron.0 OS: Darwin x64 20.6.0 Cucumber VSCode Extension: 1.8.0

🔬 How could we reproduce it?

  1. Open Visual Studio Code with the Cucumber extension running
  2. Create an empty Python step definition file inside the 'features' directory
  3. Create a feature file containing a step from one of the above examples
  4. Select the step, and click the quick fix to generate a step definition