Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support formatters that output patch #20

Open
lafrenierejm opened this issue Apr 4, 2020 · 7 comments
Open

Support formatters that output patch #20

lafrenierejm opened this issue Apr 4, 2020 · 7 comments

Comments

@lafrenierejm
Copy link

ShellCheck is an example of a tool that doesn't support writing changes in-place, but does support diff-style output. Example of running shellcheck --format=diff against edx/devstack/course-generator/create-courses.sh:

--- a/create-courses.sh
+++ b/create-courses.sh
@@ -7,21 +7,21 @@
 echo "Parsing options"
 container_error=false
 for arg in "$@"; do
-    if [ $arg == "--studio" ]; then
+    if [ "$arg" == "--studio" ]; then
         if [ ! "$(docker-compose exec lms bash -c 'echo "Course will be created for studio"; exit $?')" ]; then
             echo "Issue with studio container"
             container_error=true
         else
             studio=true
         fi
-    elif [ $arg == "--ecommerce" ]; then
+    elif [ "$arg" == "--ecommerce" ]; then
         if [ ! "$(docker exec -t edx.devstack.ecommerce bash -c 'echo "Course will be created for ecommerce"; exit $?')" ]; then
             echo "Issue with ecommerce container"
             container_error=true
         else
             ecommerce=true
         fi
-    elif [ $arg == "--marketing" ]; then
+    elif [ "$arg" == "--marketing" ]; then
         if [ ! "$(docker exec -t edx.devstack.marketing bash -c 'echo "Course will be created for marketing"; exit $?')" ]; then
             echo "Issue with marketing container. Course creation will proceed without marketing container."
         else
@purcell
Copy link
Owner

purcell commented Apr 5, 2020

Wait, I use ShellCheck all the time, and thought it was only a linter. And its README even says:

ShellCheck does not attempt to enforce any kind of formatting or indenting style, so also check out shfmt!

What am I missing? :-)

@lafrenierejm
Copy link
Author

Wait, I use ShellCheck all the time, and thought it was only a linter. And its README even says:

ShellCheck does not attempt to enforce any kind of formatting or indenting style, so also check out shfmt!

What am I missing? :-)

It is true that its authors don't intend for ShellCheck to be used as a formatter. For some of the problems it can detect, though, ShellCheck is capable of recommending fixes. And one of the output formats ShellCheck supports is diff. That output would be sufficient to be consumed in an automated way, I I find that I typically do want to apply most or all of the fixes ShellCheck is able to recommend, and I I really like the ergonomics of defining formatters using this reformatter, so my first instinct was to check reformatter to see if it supported using diffs.

The feature could feasibly be useful beyond just ShellCheck, so I thought to start a conversation about including it. :) I've started working on a branch to add the feature; if you would rather hold off judgement on the value of the feature until you can demo, I'd be glad to let you know once I have an MVP.

@purcell
Copy link
Owner

purcell commented Apr 5, 2020

The feature could feasibly be useful beyond just ShellCheck, so I thought to start a conversation about including it. :)

It's definitely something I'd consider.

@lafrenierejm
Copy link
Author

@purcell I wasn't able to figure out how to get Emacs to apply a patch in an entirely automated fashion. All of my attempts resulted in Emacs starting an interactive diff session. Do you have suggestions for how to avoid that?

@purcell
Copy link
Owner

purcell commented Apr 21, 2020

There's code floating around for programatically applying RCS-style diffs to the current buffer. That's ultimately what's needed, and ideally not just for RCS-style diffs.

@purcell
Copy link
Owner

purcell commented Apr 21, 2020

ie. the whole point is to walk the diff and then make very minimal edits in the buffer according to what the diff says.

@wyuenho
Copy link
Contributor

wyuenho commented Jul 14, 2020

py-isort, py-autopep8 apply RCS patches too. Would be nice if this package could support it so I don't have to install dozens of packages to format code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants