Git Product home page Git Product logo

unibeautify's Introduction

Unibeautify

Renovate enabled Maintainability

One Beautifier to rule them all, One Beautifier to clean them, One Beautifier to bring them all and in the darkness sheen them

Travis CI (Linux / macOS) AppVeyor (Windows) Test Coverage
Build Status Build status Test Coverage

Why

  • Single beautifier abstracting multiple beautifiers for multiple languages
  • Unified beautifier configuration options

Install

To use programmatically with Node.js:

$ npm install --save unibeautify

CLI

See Unibeautify-CLI:

$ npm install --global @unibeautify/cli

Usage

See test/ directory for examples.

Contribute

# Be sure to lint
npm run lint
# And build
npm run build
# And test
npm test

unibeautify's People

Contributors

dependabot[bot] avatar esemesek avatar eyecatchup avatar glavin001 avatar greenkeeper[bot] avatar lassik avatar renovate-bot avatar renovate[bot] avatar sam-kleiner avatar stevenzeck avatar zaoqi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unibeautify's Issues

Disable coverage when running VSCode debugger

Debugging Unibeautify in VSCode will not work 100% properly unless you disable code coverage while doing so. So we want to add `--coverage false to the launch args.

"args": ["--config", "jest.config.js", "--runInBand", "--coverage", "false"]

I have seen cases where adding a debugger statement triggered the debugger to stop, but not at the correct line. As a result, my standard practice is to turn coverage off during debugging, hence the "--coverage", "false" in the runtimeArgs parameter in launch.json

https://medium.com/@mtiller/debugging-with-typescript-jest-ts-jest-and-visual-studio-code-ef9ca8644132

Replace lodash functions with ES6 equivalents

We should start using ES6 over lodash when we can. Unfortunately not all of lodash's functions have a suitable alternative yet, but a good portion do. Ideally we want as fewer dependencies so the install is as small as possible.

_.filter(this.languages, (language: Language): boolean => can be replaced with something along the lines of this.languages.filter((language: Language): boolean =>.

_.map, _.filter, _.reduce all have ES6 equivalents.

https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#quick-links
https://www.sitepoint.com/lodash-features-replace-es6/

Standard Options

Something I have been thinking about is that options management for a long time was a mess in Pretty Diff until I rewrote the architecture of the application around a centralized standard management of options internally. Even still options management in Atom Beautify was also kind of a mess in keeping up with various different beautifiers.

I am proposing a standard set of options with a central standard API. A stand alone code repository under the Unibeautify organization.

Here is what I am thinking in more detail:

  • Options are defined in a central location to the Unibeautify project and not immediately associated with any particular beautifier (application agnostic).
  • Options and the respective API are well documented.
  • Each of the different beautifiers are free to decide which options they wish to consume/support. A beautifier is not required to support all available options.
  • New options from a beautifier should not be added unless they are integrated into the central options management first.

Potential challenges

  • We have to support the options that are already in the beautifiers and not do anything heavy handed that would break current support or backwards compatibility.
  • We would have to win support from the various beautifiers.
  • We would need to plan out a simple architecture that works for everybody.
  • We would need living documentation that declares where the options are supported in the various beautifiers and in which IDE interfaces.

Goals

  • Simplify maintenance and management as this application covers a wide spectrum horizontally and vertically.
  • Announce innovation and capabilities from various competing beautifiers in a way other beautifiers and IDE maintainers can keep up with in a compatible way.
  • Provide an additional layer of logical separation of concerns for Unibeautify.

Ignore lines of code

  • ignore-next-line - Ignore changes for next line
  • disable and enable - Temporarily disable any changes until re-enabled
  • ignore-line - Ignore changes for current line
  • disable-beautifiers and enable-beautifiers - Temporarily disable any changes by beautifier(s) until re-enabled
  • Only process if unibeautify: prefix is found in original text

See:

Thoughts on the name?

What do you think about unibeautify as the new name? This project will eventually support a Node.js API, CLI, Atom, and Sublime editor plugins.

use unibeatify with prettydiff in my react app

Hi,

I've tried to use unibeatify and prettydiff together in my react app.

Just imported unibeatify and beautifier-prettydiff but then I get this error:

import 'unibeautify';
import 'beautifier-prettydiff';
Error in ./~/sb-exec/lib/index.js
Module not found: 'child_process'

Thanks for your help!

Error handling utility / Generate debugging information

Perhaps there should be a utility to provide error handling. This utility can accept a title, message, and stack trace and format that information properly to the executing environment whether HTML, CLI, or one of the various IDEs.

Quick test

Beautifier Details
Name:
Link to project/homepage:

If this is a new beautifier, please fill out the below
Languages Supported:
How is it run (node, terminal, etc):

If this is to update an existing beautifier, please describe what should be updated

Additional context

Add functions/methods to retrieve options and beautifiers for a language

For the documentation, Atom Beautify, and potentially other things it would be best to centralize the logic that matches languages, beautifiers, and options all together. The docs scripts do a lot of this already, but should be in core Unibeautify so it can be reused.

  • List all loaded options (loadedOptions)
  • List all supported options (getOptionsSupportedForLanguage?)
  • List all loaded languages (getLoadedLanguages)
  • List all supported languages (supportedLanguages)
  • Get options supported by a beautifier for a language (getOptionsSupportedByBeautifierForLanguage)
  • Get languages for beautifier (getLanguagesForBeautifier)
  • Get languages supporting option (getLanguagesSupportingOption)
  • Get beautifiers for a language (getBeautifiersForLanguage)
  • Get beautifiers support for an option for a language (getBeautifiersSupportingOption)
  • Get language based on Atom Grammar and file extension (findLanguages)

Parsing framework

@Glavin001

@prettydiff - I'm interested in separating parsers from formatting rules (what we often call "beautifiers"), but at a more basic level I'd like to see a parsing framework that produces unified lossless parsed source trees.

Most parsers are optimized for speed, accuracy, and producing abstract syntax trees. This means they have source that is hard to read (because it does obtuse things to make it faster), they throw errors and halt on unknown syntax, and they discard whitespace and comments. All of these are bad beautifiers.

Parsers also do not interconnect or communicate - I can parse html and then parse the javascript inside the <script> tags, but the resulting parsed javascript tree is completely separate from the html tree. I could beautify each separately, but they can't interact. When we go to templating (mustache, php, braces for example), this gets really ugly. What we want is a framework of parsers that produce one syntax tree (or at very least one token stream with trees that can interact).

Design/implement what options a beautifier supports for a given language

We have the ability to specify what options and what languages a beautifier supports, https://github.com/Unibeautify/beautifier-prettydiff/blob/master/src/index.ts#L10-L119, but no way to specify which options the beautifier supports for a specific language. Example: prettydiff supports the break_chained_methods option and the CSS language, but that option wouldn't be applicable to CSS, however with the way it's currently designed it does.

So need to design and implement a way to specify which options a language supports for each beautifier. Some ideas:

  • CSS: true would mean the beautifier supports CSS and all of the beautifiers supported options are applicable to it
  • CSS: false would mean the beautifier supports CSS, but none of the options are applicable to it
  • CSS: [option1, option2, option3, etc...] would specify which options the beautifier supports for a language

Whatever the design ends up being, need to revisit getOptionsSupportedByBeautifierForLanguage and possibly other helper methods.

Cannot uninstall unibeautify in vscode

I installed Unibeautify 0.4.0 on VSCode 1.23.1 x64 Windows 10 from the VSCode marketplace and it was not working properly for me. Also, now the native VSCode html formatter is broken as well.

Afterwards, I tried to uninstall it, and it was stuck in Uninstalling state forever.

EDIT: uninstall works from the command-line (code --uninstall-extension Glavin001.unibeautify-vscode), just not the VSCode UI

Refactor beautifier.ts

  • Move generic methods into utility class
  • Break up methods in the Unibeautify class
  • Reduce similar code, such as that within the findLanguages method
  • Make getOptionsForBeautifier method less complex (edit: part of this may have to wait, as we've talked about returning an object that contains objects and errors, since errors are otherwise lost right now)

Removing task Return errors properly when going through methods

Include file extension in BeautifierBeautifyData

We need to use the file extension for the tmp file's postfix when creating a temp file. For executable beautifiers that support multiple languages, there is no way to know the extension to use there with the current BeautifierBeautifyData interface.

v0.12.0 does not work with Webpack

See Unibeautify/playground#21 and https://travis-ci.org/Unibeautify/playground/jobs/366600201#L2994

WARNING in ./node_modules/unibeautify/dist/src/DependencyManager/NodeDependency.js
39:32-39 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
 @ ./node_modules/unibeautify/dist/src/DependencyManager/NodeDependency.js
 @ ./node_modules/unibeautify/dist/src/DependencyManager/index.js
 @ ./node_modules/unibeautify/dist/src/index.js
 @ ./src/Container.tsx
 @ ./src/App.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx
ERROR in ./node_modules/unibeautify/dist/src/DependencyManager/ExecutableDependency.js
Module not found: Error: Can't resolve 'child_process' in '/home/travis/build/Unibeautify/playground/node_modules/unibeautify/dist/src/DependencyManager'
 @ ./node_modules/unibeautify/dist/src/DependencyManager/ExecutableDependency.js 3:24-48
 @ ./node_modules/unibeautify/dist/src/DependencyManager/index.js
 @ ./node_modules/unibeautify/dist/src/index.js
 @ ./src/Container.tsx
 @ ./src/App.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx
ERROR in ./node_modules/requireg/lib/requireg.js
Module not found: Error: Can't resolve 'fs' in '/home/travis/build/Unibeautify/playground/node_modules/requireg/lib'
 @ ./node_modules/requireg/lib/requireg.js 1:11-24
 @ ./node_modules/unibeautify/dist/src/DependencyManager/NodeDependency.js
 @ ./node_modules/unibeautify/dist/src/DependencyManager/index.js
 @ ./node_modules/unibeautify/dist/src/index.js
 @ ./src/Container.tsx
 @ ./src/App.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx
ERROR in ./node_modules/requireg/lib/resolvers.js
Module not found: Error: Can't resolve 'fs' in '/home/travis/build/Unibeautify/playground/node_modules/requireg/lib'
 @ ./node_modules/requireg/lib/resolvers.js 1:11-24
 @ ./node_modules/requireg/lib/requireg.js
 @ ./node_modules/unibeautify/dist/src/DependencyManager/NodeDependency.js
 @ ./node_modules/unibeautify/dist/src/DependencyManager/index.js
 @ ./node_modules/unibeautify/dist/src/index.js
 @ ./src/Container.tsx
 @ ./src/App.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx
ERROR in ./node_modules/requireg/node_modules/resolve/lib/async.js
Module not found: Error: Can't resolve 'fs' in '/home/travis/build/Unibeautify/playground/node_modules/requireg/node_modules/resolve/lib'
 @ ./node_modules/requireg/node_modules/resolve/lib/async.js 2:9-22
 @ ./node_modules/requireg/node_modules/resolve/index.js
 @ ./node_modules/requireg/lib/resolvers.js
 @ ./node_modules/requireg/lib/requireg.js
 @ ./node_modules/unibeautify/dist/src/DependencyManager/NodeDependency.js
 @ ./node_modules/unibeautify/dist/src/DependencyManager/index.js
 @ ./node_modules/unibeautify/dist/src/index.js
 @ ./src/Container.tsx
 @ ./src/App.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx
ERROR in ./node_modules/requireg/node_modules/resolve/lib/sync.js
Module not found: Error: Can't resolve 'fs' in '/home/travis/build/Unibeautify/playground/node_modules/requireg/node_modules/resolve/lib'
 @ ./node_modules/requireg/node_modules/resolve/lib/sync.js 2:9-22
 @ ./node_modules/requireg/node_modules/resolve/index.js
 @ ./node_modules/requireg/lib/resolvers.js
 @ ./node_modules/requireg/lib/requireg.js
 @ ./node_modules/unibeautify/dist/src/DependencyManager/NodeDependency.js
 @ ./node_modules/unibeautify/dist/src/DependencyManager/index.js
 @ ./node_modules/unibeautify/dist/src/index.js
 @ ./src/Container.tsx
 @ ./src/App.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx
ERROR in ./node_modules/rc/index.js
Module parse failed: Unexpected character '#' (1:0)
You may need an appropriate loader to handle this file type.
| #! /usr/bin/env node
| var cc   = require('./lib/utils')
| var join = require('path').join
 @ ./node_modules/requireg/lib/resolvers.js 4:9-22
 @ ./node_modules/requireg/lib/requireg.js
 @ ./node_modules/unibeautify/dist/src/DependencyManager/NodeDependency.js
 @ ./node_modules/unibeautify/dist/src/DependencyManager/index.js
 @ ./node_modules/unibeautify/dist/src/index.js
 @ ./src/Container.tsx
 @ ./src/App.tsx
 @ ./src/index.tsx
 @ multi ./src/index.tsx

Allow beautifiers to use their own config file instead of Unibeautify config

Important: Read Unibeautify/vscode#21 (comment) for why Unibeautify does not only use the beautifier's respective configuration files (i.e. prettierrc for Prettier, eslintrc for ESLint, etc).


Add option like prefer_beautifier_config.

Example

When Unibeautify is iterating over the selected beautifiers and reaches beautifier Prettier and the beautifier's config is set to preferBeautifierConfig=true then Unibeautify should pass Prettier's config directly: https://prettier.io/docs/en/api.html#prettierresolveconfigfilepath-options


Do you think prefer_beautifier_config should be enabled or disabled by default? Read explanation at #48 (comment)


unibeautify:disable deletes line of code

See Playground

Before:

function test() {
    // unibeautify:disable
console.log("Test1");
    // unibeautify:disable
console.log("Test2");
}

function helloWorld() {
	// unibeautify:disable
console.log('Hello World');
	// unibeautify:disable
console.log('Hello World');
}

After:

function test() {
    // unibeautify:disable
console.log("Test2");
}

function helloWorld() {
	// unibeautify:disable
console.log('Hello World');
	// unibeautify:disable
console.log('Hello World');
}

CodeClimate configuration and rules

Our current CodeClimate configuration consists of the below. We should decide how best to have it configured for all of the repos (stuff like number of lines a file, number of lines in a method/function, etc). Specifics can be found here: https://docs.codeclimate.com/docs/maintainability

version: "2"
checks:
  argument-count:
    enabled: true
    config:
      threshold: 4
  complex-logic:
    enabled: true
    config:
      threshold: 4
  file-lines:
    enabled: true
    config:
      threshold: 250
  method-complexity:
    enabled: true
    config:
      threshold: 5
  method-count:
    enabled: true
    config:
      threshold: 20
  method-lines:
    enabled: true
    config:
      threshold: 25
  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"

Embedded Languages

Continuation of #4 and related issues.

Languages like PHP often embeds HTML inside. HTML also embeds JavaScript and CSS inside.
Unibeautify should have first class support for breaking a file into languages and embedded languages, and applying the corresponding language beautifiers in series.

Use consistent naming for do and don't options

I think it would be better if we stayed consistent with the naming and function of options in relation to whether they should do something or should not do something. Take these options:

  • indent_comments (comments should be indented)
  • indent_inner_html (<head> and <body> section should be indented)
  • indent_scripts (scripts should be indented)
  • unindent_chained_methods (chained methods should not be indented)
  • keep_array_indentation (array indents should be ignored)

The odd ball is unindent_chained_methods. This should probably be changed to indent_chained_methods with the default flipped from false to true. That would preserve existing behavior an be consistent with the other options.

Thoughts?

Unibeautify: Adapter, Framework, or Both

Atom-beautify is not a beautifier or framework. It is an adapter that lets users beautify JS or other languages, but depends on other tools to do the beautifying. Those tools have no awareness of atom-beautify and can have wildly different internal design and implmentation. Determining the cause of issues is difficult because in might be from any of several tools or from interaction with those tools.

A beautification framework would provide facilities that other components would plug into. For example, the framework might provide a facilities to configure formatting rules and read input, establish APIs or base classes for parsed token trees, execute all requested formatting rules on those tokens, and then have one unified implementation of an output writer. This would not support tools outside this framework, but would make it significantly easier to analyze and fix issue.

Unibeautify can do either of these or both, but I'd make sure we've talked about it early rather than later.

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml
  • The new Node.js version is in-range for the engines in 1 of your package.json files, so that was left alone

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.