ruff-pycharm-plugin: Ruff not running on Reformat Code command

Describe the bug With the “Run ruff when Reformat Code” option is checked, ruff format is not used over the default PyCharm formatter.

To Reproduce Steps to reproduce the behavior:

  1. Enable “Run ruff when Reformat Code” and ensure a ruff executable is picked (for me it was in my local virtual environment)
  2. Use Ctrl/Command + Alt + L or the “Reformat Code” menu option to trigger a code reformat
  3. Notice that ruff was not used to reformat the code and instead the built-in PyCharm formatter was used

Expected behavior Ruff should have been used to format the code. You can tell the difference by manually running ruff from the CLI.

Screenshots If applicable, add screenshots to help explain your problem. Also, gif movies are recommended.

Environments (please complete the following information):

  • IDE: PyCharm Professional 2023.3
  • OS: Windows and macOS
  • Ruff Version 0.1.7
  • Plugin version 0.0.27

Additional context Python 12

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Reactions: 1
  • Comments: 18 (6 by maintainers)

Most upvoted comments

@hgalytoby I can’t reproduce your problem. Have you enabled the Use ruff format ... option in the settings? image

Ruff-issue

I am experiencing the same issue. Here is a gif to show what is occurring.

@hgalytoby I can’t reproduce your problem. Have you enabled the Use ruff format ... option in the settings? image

Thank you, it’s working now.

Could you please try it?

Updated ruff to 0.2.2 and plugin to 0.0.29, and it seems to work for me. Thanks!

@Kroppeb

Mmh, strange I still don’t see ruff working.

If the plugin version 0.0.29 doesn’t work with ruff==0.1, please let me know the details of your environment and code.

@koxudaxi, whoops, somehow missed the reply? I have tried enabling the LSP server setting, and got an error once that Intellij couldn’t stop the language server because it didn’t exist. Not sure if that’s related to this. Also not sure what triggered it, I think I had just restarted pycharm after an unrelated error?

I use windows, I can give you the full information tomorrow.

This still doesn’t work for me. I’m using plugin version 0.0.30, ruff version 0.3.2 and PyCharm 2023.3.4 in Ubuntu. My settings are the same as in your screenshot above.

Hi all, I’ve recently started using ruff (0.2.2) and I’ve also installed the ruff plugins (0.0.27).

I Reformat is not working, but lint is.

20240220_222114

Mmh, strange I still don’t see ruff working.

Hi @koxudaxi , thank you for the tool.

I am not sure if it is the same problem, but here is the crash log (happens on every IDE start):

currently I have ruff==0.1.10 and plugin==0.0.19

Edit: this error seems to be duplicate of https://github.com/koxudaxi/ruff-pycharm-plugin/issues/329#issuecomment-1887068669

ExternalToolPass: 

com.intellij.diagnostic.PluginException: annotator: com.koxudaxi.ruff.RuffExternalAnnotator@4f728d8e (class com.koxudaxi.ruff.RuffExternalAnnotator) [Plugin: com.koxudaxi.ruff]
	at com.intellij.diagnostic.PluginProblemReporterImpl.createPluginExceptionByClass(PluginProblemReporterImpl.java:23)
	at com.intellij.diagnostic.PluginException.createByClass(PluginException.java:89)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.processError(ExternalToolPass.java:259)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doAnnotate(ExternalToolPass.java:207)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doAnnotate(ExternalToolPass.java:198)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.runChangeAware(ExternalToolPass.java:274)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.lambda$run$1(ExternalToolPass.java:176)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:186)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:604)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:679)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:635)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:603)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:173)
	at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:361)
	at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:339)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.run(ExternalToolPass.java:175)
	at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:350)
	at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:340)
	at com.intellij.util.ui.update.MergingUpdateQueue.doExecute(MergingUpdateQueue.java:297)
	at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:280)
	at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:245)
	at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:249)
	at com.intellij.util.Alarm$Request.runSafely(Alarm.java:365)
	at com.intellij.util.Alarm$Request.run(Alarm.java:354)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:272)
	at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:248)
	at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:28)
	at com.intellij.util.concurrency.BoundedTaskExecutor$1.executeFirstTaskAndHelpQueue(BoundedTaskExecutor.java:221)
	at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:227)
	at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:210)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: The following command was executed:

/Users/axelr/pll/venv/bin/ruff --exit-zero --no-cache --force-exclude --no-fix --format json --stdin-filename demo_random.py -

The exit code: 2
The error output of the command:


error: unexpected argument '--format' found

  tip: to pass '--format' as a value, use '-- --format'

Usage: ruff check <FILES|--fix|--no-fix|--unsafe-fixes|--no-unsafe-fixes|--show-source|--no-show-source|--show-fixes|--no-show-fixes|--diff|--watch|--fix-only|--no-fix-only|--ignore-noqa|--output-format <OUTPUT_FORMAT>|--output-file <OUTPUT_FILE>|--target-version <TARGET_VERSION>|--preview|--no-preview|--config <CONFIG>|--select <RULE_CODE>|--ignore <RULE_CODE>|--extend-select <RULE_CODE>|--extend-ignore <RULE_CODE>|--per-file-ignores <PER_FILE_IGNORES>|--extend-per-file-ignores <EXTEND_PER_FILE_IGNORES>|--exclude <FILE_PATTERN>|--extend-exclude <FILE_PATTERN>|--fixable <RULE_CODE>|--unfixable <RULE_CODE>|--extend-fixable <RULE_CODE>|--extend-unfixable <RULE_CODE>|--respect-gitignore|--no-respect-gitignore|--force-exclude|--no-force-exclude|--line-length <LINE_LENGTH>|--dummy-variable-rgx <DUMMY_VARIABLE_RGX>|--no-cache|--isolated|--cache-dir <CACHE_DIR>|--stdin-filename <STDIN_FILENAME>|--exit-zero|--exit-non-zero-on-fix|--statistics|--add-noqa|--show-files|--show-settings|--extension <EXTENSION>|--ecosystem-ci>

For more information, try '--help'.

Error Running Ruff
	at com.koxudaxi.ruff.RuffKt.runCommand(Ruff.kt:191)
	at com.koxudaxi.ruff.RuffKt.runCommand(Ruff.kt:137)
	at com.koxudaxi.ruff.RuffKt.runRuff(Ruff.kt:243)
	at com.koxudaxi.ruff.RuffExternalAnnotator.doAnnotate(RuffExternalAnnotator.kt:54)
	at com.koxudaxi.ruff.RuffExternalAnnotator.doAnnotate(RuffExternalAnnotator.kt:22)
	at com.intellij.codeInsight.daemon.impl.ExternalToolPass.doAnnotate(ExternalToolPass.java:204)
	... 36 more