Code Monkey home page Code Monkey logo

custom-format's Introduction

Custom Format

Run custom CLI commands for formatting files in VSCode.

How many times have you not been able to find a VSCode formatter for your particular purpose when there was already a CLI to do the job? And how much easier is it to throw together a CLI command to format your code that it is to build an extension to suit your needs?

Because you are reading this, those questions can be favorably answered. Introducing Custom Format. Just add your CLI commands to the custom-format.formatters configuration and you're set.

feature X

Configuration

Populate the custom-format.formatters setting.

// global settings.json or .vscode/settings.json
{
	// ...

	// Create our custom formatters
	"custom-format.formatters": [
		{
			// Whatever language id you need to format
			"language": "javascript",
			// The command that will be run to format files with the language id specified above
			"command": "node format.js $FILE" // $FILE is replaced with the path of the file to be formatted
		},
		{
			"language": "typescript",
			"command": "node format-ts.js"
		}
	],

	// (optional) Set it as the default formatter for the languages we have configured formatters for
	"[javascript]": {
		"editor.defaultFormatter": "vehmloewff.custom-format"
	},
	"[typescript]": {
		"editor.defaultFormatter": "vehmloewff.custom-format"
	}
}

Running commands

All specified commands are expected to read in unformatted code on their stdin and print the formatted code to their stdout.

In all cases, if any text is printed to stderr, the error will be relayed to the "Custom Format" output panel.

If text is printed to stdout, error or no error, the file will be overwritten with the printed text.

If there is no content written to stdout, error or no error, the formatting of the file will be skipped.

If the command exits with a non-zero code, the formatting of the file will be skipped.

Before the command is executed, all instances of $FILE therein are replaced with the absolute path of the file that is being formatted.

Release Notes

See the changelog.

Issues

Please report all issues here.

License

MIT

custom-format's People

Contributors

krysl avatar minism avatar vehmloewff avatar

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.