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 all 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/**/*
29 changes: 29 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
env:
global:
- CC_TEST_REPORTER_ID=0288dbd5e8a04d83f7e4e86710d77c540968fc4e791afe95e5d3aa79e20b90f9
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
- OS_NAME=$(uname | tr A-Z a-z)
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-${OS_NAME}-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build
script:
- 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
29 changes: 29 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "node",
"name": "Jest Tests",
"request": "launch",
"args": [
"--config",
"jest.config.js",
"--runInBand",
"--coverage",
"false"
],
"runtimeArgs": [
"--nolazy"
],
"sourceMaps": true,
"cwd": "${workspaceFolder}",
"protocol": "inspector",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"outFiles": ["${workspaceRoot}/dist/"]
}
]
}
Empty file added CHANGELOG.md
Empty file.
Empty file added CODE_OF_CONDUCT.md
Empty file.
Empty file added CONTRIBUTING.md
Empty file.
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