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

Implement the beautifier #1

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
version: "2"
checks:
argument-count:
enabled: true
config:
threshold: 3
complex-logic:
enabled: true
config:
threshold: 4
file-lines:
enabled: false
config:
threshold: 250
method-complexity:
enabled: true
config:
threshold: 5
method-count:
enabled: true
config:
threshold: 20
method-lines:
enabled: true
config:
threshold: 50
nested-control-flow:
enabled: true
config:
threshold: 4
return-statements:
enabled: true
config:
threshold: 4
similar-code:
enabled: true
config:
threshold: #language-specific defaults. overrides affect all languages.
identical-code:
enabled: true
config:
threshold: #language-specific defaults. overrides affect all languages.
exclude_patterns:
- "dist/"
- "**/node_modules/"
- "/test/"
- "**/*.d.ts"
plugins:
fixme:
enabled: true
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Project
dist/

# Logs
logs
*.log
Expand All @@ -20,7 +23,7 @@ coverage
# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
Expand All @@ -29,14 +32,14 @@ bower_components
# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
# TypeScript v1 declaration files
typings/

# Optional npm cache directory
Expand All @@ -56,4 +59,3 @@ typings/

# dotenv environment variables file
.env

2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!dist/**/*
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
env:
global:
- CC_TEST_REPORTER_ID=

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
Author

Choose a reason for hiding this comment

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

Thanks! Committed

language: node_js
node_js:
- "8"
- "10"
os:
- linux
- osx
cache:
directories:
- node_modules
before_script:

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
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?

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
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
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..

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
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

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
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
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

- npm install -g elm-format
- which elm-format
- elm-format --help
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter;
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-darwin-amd64 > ./cc-test-reporter;
lassik marked this conversation as resolved.
Show resolved Hide resolved
else
echo Error:TRAVIS_OS_NAME && exit 1;
fi
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
script:

lassik marked this conversation as resolved.
Show resolved Hide resolved
- npm test
after_script:
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
notifications:
email:
on_success: never
on_failure: change
16 changes: 16 additions & 0 deletions .unibeautifyrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
TypeScript:
beautifiers: ["Prettier"]
align_assignments: false
arrow_parens: "as-needed"
break_chained_methods: true
end_with_comma: true
end_with_semicolon: true
indent_char: " "
indent_size: 2
jsx_brackets: false
multiline_ternary: true
object_curly_spacing: true
quotes: "double"
space_after_anon_function: false
wrap_line_length: 80
Empty file added CHANGELOG.md
Empty file.
Empty file added CODE_OF_CONDUCT.md
Empty file.
Empty file added CONTRIBUTING.md
Empty file.
21 changes: 0 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
MIT License
lassik marked this conversation as resolved.
Show resolved Hide resolved

Copyright (c) 2018 Unibeautify

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
# beautifier-elm-format
Elm-format beautifier for Unibeautify

[![Build Status](https://travis-ci.com/Unibeautify/beautifier-elm-format.svg?branch=master)](https://travis-ci.com/Unibeautify/beautifier-elm-format) [![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovateapp.com/)

> [elm-format](https://github.com/avh4/elm-format) beautifier for [Unibeautify](https://github.com/Unibeautify)

## Installation

```bash
npm install --global @unibeautify/beautifier-elm-format
```

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md)

## Usage

See [`unibeautify-cli`](https://github.com/Unibeautify/unibeautify-cli) for details.
11 changes: 11 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"use strict";

module.exports = {
transform: {
"^.+\\.tsx?$": "ts-jest"
},
testRegex: "test/.+\\.(test|spec)\\.ts$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
collectCoverage: true,
coverageReporters: ["json", "lcov", "text", "html"]
};
Loading