Skip to content

Implement the beautifier - #1

Open
lassik wants to merge 11 commits into
Unibeautify:masterfrom
lassik:master
Open

Implement the beautifier#1
lassik wants to merge 11 commits into
Unibeautify:masterfrom
lassik:master

Conversation

@lassik

@lassik lassik commented Oct 2, 2018

Copy link
Copy Markdown
  • This PR contains one test that passes.
  • elm-format doesn't have any options.
  • The current version of elm-format adds ANSI color codes to the error messages that it outputs to stderr, even when stderr is not a terminal. This is discussed in elm-format issue #372.

@Glavin001
Glavin001 self-requested a review October 2, 2018 23:53
@Glavin001

Copy link
Copy Markdown
Member

The current version of elm-format adds ANSI color codes to the error messages that it outputs to stderr, even when stderr is not a terminal. This is discussed in elm-format issue #372.

Consider using something like: https://www.npmjs.com/package/strip-ansi

@Glavin001 Glavin001 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests currently failing.

@Glavin001 Glavin001 added help wanted Extra attention is needed good first issue Good for newcomers labels Oct 3, 2018
@stevenzeck

Copy link
Copy Markdown

@Glavin001 please give me more access to this so I can add to CodeClimate.

@lassik

lassik commented Oct 3, 2018

Copy link
Copy Markdown
Author

It would be really nice to make do without us caring about ANSI colors. Since this is still work in progress, I'll try to persuade upstream to take care of it so we get plain text output without ANSI.

@stevenzeck

Copy link
Copy Markdown

@lassik I'll add this to the beautifier-template as well, but could you please add a .vscode/launch.json file? You can probably use https://raw.githubusercontent.com/Unibeautify/beautifier-eslint/master/.vscode/launch.json

Comment thread .travis.yml
cache:
directories:
- node_modules
before_script:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to install elm as well

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the Travis build log, at least elm-format --help is running fine when we have only elm-format installed without the rest of the Elm toolchain. Does it show an error somewhere?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the error is being written to stdout for some reason.

"I couldn't figure out what version of Elm you are using!

You should either run elm-format from the directory containing
your elm.json (for Elm 0.19) or elm-package.json (for Elm 0.18),
or tell me which version of Elm with --elm-version=0.19 or --elm-version=0.18

"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome that you noticed that, I didn't notice at all and still can't find it :-D Tried grepping the raw logs of the latest build. Anyway, I think it's saying we need an Elm project file or a command line option to let it know the Elm version. Probably we don't actually need to have that version of Elm installed. I'll try adding --elm-version= to the unit test.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's reporting an error to stdout when you try to format stdin->stdout, we need to file a bug report about that..

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try adding --elm-version= to the unit test.

I would send the projectPath into the beautify method, then include cwd: projectPath in the options

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might work. The latest version of elm-format supports both Elm 0.18 and Elm 0.19. It determines the version based on the presence of elm-package.json (0.18) or elm.json (0.19) in the current directory. That means strictly the current directory only - it doesn't look in parent directories. There's also a command line flag to control the Elm version but that seems like a more difficult solution for end users.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been debating whether elm-format should check the elm version for each file starting at the file and traversing up directories until it finds elm.json or elm-package.json, instead of looking in the current directory. It seems like that would probably be more correct for more cases. What do you think? (In any case, that would be in elm-format 0.8.2 at the earliest)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see you here @avh4. You really care about your project! You already seem to have an issue about this at avh4/elm-format#561 so let's continue discussion there to make sure everyone can find it :) For this plugin, the most useful missing elm-format feature would be using isatty() (in Haskell, queryTerminal) to disable ANSI output when stderr is not going a terminal.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion about Elm version number is ongoing in #2

@Glavin001

Copy link
Copy Markdown
Member

@stevenzeck Try now, you should be an Admin 👍 .

Comment thread .travis.yml Outdated
@@ -0,0 +1,35 @@
env:
global:
- CC_TEST_REPORTER_ID=

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ID is: 0288dbd5e8a04d83f7e4e86710d77c540968fc4e791afe95e5d3aa79e20b90f9

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Committed

Comment thread .travis.yml Outdated
Comment thread .travis.yml Outdated
Comment thread LICENSE

@Glavin001 Glavin001 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests running within Travis CI are currently failing.

@lassik

lassik commented Oct 11, 2018

Copy link
Copy Markdown
Author

To make the test pass, we need to decide how to pass the Elm version number.

@stevenzeck

Copy link
Copy Markdown

Until we do a language version option in Unibeautify core, I think you'll need to have those config json files.

@lassik

lassik commented Oct 11, 2018

Copy link
Copy Markdown
Author

Yeah, I guess we could add an empty elm.json file into the test fixtures to solve the immediate issue.

@lassik

lassik commented Oct 11, 2018

Copy link
Copy Markdown
Author

Then again, maybe the failing test is a good reminder that we have to solve the problem properly at some point.

@Glavin001

Copy link
Copy Markdown
Member

Yeah, I guess we could add an empty elm.json file into the test fixtures to solve the immediate issue.

It may take a little while before I have time to implement Unibeautify/unibeautify#196

I think adding a note in this README that elm.json is required should be sufficient for now, and we can improve this experience in an upcoming release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue Good for newcomers help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants